cloudaxe-opencode/packages/opencode/src/cli/cmd/debug/index.ts

86 lines
2.7 KiB
TypeScript
Raw Normal View History

import { Global } from "@opencode-ai/core/global"
2026-05-03 05:04:52 +00:00
import { InstallationVersion } from "@opencode-ai/core/installation/version"
import { Flag } from "@opencode-ai/core/flag/flag"
import os from "os"
import { Duration, Effect } from "effect"
2026-05-03 05:04:52 +00:00
import { Config } from "@/config/config"
import { ConfigPlugin } from "@/config/plugin"
import { effectCmd } from "../../effect-cmd"
2025-07-01 16:06:38 +00:00
import { cmd } from "../cmd"
2025-10-04 04:07:58 +00:00
import { ConfigCommand } from "./config"
2025-07-01 16:06:38 +00:00
import { FileCommand } from "./file"
import { LSPCommand } from "./lsp"
import { RipgrepCommand } from "./ripgrep"
2025-07-10 15:25:31 +00:00
import { ScrapCommand } from "./scrap"
import { SkillCommand } from "./skill"
2025-07-01 16:06:38 +00:00
import { SnapshotCommand } from "./snapshot"
import { AgentCommand } from "./agent"
import { StartupCommand } from "./startup"
2025-07-01 16:06:38 +00:00
export const DebugCommand = cmd({
command: "debug",
describe: "debugging and troubleshooting tools",
2025-07-01 16:06:38 +00:00
builder: (yargs) =>
yargs
2025-10-04 04:07:58 +00:00
.command(ConfigCommand)
2025-07-01 16:06:38 +00:00
.command(LSPCommand)
.command(RipgrepCommand)
.command(FileCommand)
2025-07-10 15:25:31 +00:00
.command(ScrapCommand)
.command(SkillCommand)
2025-07-01 16:06:38 +00:00
.command(SnapshotCommand)
.command(StartupCommand)
.command(AgentCommand)
2026-05-03 05:04:52 +00:00
.command(InfoCommand)
2025-07-23 16:14:54 +00:00
.command(PathsCommand)
.command(WaitCommand)
2025-07-01 16:06:38 +00:00
.demandCommand(),
async handler() {},
})
2025-07-23 16:14:54 +00:00
const WaitCommand = effectCmd({
command: "wait",
describe: "wait indefinitely (for debugging)",
handler: Effect.fn("Cli.debug.wait")(function* () {
yield* Effect.sleep(Duration.days(1))
}),
})
2026-05-03 05:04:52 +00:00
const InfoCommand = effectCmd({
command: "info",
describe: "show debug information",
handler: Effect.fn("Cli.debug.info")(function* () {
const config = yield* Config.Service.use((cfg) => cfg.get())
const termProgram = process.env.TERM_PROGRAM
? `${process.env.TERM_PROGRAM}${process.env.TERM_PROGRAM_VERSION ? ` ${process.env.TERM_PROGRAM_VERSION}` : ""}`
: undefined
const terminal = [termProgram, process.env.TERM].filter((item): item is string => Boolean(item)).join(" / ")
console.log(`opencode version: ${InstallationVersion}`)
console.log(`os: ${os.type()} ${os.release()} ${os.arch()}`)
console.log(`terminal: ${terminal || "unknown"}`)
console.log("plugins:")
if (Flag.OPENCODE_PURE) {
console.log("external plugins disabled (--pure)")
return
}
if (!config.plugin_origins?.length) {
console.log("none")
return
}
for (const plugin of config.plugin_origins) {
console.log(`- ${ConfigPlugin.pluginSpecifier(plugin.spec)}`)
}
}),
})
2025-07-23 16:14:54 +00:00
const PathsCommand = cmd({
command: "paths",
describe: "show global paths (data, config, cache, state)",
2025-07-23 16:14:54 +00:00
handler() {
for (const [key, value] of Object.entries(Global.Path)) {
console.log(key.padEnd(10), value)
}
},
})