Skip to content

refactor(copilot): PathResolver::new takes a required home argument - #209

Open
ecalifornica wants to merge 1 commit into
robert/config-claudefrom
robert/config-copilot
Open

refactor(copilot): PathResolver::new takes a required home argument#209
ecalifornica wants to merge 1 commit into
robert/config-claudefrom
robert/config-copilot

Conversation

@ecalifornica

@ecalifornica ecalifornica commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Part of #185: the crate reads no environment variable, Config owns every read, and the caller supplies what the crate used to resolve itself.

Judgment calls:

  • read_lines(path) and read_session_dir(dir) stay lenient. Context: an events file is a Copilot CLI session log (~/.copilot/session-state/<id>/events.jsonl) with a reverse-engineered schema, and the preview reader is deliberately tolerant of shape variations. Strict reading reports an unparseable line as an error and is an explicit opt-in via with_strict(bool), read_lines_with, or read_session_dir_with. The flag is in this PR because $COPILOT_EVENTS_STRICT selects it, and this refactor moves every environment read out of the crate.
  • Strict is presence-based: $COPILOT_EVENTS_STRICT set, whatever its value. This matches the deleted std::env::var(...).is_ok() check exactly. Config stores the raw Option<String>; providers::copilot_strict owns the presence-is-the-signal interpretation.
  • $COPILOT_HOME moves to Config with its meaning intact: copilot_resolver injects it through with_copilot_dir, which wins against the home-derived default.
  • Behavior change: with $COPILOT_HOME set but no home directory in Config, copilot_resolver returns None and the CLI reports the missing home. $COPILOT_HOME replaces the data root, not the home, so it cannot satisfy new(home). The environment is rare and the error names the fix. Both variables keep their behavior whenever a home directory exists.
  • The reverse projector and the tolerant reader are untouched. The PR changes only where the resolver's inputs come from.

@ecalifornica ecalifornica changed the title robert/config copilot refactor(copilot): PathResolver::new takes a required home argument Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

🔍 Preview deployed: https://02f6bbff.toolpath.pages.dev

@ecalifornica
ecalifornica force-pushed the robert/config-copilot branch from 60769e4 to 66796b1 Compare August 14, 2026 19:49
Comment on lines +72 to +77
let resolver = toolpath_copilot::PathResolver::new(home);
match &config.copilot_home {
Some(dir) => resolver.with_copilot_dir(dir),
None => resolver,
}
})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Previous behavior: if neither $HOME nor $USERPROFILE are set $COPILOT_HOME replaces the root. The new resolver returns None. Is this the desired behavior?

@ecalifornica
ecalifornica marked this pull request as ready for review August 17, 2026 18:00
@ecalifornica
ecalifornica requested a review from akesling August 17, 2026 18:00
@ecalifornica ecalifornica assigned akesling and unassigned akesling Aug 17, 2026
…185)

toolpath-copilot reads no environment variable. The caller supplies the
home directory and the strict-parsing flag. The crate keeps the layout
below the home directory: Copilot data is in <home>/.copilot.

PathResolver::new(home) takes the home directory as a required
argument. CopilotConvo::new(home) and ConvoIO::new(home) take the same
argument. with_copilot_dir stays as the full override, and it wins
against the home-derived default.

The home directory is always present, so the 6 pure path accessors
return a path instead of a Result. The CHANGELOG lists them.
list_session_dirs, find_session_dir, events_file, and workspace_file
keep their Result. Their error is a failed directory read or an
unresolved session id, not a missing home.

Strict events parsing is a parameter. EventReader::read_lines_with and
EventReader::read_session_dir_with take the flag directly.
CopilotConvo::with_strict and ConvoIO::with_strict store it, default
false, and pass it to the reader.

path-cli: providers::copilot_resolver returns Option<PathResolver>.
require_copilot_resolver turns None into an error for the 5 commands
that target Copilot. Config reads $COPILOT_EVENTS_STRICT, and
providers::copilot_strict turns its presence into the flag every
CopilotConvo receives.

toolpath-copilot 0.2.0: breaking.
@ecalifornica
ecalifornica force-pushed the robert/config-copilot branch from 66796b1 to 4d96f45 Compare August 18, 2026 20:09
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