diff --git a/packages/client/src/promise/generated/types.ts b/packages/client/src/promise/generated/types.ts index 67cfbf5ea05..1d27265ccdf 100644 --- a/packages/client/src/promise/generated/types.ts +++ b/packages/client/src/promise/generated/types.ts @@ -2154,6 +2154,11 @@ export type ConfigEntry = enterprise?: { url?: string } username?: string permissions?: PermissionRuleset + policies?: Array<{ + action: "provider.use" | "tool.use" | "integration.use" + resource: string + effect: "allow" | "deny" + }> agents?: { [x: string]: { model?: string | { providerID: string; model: string; variant?: string } diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index ba55687b249..7945384ac20 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -18,7 +18,6 @@ import { ConfigNormalize } from "./config/normalize.js" import { ConfigDiscovery } from "./config/discovery.js" import { ConfigWatch } from "./config/watch.js" import { WellKnown } from "./wellknown.js" -import { ConfigExperimental } from "@opencode/schema/config/experimental" import { AppProcess } from "@opencode/util/process" import { ChildProcess } from "effect/process" @@ -252,28 +251,20 @@ export const layer = (options?: Options) => ] const managedPolicies = managed .flatMap((entry) => - entry.type === "document" && entry.info.experimental?.policies + entry.type === "document" && entry.info.policies ? [ new Document({ type: "document", path: entry.path, - info: new Info({ - experimental: new ConfigExperimental.Info({ policies: entry.info.experimental.policies }), - }), + info: new Info({ policies: entry.info.policies }), }), ] : [], ) .toReversed() const managedSettings = managed.map((entry) => - entry.type === "document" && entry.info.experimental?.policies - ? new Document({ - ...entry, - info: new Info({ - ...entry.info, - experimental: new ConfigExperimental.Info({ ...entry.info.experimental, policies: undefined }), - }), - }) + entry.type === "document" && entry.info.policies + ? new Document({ ...entry, info: new Info({ ...entry.info, policies: undefined }) }) : entry, ) // Global entries sit below explicit and direct files; project directories rank above them. @@ -428,7 +419,16 @@ export function configured(options?: Options) { return makeLocationNode({ service: Service, layer: layer(options), - deps: [Watcher.node, Bus.node, FSUtil.node, Global.node, Location.node, Credential.node, WellKnown.node, AppProcess.node], + deps: [ + Watcher.node, + Bus.node, + FSUtil.node, + Global.node, + Location.node, + Credential.node, + WellKnown.node, + AppProcess.node, + ], }) } diff --git a/packages/core/src/config/normalize.ts b/packages/core/src/config/normalize.ts index dd3fb595542..4b0709adf27 100644 --- a/packages/core/src/config/normalize.ts +++ b/packages/core/src/config/normalize.ts @@ -192,6 +192,7 @@ export function normalize(input: unknown): Result { normalizeSkills(input, encoded, diagnostics) normalizeMcp(input, encoded, diagnostics) normalizeCompaction(input, encoded, diagnostics) + normalizePolicies(input, encoded, diagnostics) normalizeExperimental(input, encoded, diagnostics) normalizeWatcher(input, encoded, diagnostics) normalizeFormatter(input, encoded, diagnostics) @@ -378,12 +379,13 @@ function normalizeCompaction( if (Object.keys(result).length || !Object.keys(input.compaction).length) encoded.compaction = result } -function normalizeExperimental( +// V1 provider lists and `experimental.policies` stay supported and merge into +// top-level `policies`; within a document, later sources win ties. +function normalizePolicies( input: Record, encoded: Record, diagnostics: Diagnostic[], ) { - const result: Record = {} const generated: unknown[] = [] const enabled = decodeProviderList(input, "enabled_providers", diagnostics) if (enabled.present && (!enabled.nonEmpty || enabled.values.length)) { @@ -404,7 +406,32 @@ function normalizeExperimental( effect: "deny", })), ) - const native: unknown[] = [] + const experimental = isRecord(input.experimental) + ? decodeList( + input.experimental.policies, + ConfigPolicy.Info, + ["experimental", "policies"], + diagnostics, + decodeEncoded, + ) + : [] + const native = decodeList(input.policies, ConfigPolicy.Info, ["policies"], diagnostics, decodeEncoded) + if ( + generated.length || + experimental.length || + native.length || + Array.isArray(input.policies) || + (isRecord(input.experimental) && Array.isArray(input.experimental.policies)) + ) + encoded.policies = [...generated, ...experimental, ...native] +} + +function normalizeExperimental( + input: Record, + encoded: Record, + diagnostics: Diagnostic[], +) { + const result: Record = {} if (own(input, "experimental")) { if (!isRecord(input.experimental)) invalid(["experimental"], diagnostics) if (isRecord(input.experimental)) { @@ -430,19 +457,8 @@ function normalizeExperimental( ) if (value !== undefined) result.subagent_depth = value } - native.push( - ...decodeList( - experimental.policies, - ConfigPolicy.Info, - ["experimental", "policies"], - diagnostics, - decodeEncoded, - ), - ) } } - if (generated.length || native.length || (isRecord(input.experimental) && Array.isArray(input.experimental.policies))) - result.policies = [...generated, ...native] if (Object.keys(result).length || (isRecord(input.experimental) && !Object.keys(input.experimental).length)) encoded.experimental = result } diff --git a/packages/core/src/managed-policy.ts b/packages/core/src/managed-policy.ts index 0813a4995f3..ad595c22a5a 100644 --- a/packages/core/src/managed-policy.ts +++ b/packages/core/src/managed-policy.ts @@ -52,7 +52,7 @@ export function statements(entries: readonly Entry[], organization: State) { ...entries .filter((entry): entry is Document => entry.type === "document") .toReversed() - .flatMap((entry) => entry.info.experimental?.policies ?? []) + .flatMap((entry) => entry.info.policies ?? []) .map((policy) => ({ ...policy, message: "Blocked by configuration policy" })), ...organization.statements.map((policy) => ({ ...policy, diff --git a/packages/core/src/plugin/provider/opencode.ts b/packages/core/src/plugin/provider/opencode.ts index 75de26333ac..90705c1d916 100644 --- a/packages/core/src/plugin/provider/opencode.ts +++ b/packages/core/src/plugin/provider/opencode.ts @@ -20,6 +20,23 @@ import { Money } from "@opencode/schema/money" const defaultServer = "https://opencode.ai/console" const clientID = "opencode-cli" const methodID = Integration.MethodID.make("device") +// Drop statements whose action or effect is a value this version does not know, so a newer Console can +// extend either enum. Malformed statements still fail validation. +const RemotePolicies = Schema.Array(Schema.Unknown).pipe( + Schema.decodeTo(Schema.Unknown, { + decode: SchemaGetter.transform((policies) => + policies.filter((policy) => { + const action = Schema.decodeUnknownOption(Schema.Struct({ action: Schema.String }))(policy) + if (Option.isSome(action) && !Schema.is(ConfigPolicy.Info.fields.action)(action.value.action)) return false + const effect = Schema.decodeUnknownOption(Schema.Struct({ effect: Schema.String }))(policy) + return Option.isNone(effect) || Schema.is(ConfigPolicy.Effect)(effect.value.effect) + }), + ), + encode: SchemaGetter.passthrough({ strict: false }), + }), + Schema.decodeTo(Schema.Array(ConfigPolicy.Info)), + Schema.optional, +) const RemoteResponse = Schema.Struct({ providers: Schema.Record(Schema.String, ConfigProvider.Info), websearch: Schema.Struct({ @@ -35,22 +52,9 @@ const RemoteResponse = Schema.Struct({ ), }).pipe(Schema.optional), // Organization policy compiled for the authenticated caller; omitted when there is none. - experimental: Schema.Struct({ - policies: Schema.Array(Schema.Unknown).pipe( - Schema.decodeTo(Schema.Unknown, { - // Filter only unsupported actions. Malformed supported statements still fail validation. - decode: SchemaGetter.transform((policies) => - policies.filter((policy) => { - const action = Schema.decodeUnknownOption(Schema.Struct({ action: Schema.String }))(policy) - return Option.isNone(action) || Schema.is(ConfigPolicy.Info.fields.action)(action.value.action) - }), - ), - encode: SchemaGetter.passthrough({ strict: false }), - }), - Schema.decodeTo(Schema.Array(ConfigPolicy.Info)), - Schema.optional, - ), - }).pipe(Schema.optional), + // `experimental.policies` remains accepted alongside top-level `policies`. + policies: RemotePolicies, + experimental: Schema.Struct({ policies: RemotePolicies }).pipe(Schema.optional), }) const Device = Schema.Struct({ device_code: Schema.String, @@ -243,7 +247,10 @@ export const OpencodePlugin = define - managed.set({ statements: next.config?.experimental?.policies ?? [], organization: next.organization }) + managed.set({ + statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])], + organization: next.organization, + }) yield* ctx.integration.transform((editor) => { editor.update("opencode", (integration) => { diff --git a/packages/core/test/config/config.test.ts b/packages/core/test/config/config.test.ts index 47590d9f534..071e24a447b 100644 --- a/packages/core/test/config/config.test.ts +++ b/packages/core/test/config/config.test.ts @@ -709,7 +709,7 @@ describe("Config", () => { const project = path.join(tmp.path, "project") const remote = (entries: readonly Entry[]) => ({ provider: Config.latest(entries, "providers")?.remote?.package, - policies: Config.latest(entries, "experimental")?.policies, + policies: Config.latest(entries, "policies"), }) const loaded = { provider: "aisdk:@ai-sdk/openai-compatible", @@ -966,14 +966,14 @@ describe("Config", () => { migrateV1({ enabled_providers: ["anthropic", "openai"], disabled_providers: ["openai"], - }).experimental?.policies, + }).policies, ).toEqual([ { action: "provider.use", resource: "*", effect: "deny" }, { action: "provider.use", resource: "anthropic", effect: "allow" }, { action: "provider.use", resource: "openai", effect: "allow" }, { action: "provider.use", resource: "openai", effect: "deny" }, ]) - expect(migrateV1({ enabled_providers: [] }).experimental?.policies).toEqual([ + expect(migrateV1({ enabled_providers: [] }).policies).toEqual([ { action: "provider.use", resource: "*", effect: "deny" }, ]) }) @@ -1031,7 +1031,7 @@ describe("Config", () => { expect(migrated.model).toEqual({ providerID: "azure", model: "deployment" }) expect(migrated.agents?.reviewer?.model).toEqual({ providerID: "google-vertex", model: "claude-sonnet" }) expect(migrated.commands?.review?.model).toEqual({ providerID: "azure", model: "deployment" }) - expect(migrated.experimental?.policies).toEqual([ + expect(migrated.policies).toEqual([ { action: "provider.use", resource: "*", effect: "deny" }, { action: "provider.use", resource: "google-vertex", effect: "allow" }, { action: "provider.use", resource: "azure", effect: "deny" }, diff --git a/packages/core/test/config/normalization.test.ts b/packages/core/test/config/normalization.test.ts index 6029a3a1d67..3990f95bce1 100644 --- a/packages/core/test/config/normalization.test.ts +++ b/packages/core/test/config/normalization.test.ts @@ -44,6 +44,15 @@ function withoutEmptyCompatibilityContainers(input: Record) { delete compaction.keep if (!originallyEmpty && !Object.keys(compaction).length) delete result.compaction } + // Deprecated experimental policies normalize into top-level policies. + if (typeof result.experimental === "object" && result.experimental !== null && !Array.isArray(result.experimental)) { + const experimental = result.experimental as Record + if (Array.isArray(experimental.policies)) { + result.policies = [...experimental.policies, ...(Array.isArray(result.policies) ? result.policies : [])] + delete experimental.policies + if (!Object.keys(experimental).length) delete result.experimental + } + } return result } @@ -56,7 +65,7 @@ describe("ConfigNormalize", () => { ] as const const result = normalized({ experimental: { policies } }) expect(result.diagnostics).toEqual([]) - expect(Schema.decodeUnknownSync(Info)(result.encoded).experimental?.policies).toEqual(policies) + expect(Schema.decodeUnknownSync(Info)(result.encoded).policies).toEqual(policies) }) test("drops unsupported policy actions without losing supported policies", () => { @@ -70,7 +79,7 @@ describe("ConfigNormalize", () => { ], }, }) - expect(Schema.decodeUnknownSync(Info)(result.encoded).experimental?.policies).toEqual([supported]) + expect(Schema.decodeUnknownSync(Info)(result.encoded).policies).toEqual([supported]) expect(result.diagnostics.map((diagnostic) => diagnostic.path)).toEqual([ ["experimental", "policies", "0"], ["experimental", "policies", "2"], @@ -467,42 +476,47 @@ describe("ConfigNormalize", () => { }) test("distinguishes empty, mixed, and wholly malformed enabled provider lists", () => { - expect(normalized({ enabled_providers: [] }).encoded.experimental).toEqual({ - policies: [{ action: "provider.use", resource: "*", effect: "deny" }], - }) - expect(normalized({ enabled_providers: [1, "anthropic", false] }).encoded.experimental).toEqual({ - policies: [ - { action: "provider.use", resource: "*", effect: "deny" }, - { action: "provider.use", resource: "anthropic", effect: "allow" }, - ], - }) - expect(normalized({ enabled_providers: [1, false] }).encoded.experimental).toBeUndefined() - expect(normalized({ enabled_providers: "anthropic" }).encoded.experimental).toBeUndefined() + expect(normalized({ enabled_providers: [] }).encoded.policies).toEqual([ + { action: "provider.use", resource: "*", effect: "deny" }, + ]) + expect(normalized({ enabled_providers: [1, "anthropic", false] }).encoded.policies).toEqual([ + { action: "provider.use", resource: "*", effect: "deny" }, + { action: "provider.use", resource: "anthropic", effect: "allow" }, + ]) + expect(normalized({ enabled_providers: [1, false] }).encoded.policies).toBeUndefined() + expect(normalized({ enabled_providers: "anthropic" }).encoded.policies).toBeUndefined() }) - test("appends native policies after migrated provider policies", () => { + test("merges migrated, experimental, and native policies in order", () => { expect( normalized({ enabled_providers: ["anthropic"], disabled_providers: ["openai"], + policies: [{ action: "provider.use", resource: "native", effect: "deny" }], experimental: { portable_shell_scanner: true, subagent_depth: 0, policies: [{ action: "provider.use", resource: "custom", effect: "allow" }], }, - }).encoded.experimental, - ).toEqual({ - portable_shell_scanner: true, - subagent_depth: 0, + }).encoded, + ).toMatchObject({ + experimental: { portable_shell_scanner: true, subagent_depth: 0 }, policies: [ { action: "provider.use", resource: "*", effect: "deny" }, { action: "provider.use", resource: "anthropic", effect: "allow" }, { action: "provider.use", resource: "openai", effect: "deny" }, { action: "provider.use", resource: "custom", effect: "allow" }, + { action: "provider.use", resource: "native", effect: "deny" }, ], }) }) + test("never emits experimental policies", () => { + expect( + normalized({ experimental: { policies: [{ action: "provider.use", resource: "*", effect: "deny" }] } }).encoded, + ).toEqual({ policies: [{ action: "provider.use", resource: "*", effect: "deny" }] }) + }) + test("reports unsupported legacy settings without including their values", () => { const secret = "do-not-log-this-value" const result = normalized({ diff --git a/packages/core/test/config/policy.test.ts b/packages/core/test/config/policy.test.ts index eb54675408f..9e312ae5277 100644 --- a/packages/core/test/config/policy.test.ts +++ b/packages/core/test/config/policy.test.ts @@ -18,8 +18,7 @@ import { PluginTestLayer } from "../plugin/fixture" const it = testEffect(PluginTestLayer) const decode = Schema.decodeUnknownSync(Info) -const document = (...policies: ConfigPolicy.Info[]) => - new Document({ type: "document", info: decode({ experimental: { policies } }) }) +const document = (...policies: ConfigPolicy.Info[]) => new Document({ type: "document", info: decode({ policies }) }) const provider = (effect: ConfigPolicy.Effect, resource: string): ConfigPolicy.Info => ({ action: "provider.use", resource, diff --git a/packages/core/test/mcp.test.ts b/packages/core/test/mcp.test.ts index 2549d45ec3e..c032afeaac0 100644 --- a/packages/core/test/mcp.test.ts +++ b/packages/core/test/mcp.test.ts @@ -311,7 +311,7 @@ function resourceMcpLayer( new Document({ type: "document", info: new Info({ - experimental: { policies: overrides?.policies ?? [] }, + policies: overrides?.policies ?? [], mcp: new ConfigMCP.Info({ servers: { resources: @@ -2635,7 +2635,7 @@ for (const source of ["config", "organization"] as const) { mcp: new ConfigMCP.Info({ servers: { resources: new ConfigMCP.Remote({ type: "remote", url: server.url, oauth: false }) }, }), - experimental: { policies: [{ action: "integration.use", resource: "mcp:*", effect }] }, + policies: [{ action: "integration.use", resource: "mcp:*", effect }], }), }) yield* test.setEntries([document("allow")]) diff --git a/packages/core/test/plugin/provider-opencode.test.ts b/packages/core/test/plugin/provider-opencode.test.ts index a5be7ad5e5a..fae36926a7c 100644 --- a/packages/core/test/plugin/provider-opencode.test.ts +++ b/packages/core/test/plugin/provider-opencode.test.ts @@ -766,7 +766,7 @@ describe("OpencodePlugin", () => { ), ) - it.effect("ignores unsupported managed actions and keys while enforcing supported policies", () => + it.effect("ignores unsupported managed actions, effects, and keys while enforcing supported policies", () => Effect.acquireUseRelease( Effect.sync(() => Bun.serve({ @@ -781,6 +781,7 @@ describe("OpencodePlugin", () => { { action: "provider.use", resource: "opencode", effect: "allow" }, { action: "tool.use", resource: "shell:*", effect: "deny" }, { action: "tool.use", resource: "shell:git *", effect: "allow" }, + { action: "tool.use", resource: "shell:git status", effect: "future-effect" }, { action: "permission", resource: "*", effect: "deny" }, { action: "tool.use", resource: "shell:sudo *", effect: "deny", audience: "ignored" }, { action: "integration.use", resource: "mcp:restricted", effect: "deny" }, @@ -845,7 +846,7 @@ describe("OpencodePlugin", () => { ), ) - it.effect("refreshes past future-only policies while retaining config on malformed supported statements", () => + it.effect("refreshes past future-only policies while retaining config on malformed statements", () => Effect.acquireUseRelease( Effect.sync(() => { const state: { policies: unknown[] } = { @@ -877,7 +878,6 @@ describe("OpencodePlugin", () => { expect(managed.current()).toEqual({ statements: [sudo], organization: "Acme" }) for (const malformed of [ - { action: "tool.use", resource: "shell:*", effect: "future-effect" }, { action: "tool.use", resource: 42, effect: "deny" }, { action: "tool.use", effect: "deny" }, null, @@ -890,6 +890,11 @@ describe("OpencodePlugin", () => { expect(yield* providers.get(Provider.ID.opencode)).toBeDefined() } + state.policies = [env, { action: "tool.use", resource: "shell:*", effect: "future-effect" }] + yield* TestClock.adjust("1 minute") + yield* drain + expect(managed.current()).toEqual({ statements: [env], organization: "Acme" }) + state.policies = [{ action: "future.use", future: { values: [true] } }] yield* TestClock.adjust("1 minute") yield* drain diff --git a/packages/core/test/skill.test.ts b/packages/core/test/skill.test.ts index 3ddbd418b76..175bf9fc5c6 100644 --- a/packages/core/test/skill.test.ts +++ b/packages/core/test/skill.test.ts @@ -45,7 +45,7 @@ describe("Skill", () => { new Document({ type: "document", info: { - experimental: { policies: [{ action: "integration.use", resource: "skill:*", effect: "allow" }] }, + policies: [{ action: "integration.use", resource: "skill:*", effect: "allow" }], }, }), ]) @@ -82,12 +82,12 @@ describe("Skill", () => { yield* config.setEntries([ new Document({ type: "document", - info: { experimental: { policies: [{ action: "integration.use", resource: "skill:*", effect: "deny" }] } }, + info: { policies: [{ action: "integration.use", resource: "skill:*", effect: "deny" }] }, }), new Document({ type: "document", info: { - experimental: { policies: [{ action: "integration.use", resource: "skill:review", effect: "allow" }] }, + policies: [{ action: "integration.use", resource: "skill:review", effect: "allow" }], }, }), ]) diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index 8c9bda790fb..3f16b0f0706 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -13817,6 +13817,27 @@ "permissions": { "$ref": "#/components/schemas/Permission.Ruleset" }, + "policies": { + "type": "array", + "items": { + "type": "object", + "properties": { + "action": { + "type": "string", + "enum": ["provider.use", "tool.use", "integration.use"] + }, + "resource": { + "type": "string" + }, + "effect": { + "type": "string", + "enum": ["allow", "deny"] + } + }, + "required": ["action", "resource", "effect"], + "additionalProperties": false + } + }, "agents": { "type": "object", "additionalProperties": { @@ -14190,6 +14211,9 @@ "properties": { "compaction": { "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -14369,6 +14393,9 @@ }, "transport": { "$ref": "#/components/schemas/Provider.Transport" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -16838,6 +16865,9 @@ "properties": { "compaction": { "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -17755,6 +17785,10 @@ }, "additionalProperties": false }, + "Provider.Encoding": { + "type": "string", + "enum": ["zstd", "gzip", "none"] + }, "Provider.ID": { "type": "string" }, @@ -17859,6 +17893,9 @@ }, "transport": { "$ref": "#/components/schemas/Provider.Transport" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ diff --git a/packages/schema/src/config.ts b/packages/schema/src/config.ts index dc1791f8a1e..732947eb3fe 100644 --- a/packages/schema/src/config.ts +++ b/packages/schema/src/config.ts @@ -14,6 +14,7 @@ import { ConfigLSP } from "./config/lsp.js" import { ConfigMCP } from "./config/mcp.js" import { ConfigModel } from "./config/model.js" import { ConfigPlugin } from "./config/plugin.js" +import { ConfigPolicy } from "./config/policy.js" import { ConfigProvider } from "./config/provider.js" import { ConfigReference } from "./config/reference.js" import { ConfigWebSearch } from "./config/websearch.js" @@ -54,6 +55,9 @@ export class Info extends Schema.Class("Config.Info")({ permissions: Permission.Ruleset.pipe(optional).annotate({ description: "Ordered tool permission rules applied to agent tool use", }), + policies: ConfigPolicy.Info.pipe(Schema.Array, optional).annotate({ + description: "Ordered policies controlling access to providers, tools, and integrations", + }), agents: Schema.Record(Schema.String, ConfigAgent.Info).pipe(optional).annotate({ description: "Named built-in agent overrides and custom agent definitions", }), diff --git a/packages/schema/src/config/experimental.ts b/packages/schema/src/config/experimental.ts index 84dfa4b19b8..be9134feeb0 100644 --- a/packages/schema/src/config/experimental.ts +++ b/packages/schema/src/config/experimental.ts @@ -12,6 +12,6 @@ export class Info extends Schema.Class("ConfigExperimental.Info")({ description: "Maximum subagent nesting depth. Defaults to 1.", }), policies: ConfigPolicy.Info.pipe(Schema.Array, optional).annotate({ - description: "Ordered policies controlling access to configured resources", + description: "Deprecated: use top-level policies. Ordered policies controlling access to configured resources", }), }) {} diff --git a/services/www/openapi.json b/services/www/openapi.json index 8c9bda790fb..3f16b0f0706 100644 --- a/services/www/openapi.json +++ b/services/www/openapi.json @@ -13817,6 +13817,27 @@ "permissions": { "$ref": "#/components/schemas/Permission.Ruleset" }, + "policies": { + "type": "array", + "items": { + "type": "object", + "properties": { + "action": { + "type": "string", + "enum": ["provider.use", "tool.use", "integration.use"] + }, + "resource": { + "type": "string" + }, + "effect": { + "type": "string", + "enum": ["allow", "deny"] + } + }, + "required": ["action", "resource", "effect"], + "additionalProperties": false + } + }, "agents": { "type": "object", "additionalProperties": { @@ -14190,6 +14211,9 @@ "properties": { "compaction": { "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -14369,6 +14393,9 @@ }, "transport": { "$ref": "#/components/schemas/Provider.Transport" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -16838,6 +16865,9 @@ "properties": { "compaction": { "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -17755,6 +17785,10 @@ }, "additionalProperties": false }, + "Provider.Encoding": { + "type": "string", + "enum": ["zstd", "gzip", "none"] + }, "Provider.ID": { "type": "string" }, @@ -17859,6 +17893,9 @@ }, "transport": { "$ref": "#/components/schemas/Provider.Transport" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ diff --git a/services/www/public/openapi.json b/services/www/public/openapi.json index 8c9bda790fb..3f16b0f0706 100644 --- a/services/www/public/openapi.json +++ b/services/www/public/openapi.json @@ -13817,6 +13817,27 @@ "permissions": { "$ref": "#/components/schemas/Permission.Ruleset" }, + "policies": { + "type": "array", + "items": { + "type": "object", + "properties": { + "action": { + "type": "string", + "enum": ["provider.use", "tool.use", "integration.use"] + }, + "resource": { + "type": "string" + }, + "effect": { + "type": "string", + "enum": ["allow", "deny"] + } + }, + "required": ["action", "resource", "effect"], + "additionalProperties": false + } + }, "agents": { "type": "object", "additionalProperties": { @@ -14190,6 +14211,9 @@ "properties": { "compaction": { "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -14369,6 +14393,9 @@ }, "transport": { "$ref": "#/components/schemas/Provider.Transport" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -16838,6 +16865,9 @@ "properties": { "compaction": { "$ref": "#/components/schemas/Provider.Compaction" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ @@ -17755,6 +17785,10 @@ }, "additionalProperties": false }, + "Provider.Encoding": { + "type": "string", + "enum": ["zstd", "gzip", "none"] + }, "Provider.ID": { "type": "string" }, @@ -17859,6 +17893,9 @@ }, "transport": { "$ref": "#/components/schemas/Provider.Transport" + }, + "encoding": { + "$ref": "#/components/schemas/Provider.Encoding" } }, "allOf": [ diff --git a/services/www/src/docs/content/config.mdx b/services/www/src/docs/content/config.mdx index 77a56d0d100..c3937024948 100644 --- a/services/www/src/docs/content/config.mdx +++ b/services/www/src/docs/content/config.mdx @@ -227,13 +227,11 @@ override. ```jsonc { - "experimental": { - "policies": [ - { "action": "provider.use", "resource": "*", "effect": "deny" }, - { "action": "provider.use", "resource": "anthropic", "effect": "allow" }, - { "action": "tool.use", "resource": "shell:git push *", "effect": "deny" }, - ], - }, + "policies": [ + { "action": "provider.use", "resource": "*", "effect": "deny" }, + { "action": "provider.use", "resource": "anthropic", "effect": "allow" }, + { "action": "tool.use", "resource": "shell:git push *", "effect": "deny" }, + ], } ``` diff --git a/services/www/src/docs/content/migrate-v1.mdx b/services/www/src/docs/content/migrate-v1.mdx index 42b099a84b0..8bbec0982bf 100644 --- a/services/www/src/docs/content/migrate-v1.mdx +++ b/services/www/src/docs/content/migrate-v1.mdx @@ -68,7 +68,7 @@ V2. As in V1, system configuration and macOS managed preferences have the highest precedence, so their settings override global and project files. Their [policies](/policies#precedence), including migrated `enabled_providers` and `disabled_providers`, also outrank global and project policies. Overriding a setting cannot stop users from adding -providers, MCP servers, agents, or plugins, so express admin-enforced restrictions as `experimental.policies` rather +providers, MCP servers, agents, or plugins, so express admin-enforced restrictions as `policies` rather than ordinary settings such as `permissions`. ### Ask OpenCode to migrate diff --git a/services/www/src/docs/content/permissions.mdx b/services/www/src/docs/content/permissions.mdx index a91ed74689e..7d4192532f4 100644 --- a/services/www/src/docs/content/permissions.mdx +++ b/services/www/src/docs/content/permissions.mdx @@ -285,9 +285,7 @@ approvals run. It turns `allow` or `ask` into `deny` and never grants access. ```jsonc { - "experimental": { - "policies": [{ "action": "tool.use", "resource": "shell:sudo *", "effect": "deny" }], - }, + "policies": [{ "action": "tool.use", "resource": "shell:sudo *", "effect": "deny" }], } ``` diff --git a/services/www/src/docs/content/policies.mdx b/services/www/src/docs/content/policies.mdx index 3ef71840747..ae4dee398c8 100644 --- a/services/www/src/docs/content/policies.mdx +++ b/services/www/src/docs/content/policies.mdx @@ -4,7 +4,7 @@ description: "Allow or deny OpenCode actions on named resources, with organizati --- Policies decide whether OpenCode may perform an action on a named resource. They are -authored under `experimental.policies` and can also be delivered by a connected +authored under `policies` and can also be delivered by a connected [OpenCode Console](/console) workspace. Policies are separate from [permissions](/permissions). Permissions are per-agent tool @@ -18,15 +18,24 @@ Deny one provider everywhere by adding a statement to `opencode.jsonc`: ```jsonc { "$schema": "https://opencode.ai/config.json", - "experimental": { - "policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }], - }, + "policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }], } ``` A denied provider disappears from the catalog and model selection even when it has valid credentials. +Earlier releases read policies from `experimental.policies`. That key still works and +merges into `policies`: + +```jsonc +{ + "experimental": { + "policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }], + }, +} +``` + ## Statements Each statement has three fields: @@ -47,9 +56,7 @@ more characters and `?` matches one. ```jsonc { - "experimental": { - "policies": [{ "action": "provider.use", "resource": "company-*", "effect": "deny" }], - }, + "policies": [{ "action": "provider.use", "resource": "company-*", "effect": "deny" }], } ``` @@ -64,12 +71,10 @@ action is allowed. ```jsonc { - "experimental": { - "policies": [ - { "action": "provider.use", "resource": "*", "effect": "deny" }, - { "action": "provider.use", "resource": "anthropic", "effect": "allow" }, - ], - }, + "policies": [ + { "action": "provider.use", "resource": "*", "effect": "deny" }, + { "action": "provider.use", "resource": "anthropic", "effect": "allow" }, + ], } ``` @@ -89,12 +94,10 @@ provider ID: `anthropic`, `openai`, `opencode`, or a custom ID from "settings": { "baseURL": "https://ai.company.example/v1" }, }, }, - "experimental": { - "policies": [ - { "action": "provider.use", "resource": "*", "effect": "deny" }, - { "action": "provider.use", "resource": "company-ai", "effect": "allow" }, - ], - }, + "policies": [ + { "action": "provider.use", "resource": "*", "effect": "deny" }, + { "action": "provider.use", "resource": "company-ai", "effect": "allow" }, + ], } ``` @@ -113,13 +116,11 @@ lists. V1 files still load; see ```jsonc { - "experimental": { - "policies": [ - { "action": "tool.use", "resource": "shell:git push *", "effect": "deny" }, - { "action": "tool.use", "resource": "edit:*.env", "effect": "deny" }, - { "action": "tool.use", "resource": "webfetch:*", "effect": "deny" }, - ], - }, + "policies": [ + { "action": "tool.use", "resource": "shell:git push *", "effect": "deny" }, + { "action": "tool.use", "resource": "edit:*.env", "effect": "deny" }, + { "action": "tool.use", "resource": "webfetch:*", "effect": "deny" }, + ], } ``` @@ -141,12 +142,10 @@ broader `deny`, after which the agent's own rules decide. ```jsonc { - "experimental": { - "policies": [ - { "action": "tool.use", "resource": "shell:*", "effect": "deny" }, - { "action": "tool.use", "resource": "shell:git status *", "effect": "allow" }, - ], - }, + "policies": [ + { "action": "tool.use", "resource": "shell:*", "effect": "deny" }, + { "action": "tool.use", "resource": "shell:git status *", "effect": "allow" }, + ], } ``` @@ -165,13 +164,11 @@ resource is the integration kind and its ID: ```jsonc { - "experimental": { - "policies": [ - { "action": "integration.use", "resource": "mcp:*", "effect": "deny" }, - { "action": "integration.use", "resource": "mcp:github", "effect": "allow" }, - { "action": "integration.use", "resource": "plugin:opencode-acme-cli", "effect": "deny" }, - ], - }, + "policies": [ + { "action": "integration.use", "resource": "mcp:*", "effect": "deny" }, + { "action": "integration.use", "resource": "mcp:github", "effect": "allow" }, + { "action": "integration.use", "resource": "plugin:opencode-acme-cli", "effect": "deny" }, + ], } ``` @@ -197,17 +194,13 @@ A repository cannot re-enable a provider you deny globally: ```jsonc title="~/.config/opencode/opencode.jsonc" { - "experimental": { - "policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }], - }, + "policies": [{ "action": "provider.use", "resource": "openai", "effect": "deny" }], } ``` ```jsonc title="project/opencode.jsonc" { - "experimental": { - "policies": [{ "action": "provider.use", "resource": "openai", "effect": "allow" }], - }, + "policies": [{ "action": "provider.use", "resource": "openai", "effect": "allow" }], } ```