Open History to see the last commit
1import {
2 AntigravitySettings,
3 ClaudeSettings,
4 CodexSettings,
5 defaultInstanceIdForDriver,
6 disallowedProviderMessage,
7 type ManagedProviderInstance,
8 type ManagedProviderLimits,
9 type ManagedPolicySummary,
10 ProviderDriverKind,
11 type ProviderInstanceConfig,
12 type ProviderInstanceEnvironmentVariable,
13 type ProviderInstanceId,
14 resolveProviderInstanceEnabled,
15 type RuntimeMode,
16 type ServerSettings,
17} from "@t3tools/contracts";
18import { acpRegistryClient } from "@t3tools/provider-acp-registry/client";
19import { cursorClient } from "@t3tools/provider-cursor/client";
20import { fxClient } from "@t3tools/provider-fx/client";
21import { grokClient } from "@t3tools/provider-grok/client";
22import { kiroClient } from "@t3tools/provider-kiro/client";
23import { museClient } from "@t3tools/provider-muse/client";
24import { openCodeClient } from "@t3tools/provider-opencode/client";
25import { piClient } from "@t3tools/provider-pi/client";
26import type { ProviderClientDefinition } from "@t3tools/provider-core/client";
27
28interface KnownDriver {
29 readonly label: string;
30 readonly configFields: ReadonlySet<string>;
31 readonly hasDefaultInstance: boolean;
32}
33
34const known = (
35 driverKind: string,
36 label: string,
37 settingsSchema: { readonly fields: object },
38 hasDefaultInstance = true,
39) =>
40 [
41 ProviderDriverKind.make(driverKind),
42 { label, configFields: new Set(Object.keys(settingsSchema.fields)), hasDefaultInstance },
43 ] as const;
44
45const PACKAGED_CLIENTS: ReadonlyArray<ProviderClientDefinition> = [
46 cursorClient,
47 grokClient,
48 fxClient,
49 kiroClient,
50 museClient,
51 openCodeClient,
52 piClient,
53 acpRegistryClient,
54];
55
56/**
57 * Fields that make an instance launch without the settings a pin sets: managed Codex runs T3's own
58 * runtime against OpenAI, and a server URL points OpenCode at a server it does not start. A policy
59 * that owns a pin owns these too, holding each at the value given here, which clients still send
60 * when they add an instance.
61 */
62const PIN_BYPASS_FIELDS: ReadonlyMap<
63 ProviderDriverKind,
64 Readonly<Record<string, unknown>>
65> = new Map<ProviderDriverKind, Readonly<Record<string, unknown>>>([
66 [ProviderDriverKind.make("codex"), { setupMode: "existing" }],
67 [ProviderDriverKind.make("opencode"), { serverUrl: "" }],
68]);
69
70/** Drivers this build knows, by the names users see; a policy naming any other is refused. */
71const KNOWN_DRIVERS: ReadonlyMap<ProviderDriverKind, KnownDriver> = new Map([
72 known("codex", "Codex", CodexSettings),
73 known("claudeAgent", "Claude", ClaudeSettings),
74 known("antigravity", "Antigravity", AntigravitySettings),
75 ...PACKAGED_CLIENTS.map((client) =>
76 known(client.driverKind, client.label, client.settingsSchema, client.hasDefaultInstance),
77 ),
78]);
79
80/** Each driver a policy may name, with the label users see. */
81export const knownDriverLabels = () =>
82 Array.from(KNOWN_DRIVERS, ([driver, { label }]) => ({ driver, label }));
83
84const PINNED_CONFIG_FIELDS = ["binaryPath", "launchArgs"] as const;
85type PinnedConfigField = (typeof PINNED_CONFIG_FIELDS)[number];
86
87/**
88 * Fields that decide what a provider starts and reads on startup; a driver has those its schema
89 * has. Under a ceiling they are the administrator's: a wrapper binary, a skip-permissions flag, or
90 * a config directory with allow rules each outrank T3 Code's mode, and no flag filter stops a wrapper.
91 */
92const LAUNCH_CONFIG_FIELDS = [
93 "binaryPath",
94 "launchArgs",
95 "homePath",
96 "shadowHomePath",
97 "commandPath",
98 "commandArgs",
99 "serverUrl",
100] as const;
101
102export type ProviderWriteVerdict =
103 | { readonly _tag: "Allowed"; readonly settings: ServerSettings }
104 | { readonly _tag: "Locked"; readonly path: string }
105 | {
106 readonly _tag: "Disallowed";
107 readonly instanceId: ProviderInstanceId;
108 readonly label: string;
109 };
110
111/**
112 * How a policy's `limits.providers` shapes provider instances. Like settings locks, pinned
113 * fields are laid over instances on every read and never written to the user's settings file.
114 */
115export interface ManagedProviders {
116 readonly isDriverAllowed: (driver: ProviderDriverKind) => boolean;
117 /** Lay pinned fields over every instance of a pinned driver, its default instance included. */
118 readonly applyLimits: (settings: ServerSettings) => ServerSettings;
119 /**
120 * Vet a write from stored `current` to `next`. Refuses enabling a disallowed driver and moving
121 * a locked field off its pinned value. Pinned values a client sends back are dropped, so the
122 * user's own values return once the policy is gone.
123 */
124 readonly vetWrite: (current: ServerSettings, next: ServerSettings) => ProviderWriteVerdict;
125 /**
126 * Per driver, the instance fields users cannot change, for clients. `environment` alone means
127 * every variable.
128 */
129 readonly lockedInstanceFields: Readonly<Record<string, ReadonlyArray<string>>>;
130}
131
132export const unmanagedProviders: ManagedProviders = {
133 isDriverAllowed: () => true,
134 applyLimits: (settings) => settings,
135 vetWrite: (_current, next) => ({ _tag: "Allowed", settings: next }),
136 lockedInstanceFields: {},
137};
138
139const labelFor = (driver: ProviderDriverKind) => KNOWN_DRIVERS.get(driver)?.label ?? driver;
140
141/** Why the policy clients were told about keeps `driver` from running, or undefined when it may run. */
142export const disallowedDriverReason = (
143 summary: ManagedPolicySummary | undefined,
144 driver: ProviderDriverKind,
145): string | undefined => {
146 const allowed = summary?.limits?.providers?.allowedDrivers;
147 return allowed === undefined || allowed.includes(driver)
148 ? undefined
149 : disallowedProviderMessage(summary?.organization, labelFor(driver));
150};
151
152/**
153 * Variables that replace a provider's launch configuration. From the environment that starts the
154 * server they are ignored under any policy, which can lock launch arguments in more than one way;
155 * from an instance's own variables they are ignored when the policy locks launch arguments.
156 */
157const LAUNCH_OVERRIDE_VARIABLES = ["T3CODE_CODEX_LAUNCH_ARGS"] as const;
158
159/** The environment provider drivers launch from under the policy clients were told about. */
160export const providerHostEnvironment = (
161 summary: ManagedPolicySummary | undefined,
162 environment: NodeJS.ProcessEnv,
163): NodeJS.ProcessEnv => {
164 if (summary === undefined) return environment;
165 const next = { ...environment };
166 for (const name of Object.keys(next)) {
167 if (LAUNCH_OVERRIDE_VARIABLES.some((override) => override === name.toUpperCase())) {
168 delete next[name];
169 }
170 }
171 return next;
172};
173
174/** Each driver's home variable, and the settings that rewrite it at launch. */
175const HOME_VARIABLES: ReadonlyMap<
176 ProviderDriverKind,
177 { readonly variable: string; readonly fields: ReadonlyArray<string> }
178> = new Map([
179 [ProviderDriverKind.make("claudeAgent"), { variable: "CLAUDE_CONFIG_DIR", fields: ["homePath"] }],
180 [
181 ProviderDriverKind.make("codex"),
182 { variable: "CODEX_HOME", fields: ["homePath", "shadowHomePath"] },
183 ],
184]);
185
186const configRecord = (instance: ProviderInstanceConfig | undefined): Record<string, unknown> =>
187 instance?.config !== null &&
188 typeof instance?.config === "object" &&
189 !Array.isArray(instance.config)
190 ? (instance.config as Record<string, unknown>)
191 : {};
192
193/** Empty strings and empty lists are how clients clear a field, so they count as unset. */
194const configValue = (instance: ProviderInstanceConfig | undefined, field: string) => {
195 const value = configRecord(instance)[field];
196 return value === "" || (Array.isArray(value) && value.length === 0) ? undefined : value;
197};
198
199const sameValue = (left: unknown, right: unknown) =>
200 left === right || JSON.stringify(left) === JSON.stringify(right);
201
202const sameVariable = (
203 left: ProviderInstanceEnvironmentVariable | undefined,
204 right: ProviderInstanceEnvironmentVariable | undefined,
205) =>
206 left === right ||
207 (left !== undefined &&
208 right !== undefined &&
209 left.value === right.value &&
210 left.sensitive === right.sensitive);
211
212const pinnedFields = (pin: ManagedProviderInstance): ReadonlyArray<PinnedConfigField> =>
213 PINNED_CONFIG_FIELDS.filter((field) => pin[field] !== undefined);
214
215/**
216 * What the administrator owns on one driver's instances. `config` fields take the pin or the
217 * default, never the user's value; `fill` fields take the pin only where the user left them empty.
218 * `environment`: `all` runs with only pinned variables, `locked` lets them win, `fill` fills gaps.
219 */
220interface DriverRule {
221 readonly pin: ManagedProviderInstance | undefined;
222 readonly config: ReadonlyArray<string>;
223 readonly fill: ReadonlyArray<PinnedConfigField>;
224 readonly environment: "all" | "locked" | "fill";
225}
226
227const pinnedValue = (pin: ManagedProviderInstance | undefined, field: string): unknown =>
228 pin === undefined ? undefined : (pin as Record<string, unknown>)[field];
229
230const overlayInstance = (
231 instance: ProviderInstanceConfig,
232 rule: DriverRule,
233 variableKey: (name: string) => string,
234): ProviderInstanceConfig => {
235 const config = { ...configRecord(instance) };
236 for (const field of rule.config) {
237 const value = pinnedValue(rule.pin, field);
238 if (value === undefined) delete config[field];
239 else config[field] = value;
240 }
241 for (const field of rule.fill) {
242 if (configValue(instance, field) === undefined) config[field] = rule.pin?.[field];
243 }
244 const pinnedEnvironment = (rule.pin?.environment ?? []).map((variable) => ({
245 name: variable.name,
246 value: variable.value,
247 sensitive: false,
248 }));
249 const pinnedByName = new Map(
250 pinnedEnvironment.map((variable) => [variableKey(variable.name), variable]),
251 );
252 const environment: Array<NonNullable<ProviderInstanceConfig["environment"]>[number]> =
253 rule.environment === "all" ? pinnedEnvironment : [];
254 if (rule.environment !== "all") {
255 const seen = new Set<string>();
256 // A user's override would replace launch arguments the administrator locked.
257 const overrides = rule.config.includes("launchArgs")
258 ? new Set(LAUNCH_OVERRIDE_VARIABLES.map(variableKey))
259 : new Set<string>();
260 // The last entry for a name wins at launch, so a lock replaces every entry with that name.
261 for (const variable of instance.environment ?? []) {
262 const key = variableKey(variable.name);
263 if (overrides.has(key)) continue;
264 const pinned = rule.environment === "locked" ? pinnedByName.get(key) : undefined;
265 if (pinned === undefined) environment.push(variable);
266 else if (!seen.has(key)) environment.push(pinned);
267 seen.add(key);
268 }
269 for (const pinned of pinnedEnvironment) {
270 if (!seen.has(variableKey(pinned.name))) environment.push(pinned);
271 }
272 }
273 const { config: _config, environment: _environment, ...envelope } = instance;
274 return {
275 ...envelope,
276 ...(instance.config === undefined && Object.keys(config).length === 0 ? {} : { config }),
277 ...(environment.length === 0 ? {} : { environment }),
278 };
279};
280
281/**
282 * Build the overlay for `limits.providers` and `limits.maxRuntimeMode`, or say why it cannot be
283 * enforced. A ceiling takes each driver's launch fields and its whole `environment`, which can
284 * carry `CLAUDE_CONFIG_DIR`, `PATH`, or `NODE_OPTIONS`; a deny list would miss the next one.
285 */
286export function makeManagedProviders(
287 limits: ManagedProviderLimits,
288 maxRuntimeMode: RuntimeMode | undefined,
289 platform: NodeJS.Platform,
290):
291 | { readonly _tag: "Valid"; readonly providers: ManagedProviders }
292 | { readonly _tag: "Invalid"; readonly reason: string } {
293 // Windows reads a variable name without regard to case, so there a lock covers every spelling.
294 const variableKey = (name: string) => (platform === "win32" ? name.toUpperCase() : name);
295 for (const driver of limits.allowedDrivers ?? []) {
296 if (!KNOWN_DRIVERS.has(driver)) {
297 return { _tag: "Invalid", reason: `"${driver}" in allowedDrivers is not a known provider` };
298 }
299 }
300 const pins = new Map<ProviderDriverKind, ManagedProviderInstance>();
301 for (const [rawDriver, pin] of Object.entries(limits.instances ?? {})) {
302 const driver = ProviderDriverKind.make(rawDriver);
303 const known = KNOWN_DRIVERS.get(driver);
304 if (known === undefined) {
305 return { _tag: "Invalid", reason: `"${driver}" in instances is not a known provider` };
306 }
307 const unsupported = pinnedFields(pin).find((field) => !known.configFields.has(field));
308 if (unsupported !== undefined) {
309 return {
310 _tag: "Invalid",
311 reason: `the ${known.label} provider has no ${unsupported} setting`,
312 };
313 }
314 const names = (pin.environment ?? []).map((variable) => variableKey(variable.name));
315 if (new Set(names).size !== names.length) {
316 return { _tag: "Invalid", reason: `instances.${driver}.environment repeats a variable` };
317 }
318 pins.set(driver, pin);
319 }
320
321 const rules = new Map<ProviderDriverKind, DriverRule>();
322 for (const [driver, known] of KNOWN_DRIVERS) {
323 const pin = pins.get(driver);
324 const bypasses = pin === undefined ? [] : Object.keys(PIN_BYPASS_FIELDS.get(driver) ?? {});
325 if (maxRuntimeMode !== undefined) {
326 rules.set(driver, {
327 pin,
328 config: [
329 ...LAUNCH_CONFIG_FIELDS.filter((field) => known.configFields.has(field)),
330 ...bypasses,
331 ],
332 fill: [],
333 environment: "all",
334 });
335 } else if (pin !== undefined) {
336 // A home path setting rewrites the provider's home variable at launch, so a lock on that
337 // variable owns the setting too.
338 const home = HOME_VARIABLES.get(driver);
339 const homeLocked =
340 home !== undefined &&
341 (pin.environment ?? []).some(
342 (variable) => variableKey(variable.name) === variableKey(home.variable),
343 );
344 rules.set(driver, {
345 pin,
346 config: pin.locked
347 ? [...pinnedFields(pin), ...bypasses, ...(homeLocked ? home.fields : [])]
348 : [],
349 fill: pin.locked ? [] : pinnedFields(pin),
350 environment: pin.locked ? "locked" : "fill",
351 });
352 }
353 }
354
355 const allowed =
356 limits.allowedDrivers === undefined ? undefined : new Set<string>(limits.allowedDrivers);
357 const isDriverAllowed = (driver: ProviderDriverKind) => allowed?.has(driver) ?? true;
358 const allowedSelection = (
359 settings: ServerSettings,
360 selection: { readonly instanceId: ProviderInstanceId } | null | undefined,
361 ) =>
362 selection == null ||
363 isDriverAllowed(
364 settings.providerInstances[selection.instanceId]?.driver ??
365 ProviderDriverKind.make(selection.instanceId),
366 );
367
368 const cache = new WeakMap<ServerSettings, ServerSettings>();
369 const applyLimits = (settings: ServerSettings): ServerSettings => {
370 const cached = cache.get(settings);
371 if (cached !== undefined) return cached;
372 const providerInstances: Record<string, ProviderInstanceConfig> = {
373 ...settings.providerInstances,
374 };
375 // Default instances exist without a settings entry until the user edits one; pin them too.
376 for (const driver of pins.keys()) {
377 const instanceId = defaultInstanceIdForDriver(driver);
378 if (KNOWN_DRIVERS.get(driver)?.hasDefaultInstance === false) continue;
379 if (providerInstances[instanceId] === undefined) providerInstances[instanceId] = { driver };
380 }
381 for (const [instanceId, instance] of Object.entries(providerInstances)) {
382 const rule = rules.get(instance.driver);
383 if (rule !== undefined) {
384 providerInstances[instanceId] = overlayInstance(instance, rule, variableKey);
385 }
386 }
387 // A cleared selection falls back to the text generation model, which is resolved afterwards.
388 const result: ServerSettings = {
389 ...settings,
390 providerInstances: providerInstances as ServerSettings["providerInstances"],
391 sourceControlWriterModelSelection: allowedSelection(
392 settings,
393 settings.sourceControlWriterModelSelection,
394 )
395 ? settings.sourceControlWriterModelSelection
396 : null,
397 reviewGuideModelSelection: allowedSelection(settings, settings.reviewGuideModelSelection)
398 ? settings.reviewGuideModelSelection
399 : null,
400 };
401 cache.set(settings, result);
402 return result;
403 };
404
405 type Locked = { readonly _tag: "Locked"; readonly path: string };
406
407 /**
408 * Vet the environment a client sent. Pinned values it echoes back are dropped; anything else
409 * the administrator owns must match what is stored. Returns the environment to store.
410 */
411 const vetEnvironment = (
412 instanceId: string,
413 stored: ProviderInstanceConfig | undefined,
414 next: ProviderInstanceConfig,
415 rule: DriverRule,
416 ):
417 | Locked
418 | {
419 readonly _tag: "Kept";
420 readonly environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>;
421 } => {
422 const pinned = rule.pin?.environment ?? [];
423 const storedVariable = (name: string) =>
424 stored?.environment?.find((existing) => variableKey(existing.name) === variableKey(name));
425 const storedUnchanged = (variable: ProviderInstanceEnvironmentVariable) =>
426 (stored?.environment ?? []).some((existing) => sameVariable(variable, existing));
427 const echoed = (variable: ProviderInstanceEnvironmentVariable) =>
428 !variable.sensitive &&
429 pinned.some((pin) => pin.name === variable.name && pin.value === variable.value);
430 if (rule.environment === "all") {
431 // Only the pinned variables were shown, so the user's own stay as stored.
432 for (const variable of next.environment ?? []) {
433 if (echoed(variable) || storedUnchanged(variable)) continue;
434 return { _tag: "Locked", path: `providerInstances.${instanceId}.environment` };
435 }
436 return { _tag: "Kept", environment: stored?.environment ?? [] };
437 }
438 let environment: ReadonlyArray<ProviderInstanceEnvironmentVariable> = next.environment ?? [];
439 for (const variable of pinned) {
440 const sent = environment.find(
441 (existing) => variableKey(existing.name) === variableKey(variable.name),
442 );
443 const kept = storedVariable(variable.name);
444 if ((sent !== undefined && echoed(sent)) || sameVariable(sent, kept)) {
445 // Put the user's own entries back where it was sent, or drop the echoed policy value.
446 const storedEntries = (stored?.environment ?? []).filter(
447 (existing) => variableKey(existing.name) === variableKey(variable.name),
448 );
449 let restored = false;
450 environment = environment.flatMap((existing) => {
451 if (variableKey(existing.name) !== variableKey(variable.name)) return [existing];
452 if (restored) return [];
453 restored = true;
454 return storedEntries;
455 });
456 } else if (rule.environment === "locked") {
457 return {
458 _tag: "Locked",
459 path: `providerInstances.${instanceId}.environment.${variable.name}`,
460 };
461 }
462 }
463 // The client never saw a launch override the lock hides, so keep the stored one.
464 if (rule.config.includes("launchArgs")) {
465 const overrides = new Set(LAUNCH_OVERRIDE_VARIABLES.map(variableKey));
466 environment = [
467 ...environment.filter((variable) => !overrides.has(variableKey(variable.name))),
468 ...(stored?.environment ?? []).filter((variable) =>
469 overrides.has(variableKey(variable.name)),
470 ),
471 ];
472 }
473 return { _tag: "Kept", environment };
474 };
475
476 const vetInstance = (
477 instanceId: string,
478 stored: ProviderInstanceConfig | undefined,
479 next: ProviderInstanceConfig,
480 rule: DriverRule,
481 ): Locked | { readonly _tag: "Kept"; readonly instance: ProviderInstanceConfig | undefined } => {
482 const config = { ...configRecord(next) };
483 const harmless = PIN_BYPASS_FIELDS.get(next.driver) ?? {};
484 for (const field of [...rule.config, ...rule.fill]) {
485 const value = configValue(next, field);
486 const storedValue = configValue(stored, field);
487 if (
488 sameValue(value, pinnedValue(rule.pin, field)) ||
489 sameValue(value, storedValue) ||
490 (field in harmless && sameValue(value, harmless[field]))
491 ) {
492 if (storedValue === undefined) delete config[field];
493 else config[field] = configRecord(stored)[field];
494 } else if (rule.config.includes(field)) {
495 return { _tag: "Locked", path: `providerInstances.${instanceId}.config.${field}` };
496 }
497 }
498 const vettedEnvironment = vetEnvironment(instanceId, stored, next, rule);
499 if (vettedEnvironment._tag === "Locked") return vettedEnvironment;
500 const { environment } = vettedEnvironment;
501 const { config: _config, environment: _environment, ...envelope } = next;
502 const kept: ProviderInstanceConfig = {
503 ...envelope,
504 ...(Object.keys(config).length === 0 && stored?.config === undefined ? {} : { config }),
505 ...(environment.length === 0 ? {} : { environment }),
506 };
507 // A default instance the client echoed back with only pinned values stays implicit.
508 const echoedDefault =
509 stored === undefined &&
510 instanceId === defaultInstanceIdForDriver(next.driver) &&
511 Object.keys(kept).length === 1;
512 return { _tag: "Kept", instance: echoedDefault ? undefined : kept };
513 };
514
515 const vetWrite = (current: ServerSettings, next: ServerSettings): ProviderWriteVerdict => {
516 const providerInstances: Record<string, ProviderInstanceConfig> = {};
517 for (const [instanceId, instance] of Object.entries(next.providerInstances)) {
518 const stored = current.providerInstances[instanceId as ProviderInstanceId];
519 // Clients echo instances with policy fields laid over them, so compare only whether it runs.
520 // A driver's default instance runs before it is configured.
521 const wasEnabled =
522 stored !== undefined
523 ? stored.driver === instance.driver && resolveProviderInstanceEnabled(stored)
524 : instanceId === defaultInstanceIdForDriver(instance.driver);
525 if (
526 !isDriverAllowed(instance.driver) &&
527 resolveProviderInstanceEnabled(instance) &&
528 !wasEnabled
529 ) {
530 return {
531 _tag: "Disallowed",
532 instanceId: instanceId as ProviderInstanceId,
533 label: labelFor(instance.driver),
534 };
535 }
536 const rule = rules.get(instance.driver);
537 if (rule === undefined) {
538 providerInstances[instanceId] = instance;
539 continue;
540 }
541 const vetted = vetInstance(
542 instanceId,
543 stored?.driver === instance.driver ? stored : undefined,
544 instance,
545 rule,
546 );
547 if (vetted._tag === "Locked") return vetted;
548 if (vetted.instance !== undefined) providerInstances[instanceId] = vetted.instance;
549 }
550 // A project can switch an instance on for itself; that is enabling it too.
551 for (const [projectId, overrides] of Object.entries(next.projectSettingsOverrides)) {
552 const storedOverrides =
553 current.projectSettingsOverrides[projectId as keyof typeof current.projectSettingsOverrides]
554 ?.providerInstances;
555 for (const [instanceId, override] of Object.entries(overrides.providerInstances ?? {})) {
556 const driver =
557 next.providerInstances[instanceId as ProviderInstanceId]?.driver ??
558 ProviderDriverKind.make(instanceId);
559 if (
560 override.enabled === true &&
561 storedOverrides?.[instanceId as ProviderInstanceId]?.enabled !== true &&
562 !isDriverAllowed(driver)
563 ) {
564 return {
565 _tag: "Disallowed",
566 instanceId: instanceId as ProviderInstanceId,
567 label: labelFor(driver),
568 };
569 }
570 }
571 }
572 return {
573 _tag: "Allowed",
574 settings: {
575 ...next,
576 providerInstances: providerInstances as ServerSettings["providerInstances"],
577 },
578 };
579 };
580
581 const lockedInstanceFields = Object.fromEntries(
582 [...rules].flatMap(([driver, rule]) => {
583 const fields = [
584 ...rule.config.map((field) => `config.${field}`),
585 ...(rule.environment === "all"
586 ? ["environment"]
587 : rule.environment === "locked"
588 ? (rule.pin?.environment ?? []).map((variable) => `environment.${variable.name}`)
589 : []),
590 ];
591 return fields.length === 0 ? [] : [[driver, fields] as const];
592 }),
593 );
594
595 return {
596 _tag: "Valid",
597 providers: {
598 isDriverAllowed,
599 applyLimits,
600 vetWrite,
601 lockedInstanceFields,
602 },
603 };
604}