Commit Graph

8 Commits

  • fix(coding-agent): prevent duplicate session headers when forking from pre-assistant entry
    createBranchedSession() wrote the file and set flushed=true even when the
    branched path had no assistant message. The next _persist() call saw no
    assistant, reset flushed=false, and the subsequent flush appended all
    in-memory entries to the already-populated file, duplicating the header
    and entries.
    
    Fix: defer file creation when the branched path has no assistant message,
    matching the newSession() contract. _persist() creates the file on the
    first assistant response.
    
    closes #1672
  • Merge hooks and custom-tools into unified extensions system (#454)
    Breaking changes:
    - Settings: 'hooks' and 'customTools' arrays replaced with 'extensions'
    - CLI: '--hook' and '--tool' flags replaced with '--extension' / '-e'
    - API: HookMessage renamed to CustomMessage, role 'hookMessage' to 'custom'
    - API: FileSlashCommand renamed to PromptTemplate
    - API: discoverSlashCommands() renamed to discoverPromptTemplates()
    - Directories: commands/ renamed to prompts/ for prompt templates
    
    Migration:
    - Session version bumped to 3 (auto-migrates v2 sessions)
    - Old 'hookMessage' role entries converted to 'custom'
    
    Structural changes:
    - src/core/hooks/ and src/core/custom-tools/ merged into src/core/extensions/
    - src/core/slash-commands.ts renamed to src/core/prompt-templates.ts
    - examples/hooks/ and examples/custom-tools/ merged into examples/extensions/
    - docs/hooks.md and docs/custom-tools.md merged into docs/extensions.md
    
    New test coverage:
    - test/extensions-runner.test.ts (10 tests)
    - test/extensions-discovery.test.ts (26 tests)
    - test/prompt-templates.test.ts
  • Rework custom tools API with CustomToolContext
    - CustomAgentTool renamed to CustomTool
    - ToolAPI renamed to CustomToolAPI
    - ToolContext renamed to CustomToolContext
    - ToolSessionEvent renamed to CustomToolSessionEvent
    - Added CustomToolContext parameter to execute() and onSession()
    - CustomToolFactory now returns CustomTool<any, any> for type compatibility
    - dispose() replaced with onSession({ reason: 'shutdown' })
    - Added wrapCustomTool() to convert CustomTool to AgentTool
    - Session exposes setToolUIContext() instead of leaking internals
    - Fix ToolExecutionComponent to sync with toolOutputExpanded state
    - Update all custom tool examples for new API
  • Add tree navigation tests and shared test utilities
    - Add test/utilities.ts with shared helpers (API_KEY, userMsg, assistantMsg, createTestSession)
    - Add agent-session-tree-navigation.test.ts with e2e tests for tree navigation
    - Add getChildren() method to SessionManager
    - Add summaryEntry to navigateTree return type
    - Update existing tests to use shared utilities
  • Fix branch summarization abort handling and tree navigation
    - Check response.stopReason instead of catching errors for abort detection
    - Return result object from _generateBranchSummary instead of throwing
    - Fix summary attachment: attach to navigation target position, not old branch
    - Support root-level summaries (parentId=null) in branchWithSummary
    - Remove setTimeout hack for re-showing tree selector on abort
  • 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.
  • Session tree: simplify types, add branching API, comprehensive tests
    Types:
    - SessionEntryBase with type field, extended by all entry types
    - CustomEntry for hooks (type: 'custom', customType, data)
    - Remove XXXContent types and TreeNode (redundant)
    
    API:
    - Rename saveXXX to appendXXX with JSDoc explaining tree semantics
    - Rename branchInPlace to branch() with better docs
    - Add createBranchedSession(leafId) replacing index-based version
    - Add getTree() returning SessionTreeNode[] for tree traversal
    - Add appendCustomEntry(customType, data) for hooks
    
    Tests:
    - tree-traversal.test.ts: 28 tests covering append, getPath, getTree,
      branch, branchWithSummary, createBranchedSession
    - save-entry.test.ts: custom entry integration
    
    Docs:
    - Class-level JSDoc explaining append-only tree model
    - Method docs explaining leaf advancement and branching
    - CHANGELOG.md entry for all changes