Skip to content

Develop#277

Merged
Alex793x merged 38 commits intomainfrom
develop
Jan 15, 2026
Merged

Develop#277
Alex793x merged 38 commits intomainfrom
develop

Conversation

@Alex793x
Copy link
Copy Markdown
Contributor

No description provided.

Alex Holmberg and others added 30 commits January 12, 2026 17:22
Phase 1: Audit & Triage
- 3 plans created
- 7 total tasks defined
- Ready for execution

Plans:
- 01-01: Tool inventory (2 auto tasks)
- 01-02: Testing protocol & results (1 auto, 1 checkpoint, 1 auto)
- 01-03: Bug categorization & prioritization (3 auto tasks)

Co-Authored-By: Claude <noreply@anthropic.com>
- Organized 28 tools into 5 test categories (A-E) by prerequisites
- Defined basic, realistic, and edge case tests per tool
- Included test prompts to trigger each tool
- Prioritized P0-P3 based on risk from inventory
- Added pre-test setup and post-test cleanup checklists
…mode

- Moved src/agent/session.rs to src/agent/session/mod.rs
- Created src/agent/session/plan_mode.rs with extracted types
- Extracted: IncompletePlan struct, find_incomplete_plans fn, PlanMode enum
- Added re-exports for backward compatibility
- mod.rs reduced from 1937 to 1839 lines

Co-Authored-By: Claude <noreply@anthropic.com>
Extract ~560 lines from session/mod.rs to providers.rs:
- get_available_models function
- has_api_key function
- load_api_key_to_env function
- get_configured_providers function
- run_bedrock_setup_wizard function
- prompt_api_key function

ChatSession methods delegate to providers module functions.
Re-exports added for backward compatibility.

Co-Authored-By: Claude <noreply@anthropic.com>
Extract 7 slash command handlers from session/mod.rs into dedicated
commands.rs module as free functions that take &mut ChatSession:
- handle_model_command
- handle_provider_command
- handle_reset_command
- handle_profile_command
- handle_plans_command
- handle_resume_command
- handle_list_sessions_command

Also includes list_profiles helper function used by profile command.

Co-Authored-By: Claude <noreply@anthropic.com>
- Add mod commands declaration
- Replace all 7 handle_* method implementations with delegations to
  commands::handle_* functions
- Remove list_profiles helper (now in commands.rs)
- Clean up unused imports (load_agent_config, save_agent_config, Write)

session/mod.rs reduced by ~730 lines.

Co-Authored-By: Claude <noreply@anthropic.com>
Extract print_help, print_logo, and print_banner functions from
session/mod.rs to a dedicated ui.rs submodule. This completes the
session module decomposition by moving all UI display logic to a
focused module.

Co-Authored-By: Claude <noreply@anthropic.com>
Add src/agent/tools/error.rs with shared error handling infrastructure:
- ToolErrorContext trait for adding context when propagating errors
- format_error_for_llm function for LLM-friendly error JSON formatting
- format_error_with_context for errors with additional fields
- ErrorCategory enum with common error types (FileNotFound, PermissionDenied, etc.)
- detect_error_category helper for automatic category detection
- Comprehensive unit tests

This module provides utilities without replacing individual tool error types.
Each tool keeps its own error type but uses these utilities for consistent formatting.

Co-Authored-By: Claude <noreply@anthropic.com>
Update file_ops.rs, shell.rs, and analyze.rs to use new error utilities:

file_ops.rs:
- Improve validate_path error messages with specific io::ErrorKind handling
- Add path info to error messages for FileNotFound, PermissionDenied
- Use format_error_for_llm for file-too-large and invalid line range errors
- Better context in path-outside-boundary errors

shell.rs:
- Use format_error_with_context for command rejection errors
- Improve validate_working_dir with specific error messages
- Better structured errors for plan mode rejections
- Use ErrorCategory::UserCancelled for cancellation responses

analyze.rs:
- Validate path exists before analysis
- Return structured errors with suggestions
- Auto-detect error category (permission, file not found, etc.)

Each tool keeps its own error type but uses utilities for consistent formatting.

Co-Authored-By: Claude <noreply@anthropic.com>
- Add `pub mod error;` declaration in mod.rs
- Add re-exports for commonly used error utilities:
  - ErrorCategory, ToolErrorContext, detect_error_category
  - format_error_for_llm, format_error_with_context
- Add module-level documentation explaining the error handling pattern
- Document the 4-step pattern for using error utilities in tools

Co-Authored-By: Claude <noreply@anthropic.com>
Add src/agent/tools/response.rs with standardized response formatting:
- ToolResponse struct with success, data, metadata fields
- ResponseMetadata struct with truncation/compression info
- format_success() for simple success responses
- format_success_with_metadata() for responses with metadata
- format_file_content() for file read operations
- format_file_content_range() for line range reads
- format_list() for directory/list operations
- format_write_success() for write operations
- format_cancelled() for user cancellation responses
- 12 unit tests covering all functionality

