Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/usage/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Configuration can be controlled via environment variables:
| `ALTIMATE_CLI_DISABLE_MODELS_FETCH` | Don't fetch models from models.dev |
| `ALTIMATE_DISABLE_WORKSPACE` | Set to `1` to turn off every workspace feature (linking, skill and memory sync, the workspace engine, and the project lookup each session makes). The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set. Workspaces are on by default |
| `ALTIMATE_DISABLE_SCHEMA_VALUES` | Set to `1` to turn off `schema_inspect`'s column value profiles for every call, whatever the model passes as `values`, so no cell values are sampled or sent to the model provider. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set |
| `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` | Set to `1` to skip the background install of `@opencode-ai/plugin` into config directories that hold custom tools or plugins. Use it where that package is already provided or the npm registry is not reachable; custom tools or plugins that import the package then need it installed some other way. The value is trimmed and read without regard to case; anything other than `0`, `false` or an empty value counts as set |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR · documentation — the flag covers less than this row suggests

| ALTIMATE_DISABLE_DEPENDENCY_INSTALL | Set to 1 to skip the background install of @opencode-ai/plugin into config directories ... Use it where that package is already provided or the npm registry is not reachable; ...

The flag only gates the config-dir @opencode-ai/plugin install (ConfigPlugin.shouldInstallDependencies). Other installs still run with it set:

  • npm plugin specs: BunProc.install in src/plugin/index.ts:141 and Npm.add in src/plugin/shared.ts:213
  • provider SDKs: BunProc.install in src/provider/provider.ts:2272

So an operator who sets it because the registry is unreachable, with "plugin": ["some-plugin@1.0.0"] in their config, still gets a registry install attempt at startup.

Suggested: state in this row that npm plugin and provider SDK installs are not affected. Or rename the flag to match its scope, e.g. ALTIMATE_DISABLE_PLUGIN_SDK_INSTALL.

| `ALTIMATE_WORKSPACE_WEB_URL` | Development only: the base URL of a local web app's Workspaces pages, used instead of the tenant's for `link`'s browser hand-off and workspace links. Include the mount path, e.g. `http://acme.localhost:3000/workspaces` |
| `ALTIMATE_INTEGRATIONS` | Set to `local` to keep warehouse tools local rather than routing them through a bound workspace's engine |
| `ALTIMATE_CODE_SERVE` | Set to `1` by `altimate-code serve` itself, whether the IDE extension or you launched it. Marks that process as the extension's host — so it is the one that reads the pin variables — and is stripped from every child the bash and shell tools start |
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/flag/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ export const Flag = {
const value = env("ALTIMATE_DISABLE_SCHEMA_VALUES")?.trim().toLowerCase()
return value !== undefined && value !== "" && value !== "0" && value !== "false"
},
/**
* Skips the background install of `@opencode-ai/plugin` into config dirs (see
* `ConfigPlugin.shouldInstallDependencies`). The test suite sets it: an install one test
* starts is not awaited, outlives the test and runs inside the test process. Same
* fail-closed parsing as ALTIMATE_DISABLE_WORKSPACE.
*/
get ALTIMATE_DISABLE_DEPENDENCY_INSTALL() {
return killSwitchSet(env("ALTIMATE_DISABLE_DEPENDENCY_INSTALL"))
},
// altimate_change end

