diff --git a/CHANGELOG.md b/CHANGELOG.md index 6babe5a..7ae4a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Add `--agent-model` and `DX_AGENT_MODEL` support. When set, the CLI sends the model name as the `X-DX-Agent-Model` header alongside existing agent provenance headers. + ### Fixed - `dx -v` now prints the CLI version, matching the documented lowercase version flag. Version checks are also skipped for help/version output and global-option-only invocations, preventing update prompts from interfering with those commands. diff --git a/src/cli.ts b/src/cli.ts index dc611dc..91f3340 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -60,6 +60,12 @@ function createProgram(): Command { .addOption( new Option("--agent ", "Agent name to send as an HTTP header"), ) + .addOption( + new Option( + "--agent-model ", + "Agent model name to send as an HTTP header", + ), + ) .addOption( new Option( "--agent-session-id ", diff --git a/src/commandHelpers.ts b/src/commandHelpers.ts index 1a02289..5246e29 100644 --- a/src/commandHelpers.ts +++ b/src/commandHelpers.ts @@ -9,6 +9,7 @@ export function getContext(command: Command): CliContext { return { json: Boolean(root.json), agent: root.agent || process.env.DX_AGENT_NAME, + agentModel: root.agentModel || process.env.DX_AGENT_MODEL, agentSessionId: root.agentSessionId || process.env.DX_AGENT_SESSION_ID, }; } diff --git a/src/commands/catalog/entities.test.ts b/src/commands/catalog/entities.test.ts index 8a6f98b..499df53 100644 --- a/src/commands/catalog/entities.test.ts +++ b/src/commands/catalog/entities.test.ts @@ -1059,6 +1059,7 @@ describe("catalog entities commands", () => { it("sends agent provenance from environment variables", async () => { process.env.DX_API_BASE_URL = "https://api.example.com"; process.env.DX_AGENT_NAME = "codex"; + process.env.DX_AGENT_MODEL = "gpt-5"; process.env.DX_AGENT_SESSION_ID = "session-123"; getToken.mockReturnValue("token-123"); @@ -1099,6 +1100,7 @@ describe("catalog entities commands", () => { const headers = (vi.mocked(fetch).mock.calls[0]?.[1] as RequestInit) .headers as Headers; expect(headers.get("X-DX-Agent-Name")).toBe("codex"); + expect(headers.get("X-DX-Agent-Model")).toBe("gpt-5"); expect(headers.get("X-DX-Agent-Session-Id")).toBe("session-123"); }); diff --git a/src/commands/studio/query.ts b/src/commands/studio/query.ts index 755d730..7fdc3dc 100644 --- a/src/commands/studio/query.ts +++ b/src/commands/studio/query.ts @@ -313,6 +313,10 @@ function buildHeaders(runtime: Runtime, accept: string): Headers { headers.set("X-DX-Agent-Name", runtime.context.agent); } + if (runtime.context.agentModel) { + headers.set("X-DX-Agent-Model", runtime.context.agentModel); + } + if (runtime.context.agentSessionId) { headers.set("X-DX-Agent-Session-Id", runtime.context.agentSessionId); } diff --git a/src/http.ts b/src/http.ts index 50737c0..f92a521 100644 --- a/src/http.ts +++ b/src/http.ts @@ -29,6 +29,10 @@ export async function request>( headers.set("X-DX-Agent-Name", runtime.context.agent); } + if (runtime.context.agentModel) { + headers.set("X-DX-Agent-Model", runtime.context.agentModel); + } + if (runtime.context.agentSessionId) { headers.set("X-DX-Agent-Session-Id", runtime.context.agentSessionId); } diff --git a/src/types.ts b/src/types.ts index 378c5e1..f66ac8e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,6 +12,7 @@ export interface Runtime { export interface CliContext { json: boolean; agent?: string; + agentModel?: string; agentSessionId?: string; } diff --git a/src/versionCheck.ts b/src/versionCheck.ts index b158d38..451cbdf 100644 --- a/src/versionCheck.ts +++ b/src/versionCheck.ts @@ -129,6 +129,7 @@ export async function checkForNewVersion( const context = { json: argv.includes("--json"), agent: undefined, + agentModel: undefined, agentSessionId: undefined, }; const runtime = await buildRuntimeSafe(context);