fix(opencode): pass missing auth headers in run --attach#16097
fix(opencode): pass missing auth headers in run --attach#16097ericclemmons wants to merge 5 commits intoanomalyco:devfrom
run --attach#16097Conversation
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: feat(github-action): Support remote server connection via --attach (#15866)
However, this appears to be a feature addition for GitHub Actions rather than a direct duplicate of the auth headers bug fix. The current PR (#16097) is specifically addressing a bug where auth headers are missing when using No duplicate PRs found |
Fixes anomalyco#16096 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c8a6687 to
35405a3
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consolidates auth header logic from worker.ts and attach.ts into a shared util used by run.ts, attach.ts, and worker.ts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Match existing inline pattern from attach.ts instead of extracting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Match attach.ts pattern: accept --password/-p flag and fall back to OPENCODE_SERVER_PASSWORD env var. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| .option("password", { | ||
| alias: ["p"], | ||
| type: "string", | ||
| describe: "basic auth password (defaults to OPENCODE_SERVER_PASSWORD)", | ||
| }) |
There was a problem hiding this comment.
So that we're consistent with attach:
opencode/packages/opencode/src/cli/cmd/tui/attach.ts
Lines 37 to 41 in 85ff056
| 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 } | ||
| })() |
There was a problem hiding this comment.
This is modeled after
opencode/packages/opencode/src/cli/cmd/tui/attach.ts
Lines 63 to 68 in 85ff056
| if (args.attach) { | ||
| const sdk = createOpencodeClient({ baseUrl: args.attach, directory }) | ||
| const headers = (() => { | ||
| const password = args.password ?? process.env.OPENCODE_SERVER_PASSWORD |
There was a problem hiding this comment.
This still hardcodes "opencode", so run --attach will keep failing against servers using a non-default OPENCODE_SERVER_USERNAME. Can we read the username from env here (like worker.ts) instead of only fixing the password path?
Issue for this PR
Closes #16096
Type of change
What does this PR do?
Adds missing Basic auth headers to
runcommand, just likeattach.How did you verify your code works?
Relied on tests (that I've since removed to be consistent with the other patterns) and comparing
runagainstopencode servevs. one with Basic auth (like whatOpenCode.appstarts):✅
opencode --attach http://127.0.0.1:45103 --dir ~/workspace run howdy❌
OPENCODE_SERVER_USERNAME=opencode OPENCODE_SERVER_PASSWORD=hunter2 opencode --attach=localhost:4096 run howdyChecklist
Notes
I originally started refactoring out a
getAuthorizationHeaderutility based onopencode/packages/opencode/src/cli/cmd/tui/worker.ts
Line 147 in 85ff056
opencode/packages/opencode/src/cli/cmd/tui/attach.ts
Lines 63 to 68 in 85ff056
I did use AI to author this because I was in the middle of another project when I finally asked Claude "Wait, is this an opencode bug??" and wound up here.
I'm sorry. 😔