Skip to content

Conversation

StanAngeloff
Copy link
Collaborator

No description provided.

@StanAngeloff StanAngeloff marked this pull request as draft June 9, 2025 14:16
@StanAngeloff StanAngeloff self-assigned this Jun 9, 2025
StanAngeloff and others added 30 commits September 8, 2025 16:33
- Add state module require at top of init.lua
- Call state.set_config() in M.setup after merging user options
- Update initialize_provider to use state.set_provider()
- Replace all local config, provider, and session_usage variable usage with state module calls
- Fix variable shadowing issues in send_to_provider, cancel_request, and start_loading_spinner functions
- Update public API functions to delegate to state module
- Establish centralized state management through controlled getter/setter functions

This decouples state management from init.lua and makes state.lua the single source of truth for plugin configuration, provider instance, and session usage data.

Amp-Thread-ID: https://ampcode.com/threads/T-2889fdef-9b8e-409c-8fd8-75fc761ceb26
Co-authored-by: Amp <[email protected]>
- Create core/validation.lua for centralized provider/model validation
- Create core/config_manager.lua for parameter merging and config management
- Refactor initialize_provider() from ~150 lines to ~30 lines
- Simplify M.switch() to use centralized validation and config flow
- Update get_current_reasoning_setting() for new flattened parameter structure
- Fix test to use o3 model instead of o1-mini for reasoning functionality
- Remove unused models import from init.lua

BREAKING CHANGE: None - all functionality preserved and tests passing

Amp-Thread-ID: https://ampcode.com/threads/T-dfc50efd-4e96-490d-aa72-2a87f7209d11
Co-authored-by: Amp <[email protected]>
- Remove unused plugin_config import in validation.lua
- Fix reasoning_value redefinition in validation.lua
- Remove unused session_usage variable in init.lua
- Fix config variable shadowing in initialize_provider function
- Remove unused bufnr variable in set_syntax function
- Fix state variable shadowing in cleanup_spinner function
- Remove unused provider_name capture in pricing.lua
- Remove unused log import in textobject.lua
- Fix token variable redefinition in vertex.lua provider
- Remove unnecessary _get_config() wrapper function
- Move get_current_reasoning_setting() to lualine component
- Update tests to access state module directly

All tests pass after refactoring. Code is cleaner with better variable
naming and no shadowing/redefinition issues.

Amp-Thread-ID: https://ampcode.com/threads/T-812737bc-9d61-4ca3-bb81-6f409e160c38
Co-authored-by: Amp <[email protected]>
…nction

- Return config table directly from config.lua instead of wrapping in M.defaults
- Move is_general_parameter function to config_manager module
- Update init.lua to use plugin_config directly instead of plugin_config.defaults
- Add public interface for is_general_parameter in config_manager

BREAKING CHANGE: config.lua now exports config directly instead of M.defaults structure

Amp-Thread-ID: https://ampcode.com/threads/T-19440082-dda4-42f1-8200-82f12c61f22b
Co-authored-by: Amp <[email protected]>
…e.lua

- Move provider initialization and switching logic from init.lua to core.lua
- Extract send_to_provider and cancel_request functions to core.lua
- Transform init.lua into pure setup/orchestration layer
- Keep backward compatibility with wrapper functions in init.lua
- Update command definitions to use new core module functions

BREAKING CHANGE: Internal API structure changed with core logic extraction

Amp-Thread-ID: https://ampcode.com/threads/T-f094b0db-3637-487b-9018-26ba0b22e8e6
Co-authored-by: Amp <[email protected]>
- Create ui.lua module with all visual presentation functions
  - Move add_rulers, start_loading_spinner, cleanup_spinner from core.lua
  - Move fold_last_thinking_block, place_signs, setup_folding from init.lua
  - Add ui.setup() function for UI-related autocmds
  - UI module is now self-contained and manages own event listeners

- Enhance buffers.lua as complete buffer operations module
  - Move parse_message and parse_buffer from init.lua to buffers.lua
  - Move auto_write_buffer from core.lua to buffers.lua
  - Move buffer_cmd from core.lua to buffers.lua
  - Buffer parsing now properly calls ui.place_signs during parsing

- Update core.lua to delegate all UI operations to ui module
  - Replace local UI functions with ui module calls
  - Remove intermingled UI code from request logic
  - Core now focuses purely on provider communication and orchestration

- Update init.lua to use new module structure
  - Call ui.setup() for UI initialization
  - Add wrapper functions for backward compatibility
  - Update all buffer_cmd references to use buffers module

BREAKING CHANGE: UI functions moved to dedicated ui.lua module, buffer operations consolidated in buffers.lua

