Skip to content

feat(engine): add per-engine model and engine env vars#538

Open
davidslater wants to merge 1 commit into
mainfrom
ace/01KXGX31QS01VV2T87VAVZJ10M
Open

feat(engine): add per-engine model and engine env vars#538
davidslater wants to merge 1 commit into
mainfrom
ace/01KXGX31QS01VV2T87VAVZJ10M

Conversation

@davidslater

Copy link
Copy Markdown
Collaborator

Created by GitHub Ace · View Session

Closes #382

Summary

Adds environment variable support for configuring the AI model used by each engine, without requiring the --model CLI flag. Also adds THREAT_DETECTION_ENGINE as an env-var default for --engine.

New env vars

Variable Purpose
THREAT_DETECTION_ENGINE Default engine when --engine is not specified (copilot, claude, codex)
THREAT_DETECTION_COPILOT_MODEL Default model for the Copilot engine
THREAT_DETECTION_CLAUDE_MODEL Default model for the Claude engine
THREAT_DETECTION_CODEX_MODEL Default model for the Codex engine

Precedence

  • --engine flag overrides THREAT_DETECTION_ENGINE
  • --model flag overrides the per-engine model env var
  • Per-engine model env vars are engine-scoped: THREAT_DETECTION_COPILOT_MODEL is 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 when model is empty.
  • cmd/threat-detect/main.go: --engine flag defaults to THREAT_DETECTION_ENGINE (consistent with how THREAT_DETECTION_RETRIES works for --retries). Added envString helper. 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.
  • Tests: Added TestNew_ModelEnvVarFallback, TestNew_FlagModelOverridesEnvVar, TestNew_EnvVarNotLeakedToOtherEngine, and TestRunUsesEngineEnvVar.

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>
Copilot AI review requested due to automatic review settings July 14, 2026 21:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds environment-based engine and model defaults to the threat-detection CLI.

Changes:

  • Adds THREAT_DETECTION_ENGINE and 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)
}
Comment thread pkg/engine/engine_test.go

func TestNew_EnvVarNotLeakedToOtherEngine(t *testing.T) {
// THREAT_DETECTION_COPILOT_MODEL must not affect the claude engine.
t.Setenv(EnvCopilotModel, "copilot-specific-model")
Comment thread cmd/threat-detect/main.go

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)")
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.

Model configuration

2 participants