Commit Graph

25 Commits

  • Fix API key priority and compaction bugs
    - getEnvApiKey: ANTHROPIC_OAUTH_TOKEN now takes precedence over ANTHROPIC_API_KEY
    - findCutPoint: Stop scan-backwards loop at session header (was decrementing past it causing null preparation)
    - generateSummary/generateTurnPrefixSummary: Throw on stopReason=error instead of returning empty string
    - Test files: Fix API key priority order, use keepRecentTokens=1 for small test conversations
  • Session tree structure with id/parentId linking
    - Add TreeNode base type with id, parentId, timestamp
    - Add *Content types for clean input/output separation
    - Entry types are now TreeNode & *Content intersections
    - SessionManager assigns id/parentId on save, tracks leafId
    - Add migrateSessionEntries() for v1 to v2 conversion
    - Migration runs on load, rewrites file
    - buildSessionContext() uses tree traversal from leaf
    - Compaction returns CompactionResult (content only)
    - Hooks return compaction content, not full entries
    - Add firstKeptEntryId to before_compact hook event
    - Update mom package for tree fields
    - Better error messages for compaction failures
  • feat(coding-agent): Add --session-dir flag for custom session directory
    - Add --session-dir CLI flag to specify custom session directory
    - SessionManager API: second param of create(), continueRecent(), list(), open()
      changed from agentDir to sessionDir (direct directory, no cwd encoding)
    - When omitted, uses default (~/.pi/agent/sessions/<encoded-cwd>/)
    - --session now derives sessionDir from file's parent if --session-dir not provided
    - list() validates session header before processing files
    - Closes #313
    
    Co-authored-by: scutifer <scutifer@users.noreply.github.com>
  • Rename /clear to /new, update hook events to before_new/new
    Closes #305 - took direct rename approach instead of alias system
    
    Thanks @mitsuhiko for the nudge!
  • Refactor OAuth/API key handling: AuthStorage and ModelRegistry
    - Add AuthStorage class for credential storage (auth.json)
    - Add ModelRegistry class for model management with API key resolution
    - Add discoverAuthStorage() and discoverModels() discovery functions
    - Add migration from legacy oauth.json and settings.json apiKeys to auth.json
    - Remove configureOAuthStorage, defaultGetApiKey, findModel, discoverAvailableModels
    - Remove apiKeys from Settings type and SettingsManager methods
    - Rename getOAuthPath to getAuthPath
    - Update SDK, examples, docs, tests, and mom package
    
    Fixes #296
  • WIP: Remove global state from pi-ai OAuth/API key handling
    - Remove setApiKey, resolveApiKey, and global apiKeys Map from stream.ts
    - Rename getApiKey to getApiKeyFromEnv (only checks env vars)
    - Remove OAuth storage layer (storage.ts deleted)
    - OAuth login/refresh functions now return credentials instead of saving
    - getOAuthApiKey/refreshOAuthToken now take credentials as params
    - Add test/oauth.ts helper for ai package tests
    - Simplify root npm run check (single biome + tsgo pass)
    - Remove redundant check scripts from most packages
    - Add web-ui and coding-agent examples to biome/tsgo includes
    
    coding-agent still has compile errors - needs refactoring for new API
  • Add before/after session events with cancellation support
    - Merge branch event into session with before_branch/branch reasons
    - Add before_switch, before_clear, shutdown reasons
    - before_* events can be cancelled with { cancel: true }
    - Update RPC commands to return cancelled status
    - Add shutdown event on process exit
    - New example hooks: confirm-destructive, dirty-repo-guard, auto-commit-on-exit
    
    fixes #278
  • Fix SDK tools to respect cwd option
    Core tools now properly use the cwd passed to createAgentSession().
    Added tool factory functions for SDK users who specify custom cwd with explicit tools.
    
    Fixes #279
  • Add project-specific settings and SettingsManager factories
    - SettingsManager now loads .pi/settings.json from cwd (project settings)
    - Project settings merge with global settings (deep merge for objects)
    - Setters only modify global settings, project settings are read-only
    - Add static factories: SettingsManager.create(cwd?, agentDir?), SettingsManager.inMemory(settings?)
    - Add applyOverrides() for programmatic overrides
    - Replace 'settings' option with 'settingsManager' in CreateAgentSessionOptions
    - Update examples to use new pattern
    
    Incorporates PR #276 approach
  • Add SDK usage examples
    12 examples showing increasing levels of customization:
    - 01-minimal: all defaults
    - 02-custom-model: model and thinking level
    - 03-custom-prompt: replace or modify prompt
    - 04-skills: discover, filter, merge skills
    - 05-tools: built-in tools, custom tools
    - 06-hooks: logging, blocking, result modification
    - 07-context-files: AGENTS.md files
    - 08-slash-commands: file-based commands
    - 09-api-keys-and-oauth: API key resolution, OAuth config
    - 10-settings: compaction, retry, terminal settings
    - 11-sessions: persistence options
    - 12-full-control: replace everything
    
    Also exports FileSlashCommand type from index.ts
  • Convert custom tool examples to subdirectory/index.ts structure
    - hello.ts → hello/index.ts
    - question.ts → question/index.ts
    - todo.ts → todo/index.ts
    - subagent/subagent.ts → subagent/index.ts
  • Subagent: markdown rendering in expanded view, chain streaming shows all steps
    - Export getMarkdownTheme() from coding-agent for custom tools
    - Chain/parallel modes now use Markdown component in expanded view
    - Chain streaming updates include all previous steps (not just current)
    - Strip {previous} placeholder from task preview in renderCall
  • Refactor subagent tool, fix custom tool discovery, fix JSON mode stdout flush
    Breaking changes:
    - Custom tools now require index.ts entry point in subdirectory
      (e.g., tools/mytool/index.ts instead of tools/mytool.ts)
    
    Subagent tool improvements:
    - Refactored to use Message[] from ai package instead of custom types
    - Extracted agent discovery to separate agents.ts module
    - Added parallel mode streaming (shows progress from all tasks)
    - Added turn count to usage stats footer
    - Removed redundant Query section from scout output
    
    Fixes:
    - JSON mode stdout flush: Fixed race condition where pi --mode json
      could exit before all output was written, causing consumers to
      miss final events
    
    Also:
    - Added signal/timeout support to pi.exec() for custom tools and hooks
    - Renamed pi-pods bin to avoid conflict with pi
  • Custom tools with session lifecycle, examples for hooks and tools
    - Custom tools: TypeScript modules that extend pi with new tools
      - Custom TUI rendering via renderCall/renderResult
      - User interaction via pi.ui (select, confirm, input, notify)
      - Session lifecycle via onSession callback for state reconstruction
      - Examples: todo.ts, question.ts, hello.ts
    
    - Hook examples: permission-gate, git-checkpoint, protected-paths
    
    - Session lifecycle centralized in AgentSession
      - Works across all modes (interactive, print, RPC)
      - Unified session event for hooks (replaces session_start/session_switch)
    
    - Box component added to pi-tui
    
    - Examples bundled in npm and binary releases
    
    Fixes #190