|
|
@@ -19,21 +19,34 @@ export const AttachCommand = cmd({
|
|
|
alias: ["s"],
|
|
|
type: "string",
|
|
|
describe: "session id to continue",
|
|
|
+ })
|
|
|
+ .option("password", {
|
|
|
+ alias: ["p"],
|
|
|
+ type: "string",
|
|
|
+ describe: "basic auth password (defaults to OPENCODE_SERVER_PASSWORD)",
|
|
|
}),
|
|
|
handler: async (args) => {
|
|
|
- let directory = args.dir
|
|
|
- if (args.dir) {
|
|
|
+ const directory = (() => {
|
|
|
+ if (!args.dir) return undefined
|
|
|
try {
|
|
|
process.chdir(args.dir)
|
|
|
- directory = process.cwd()
|
|
|
+ return process.cwd()
|
|
|
} catch {
|
|
|
// If the directory doesn't exist locally (remote attach), pass it through.
|
|
|
+ return args.dir
|
|
|
}
|
|
|
- }
|
|
|
+ })()
|
|
|
+ const headers = (() => {
|
|
|
+ const password = args.password ?? process.env.OPENCODE_SERVER_PASSWORD
|
|
|
+ if (!password) return undefined
|
|
|
+ const auth = `Basic ${Buffer.from(`opencode:${password}`).toString("base64")}`
|
|
|
+ return { Authorization: auth }
|
|
|
+ })()
|
|
|
await tui({
|
|
|
url: args.url,
|
|
|
args: { sessionID: args.session },
|
|
|
directory,
|
|
|
+ headers,
|
|
|
})
|
|
|
},
|
|
|
})
|