src/vs/platform/agentHost/common/codexSessionConfigKeys.ts
114 LOC · 114 covered · 0 uncovered · 13 ranges · 25 concepts · 7 introducers · 13 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
codexAgent.ts ×158
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Well-known session-config keys advertised by the agent-host Codex provider
* in its `resolveSessionConfig` schema.
*
* This file is intentionally protocol-free (no imports from the generated
* `node/protocol` types) so it can be shared with the browser pickers, which
* cannot import from the `node` layer. The string-literal unions below are
* declared to match — and are structurally assignable to — the corresponding
* generated Codex app-server types (`AskForApproval`, `SandboxMode`,
* `ApprovalsReviewer`). Protocol-typed narrowing helpers live alongside the
* node agent in `node/codex/codexSessionConfigKeys.ts`.
*/
export const enum CodexSessionConfigKey {
PermissionsPreset = 'codex.permissionsPreset',
ApprovalPolicy = 'codex.approvalPolicy',
SandboxMode = 'codex.sandboxMode',
AdditionalDirectories = 'codex.additionalDirectories',
NetworkAccessEnabled = 'codex.networkAccessEnabled',
WebSearchMode = 'codex.webSearchMode',
ModelReasoningEffort = 'codex.modelReasoningEffort',
Personality = 'codex.personality',
ReasoningSummary = 'codex.reasoningSummary',
}
/** Subset of the generated `AskForApproval` union that VS Code exposes. */
export type CodexApprovalPolicy = 'never' | 'on-request' | 'on-failure' | 'untrusted';
/** Mirrors the generated `SandboxMode` union. */
export type CodexSandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access';
/** Mirrors the generated `ApprovalsReviewer` union. */
export type CodexApprovalsReviewer = 'user' | 'auto_review' | 'guardian_subagent';
/**
* Codex collapses its three security axes (sandbox × approval policy ×
* approvals reviewer) into a single user-facing "permissions" preset, matching
* the selector in the Codex app and IDE extension.
*
* @see https://developers.openai.com/codex/concepts/sandboxing#how-you-control-it
*/
export type CodexPermissionsPreset = 'default' | 'auto-review' | 'full-access';
/** Ordered preset list advertised in the Codex session-config schema. */
export const CODEX_PERMISSIONS_PRESETS: readonly CodexPermissionsPreset[] = ['default', 'auto-review', 'full-access'];
/** Default preset applied to new Codex sessions. */
export const CODEX_DEFAULT_PERMISSIONS_PRESET: CodexPermissionsPreset = 'default';
/**
* Single source of truth for narrowing an arbitrary runtime value to the
* closed {@link CodexPermissionsPreset} union. Returns `undefined` for
* non-strings or unmatched strings; callers apply their own fallback.
*/
export function narrowCodexPermissionsPreset(raw: unknown): CodexPermissionsPreset | undefined {
case 'default':
case 'auto-review':
case 'full-access':
return undefined;
}
}
export interface ICodexResolvedPermissions {
readonly approvalPolicy: CodexApprovalPolicy;
readonly sandboxMode: CodexSandboxMode;
readonly approvalsReviewer: CodexApprovalsReviewer;
}
/**
* Expand a {@link CodexPermissionsPreset} into the three underlying Codex
* security axes sent to the app-server (`approvalPolicy`, `sandbox`,
* `approvalsReviewer`).
*/
export function resolveCodexPermissionsPreset(preset: CodexPermissionsPreset): ICodexResolvedPermissions {
case 'auto-review':
// Same workspace-write sandbox as `default`, but on-request approvals
codexSessionConfigKeys.ts ×2
// are routed through the auto-reviewer instead of a UI prompt.
return { approvalPolicy: 'on-request', sandboxMode: 'workspace-write', approvalsReviewer: 'auto_review' };
return { approvalPolicy: 'never', sandboxMode: 'danger-full-access', approvalsReviewer: 'user' };
codexSessionConfigKeys.ts ×2
default:
return { approvalPolicy: 'on-request', sandboxMode: 'workspace-write', approvalsReviewer: 'user' };
}
}
/**
* Inverse of {@link resolveCodexPermissionsPreset}: find the preset whose
* expanded axes exactly match the given resolved permissions, or `undefined`
* when no preset can represent them (e.g. a `read-only` sandbox, which no
* preset expands to).
*
* Used when restoring a legacy session that persisted the individual security
* axes but no preset: if the axes map cleanly onto a preset we can migrate them
* to the modern single-preset representation; otherwise the raw axes must be
* preserved so they are not silently escalated.
*/
export function presetForResolvedPermissions(resolved: ICodexResolvedPermissions): CodexPermissionsPreset | undefined {
const axes = resolveCodexPermissionsPreset(preset);
if (axes.approvalPolicy === resolved.approvalPolicy && axes.sandboxMode === resolved.sandboxMode && axes.approvalsReviewer === resolved.approvalsReviewer) {
return preset;
}
}
}