Skip to content

Commit cb4f5cd

Browse files
authored
refactor(flags): move auto share to runtime flags (anomalyco#27611)
1 parent d34a019 commit cb4f5cd

6 files changed

Lines changed: 21 additions & 5 deletions

File tree

packages/core/src/flag/flag.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export const Flag = {
2020
OTEL_EXPORTER_OTLP_ENDPOINT: process.env["OTEL_EXPORTER_OTLP_ENDPOINT"],
2121
OTEL_EXPORTER_OTLP_HEADERS: process.env["OTEL_EXPORTER_OTLP_HEADERS"],
2222

23-
OPENCODE_AUTO_SHARE: truthy("OPENCODE_AUTO_SHARE"),
2423
OPENCODE_AUTO_HEAP_SNAPSHOT: truthy("OPENCODE_AUTO_HEAP_SNAPSHOT"),
2524
OPENCODE_GIT_BASH_PATH: process.env["OPENCODE_GIT_BASH_PATH"],
2625
OPENCODE_CONFIG: process.env["OPENCODE_CONFIG"],

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import { pathToFileURL } from "url"
1717
import { Effect } from "effect"
1818
import { UI } from "../ui"
1919
import { effectCmd } from "../effect-cmd"
20-
import { Flag } from "@opencode-ai/core/flag/flag"
2120
import { ServerAuth } from "@/server/auth"
2221
import { EOL } from "os"
2322
import { Filesystem } from "@/util/filesystem"
2423
import { createOpencodeClient, type OpencodeClient, type ToolPart } from "@opencode-ai/sdk/v2"
2524
import { Agent } from "@/agent/agent"
2625
import { Permission } from "@/permission"
26+
import { RuntimeFlags } from "@/effect/runtime-flags"
2727
import { FormatError, FormatUnknownError } from "../error"
2828
import { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from "./run/runtime.stdin"
2929

@@ -235,6 +235,7 @@ export const RunCommand = effectCmd({
235235
}),
236236
handler: Effect.fn("Cli.run")(function* (args) {
237237
const agentSvc = yield* Agent.Service
238+
const flags = yield* RuntimeFlags.Service
238239
yield* Effect.promise(async () => {
239240
const rawMessage = [...args.message, ...(args["--"] || [])].join(" ")
240241
const thinking = args.interactive ? (args.thinking ?? true) : (args.thinking ?? false)
@@ -446,7 +447,7 @@ export const RunCommand = effectCmd({
446447
async function share(sdk: OpencodeClient, sessionID: string) {
447448
const cfg = await sdk.config.get()
448449
if (!cfg.data) return
449-
if (cfg.data.share !== "auto" && !Flag.OPENCODE_AUTO_SHARE && !args.share) return
450+
if (cfg.data.share !== "auto" && !flags.autoShare && !args.share) return
450451
const res = await sdk.session.share({ sessionID }).catch((error) => {
451452
if (error instanceof Error && error.message.includes("disabled")) {
452453
UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message)

packages/opencode/src/effect/app-runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { Npm } from "@opencode-ai/core/npm"
5656
import { memoMap } from "@opencode-ai/core/effect/memo-map"
5757
import { DataMigration } from "@/data-migration"
5858
import { BackgroundJob } from "@/background/job"
59+
import { RuntimeFlags } from "@/effect/runtime-flags"
5960

6061
export const AppLayer = Layer.mergeAll(
6162
Npm.defaultLayer,
@@ -83,6 +84,7 @@ export const AppLayer = Layer.mergeAll(
8384
Session.defaultLayer,
8485
SessionStatus.defaultLayer,
8586
BackgroundJob.defaultLayer,
87+
RuntimeFlags.defaultLayer,
8688
SessionRunState.defaultLayer,
8789
SessionProcessor.defaultLayer,
8890
SessionCompaction.defaultLayer,

packages/opencode/src/effect/runtime-flags.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const enabledByExperimental = (name: string) =>
1212
Config.all({ experimental, enabled: bool(name) }).pipe(Config.map((flags) => flags.experimental || flags.enabled))
1313

1414
export class Service extends ConfigService.Service<Service>()("@opencode/RuntimeFlags", {
15+
autoShare: bool("OPENCODE_AUTO_SHARE"),
1516
pure: bool("OPENCODE_PURE"),
1617
disableDefaultPlugins: bool("OPENCODE_DISABLE_DEFAULT_PLUGINS"),
1718
disableEmbeddedWebUi: bool("OPENCODE_DISABLE_EMBEDDED_WEB_UI"),

packages/opencode/src/share/session.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SessionID } from "@/session/schema"
33
import { SyncEvent } from "@/sync"
44
import { Effect, Layer, Scope, Context } from "effect"
55
import { Config } from "@/config/config"
6-
import { Flag } from "@opencode-ai/core/flag/flag"
6+
import { RuntimeFlags } from "@/effect/runtime-flags"
77
import * as ShareNext from "./share-next"
88

99
export interface Interface {
@@ -22,6 +22,7 @@ export const layer = Layer.effect(
2222
const shareNext = yield* ShareNext.Service
2323
const scope = yield* Scope.Scope
2424
const sync = yield* SyncEvent.Service
25+
const flags = yield* RuntimeFlags.Service
2526

2627
const share = Effect.fn("SessionShare.share")(function* (sessionID: SessionID) {
2728
const conf = yield* cfg.get()
@@ -40,7 +41,7 @@ export const layer = Layer.effect(
4041
const result = yield* session.create(input)
4142
if (result.parentID) return result
4243
const conf = yield* cfg.get()
43-
if (!(Flag.OPENCODE_AUTO_SHARE || conf.share === "auto")) return result
44+
if (!(flags.autoShare || conf.share === "auto")) return result
4445
yield* share(result.id).pipe(Effect.ignore, Effect.forkIn(scope))
4546
return result
4647
})
@@ -54,6 +55,7 @@ export const defaultLayer = layer.pipe(
5455
Layer.provide(Session.defaultLayer),
5556
Layer.provide(Config.defaultLayer),
5657
Layer.provide(SyncEvent.defaultLayer),
58+
Layer.provide(RuntimeFlags.defaultLayer),
5759
)
5860

5961
export * as SessionShare from "./session"

packages/opencode/test/effect/runtime-flags.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@ const fromConfig = (input: Record<string, unknown>) =>
99
const readFlags = RuntimeFlags.Service.useSync((flags) => flags)
1010

1111
describe("RuntimeFlags", () => {
12+
it.effect("defaultLayer defaults autoShare to false", () =>
13+
Effect.gen(function* () {
14+
const flags = yield* readFlags.pipe(Effect.provide(fromConfig({})))
15+
16+
expect(flags.autoShare).toBe(false)
17+
}),
18+
)
19+
1220
it.effect("defaultLayer parses plugin flags from the active ConfigProvider", () =>
1321
Effect.gen(function* () {
1422
const flags = yield* readFlags.pipe(
1523
Effect.provide(
1624
fromConfig({
1725
OPENCODE_PURE: "true",
1826
OPENCODE_DISABLE_DEFAULT_PLUGINS: "true",
27+
OPENCODE_AUTO_SHARE: "true",
1928
OPENCODE_DISABLE_EMBEDDED_WEB_UI: "true",
2029
OPENCODE_EXPERIMENTAL: "true",
2130
OPENCODE_ENABLE_EXA: "true",
@@ -28,6 +37,7 @@ describe("RuntimeFlags", () => {
2837
)
2938

3039
expect(flags.pure).toBe(true)
40+
expect(flags.autoShare).toBe(true)
3141
expect(flags.disableDefaultPlugins).toBe(true)
3242
expect(flags.disableEmbeddedWebUi).toBe(true)
3343
expect(flags.enableExa).toBe(true)
@@ -68,6 +78,7 @@ describe("RuntimeFlags", () => {
6878
)
6979

7080
expect(flags.pure).toBe(false)
81+
expect(flags.autoShare).toBe(false)
7182
expect(flags.disableDefaultPlugins).toBe(true)
7283
expect(flags.disableEmbeddedWebUi).toBe(false)
7384
expect(flags.disableClaudeCodeSkills).toBe(false)

0 commit comments

Comments
 (0)