Skip to content

Commit 7fb7938

Browse files
authored
feat(cli): select individual debug paths (#48216)
1 parent 7f2510c commit 7fb7938

5 files changed

Lines changed: 63 additions & 11 deletions

File tree

packages/cli/src/commands/commands.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,26 @@ const Root = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCODE_CLI_NAME
119119
commands: [
120120
Spec.make("agents", { description: "List all agents" }),
121121
Spec.make("config", { description: "List configuration sources" }),
122-
Spec.make("paths", { description: "Show global paths (data, config, cache, state)" }),
122+
Spec.make("paths", {
123+
description: "Show global paths (data, config, cache, state)",
124+
params: {
125+
name: Argument.choice("name", [
126+
"db",
127+
"home",
128+
"data",
129+
"config",
130+
"cache",
131+
"state",
132+
"tmp",
133+
"bin",
134+
"log",
135+
"repos",
136+
]).pipe(
137+
Argument.withDescription("Print only one path: db, home, data, config, cache, state, tmp, bin, log, repos"),
138+
Argument.optional,
139+
),
140+
},
141+
}),
123142
],
124143
}),
125144
Spec.make("auth", {

packages/cli/src/commands/handlers/debug/paths.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { EOL } from "os"
2-
import { Effect } from "effect"
2+
import { Effect, Option } from "effect"
33
import { Global } from "@opencode/util/global"
44
import { Commands } from "../../commands"
55
import { Runtime } from "../../../framework/runtime"
6+
import { databasePath } from "../../../database-path"
67

78
export default Runtime.handler(
89
Commands.commands.debug.commands.paths,
9-
Effect.fn("cli.debug.paths")(function* () {
10+
Effect.fn("cli.debug.paths")(function* (input) {
1011
const global = yield* Global.Service
12+
const paths = { ...global, db: databasePath(global.data) }
13+
if (Option.isSome(input.name)) {
14+
process.stdout.write(paths[input.name.value] + EOL)
15+
return
16+
}
1117
process.stdout.write(
12-
Object.entries(global)
18+
Object.entries(paths)
1319
.map(([key, value]) => `${key.padEnd(10)} ${value}${EOL}`)
1420
.join(""),
1521
)

packages/cli/src/database-path.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import path from "node:path"
2+
import { OPENCODE_CHANNEL } from "./version"
3+
4+
export function databasePath(data: string) {
5+
const filename =
6+
process.env.OPENCODE_DB ??
7+
(["latest", "dev", "beta", "next", "prod"].includes(OPENCODE_CHANNEL) ||
8+
process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" ||
9+
process.env.OPENCODE_DISABLE_CHANNEL_DB === "true"
10+
? "opencode.db"
11+
: `opencode-${OPENCODE_CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
12+
return filename === ":memory:" ? filename : path.resolve(data, filename)
13+
}

packages/cli/src/server-process.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ServiceConfig } from "./services/service-config"
1515
import { ServiceRegistration } from "./services/service-registration"
1616
import { Updater } from "./services/updater"
1717
import { WebUi } from "./services/web-ui"
18+
import { databasePath } from "./database-path"
1819

1920
export type Mode = "default" | "service" | "stdio"
2021

@@ -94,13 +95,7 @@ const processEffect = Effect.fnUntraced(function* (options: Options) {
9495
pty: { handoff },
9596
simulation: truthy(process.env.OPENCODE_SIMULATE),
9697
database: {
97-
path:
98-
process.env.OPENCODE_DB ??
99-
(["latest", "dev", "beta", "next", "prod"].includes(OPENCODE_CHANNEL) ||
100-
process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" ||
101-
process.env.OPENCODE_DISABLE_CHANNEL_DB === "true"
102-
? "opencode.db"
103-
: `opencode-${OPENCODE_CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`),
98+
path: databasePath(global.data),
10499
},
105100
models: {
106101
url: process.env.OPENCODE_MODELS_URL,

services/www/src/docs/content/cli/index.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ opencode2 --server http://localhost:4096
5757

5858
See [Troubleshooting](/troubleshooting) for shared service diagnostics and the [API reference](/api) for server endpoints.
5959

60+
## Paths
61+
62+
Print a specific local path for use with other tools:
63+
64+
```bash
65+
opencode2 debug paths db
66+
sqlite3 "$(opencode2 debug paths db)"
67+
```
68+
69+
The optional selector accepts `db`, `home`, `data`, `config`, `cache`, `state`, `tmp`, `bin`, `log`, or `repos` and prints
70+
only the path and a newline. The database path respects the release channel and `OPENCODE_DB`; relative database overrides
71+
resolve under the data directory, and `:memory:` is printed as-is. This command does not start a server or open the database.
72+
73+
Omit the selector to show all paths with labels:
74+
75+
```bash
76+
opencode2 debug paths
77+
```
78+
6079
## Uninstall
6180

6281
Preview the files and installation that will be removed:

0 commit comments

Comments
 (0)