Skip to content

feat(config): add hooks.pre_run for pre-eval environment injection #1149

@christso

Description

@christso

Objective

Add a hooks.pre_run field to the AgentV config (both agentv.config.ts and .agentv/config.yaml) that executes a shell command before an eval run starts and injects its exported environment variables into the process.

Users who fetch secrets at runtime (e.g. from Azure Key Vault, AWS Secrets Manager) currently must wrap the agentv CLI in a project-level script. A generic hooks.pre_run config option lets any project inject environment variables from any source by running a shell command, without needing a wrapper.

Design latitude

  • New optional hooks block in config with pre_run field (a shell command string)
  • Command runs before the eval starts; stdout is captured and parsed
  • Parses export KEY="value" lines (shell-export format) OR KEY=value lines (dotenv format)
  • Injects parsed values into process.env — only for keys not already set (existing env wins)
  • Stderr forwarded to user's stderr for visibility
  • Non-zero exit code aborts the eval with a clear error message
  • YAML surface: hooks.pre_run (snake_case); TypeScript surface: hooks.preRun (camelCase)

Acceptance signals

  • hooks.pre_run: "bun scripts/load-secrets.ts" in .agentv/config.yaml runs the command before the eval and injects exported env vars
  • defineConfig({ hooks: { preRun: "bun scripts/load-secrets.ts" } }) in agentv.config.ts works equivalently
  • Variables already set in the environment are NOT overwritten
  • Non-zero exit from the hook command aborts the eval with an error message
  • Stderr from the hook command is forwarded to the user's stderr
  • Existing configs without hooks continue to work unchanged
  • Unit tests cover env parsing (both export KEY="value" and KEY=value formats)

Non-goals

  • Supporting multiple pre-run hooks (single command only; use a shell script for composition)
  • Post-run hooks (separate concern, separate issue)
  • Target-level hooks (this is project-level config only)

Example

# .agentv/config.yaml
hooks:
  pre_run: "bun scripts/load-secrets.ts"
// agentv.config.ts
export default defineConfig({
  hooks: {
    preRun: "bun scripts/load-secrets.ts",
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions