Skip to content

Commit 3874862

Browse files
sahrizviclaude
andcommitted
fix(flag): apply the documented-name rule on every read path, not only Flag.*
The first cut aliased only the opencode `Flag` namespace. Skill discovery does not read that: `skill/index.ts` takes `RuntimeFlags.disableExternalSkills`, an Effect `Config` resolved through the ambient ConfigProvider, and `config.ts` reads `packages/core`'s `Flag` object — so `ALTIMATE_CLI_DISABLE_EXTERNAL_SKILLS` still scanned external skills and `ALTIMATE_CLI_CONFIG` still did nothing. (cubic on #1341) - One definition of the rule, in core `flag/flag.ts`: `documentedAlias`, `env` (documented name first, empty counts as unset), `truthy`/`numberEnv` and every direct `process.env["OPENCODE_*"]` read go through it; the two Effect `Config` flags it carries resolve the documented name via `Config.orElse` - `effect/config-service.ts` wraps whatever ConfigProvider is active so `RuntimeFlags` and `ServerAuthConfig` try the documented spelling first — built with `ConfigProvider.make`, since `orElse`'s fallback bypasses `mapInput` - opencode `flag.ts` imports the rule instead of its own copy; `altTruthy` / `altEnv` let a set documented value win outright, so a documented `false` is not overridden by a fallback `true` - `config.ts` (`OPENCODE_CONFIG_CONTENT`) and `run --attach` (`OPENCODE_SERVER_PASSWORD` / `_USERNAME`) read through `env` instead of `process.env` directly - Tests: RuntimeFlags and ServerAuthConfig through a `fromEnv` provider (documented alone, documented `false` vs fallback `true`, empty documented, numeric); the core `Flag` object in a subprocess (config paths, `altTruthy` precedence, the Effect `Config` flag) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent 1b374b6 commit 3874862

6 files changed

Lines changed: 230 additions & 46 deletions

File tree

‎packages/core/src/flag/flag.ts‎

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,78 @@
11
import { Config } from "effect"
22

3+
// altimate_change start — every OPENCODE_* variable is documented under its ALTIMATE_CLI_*
4+
// name (docs/docs/usage/cli.md), so the documented spelling is read first and the OPENCODE_
5+
// one is the fallback. This is the one definition of that rule: the opencode `Flag`
6+
// namespace and the Effect `Config`-backed services (`effect/config-service.ts`) import it,
7+
// so every read path — this object, that namespace, `RuntimeFlags` — agrees. #1329 was one
8+
// flag that missed the dual read; a cross-check found the table mostly in that state.
9+
// An empty documented value counts as unset: `ALTIMATE_CLI_CONFIG=""` must not hide a real
10+
// `OPENCODE_CONFIG`.
11+
export function documentedAlias(key: string): string | undefined {
12+
return key.startsWith("OPENCODE_") ? "ALTIMATE_CLI_" + key.slice("OPENCODE_".length) : undefined
13+
}
14+
15+
/** The variable as the environment has it now, documented name first. For the few sites
16+
* that must read at call time rather than through the import-time constants below. */
17+
export function env(key: string): string | undefined {
18+
const alias = documentedAlias(key)
19+
const documented = alias !== undefined ? process.env[alias] : undefined
20+
return documented !== undefined && documented !== "" ? documented : process.env[key]
21+
}
22+
323
export function truthy(key: string) {
4-
const value = process.env[key]?.toLowerCase()
24+
const value = env(key)?.toLowerCase()
525
return value === "true" || value === "1"
626
}
727

28+
/** An Effect `Config` boolean with the same documented-name-first rule, for the flags
29+
* that are resolved through the ambient ConfigProvider rather than `process.env`. */
30+
function bool(key: string) {
31+
const alias = documentedAlias(key)
32+
const fallback = Config.boolean(key).pipe(Config.withDefault(false))
33+
return alias === undefined
34+
? fallback
35+
: Config.boolean(alias).pipe(Config.orElse(() => fallback))
36+
}
37+
// altimate_change end
38+
839
// altimate_change start — dual env var support: ALTIMATE_CLI_* (primary) + OPENCODE_* (fallback).
940
// Re-homed from packages/opencode/src/flag/flag.ts so the extracted TUI (packages/tui, which
10-
// depends on core not opencode) can read the fork flags it uses.
41+
// depends on core not opencode) can read the fork flags it uses. A set documented value wins
42+
// outright — a documented `false` is not overridden by a fallback `true`.
1143
function altTruthy(altKey: string, openKey: string) {
12-
return truthy(altKey) || truthy(openKey)
44+
const documented = process.env[altKey]
45+
return documented !== undefined && documented !== "" ? truthy(altKey) : truthy(openKey)
1346
}
1447
function numberEnv(key: string) {
15-
const value = process.env[key]
48+
const value = env(key)
1649
if (!value) return undefined
1750
const parsed = Number(value)
1851
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined
1952
}
2053
// altimate_change end
2154

22-
const copy = process.env["OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"]
23-
const fff = process.env["OPENCODE_DISABLE_FFF"]
55+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
56+
const copy = env("OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT")
57+
const fff = env("OPENCODE_DISABLE_FFF")
58+
// altimate_change end
2459

2560
function enabledByExperimental(key: string) {
26-
return process.env[key] === undefined ? truthy("OPENCODE_EXPERIMENTAL") : truthy(key)
61+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
62+
return env(key) === undefined ? truthy("OPENCODE_EXPERIMENTAL") : truthy(key)
63+
// altimate_change end
2764
}
2865

2966
export const Flag = {
3067
OTEL_EXPORTER_OTLP_ENDPOINT: process.env["OTEL_EXPORTER_OTLP_ENDPOINT"],
3168
OTEL_EXPORTER_OTLP_HEADERS: process.env["OTEL_EXPORTER_OTLP_HEADERS"],
3269

3370
OPENCODE_AUTO_HEAP_SNAPSHOT: truthy("OPENCODE_AUTO_HEAP_SNAPSHOT"),
34-
OPENCODE_GIT_BASH_PATH: process.env["OPENCODE_GIT_BASH_PATH"],
35-
OPENCODE_CONFIG: process.env["OPENCODE_CONFIG"],
36-
OPENCODE_CONFIG_CONTENT: process.env["OPENCODE_CONFIG_CONTENT"],
71+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
72+
OPENCODE_GIT_BASH_PATH: env("OPENCODE_GIT_BASH_PATH"),
73+
OPENCODE_CONFIG: env("OPENCODE_CONFIG"),
74+
OPENCODE_CONFIG_CONTENT: env("OPENCODE_CONFIG_CONTENT"),
75+
// altimate_change end
3776
OPENCODE_DISABLE_AUTOUPDATE: truthy("OPENCODE_DISABLE_AUTOUPDATE"),
3877
OPENCODE_ALWAYS_NOTIFY_UPDATE: truthy("OPENCODE_ALWAYS_NOTIFY_UPDATE"),
3978
OPENCODE_DISABLE_PRUNE: truthy("OPENCODE_DISABLE_PRUNE"),
@@ -42,25 +81,29 @@ export const Flag = {
4281
OPENCODE_DISABLE_AUTOCOMPACT: truthy("OPENCODE_DISABLE_AUTOCOMPACT"),
4382
OPENCODE_DISABLE_MODELS_FETCH: truthy("OPENCODE_DISABLE_MODELS_FETCH"),
4483
OPENCODE_DISABLE_MOUSE: truthy("OPENCODE_DISABLE_MOUSE"),
45-
OPENCODE_FAKE_VCS: process.env["OPENCODE_FAKE_VCS"],
46-
OPENCODE_SERVER_PASSWORD: process.env["OPENCODE_SERVER_PASSWORD"],
47-
OPENCODE_SERVER_USERNAME: process.env["OPENCODE_SERVER_USERNAME"],
84+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
85+
OPENCODE_FAKE_VCS: env("OPENCODE_FAKE_VCS"),
86+
OPENCODE_SERVER_PASSWORD: env("OPENCODE_SERVER_PASSWORD"),
87+
OPENCODE_SERVER_USERNAME: env("OPENCODE_SERVER_USERNAME"),
88+
// altimate_change end
4889
OPENCODE_DISABLE_FFF: fff === undefined ? process.platform === "win32" : truthy("OPENCODE_DISABLE_FFF"),
4990

5091
// Experimental
51-
OPENCODE_EXPERIMENTAL_FILEWATCHER: Config.boolean("OPENCODE_EXPERIMENTAL_FILEWATCHER").pipe(
52-
Config.withDefault(false),
53-
),
54-
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: Config.boolean("OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER").pipe(
55-
Config.withDefault(false),
56-
),
92+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `bool`)
93+
OPENCODE_EXPERIMENTAL_FILEWATCHER: bool("OPENCODE_EXPERIMENTAL_FILEWATCHER"),
94+
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: bool("OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER"),
95+
// altimate_change end
5796
OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT:
5897
copy === undefined ? process.platform === "win32" : truthy("OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"),
59-
OPENCODE_MODELS_URL: process.env["OPENCODE_MODELS_URL"],
60-
OPENCODE_MODELS_PATH: process.env["OPENCODE_MODELS_PATH"],
61-
OPENCODE_DB: process.env["OPENCODE_DB"],
98+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
99+
OPENCODE_MODELS_URL: env("OPENCODE_MODELS_URL"),
100+
OPENCODE_MODELS_PATH: env("OPENCODE_MODELS_PATH"),
101+
OPENCODE_DB: env("OPENCODE_DB"),
102+
// altimate_change end
62103

63-
OPENCODE_WORKSPACE_ID: process.env["OPENCODE_WORKSPACE_ID"],
104+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
105+
OPENCODE_WORKSPACE_ID: env("OPENCODE_WORKSPACE_ID"),
106+
// altimate_change end
64107
// Unrelated to ALTIMATE_WORKSPACE (SaaS project-binding pilot) — this gates upstream's multi-instance/worktree control plane.
65108
OPENCODE_EXPERIMENTAL_WORKSPACES: enabledByExperimental("OPENCODE_EXPERIMENTAL_WORKSPACES"),
66109

@@ -94,24 +137,28 @@ export const Flag = {
94137
get OPENCODE_EXPERIMENTAL_REFERENCES() {
95138
return enabledByExperimental("OPENCODE_EXPERIMENTAL_REFERENCES")
96139
},
140+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
97141
get OPENCODE_TUI_CONFIG() {
98-
return process.env["OPENCODE_TUI_CONFIG"]
142+
return env("OPENCODE_TUI_CONFIG")
99143
},
100144
get OPENCODE_CONFIG_DIR() {
101-
return process.env["OPENCODE_CONFIG_DIR"]
145+
return env("OPENCODE_CONFIG_DIR")
102146
},
147+
// altimate_change end
103148
get OPENCODE_PURE() {
104149
return truthy("OPENCODE_PURE")
105150
},
151+
// altimate_change start — documented ALTIMATE_CLI_ name read first (see `env`)
106152
get OPENCODE_PERMISSION() {
107-
return process.env["OPENCODE_PERMISSION"]
153+
return env("OPENCODE_PERMISSION")
108154
},
109155
get OPENCODE_PLUGIN_META_FILE() {
110-
return process.env["OPENCODE_PLUGIN_META_FILE"]
156+
return env("OPENCODE_PLUGIN_META_FILE")
111157
},
112158
get OPENCODE_CLIENT() {
113-
return process.env["OPENCODE_CLIENT"] ?? "cli"
159+
return env("OPENCODE_CLIENT") ?? "cli"
114160
},
161+
// altimate_change end
115162
// altimate_change start — fork flags used by the extracted TUI (packages/tui). Getters so the
116163
// runtime-set yolo flag (set by --yolo middleware after module load) evaluates at access time.
117164
get ALTIMATE_CALM_MODE() {
@@ -136,7 +183,7 @@ export const Flag = {
136183
const v = alt.toLowerCase()
137184
return v === "true" || v === "1"
138185
}
139-
const oc = process.env["OPENCODE_YOLO"]?.toLowerCase()
186+
const oc = env("OPENCODE_YOLO")?.toLowerCase()
140187
return oc === "true" || oc === "1"
141188
},
142189
// altimate_change end

‎packages/opencode/src/cli/cmd/run.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { Telemetry } from "../../altimate/telemetry"
99
// altimate_change start — workspace feature gate (see the flush after loopPromise)
1010
import { Flag as CoreFlag } from "@opencode-ai/core/flag/flag"
1111
// altimate_change end
12+
// altimate_change start — runtime env read with the documented-name rule
13+
import { env as FlagEnv } from "@opencode-ai/core/flag/flag"
14+
// altimate_change end
1215
import { bootstrap } from "../bootstrap"
1316
import { EOL } from "os"
1417
import { Filesystem } from "../../util/filesystem"
@@ -1508,9 +1511,11 @@ You are speaking to a non-technical business executive. Follow these rules stric
15081511

15091512
if (args.attach) {
15101513
const headers = (() => {
1511-
const password = args.password ?? process.env.OPENCODE_SERVER_PASSWORD
1514+
// altimate_change start — documented ALTIMATE_CLI_SERVER_* names read first (core `env`)
1515+
const password = args.password ?? FlagEnv("OPENCODE_SERVER_PASSWORD")
15121516
if (!password) return undefined
1513-
const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode"
1517+
const username = FlagEnv("OPENCODE_SERVER_USERNAME") ?? "opencode"
1518+
// altimate_change end
15141519
const auth = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`
15151520
return { Authorization: auth }
15161521
})()

‎packages/opencode/src/config/config.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { mergeDeep } from "remeda"
99
import { Global } from "../global"
1010
import fsNode from "fs/promises"
1111
import { Flag } from "@opencode-ai/core/flag/flag"
12+
// altimate_change start — runtime env read with the documented-name rule
13+
import { env as FlagEnv } from "@opencode-ai/core/flag/flag"
14+
// altimate_change end
1215
import { Auth } from "../auth"
1316
import { Env } from "../env"
1417
import { applyEdits, modify } from "jsonc-parser"
@@ -577,12 +580,17 @@ export const layer = Layer.effect(
577580
yield* mergePluginOrigins(dir, list)
578581
}
579582

580-
if (process.env.OPENCODE_CONFIG_CONTENT) {
583+
// altimate_change start — documented ALTIMATE_CLI_CONFIG_CONTENT read first (core `env`)
584+
const configContent = FlagEnv("OPENCODE_CONFIG_CONTENT")
585+
if (configContent) {
586+
// altimate_change end
581587
const source = "OPENCODE_CONFIG_CONTENT"
582588
// altimate_change start — upstream_fix (#701): clear before this load.
583589
ConfigVariable.resetBlankedEnvVars(source)
584590
// altimate_change end
585-
const next = yield* loadConfig(process.env.OPENCODE_CONFIG_CONTENT, {
591+
// altimate_change start — see above
592+
const next = yield* loadConfig(configContent, {
593+
// altimate_change end
586594
dir: ctx.directory,
587595
source,
588596
})

‎packages/opencode/src/effect/config-service.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { Config, Context, Effect, Layer } from "effect"
1+
import { Config, ConfigProvider, Context, Effect, Layer } from "effect"
2+
// altimate_change start — every OPENCODE_* variable is documented under an ALTIMATE_CLI_* name
3+
import { documentedAlias } from "@opencode-ai/core/flag/flag"
4+
// altimate_change end
25

36
type ConfigMap = Record<string, Config.Config<unknown>>
47

@@ -52,7 +55,19 @@ export const Service =
5255
return Layer.effect(
5356
tag,
5457
Effect.gen(function* () {
55-
const config = yield* Config.all(fields)
58+
// altimate_change start — resolve the documented ALTIMATE_CLI_* name before the
59+
// OPENCODE_* one, whatever provider is active. Same rule as `flag.ts`'s `read`;
60+
// without it a documented name reached `Flag.*` but never a Config-backed field,
61+
// and `RuntimeFlags.disableExternalSkills` — the real skill-discovery gate — kept
62+
// ignoring `ALTIMATE_CLI_DISABLE_EXTERNAL_SKILLS` (#1329). Built with `make`
63+
// rather than `orElse`, whose fallback calls `get` and skips `mapInput`.
64+
const config = yield* Config.all(fields).pipe(
65+
Effect.provideServiceEffect(
66+
ConfigProvider.ConfigProvider,
67+
Effect.map(ConfigProvider.ConfigProvider, aliasDocumentedNames),
68+
),
69+
)
70+
// altimate_change end
5671
// oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- Config.all preserves the field shape, but its conditional return type also supports iterable inputs.
5772
return tag.of(config as Shape<Fields>)
5873
}),
@@ -65,3 +80,18 @@ export const Service =
6580
}
6681

6782
export * as ConfigService from "./config-service"
83+
84+
// altimate_change start — see `defaultLayer`
85+
/** A provider that tries the documented `ALTIMATE_CLI_*` spelling of an `OPENCODE_*` path
86+
* first and falls back to the path as written. An empty documented value counts as unset. */
87+
export function aliasDocumentedNames(provider: ConfigProvider.ConfigProvider): ConfigProvider.ConfigProvider {
88+
return ConfigProvider.make((path) => {
89+
const head = path[0]
90+
const alias = typeof head === "string" ? documentedAlias(head) : undefined
91+
if (alias === undefined) return provider.load(path)
92+
return Effect.flatMap(provider.load([alias, ...path.slice(1)]), (node) =>
93+
node && !(node._tag === "Value" && node.value === "") ? Effect.succeed(node) : provider.load(path),
94+
)
95+
})
96+
}
97+
// altimate_change end

‎packages/opencode/src/flag/flag.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
// the fallback. Done once here rather than per flag: #1329 was one flag that missed the dual
44
// read, and a cross-check found most of the table in the same state. Non-OPENCODE_ keys are
55
// read as-is.
6-
function documentedAlias(key: string): string | undefined {
7-
return key.startsWith("OPENCODE_") ? "ALTIMATE_CLI_" + key.slice("OPENCODE_".length) : undefined
8-
}
9-
10-
function read(key: string): string | undefined {
11-
const alias = documentedAlias(key)
12-
return (alias !== undefined ? process.env[alias] : undefined) ?? process.env[key]
13-
}
6+
// The rule itself lives in core's `flag/flag.ts` (`env`), which the core `Flag` object, this
7+
// namespace and the Effect `Config`-backed services (`effect/config-service.ts`) all share.
8+
import { env as read } from "@opencode-ai/core/flag/flag"
149
// altimate_change end
1510

1611
function truthy(key: string) {
@@ -23,13 +18,17 @@ function falsy(key: string) {
2318
return value === "false" || value === "0"
2419
}
2520

26-
// altimate_change start - dual env var support: ALTIMATE_CLI_* (primary) + OPENCODE_* (fallback)
21+
// altimate_change start - dual env var support: ALTIMATE_CLI_* (primary) + OPENCODE_* (fallback).
22+
// Both go through `read`, so a documented value wins outright (a documented `false` is not
23+
// overridden by a fallback `true`) — the one precedence rule for every paired flag.
2724
function altTruthy(altKey: string, openKey: string) {
28-
return truthy(altKey) || truthy(openKey)
25+
const documented = process.env[altKey]
26+
return documented !== undefined && documented !== "" ? truthy(altKey) : truthy(openKey)
2927
}
3028

3129
function altEnv(altKey: string, openKey: string) {
32-
return process.env[altKey] ?? process.env[openKey]
30+
const documented = process.env[altKey]
31+
return documented !== undefined && documented !== "" ? documented : read(openKey)
3332
}
3433
// altimate_change end
3534

0 commit comments

Comments
 (0)