Integrates with existing truncation.rs limits for consistency.
Module declared as public for use by other tools.

Co-Authored-By: Claude <noreply@anthropic.com>
Update file_ops.rs to use response formatting utilities:
- ReadFileTool: use format_file_content() and format_file_content_range()
- ListDirectoryTool: use format_list() for consistent directory listings
- WriteFileTool: use format_cancelled() for cancellation responses
- WriteFilesTool: use format_cancelled() for cancellation responses

Response format remains backward compatible with existing agent prompts.
analyze.rs already uses compress_analysis_output which provides
appropriate metadata (retrieval_id, compression info) - no changes needed.

Co-Authored-By: Claude <noreply@anthropic.com>
Add response pattern documentation to mod.rs:
- Document usage of format_file_content, format_list, etc.
- Add example showing recommended usage pattern
- Add re-exports for all response formatting utilities:
  ResponseMetadata, ToolResponse, format_cancelled, format_file_content,
  format_file_content_range, format_list, format_list_with_metadata,
  format_success, format_success_with_metadata, format_write_success

This completes Phase 3 Tool Infrastructure:
- 03-01: Audited patterns (TOOL-PATTERNS.md)
- 03-02: Created error.rs with error utilities
- 03-03: Created response.rs with response utilities

Co-Authored-By: Claude <noreply@anthropic.com>
- Add general development commands: echo, printf, test, expr
- Add build/package commands: pnpm run, yarn run, gradle, mvn, poetry, pip install, bundle exec
- Add testing commands: npm test, yarn test, pnpm test, cargo test, go test, pytest, jest, vitest
- Add git write commands: git add, commit, push, checkout, branch, merge, rebase, stash, fetch, pull, clone
- Organize commands by category with documentation comments

Addresses BUG-001: Shell command allowlist too restrictive

Co-Authored-By: Claude <noreply@anthropic.com>
- Update tool definition to be more welcoming (remove RESTRICTED language)
- List supported command categories in description
- Explain the confirmation system that allows session-level approvals
- Add categorize_command() helper to identify command types
- Add get_category_suggestions() for context-aware suggestions
- Improve rejection messages with category hints and specific guidance
- Change "not in allowed list" to "not in default allowlist" (more accurate)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive test module with 14 test functions covering:
- General development commands (echo, printf, test, expr) - addresses BUG-001
- Build commands (npm/yarn/pnpm alternatives, gradle, mvn, poetry, pip, bundle)
- Testing commands (npm/yarn/pnpm test, cargo/go test, pytest, jest, vitest)
- Git write commands (add, commit, push, checkout, branch, merge, etc.)
- Dangerous commands still rejected (rm, bash, sudo, curl, wget)
- Read-only mode allows read commands and blocks write commands
- Command chain validation in read-only mode
- Command categorization helper function
- Category-specific suggestions
- Regression tests for existing docker/terraform/kubernetes/linting commands

Co-Authored-By: Claude <noreply@anthropic.com>
- ReadFileTool: Document truncation limits (2000 lines, 2000 char lines),
  start_line/end_line usage, and path restrictions
- WriteFileTool: CLEARLY document path restriction as intentional security
  feature, suggest tmp/ directory in project for temporary files,
  document confirmation workflow
- WriteFilesTool: Same path restriction documentation, document atomicity
  (all paths validated before any writes)
- ListDirectoryTool: Document max entries (500), alphabetical sorting,
  automatic filtering of node_modules/.git/etc

Addresses BUG-002 by making path restrictions clear and intentional.

Co-Authored-By: Claude <noreply@anthropic.com>
- All path validation errors now use format_error_for_llm for consistent
  LLM-friendly error responses with structured JSON
- ReadFileTool: Errors include suggestions like "Use list_directory to
  explore available files" and project root path
- ListDirectoryTool: Errors suggest using '.' for project root
- WriteFileTool/WriteFilesTool: Path boundary errors now include clear
  security explanation and suggest creating 'tmp/' directory in project
- All errors include: attempted path, error category, project boundary,
  and actionable suggestions

Path errors now return Ok(error_json) instead of Err() so LLM receives
helpful feedback instead of opaque failure.

Co-Authored-By: Claude <noreply@anthropic.com>
- Empty file handling: ReadFileTool returns clear "(empty file)" message
  instead of error when file has zero bytes
- Binary file detection: Check for null bytes in first 1KB, return
  helpful message suggesting specialized tools for binary content
- Symlink handling: ReadFileTool validates symlink targets are within
  project boundary, with clear error if symlink points outside
- WriteFilesTool atomicity: All paths are validated BEFORE any files
  are written; if any path is invalid, lists all invalid paths and
  writes nothing

Added helper functions:
- is_likely_binary(): Detects binary content by checking for null bytes
- validate_symlink_target(): Validates symlinks stay within project

