pub fn resolve_mode(
task_param: Option<&str>,
project_root: Option<&Path>,
) -> HarnessModeExpand description
Resolve the effective HarnessMode for one task.run call, per §5.9’s
three-tier precedence (highest to lowest): MODE_ENV_VAR > task_param
(the task.run request’s own mode field) > .claude/settings.json’s
code_harness.mode > HarnessMode::default.
Why: the single place this precedence is implemented, so task::protocol
never has to re-derive it.
What: checks each tier in order; a tier whose value is absent OR fails
to parse (see HarnessMode::parse_lenient’s docs — this is the
“clear error or fall back to default” choice this ticket asks to be
made explicit: an invalid value at ANY tier is treated exactly like an
absent one, falling through to the next tier, rather than hard-erroring
the whole call) is skipped.
project_root is Option because a projectless workstream has no project
and therefore no .claude/settings.json tier to consult — that tier is
simply skipped, exactly as an absent file already was. Projectless is a
supported state, never an error, so it still resolves a mode (env var, then
the request’s own mode, then the default).
Test: mode::tests::env_var_wins_over_everything,
mode::tests::task_param_wins_over_settings_json,
mode::tests::settings_json_wins_over_default,
mode::tests::default_when_nothing_set,
mode::tests::invalid_env_var_falls_through_to_next_tier,
mode::tests::projectless_skips_settings_tier_and_still_resolves.