Skip to content

refactor: unify path handling with SearchPath struct#125

Closed
alexec wants to merge 9 commits into
mainfrom
refactor/paths-to-searchpath-struct
Closed

refactor: unify path handling with SearchPath struct#125
alexec wants to merge 9 commits into
mainfrom
refactor/paths-to-searchpath-struct

Conversation

@alexec
Copy link
Copy Markdown
Contributor

@alexec alexec commented Nov 24, 2025

Summary

Refactors path handling to use a unified SearchPath struct instead of separate functions for local and remote paths.

Changes

  • Introduced SearchPath struct with BasePath, RulesSubPaths, TaskSubPaths, and DownloadedDir fields
  • Replaced AllTaskSearchPaths, AllRulePaths, DownloadedRulePaths, and DownloadedTaskSearchPaths functions with:
    • DefaultSearchPaths(baseDir, homeDir) - returns search paths for default local paths
    • PathSearchPaths(dir) - returns search paths for a given directory (used for both local and remote)
    • NewSearchPathWithDefaults(basePath) - creates a SearchPath with default subpaths
  • Replaced WithRemotePaths option with:
    • WithSearchPaths([]SearchPath) - sets search paths directly
  • Unified local and remote path handling - both go through go-getter and are copied to temp directories
  • Downloaded paths now use default subpaths via NewSearchPathWithDefaults instead of empty subpaths
  • Added DownloadedDir field to SearchPath to track downloaded directories directly on the struct
  • Removed downloadedDirs []string field from Context struct (replaced by DownloadedDir on SearchPath)
  • Updated TaskSearchDirs() and RulesSearchDirs() to use DownloadedDir if set, otherwise BasePath
  • Removed unnecessary check for empty subpaths (condition never occurs)
  • Removed unused homeDir parameter from findTaskFile and findExecuteRuleFiles functions
  • Removed isRemoteURL guard - all paths go through go-getter which handles both local and remote
  • Updated all tests to use the new API
  • Updated documentation

Benefits

  • More flexible and extensible API
  • Cleaner separation of concerns
  • Unified handling of local and remote paths
  • Explicit opt-in for default local paths via WithSearchPaths(DefaultSearchPaths(...))
  • Consistent default subpaths for all paths
  • Simplified function signatures by removing redundant parameters
  • Better encapsulation - downloaded directory tracking is now part of SearchPath rather than separate state

- Replace separate functions (AllTaskSearchPaths, AllRulePaths, etc.) with unified SearchPath struct
- Add SearchPath struct with BasePath, RulesSubPaths, and TaskSubPaths fields
- Replace WithRemotePaths with WithSearchPaths and WithPath options
- Treat local and remote paths uniformly via go-getter
- Update all tests to use new SearchPath API
- Update documentation
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the path handling system to use a unified SearchPath struct, replacing separate functions for managing local and remote paths. The refactoring introduces a cleaner, more flexible API where path searching is explicitly configured through options rather than being automatically included.

Key changes:

  • Introduced SearchPath struct to unify path representation with BasePath, RulesSubPaths, and TaskSubPaths
  • Replaced path helper functions with DefaultSearchPaths(baseDir, homeDir) and PathSearchPaths(dir)
  • Changed CLI flag from -d to -P and replaced WithRemotePaths() with WithSearchPaths() and WithPath() options
  • Unified local and remote path handling through go-getter for consistent behavior

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/codingcontext/paths.go Introduces SearchPath struct and replaces individual path functions with unified DefaultSearchPaths() and PathSearchPaths() functions
pkg/codingcontext/context.go Updates Context struct with searchPaths and paths fields; adds WithSearchPaths() and WithPath() options; updates findTaskFile() and findExecuteRuleFiles() to use new search path structure
pkg/codingcontext/remote.go Renames downloadRemoteDirectory() to downloadPath() to reflect unified handling of both local and remote paths
pkg/codingcontext/context_test.go Adds getTestSearchPaths() helper and updates all tests to use new API with explicit searchPaths configuration
pkg/codingcontext/README.md Documents new SearchPath struct, DefaultSearchPaths(), PathSearchPaths(), WithSearchPaths(), and WithPath() functions
main.go Changes CLI flag from -d to -P, retrieves homeDir for default search paths, and constructs options using new WithSearchPaths() and WithPath() API
integration_test.go Updates integration test to use new -P flag instead of -d

Comment thread pkg/codingcontext/context.go Outdated
Comment thread main.go
Comment thread pkg/codingcontext/context.go Outdated
@alexec alexec closed this Nov 24, 2025
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.

2 participants