Amp-Thread-ID: https://ampcode.com/threads/T-e7954986-05d0-4cda-b998-59a8dd37155a
Co-authored-by: Amp <[email protected]>
- Create navigation.lua with find_next_message and find_prev_message functions
- Create commands.lua with all vim.api.nvim_create_user_command calls
- Create keymaps.lua with FileType autocommand for buffer-local keymaps
- Update init.lua to orchestrate module initialization in proper order
- Remove ~280 lines of code from init.lua, improving maintainability
- All user-facing interactions now centralized and easily configurable

This completes Phase 4 of the refactoring: consolidating commands,
keymaps, and navigation into their own dedicated modules while
transforming init.lua into a clean orchestrator.

Amp-Thread-ID: https://ampcode.com/threads/T-ea37776b-c70d-404e-b6de-7859878512eb
Co-authored-by: Amp <[email protected]>
…ted module

- Create new lua/flemma/highlight.lua module for all visual theming
- Move syntax highlighting logic from init.lua to highlight.apply_syntax()
- Move signs setup logic from init.lua to highlight module
- Eliminate code duplication of set_highlight helper function
- Consolidate all highlight groups, syntax rules, and signs in one module
- Improve separation of concerns by isolating visual/theming functionality

All tests pass after refactoring.

Amp-Thread-ID: https://ampcode.com/threads/T-1067f2a2-f35d-44f2-97d6-2562d721738f
Co-authored-by: Amp <[email protected]>
BREAKING CHANGE: Import functionality is now provider-specific

- Add try_import_from_buffer virtual method to base provider
- Move all import logic from generic import.lua to claude provider
- Rename import helper functions with import_ prefix for clarity
- Update FlemmaImport command to use provider-specific method
- Add comprehensive tests for claude import functionality
- Remove redundant lua/flemma/import.lua file

The import feature only applies to Claude Workbench format, so it belongs
in the claude provider rather than being a generic feature. Other providers
will return nil from try_import_from_buffer indicating no support.

Amp-Thread-ID: https://ampcode.com/threads/T-c606c49d-64f7-46e2-af2b-881424592219
Co-authored-by: Amp <[email protected]>
- Add Amp alongside Aider in development recommendations with links
- Update AI development approach to reflect use of both Aider and Amp
- Change preference from Aider to Amp in contributor guidelines
- Add flemma-amp command to development workflow
- Correct plugin defaults to match actual config.lua values
- Update prerequisites to use OPENAI_API_KEY for flemma-dev command

Amp-Thread-ID: https://ampcode.com/threads/T-e78f1b49-e2d9-40b1-8d45-fa3a2b6d0e79
Co-authored-by: Amp <[email protected]>
- Change default from claude-sonnet-4 to claude-sonnet-4-0
- Remove invalid claude-sonnet-4 and claude-opus-4 models
- Remove deprecated models: claude-3-5-sonnet variants, claude-3-opus-20240229, claude-3-sonnet-20240229, claude-2.x, claude-instant-1.2
- Fix duplicate claude-3-5-haiku-latest entry
- Keep only valid models per Anthropic documentation

Amp-Thread-ID: https://ampcode.com/threads/T-d42c57a7-f84d-4985-8b14-fe884d59d4fa
Co-authored-by: Amp <[email protected]>
- Create dedicated client.lua module for HTTP transport logic
- Move fixture registration from provider to client with domain-based matching
- Replace unwieldy function parameters with table-based API and EmmyLua annotations
- Remove redundant API key validation (providers handle this internally)
- Eliminate core.lua dependency on base provider
- Update tests to use domain patterns (api.openai.com, api.anthropic.com)

BREAKING CHANGE: Fixture registration now uses domain patterns instead of model names

Amp-Thread-ID: https://ampcode.com/threads/T-ad481336-0cdd-44a4-8a5c-f588bc4248c7
Co-authored-by: Amp <[email protected]>
…umentation

- Remove duplicate callbacks: on_data, on_stderr, on_done
- Rename callbacks for clarity: on_complete → on_request_complete, on_message_complete → on_response_complete
- Rename function parameters for consistency: on_stdout_fn → process_response_line_fn, on_exit_fn → finalize_response_fn
- Move stderr logging directly to client, eliminate callback indirection
- Add comprehensive EmmyLua documentation for provider callbacks and types
- Simplify completion flow with clear separation of concerns between request and response completion

BREAKING CHANGE: Callback names have changed - external code using these callbacks will need updates

Amp-Thread-ID: https://ampcode.com/threads/T-faf2fd13-eff1-4cb5-ab7d-f17c430893f8
Co-authored-by: Amp <[email protected]>
- Add API key safety check before calling get_request_headers() to prevent
  nil concatenation errors when no API key is available
- Move fixture detection earlier in the flow to bypass API key validation
  when using test fixtures
- Reorder headers and endpoint variable declaration before create_request_body
  to follow logical HTTP request construction order
- Improve error message to include provider name and follow quoting conventions
- Make client.find_fixture_for_endpoint() public to enable early fixture detection

Fixes issue where missing API key would cause Lua errors instead of
graceful error messages, particularly affecting Claude provider at line 205.

Amp-Thread-ID: https://ampcode.com/threads/T-8e52a07a-c5df-4fdd-905e-956e1e5d562a
Co-authored-by: Amp <[email protected]>
- Create lua/flemma/content_parser.lua with M.parse function
- Remove parse_message_content_chunks from provider base class
- Update claude, openai, and vertex providers to use content_parser.parse
- Update tests to use new content_parser API

This separates the generic @file reference parsing logic from the provider
base class, making it a reusable utility module.

Amp-Thread-ID: https://ampcode.com/threads/T-6644c6ce-692c-4154-8120-ca5eaf982a98
Co-authored-by: Amp <[email protected]>
- Remove wrapper methods: cancel_request, cleanup_spinner, send_to_provider, parse_buffer, _get_last_request_body
- Update all call sites to use direct module imports instead of passthrough functions
- Improve code maintainability by eliminating unnecessary indirection
- All tests continue to pass

Amp-Thread-ID: https://ampcode.com/threads/T-356faf6a-2af6-444e-8018-155476ee8d6d
Co-authored-by: Amp <[email protected]>
- Create lua/flemma/usage.lua with format_notification function
- Move format_usage logic from core.lua to usage.lua for better separation
- Keep session_usage state management in state.lua where it belongs
- Update core.lua to use usage.format_notification for cost display
- Add comprehensive test suite with 8 test cases covering:
  * Request and session usage formatting
  * Thoughts tokens handling
  * Cost calculation scenarios
  * Edge cases and zero usage

BREAKING CHANGE: None - all functionality preserved

Amp-Thread-ID: https://ampcode.com/threads/T-6589b8f9-f360-4d7c-b4ea-3711f1d2d38f
Co-authored-by: Amp <[email protected]>
- Move response accumulation logic from individual providers to base class
- Add _new_response_buffer(), _buffer_response_line(), _mark_response_successful(), _check_buffered_response() methods to base
- Add extract_json_response_error() override point with flexible error pattern matching
- Update OpenAI provider to use base class methods, removing ~50 lines of duplicated code
- Update Vertex provider to use base class methods with accumulated_thoughts extension, removing ~80 lines
- Update Claude provider to gain robust error handling using base class methods
- Implement proper inheritance with base.reset() calls in derived classes
- Use consistent protected method naming with underscore prefixes for internal APIs

BREAKING CHANGE: Providers must now call base.reset(self) instead of implementing custom reset logic

Amp-Thread-ID: https://ampcode.com/threads/T-93b7ff27-e294-4934-8179-72352acbb3f3
Co-authored-by: Amp <[email protected]>
Add templating_spec.lua to test Phase 5.1 requirements:
- Verify frontmatter variables are accessible in message expressions
- Test data flow between frontmatter.execute and eval.eval_expression
- Mock provider send_request to capture evaluated content
- Validate template evaluation with variables and functions

Amp-Thread-ID: https://ampcode.com/threads/T-d97f30c3-88c8-4b01-a9a1-2081fdd533f0
Co-authored-by: Amp <[email protected]>
- Add fixture files for testing nested include resolution
- Test relative path resolution with multi-level includes
- Test multiple levels of nested includes with dynamic temp files
- Test circular include detection and prevention
- Verify include stack tracking prevents infinite recursion

Closes Task 5.2 from Phase 5: Advanced Templating and File Inclusion

Amp-Thread-ID: https://ampcode.com/threads/T-118fb41a-adff-4044-b6b8-8733ab96a3e3
Co-authored-by: Amp <[email protected]>
- Add extensive test coverage for file path parsing and URL decoding
- Add MIME type detection tests with mocking and error handling
- Add provider-specific file formatting tests for Claude, OpenAI, and Vertex AI
- Test PNG, PDF, and text file handling across all three providers
- Verify correct API payload formats for each provider's specifications
- Remove redundant URL-encoded filename test from provider_base_spec.lua

fix: preserve trailing punctuation in content parser

- Fix bug where punctuation after @file references was being lost
- Update content parser to emit stripped punctuation as separate text chunks
- Ensure file references like '@file.pdf, and more text' correctly parse both parts
- Update raw_filename to exclude trailing punctuation for consistency

The test suite now includes:
- 8 MIME type detection tests covering success, failure, and caching scenarios
- 7 file reference parsing tests for URL decoding and punctuation handling
- 9 provider-specific file formatting tests ensuring API compliance
- All tests use proper mocking for isolation and reliability

Amp-Thread-ID: https://ampcode.com/threads/T-e063d499-ebba-4135-9ca1-a65fb4ec1069
Co-authored-by: Amp <[email protected]>
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