mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
feat(cli): select individual debug paths (#48216)
This commit is contained in:
@@ -119,7 +119,26 @@ const Root = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCODE_CLI_NAME
|
||||
commands: [
|
||||
Spec.make("agents", { description: "List all agents" }),
|
||||
Spec.make("config", { description: "List configuration sources" }),
|
||||
Spec.make("paths", { description: "Show global paths (data, config, cache, state)" }),
|
||||
Spec.make("paths", {
|
||||
description: "Show global paths (data, config, cache, state)",
|
||||
params: {
|
||||
name: Argument.choice("name", [
|
||||
"db",
|
||||
"home",
|
||||
"data",
|
||||
"config",
|
||||
"cache",
|
||||
"state",
|
||||
"tmp",
|
||||
"bin",
|
||||
"log",
|
||||
"repos",
|
||||
]).pipe(
|
||||
Argument.withDescription("Print only one path: db, home, data, config, cache, state, tmp, bin, log, repos"),
|
||||
Argument.optional,
|
||||
),
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
Spec.make("auth", {
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import { EOL } from "os"
|
||||
import { Effect } from "effect"
|
||||
import { Effect, Option } from "effect"
|
||||
import { Global } from "@opencode/util/global"
|
||||
import { Commands } from "../../commands"
|
||||
import { Runtime } from "../../../framework/runtime"
|
||||
import { databasePath } from "../../../database-path"
|
||||
|
||||
export default Runtime.handler(
|
||||
Commands.commands.debug.commands.paths,
|
||||
Effect.fn("cli.debug.paths")(function* () {
|
||||
Effect.fn("cli.debug.paths")(function* (input) {
|
||||
const global = yield* Global.Service
|
||||
const paths = { ...global, db: databasePath(global.data) }
|
||||
if (Option.isSome(input.name)) {
|
||||
process.stdout.write(paths[input.name.value] + EOL)
|
||||
return
|
||||
}
|
||||
process.stdout.write(
|
||||
Object.entries(global)
|
||||
Object.entries(paths)
|
||||
.map(([key, value]) => `${key.padEnd(10)} ${value}${EOL}`)
|
||||
.join(""),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import path from "node:path"
|
||||
import { OPENCODE_CHANNEL } from "./version"
|
||||
|
||||
export function databasePath(data: string) {
|
||||
const filename =
|
||||
process.env.OPENCODE_DB ??
|
||||
(["latest", "dev", "beta", "next", "prod"].includes(OPENCODE_CHANNEL) ||
|
||||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" ||
|
||||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "true"
|
||||
? "opencode.db"
|
||||
: `opencode-${OPENCODE_CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
|
||||
return filename === ":memory:" ? filename : path.resolve(data, filename)
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { ServiceConfig } from "./services/service-config"
|
||||
import { ServiceRegistration } from "./services/service-registration"
|
||||
import { Updater } from "./services/updater"
|
||||
import { WebUi } from "./services/web-ui"
|
||||
import { databasePath } from "./database-path"
|
||||
|
||||
export type Mode = "default" | "service" | "stdio"
|
||||
|
||||
@@ -94,13 +95,7 @@ const processEffect = Effect.fnUntraced(function* (options: Options) {
|
||||
pty: { handoff },
|
||||
simulation: truthy(process.env.OPENCODE_SIMULATE),
|
||||
database: {
|
||||
path:
|
||||
process.env.OPENCODE_DB ??
|
||||
(["latest", "dev", "beta", "next", "prod"].includes(OPENCODE_CHANNEL) ||
|
||||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" ||
|
||||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "true"
|
||||
? "opencode.db"
|
||||
: `opencode-${OPENCODE_CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`),
|
||||
path: databasePath(global.data),
|
||||
},
|
||||
models: {
|
||||
url: process.env.OPENCODE_MODELS_URL,
|
||||
|
||||
@@ -57,6 +57,25 @@ opencode2 --server http://localhost:4096
|
||||
|
||||
See [Troubleshooting](/troubleshooting) for shared service diagnostics and the [API reference](/api) for server endpoints.
|
||||
|
||||
## Paths
|
||||
|
||||
Print a specific local path for use with other tools:
|
||||
|
||||
```bash
|
||||
opencode2 debug paths db
|
||||
sqlite3 "$(opencode2 debug paths db)"
|
||||
```
|
||||
|
||||
The optional selector accepts `db`, `home`, `data`, `config`, `cache`, `state`, `tmp`, `bin`, `log`, or `repos` and prints
|
||||
only the path and a newline. The database path respects the release channel and `OPENCODE_DB`; relative database overrides
|
||||
resolve under the data directory, and `:memory:` is printed as-is. This command does not start a server or open the database.
|
||||
|
||||
Omit the selector to show all paths with labels:
|
||||
|
||||
```bash
|
||||
opencode2 debug paths
|
||||
```
|
||||
|
||||
## Uninstall
|
||||
|
||||
Preview the files and installation that will be removed:
|
||||
|
||||
Reference in New Issue
Block a user