Commit Graph

12 Commits

  • 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
  • refactor(coding-agent): fix compaction for branched sessions, consolidate hook context types
    Compaction API:
    - prepareCompaction() now takes (pathEntries, settings) only
    - CompactionPreparation restructured: removed cutPoint/messagesToKeep/boundaryStart, added turnPrefixMessages/isSplitTurn/previousSummary/fileOps/settings
    - compact() now takes (preparation, model, apiKey, customInstructions?, signal?)
    - Fixed token overflow by using getPath() instead of getEntries()
    
    Hook types:
    - HookEventContext renamed to HookContext
    - HookCommandContext removed, RegisteredCommand.handler takes (args, ctx)
    - HookContext now includes model field
    - SessionBeforeCompactEvent: removed previousCompactions/model, added branchEntries
    - SessionBeforeTreeEvent: removed model (use ctx.model)
    - HookRunner.initialize() added for modes to set up callbacks
  • Extract shared compaction/branch-summarization utils
    - New utils.ts with shared functions:
      - FileOperations type and createFileOps()
      - extractFileOpsFromMessage()
      - computeFileLists()
      - formatFileOperations()
      - serializeConversation()
      - SUMMARIZATION_SYSTEM_PROMPT
    
    - branch-summarization.ts now uses:
      - Serialization approach (conversation as text, not LLM messages)
      - completeSimple with system prompt
      - Shared utility functions
  • Use convertToLlm before serializing, include thinking, remove truncation
    - serializeConversation now takes Message[] (after convertToLlm)
    - Handles all custom message types via convertToLlm
    - Includes thinking blocks as [Assistant thinking]
    - Removes truncation of tool args and results (already token-budgeted)
  • Serialize conversation to text for summarization
    Instead of passing conversation as LLM messages (which makes the model
    try to continue it), serialize to text wrapped in <conversation> tags.
    
    - serializeConversation() formats messages as [User]/[Assistant]/[Tool result]
    - Tool calls shown as function(args) format
    - Tool results truncated to prevent bloat
    - Conversation wrapped in <conversation> tags in the prompt
  • Add system prompt to compaction summarization
    - SUMMARIZATION_SYSTEM_PROMPT explains the task clearly
    - Tells model to NOT continue conversation, ONLY output summary
    - Updated prompts to reference 'messages above' for clarity
    - Pass systemPrompt to completeSimple
  • Add file tracking and iterative summary merging to compaction
    - CompactionDetails type with readFiles/modifiedFiles
    - extractFileOperations collects from tool calls and previous compaction details
    - UPDATE_SUMMARIZATION_PROMPT for merging with previous summary
    - generateSummary now accepts previousSummary for iterative updates
    - compact() extracts files, passes previousSummary, returns details
    - Only merges from !fromHook compaction entries (backward compatible)
  • Use structured output format for compaction and branch summarization
    Both now use consistent sections:
    - Goal
    - Constraints & Preferences
    - Progress (Done/In Progress/Blocked)
    - Key Decisions
    - Next Steps
    - Critical Context (compaction only)
    
    Prompts instruct LLM to use EXACT format and preserve file paths/function names.
  • Refactor: move compaction code to src/core/compaction/
    - Move compaction.ts to src/core/compaction/compaction.ts
    - Extract branch summarization to src/core/compaction/branch-summarization.ts
    - Add index.ts to re-export all compaction utilities
    - Update all imports across the codebase