diff --git a/.env.example b/.env.example index c3c02f2d18..c3cd93f18b 100644 --- a/.env.example +++ b/.env.example @@ -736,9 +736,11 @@ TTS_API_KEY= # LIBRECHAT_CODE_API_KEY= -# Advertise the immutable per-conversation code-environment decision protocol. -# Enable only after every LibreChat API replica runs a version that supports protocol v1. -# CODE_ENVIRONMENT_DECISION_VERSION=1 +# The immutable per-conversation code-environment decision protocol (v1) is advertised by +# default; per-chat machine choice depends on it. Set 0 to keep the legacy path, for example +# while LibreChat API replicas that predate protocol v1 are still running; 0 also turns off +# per-chat machine choice, so every agent stays on its fixed machine. +# CODE_ENVIRONMENT_DECISION_VERSION=0 # LIBRECHAT_CODE_BASEURL= # Current self-hosted Code Interpreter deployments use per-user LibreChat JWTs outside local mode. # Configure the matching public verifier on Code Interpreter; see: diff --git a/api/server/routes/__tests__/config.spec.js b/api/server/routes/__tests__/config.spec.js index c6eb406b35..5042cff638 100644 --- a/api/server/routes/__tests__/config.spec.js +++ b/api/server/routes/__tests__/config.spec.js @@ -511,7 +511,7 @@ describe('GET /api/config', () => { expect(response.body.modelSpecs).toEqual({ list: [{ name: 'test-spec' }] }); expect(response.body.balance).toEqual({ enabled: true, startBalance: 10000 }); expect(response.body.webSearch).toEqual({ searchProvider: 'tavily' }); - expect(response.body.codeEnvironmentDecisionVersion).toBeUndefined(); + expect(response.body.codeEnvironmentDecisionVersion).toBe(1); }); it('does not advertise conversation moves unless the effective policy enables them', async () => { @@ -536,7 +536,7 @@ describe('GET /api/config', () => { }, }, }); - delete process.env.CODE_ENVIRONMENT_DECISION_VERSION; + process.env.CODE_ENVIRONMENT_DECISION_VERSION = '0'; const app = createApp(mockUser); const response = await request(app).get('/api/config'); @@ -549,15 +549,22 @@ describe('GET /api/config', () => { expect(response.body.codeWorkspaceRecoveryVersion).toBe(1); }); - it('advertises code environment decisions only after deployment-wide activation', async () => { - mockGetAppConfig.mockResolvedValue(baseAppConfig); - process.env.CODE_ENVIRONMENT_DECISION_VERSION = '1'; - const app = createApp(mockUser); + it.each([undefined, '1'])( + 'advertises code environment decisions by default and when set to 1 (%p)', + async (version) => { + mockGetAppConfig.mockResolvedValue(baseAppConfig); + if (version === undefined) { + delete process.env.CODE_ENVIRONMENT_DECISION_VERSION; + } else { + process.env.CODE_ENVIRONMENT_DECISION_VERSION = version; + } + const app = createApp(mockUser); - const response = await request(app).get('/api/config'); + const response = await request(app).get('/api/config'); - expect(response.body.codeEnvironmentDecisionVersion).toBe(1); - }); + expect(response.body.codeEnvironmentDecisionVersion).toBe(1); + }, + ); it.each(['0', '2', '1.0', 'true'])( 'does not advertise unsupported code environment decision version %s', diff --git a/e2e/byom/README.md b/e2e/byom/README.md index 507c931446..a85ad10b66 100644 --- a/e2e/byom/README.md +++ b/e2e/byom/README.md @@ -62,8 +62,9 @@ do not relax that policy to make the test pass. Both chats read different physical files. An offline B never falls back to A. The disposable fixture enables `endpoints.agents.statefulCodeSessions.allowEnvironmentSelection` -and the environment-decision protocol. Production deployments keep fixed-agent routing unless -that opt-in is enabled and the agent has a nonempty `code_environment_ids` list. The default +and the environment-decision protocol. Machine selection is on by default, but an agent keeps +fixed routing unless it has a nonempty `code_environment_ids` list, and a deployment can turn it +off with `allowEnvironmentSelection: false`. The default `code_environment_id` is implicitly allowed; every additional machine still requires the user's own access and current worker capabilities. This does not move an existing chat between machines. diff --git a/librechat.example.yaml b/librechat.example.yaml index 280886cc3a..8c3599edc6 100644 --- a/librechat.example.yaml +++ b/librechat.example.yaml @@ -782,9 +782,9 @@ endpoints: # # (optional) Limit the workspace scopes users may select. Omit to allow all three. # statefulCodeSessions: # # Let new chats choose an attached machine from their agent's explicit machine allowlist. - # # Keep false until ALL API replicas support this field, then refresh clients. - # # Omitted/false preserves agents' fixed machine bindings. - # allowEnvironmentSelection: false + # # On by default; only agents with a saved allowlist are affected. Set false to keep + # # every agent on its fixed machine (for example while older API replicas still run). + # allowEnvironmentSelection: true # # Maximum additional machines per agent; default 32, supported ceiling 128. # maxEnvironmentChoices: 32 # # Keep move-only behavior unless attach/detach is explicitly enabled. diff --git a/packages/api/src/agents/__tests__/initialize.test.ts b/packages/api/src/agents/__tests__/initialize.test.ts index 3fa37ae475..3319102e3f 100644 --- a/packages/api/src/agents/__tests__/initialize.test.ts +++ b/packages/api/src/agents/__tests__/initialize.test.ts @@ -3531,11 +3531,12 @@ describe('initializeAgent — execute_code capability expansion', () => { ); }); - it('keeps legacy opt-out classification until the deployment protocol is enabled', async () => { + it('keeps legacy opt-out classification when the deployment opts out of the protocol', async () => { const { agent, req, res, loadTools, db } = createMocks(); agent.tools = [Tools.execute_code]; agent.stateful_code_sessions = true; delete agent.code_environment_id; + process.env.CODE_ENVIRONMENT_DECISION_VERSION = '0'; process.env.LIBRECHAT_CODE_BASEURL_STATEFUL = 'https://stateful-code.example.com/v1/'; req.config = { endpoints: { @@ -3568,6 +3569,7 @@ describe('initializeAgent — execute_code capability expansion', () => { expect(result.codeEnvAvailable).toBe(false); expect(result.statefulCodeSessions).toBe(false); } finally { + delete process.env.CODE_ENVIRONMENT_DECISION_VERSION; delete process.env.LIBRECHAT_CODE_BASEURL_STATEFUL; } }); diff --git a/packages/api/src/agents/execution.spec.ts b/packages/api/src/agents/execution.spec.ts index 870defac2a..e090585bf3 100644 --- a/packages/api/src/agents/execution.spec.ts +++ b/packages/api/src/agents/execution.spec.ts @@ -152,6 +152,20 @@ describe('resolveCodeExecutionContext', () => { ); }); + it('routes to the chosen machine when the deployment leaves the flag unset', () => { + const { allowEnvironmentSelection: _unset, ...unset } = params; + expect(resolveCodeExecutionContext(unset).environmentId).toBe('runtime-vm'); + }); + + it('retains fixed routing when the deployment turns the decision protocol off', () => { + process.env.CODE_ENVIRONMENT_DECISION_VERSION = '0'; + try { + expect(resolveCodeExecutionContext(params).environmentId).toBe('application-vm'); + } finally { + delete process.env.CODE_ENVIRONMENT_DECISION_VERSION; + } + }); + it.each(['allowEnvironmentSelection', 'environmentIds'] as const)( 'retains fixed routing when %s is disabled', (gate) => { diff --git a/packages/api/src/agents/execution.ts b/packages/api/src/agents/execution.ts index 4a29323c77..cd234175c2 100644 --- a/packages/api/src/agents/execution.ts +++ b/packages/api/src/agents/execution.ts @@ -13,6 +13,7 @@ import type { TAgentsEndpoint, } from 'librechat-data-provider'; import type { WorkspaceEditFileFeature } from '~/code/edits'; +import { isCodeEnvironmentSelectionEnabled } from '~/code/protocol'; import { CodeWorkspaceSelectionError } from '~/code/errors'; export const CODE_API_EXPECTED_PROFILE_HEADER = 'X-CodeAPI-Expected-Profile'; @@ -352,7 +353,8 @@ export function resolveCodeExecutionContext(params: { userId?: string | null; agentId?: string | null; conversationId?: string | null; - /** Deployment ceiling and the persisted agent machine allowlist are both required. */ + /** Deployment ceiling (on unless `false` or the decision protocol is off) and a persisted + * agent machine allowlist are both required. */ allowEnvironmentSelection?: boolean; environmentIds?: readonly string[]; workspaceSelections?: unknown; @@ -373,7 +375,7 @@ export function resolveCodeExecutionContext(params: { (params.environmentId ? candidate.id === params.environmentId : candidate.default === true), ); const allowSelection = - params.allowEnvironmentSelection === true && + isCodeEnvironmentSelectionEnabled(params.allowEnvironmentSelection) && (params.environmentIds?.length ?? 0) > 0 && (defaultEnvironment?.type === 'attached' || (defaultEnvironment == null && Boolean(params.environmentId))); diff --git a/packages/api/src/code/capabilities.spec.ts b/packages/api/src/code/capabilities.spec.ts index 93a1b22a7c..f3571df107 100644 --- a/packages/api/src/code/capabilities.spec.ts +++ b/packages/api/src/code/capabilities.spec.ts @@ -452,19 +452,32 @@ describe('resolveCodeExecutionWorkspaceContext', () => { expect(resolved.codeWorkspace?.environment).toEqual(environment); }); - it.each(['source', 'isolated'] as const)( - 'honors an explicit %s checkout choice', - async (checkout) => { - jest - .spyOn(globalThis, 'fetch') - .mockResolvedValue( - workspaceStatus([{ id: 'worktree', workspaceInstances: ['git_worktree'] }]), - ); + it.each([ + { checkout: 'source', linkedWorktrees: undefined, lanes: true }, + { checkout: 'source', linkedWorktrees: true, lanes: true }, + { checkout: 'source', linkedWorktrees: false, lanes: false }, + { checkout: 'isolated', linkedWorktrees: undefined, lanes: false }, + { checkout: 'isolated', linkedWorktrees: true, lanes: false }, + { checkout: 'isolated', linkedWorktrees: false, lanes: false }, + ] as const)( + 'honors checkout $checkout with linkedWorktrees=$linkedWorktrees', + async ({ checkout, linkedWorktrees, lanes }) => { + jest.spyOn(globalThis, 'fetch').mockResolvedValue( + workspaceStatus([ + { + id: 'worktree', + workspaceInstances: ['git_worktree'], + workspaceScopes: ['git_linked_worktree'], + }, + ]), + ); const resolved = await resolveCodeExecutionWorkspaceContext({ context: { ...context, conversationWorkspaceInstanceId: 'c'.repeat(64), - codeEnvironmentConfigSchema: { workspaces: { allowCheckoutSelection: true } }, + codeEnvironmentConfigSchema: { + workspaces: { allowCheckoutSelection: true, linkedWorktrees }, + }, }, requestedSelections: [{ environmentId: 'personal', workspaceId: 'worktree', checkout }], environments, @@ -474,6 +487,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => { expect(resolved.codeWorkspace?.workspaceInstanceId).toBe( checkout === 'isolated' ? 'c'.repeat(64) : undefined, ); + expect(resolved.codeWorkspace?.linkedWorktrees).toBe(lanes ? true : undefined); }, ); @@ -549,7 +563,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => { expect(legacy.codeWorkspace).not.toHaveProperty('workspaceInstanceId'); }); - it('routes linked worktrees into lanes only when configured and no conversation instance owns the checkout', async () => { + it('routes linked worktrees into lanes unless disabled or a conversation instance owns the checkout', async () => { const workspaceInstanceId = 'c'.repeat(64); jest.spyOn(globalThis, 'fetch').mockImplementation(async () => workspaceStatus([ @@ -588,7 +602,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => { expect(lanes.codeWorkspace?.linkedWorktrees).toBe(true); expect(disabled.codeWorkspace).not.toHaveProperty('linkedWorktrees'); - expect(unconfigured.codeWorkspace).not.toHaveProperty('linkedWorktrees'); + expect(unconfigured.codeWorkspace?.linkedWorktrees).toBe(true); expect(instance.codeWorkspace?.workspaceInstanceId).toBe(workspaceInstanceId); expect(instance.codeWorkspace).not.toHaveProperty('linkedWorktrees'); expect(legacy.codeWorkspace).not.toHaveProperty('linkedWorktrees'); diff --git a/packages/api/src/code/capabilities.ts b/packages/api/src/code/capabilities.ts index d76e1b089e..f1cd9e6916 100644 --- a/packages/api/src/code/capabilities.ts +++ b/packages/api/src/code/capabilities.ts @@ -1,6 +1,7 @@ import { logger } from '@librechat/data-schemas'; import { isCodeWorkspaceSelections, + isLinkedWorktreeRoutingAllowed, canonicalizeCodeWorkspaceSelections, isCodeWorkspaceCheckoutAvailable, } from 'librechat-data-provider'; @@ -161,7 +162,9 @@ export async function resolveCodeExecutionWorkspaceContext({ ...selection, operations: [...(workspace.operations ?? status.operations)], ...(usesIsolation ? { workspaceInstanceId: context.conversationWorkspaceInstanceId } : {}), - ...(context.codeEnvironmentConfigSchema?.workspaces?.linkedWorktrees === true && + ...(isLinkedWorktreeRoutingAllowed( + context.codeEnvironmentConfigSchema?.workspaces?.linkedWorktrees, + ) && workspace.workspaceScopes?.includes('git_linked_worktree') && !usesIsolation ? { linkedWorktrees: true } diff --git a/packages/api/src/code/config.spec.ts b/packages/api/src/code/config.spec.ts index cd3e7c6c38..d889a8787e 100644 --- a/packages/api/src/code/config.spec.ts +++ b/packages/api/src/code/config.spec.ts @@ -2,6 +2,7 @@ import { EModelEndpoint } from 'librechat-data-provider'; import type { AppConfig } from '@librechat/data-schemas'; import { isImplicitStatefulCodeRouteAvailable, + isCodeEnvironmentSelectionEnabled, mergeAccessibleCodeEnvironments, resolveCodeEnvironmentDecisionVersion, resolveCodeEnvironmentMoveVersion, @@ -14,7 +15,11 @@ describe('resolveCodeEnvironmentDecisionVersion', () => { expect(resolveCodeEnvironmentDecisionVersion('1')).toBe(1); }); - it.each([undefined, '0', '2', '1.0', 'true'])( + it.each([undefined, '', ' '])('advertises the supported version when unset (%p)', (version) => { + expect(resolveCodeEnvironmentDecisionVersion(version)).toBe(1); + }); + + it.each(['0', '2', '1.0', 'true'])( 'keeps unsupported configured version %s on the legacy-safe path', (version) => { expect(resolveCodeEnvironmentDecisionVersion(version)).toBeUndefined(); @@ -82,10 +87,23 @@ describe('resolveCodeEnvironmentMoveVersion', () => { }); }); +describe('isCodeEnvironmentSelectionEnabled', () => { + it.each([ + [undefined, undefined, true], + [true, '1', true], + [false, undefined, false], + [undefined, '0', false], + [true, '0', false], + ])('flag %p with decision version %p resolves to %p', (flag, version, expected) => { + expect(isCodeEnvironmentSelectionEnabled(flag, version)).toBe(expected); + }); +}); + describe('isImplicitStatefulCodeRouteAvailable', () => { it('requires both the deployed protocol version and a non-empty managed base URL', () => { expect(isImplicitStatefulCodeRouteAvailable('1', 'https://code.example/v1')).toBe(true); - expect(isImplicitStatefulCodeRouteAvailable(undefined, 'https://code.example/v1')).toBe(false); + expect(isImplicitStatefulCodeRouteAvailable(undefined, 'https://code.example/v1')).toBe(true); + expect(isImplicitStatefulCodeRouteAvailable('0', 'https://code.example/v1')).toBe(false); expect(isImplicitStatefulCodeRouteAvailable('1', ' ')).toBe(false); }); }); diff --git a/packages/api/src/code/config.ts b/packages/api/src/code/config.ts index 619208ed0f..8e293d2760 100644 --- a/packages/api/src/code/config.ts +++ b/packages/api/src/code/config.ts @@ -1,6 +1,5 @@ import { logger } from '@librechat/data-schemas'; import { - CODE_ENVIRONMENT_DECISION_VERSION, CODE_ENVIRONMENT_MOVE_VERSION, CODE_ENVIRONMENT_TRANSITION_VERSION, CODE_WORKSPACE_RECOVERY_VERSION, @@ -12,6 +11,12 @@ import type { AccessibleCodeEnvironmentConfiguration, CodeEnvironmentPrincipalContext, } from './environments'; +import { resolveCodeEnvironmentDecisionVersion } from './protocol'; + +export { + resolveCodeEnvironmentDecisionVersion, + isCodeEnvironmentSelectionEnabled, +} from './protocol'; type ConfigurationRegistry = { listAccessibleConfigurations: ( @@ -25,18 +30,6 @@ type StatefulCodeConfig = NonNullable< >['statefulCodeSessions']; type CodeEnvironmentConfig = NonNullable['environments']>[number]; -/** - * Resolves the deployment-wide browser protocol gate. The exact version match - * keeps older and future wire shapes on the legacy-safe path. - */ -export function resolveCodeEnvironmentDecisionVersion( - configuredVersion?: string, -): typeof CODE_ENVIRONMENT_DECISION_VERSION | undefined { - return configuredVersion === String(CODE_ENVIRONMENT_DECISION_VERSION) - ? CODE_ENVIRONMENT_DECISION_VERSION - : undefined; -} - function conversationMovesEnabled(appConfig?: Pick | null): boolean { return ( appConfig?.endpoints?.[EModelEndpoint.agents]?.statefulCodeSessions?.conversationMoves diff --git a/packages/api/src/code/protocol.ts b/packages/api/src/code/protocol.ts new file mode 100644 index 0000000000..615b02dd2e --- /dev/null +++ b/packages/api/src/code/protocol.ts @@ -0,0 +1,33 @@ +import { + CODE_ENVIRONMENT_DECISION_VERSION, + isCodeEnvironmentSelectionAllowed, +} from 'librechat-data-provider'; + +/** + * Resolves the deployment-wide browser protocol gate. Unset or blank advertises the supported + * version, so per-chat machine choice works without a second opt-in. Any other value than the + * exact version — `0` to opt out, or an older or future wire shape — keeps the legacy-safe path. + */ +export function resolveCodeEnvironmentDecisionVersion( + configuredVersion?: string, +): typeof CODE_ENVIRONMENT_DECISION_VERSION | undefined { + const version = configuredVersion?.trim() ?? ''; + return version === '' || version === String(CODE_ENVIRONMENT_DECISION_VERSION) + ? CODE_ENVIRONMENT_DECISION_VERSION + : undefined; +} + +/** + * Per-chat machine choice is recorded through the decision protocol, so a deployment that turns + * the protocol off (`CODE_ENVIRONMENT_DECISION_VERSION=0`) turns machine choice off as well, for + * both what the server advertises and what it routes. + */ +export function isCodeEnvironmentSelectionEnabled( + allowEnvironmentSelection?: boolean | null, + configuredDecisionVersion: string | undefined = process.env.CODE_ENVIRONMENT_DECISION_VERSION, +): boolean { + return ( + isCodeEnvironmentSelectionAllowed(allowEnvironmentSelection) && + resolveCodeEnvironmentDecisionVersion(configuredDecisionVersion) != null + ); +} diff --git a/packages/api/src/endpoints/config/endpoints.spec.ts b/packages/api/src/endpoints/config/endpoints.spec.ts index e4a8839a37..112823cbaf 100644 --- a/packages/api/src/endpoints/config/endpoints.spec.ts +++ b/packages/api/src/endpoints/config/endpoints.spec.ts @@ -246,6 +246,8 @@ describe('createEndpointsConfigService', () => { expect(result?.[EModelEndpoint.agents]?.statefulCodeSessions).toEqual({ allowedEnvironments: ['user', 'agent-user'], + allowEnvironmentSelection: true, + maxEnvironmentChoices: 32, approvalsEnabled: false, approvalModes: [], environments: [ @@ -299,32 +301,68 @@ describe('createEndpointsConfigService', () => { expect(result?.[EModelEndpoint.agents]?.statefulCodeSessions).toEqual({ allowedEnvironments: ['user'], + allowEnvironmentSelection: true, + maxEnvironmentChoices: 32, approvalsEnabled: true, approvalModes: ['ask', 'acceptEdits', 'fullAccess'], environments: [], }); }); - it('advertises machine selection only when the deployment enables it', async () => { - const deps = createMockDeps({ - loadDefaultEndpointsConfig: jest.fn().mockResolvedValue({ - [EModelEndpoint.agents]: { userProvide: false, order: 0 }, - }), - getAppConfig: jest.fn().mockResolvedValue( - appConfig({ - endpoints: { - [EModelEndpoint.agents]: { - statefulCodeSessions: { allowEnvironmentSelection: true }, - }, - }, + it.each([ + [undefined, true], + [true, true], + [false, undefined], + ])( + 'advertises machine selection unless the deployment turns it off (configured: %p)', + async (allowEnvironmentSelection, advertised) => { + const deps = createMockDeps({ + loadDefaultEndpointsConfig: jest.fn().mockResolvedValue({ + [EModelEndpoint.agents]: { userProvide: false, order: 0 }, }), - ), - }); - const { getEndpointsConfig } = createEndpointsConfigService(deps); - const result = await getEndpointsConfig(fakeReq()); - expect(result?.[EModelEndpoint.agents]?.statefulCodeSessions?.allowEnvironmentSelection).toBe( - true, - ); + getAppConfig: jest.fn().mockResolvedValue( + appConfig({ + endpoints: { + [EModelEndpoint.agents]: { + statefulCodeSessions: { + ...(allowEnvironmentSelection === undefined + ? {} + : { allowEnvironmentSelection }), + }, + }, + }, + }), + ), + }); + const { getEndpointsConfig } = createEndpointsConfigService(deps); + const result = await getEndpointsConfig(fakeReq()); + const advertisedConfig = result?.[EModelEndpoint.agents]?.statefulCodeSessions; + expect(advertisedConfig?.allowEnvironmentSelection).toBe(advertised); + expect(advertisedConfig?.maxEnvironmentChoices).toBe(advertised ? 32 : undefined); + }, + ); + + it('does not advertise machine selection when the decision protocol is off', async () => { + process.env.CODE_ENVIRONMENT_DECISION_VERSION = '0'; + try { + const deps = createMockDeps({ + loadDefaultEndpointsConfig: jest.fn().mockResolvedValue({ + [EModelEndpoint.agents]: { userProvide: false, order: 0 }, + }), + getAppConfig: jest.fn().mockResolvedValue( + appConfig({ + endpoints: { [EModelEndpoint.agents]: { statefulCodeSessions: {} } }, + }), + ), + }); + const { getEndpointsConfig } = createEndpointsConfigService(deps); + const result = await getEndpointsConfig(fakeReq()); + expect( + result?.[EModelEndpoint.agents]?.statefulCodeSessions?.allowEnvironmentSelection, + ).toBeUndefined(); + } finally { + delete process.env.CODE_ENVIRONMENT_DECISION_VERSION; + } }); it.each([ diff --git a/packages/api/src/endpoints/config/endpoints.ts b/packages/api/src/endpoints/config/endpoints.ts index 825996d688..6e866c9b7d 100644 --- a/packages/api/src/endpoints/config/endpoints.ts +++ b/packages/api/src/endpoints/config/endpoints.ts @@ -12,6 +12,7 @@ import type { AppConfig } from '@librechat/data-schemas'; import type { ServerRequest, TCustomEndpointsConfig } from '~/types'; import type { GetAppConfigOptions } from '~/app/service'; import { loadCustomEndpointsConfig as defaultLoadCustomEndpoints } from '~/endpoints/custom'; +import { isCodeEnvironmentSelectionEnabled } from '~/code/protocol'; import { getAppConfigOptionsFromUser } from '~/app/service'; import { getResponsesApiRouting } from './responses'; @@ -103,7 +104,7 @@ export function createEndpointsConfigService(deps: EndpointsConfigDeps): { const clientStatefulCodeSessions = statefulCodeSessions ? { allowedEnvironments: statefulCodeSessions.allowedEnvironments, - ...(statefulCodeSessions.allowEnvironmentSelection === true + ...(isCodeEnvironmentSelectionEnabled(statefulCodeSessions.allowEnvironmentSelection) ? { allowEnvironmentSelection: true, maxEnvironmentChoices: diff --git a/packages/data-provider/src/code/workspace.ts b/packages/data-provider/src/code/workspace.ts index 1b6afad5aa..c18de19550 100644 --- a/packages/data-provider/src/code/workspace.ts +++ b/packages/data-provider/src/code/workspace.ts @@ -6,6 +6,25 @@ export const CODE_WORKSPACE_MAX_COUNT = 32; /** Wire/storage safety ceiling; deployments may set a lower per-agent choice limit. */ export const MAX_AGENT_CODE_ENVIRONMENT_CHOICES = 128; export const DEFAULT_AGENT_CODE_ENVIRONMENT_CHOICES = 32; + +/** + * Per-chat machine choice is on unless a deployment sets `allowEnvironmentSelection: false`. + * It only ever applies to agents whose author saved a machine allowlist; every other agent + * keeps its fixed machine either way. + */ +export function isCodeEnvironmentSelectionAllowed( + allowEnvironmentSelection?: boolean | null, +): boolean { + return allowEnvironmentSelection !== false; +} + +/** + * Linked-worktree lanes are on unless an environment sets `workspaces.linkedWorktrees: false`. + * They only apply where the worker advertises the `git_linked_worktree` scope. + */ +export function isLinkedWorktreeRoutingAllowed(linkedWorktrees?: boolean | null): boolean { + return linkedWorktrees !== false; +} /** API/client protocol for immutable conversation-owned environment decisions. */ export const CODE_ENVIRONMENT_DECISION_VERSION = 1 as const; /** API/client protocol for an owner's explicit move of a sealed environment decision. */ diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index 3ea0043fa2..461d4dc481 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -1347,8 +1347,8 @@ export const codeEnvironmentUserConfigSchema = z workspaces: z .object({ /** Run requests aimed at `.worktrees/` in that worktree's own lane when the - * worker advertises linked-worktree lanes. Omission keeps every request scoped to - * its checkout. */ + * worker advertises linked-worktree lanes. Omission allows it; `false` keeps every + * request scoped to its checkout. */ linkedWorktrees: z.boolean().optional(), /** Permit explicit per-conversation checkout choices after every API replica supports * them. Omission preserves automatic worker isolation and hides the selector. */ @@ -1526,8 +1526,8 @@ export const agentsEndpointSchema = baseEndpointSchema statefulCodeSessions: z .object({ allowedEnvironments: z.array(z.enum(STATEFUL_CODE_ENVIRONMENTS)).min(1), - /** Allow agents with a machine allowlist to use a chat-owned machine instead of their default. - * Enable after every API replica supports per-chat machine routing. */ + /** Let new chats pick a machine from their agent's saved allowlist instead of its default. + * Omission allows it; `false` keeps every agent on its fixed machine. */ allowEnvironmentSelection: z.boolean().optional(), /** Maximum additional machine choices saved on an agent (wire ceiling: 128). */ maxEnvironmentChoices: z