// Evaluated at access time (not module load) because tests, the CLI, and
Expand Down
3 changes: 2 additions & 1 deletion packages/opencode/src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ export function needsDependencies(dir: string, plugins: readonly ConfigPluginV1.
// PURE mode skips dependency installs entirely: isolated-HOME environments and subprocess tests run
// with no package cache, so the install attempt fails, npm retries, and the process hangs past exit.
// Fold that check in here so both call sites (Config and TuiConfig) stay in sync.
// `ALTIMATE_DISABLE_DEPENDENCY_INSTALL` skips it the same way (see the flag).
export function shouldInstallDependencies(
dir: string,
plugins: readonly ConfigPluginV1.Spec[] | undefined,
): boolean {
return !Flag.OPENCODE_PURE && needsDependencies(dir, plugins)
return !Flag.OPENCODE_PURE && !Flag.ALTIMATE_DISABLE_DEPENDENCY_INSTALL && needsDependencies(dir, plugins)
}
// altimate_change end

Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/test/cli/serve/fresh-start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ cliIt.live(
extraArgs: ["--print-logs"],
env: {
OPENCODE_PURE: "0",
// The suite's preload switches the install off, and a child inherits it: a real cold
// start must decide for itself. The registry below answers 503 with no retries.
ALTIMATE_DISABLE_DEPENDENCY_INSTALL: "0",
OPENCODE_CONFIG_DIR: configDir,
OPENCODE_CONFIG_CONTENT: JSON.stringify({ plugin: [pathToFileURL(plugin).href] }),
OPENCODE_DISABLE_DEFAULT_PLUGINS: "1",
Expand Down
24 changes: 24 additions & 0 deletions packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,18 @@ const loadConfigDirWithDependencies = (
describe("config dir plugin dependency install", () => {
const npmIt = testEffect(Layer.mergeAll(infra, FSUtil.defaultLayer))

// The suite's preload switches the background install off. These cases check when the app

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR: no layer-level test shows that the switch actually stops the install.

// The suite's preload switches the background install off. These cases check when the app
// asks for one, through a recording installer that never reaches the network.

The new test calls ConfigPlugin.shouldInstallDependencies directly. No case goes through the Config (or TuiConfig) layer with the switch set to 1 and a tool/ file present and checks that the recording installer receives nothing (npm.dirs / installs is []). Both call sites use the shared gate today, so this is about guarding that wiring rather than a current bug. A single case here and one in the TUI matrix would cover it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 33cb412. One Config case sets the switch to 1 with a tools/ file present and expects the recording installer to receive nothing, and the TUI matrix has the same case. Checked by making the code ignore the switch: both fail, along with the switch's own test.

// asks for one, through a recording installer that never reaches the network.
let installOff: string | undefined
beforeEach(() => {
installOff = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
})
afterEach(() => {
if (installOff === undefined) delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
else process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = installOff
})

npmIt.effect("skips the install in a bare writable config dir but still writes .gitignore", () =>
Effect.gen(function* () {
const npm = recordingNpm()
Expand All @@ -1086,6 +1098,18 @@ describe("config dir plugin dependency install", () => {
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(CrossSpawnSpawner.defaultLayer)),
)

npmIt.effect("ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1 asks for no install even with a local tool source", () =>
Effect.gen(function* () {
process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1"
const npm = recordingNpm()
const dir = yield* tmpdirScoped()
const configDir = path.join(dir, "configdir")
yield* FSUtil.use.writeWithDirs(path.join(configDir, "tools", "hello.ts"), "export default {}\n")
yield* loadConfigDirWithDependencies(dir, configDir, npm)
expect(npm.dirs).toEqual([])
}).pipe(Effect.provide(testInstanceStoreLayer), Effect.provide(CrossSpawnSpawner.defaultLayer)),
)

npmIt.effect("installs when the config dir has a local plugin source", () =>
Effect.gen(function* () {
const npm = recordingNpm()
Expand Down
90 changes: 52 additions & 38 deletions packages/opencode/test/config/tui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,48 +91,62 @@ const getTuiPluginOrigins = (directory: string) =>
)

// altimate_change start — cover the TUI call site independently from server Config.
for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] as const) {
for (const pure of [false, true]) {
it.instance(`tui dependency install gate: ${source}${pure ? " (PURE)" : ""}`, () =>
// The suite's preload switches the install off. Each case sets the switch itself: unset, as users
// run, or `1`. The installer only records the request.
const installSources = ["bare", "npm", "file", "tool", "node_modules", "outside"] as const
const installGates = [
...installSources.flatMap((source) => [false, true].map((pure) => ({ source, pure, off: false }))),
{ source: "tool" as const, pure: false, off: true },
]
for (const { source, pure, off } of installGates) {
it.instance(
`tui dependency install gate: ${source}${pure ? " (PURE)" : ""}${off ? " (install switched off)" : ""}`,
() =>
withEnv(
"OPENCODE_PURE",
pure ? "1" : "0",
withCleanState(
Effect.gen(function* () {
const fs = yield* FSUtil.Service
const test = yield* TestInstance
const local = path.join(test.directory, ".opencode")
const installs: string[] = []
yield* fs.makeDirectory(local, { recursive: true })
const plugin =
source === "file" ? "./custom.ts" : source === "outside" ? "../custom.ts" : "npm-plugin@1.0.0"
if (source !== "bare") yield* fs.writeJson(path.join(local, "tui.json"), { plugin: [plugin] })
if (source === "file" || source === "outside") {
yield* fs.writeWithDirs(path.resolve(local, plugin), "export default {}\n")
}
if (source === "tool") yield* fs.writeWithDirs(path.join(local, "tools", "hello.ts"), "export default {}\n")
if (source === "node_modules") yield* fs.makeDirectory(path.join(local, "node_modules"))

const npm = Layer.mock(Npm.Service)({
install: (dir: string) =>
Effect.yieldNow.pipe(Effect.andThen(Effect.sync(() => void installs.push(dir)))),
})
yield* TuiConfig.Service.use((svc) => svc.get().pipe(Effect.andThen(svc.waitForDependencies()))).pipe(
Effect.provide(
TuiConfig.layer.pipe(
Layer.provide(Layer.succeed(CurrentWorkingDirectory, test.directory)),
Layer.provide(Project.defaultLayer),
Layer.provide(npm),
Layer.provide(FSUtil.defaultLayer),
"ALTIMATE_DISABLE_DEPENDENCY_INSTALL",
off ? "1" : undefined,
withEnv(
"OPENCODE_PURE",
pure ? "1" : "0",
withCleanState(
Effect.gen(function* () {
const fs = yield* FSUtil.Service
const test = yield* TestInstance
const local = path.join(test.directory, ".opencode")
const installs: string[] = []
yield* fs.makeDirectory(local, { recursive: true })
const plugin =
source === "file" ? "./custom.ts" : source === "outside" ? "../custom.ts" : "npm-plugin@1.0.0"
if (source !== "bare") yield* fs.writeJson(path.join(local, "tui.json"), { plugin: [plugin] })
if (source === "file" || source === "outside") {
yield* fs.writeWithDirs(path.resolve(local, plugin), "export default {}\n")
}
if (source === "tool")
yield* fs.writeWithDirs(path.join(local, "tools", "hello.ts"), "export default {}\n")
if (source === "node_modules") yield* fs.makeDirectory(path.join(local, "node_modules"))

const npm = Layer.mock(Npm.Service)({
install: (dir: string) =>
Effect.yieldNow.pipe(Effect.andThen(Effect.sync(() => void installs.push(dir)))),
})
yield* TuiConfig.Service.use((svc) => svc.get().pipe(Effect.andThen(svc.waitForDependencies()))).pipe(
Effect.provide(
TuiConfig.layer.pipe(
Layer.provide(Layer.succeed(CurrentWorkingDirectory, test.directory)),
Layer.provide(Project.defaultLayer),
Layer.provide(npm),
Layer.provide(FSUtil.defaultLayer),
),
),
),
)
expect(installs).toEqual(!pure && ["file", "tool", "node_modules"].includes(source) ? [local] : [])
}),
)
expect(installs).toEqual(
!pure && !off && ["file", "tool", "node_modules"].includes(source) ? [local] : [],
)
}),
),
),
),
)
}
)
}
// altimate_change end

Expand Down
6 changes: 6 additions & 0 deletions packages/opencode/test/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ process.env["ALTIMATE_DISABLE_WORKSPACE"] = "1"
// keychain); tests must never write there. Credential-store tests inject a backend instead.
process.env["ALTIMATE_CODE_DISABLE_OS_CREDENTIAL_STORE"] = "1"
// altimate_change end
// altimate_change start — a test that writes a tool or plugin file into a config dir makes the
// app start a real `npm install` of `@opencode-ai/plugin` there, in this process and not awaited.
// It outlives the test: several pile up, starve the event loop, and the tests that run next time
// out. Tests that check the install itself clear this and inject an installer.
process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR — this hides the cold-start subprocess regression test.

process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1"

The CLI test helpers pass the runner's environment to every child: test/lib/cli-process.ts:240 uses extendEnv: true, and lines 365 and 459 use env: { ...process.env, ...env, ...opts?.env }. As a result, test/cli/serve/fresh-start.test.ts (the only subprocess test that sets OPENCODE_PURE: "0" to run a real cold start) also gets ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1. Its checks (expect(requests).toEqual([]), no background dependency install failed in stderr, no node_modules/package.json in the config dirs) now pass whether or not needsDependencies decides correctly. If it ever regressed to installing into every config dir, this test would stay green.

Fix: opt that test back in, the same way it already does for PURE:

env: {
  OPENCODE_PURE: "0",
  ALTIMATE_DISABLE_DEPENDENCY_INSTALL: "0",
  ...

Its fake registry returns 503, and npm_config_fetch_retries is 0, so this cannot reintroduce the hang.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 33cb412. fresh-start.test.ts now sets ALTIMATE_DISABLE_DEPENDENCY_INSTALL: "0" for its child, next to OPENCODE_PURE: "0". Checked by breaking the code: with needsDependencies forced to return true the test fails, and without the new line it passes, which is the gap you described.

// altimate_change end

// Set test home directory to isolate tests from user's actual home directory
// This prevents tests from picking up real user configs/skills from ~/.claude/skills
Expand Down
39 changes: 30 additions & 9 deletions packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* check via a different branch than the existing `ftp://` test (plain `http://` and an
* embedded-credentials `https://` URL).
*/
import { afterEach, describe, expect, spyOn, test } from "bun:test"
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test"
import * as fs from "fs"
import * as os from "os"
import * as path from "path"
Expand Down Expand Up @@ -228,29 +228,50 @@ describe("needsDependencies — glob source-detection edge cases", () => {
})

describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => {
const ENV_KEY = "OPENCODE_PURE"
let saved: string | undefined
const PURE = "OPENCODE_PURE"
const OFF = "ALTIMATE_DISABLE_DEPENDENCY_INSTALL"
const saved: Record<string, string | undefined> = {}
// The suite's preload sets OFF; every case here starts with both switches unset.
beforeEach(() => {
for (const key of [PURE, OFF]) {
saved[key] = process.env[key]
delete process.env[key]
}
})
afterEach(() => {
if (saved === undefined) delete process.env[ENV_KEY]
else process.env[ENV_KEY] = saved
for (const key of [PURE, OFF]) {
if (saved[key] === undefined) delete process.env[key]
else process.env[key] = saved[key]
}
})

test("OPENCODE_PURE=1 suppresses installation even when needsDependencies would be true", () => {
const dir = tmp()
fs.mkdirSync(path.join(dir, "node_modules"))
saved = process.env[ENV_KEY]
process.env[ENV_KEY] = "1"
process.env[PURE] = "1"
expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true)
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false)
})

test("without OPENCODE_PURE, shouldInstallDependencies matches needsDependencies", () => {
const dir = tmp()
fs.mkdirSync(path.join(dir, "node_modules"))
saved = process.env[ENV_KEY]
delete process.env[ENV_KEY]
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true)
})

test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL suppresses installation; `0` and `false` leave it on", () => {
const dir = tmp()
fs.mkdirSync(path.join(dir, "node_modules"))
expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true)
for (const value of ["1", "true", "yes"]) {
process.env[OFF] = value
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false)
}
for (const value of ["0", "false", ""]) {
process.env[OFF] = value
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true)
}
})
})

// ---------------------------------------------------------------------------
Expand Down
Loading