Co-Authored-By: Claude <noreply@anthropic.com>
Expanded tool definition with comprehensive documentation:
- What gets analyzed: languages, frameworks, dependencies, build tools, architecture
- Monorepo detection and handling explanation
- Output format with compression and retrieval pattern
- Supported languages list (Java, Go, JS/TS, Rust, Python)
- Improved path parameter documentation for subdirectory analysis

Co-Authored-By: Claude <noreply@anthropic.com>
Added graceful handling for edge cases:
- Empty directory: Checks for empty dirs before analysis, returns helpful message
- Large projects: Warns when >10000 files detected with count_files_recursive()
- Unsupported project types: Returns guidance when no languages detected
- Directory read errors: Proper error handling with suggestions

The file count function skips common non-source directories (node_modules,
target, .git, etc.) for efficiency and limits scanning to 15000 files.

Co-Authored-By: Claude <noreply@anthropic.com>
- Add structured error handling using format_error_for_llm for:
  - File not found errors with recovery suggestions
  - Path outside boundary validation
  - Permission denied handling
  - Directory vs file validation
- Enhance tool definition with comprehensive documentation:
  - Native implementation details
  - Supported rule categories
  - Output format explanation
  - Parameter descriptions with defaults
- Add 6 new tests for helper functions and error handling

Co-Authored-By: Claude <noreply@anthropic.com>
- Add format_error_for_llm imports from error module
- Update chart path validation to use structured error responses
- Handle edge cases: empty directory, missing Chart.yaml, file-not-dir
- Improve tool definition with clear helmlint vs kubelint scope
- Document all rule categories (HL1xxx-HL5xxx)
- Add unit tests for parse_threshold, get_priority, fix_recommendations
- Add integration tests for all error paths

Co-Authored-By: Claude <noreply@anthropic.com>
- Add format_error_for_llm import for consistent error handling
- Update path validation errors to use structured LLM-friendly format
- Add edge case handling for empty directories, invalid YAML, non-K8s YAML
- Improve tool definition with clear documentation on scope vs helmlint
- Document check categories (Security, Resources, RBAC, Best Practice)
- Document parameters and compression behavior
- Add unit tests for parse_threshold, get_check_category, get_priority

Co-Authored-By: Claude <noreply@anthropic.com>
- Add format_error_for_llm error handling for file not found, empty file,
  invalid YAML, and non-compose content
- Improve tool definition with comprehensive documentation of capabilities,
  rule categories, parameters, and usage guidance
- Add unit tests for parse_threshold, get_priority, fix_recommendations,
  and rule_url_generation

Co-Authored-By: Claude <noreply@anthropic.com>
- Add format_error_for_llm for structured error responses
- Handle path not found with helpful suggestions
- Handle empty directory (no K8s manifests) gracefully
- Add Prometheus connection error handling with graceful degradation
- Add tests for error cases: test_path_not_found_error,
  test_empty_content_handled, test_no_k8s_manifests_in_directory

Co-Authored-By: Claude <noreply@anthropic.com>
- Add format_error_for_llm for consistent error handling
- Add port validation (1-65535)
- Add URL format validation (must start with http:// or https://)
- Update all error paths to use structured errors with suggestions
- Add comprehensive tests for validation and error cases

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
- Add clear_turns_preserve_context() method to ConversationHistory
- Replace .clear() calls with preserve method in both truncation paths
- Truncation now compacts remaining turns before clearing
- Summary frame preserved across truncations
- Add 2 tests for new context preservation behavior

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Serialize/Deserialize to ConversationHistory and SummaryFrame
- Add to_json()/from_json() methods for history serialization
- Add history_snapshot field to ConversationRecord
- Add save_with_history() to SessionRecorder
- Update session resume to restore from history_snapshot
- Fallback to legacy message loading for old sessions
- Add 2 tests for history serialization

Sessions now preserve full context including compacted summaries.

Co-Authored-By: Claude <noreply@anthropic.com>
Alex Holmberg and others added 8 commits January 15, 2026 12:29
Add 24 new tests for previously untested UI files:
- input.rs: 15 tests covering UTF-8 handling, cursor movement,
  multi-line navigation, backspace, delete word left
- autocomplete.rs: 9 tests covering @ trigger detection,
  file filter extraction, mode transitions

Co-Authored-By: Claude <noreply@anthropic.com>
Add 14 new tests to previously untested tool files:
- file_ops.rs: 7 tests for binary detection, file reading, directory listing
- analyze.rs: 3 tests for file counting, nonexistent path handling
- plan.rs: 2 tests for plan listing with empty and populated directories
- security.rs: 2 tests for security scanning

Total test count increases from 139 to 153.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@Alex793x Alex793x merged commit 2e184a6 into main Jan 15, 2026
4 checks passed
@Alex793x Alex793x mentioned this pull request Jan 15, 2026
Alex793x added a commit that referenced this pull request Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant