GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(core): stabilize top-level policies config (#55297) · matglas/opencode@f576da5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • client/src/promise/generated
      • types.ts
    • core
      • src
        • config.ts
        • config
          • normalize.ts
        • managed-policy.ts
        • plugin/provider
          • opencode.ts
      • test
        • config
          • config.test.ts
          • normalization.test.ts
          • policy.test.ts
        • mcp.test.ts
        • plugin
          • provider-opencode.test.ts
        • skill.test.ts
    • protocol
      • openapi.json
    • schema/src
      • config.ts
      • config
        • experimental.ts
  • services/www
    • openapi.json
    • public
      • openapi.json
    • src/docs/content
      • config.mdx
      • migrate-v1.mdx
      • permissions.mdx
      • policies.mdx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/client/src/promise/generated/types.ts‎

Copy file name to clipboardExpand all lines: packages/client/src/promise/generated/types.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,11 @@ export type ConfigEntry =
21542154
enterprise?: { url?: string }
21552155
username?: string
21562156
permissions?: PermissionRuleset
2157+
policies?: Array<{
2158+
action: "provider.use" | "tool.use" | "integration.use"
2159+
resource: string
2160+
effect: "allow" | "deny"
2161+
}>
21572162
agents?: {
21582163
[x: string]: {
21592164
model?: string | { providerID: string; model: string; variant?: string }
Collapse file

‎packages/core/src/config.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/config.ts
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { ConfigNormalize } from "./config/normalize.js"
1818
import { ConfigDiscovery } from "./config/discovery.js"
1919
import { ConfigWatch } from "./config/watch.js"
2020
import { WellKnown } from "./wellknown.js"
21-
import { ConfigExperimental } from "@opencode/schema/config/experimental"
2221
import { AppProcess } from "@opencode/util/process"
2322
import { ChildProcess } from "effect/process"
2423

@@ -252,28 +251,20 @@ export const layer = (options?: Options) =>
252251
]
253252
const managedPolicies = managed
254253
.flatMap((entry) =>
255-
entry.type === "document" && entry.info.experimental?.policies
254+
entry.type === "document" && entry.info.policies
256255
? [
257256
new Document({
258257
type: "document",
259258
path: entry.path,
260-
info: new Info({
261-
experimental: new ConfigExperimental.Info({ policies: entry.info.experimental.policies }),
262-
}),
259+
info: new Info({ policies: entry.info.policies }),
263260
}),
264261
]
265262
: [],
266263
)
267264
.toReversed()
268265
const managedSettings = managed.map((entry) =>
269-
entry.type === "document" && entry.info.experimental?.policies
270-
? new Document({
271-
...entry,
272-
info: new Info({
273-
...entry.info,
274-
experimental: new ConfigExperimental.Info({ ...entry.info.experimental, policies: undefined }),
275-
}),
276-
})
266+
entry.type === "document" && entry.info.policies
267+
? new Document({ ...entry, info: new Info({ ...entry.info, policies: undefined }) })
277268
: entry,
278269
)
279270
// Global entries sit below explicit and direct files; project directories rank above them.
@@ -428,7 +419,16 @@ export function configured(options?: Options) {
428419
return makeLocationNode({
429420
service: Service,
430421
layer: layer(options),
431-
deps: [Watcher.node, Bus.node, FSUtil.node, Global.node, Location.node, Credential.node, WellKnown.node, AppProcess.node],
422+
deps: [
423+
Watcher.node,
424+
Bus.node,
425+
FSUtil.node,
426+
Global.node,
427+
Location.node,
428+
Credential.node,
429+
WellKnown.node,
430+
AppProcess.node,
431+
],
432432
})
433433
}
434434

Collapse file

‎packages/core/src/config/normalize.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/config/normalize.ts
+30-14Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export function normalize(input: unknown): Result {
192192
normalizeSkills(input, encoded, diagnostics)
193193
normalizeMcp(input, encoded, diagnostics)
194194
normalizeCompaction(input, encoded, diagnostics)
195+
normalizePolicies(input, encoded, diagnostics)
195196
normalizeExperimental(input, encoded, diagnostics)
196197
normalizeWatcher(input, encoded, diagnostics)
197198
normalizeFormatter(input, encoded, diagnostics)
@@ -378,12 +379,13 @@ function normalizeCompaction(
378379
if (Object.keys(result).length || !Object.keys(input.compaction).length) encoded.compaction = result
379380
}
380381

381-
function normalizeExperimental(
382+
// V1 provider lists and `experimental.policies` stay supported and merge into
383+
// top-level `policies`; within a document, later sources win ties.
384+
function normalizePolicies(
382385
input: Record<string, unknown>,
383386
encoded: Record<string, unknown>,
384387
diagnostics: Diagnostic[],
385388
) {
386-
const result: Record<string, unknown> = {}
387389
const generated: unknown[] = []
388390
const enabled = decodeProviderList(input, "enabled_providers", diagnostics)
389391
if (enabled.present && (!enabled.nonEmpty || enabled.values.length)) {
@@ -404,7 +406,32 @@ function normalizeExperimental(
404406
effect: "deny",
405407
})),
406408
)
407-
const native: unknown[] = []
409+
const experimental = isRecord(input.experimental)
410+
? decodeList(
411+
input.experimental.policies,
412+
ConfigPolicy.Info,
413+
["experimental", "policies"],
414+
diagnostics,
415+
decodeEncoded,
416+
)
417+
: []
418+
const native = decodeList(input.policies, ConfigPolicy.Info, ["policies"], diagnostics, decodeEncoded)
419+
if (
420+
generated.length ||
421+
experimental.length ||
422+
native.length ||
423+
Array.isArray(input.policies) ||
424+
(isRecord(input.experimental) && Array.isArray(input.experimental.policies))
425+
)
426+
encoded.policies = [...generated, ...experimental, ...native]
427+
}
428+
429+
function normalizeExperimental(
430+
input: Record<string, unknown>,
431+
encoded: Record<string, unknown>,
432+
diagnostics: Diagnostic[],
433+
) {
434+
const result: Record<string, unknown> = {}
408435
if (own(input, "experimental")) {
409436
if (!isRecord(input.experimental)) invalid(["experimental"], diagnostics)
410437
if (isRecord(input.experimental)) {
@@ -430,19 +457,8 @@ function normalizeExperimental(
430457
)
431458
if (value !== undefined) result.subagent_depth = value
432459
}
433-
native.push(
434-
...decodeList(
435-
experimental.policies,
436-
ConfigPolicy.Info,
437-
["experimental", "policies"],
438-
diagnostics,
439-
decodeEncoded,
440-
),
441-
)
442460
}
443461
}
444-
if (generated.length || native.length || (isRecord(input.experimental) && Array.isArray(input.experimental.policies)))
445-
result.policies = [...generated, ...native]
446462
if (Object.keys(result).length || (isRecord(input.experimental) && !Object.keys(input.experimental).length))
447463
encoded.experimental = result
448464
}
Collapse file

‎packages/core/src/managed-policy.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/managed-policy.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function statements(entries: readonly Entry[], organization: State) {
5252
...entries
5353
.filter((entry): entry is Document => entry.type === "document")
5454
.toReversed()
55-
.flatMap((entry) => entry.info.experimental?.policies ?? [])
55+
.flatMap((entry) => entry.info.policies ?? [])
5656
.map((policy) => ({ ...policy, message: "Blocked by configuration policy" })),
5757
...organization.statements.map((policy) => ({
5858
...policy,
Collapse file

‎packages/core/src/plugin/provider/opencode.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/plugin/provider/opencode.ts
+24-17Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ import { Money } from "@opencode/schema/money"
2020
const defaultServer = "https://opencode.ai/console"
2121
const clientID = "opencode-cli"
2222
const methodID = Integration.MethodID.make("device")
23+
// Drop statements whose action or effect is a value this version does not know, so a newer Console can
24+
// extend either enum. Malformed statements still fail validation.
25+
const RemotePolicies = Schema.Array(Schema.Unknown).pipe(
26+
Schema.decodeTo(Schema.Unknown, {
27+
decode: SchemaGetter.transform((policies) =>
28+
policies.filter((policy) => {
29+
const action = Schema.decodeUnknownOption(Schema.Struct({ action: Schema.String }))(policy)
30+
if (Option.isSome(action) && !Schema.is(ConfigPolicy.Info.fields.action)(action.value.action)) return false
31+
const effect = Schema.decodeUnknownOption(Schema.Struct({ effect: Schema.String }))(policy)
32+
return Option.isNone(effect) || Schema.is(ConfigPolicy.Effect)(effect.value.effect)
33+
}),
34+
),
35+
encode: SchemaGetter.passthrough({ strict: false }),
36+
}),
37+
Schema.decodeTo(Schema.Array(ConfigPolicy.Info)),
38+
Schema.optional,
39+
)
2340
const RemoteResponse = Schema.Struct({
2441
providers: Schema.Record(Schema.String, ConfigProvider.Info),
2542
websearch: Schema.Struct({
@@ -35,22 +52,9 @@ const RemoteResponse = Schema.Struct({
3552
),
3653
}).pipe(Schema.optional),
3754
// Organization policy compiled for the authenticated caller; omitted when there is none.
38-
experimental: Schema.Struct({
39-
policies: Schema.Array(Schema.Unknown).pipe(
40-
Schema.decodeTo(Schema.Unknown, {
41-
// Filter only unsupported actions. Malformed supported statements still fail validation.
42-
decode: SchemaGetter.transform((policies) =>
43-
policies.filter((policy) => {
44-
const action = Schema.decodeUnknownOption(Schema.Struct({ action: Schema.String }))(policy)
45-
return Option.isNone(action) || Schema.is(ConfigPolicy.Info.fields.action)(action.value.action)
46-
}),
47-
),
48-
encode: SchemaGetter.passthrough({ strict: false }),
49-
}),
50-
Schema.decodeTo(Schema.Array(ConfigPolicy.Info)),
51-
Schema.optional,
52-
),
53-
}).pipe(Schema.optional),
55+
// `experimental.policies` remains accepted alongside top-level `policies`.
56+
policies: RemotePolicies,
57+
experimental: Schema.Struct({ policies: RemotePolicies }).pipe(Schema.optional),
5458
})
5559
const Device = Schema.Struct({
5660
device_code: Schema.String,
@@ -243,7 +247,10 @@ export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | Manag
243247
})
244248
// Statements ride on the snapshot, so a credential switch, disconnect, or 404 replaces them too.
245249
const publish = (next: typeof snapshot) =>
246-
managed.set({ statements: next.config?.experimental?.policies ?? [], organization: next.organization })
250+
managed.set({
251+
statements: [...(next.config?.experimental?.policies ?? []), ...(next.config?.policies ?? [])],
252+
organization: next.organization,
253+
})
247254

248255
yield* ctx.integration.transform((editor) => {
249256
editor.update("opencode", (integration) => {
Collapse file

‎packages/core/test/config/config.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/config/config.test.ts
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ describe("Config", () => {
709709
const project = path.join(tmp.path, "project")
710710
const remote = (entries: readonly Entry[]) => ({
711711
provider: Config.latest(entries, "providers")?.remote?.package,
712-
policies: Config.latest(entries, "experimental")?.policies,
712+
policies: Config.latest(entries, "policies"),
713713
})
714714
const loaded = {
715715
provider: "aisdk:@ai-sdk/openai-compatible",
@@ -966,14 +966,14 @@ describe("Config", () => {
966966
migrateV1({
967967
enabled_providers: ["anthropic", "openai"],
968968
disabled_providers: ["openai"],
969-
}).experimental?.policies,
969+
}).policies,
970970
).toEqual([
971971
{ action: "provider.use", resource: "*", effect: "deny" },
972972
{ action: "provider.use", resource: "anthropic", effect: "allow" },
973973
{ action: "provider.use", resource: "openai", effect: "allow" },
974974
{ action: "provider.use", resource: "openai", effect: "deny" },
975975
])
976-
expect(migrateV1({ enabled_providers: [] }).experimental?.policies).toEqual([
976+
expect(migrateV1({ enabled_providers: [] }).policies).toEqual([
977977
{ action: "provider.use", resource: "*", effect: "deny" },
978978
])
979979
})
@@ -1031,7 +1031,7 @@ describe("Config", () => {
10311031
expect(migrated.model).toEqual({ providerID: "azure", model: "deployment" })
10321032
expect(migrated.agents?.reviewer?.model).toEqual({ providerID: "google-vertex", model: "claude-sonnet" })
10331033
expect(migrated.commands?.review?.model).toEqual({ providerID: "azure", model: "deployment" })
1034-
expect(migrated.experimental?.policies).toEqual([
1034+
expect(migrated.policies).toEqual([
10351035
{ action: "provider.use", resource: "*", effect: "deny" },
10361036
{ action: "provider.use", resource: "google-vertex", effect: "allow" },
10371037
{ action: "provider.use", resource: "azure", effect: "deny" },
Collapse file

‎packages/core/test/config/normalization.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/config/normalization.test.ts
+32-18Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ function withoutEmptyCompatibilityContainers(input: Record<string, unknown>) {
4444
delete compaction.keep
4545
if (!originallyEmpty && !Object.keys(compaction).length) delete result.compaction
4646
}
47+
// Deprecated experimental policies normalize into top-level policies.
48+
if (typeof result.experimental === "object" && result.experimental !== null && !Array.isArray(result.experimental)) {
49+
const experimental = result.experimental as Record<string, unknown>
50+
if (Array.isArray(experimental.policies)) {
51+
result.policies = [...experimental.policies, ...(Array.isArray(result.policies) ? result.policies : [])]
52+
delete experimental.policies
53+
if (!Object.keys(experimental).length) delete result.experimental
54+
}
55+
}
4756
return result
4857
}
4958

@@ -56,7 +65,7 @@ describe("ConfigNormalize", () => {
5665
] as const
5766
const result = normalized({ experimental: { policies } })
5867
expect(result.diagnostics).toEqual([])
59-
expect(Schema.decodeUnknownSync(Info)(result.encoded).experimental?.policies).toEqual(policies)
68+
expect(Schema.decodeUnknownSync(Info)(result.encoded).policies).toEqual(policies)
6069
})
6170

6271
test("drops unsupported policy actions without losing supported policies", () => {
@@ -70,7 +79,7 @@ describe("ConfigNormalize", () => {
7079
],
7180
},
7281
})
73-
expect(Schema.decodeUnknownSync(Info)(result.encoded).experimental?.policies).toEqual([supported])
82+
expect(Schema.decodeUnknownSync(Info)(result.encoded).policies).toEqual([supported])
7483
expect(result.diagnostics.map((diagnostic) => diagnostic.path)).toEqual([
7584
["experimental", "policies", "0"],
7685
["experimental", "policies", "2"],
@@ -467,42 +476,47 @@ describe("ConfigNormalize", () => {
467476
})
468477

469478
test("distinguishes empty, mixed, and wholly malformed enabled provider lists", () => {
470-
expect(normalized({ enabled_providers: [] }).encoded.experimental).toEqual({
471-
policies: [{ action: "provider.use", resource: "*", effect: "deny" }],
472-
})
473-
expect(normalized({ enabled_providers: [1, "anthropic", false] }).encoded.experimental).toEqual({
474-
policies: [
475-
{ action: "provider.use", resource: "*", effect: "deny" },
476-
{ action: "provider.use", resource: "anthropic", effect: "allow" },
477-
],
478-
})
479-
expect(normalized({ enabled_providers: [1, false] }).encoded.experimental).toBeUndefined()
480-
expect(normalized({ enabled_providers: "anthropic" }).encoded.experimental).toBeUndefined()
479+
expect(normalized({ enabled_providers: [] }).encoded.policies).toEqual([
480+
{ action: "provider.use", resource: "*", effect: "deny" },
481+
])
482+
expect(normalized({ enabled_providers: [1, "anthropic", false] }).encoded.policies).toEqual([
483+
{ action: "provider.use", resource: "*", effect: "deny" },
484+
{ action: "provider.use", resource: "anthropic", effect: "allow" },
485+
])
486+
expect(normalized({ enabled_providers: [1, false] }).encoded.policies).toBeUndefined()
487+
expect(normalized({ enabled_providers: "anthropic" }).encoded.policies).toBeUndefined()
481488
})
482489

483-
test("appends native policies after migrated provider policies", () => {
490+
test("merges migrated, experimental, and native policies in order", () => {
484491
expect(
485492
normalized({
486493
enabled_providers: ["anthropic"],
487494
disabled_providers: ["openai"],
495+
policies: [{ action: "provider.use", resource: "native", effect: "deny" }],
488496
experimental: {
489497
portable_shell_scanner: true,
490498
subagent_depth: 0,
491499
policies: [{ action: "provider.use", resource: "custom", effect: "allow" }],
492500
},
493-
}).encoded.experimental,
494-
).toEqual({
495-
portable_shell_scanner: true,
496-
subagent_depth: 0,
501+
}).encoded,
502+
).toMatchObject({
503+
experimental: { portable_shell_scanner: true, subagent_depth: 0 },
497504
policies: [
498505
{ action: "provider.use", resource: "*", effect: "deny" },
499506
{ action: "provider.use", resource: "anthropic", effect: "allow" },
500507
{ action: "provider.use", resource: "openai", effect: "deny" },
501508
{ action: "provider.use", resource: "custom", effect: "allow" },
509+
{ action: "provider.use", resource: "native", effect: "deny" },
502510
],
503511
})
504512
})
505513

514+
test("never emits experimental policies", () => {
515+
expect(
516+
normalized({ experimental: { policies: [{ action: "provider.use", resource: "*", effect: "deny" }] } }).encoded,
517+
).toEqual({ policies: [{ action: "provider.use", resource: "*", effect: "deny" }] })
518+
})
519+
506520
test("reports unsupported legacy settings without including their values", () => {
507521
const secret = "do-not-log-this-value"
508522
const result = normalized({
Collapse file

‎packages/core/test/config/policy.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/config/policy.test.ts
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { PluginTestLayer } from "../plugin/fixture"
1818
const it = testEffect(PluginTestLayer)
1919
const decode = Schema.decodeUnknownSync(Info)
2020

21-
const document = (...policies: ConfigPolicy.Info[]) =>
22-
new Document({ type: "document", info: decode({ experimental: { policies } }) })
21+
const document = (...policies: ConfigPolicy.Info[]) => new Document({ type: "document", info: decode({ policies }) })
2322
const provider = (effect: ConfigPolicy.Effect, resource: string): ConfigPolicy.Info => ({
2423
action: "provider.use",
2524
resource,
Collapse file

‎packages/core/test/mcp.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/mcp.test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ function resourceMcpLayer(
311311
new Document({
312312
type: "document",
313313
info: new Info({
314-
experimental: { policies: overrides?.policies ?? [] },
314+
policies: overrides?.policies ?? [],
315315
mcp: new ConfigMCP.Info({
316316
servers: {
317317
resources:
@@ -2635,7 +2635,7 @@ for (const source of ["config", "organization"] as const) {
26352635
mcp: new ConfigMCP.Info({
26362636
servers: { resources: new ConfigMCP.Remote({ type: "remote", url: server.url, oauth: false }) },
26372637
}),
2638-
experimental: { policies: [{ action: "integration.use", resource: "mcp:*", effect }] },
2638+
policies: [{ action: "integration.use", resource: "mcp:*", effect }],
26392639
}),
26402640
})
26412641
yield* test.setEntries([document("allow")])

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.