Skip to content
Closed
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
26 changes: 13 additions & 13 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "opencode",
"name": "apex",
"description": "AI-powered development tool",
"private": true,
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { State } from "./state"

export const ID = Schema.String.pipe(Schema.brand("AgentV2.ID"))
export type ID = typeof ID.Type
export const defaultID = ID.make("build")
export const defaultID = ID.make("apex-revenant")

export const Color = Schema.Union([
Schema.String.check(Schema.isPattern(/^#[0-9a-fA-F]{6}$/)),
Expand Down Expand Up @@ -98,7 +98,7 @@ export const layer = Layer.effect(
const data = state.get()
const configured = data.default ? selectable(data.agents.get(data.default)) : undefined
if (configured) return configured
const build = selectable(data.agents.get(ID.make("build")))
const build = selectable(data.agents.get(ID.make("apex-revenant")))
if (build) return build
for (const agent of data.agents.values()) {
const fallback = selectable(agent)
Expand Down
25 changes: 24 additions & 1 deletion packages/core/src/config/plugin/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * as ConfigAgentPlugin from "./agent"

import { define } from "@opencode-ai/plugin/v2/effect"
import path from "path"
import { fileURLToPath } from "url"
import { Effect, Option, Schema } from "effect"
import { AgentV2 } from "../../agent"
import { Config } from "../../config"
Expand Down Expand Up @@ -56,9 +57,31 @@ export const Plugin = define({
)
})
}).pipe(Effect.map((documents) => documents.flat()))

const isBun = path.basename(process.execPath).toLowerCase().startsWith("bun")
const builtinAgentsDir = isBun
? path.join(path.dirname(fileURLToPath(import.meta.url)), "../../../../opencode/assets/agents")
: path.join(path.dirname(process.execPath), "../assets/agents")
const builtinFiles = yield* discover(fs, builtinAgentsDir)
const builtinDocuments = yield* Effect.forEach(builtinFiles, (file) =>
fs.readFileStringSafe(file.filepath).pipe(
Effect.map((content) => content && decode(file, content)),
Effect.catch(() => Effect.succeed(undefined)),
),
).pipe(
Effect.map((documents) =>
documents.filter((document): document is Config.Document => document !== undefined),
),
)
documents.push(...builtinDocuments)

const global = documents.flatMap((document) => document.info.permissions ?? [])
const configuredDefault = Config.latest(documents, "default_agent")
if (configuredDefault !== undefined) draft.default(AgentV2.ID.make(configuredDefault))
if (configuredDefault !== undefined) {
draft.default(AgentV2.ID.make(configuredDefault))
} else if (draft.get(AgentV2.ID.make("apex-revenant"))) {
draft.default(AgentV2.ID.make("apex-revenant"))
}
for (const current of draft.list()) {
draft.update(current.id, (agent) => agent.permissions.push(...global))
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export function layerFromPath(filename: string) {
}

export function path() {
if (Flag.OPENCODE_DB) {
if (Flag.OPENCODE_DB === ":memory:" || isAbsolute(Flag.OPENCODE_DB)) return Flag.OPENCODE_DB
return join(Global.Path.data, Flag.OPENCODE_DB)
if (Flag.APEX_DB) {
if (Flag.APEX_DB === ":memory:" || isAbsolute(Flag.APEX_DB)) return Flag.APEX_DB
return join(Global.Path.data, Flag.APEX_DB)
}
if (
["latest", "beta", "prod"].includes(InstallationChannel) ||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" ||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "true"
process.env.APEX_DISABLE_CHANNEL_DB === "1" ||
process.env.APEX_DISABLE_CHANNEL_DB === "true"
)
return join(Global.Path.data, "opencode.db")
return join(Global.Path.data, `opencode-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/filesystem/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@ export const fffLayer = Layer.effect(
)

export const locationLayer = Layer.unwrap(
Effect.sync(() => (Flag.OPENCODE_DISABLE_FFF || !Fff.available() ? ripgrepLayer : fffLayer)),
Effect.sync(() => (Flag.APEX_DISABLE_FFF || !Fff.available() ? ripgrepLayer : fffLayer)),
)
8 changes: 4 additions & 4 deletions packages/core/src/filesystem/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { lazy } from "../util/lazy"
import { Ignore } from "./ignore"
import { Protected } from "./protected"

declare const OPENCODE_LIBC: string | undefined
declare const APEX_LIBC: string | undefined

const SUBSCRIBE_TIMEOUT_MS = 10_000

Expand All @@ -31,7 +31,7 @@ export const Event = {

const watcher = lazy((): typeof import("@parcel/watcher") | undefined => {
try {
const libc = typeof OPENCODE_LIBC === "undefined" ? undefined : OPENCODE_LIBC
const libc = typeof APEX_LIBC === "undefined" ? undefined : APEX_LIBC
const binding = require(
`@parcel/watcher-${process.platform}-${process.arch}${process.platform === "linux" ? `-${libc || "glibc"}` : ""}`,
)
Expand Down Expand Up @@ -63,7 +63,7 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/v2
export const layer = Layer.effect(
Service,
Effect.gen(function* () {
if (yield* Flag.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER) return Service.of({})
if (yield* Flag.APEX_EXPERIMENTAL_DISABLE_FILEWATCHER) return Service.of({})

const backend = getBackend()
const location = yield* Location.Service
Expand Down Expand Up @@ -112,7 +112,7 @@ export const layer = Layer.effect(
const config = (yield* (yield* Config.Service).entries())
.filter((entry): entry is Config.Document => entry.type === "document")
.flatMap((item) => item.info.watcher?.ignore ?? [])
if (yield* Flag.OPENCODE_EXPERIMENTAL_FILEWATCHER) {
if (yield* Flag.APEX_EXPERIMENTAL_FILEWATCHER) {
yield* Effect.forkScoped(
subscribe(location.directory, [...Ignore.PATTERNS, ...config, ...protecteds(location.directory)]),
)
Expand Down
88 changes: 44 additions & 44 deletions packages/core/src/flag/flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,74 @@ export function truthy(key: string) {
return value === "true" || value === "1"
}

const copy = process.env["OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"]
const fff = process.env["OPENCODE_DISABLE_FFF"]
const copy = process.env["APEX_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"]
const fff = process.env["APEX_DISABLE_FFF"]

function enabledByExperimental(key: string) {
return process.env[key] === undefined ? truthy("OPENCODE_EXPERIMENTAL") : truthy(key)
return process.env[key] === undefined ? truthy("APEX_EXPERIMENTAL") : truthy(key)
}

export const Flag = {
OTEL_EXPORTER_OTLP_ENDPOINT: process.env["OTEL_EXPORTER_OTLP_ENDPOINT"],
OTEL_EXPORTER_OTLP_HEADERS: process.env["OTEL_EXPORTER_OTLP_HEADERS"],

OPENCODE_AUTO_HEAP_SNAPSHOT: truthy("OPENCODE_AUTO_HEAP_SNAPSHOT"),
OPENCODE_GIT_BASH_PATH: process.env["OPENCODE_GIT_BASH_PATH"],
OPENCODE_CONFIG: process.env["OPENCODE_CONFIG"],
OPENCODE_CONFIG_CONTENT: process.env["OPENCODE_CONFIG_CONTENT"],
OPENCODE_DISABLE_AUTOUPDATE: truthy("OPENCODE_DISABLE_AUTOUPDATE"),
OPENCODE_ALWAYS_NOTIFY_UPDATE: truthy("OPENCODE_ALWAYS_NOTIFY_UPDATE"),
OPENCODE_DISABLE_PRUNE: truthy("OPENCODE_DISABLE_PRUNE"),
OPENCODE_DISABLE_TERMINAL_TITLE: truthy("OPENCODE_DISABLE_TERMINAL_TITLE"),
OPENCODE_SHOW_TTFD: truthy("OPENCODE_SHOW_TTFD"),
OPENCODE_DISABLE_AUTOCOMPACT: truthy("OPENCODE_DISABLE_AUTOCOMPACT"),
OPENCODE_DISABLE_MODELS_FETCH: truthy("OPENCODE_DISABLE_MODELS_FETCH"),
OPENCODE_DISABLE_MOUSE: truthy("OPENCODE_DISABLE_MOUSE"),
OPENCODE_FAKE_VCS: process.env["OPENCODE_FAKE_VCS"],
OPENCODE_SERVER_PASSWORD: process.env["OPENCODE_SERVER_PASSWORD"],
OPENCODE_SERVER_USERNAME: process.env["OPENCODE_SERVER_USERNAME"],
OPENCODE_DISABLE_FFF: fff === undefined ? process.platform === "win32" : truthy("OPENCODE_DISABLE_FFF"),
APEX_AUTO_HEAP_SNAPSHOT: truthy("APEX_AUTO_HEAP_SNAPSHOT"),
APEX_GIT_BASH_PATH: process.env["APEX_GIT_BASH_PATH"],
APEX_CONFIG: process.env["APEX_CONFIG"],
APEX_CONFIG_CONTENT: process.env["APEX_CONFIG_CONTENT"],
APEX_DISABLE_AUTOUPDATE: truthy("APEX_DISABLE_AUTOUPDATE"),
APEX_ALWAYS_NOTIFY_UPDATE: truthy("APEX_ALWAYS_NOTIFY_UPDATE"),
APEX_DISABLE_PRUNE: truthy("APEX_DISABLE_PRUNE"),
APEX_DISABLE_TERMINAL_TITLE: truthy("APEX_DISABLE_TERMINAL_TITLE"),
APEX_SHOW_TTFD: truthy("APEX_SHOW_TTFD"),
APEX_DISABLE_AUTOCOMPACT: truthy("APEX_DISABLE_AUTOCOMPACT"),
APEX_DISABLE_MODELS_FETCH: truthy("APEX_DISABLE_MODELS_FETCH"),
APEX_DISABLE_MOUSE: truthy("APEX_DISABLE_MOUSE"),
APEX_FAKE_VCS: process.env["APEX_FAKE_VCS"],
APEX_SERVER_PASSWORD: process.env["APEX_SERVER_PASSWORD"],
APEX_SERVER_USERNAME: process.env["APEX_SERVER_USERNAME"],
APEX_DISABLE_FFF: fff === undefined ? process.platform === "win32" : truthy("APEX_DISABLE_FFF"),

// Experimental
OPENCODE_EXPERIMENTAL_FILEWATCHER: Config.boolean("OPENCODE_EXPERIMENTAL_FILEWATCHER").pipe(
APEX_EXPERIMENTAL_FILEWATCHER: Config.boolean("APEX_EXPERIMENTAL_FILEWATCHER").pipe(
Config.withDefault(false),
),
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: Config.boolean("OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER").pipe(
APEX_EXPERIMENTAL_DISABLE_FILEWATCHER: Config.boolean("APEX_EXPERIMENTAL_DISABLE_FILEWATCHER").pipe(
Config.withDefault(false),
),
OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT:
copy === undefined ? process.platform === "win32" : truthy("OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"),
OPENCODE_MODELS_URL: process.env["OPENCODE_MODELS_URL"],
OPENCODE_MODELS_PATH: process.env["OPENCODE_MODELS_PATH"],
OPENCODE_DB: process.env["OPENCODE_DB"],
APEX_EXPERIMENTAL_DISABLE_COPY_ON_SELECT:
copy === undefined ? process.platform === "win32" : truthy("APEX_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"),
APEX_MODELS_URL: process.env["APEX_MODELS_URL"],
APEX_MODELS_PATH: process.env["APEX_MODELS_PATH"],
APEX_DB: process.env["APEX_DB"],

OPENCODE_WORKSPACE_ID: process.env["OPENCODE_WORKSPACE_ID"],
OPENCODE_EXPERIMENTAL_WORKSPACES: enabledByExperimental("OPENCODE_EXPERIMENTAL_WORKSPACES"),
APEX_WORKSPACE_ID: process.env["APEX_WORKSPACE_ID"],
APEX_EXPERIMENTAL_WORKSPACES: enabledByExperimental("APEX_EXPERIMENTAL_WORKSPACES"),

// Evaluated at access time (not module load) because tests, the CLI, and
// external tooling set these env vars at runtime.
get OPENCODE_DISABLE_PROJECT_CONFIG() {
return truthy("OPENCODE_DISABLE_PROJECT_CONFIG")
get APEX_DISABLE_PROJECT_CONFIG() {
return truthy("APEX_DISABLE_PROJECT_CONFIG")
},
get OPENCODE_EXPERIMENTAL_REFERENCES() {
return enabledByExperimental("OPENCODE_EXPERIMENTAL_REFERENCES")
get APEX_EXPERIMENTAL_REFERENCES() {
return enabledByExperimental("APEX_EXPERIMENTAL_REFERENCES")
},
get OPENCODE_TUI_CONFIG() {
return process.env["OPENCODE_TUI_CONFIG"]
get APEX_TUI_CONFIG() {
return process.env["APEX_TUI_CONFIG"]
},
get OPENCODE_CONFIG_DIR() {
return process.env["OPENCODE_CONFIG_DIR"]
get APEX_CONFIG_DIR() {
return process.env["APEX_CONFIG_DIR"]
},
get OPENCODE_PURE() {
return truthy("OPENCODE_PURE")
get APEX_PURE() {
return truthy("APEX_PURE")
},
get OPENCODE_PERMISSION() {
return process.env["OPENCODE_PERMISSION"]
get APEX_PERMISSION() {
return process.env["APEX_PERMISSION"]
},
get OPENCODE_PLUGIN_META_FILE() {
return process.env["OPENCODE_PLUGIN_META_FILE"]
get APEX_PLUGIN_META_FILE() {
return process.env["APEX_PLUGIN_META_FILE"]
},
get OPENCODE_CLIENT() {
return process.env["OPENCODE_CLIENT"] ?? "cli"
get APEX_CLIENT() {
return process.env["APEX_CLIENT"] ?? "cli"
},
}
8 changes: 4 additions & 4 deletions packages/core/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Flock } from "./util/flock"
import { Flag } from "./flag/flag"
import { LayerNode } from "./effect/layer-node"

const app = "opencode"
const app = "apex"
const data = path.join(xdgData!, app)
const cache = path.join(xdgCache!, app)
const config = path.join(xdgConfig!, app)
Expand All @@ -16,7 +16,7 @@ const tmp = path.join(os.tmpdir(), app)

const paths = {
get home() {
return process.env.OPENCODE_TEST_HOME ?? os.homedir()
return process.env.APEX_TEST_HOME ?? os.homedir()
},
data,
bin: path.join(cache, "bin"),
Expand All @@ -42,7 +42,7 @@ await Promise.all([
fs.mkdir(Path.repos, { recursive: true }),
])

export class Service extends Context.Service<Service, Interface>()("@opencode/Global") {}
export class Service extends Context.Service<Service, Interface>()("@apex/Global") {}

export interface Interface {
readonly home: string
Expand All @@ -61,7 +61,7 @@ export function make(input: Partial<Interface> = {}): Interface {
home: Path.home,
data: Path.data,
cache: Path.cache,
config: Flag.OPENCODE_CONFIG_DIR ?? Path.config,
config: Flag.APEX_CONFIG_DIR ?? Path.config,
state: Path.state,
tmp: Path.tmp,
bin: Path.bin,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/image/photon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DecodeError, ResizerUnavailableError, SizeError } from "../image"
const JPEG_QUALITIES = [80, 85, 70, 55, 40]

export const make = Effect.gen(function* () {
;(globalThis as typeof globalThis & { __OPENCODE_PHOTON_WASM_PATH?: string }).__OPENCODE_PHOTON_WASM_PATH =
;(globalThis as typeof globalThis & { __APEX_PHOTON_WASM_PATH?: string }).__APEX_PHOTON_WASM_PATH =
path.isAbsolute(photonWasm) ? photonWasm : fileURLToPath(new URL(photonWasm, import.meta.url))
const loadPhoton = yield* Effect.cached(
Effect.tryPromise({
Expand Down
Loading
Loading