Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Config key for the numeric "Context Size" selection (a context-window token count). Mapped to the
* SDK's two-valued {@link SessionConfig.contextTier} by {@link getCopilotContextTier}.
*/
export
const
=
'contextSize'
;
/**
* @deprecated Legacy config key that stored the resolved tier string (`'default'` / `'long_context'`)
* directly. Replaced by the numeric {@link ContextSizeConfigKey}; still read from persisted sessions
* for backward compatibility.
*/
export
const
=
'contextTier'
;
/**
* Config key for the Auto model's routing-profile ("Optimize for") selection. Named to match the
* Copilot Chat extension's `AUTO_MODE_TIER_PROPERTY` so both Auto surfaces use the same picker key.
*/
export
const
=
'tier'
;
/**
* Every reasoning-effort tier that the runtime may advertise via a model's
* `supportedReasoningEfforts`. This is intentionally broader than the SDK's
* `SessionConfig['reasoningEffort']` union, which lags behind newly-introduced
* tiers such as `'max'`; values are passed through to the runtime as-is.
*
* Aliased from the canonical list rather than re-declared: a private copy that
* misses a tier silently drops it from the model picker, which is exactly how
* `'max'` went missing.
*/
const
=
;
type
AgentHostReasoningEffort
=
;
function
disabledMcpServersSessionOption
(
:
readonly
[
]
,
:
readonly
string
[
]
|
undefined
,
:
readonly
string
[
]
|
undefined
)
:
<
>
{
const
=
[
...
new
Set
(
[
...
.
flatMap
(
=>
.
??
[
]
)
,
...
(
??
[
]
)
,
...
(
??
[
]
)
,
]
)
]
;
return
.
>
0
?
{
}
:
{
}
;
}
/**
* Returns whether Agent Host must include the server in `SessionConfig.mcpServers` instead of leaving it to SDK plugin discovery.
*/
export
function
isMcpServerExplicitlyProjected
(
:
)
:
boolean
{
return
.
===
'sessionConfig'
;
}
/**
* Narrows a reasoning-effort value to the SDK's declared union. The SDK type is
* a strict subset of the tiers the runtime accepts, so newer tiers are forwarded
* unchanged rather than dropped.
*/
export
function
toSdkReasoningEffort
(
:
|
undefined
)
:
[
'reasoningEffort'
]
{
return
as
[
'reasoningEffort'
]
;
}
const
=
[
'default'
,
'long_context'
]
as
const
;
const
AGENT_HOST_COPILOT_CLIENT_NAME
=
'vscode-agent-host'
;
/**
* The SDK's CAPI options widened with `autoTier`. The published SDK types still declare only
* `enableWebSocketResponses`; drop the widening once they catch up.
*/
type
CapiSessionOptionsWithAutoTier
=
<
[
'capi'
]
>
&
{
?
:
}
;
type
UserInputHandler
=
<
[
'onUserInputRequest'
]
>
;
type
UserInputRequest
=
<
>
[
0
]
;
type
UserInputInvocation
=
<
>
[
1
]
;
type
UserInputResponse
=
<
<
>>
;
type
McpAuthHandler
=
<
[
'onMcpAuthRequest'
]
>
;
type
McpAuthRequest
=
<
>
[
0
]
;
type
McpAuthContext
=
<
>
[
1
]
;
type
McpAuthResponse
=
<
<
>>
;
type
PreToolUseHookInput
=
<
<
[
'onPreToolUse'
]
>>
[
0
]
;
type
PostToolUseHookInput
=
<
<
[
'onPostToolUse'
]
>>
[
0
]
;
/**
* Immutable snapshot of the active client's structural contributions at
* session creation time. Used to detect when the session needs to be
* refreshed. Root MCP servers participate in restart detection because they
* are merged into the SDK session config. The owning `clientId`s are
* deliberately NOT part of this snapshot: client identity is tracked live via
* {@link ActiveClientToolSet} so a window
* reload (new `clientId`, identical tools/plugins) does not force a restart.
*/
export
interface
IActiveClientSnapshot
{
readonly
:
readonly
[
]
;
readonly
:
readonly
[
]
;
readonly
:
;
}
/**
* The set of client-tool names the agent sees for a snapshot — each tool's
* `ToolDefinition.name` (the camelCase `toolReferenceName`). Gates prompt
* sections at launch and routes client tool calls, so the two stay derived from
* one definition.
*/
export
function
clientToolNamesFromSnapshot
(
:
)
:
<
string
>
{
return
new
Set
(
.
.
map
(
=>
.
)
)
;
}
/**
* Narrows the names that gate prompt content so the system message never
* advertises a tool the filters disabled. Client tools are `custom:`-source even
* when they override a built-in, so bare-name and `custom:` forms match (the
* tool-search tool under either of its names). Routing keeps the unfiltered
* set — the runtime is the enforcement point.
*/
export
function
filterClientToolNames
(
:
<
string
>
,
:
readonly
string
[
]
|
undefined
,
:
readonly
string
[
]
|
undefined
)
:
<
string
>
{
if
(
!
&&
!
)
{
return
;
}
const
matches
=
(
:
readonly
string
[
]
,
:
string
)
=>
{
const
=
toSdkClientToolName
(
)
;
return
.
some
(
=>
===
||
===
||
===
`custom:${name}`
||
===
`custom:${sdkName}`
||
===
'custom:*'
)
;
}
;
const
=
new
Set<string>
(
)
;
for
(
const
of
)
{
const
=
!
||
matches
(
,
)
;
if
(
&&
!
(
&&
matches
(
,
)
)
)
{
.
add
(
)
;
}
}
return
;
}
/** The SDK-registered name for a client tool; only the tool-search tool differs. */
function
toSdkClientToolName
(
:
string
)
:
string
{
return
===
CLIENT_TOOL_SEARCH_REFERENCE_NAME
?
RUNTIME_TOOL_SEARCH_TOOL_NAME
:
;
}
/** Maps Agent Host reference names to the names registered with the SDK. */
/**
* Creates an unowned SDK session wrapper. The caller is responsible for
* registering or disposing the returned wrapper.
*/
launch
(
:
,
:
)
:
Promise
<
>
;
}
type
CopilotSessionClient
=
<
,
'createSession'
|
'resumeSession'
>
;
interface
ICopilotSessionLaunchBase
{
readonly
:
;
readonly
:
string
;
/** Whether this launch is for a transient session that skips durable-only provider work. */
readonly
?
:
boolean
;
/**
* Whether the owning chat surface is scoped to editing a single file, so
* blanket shell auto-approvals must not apply. See
* {@link IAgentCreateChatOptions.hasScopedEditSurface}.
*/
readonly
?
:
boolean
;
readonly
:
URI
|
undefined
;
/**
* The additional working directories beyond the primary process root
* ({@link workingDirectory} = index 0). These are the peer roots of a
* multi-root session's ordered set — the directories the agent should be
* granted tool access to in addition to its process cwd. Empty (or absent)
* for a single-root session. Passed through so the SDK can register them as
* extra accessible roots once that surface is available; the process still
* launches in {@link workingDirectory}.
*/
readonly
?
:
readonly
URI
[
]
;
readonly
:
string
|
undefined
;
readonly
:
;
/** Root-configured MCP servers disabled by the owning session's resolved customization state. */
readonly
?
:
readonly
string
[
]
;
/**
* Live, long-lived registry of every active client's tool contributions.
* Read at tool-call stamp time so a window reload (new `clientId`,
* identical tools) stamps subsequent client tool calls with the current
* owning id rather than the one frozen into {@link snapshot} at creation,
* and so a tool call is attributed to whichever client contributed it.
*/
readonly
:
;
readonly
:
|
undefined
;
readonly
:
string
|
undefined
;
/**
* Whether this is a workspace-less session. Threaded into the
* prompt context so the resolved system message gets the scratch/repoless
* variant. Named to match the `workspaceless` marker used throughout the AH
* layer (session `_meta`, stored metadata) that this value flows from.
*/
readonly
?
:
boolean
;
}
export
interface
ICopilotCreateSessionLaunchPlan
extends
ICopilotSessionLaunchBase
{
readonly
:
'create'
;
readonly
:
|
undefined
;
readonly
?
:
number
;
readonly
?
:
boolean
;
}
export
interface
ICopilotResumeSessionLaunchPlan
extends
ICopilotSessionLaunchBase
{
readonly
:
'resume'
;
readonly
:
URI
;
readonly
:
{
readonly
:
|
undefined
;
readonly
?
:
number
;
readonly
?
:
boolean
;
}
;
}
export
type
CopilotSessionLaunchPlan
=
|
;
export
function
isCopilotReasoningEffort
(
:
unknown
)
:
is
{
return
.
some
(
=>
===
)
;
}
function
isContextTier
(
:
unknown
)
:
is
{
return
.
some
(
=>
===
)
;
}
function
getCopilotSdkErrorCode
(
:
unknown
)
:
number
|
undefined
{
if
(
typeof
!==
'object'
||
===
null
)
{
return
undefined
;
}
const
=
.
getOwnPropertyDescriptor
(
,
'code'
)
?.
;
return
typeof
===
'number'
?
:
undefined
;
}
function
getErrorMessage
(
:
unknown
)
:
string
{
if
(
instanceof
Error
)
{
return
.
;
}
if
(
typeof
===
'object'
&&
!==
null
)
{
const
=
.
getOwnPropertyDescriptor
(
,
'message'
)
?.
;
if
(
typeof
===
'string'
)
{
return
;
}
}
return
String
(
)
;
}
/**
* Messages from a failed Copilot SDK `session.resume` that positively indicate
* the session has no events on disk, so there is no history to lose. Includes
* the post-"Start Over" case, where `truncateChat` leaves zero events.
*/
const
RESUMABLE_HISTORY_ABSENT_PATTERNS
=
[
/\bSession not found\b/i
,
/\bno events\b/i
,
/\bempty session\b/i
,
]
;
/**
* Decide whether a Copilot SDK `resumeSession` failure should fall back to
* `createSession({ sessionId })`, which presents the session as having no
* history. Deliberately an allowlist: a fallback on an unrelated failure (a
* transient `network fetch failed` is also `-32603`) discards a live session's
* history and leaves it exposed to empty-session GC.
*/
function
shouldCreateEmptySessionAfterResumeError
(
:
unknown
)
:
boolean
{
if
(
getCopilotSdkErrorCode
(
)
!==
-
32603
)
{
return
false
;
}
const
=
getErrorMessage
(
)
;
return
RESUMABLE_HISTORY_ABSENT_PATTERNS
.
some
(
=>
.
test
(
)
)
;
}
function
isCustomAgentNotFoundError
(
:
unknown
)
:
boolean
{
return
getCopilotSdkErrorCode
(
)
===
-
32603
&&
/\bCustom agent '.+' not found\b/i
.
test
(
getErrorMessage
(
)
)
;
}
/**
* Resolves the reasoning effort: a recognized override level wins over the
* model picker's thinking level; an unrecognized override is ignored (degrades
* to the picker). Validation is against the known effort levels only — the
* caller/operator is responsible for choosing a level the model supports.
*/
export
function
getCopilotReasoningEffort
(
:
|
undefined
,
?
:
string
)
:
[
'reasoningEffort'
]
{
if
(
isCopilotReasoningEffort
(
)
)
{
return
toSdkReasoningEffort
(
)
;
}
const
=
?.
?.
[
]
;
return
isCopilotReasoningEffort
(
)
?
toSdkReasoningEffort
(
)
:
undefined
;
}
/** Log label for a session's model; a session may have none (server-side "Auto"). */
function
describeModelId
(
:
|
undefined
)
:
string
{
return
?.
??
'(no model)'
;
}
/**
* The configured reasoning-effort override alone, with no picker fallback.
* Keyed by the un-aliased model id, falling back to the `*` entry; `undefined`
* means no override is configured.
*/
export
function
resolveConfiguredReasoningEffortOverride
(
:
|
undefined
,
:
<
,
'getRootValue'
>
,
:
,
:
string
)
:
[
'reasoningEffort'
]
{
const
=
.
getRootValue
(
,
.
)
;
const
=
resolveModelCapabilityOverrideField
(
,
?.
,
'reasoningEffort'
,
,
=>
{
.
warn
(
`[Copilot:${sessionId}] Ignoring invalid reasoning-effort override '${value}' for '${describeModelId(model)}'; expected one of [${ReasoningEfforts.join(', ')}]`
)
;
}
)
;
if
(
!==
undefined
)
{
.
info
(
`[Copilot:${sessionId}] Applying reasoning-effort override '${effort}' for '${describeModelId(model)}'`
)
;
return
toSdkReasoningEffort
(
)
;
}
return
undefined
;
}
/**
* The configured override over the picker's thinking level. Shared by the
* launcher and `CopilotAgent._changeModel` so both resolve it the same way.
*/
export
function
resolveCopilotReasoningEffort
(
:
|
undefined
,
:
<
,
'getRootValue'
>
,
:
,
:
string
)
:
[
'reasoningEffort'
]
{
return
resolveConfiguredReasoningEffortOverride
(
,
,
,
)
??
getCopilotReasoningEffort
(
)
;
}
/**
* Shape-checked only: the SDK deep-merges this over its own defaults and ignores
* unrecognized keys, so field-level validation belongs at that boundary.
*/
function
getModelCapabilitiesOverride
(
:
<
string
,
unknown
>
|
undefined
,
:
string
,
:
,
:
string
)
:
|
undefined
{
if
(
===
undefined
)
{
return
undefined
;
}
.
info
(
`[Copilot:${sessionId}] Applying 'modelCapabilities' capability override for '${modelId}'`
)
;
return
as
;
}
/** The sources a bare `'*'` means; the SDK only accepts source-qualified wildcards. */
const
TOOL_FILTER_SOURCE_WILDCARDS
=
[
'builtin:*'
,
'mcp:*'
,
'custom:*'
]
;
/**
* The patterns in a tool-filter override, or `undefined` when the value is not a
* list (a lone string reads as one entry). A bare `'*'` expands to the source
* wildcards: the SDK throws on the bare form, and dropping it would turn
* "exclude everything" into "exclude nothing". Pure, so the launcher and
* {@link CopilotAgentSession} gate on the same set without duplicate logging.
*/
export
function
normalizeToolFilterPatterns
(
:
unknown
)
:
string
[
]
|
undefined
{
const
=
typeof
===
'string'
?
[
]
:
;
if
(
!
isStringArray
(
)
)
{
return
undefined
;
}
// `[]` is preserved, not collapsed to "unset": an empty allowlist means "no
// tools", and dropping it would enable every tool instead.
return
[
...
new
Set
(
.
flatMap
(
=>
===
'*'
?
TOOL_FILTER_SOURCE_WILDCARDS
:
[
]
)
)
]
;
}
/**
* {@link normalizeToolFilterPatterns} plus the launch-time log line. The field
* resolver already rejected unusable values, so the input normalizes cleanly.
*/
function
getToolFilterOverride
(
:
string
|
readonly
string
[
]
|
undefined
,
:
string
,
:
string
,
:
,
:
string
)
:
string
[
]
|
undefined
{
const
=
!==
undefined
?
normalizeToolFilterPatterns
(
)
:
undefined
;
if
(
!==
undefined
)
{
.
info
(
`[Copilot:${sessionId}] Applying '${field}' capability override for '${modelId}': ${patterns.join(', ')}`
)
;
}
return
;
}
export
function
getCopilotContextTier
(
:
|
undefined
,
?
:
number
,
?
:
boolean
)
:
[
'contextTier'
]
{
// Legacy persisted selections stored the resolved tier string directly under the deprecated key.
const
=
?.
?.
[
]
;
if
(
isContextTier
(
)
)
{
return
;
}
// The "Context Size" picker exposes numeric token-count enum values, so a current selection arrives
// under `contextSize` as a token count. Map it to the SDK's two-valued tier using the model's
// long-context window: only a selection that reaches that window opts into `long_context`. Without
// the window (model exposes no picker, or the model list isn't loaded) leave the SDK on its default
// tier.
const
=
?.
?.
[
]
;
if
(
===
undefined
)
{
// No selection: free long context defaults to the full window; other models stay on the SDK default tier.
return
?
'long_context'
:
undefined
;
}
const
=
Number
(
)
;
if
(
!
.
isFinite
(
)
||
typeof
!==
'number'
)
{
return
undefined
;
}
return
>=
?
'long_context'
:
'default'
;
}
/**
* The Auto routing profile ("Optimize for") a session should launch with. Only the Auto model routes
* per turn, so a profile left on another model by an earlier selection is ignored.
*/
export
function
getCopilotAutoTier
(
:
|
undefined
)
:
|
undefined
{
if
(
!
isAutoModel
(
?.
)
)
{
return
undefined
;
}
const
=
?.
?.
[
]
;
return
isAutoModeTier
(
)
?
:
undefined
;
}
/**
* {@link getCopilotAutoTier} behind the `autoModeTiers` gate. Re-read here rather than trusted from
* the picker schema, since the runtime rejects unknown `capi` fields and would fail the session.
*/
export
function
resolveCopilotAutoTier
(
:
|
undefined
,
:
<
,
'getRootValue'
>
,
:
,
:
string
)
:
|
undefined
{
const
=
getCopilotAutoTier
(
)
;
if
(
===
undefined
)
{
return
undefined
;
}
if
(
.
getRootValue
(
,
.
)
!==
true
)
{
.
trace
(
`[Copilot:${sessionId}] Auto routing profiles are disabled; ignoring '${tier}'`
)
;
return
undefined
;
}
.
info
(
`[Copilot:${sessionId}] Launching Auto session with the '${tier}' routing profile`
)
;
return
;
}
/**
* The CAPI session options for a routing profile. Omitting `capi` entirely, rather than sending an
* empty profile, is what leaves the runtime on its default routing.
*/
export
function
toSdkCapiSessionOptions
(
:
|
undefined
)
:
<
,
'capi'
>
{
if
(
===
undefined
)
{
return
{
}
;
}
const
:
=
{
}
;
return
{
}
;
}
/**
* Resolve the BYOK provider/model session config for `sessionId` from the
* renderer's active bridge. Returns empty — the session launches without BYOK
* models — when BYOK is gated off (no active bridge), when the renderer reports
* no BYOK models, or when enumeration fails; `startProxy` is invoked only once
* at least one model is present.
*
* Each vendor maps to one `type: 'openai'` / `wireApi: 'responses'` provider
* whose `baseUrl` points at the proxy and authenticates with the session-scoped
* `Bearer <nonce>.<sessionId>`; each model is surfaced under the
* provider-qualified selection id `vendor/[group/]id`, matching what the renderer's
* `AgentHostByokLmHandler` resolves.
*
* Extracted from {@link CopilotSessionLauncher} so the synthesis and gating are
* unit-testable without instantiating the launcher; the launcher passes a
* `startProxy` thunk that memoizes the single shared proxy handle.
*/
export
async
function
resolveByokSessionConfig
(
:
string
,
:
,
startProxy
:
(
)
=>
Promise
<
>
,
:
,
)
:
Promise
<
{
?
:
[
]
;
?
:
[
]
}
>
{
// Surface the serving window's BYOK models. The registry does not union
// windows' model sets — all serving windows expose the same set, so it picks
// one (see `IByokLmBridgeRegistry`) and the proxy routes inference there.
let
:
[
]
;
try
{
=
[
...
.
getModels
(
)
]
;
}
catch
(
)
{
.
warn
(
`[Copilot:${sessionId}] Failed to enumerate BYOK models from renderer bridges`
,
)
;
return
{
}
;
}
if
(
.
===
0
)
{
return
{
}
;
}
// Deduplicate by group-qualified selection id (`vendor/[group/]id`). The same BYOK model can be
// reported more than once — e.g. when two renderer bridges are transiently
// serving during a window hand-off (continuing a chat into a new session) —
// and the runtime rejects a session config with duplicate BYOK model
// selection ids ("Duplicate BYOK model selection id ...").
const
=
new
Set<string>
(
)
;
=
.
filter
(
=>
{
const
=
`${m.vendor}/${getByokLmSelectionModelId(m)}`
;
if
(
.
has
(
)
)
{
return
false
;
}
.
add
(
)
;
return
true
;
}
)
;
// `startProxy` binds a local loopback listener — unlikely to fail, but it
// must never break session materialization (which fires the cross-window
// `sessionAdded` broadcast). Degrade to no BYOK config on failure.
let
:
;
try
{
=
await
startProxy
(
)
;
}
catch
(
)
{
.
warn
(
`[Copilot:${sessionId}] Failed to start BYOK loopback proxy`
,
)
;
return
{
}
;
}
const
:
[
]
=
[
...
new
Set
(
.
map
(
=>
.
)
)
]
.
map
(
=>
(
{
:
,
:
'openai'
,
:
'responses'
,
:
.
providerBaseUrl
(
)
,
:
`${handle.nonce}.${sessionId}`
,
}
)
)
;
const
:
[
]
=
.
map
(
=>
(
{
:
getByokLmSelectionModelId
(
)
,
:
.
,
...
(
.
!==
undefined
?
{
:
.
}
:
{
}
)
,
...
(
.
!==
undefined
?
{
:
.
}
:
{
}
)
,
}
)
)
;
.
info
(
`[Copilot:${sessionId}] Wired ${models.length} BYOK model(s) across ${providers.length} provider(s) via loopback proxy ${handle.baseUrl}`
)
;
return
{
,
}
;
}
export
class
CopilotSessionLauncher
implements
ICopilotSessionLauncher
{
/**
* Memoized handle for the single shared BYOK loopback proxy, started lazily
* on the first session launch that surfaces BYOK models (see
* {@link _resolveByokSessionConfig}). Held as a promise so concurrent
* launches share one bind. Released and cleared by
* {@link disposeByokProxyHandle} when the owning Copilot client/runtime is
* stopped, so the next start mints a fresh nonce.
*/
// Create-time only: the runtime then owns the profile, keeping it fixed while the session is
// resident and restoring it on cold resume.
...
toSdkCapiSessionOptions
(
resolveCopilotAutoTier
(
.
,
this
.
,
this
.
,
.
)
)
,
...
(
.
?
{
:
.
}
:
{
}
)
,
:
.
?.
,
}
)
)
;
return
this
.
_finalizeSession
(
,
,
.
,
.
?.
)
;
}
private
async
_finalizeSession
(
:
[
'session'
]
,
:
|
undefined
,
:
string
,
:
string
|
undefined
)
:
Promise
<
>
{
await
this
.
_applySandboxConfig
(
,
,
)
;
try
{
await
this
.
_applyScriptSafety
(
,
)
;
}
catch
(
)
{
// Nothing owns `raw` until it is wrapped below, so a fail-closed launch has
// to disconnect it here or the runtime keeps an orphaned session alive.
await
.
disconnect
(
)
.
catch
(
(
)
=>
{
/* best-effort teardown */
}
)
;
throw
;
}
// TODO: Remove these post-launch updates once the SDK exposes verbosity and
// reasoningSummary in SessionConfig, alongside launch options such as reasoningEffort.
if
(
isGpt56Model
(
)
)
{
await
this
.
_applyGpt56Customizations
(
,
)
;
}
return
new
CopilotSessionWrapper
(
)
;
}
/**
* Enables the runtime's shell-script safety classifier, which managed permissions
* depend on to govern shell operations.
*
* Without it the runtime short-circuits the classifier, so a shell command reaches
* the permission layer with an empty `possiblePaths` and `hasWriteFileRedirection:
* false`. Managed `Read(...)`/`Edit(...)` rules then cannot match a redirect target,
* letting `echo ... >> denied/path` bypass a managed deny. The Copilot CLI opts in at
* session creation; the SDK exposes it to hosts only through `options.update`, so it
* is applied here to cover both created and resumed sessions.
*
* This fails the launch closed unconditionally. The host cannot tell whether a
* session is policy-bearing: `IAgentHostManagedSettingsService` only carries the
* legacy VS Code settings bridge, which is itself behind a false-by-default
* compatibility setting, while server and MDM policy is discovered by the runtime
* itself under `enableManagedSettings`. Gating a security control on that signal
* would leave exactly the enterprise sessions it protects unprotected, so the
* option is treated as required for every session.
*
* The client-level `managedSettings.read` is not a usable substitute: it discovers
* only device sources (MDM and managed-file), so a session governed solely by
* GitHub org policy would still read as unmanaged. Approximating the boundary is
* worse than not drawing one.
*/
private
async
_applyScriptSafety
(
:
[
'session'
]
,
:
string
)
:
Promise
<
void
>
{
try
{
const
=
await
.
.
.
update
(
{
:
true
}
)
;
if
(
!
.
)
{
throw
new
Error
(
'SDK rejected enabling script safety'
)
;
}
}
catch
(
)
{
// The runtime reports success for any patch it accepts and signals real
// problems by failing the request, so this is the path a genuine failure
// takes. Log the reason before it propagates: the launch is aborted below
// and the raw RPC error alone would not say which option was refused.
this
.
.
error
(
`[Copilot:${sessionId}] Could not enable script safety; managed permissions cannot govern shell paths`
,
)
;
throw
;
}
}
/** Applies the post-launch session options used by GPT-5.6 models. */
private
async
_applyGpt56Customizations
(
:
[
'session'
]
,
:
string
)
:
Promise
<
void
>
{
await
this
.
_applyVerbosity
(
,
'medium'
,
)
;
const
=
this
.
.
getRootValue
(
,
.
)
===
true
;
if
(
)
{
await
this
.
_applyReasoningSummary
(
,
'concise'
,
)
;
}
}
/** Sets output verbosity after session creation. */
`[Copilot:${sessionId}] Failed to apply '${reasoningSummary}' reasoning summary`
,
)
;
}
}
/**
* Compute the SDK-shaped sandbox policy to push to the runtime for the
* SDK's built-in shell tool.
*
* Returns `undefined` when {@link CopilotCliConfigKey.EnableCustomTerminalTool}
* is ON — in that case the AgentHost provides its own shell tools, which
* wrap commands via the host terminal sandbox engine, so no SDK-side
* sandbox policy is needed. Otherwise the policy is derived from the
* host's `sandbox` config bag (forwarded from the workbench's
* `chat.agent.sandbox.*` settings), mirroring what
* `buildSandboxConfigForCLI` does for the Copilot extension's CLI path.
*/
private
_computeSandboxConfig
(
)
:
|
undefined
{
const
=
this
.
.
getRootValue
(
,
.
)
===
true
;
if
(
)
{
return
undefined
;
}
return
buildSandboxConfigForSdk
(
.
,
this
.
.
getRootValue
(
,
.
)
)
;
}
/**
* Forward the SDK-shaped sandbox policy to the runtime via
* `session.options.update`, immediately after the session is created or
* resumed.
*
* No-op when {@link _computeSandboxConfig} returned `undefined` (custom
* terminal tool enabled, or the host sandbox config evaluates to disabled).
*/
private
async
_applySandboxConfig
(
:
[
'session'
]
,
:
|
undefined
,
:
string
)
:
Promise
<
void
>
{
if
(
!
)
{
return
;
}
try
{
await
.
.
.
update
(
{
}
)
;
this
.
.
info
(
`[Copilot:${sessionId}] Applied SDK sandboxConfig via session.options.update`
)
;
}
catch
(
)
{
this
.
.
warn
(
`[Copilot:${sessionId}] Failed to apply SDK sandboxConfig`
,
)
;
}
}
/**
* Launcher-bound wrapper over {@link resolveByokSessionConfig}: supplies the
* active bridge registry and a `startProxy` thunk that memoizes the single
* shared proxy handle for this launcher (started lazily on first use).
*/
/**
* Release the memoized BYOK loopback proxy handle (if any) and clear it so
* the next session launch mints a fresh nonce. Idempotent.
*
* **Ownership invariant.** The caller MUST stop the Copilot client/runtime
* subprocess before invoking this: disposing the handle drops the proxy's
* refcount and may rebind it on a different port/nonce, so a still-running
* subprocess would silently lose its endpoint — see {@link IByokLmProxyHandle}.
* Invoked from `CopilotAgent._stopClient` / `CopilotAgent.shutdown` after the
* client has stopped.
*/
async
disposeByokProxyHandle
(
)
:
Promise
<
void
>
{
const
=
this
.
;
this
.
=
undefined
;
if
(
!
)
{
return
;
}
try
{
(
await
)
.
dispose
(
)
;
}
catch
{
// The lazy `start()` rejected; there is nothing to release.
}
}
private
async
_buildSessionConfig
(
:
,
:
)
:
Promise
<
>
{
const
=
.
.
;
// Synthesize BYOK provider/model config (empty when BYOK is gated off or the
// renderer reports no BYOK models), merged into the returned config so both
// createSession and resumeSession advertise the models to the runtime.
const
=
await
this
.
_resolveByokSessionConfig
(
.
)
;
const
=
this
.
.
getRootValue
(
,
.
)
===
true
;
let
:
<
<
typeof
>>
=
[
]
;
if
(
)
{
if
(
!
.
)
{
throw
new
Error
(
`ShellManager is required to launch Copilot session '${plan.sessionId}'`
)
;
}
=
await
createShellTools
(
.
,
.
,
this
.
,
this
.
,
=>
.
requestUnsandboxedCommandConfirmation
(
)
)
;
}
// Rely on the SDK to discover most agents/skills/etc. from `pluginDirectories`
// instead of feeding them explicitly, to avoid duplicates. Custom agents are the
// exception: the SDK validates the session-start `agent:` against `customAgents`
// by name, so the selected agent is force-included (see `toSdkSessionCustomAgents`).
const
=
.
filter
(
=>
!
.
||
.
.
!==
.
)
;
const
=
.
?
[
]
:
.
flatMap
(
=>
.
.
filter
(
=>
!
.
?.
includes
(
.
)
&&
isMcpServerExplicitlyProjected
(
)
)
)
;
// An ephemeral session skips the explicit enumeration (and its file I/O). The SDK can
// still discover agents from `pluginDirectories`; suppressing that too would also drop
// skills and instructions, so it is left alone.
const
=
.
?
[
]
:
await
toSdkSessionCustomAgents
(
,
.
,
this
.
)
;
const
=
toSdkSkillDirectories
(
.
flatMap
(
=>
.
)
)
;
const
=
toSdkInstructionDirectories
(
.
flatMap
(
=>
.
)
)
;
const
=
.
===
'create'
?
.
:
.
.
;
// Keyed by the real, un-aliased model id; a model-less "Auto" session
// matches the `*` entry only.
const
=
this
.
.
getRootValue
(
,
.
)
;
const
=
describeModelId
(
)
;
const
=
resolveModelCapabilityOverrideField
(
,
?.
,
'family'
,
(
)
:
is
string
=>
normalizeModelFamilyAlias
(
)
!==
undefined
,
=>
{
const
=
typeof
===
'string'
?
JSON
.
stringify
(
.
slice
(
0
,
40
)
)
:
typeof
;
this
.
.
warn
(
`[Copilot:${plan.sessionId}] Ignoring invalid 'family' capability override ${description} for '${modelId}'; expected a model id of at most 128 characters`
)
;
}
)
;
// Re-applied on every launch and resume, but NOT on a mid-session model
// change: a session keeps the filters of the model it launched with.
const
=
resolveModelCapabilityOverrideField
(
,
?.
,
'availableTools'
,
(
)
:
is
string
|
readonly
string
[
]
=>
normalizeToolFilterPatterns
(
)
!==
undefined
,
(
)
=>
{
this
.
.
warn
(
`[Copilot:${plan.sessionId}] Ignoring unusable 'availableTools' capability override for '${modelId}'; expected an array of tool patterns`
)
;
}
)
;
const
=
resolveModelCapabilityOverrideField
(
,
?.
,
'excludedTools'
,
(
)
:
is
string
|
readonly
string
[
]
=>
normalizeToolFilterPatterns
(
)
!==
undefined
,
(
)
=>
{
this
.
.
warn
(
`[Copilot:${plan.sessionId}] Ignoring unusable 'excludedTools' capability override for '${modelId}'; expected an array of tool patterns`
)
;
}
)
;
const
=
getToolFilterOverride
(
,
'availableTools'
,
,
this
.
,
.
)
;
const
=
getToolFilterOverride
(
,
'excludedTools'
,
,
this
.
,
.
)
;
const
=
toSdkToolFilterPatterns
(
)
;
const
=
.
?
[
...
(
toSdkToolFilterPatterns
(
)
??
[
]
)
,
...
EPHEMERAL_DISABLED_COPILOT_TOOLS
]
:
toSdkToolFilterPatterns
(
)
;
const
=
filterClientToolNames
(
clientToolNamesFromSnapshot
(
.
)
,
,
)
;
const
=
.
has
(
SEMANTIC_SEARCH_TOOL_NAME
)
?
:
[
...
new
Set
(
[
...
(
??
[
]
)
,
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
)
]
;
const
=
resolveModelCapabilityOverrideField
(
,
?.
,
'modelCapabilities'
,
(
)
:
is
<
string
,
unknown
>
=>
isObject
(
)
,
(
)
=>
{
this
.
.
warn
(
`[Copilot:${plan.sessionId}] Ignoring invalid 'modelCapabilities' capability override for '${modelId}'; expected an object`
)
;
}
)
;
const
=
getModelCapabilitiesOverride
(
,
,
this
.
,
.
)
;
// Host-side routing only — the prompt contributor and the tool-search gate
// below. The wire model stays the selected one, so the session still runs
// on the real model with the aliased family's prompt and tool profile.
const
=
?
{
...
,
:
}
:
;
if
(
)
{
this
.
.
info
(
`[Copilot:${plan.sessionId}] Model capability override: routing prompt for '${describeModelId(model)}' as family '${modelFamily}'`
)
;
}
const
=
this
.
.
getRootValue
(
,
.
)
===
true
&&
agentHostModelSupportsToolSearch
(
?.
)
&&
.
has
(
CLIENT_TOOL_SEARCH_REFERENCE_NAME
)
;
const
=
normalizeToolSearchDeferThreshold
(
this
.
.
getRootValue
(
,
.
)
)
;
const
=
this
.
.
;
const
:
=
{
getSetting
:
=>
this
.
.
getRootValue
(
,
)
,
hasClientTool
:
=>
.
has
(
)
,
:
.
===
true
,
,
}
;
const
=
.
?.
map
(
=>
.
)
;
// Resolved once per (re)launch — the SDK has no mid-session system-message
// update, so this reflects the model/tools/settings at launch time. Log a
// summary at info for prompt observability; the full config at trace.
const
=
.
resolveSystemMessageConfig
(
,
)
;
this
.
.
info
(
`[Copilot:${plan.sessionId}] Resolved system message: ${describeSystemMessageConfig(systemMessage)}`
)
;
const
=
.
?
[
...
.
flatMap
(
=>
.
.
map
(
=>
.
)
)
,
...
.
keys
(
.
.
)
,
]
:
undefined
;
const
=
disabledMcpServersSessionOption
(
,
.
,
)
;
const
=
.
?
{
}
:
{
...
toSdkMcpServersFromConfigMap
(
.
.
)
,
...
toSdkMcpServers
(
)
}
;
if
(
this
.
.
getLevel
(
)
<=
.
)
{
// Guarded: a `replace`-mode prompt's content can be multiple KB, so only
// serialize it when trace output is actually emitted.
this
.
.
trace
(
`[Copilot:${plan.sessionId}] System message config: ${JSON.stringify(systemMessage,(_key, value)=>typeof value ==='function'?'[transform fn]': value)}`