feat(engine): add per-engine model and engine env vars#538
Open
davidslater wants to merge 1 commit into
Open
Conversation
Add THREAT_DETECTION_COPILOT_MODEL, THREAT_DETECTION_CLAUDE_MODEL, and THREAT_DETECTION_CODEX_MODEL env vars to configure the default model for each engine without requiring the --model flag. The --model flag always takes precedence; per-engine env vars are engine-scoped (the copilot env var is only consulted when the copilot engine is selected, etc.). Add THREAT_DETECTION_ENGINE env var as a default for --engine, consistent with how THREAT_DETECTION_RETRIES works for --retries. Update spec (TD-22) and README to document the new env vars. Closes #382 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: David Slater <12449447+davidslater@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds environment-based engine and model defaults to the threat-detection CLI.
Changes:
- Adds
THREAT_DETECTION_ENGINEand per-engine model variables. - Preserves command-line flag precedence.
- Updates specifications, documentation, and tests.
Show a summary per file
| File | Description |
|---|---|
README.md |
Documents environment defaults. |
cmd/threat-detect/main.go |
Reads the engine default from the environment. |
cmd/threat-detect/main_test.go |
Tests engine environment selection. |
pkg/engine/engine.go |
Applies per-engine model environment defaults. |
pkg/engine/engine_test.go |
Tests model fallback, precedence, and scoping. |
specs/threat-detection-spec.md |
Defines the new environment-variable contract. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 3
- Review effort level: Medium
Comment on lines
+207
to
+215
| "THREAT_DETECTION_ENGINE": "copilot", | ||
| }) | ||
|
|
||
| if code != exitSafe { | ||
| t.Fatalf("run() exit code = %d, want %d", code, exitSafe) | ||
| } | ||
| if _, err := os.Stat(copilotMarker); err != nil { | ||
| t.Fatalf("expected copilot to run (selected via THREAT_DETECTION_ENGINE): %v", err) | ||
| } |
|
|
||
| func TestNew_EnvVarNotLeakedToOtherEngine(t *testing.T) { | ||
| // THREAT_DETECTION_COPILOT_MODEL must not affect the claude engine. | ||
| t.Setenv(EnvCopilotModel, "copilot-specific-model") |
|
|
||
| flag.StringVar(&engineID, "engine", "", "AI engine to use (copilot, claude, codex)") | ||
| flag.StringVar(&model, "model", "", "Model to use for detection") | ||
| flag.StringVar(&engineID, "engine", envString("THREAT_DETECTION_ENGINE", ""), "AI engine to use (copilot, claude, codex) (env: THREAT_DETECTION_ENGINE)") |
This was referenced Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #382
Summary
Adds environment variable support for configuring the AI model used by each engine, without requiring the
--modelCLI flag. Also addsTHREAT_DETECTION_ENGINEas an env-var default for--engine.New env vars
THREAT_DETECTION_ENGINE--engineis not specified (copilot,claude,codex)THREAT_DETECTION_COPILOT_MODELTHREAT_DETECTION_CLAUDE_MODELTHREAT_DETECTION_CODEX_MODELPrecedence
--engineflag overridesTHREAT_DETECTION_ENGINE--modelflag overrides the per-engine model env varTHREAT_DETECTION_COPILOT_MODELis only consulted when the Copilot engine is selected, etc.Changes
pkg/engine/engine.go: Added exported constants for env var names.New()now falls back to the per-engine model env var whenmodelis empty.cmd/threat-detect/main.go:--engineflag defaults toTHREAT_DETECTION_ENGINE(consistent with howTHREAT_DETECTION_RETRIESworks for--retries). AddedenvStringhelper. Updated flag help text.specs/threat-detection-spec.md: Updated TD-22 to document all new env vars.README.md: Updated flags section to reference new env vars.TestNew_ModelEnvVarFallback,TestNew_FlagModelOverridesEnvVar,TestNew_EnvVarNotLeakedToOtherEngine, andTestRunUsesEngineEnvVar.