Compare commits
3 Commits
fix/provid
...
fix/skillt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e72fc94cb | ||
|
|
be7ec1b5fa | ||
|
|
cdfaea5ced |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,4 +10,3 @@ GEMINI.md
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
/.claude
|
/.claude
|
||||||
coverage/
|
coverage/
|
||||||
.worktrees/
|
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ import { usePromptsFromClaudeInChrome } from 'src/hooks/usePromptsFromClaudeInCh
|
|||||||
import { getTipToShowOnSpinner, recordShownTip } from 'src/services/tips/tipScheduler.js';
|
import { getTipToShowOnSpinner, recordShownTip } from 'src/services/tips/tipScheduler.js';
|
||||||
import type { Theme } from 'src/utils/theme.js';
|
import type { Theme } from 'src/utils/theme.js';
|
||||||
import { isPromptTypingSuppressionActive } from './replInputSuppression.js';
|
import { isPromptTypingSuppressionActive } from './replInputSuppression.js';
|
||||||
import { shouldStartStartupChecks } from './replStartupGates.js';
|
|
||||||
import { checkAndDisableBypassPermissionsIfNeeded, checkAndDisableAutoModeIfNeeded, useKickOffCheckAndDisableBypassPermissionsIfNeeded, useKickOffCheckAndDisableAutoModeIfNeeded } from 'src/utils/permissions/bypassPermissionsKillswitch.js';
|
import { checkAndDisableBypassPermissionsIfNeeded, checkAndDisableAutoModeIfNeeded, useKickOffCheckAndDisableBypassPermissionsIfNeeded, useKickOffCheckAndDisableAutoModeIfNeeded } from 'src/utils/permissions/bypassPermissionsKillswitch.js';
|
||||||
import { SandboxManager } from 'src/utils/sandbox/sandbox-adapter.js';
|
import { SandboxManager } from 'src/utils/sandbox/sandbox-adapter.js';
|
||||||
import { SANDBOX_NETWORK_ACCESS_TOOL_NAME } from 'src/cli/structuredIO.js';
|
import { SANDBOX_NETWORK_ACCESS_TOOL_NAME } from 'src/cli/structuredIO.js';
|
||||||
@@ -785,6 +784,19 @@ export function REPL({
|
|||||||
});
|
});
|
||||||
const tasksV2 = useTasksV2WithCollapseEffect();
|
const tasksV2 = useTasksV2WithCollapseEffect();
|
||||||
|
|
||||||
|
// Start background plugin installations
|
||||||
|
|
||||||
|
// SECURITY: This code is guaranteed to run ONLY after the "trust this folder" dialog
|
||||||
|
// has been confirmed by the user. The trust dialog is shown in cli.tsx (line ~387)
|
||||||
|
// before the REPL component is rendered. The dialog blocks execution until the user
|
||||||
|
// accepts, and only then is the REPL component mounted and this effect runs.
|
||||||
|
// This ensures that plugin installations from repository and user settings only
|
||||||
|
// happen after explicit user consent to trust the current working directory.
|
||||||
|
useEffect(() => {
|
||||||
|
if (isRemoteSession) return;
|
||||||
|
void performStartupChecks(setAppState);
|
||||||
|
}, [setAppState, isRemoteSession]);
|
||||||
|
|
||||||
// Allow Claude in Chrome MCP to send prompts through MCP notifications
|
// Allow Claude in Chrome MCP to send prompts through MCP notifications
|
||||||
// and sync permission mode changes to the Chrome extension
|
// and sync permission mode changes to the Chrome extension
|
||||||
usePromptsFromClaudeInChrome(isRemoteSession ? EMPTY_MCP_CLIENTS : mcpClients, toolPermissionContext.mode);
|
usePromptsFromClaudeInChrome(isRemoteSession ? EMPTY_MCP_CLIENTS : mcpClients, toolPermissionContext.mode);
|
||||||
@@ -1325,7 +1337,6 @@ export function REPL({
|
|||||||
const [inputValue, setInputValueRaw] = useState(() => consumeEarlyInput());
|
const [inputValue, setInputValueRaw] = useState(() => consumeEarlyInput());
|
||||||
const inputValueRef = useRef(inputValue);
|
const inputValueRef = useRef(inputValue);
|
||||||
inputValueRef.current = inputValue;
|
inputValueRef.current = inputValue;
|
||||||
const startupChecksStartedRef = useRef(false);
|
|
||||||
const promptTypingSuppressionActive = isPromptTypingSuppressionActive(isPromptInputActive, inputValue);
|
const promptTypingSuppressionActive = isPromptTypingSuppressionActive(isPromptInputActive, inputValue);
|
||||||
const insertTextRef = useRef<{
|
const insertTextRef = useRef<{
|
||||||
insert: (text: string) => void;
|
insert: (text: string) => void;
|
||||||
@@ -1333,24 +1344,6 @@ export function REPL({
|
|||||||
cursorOffset: number;
|
cursorOffset: number;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
// Start background plugin installations after the initial input window is idle.
|
|
||||||
// SECURITY: This still runs only after the "trust this folder" dialog has been
|
|
||||||
// confirmed because the REPL is not mounted until that dialog completes.
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
!shouldStartStartupChecks({
|
|
||||||
isRemoteSession,
|
|
||||||
promptTypingSuppressionActive,
|
|
||||||
startupChecksStarted: startupChecksStartedRef.current,
|
|
||||||
})
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
startupChecksStartedRef.current = true;
|
|
||||||
void performStartupChecks(setAppState);
|
|
||||||
}, [isRemoteSession, promptTypingSuppressionActive, setAppState]);
|
|
||||||
|
|
||||||
// Wrap setInputValue to co-locate suppression state updates.
|
// Wrap setInputValue to co-locate suppression state updates.
|
||||||
// Both setState calls happen in the same synchronous context so React
|
// Both setState calls happen in the same synchronous context so React
|
||||||
// batches them into a single render, eliminating the extra render that
|
// batches them into a single render, eliminating the extra render that
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
import { describe, expect, test } from 'bun:test'
|
|
||||||
import { shouldStartStartupChecks } from './replStartupGates.js'
|
|
||||||
|
|
||||||
describe('shouldStartStartupChecks', () => {
|
|
||||||
test('returns false for remote sessions', () => {
|
|
||||||
expect(
|
|
||||||
shouldStartStartupChecks({
|
|
||||||
isRemoteSession: true,
|
|
||||||
promptTypingSuppressionActive: false,
|
|
||||||
startupChecksStarted: false,
|
|
||||||
}),
|
|
||||||
).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('returns false while prompt typing suppression is active', () => {
|
|
||||||
expect(
|
|
||||||
shouldStartStartupChecks({
|
|
||||||
isRemoteSession: false,
|
|
||||||
promptTypingSuppressionActive: true,
|
|
||||||
startupChecksStarted: false,
|
|
||||||
}),
|
|
||||||
).toBe(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('returns true once local startup is idle and checks have not started', () => {
|
|
||||||
expect(
|
|
||||||
shouldStartStartupChecks({
|
|
||||||
isRemoteSession: false,
|
|
||||||
promptTypingSuppressionActive: false,
|
|
||||||
startupChecksStarted: false,
|
|
||||||
}),
|
|
||||||
).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('returns false after startup checks have already started', () => {
|
|
||||||
expect(
|
|
||||||
shouldStartStartupChecks({
|
|
||||||
isRemoteSession: false,
|
|
||||||
promptTypingSuppressionActive: false,
|
|
||||||
startupChecksStarted: true,
|
|
||||||
}),
|
|
||||||
).toBe(false)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
export function shouldStartStartupChecks(options: {
|
|
||||||
isRemoteSession: boolean
|
|
||||||
promptTypingSuppressionActive: boolean
|
|
||||||
startupChecksStarted: boolean
|
|
||||||
}): boolean {
|
|
||||||
return (
|
|
||||||
!options.isRemoteSession &&
|
|
||||||
!options.promptTypingSuppressionActive &&
|
|
||||||
!options.startupChecksStarted
|
|
||||||
)
|
|
||||||
}
|
|
||||||
33
src/services/tools/toolExecution.test.ts
Normal file
33
src/services/tools/toolExecution.test.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { describe, expect, test } from 'bun:test'
|
||||||
|
|
||||||
|
import { SkillTool } from '../../tools/SkillTool/SkillTool.js'
|
||||||
|
import {
|
||||||
|
getSchemaValidationErrorOverride,
|
||||||
|
getSchemaValidationToolUseResult,
|
||||||
|
} from './toolExecution.js'
|
||||||
|
|
||||||
|
describe('getSchemaValidationErrorOverride', () => {
|
||||||
|
test('returns actionable missing-skill error for SkillTool', () => {
|
||||||
|
expect(getSchemaValidationErrorOverride(SkillTool, {})).toBe(
|
||||||
|
'Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does not override unrelated tool schema failures', () => {
|
||||||
|
expect(getSchemaValidationErrorOverride({ name: 'Read' } as never, {})).toBe(
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does not override SkillTool when skill is present', () => {
|
||||||
|
expect(
|
||||||
|
getSchemaValidationErrorOverride(SkillTool, { skill: 'commit' }),
|
||||||
|
).toBe(null)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('uses the actionable override for structured toolUseResult too', () => {
|
||||||
|
expect(getSchemaValidationToolUseResult(SkillTool, {} as never)).toBe(
|
||||||
|
'InputValidationError: Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -43,6 +43,7 @@ import { FILE_READ_TOOL_NAME } from '../../tools/FileReadTool/prompt.js'
|
|||||||
import { FILE_WRITE_TOOL_NAME } from '../../tools/FileWriteTool/prompt.js'
|
import { FILE_WRITE_TOOL_NAME } from '../../tools/FileWriteTool/prompt.js'
|
||||||
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
|
import { NOTEBOOK_EDIT_TOOL_NAME } from '../../tools/NotebookEditTool/constants.js'
|
||||||
import { POWERSHELL_TOOL_NAME } from '../../tools/PowerShellTool/toolName.js'
|
import { POWERSHELL_TOOL_NAME } from '../../tools/PowerShellTool/toolName.js'
|
||||||
|
import { SKILL_TOOL_NAME } from '../../tools/SkillTool/constants.js'
|
||||||
import { parseGitCommitId } from '../../tools/shared/gitOperationTracking.js'
|
import { parseGitCommitId } from '../../tools/shared/gitOperationTracking.js'
|
||||||
import {
|
import {
|
||||||
isDeferredTool,
|
isDeferredTool,
|
||||||
@@ -596,6 +597,31 @@ export function buildSchemaNotSentHint(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSchemaValidationErrorOverride(
|
||||||
|
tool: Tool,
|
||||||
|
input: unknown,
|
||||||
|
): string | null {
|
||||||
|
if (tool.name !== SKILL_TOOL_NAME || !input || typeof input !== 'object') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const skill = (input as { skill?: unknown }).skill
|
||||||
|
if (skill === undefined || skill === null) {
|
||||||
|
return 'Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).'
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSchemaValidationToolUseResult(
|
||||||
|
tool: Tool,
|
||||||
|
input: unknown,
|
||||||
|
fallbackMessage?: string,
|
||||||
|
): string {
|
||||||
|
const override = getSchemaValidationErrorOverride(tool, input)
|
||||||
|
return `InputValidationError: ${override ?? fallbackMessage ?? ''}`
|
||||||
|
}
|
||||||
|
|
||||||
async function checkPermissionsAndCallTool(
|
async function checkPermissionsAndCallTool(
|
||||||
tool: Tool,
|
tool: Tool,
|
||||||
toolUseID: string,
|
toolUseID: string,
|
||||||
@@ -614,7 +640,9 @@ async function checkPermissionsAndCallTool(
|
|||||||
// Validate input types with zod (surprisingly, the model is not great at generating valid input)
|
// Validate input types with zod (surprisingly, the model is not great at generating valid input)
|
||||||
const parsedInput = tool.inputSchema.safeParse(input)
|
const parsedInput = tool.inputSchema.safeParse(input)
|
||||||
if (!parsedInput.success) {
|
if (!parsedInput.success) {
|
||||||
let errorContent = formatZodValidationError(tool.name, parsedInput.error)
|
const fallbackErrorContent = formatZodValidationError(tool.name, parsedInput.error)
|
||||||
|
let errorContent =
|
||||||
|
getSchemaValidationErrorOverride(tool, input) ?? fallbackErrorContent
|
||||||
|
|
||||||
const schemaHint = buildSchemaNotSentHint(
|
const schemaHint = buildSchemaNotSentHint(
|
||||||
tool,
|
tool,
|
||||||
@@ -672,7 +700,11 @@ async function checkPermissionsAndCallTool(
|
|||||||
tool_use_id: toolUseID,
|
tool_use_id: toolUseID,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
toolUseResult: `InputValidationError: ${parsedInput.error.message}`,
|
toolUseResult: getSchemaValidationToolUseResult(
|
||||||
|
tool,
|
||||||
|
input,
|
||||||
|
parsedInput.error.message,
|
||||||
|
),
|
||||||
sourceToolAssistantUUID: assistantMessage.uuid,
|
sourceToolAssistantUUID: assistantMessage.uuid,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|||||||
31
src/tools/SkillTool/SkillTool.test.ts
Normal file
31
src/tools/SkillTool/SkillTool.test.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { describe, expect, test } from 'bun:test'
|
||||||
|
|
||||||
|
import { SkillTool } from './SkillTool.js'
|
||||||
|
|
||||||
|
describe('SkillTool missing parameter handling', () => {
|
||||||
|
test('missing skill stays required at the schema level', async () => {
|
||||||
|
const parsed = SkillTool.inputSchema.safeParse({})
|
||||||
|
|
||||||
|
expect(parsed.success).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('validateInput still returns an actionable error when called with missing skill', async () => {
|
||||||
|
const result = await SkillTool.validateInput?.({} as never, {
|
||||||
|
options: { tools: [] },
|
||||||
|
messages: [],
|
||||||
|
} as never)
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
result: false,
|
||||||
|
message:
|
||||||
|
'Missing skill name. Pass the slash command name as the skill parameter (e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||||
|
errorCode: 1,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('valid skill input still parses and validates', async () => {
|
||||||
|
const parsed = SkillTool.inputSchema.safeParse({ skill: 'commit' })
|
||||||
|
|
||||||
|
expect(parsed.success).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -352,6 +352,16 @@ export const SkillTool: Tool<InputSchema, Output, Progress> = buildTool({
|
|||||||
toAutoClassifierInput: ({ skill }) => skill ?? '',
|
toAutoClassifierInput: ({ skill }) => skill ?? '',
|
||||||
|
|
||||||
async validateInput({ skill }, context): Promise<ValidationResult> {
|
async validateInput({ skill }, context): Promise<ValidationResult> {
|
||||||
|
if (!skill || typeof skill !== 'string') {
|
||||||
|
return {
|
||||||
|
result: false,
|
||||||
|
message:
|
||||||
|
'Missing skill name. Pass the slash command name as the skill parameter ' +
|
||||||
|
'(e.g., skill: "commit" for /commit, skill: "review-pr" for /review-pr).',
|
||||||
|
errorCode: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Skills are just skill names, no arguments
|
// Skills are just skill names, no arguments
|
||||||
const trimmed = skill.trim()
|
const trimmed = skill.trim()
|
||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
@@ -434,7 +444,7 @@ export const SkillTool: Tool<InputSchema, Output, Progress> = buildTool({
|
|||||||
context,
|
context,
|
||||||
): Promise<PermissionDecision> {
|
): Promise<PermissionDecision> {
|
||||||
// Skills are just skill names, no arguments
|
// Skills are just skill names, no arguments
|
||||||
const trimmed = skill.trim()
|
const trimmed = skill ?? ''
|
||||||
|
|
||||||
// Remove leading slash if present (for compatibility)
|
// Remove leading slash if present (for compatibility)
|
||||||
const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
|
const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
|
||||||
@@ -592,7 +602,7 @@ export const SkillTool: Tool<InputSchema, Output, Progress> = buildTool({
|
|||||||
// - Skill is a prompt-based skill
|
// - Skill is a prompt-based skill
|
||||||
|
|
||||||
// Skills are just names, with optional arguments
|
// Skills are just names, with optional arguments
|
||||||
const trimmed = skill.trim()
|
const trimmed = skill ?? ''
|
||||||
|
|
||||||
// Remove leading slash if present (for compatibility)
|
// Remove leading slash if present (for compatibility)
|
||||||
const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
|
const commandName = trimmed.startsWith('/') ? trimmed.substring(1) : trimmed
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { expect, test } from 'bun:test'
|
import { expect, test } from 'bun:test'
|
||||||
import { z } from 'zod/v4'
|
import { z } from 'zod/v4'
|
||||||
import { getEmptyToolPermissionContext, type Tool, type Tools } from '../Tool.js'
|
import { getEmptyToolPermissionContext, type Tool, type Tools } from '../Tool.js'
|
||||||
|
import { SkillTool } from '../tools/SkillTool/SkillTool.js'
|
||||||
import { toolToAPISchema } from './api.js'
|
import { toolToAPISchema } from './api.js'
|
||||||
|
|
||||||
test('toolToAPISchema preserves provider-specific schema keywords in input_schema', async () => {
|
test('toolToAPISchema preserves provider-specific schema keywords in input_schema', async () => {
|
||||||
@@ -64,3 +65,16 @@ test('toolToAPISchema preserves provider-specific schema keywords in input_schem
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('toolToAPISchema keeps skill required for SkillTool', async () => {
|
||||||
|
const schema = await toolToAPISchema(SkillTool, {
|
||||||
|
getToolPermissionContext: async () => getEmptyToolPermissionContext(),
|
||||||
|
tools: [] as unknown as Tools,
|
||||||
|
agents: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect((schema as { input_schema: unknown }).input_schema).toMatchObject({
|
||||||
|
type: 'object',
|
||||||
|
required: ['skill'],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
} from './managedEnvConstants.js'
|
} from './managedEnvConstants.js'
|
||||||
import { clearMTLSCache } from './mtls.js'
|
import { clearMTLSCache } from './mtls.js'
|
||||||
import { clearProxyCache, configureGlobalAgents } from './proxy.js'
|
import { clearProxyCache, configureGlobalAgents } from './proxy.js'
|
||||||
import { filterSettingsEnvForExplicitProvider } from './providerEnvSelection.js'
|
|
||||||
import { applyActiveProviderProfileFromConfig } from './providerProfiles.js'
|
import { applyActiveProviderProfileFromConfig } from './providerProfiles.js'
|
||||||
import { isSettingSourceEnabled } from './settings/constants.js'
|
import { isSettingSourceEnabled } from './settings/constants.js'
|
||||||
import {
|
import {
|
||||||
@@ -88,9 +87,7 @@ function filterSettingsEnv(
|
|||||||
env: Record<string, string> | undefined,
|
env: Record<string, string> | undefined,
|
||||||
): Record<string, string> {
|
): Record<string, string> {
|
||||||
return withoutCcdSpawnEnvKeys(
|
return withoutCcdSpawnEnvKeys(
|
||||||
filterSettingsEnvForExplicitProvider(
|
withoutHostManagedProviderVars(withoutSSHTunnelVars(env)),
|
||||||
withoutHostManagedProviderVars(withoutSSHTunnelVars(env)),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,116 +0,0 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
||||||
import { filterSettingsEnvForExplicitProvider } from './providerEnvSelection.js'
|
|
||||||
|
|
||||||
const originalEnv = { ...process.env }
|
|
||||||
|
|
||||||
const RESET_KEYS = [
|
|
||||||
'CLAUDE_CODE_EXPLICIT_PROVIDER',
|
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
|
||||||
'CLAUDE_CODE_USE_GEMINI',
|
|
||||||
'CLAUDE_CODE_USE_GITHUB',
|
|
||||||
'CLAUDE_CODE_USE_BEDROCK',
|
|
||||||
'CLAUDE_CODE_USE_VERTEX',
|
|
||||||
'CLAUDE_CODE_USE_FOUNDRY',
|
|
||||||
] as const
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
for (const key of RESET_KEYS) {
|
|
||||||
delete process.env[key]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
for (const key of RESET_KEYS) {
|
|
||||||
if (originalEnv[key] === undefined) delete process.env[key]
|
|
||||||
else process.env[key] = originalEnv[key]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('filterSettingsEnvForExplicitProvider', () => {
|
|
||||||
test('does not treat plain provider flags as an explicit CLI override', () => {
|
|
||||||
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
CLAUDE_CODE_USE_OPENAI: '1',
|
|
||||||
OPENAI_MODEL: 'gpt-4o',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({
|
|
||||||
CLAUDE_CODE_USE_OPENAI: '1',
|
|
||||||
OPENAI_MODEL: 'gpt-4o',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('strips settings-sourced provider flags when CLI provider is explicit', () => {
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'openai'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
CLAUDE_CODE_USE_GITHUB: '1',
|
|
||||||
CLAUDE_CODE_USE_OPENAI: '1',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({ OTHER: 'keep-me' })
|
|
||||||
})
|
|
||||||
|
|
||||||
test('strips a stale GitHub model when explicit provider is not github', () => {
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'openai'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
OPENAI_MODEL: 'github:copilot',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({ OTHER: 'keep-me' })
|
|
||||||
})
|
|
||||||
|
|
||||||
test('keeps a normal OpenAI model when explicit provider is openai', () => {
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'openai'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
OPENAI_MODEL: 'gpt-4o',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({ OPENAI_MODEL: 'gpt-4o', OTHER: 'keep-me' })
|
|
||||||
})
|
|
||||||
|
|
||||||
test('strips a non-GitHub OpenAI model when explicit provider is github', () => {
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'github'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
OPENAI_MODEL: 'gpt-4o',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({ OTHER: 'keep-me' })
|
|
||||||
})
|
|
||||||
|
|
||||||
test('preserves anthropic startup intent by stripping stale GitHub/OpenAI settings', () => {
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'anthropic'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
CLAUDE_CODE_USE_GITHUB: '1',
|
|
||||||
CLAUDE_CODE_USE_OPENAI: '1',
|
|
||||||
OPENAI_MODEL: 'github:copilot',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({ OTHER: 'keep-me' })
|
|
||||||
})
|
|
||||||
|
|
||||||
test('preserves explicit ollama startup intent by stripping OpenAI routing settings', () => {
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'ollama'
|
|
||||||
|
|
||||||
expect(
|
|
||||||
filterSettingsEnvForExplicitProvider({
|
|
||||||
OPENAI_BASE_URL: 'https://api.openai.com/v1',
|
|
||||||
OPENAI_MODEL: 'gpt-4o',
|
|
||||||
OPENAI_API_KEY: 'sk-test',
|
|
||||||
OTHER: 'keep-me',
|
|
||||||
}),
|
|
||||||
).toEqual({ OTHER: 'keep-me' })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
export const EXPLICIT_PROVIDER_ENV_VAR = 'CLAUDE_CODE_EXPLICIT_PROVIDER'
|
|
||||||
|
|
||||||
const PROVIDER_FLAG_KEYS = [
|
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
|
||||||
'CLAUDE_CODE_USE_GEMINI',
|
|
||||||
'CLAUDE_CODE_USE_GITHUB',
|
|
||||||
'CLAUDE_CODE_USE_BEDROCK',
|
|
||||||
'CLAUDE_CODE_USE_VERTEX',
|
|
||||||
'CLAUDE_CODE_USE_FOUNDRY',
|
|
||||||
] as const
|
|
||||||
|
|
||||||
export function clearProviderSelectionFlags(
|
|
||||||
env: NodeJS.ProcessEnv = process.env,
|
|
||||||
): void {
|
|
||||||
for (const key of PROVIDER_FLAG_KEYS) {
|
|
||||||
delete env[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getExplicitProvider(processEnv: NodeJS.ProcessEnv): string | undefined {
|
|
||||||
return processEnv[EXPLICIT_PROVIDER_ENV_VAR]?.trim() || undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
function isGithubModel(model: string | undefined): boolean {
|
|
||||||
return (model ?? '').trim().toLowerCase().startsWith('github:')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function filterSettingsEnvForExplicitProvider(
|
|
||||||
env: Record<string, string> | undefined,
|
|
||||||
processEnv: NodeJS.ProcessEnv = process.env,
|
|
||||||
): Record<string, string> {
|
|
||||||
if (!env) return {}
|
|
||||||
|
|
||||||
const explicitProvider = getExplicitProvider(processEnv)
|
|
||||||
if (!explicitProvider) {
|
|
||||||
return env
|
|
||||||
}
|
|
||||||
|
|
||||||
const filtered = { ...env }
|
|
||||||
for (const key of PROVIDER_FLAG_KEYS) {
|
|
||||||
delete filtered[key]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (explicitProvider === 'ollama') {
|
|
||||||
delete filtered.OPENAI_BASE_URL
|
|
||||||
delete filtered.OPENAI_MODEL
|
|
||||||
delete filtered.OPENAI_API_KEY
|
|
||||||
return filtered
|
|
||||||
}
|
|
||||||
|
|
||||||
if (explicitProvider === 'github') {
|
|
||||||
if (!isGithubModel(filtered.OPENAI_MODEL)) {
|
|
||||||
delete filtered.OPENAI_MODEL
|
|
||||||
}
|
|
||||||
return filtered
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isGithubModel(filtered.OPENAI_MODEL)) {
|
|
||||||
delete filtered.OPENAI_MODEL
|
|
||||||
}
|
|
||||||
|
|
||||||
return filtered
|
|
||||||
}
|
|
||||||
@@ -9,13 +9,11 @@ import {
|
|||||||
const originalEnv = { ...process.env }
|
const originalEnv = { ...process.env }
|
||||||
|
|
||||||
const RESET_KEYS = [
|
const RESET_KEYS = [
|
||||||
'CLAUDE_CODE_EXPLICIT_PROVIDER',
|
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
'CLAUDE_CODE_USE_GEMINI',
|
'CLAUDE_CODE_USE_GEMINI',
|
||||||
'CLAUDE_CODE_USE_GITHUB',
|
'CLAUDE_CODE_USE_GITHUB',
|
||||||
'CLAUDE_CODE_USE_BEDROCK',
|
'CLAUDE_CODE_USE_BEDROCK',
|
||||||
'CLAUDE_CODE_USE_VERTEX',
|
'CLAUDE_CODE_USE_VERTEX',
|
||||||
'CLAUDE_CODE_USE_FOUNDRY',
|
|
||||||
'OPENAI_BASE_URL',
|
'OPENAI_BASE_URL',
|
||||||
'OPENAI_API_KEY',
|
'OPENAI_API_KEY',
|
||||||
'OPENAI_MODEL',
|
'OPENAI_MODEL',
|
||||||
@@ -85,16 +83,6 @@ describe('applyProviderFlag - openai', () => {
|
|||||||
applyProviderFlag('openai', ['--model', 'gpt-4o'])
|
applyProviderFlag('openai', ['--model', 'gpt-4o'])
|
||||||
expect(process.env.OPENAI_MODEL).toBe('gpt-4o')
|
expect(process.env.OPENAI_MODEL).toBe('gpt-4o')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('clears a previously persisted GitHub flag', () => {
|
|
||||||
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
|
||||||
|
|
||||||
const result = applyProviderFlag('openai', [])
|
|
||||||
|
|
||||||
expect(result.error).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBe('1')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('applyProviderFlag - gemini', () => {
|
describe('applyProviderFlag - gemini', () => {
|
||||||
@@ -116,16 +104,6 @@ describe('applyProviderFlag - github', () => {
|
|||||||
expect(result.error).toBeUndefined()
|
expect(result.error).toBeUndefined()
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBe('1')
|
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBe('1')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('clears a previously set OpenAI flag', () => {
|
|
||||||
process.env.CLAUDE_CODE_USE_OPENAI = '1'
|
|
||||||
|
|
||||||
const result = applyProviderFlag('github', [])
|
|
||||||
|
|
||||||
expect(result.error).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBe('1')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('applyProviderFlag - bedrock', () => {
|
describe('applyProviderFlag - bedrock', () => {
|
||||||
@@ -173,19 +151,6 @@ describe('applyProviderFlag - invalid provider', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('applyProviderFlag - anthropic', () => {
|
|
||||||
test('clears third-party provider flags', () => {
|
|
||||||
process.env.CLAUDE_CODE_USE_GITHUB = '1'
|
|
||||||
process.env.CLAUDE_CODE_USE_OPENAI = '1'
|
|
||||||
|
|
||||||
const result = applyProviderFlag('anthropic', [])
|
|
||||||
|
|
||||||
expect(result.error).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('applyProviderFlagFromArgs', () => {
|
describe('applyProviderFlagFromArgs', () => {
|
||||||
test('applies ollama provider and model from argv in one step', () => {
|
test('applies ollama provider and model from argv in one step', () => {
|
||||||
const result = applyProviderFlagFromArgs([
|
const result = applyProviderFlagFromArgs([
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
import {
|
|
||||||
clearProviderSelectionFlags,
|
|
||||||
EXPLICIT_PROVIDER_ENV_VAR,
|
|
||||||
} from './providerEnvSelection.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* --provider CLI flag support.
|
* --provider CLI flag support.
|
||||||
*
|
*
|
||||||
@@ -82,9 +77,6 @@ export function applyProviderFlag(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearProviderSelectionFlags()
|
|
||||||
process.env[EXPLICIT_PROVIDER_ENV_VAR] = provider
|
|
||||||
|
|
||||||
const model = parseModelFlag(args)
|
const model = parseModelFlag(args)
|
||||||
|
|
||||||
switch (provider as ProviderFlagName) {
|
switch (provider as ProviderFlagName) {
|
||||||
|
|||||||
@@ -485,26 +485,6 @@ test('buildStartupEnvFromProfile leaves explicit provider selections untouched',
|
|||||||
assert.equal(env.OPENAI_API_KEY, undefined)
|
assert.equal(env.OPENAI_API_KEY, undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('buildStartupEnvFromProfile preserves explicit anthropic startup selection', async () => {
|
|
||||||
const processEnv = {
|
|
||||||
CLAUDE_CODE_EXPLICIT_PROVIDER: 'anthropic',
|
|
||||||
}
|
|
||||||
|
|
||||||
const env = await buildStartupEnvFromProfile({
|
|
||||||
persisted: profile('openai', {
|
|
||||||
CLAUDE_CODE_USE_GITHUB: '1',
|
|
||||||
OPENAI_MODEL: 'github:copilot',
|
|
||||||
}),
|
|
||||||
processEnv,
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.equal(env, processEnv)
|
|
||||||
assert.equal(env.CLAUDE_CODE_EXPLICIT_PROVIDER, 'anthropic')
|
|
||||||
assert.equal(env.CLAUDE_CODE_USE_OPENAI, undefined)
|
|
||||||
assert.equal(env.CLAUDE_CODE_USE_GITHUB, undefined)
|
|
||||||
assert.equal(env.OPENAI_MODEL, undefined)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('buildStartupEnvFromProfile leaves profile-managed env untouched', async () => {
|
test('buildStartupEnvFromProfile leaves profile-managed env untouched', async () => {
|
||||||
const processEnv = {
|
const processEnv = {
|
||||||
CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED: '1',
|
CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED: '1',
|
||||||
|
|||||||
@@ -412,10 +412,6 @@ export function hasExplicitProviderSelection(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (processEnv.CLAUDE_CODE_EXPLICIT_PROVIDER?.trim()) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ async function importFreshProvidersModule() {
|
|||||||
const originalEnv = { ...process.env }
|
const originalEnv = { ...process.env }
|
||||||
|
|
||||||
const RESTORED_KEYS = [
|
const RESTORED_KEYS = [
|
||||||
'CLAUDE_CODE_EXPLICIT_PROVIDER',
|
|
||||||
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED',
|
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED',
|
||||||
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID',
|
'CLAUDE_CODE_PROVIDER_PROFILE_ENV_APPLIED_ID',
|
||||||
'CLAUDE_CODE_USE_OPENAI',
|
'CLAUDE_CODE_USE_OPENAI',
|
||||||
@@ -143,29 +142,6 @@ describe('applyProviderProfileToProcessEnv', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('applyActiveProviderProfileFromConfig', () => {
|
describe('applyActiveProviderProfileFromConfig', () => {
|
||||||
test('does not override explicit anthropic startup selection', async () => {
|
|
||||||
const { applyActiveProviderProfileFromConfig } =
|
|
||||||
await importFreshProviderProfileModules()
|
|
||||||
process.env.CLAUDE_CODE_EXPLICIT_PROVIDER = 'anthropic'
|
|
||||||
|
|
||||||
const applied = applyActiveProviderProfileFromConfig({
|
|
||||||
providerProfiles: [
|
|
||||||
buildProfile({
|
|
||||||
id: 'saved_github',
|
|
||||||
baseUrl: 'https://api.githubcopilot.com',
|
|
||||||
model: 'github:copilot',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
activeProviderProfileId: 'saved_github',
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
expect(applied).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_EXPLICIT_PROVIDER).toBe('anthropic')
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_OPENAI).toBeUndefined()
|
|
||||||
expect(process.env.CLAUDE_CODE_USE_GITHUB).toBeUndefined()
|
|
||||||
expect(process.env.OPENAI_MODEL).toBeUndefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('does not override explicit startup provider selection', async () => {
|
test('does not override explicit startup provider selection', async () => {
|
||||||
const { applyActiveProviderProfileFromConfig } =
|
const { applyActiveProviderProfileFromConfig } =
|
||||||
await importFreshProviderProfileModules()
|
await importFreshProviderProfileModules()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
type ProviderProfile,
|
type ProviderProfile,
|
||||||
} from './config.js'
|
} from './config.js'
|
||||||
import type { ModelOption } from './model/modelOptions.js'
|
import type { ModelOption } from './model/modelOptions.js'
|
||||||
import { EXPLICIT_PROVIDER_ENV_VAR } from './providerEnvSelection.js'
|
|
||||||
|
|
||||||
export type ProviderPreset =
|
export type ProviderPreset =
|
||||||
| 'anthropic'
|
| 'anthropic'
|
||||||
@@ -257,7 +256,6 @@ function hasProviderSelectionFlags(
|
|||||||
processEnv: NodeJS.ProcessEnv = process.env,
|
processEnv: NodeJS.ProcessEnv = process.env,
|
||||||
): boolean {
|
): boolean {
|
||||||
return (
|
return (
|
||||||
processEnv[EXPLICIT_PROVIDER_ENV_VAR] !== undefined ||
|
|
||||||
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
processEnv.CLAUDE_CODE_USE_OPENAI !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_GEMINI !== undefined ||
|
processEnv.CLAUDE_CODE_USE_GEMINI !== undefined ||
|
||||||
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
processEnv.CLAUDE_CODE_USE_GITHUB !== undefined ||
|
||||||
|
|||||||
Reference in New Issue
Block a user