Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/import{ Event }from'../../../base/common/event.js';import{ IPolicyData }from'../../../base/common/defaultAccount.js';import{ ExtraKnownMarketplacesConfigDict, IExtraKnownMarketplaceEntry, extraKnownMarketplacesToConfigDict }from'../../../base/common/managedSettings.js';import{ IManagedSettingPolicyDefinition, IManagedSettingsPolicyDefinitions, ManagedSettingValue, ManagedSettingsData }from'../../../base/common/policy.js';import{ IStringDictionary }from'../../../base/common/collections.js';import{ isEmptyObject, isObject, isString }from'../../../base/common/types.js';
createDecorator
PolicyDefinition
ManagedSettingsData
ReadonlyRecord
IManagedSettingsPolicyDefinitions
type
type
managedSettingValueCallbacks ManagedSettingValue
key policyData IPolicyData ManagedSettingValue
callback managedSettingValueCallbackskey
callback
policyData policyDatamanagedSettingskey
managedSettingValueCallbackskey callback
callback
effective source ManagedSettingsChannel
effective
nativeMdm ManagedSettingsData server ManagedSettingsData file ManagedSettingsData IForceRemoteSettingsRefreshResolution
resolution nativeMdm server fileresolutions
contribution resolutioncontributionscandidate candidatevalue
contribution
effective
contributionvalue
effective source contributionchannel
effective
IManagedSettingsService
_serviceBrand
onDidChangeManagedSettings Event
key ManagedSettingValue
_serviceBrand
onDidChangeManagedSettings EventNone
ManagedSettingValue
managedModelValueCallback policyData IPolicyData ManagedSettingValue
value ManagedSettingValue
trimmed value value
trimmed trimmed
policyData IPolicyData ManagedSettingValue
managedModelValueCallback
policyData
topLevel policyDatamanagedSettings
topLevel policyDatamanagedSettings
managedModelValueCallback
policyData IPolicyData
policyDatachat_preview_features_enabled policyDatamanagedSettingsActive
INativeManagedSettingsService
_serviceBrand
managedSettings ManagedSettingsData
onDidChangeManagedSettings EventManagedSettingsData
ManagedSettingsData
policyDefinitions IStringDictionaryPolicyDefinition ManagedSettingsData
_serviceBrand
managedSettings ManagedSettingsData
onDidChangeManagedSettings EventNone
ManagedSettingsData managedSettings
ManagedSettingsData managedSettings
object Record
result Record
object result
result
value prefix result Record
value value value
prefix
resultprefix value
value
key value
valuekey prefix key result
value value Record
value value value
policyDefinitions IStringDictionaryPolicyDefinition IManagedSettingsPolicyDefinitions
definitions Record IManagedSettingPolicyDefinition
policyName policyDefinitions
policyManagedSettings policyDefinitionspolicyNamemanagedSettings
policyManagedSettings
key policyManagedSettings
definitionskey policyManagedSettingskey
definitions
policyDefinitions IStringDictionaryPolicyDefinition
policyName policyDefinitions
policyManagedSettings policyDefinitionspolicyNamemanagedSettings
policyManagedSettings policyManagedSettings
values ManagedSettingsData definitions IManagedSettingsPolicyDefinitions onWarn msg ManagedSettingsData
projected Record ManagedSettingValue
key definitions
value valueskey
value
value definitionskeytype
projectedkey value
onWarn
projected
ManagedSettingsChannel
ManagedSettingsChannel
channel ManagedSettingsChannel
value ManagedSettingValue
value ManagedSettingValue
source ManagedSettingsChannel
contributions IManagedSettingsContribution
values ManagedSettingsData
resolutions ReadonlyMap IManagedSettingResolution
activeSources ManagedSettingsChannel
nativeMdm ManagedSettingsData server ManagedSettingsData file ManagedSettingsData IManagedSettingsPick
bags RecordManagedSettingsChannel ManagedSettingsData nativeMdm server file
resolutions
channel
bag bagschannel
bag
key Objectbag
value bagkey
value
existing resolutionskey
existing
existingcontributions channel value
resolutionskey value source channel contributions channel value
activeSources
entries ManagedSettingValue
key resolution resolutions
entrieskey resolutionvalue
activeSourcesresolutionsource
values Objectentries
resolutions
activeSources channel activeSourceschannel
key
value onWarn msg
value Record
value
out Record
k v Objectvalue
k k k
v
outk v
v v
outk v
out
value object
value value
value
value value
value onWarn msg ExtraKnownMarketplacesConfigDict
value onWarn
IStructuredManagedSetting
key
encode encodeObject
key
encode encodeArray
key
encode encodeArray
key
encode encodeArray
key
encode encodeExtraMarketplaces
key
encode encodeStringMap
key
encode encodeStringMap
obj Record dottedKey
current obj
segment dottedKey
current
current current Record segment
current
obj Record dottedKey Record
dot dottedKey
dot
clone obj
clonedottedKey
clone
head dottedKey dot
child objhead
child
obj
obj head child Record dottedKeydot
parsed Record onWarn msg ManagedSettingsData
scalarRest Record parsed
setting
scalarRest scalarRest settingkey
result Record ManagedSettingValue scalarRest
setting
encoded settingparsed settingkey onWarn
encoded
resultsettingkey encoded
result
value onWarn msg IExtraKnownMarketplaceEntry
value
seen
entries IExtraKnownMarketplaceEntry
name entry Objectvalue
entry entry Record source
onWarn
rawEntry entry Record
src rawEntrysource source repo url ref
autoUpdate rawEntryautoUpdate rawEntryautoUpdate
rawEntryautoUpdate autoUpdate
onWarn
normalized IExtraKnownMarketplaceEntry
srcsource srcrepo
normalized name autoUpdate autoUpdate source source repo srcrepo srcref ref srcref
srcsource srcurl
normalized name autoUpdate autoUpdate source source url srcurl srcref ref srcref
srcsource srcsource
onWarn
onWarn
normalized seenname
seenname
entriesnormalized
entries
IFileManagedSettingsService
_serviceBrand
rawManagedSettings RawManagedSettingsData
managedSettings ManagedSettingsData
onDidChangeRawManagedSettings EventRawManagedSettingsData
onDidChangeManagedSettings EventManagedSettingsData
ManagedSettingsData
_serviceBrand
rawManagedSettings RawManagedSettingsData
managedSettings ManagedSettingsData
onDidChangeRawManagedSettings EventNone
onDidChangeManagedSettings EventNone
ManagedSettingsData managedSettings
/** Windows registry root for GitHub Copilot policies. */
export
const
GITHUB_COPILOT_WIN32_REGISTRY_PATH
=
'SOFTWARE\\Policies\\GitHubCopilot'
;
/** Windows product name passed to the native policy watcher. */
export
const
GITHUB_COPILOT_WIN32_POLICY_NAME
=
'GitHubCopilot'
;
/** macOS CFPreferences application ID for GitHub Copilot managed preferences. */
export
const
GITHUB_COPILOT_MACOS_BUNDLE_ID
=
'com.github.copilot'
;
/** MDM key for the V0 managed setting. */
export
const
COPILOT_DISABLE_BYPASS_PERMISSIONS_MODE_KEY
=
'permissions.disableBypassPermissionsMode'
;
/** Managed-settings key for enterprise plugin enablement (carried as a JSON-encoded `{ [pluginId]: boolean }`). */
export
const
COPILOT_ENABLED_PLUGINS_KEY
=
'enabledPlugins'
;
/** Managed-settings key for enterprise marketplaces (carried as a JSON-encoded `{ [name]: url-or-shorthand }`). */
export
const
COPILOT_EXTRA_MARKETPLACES_KEY
=
'extraKnownMarketplaces'
;
/** Managed-settings key for the strict-marketplace allowlist (carried as a JSON-encoded array of source entries; absent = no restrictions, `[]` = lockdown). */
export
const
COPILOT_STRICT_MARKETPLACES_KEY
=
'strictKnownMarketplaces'
;
/** Managed-settings key for the per-server MCP allowlist (carried as a JSON-encoded array of matcher entries; absent = no allow restriction, `[]` = only servers matching an entry, i.e. block all). */
export
const
COPILOT_ALLOWED_MCP_SERVERS_KEY
=
'allowedMcpServers'
;
/** Managed-settings key for the per-server MCP denylist (carried as a JSON-encoded array of matcher entries; deny always takes precedence over allow). */
export
const
COPILOT_DENIED_MCP_SERVERS_KEY
=
'deniedMcpServers'
;
/** Managed-settings key that blocks standalone user/workspace customizations. */
export
const
COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY
=
'strictPluginOnlyCustomization'
;
/** Managed-settings key that makes the enterprise MCP allowlist authoritative. */
export
const
COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_KEY
=
'allowManagedMcpServersOnly'
;
/** Managed-settings key that allows hooks only from managed sources. */
export
const
COPILOT_ALLOW_MANAGED_HOOKS_ONLY_KEY
=
'allowManagedHooksOnly'
;
/** Managed-settings transport control that requires a fresh server fetch on startup. */
export
const
COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY
=
'forceRemoteSettingsRefresh'
;
/**
* Enterprise-mandated sandbox floor (`sandbox.enabled` in the runtime's managed-settings schema).
* The runtime owns composing and enforcing this floor — it is `force-on-wins`, so a managed `true`
* cannot be loosened by the user. VS Code only *reads* it to decide which chat harness to offer,
* and deliberately declares no configuration policy for it: the control is runtime-owned, and
* mirroring it as a VS Code policy would invert ownership.
*/
export
const
COPILOT_SANDBOX_ENABLED_KEY
=
'sandbox.enabled'
;
/**
* Managed-settings controls consumed by the delivery pipeline itself rather than by a
* configuration policy. Native MDM must watch these even though no setting declares them.
*/
export
const
MANAGED_SETTINGS_CONTROL_DEFINITIONS
:
=
{
[
COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY
]
:
{
:
'boolean'
}
,
[
COPILOT_SANDBOX_ENABLED_KEY
]
:
{
:
'boolean'
}
,
}
;
/** Policy-only configuration delivery slot for {@link COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY}. */
/** Policy-only configuration delivery slot for {@link COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_KEY}. */
export
const
COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_CONFIG
=
'chat.mcp.allowManagedServersOnly'
;
/** Policy-only configuration delivery slot for {@link COPILOT_ALLOW_MANAGED_HOOKS_ONLY_KEY}. */
export
const
COPILOT_ALLOW_MANAGED_HOOKS_ONLY_CONFIG
=
'chat.hooks.allowManagedOnly'
;
/**
* Legacy managed-settings key for the default chat model, nested under `permissions` so it flattens
* to `permissions.model`. Retained for original-schema deployments; superseded by the top-level
* {@link COPILOT_TOP_LEVEL_MODEL_KEY}, which wins when both are present (see {@link managedModelValue}).
*/
export
const
COPILOT_MODEL_KEY
=
'permissions.model'
;
/**
* Canonical top-level managed-settings key for the default chat model (flattens to the bag key
* `model`). Supersedes the legacy nested {@link COPILOT_MODEL_KEY} when both are present.
*/
export
const
COPILOT_TOP_LEVEL_MODEL_KEY
=
'model'
;
/**
* Enterprise OTel managed-settings keys. These are the scalar leaves of the canonical
* `telemetry` block from the cross-client managed-settings schema (see the CLI
* `ManagedTelemetrySettings`); they flatten to dot-path bag keys via
* {@link normalizeManagedSettings}, so no {@link STRUCTURED_MANAGED_SETTINGS} entry is needed.
* The `telemetry.resourceAttributes` and `telemetry.headers` map fields are structured
* ({@link STRUCTURED_MANAGED_SETTINGS} rows carry them as JSON-encoded objects under their nested
* keys); `telemetry.serviceName` is a scalar.
*/
/** Managed-settings key for enterprise OTel enablement. */
export
const
COPILOT_OTEL_ENABLED_KEY
=
'telemetry.enabled'
;
/** Managed-settings key for the enterprise OTLP collector endpoint. */
export
const
COPILOT_OTEL_ENDPOINT_KEY
=
'telemetry.endpoint'
;
/** Managed-settings key for the enterprise OTLP protocol (`http/json`, `http/protobuf`, or `grpc`). */
export
const
COPILOT_OTEL_PROTOCOL_KEY
=
'telemetry.protocol'
;
/** Managed-settings key for enterprise OTel content capture. */
export
const
COPILOT_OTEL_CAPTURE_CONTENT_KEY
=
'telemetry.captureContent'
;
/** Managed-settings key that prevents users from enabling OTel content capture themselves. */
export
const
COPILOT_OTEL_LOCK_CAPTURE_CONTENT_KEY
=
'telemetry.lockCaptureContent'
;
/** Managed-settings key for the OTel `service.name` resource attribute. */
export
const
COPILOT_OTEL_SERVICE_NAME_KEY
=
'telemetry.serviceName'
;
/** Managed-settings key for additional OTel resource attributes (a `{ [k]: string }` map). */
export
const
COPILOT_OTEL_RESOURCE_ATTRIBUTES_KEY
=
'telemetry.resourceAttributes'
;
/** Managed-settings key for extra OTLP exporter headers (a `{ [k]: string }` map). */
export
const
COPILOT_OTEL_HEADERS_KEY
=
'telemetry.headers'
;
const
=
new
Map<string,(policyData: IPolicyData)=>
|
undefined
>
(
)
;
/**
* Standard pass-through `value` callback for a managed-settings-driven policy: locks the setting
* to the managed value when the enterprise has set it, and returns `undefined` otherwise so the
* user's own setting falls through. Use for the common case; policies that combine the managed
* value with other conditions (e.g. `chat_preview_features_enabled`) keep a custom callback.
*
* The callback is memoized per key, so repeated calls for the same key return the SAME function
* reference. That reference identity is what lets `isSamePolicyDefinition` skip needless
* re-registration, and memoizing makes the guarantee hold regardless of where the helper is called.
*/
export
function
managedSettingValue
(
:
string
)
:
(
:
)
=>
|
undefined
{
let
=
.
get
(
)
;
if
(
!
)
{
callback
=
=>
.
?.
[
]
;
.
set
(
,
)
;
}
return
;
}
export
type
IForceRemoteSettingsRefreshResolution
=
|
{
readonly
:
true
;
readonly
:
}
|
{
readonly
:
false
}
;
/**
* Resolve the fail-closed startup refresh control across every delivery channel, reusing
* {@link pickManagedSettings} precedence rather than re-implementing it. A non-boolean value is
* treated as absent, so a malformed high-precedence value cannot mask a well-formed lower one.
*/
export
function
resolveForceRemoteSettingsRefresh
(
:
|
undefined
,
:
|
undefined
,
:
|
undefined
)
:
{
const
=
pickManagedSettings
(
,
,
)
.
.
get
(
COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY
)
;
const
=
?.
.
find
(
=>
typeof
.
===
'boolean'
)
;
if
(
!
)
{
return
{
:
false
}
;
}
return
.
===
true
?
{
:
true
,
:
.
}
:
{
:
false
}
;
}
export
const
=
createDecorator<IManagedSettingsService>
(
'managedSettingsService'
)
;
/** Read-only access to effective managed settings after channel resolution. */
export
interface
IManagedSettingsService
{
readonly
:
undefined
;
readonly
:
<
void
>
;
getManagedSettingValue
(
:
string
)
:
|
undefined
;
}
export
class
NullManagedSettingsService
implements
IManagedSettingsService
{
readonly
:
undefined
;
readonly
=
.
;
getManagedSettingValue
(
)
:
|
undefined
{
return
undefined
;
}
}
let
:
(
(
:
)
=>
|
undefined
)
|
undefined
;
/** Trim a managed-settings model value, treating a blank/whitespace-only string as unset. */
function
normalizeModelValue
(
:
|
undefined
)
:
string
|
undefined
{
const
=
typeof
===
'string'
?
.
trim
(
)
:
undefined
;
return
?
:
undefined
;
}
/**
* `value` callback for the default-chat-model managed setting: resolves the top-level
* {@link COPILOT_TOP_LEVEL_MODEL_KEY} first, falling back to the legacy nested {@link COPILOT_MODEL_KEY}
* (each trimmed, blank treated as unset), so the top-level value wins when both are present. Memoized
* so repeated calls return the same reference, matching the identity contract {@link managedSettingValue}
* relies on for `isSamePolicyDefinition`.
*/
export
function
managedModelValue
(
)
:
(
:
)
=>
|
undefined
{
if
(
!
)
{
managedModelValueCallback
=
=>
{
const
=
normalizeModelValue
(
.
?.
[
COPILOT_TOP_LEVEL_MODEL_KEY
]
)
;
return
??
normalizeModelValue
(
.
?.
[
COPILOT_MODEL_KEY
]
)
;
}
;
}
return
;
}
/**
* `value` callback shared by the third-party agent harness policies (`Claude3PIntegration`,
* `Codex3PIntegration`): forces the harness off when the account disables chat preview features,
* or when the user is governed by managed settings at all.
*
* Managed settings are composed and enforced by the Copilot runtime and never reach the Claude or
* Codex harnesses, so leaving them available would hand a governed user an ungoverned path around
* every managed control the enterprise set.
*/
export
function
thirdPartyAgentEnabledValue
(
:
)
:
boolean
|
undefined
{
return
.
===
false
||
.
===
true
?
false
:
undefined
;
}
export
const
=
createDecorator<INativeManagedSettingsService>
(
'nativeManagedSettingsService'
)
;
export
interface
INativeManagedSettingsService
{
readonly
:
undefined
;
readonly
:
;
readonly
:
<
>
;
initialize
(
)
:
Promise
<
>
;
updatePolicyDefinitions
(
:
<
>
)
:
Promise
<
>
;
}
export
class
NullNativeManagedSettingsService
implements
INativeManagedSettingsService
{
readonly
:
undefined
;
readonly
:
=
{
}
;
readonly
=
.
;
async
initialize
(
)
:
Promise
<
>
{
return
this
.
;
}
async
updatePolicyDefinitions
(
)
:
Promise
<
>
{
return
this
.
;
}
}
function
flattenManagedSettings
(
:
unknown
)
:
<
string
,
string
|
number
|
boolean
>
{
const
:
<
string
,
string
|
number
|
boolean
>
=
{
}
;
flattenManagedSettingsValue
(
,
undefined
,
)
;
return
;
}
function
flattenManagedSettingsValue
(
:
unknown
,
:
string
|
undefined
,
:
<
string
,
string
|
number
|
boolean
>
)
:
void
{
if
(
typeof
===
'string'
||
typeof
===
'number'
||
typeof
===
'boolean'
)
{
if
(
!==
undefined
)
{
[
]
=
;
}
return
;
}
if
(
!
isManagedSettingsObject
(
)
)
{
return
;
}
for
(
const
in
)
{
flattenManagedSettingsValue
(
[
]
,
?
`${prefix}.${key}`
:
,
)
;
}
}
function
isManagedSettingsObject
(
:
unknown
)
:
is
<
string
,
unknown
>
{
return
typeof
===
'object'
&&
!==
null
&&
!
Array
.
isArray
(
)
;
}
/**
* Aggregate the `managedSettings` declarations of every policy definition into a single
* key -> definition map. This is the single source of truth for policy-backed Copilot
* managed-settings keys and drives both server projection and the declaration-driven portion of
* the native MDM watcher. Transport controls are declared separately.
*/
export
function
collectManagedSettingsDefinitions
(
:
<
>
)
:
{
const
:
<
string
,
>
=
{
}
;
for
(
const
in
)
{
const
=
[
]
.
;
if
(
)
{
for
(
const
in
)
{
[
]
=
[
]
;
}
}
}
return
;
}
/**
* Whether any policy in `policyDefinitions` declares at least one managed-settings key. Cheap
* existence check (short-circuits) used to decide whether the declaration-driven portion of the
* native MDM watcher needs updating, without aggregating the full
* {@link collectManagedSettingsDefinitions} map.
*/
export
function
hasManagedSettingsDefinitions
(
:
<
>
)
:
boolean
{
for
(
const
in
)
{
const
=
[
]
.
;
if
(
&&
!
isEmptyObject
(
)
)
{
return
true
;
}
}
return
false
;
}
/**
* Project a raw managed-settings bag onto the declared schema: keep only keys declared by a
* policy definition whose runtime value matches the declared type. Undeclared keys and
* type-mismatched values are dropped (with an optional warning). Values are validated, never
* coerced, so a key declared as `string` keeps its string value untouched.
*
* This keeps the server endpoint and native MDM delivery aligned on the same
* declaration-driven key set and value types.
*/
/**
* A delivery channel that can provide managed settings. Managed settings can be delivered by more
* than one channel, so this names the known sources to give policy evaluation and the Policy
* Diagnostics report one shared vocabulary. Extend this union (and {@link MANAGED_SETTINGS_CHANNELS}
* / {@link pickManagedSettings}) when adding a new channel.
*/
/** Native MDM: OS registry (Windows) / managed preferences (macOS) via `@vscode/policy-watcher`. */
|
'nativeMdm'
/** File on a well-known disk path (`managed-settings.json`). */
|
'file'
;
/**
* The source attributed to an effective managed setting (or to the overall report). A
* {@link ManagedSettingsChannel} once a channel has won, or `'none'` when no channel contributes.
*/
export
type
ManagedSettingsSource
=
|
'none'
;
/**
* The delivery channels in fixed precedence order (highest first): native MDM → server-delivered →
* file on disk. This single ordered list drives the per-key resolution in {@link pickManagedSettings}
* and is the one place to extend when a new channel is introduced. Rationale for the order: the
* server is harder to bypass than local MDM, and a local file is the most easily tampered with.
*/
export
const
MANAGED_SETTINGS_CHANNELS
:
readonly
[
]
=
[
'nativeMdm'
,
'server'
,
'file'
]
;
/** A single channel's contribution to a managed-settings key, for provenance in the resolution. */
export
interface
IManagedSettingsContribution
{
/** The channel that supplied this value. */
readonly
:
;
/** The value the channel supplied for the key. */
readonly
:
;
}
/** How a single managed-settings key was resolved across the delivery channels. */
export
interface
IManagedSettingResolution
{
/** The effective (winning) value applied for the key. */
readonly
:
;
/** The channel whose value won (always the first {@link contributions} entry's channel). */
readonly
:
;
/** Every channel that supplied this key, in precedence order (winner first, overridden after). */
readonly
:
readonly
[
]
;
}
/** The result of merging managed settings from every delivery channel on a per-key basis. */
export
interface
IManagedSettingsPick
{
/** The effective merged bag: the winning value for each key contributed by any channel. */
readonly
:
;
/** Per-key provenance: how each key resolved and which channels were overridden. */
readonly
:
<
string
,
>
;
/** The channels that supplied at least one *winning* key, in precedence order. */
readonly
:
readonly
[
]
;
}
/**
* Merge the managed-settings bags from every delivery channel on a **per-key** basis.
*
* Precedence (highest first): native MDM → server-delivered → file on disk. Unlike a single
* authoritative source, the channels *are* merged key-by-key: for each key the highest-precedence
* channel that supplies it wins, but a key that the higher channels never set is still filled in by
* a lower channel. A value an admin locks via native MDM therefore cannot be overwritten by the
* server or a file, while keys those higher channels leave unset remain available to lower ones.
*
* The parameter order matches the precedence so call sites read top-to-bottom. Centralizing the
* resolution here (rather than inlining it at each call site) keeps policy evaluation
* ({@link AccountPolicyService.getPolicyData}) and the Policy Diagnostics report from drifting apart,
* and gives one obvious place to extend when a new channel is introduced. Empty or absent channels
* contribute nothing.
*/
export
function
pickManagedSettings
(
:
|
undefined
,
:
|
undefined
,
:
|
undefined
)
:
{
const
:
<
,
|
undefined
>
=
{
,
,
}
;
// Walk channels highest-precedence first: the first channel to supply a key wins, and later
// channels are appended as overridden contributions for provenance.
/** Linux well-known path for file-based managed settings. */
export
const
MANAGED_SETTINGS_LINUX_FILE_PATH
=
'/etc/github-copilot/managed-settings.json'
;
/** Windows directory name under %ProgramFiles% for file-based managed settings. */
export
const
MANAGED_SETTINGS_WINDOWS_DIR
=
'GitHubCopilot'
;
/** Managed settings file name. */
export
const
MANAGED_SETTINGS_FILE_NAME
=
'managed-settings.json'
;
/**
* Descriptor for a structured (object/array) managed setting: one carried across every delivery
* channel as a canonical JSON string under a single key. This table is the single place that
* knows how to turn a managed-settings schema field into that canonical value, so adding a
* structured key is one row here (plus the policy declaration that reads the bag key).
*
* `key` is both the source field name read from the parsed input and the canonical bag key the
* JSON string is stored under — for structured settings these are identical by contract (a
* structured key's bag name matches the schema field exactly; only scalar settings flatten to a
* differently-shaped dot-path, and those don't go through this table).
*/
interface
IStructuredManagedSetting
{
/** Source field name read from the parsed input, and the canonical bag key the JSON string is stored under. */
readonly
:
string
;
/**
* Normalize the raw value into the canonical pre-stringify shape an admin authors via native
* MDM. Return `undefined` to omit the key (absent or malformed value). Note an empty array (the
* `strictKnownMarketplaces` lockdown case) is returned as-is, not omitted.
*/
readonly
encode
:
(
:
unknown
,
?
:
(
:
string
)
=>
void
)
=>
unknown
;
}
/**
* Encode a managed-settings value into a canonical `{ [k]: string }` map: keeps string values
* as-is and coerces number/boolean values to strings; drops keys with non-primitive values.
* Returns `undefined` for a non-object input so the structured key is omitted.
*/
function
encodeStringMap
(
:
unknown
)
:
<
string
,
string
>
|
undefined
{
if
(
!
isObject
(
)
)
{
return
undefined
;
}
const
:
<
string
,
string
>
=
{
}
;
for
(
const
[
,
]
of
.
entries
(
)
)
{
if
(
===
'__proto__'
||
===
'constructor'
||
===
'prototype'
)
{
continue
;
// defend the shared normalizer against prototype pollution
}
if
(
isString
(
)
)
{
[
]
=
;
}
else
if
(
typeof
===
'number'
||
typeof
===
'boolean'
)
{
[
]
=
String
(
)
;
}
}
return
;
}
/** Pass an object value through unchanged; omit the key for any non-object value. */
function
encodeObject
(
:
unknown
)
:
|
undefined
{
return
isObject
(
)
?
:
undefined
;
}
/** Pass an array value through unchanged (including an empty array); omit the key otherwise. */
function
encodeArray
(
:
unknown
)
:
unknown
[
]
|
undefined
{
return
Array
.
isArray
(
)
?
:
undefined
;
}
/**
* Encode the schema's `{ [id]: { source, autoUpdate? }}` marketplace map into the canonical
* policy dict; drops malformed entries (with an optional warning) and omits
* the key when there are none.
*/
function
encodeExtraMarketplaces
(
:
unknown
,
?
:
(
:
string
)
=>
void
)
:
|
undefined
{
return
extraKnownMarketplacesToConfigDict
(
normalizeExtraKnownMarketplaces
(
,
)
)
;
}
const
STRUCTURED_MANAGED_SETTINGS
:
readonly
[
]
=
[
{
:
COPILOT_ENABLED_PLUGINS_KEY
,
:
,
}
,
{
:
COPILOT_STRICT_MARKETPLACES_KEY
,
:
,
}
,
{
:
COPILOT_ALLOWED_MCP_SERVERS_KEY
,
:
,
}
,
{
:
COPILOT_DENIED_MCP_SERVERS_KEY
,
:
,
}
,
{
:
COPILOT_EXTRA_MARKETPLACES_KEY
,
:
,
}
,
{
// Nested under `telemetry`; carried as a JSON-encoded `{ [k]: string }` map. Non-string
// primitive values are coerced to strings; non-primitive values are dropped.
:
COPILOT_OTEL_RESOURCE_ATTRIBUTES_KEY
,
:
,
}
,
{
// Nested under `telemetry`; carried as a JSON-encoded `{ [k]: string }` map of OTLP headers.
:
COPILOT_OTEL_HEADERS_KEY
,
:
,
}
,
]
;
/**
* Read a (possibly nested) dot-separated key from a parsed managed-settings object, e.g.
* `telemetry.resourceAttributes`. Returns `undefined` if any path segment is missing or not an
* object. Single-segment keys behave like a plain property read.
*/
function
readNestedManagedKey
(
:
<
string
,
unknown
>
,
:
string
)
:
unknown
{
let
:
unknown
=
;
for
(
const
of
.
split
(
'.'
)
)
{
if
(
!
isObject
(
)
)
{
return
undefined
;
}
=
(
as
<
string
,
unknown
>
)
[
]
;
}
return
;
}
/**
* Return a copy of `obj` with the (possibly nested) dot-separated key removed, cloning only the
* objects along the touched path so the original (and any shared sub-objects) stay untouched. The
* spread-then-`delete` shape matches a destructuring rest: it copies own enumerable keys (including
* an own `__proto__`) without triggering the inherited `__proto__` setter.
*/
function
withNestedManagedKeyDeleted
(
:
<
string
,
unknown
>
,
:
string
)
:
<
string
,
unknown
>
{
const
=
.
indexOf
(
'.'
)
;
if
(
===
-
1
)
{
const
=
{
...
}
;
delete
[
]
;
return
;
}
const
=
.
slice
(
0
,
)
;
const
=
[
]
;
if
(
!
isObject
(
)
)
{
return
;
}
return
{
...
,
[
]
:
withNestedManagedKeyDeleted
(
as
<
string
,
unknown
>
,
.
slice
(
+
1
)
)
}
;
}
/**
* Normalize a parsed managed-settings object (from the server `managed_settings` API, a file on
* disk, or any other source using the managed-settings schema) into the canonical
* `ManagedSettingsData` bag that the policy framework consumes. This is the **single**
* normalization path for all delivery channels, so downstream projection and policy `value()`
* callbacks behave identically regardless of source. It does not enforce the declared
* `managedSettings` schema — dropping undeclared or type-mismatched keys happens later, at
* {@link projectManagedSettings}.
*
* - Scalar leaves (`permissions.*` and any forward-compatible scalar keys) are flattened into
* dot-separated keys.
* - Structured settings (declared in {@link STRUCTURED_MANAGED_SETTINGS}) are carried as canonical
* JSON strings under a single key each — the same shape an admin authors via native MDM.
* `PolicyConfiguration` parses the JSON back into the object-typed setting on read.
* `extraKnownMarketplaces` is normalized from the schema's `{ [id]: { source, autoUpdate? }}`
* map to the policy-backed marketplace dict.
*
* Malformed marketplace entries are dropped (with an optional warning via {@link onWarn}) rather
* than throwing, so a bad enterprise settings file degrades gracefully instead of blocking startup.
*/
export
function
normalizeManagedSettings
(
:
<
string
,
unknown
>
,
?
:
(
:
string
)
=>
void
)
:
{
// Spread + delete (not for..in + assignment) so the scalar remainder keeps exact `{ ...rest }`
// semantics: it never triggers the inherited `__proto__` setter for a source-sent own
// `__proto__` key, matching a destructuring rest. Structured keys may be nested (e.g.
// `telemetry.resourceAttributes`), so removal clones only the touched path.
let
:
<
string
,
unknown
>
=
{
...
}
;
for
(
const
of
STRUCTURED_MANAGED_SETTINGS
)
{
=
withNestedManagedKeyDeleted
(
,
.
)
;
}
const
:
<
string
,
>
=
{
...
flattenManagedSettings
(
)
}
;
for
(
const
of
STRUCTURED_MANAGED_SETTINGS
)
{
const
=
.
encode
(
readNestedManagedKey
(
,
.
)
,
)
;
if
(
!==
undefined
)
{
[
.
]
=
JSON
.
stringify
(
)
;
}
}
return
;
}
/**
* Normalize the schema's `{ [id]: { source, autoUpdate? }}` marketplace map into an
* {@link IExtraKnownMarketplaceEntry} array, preserving the marketplace `name`,
* source discriminator, and any `ref`. Malformed or off-spec entries are dropped
* (with an optional warning via {@link onWarn}).
*/