From f7c6f560c048a075cc2e4bcbc09ca2650efc4957 Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Thu, 9 Jul 2026 21:36:14 -0700 Subject: [PATCH] FN-7753: route grok-cli execution through the grok CLI when no Fusion-visible GROK_API_KEY resolves Route grok-cli model selections through the grok CLI runtime when no Fusion-visible GROK_API_KEY is available. - Add read-only isGrokApiKeyFusionVisible() in packages/core/src/grok-provider.ts, refactored to share user-settings-file reading with hydrateGrokApiKeyFromUserSettings without mutating process.env or logging key material. - In packages/engine/src/agent-session-helpers.ts, auto-derive the existing "grok" runtimeHint when defaultProvider is grok-cli, no key is Fusion-visible, and the grok plugin runtime is registered; explicit runtime hints and mock/test-mode routing remain unchanged, and the provider-qualified model prefix is stripped before handoff. - Normalize provider-qualified model ids (grok-cli/, grok/) in the grok-runtime plugin's runtime-adapter and CLI stream spawn so the concrete model reaches `grok --model`, with the historical grok/default fallback preserved for the no-model path. - Update docs (grok-cli-contract.md, settings-reference.md, plugin README) and add/extend tests covering the new fallback behavior, model normalization, and CLI streaming. - Add changeset fn-7753-grok-cli-no-key-fallback.md (patch, fix). Files changed: .changeset/fn-7753-grok-cli-no-key-fallback.md | 7 ++ docs/grok-cli-contract.md | 83 ++++++++++------ docs/settings-reference.md | 6 +- .../__tests__/grok-provider-user-settings.test.ts | 46 +++++++++ packages/core/src/grok-provider.ts | 39 +++++++- packages/core/src/index.gate.ts | 1 + packages/core/src/index.ts | 1 + .../src/__tests__/grok-runtime-routing.test.ts | 107 +++++++++++++++++++-- packages/engine/src/agent-session-helpers.ts | 52 +++++++++- plugins/fusion-plugin-grok-runtime/README.md | 46 +++++---- .../src/__tests__/cli-stream.test.ts | 70 ++++++++++++++ .../src/__tests__/runtime-adapter.test.ts | 28 ++++++ .../fusion-plugin-grok-runtime/src/cli-stream.ts | 6 ++ .../src/runtime-adapter.ts | 24 ++++- 14 files changed, 443 insertions(+), 73 deletions(-) Fusion-Task-Id: FN-7753 Fusion-Task-Lineage: 30ef7265-1ba9-47fd-8c4e-87b02f6a1d78 Co-authored-by: Fusion (runfusion.ai) --- .../fn-7753-grok-cli-no-key-fallback.md | 7 ++ docs/grok-cli-contract.md | 81 ++++++++----- docs/settings-reference.md | 6 +- .../grok-provider-user-settings.test.ts | 46 ++++++++ packages/core/src/grok-provider.ts | 39 ++++++- packages/core/src/index.gate.ts | 1 + packages/core/src/index.ts | 1 + .../__tests__/grok-runtime-routing.test.ts | 107 ++++++++++++++++-- packages/engine/src/agent-session-helpers.ts | 52 ++++++++- plugins/fusion-plugin-grok-runtime/README.md | 44 ++++--- .../src/__tests__/cli-stream.test.ts | 70 ++++++++++++ .../src/__tests__/runtime-adapter.test.ts | 28 +++++ .../src/cli-stream.ts | 6 + .../src/runtime-adapter.ts | 24 +++- 14 files changed, 441 insertions(+), 71 deletions(-) create mode 100644 .changeset/fn-7753-grok-cli-no-key-fallback.md create mode 100644 plugins/fusion-plugin-grok-runtime/src/__tests__/cli-stream.test.ts diff --git a/.changeset/fn-7753-grok-cli-no-key-fallback.md b/.changeset/fn-7753-grok-cli-no-key-fallback.md new file mode 100644 index 0000000000..2609be6e77 --- /dev/null +++ b/.changeset/fn-7753-grok-cli-no-key-fallback.md @@ -0,0 +1,7 @@ +--- +"@runfusion/fusion": patch +--- + +summary: Grok CLI models now run via the grok CLI when no Fusion-visible API key is set. +category: fix +dev: createResolvedAgentSession (packages/engine/src/agent-session-helpers.ts) auto-derives runtimeHint "grok" when defaultProvider is grok-cli, no GROK_API_KEY is Fusion-visible (new read-only isGrokApiKeyFusionVisible in packages/core/src/grok-provider.ts), and the Grok runtime is registered; the selected model is passed to the CLI via a new --model option on spawnGrokStream. Explicit runtime hints and the key-visible direct-endpoint default are unchanged. Closes the deferred FN-7722/FN-7725 follow-up. diff --git a/docs/grok-cli-contract.md b/docs/grok-cli-contract.md index 7b5e2faa30..fff3a188a7 100644 --- a/docs/grok-cli-contract.md +++ b/docs/grok-cli-contract.md @@ -134,7 +134,7 @@ Notes: `GrokCliProviderCard.tsx`) is out of scope for this task and is not modified here. -## Wiring (resolved — FN-7725) +## Wiring (resolved — FN-7725, extended by FN-7753)