Repository navigation
Conversation
The new internal/setup/agent package runs one OpenCode session for a setup task. It starts `opencode serve` in the project folder on the loopback interface, with a random password for each run, and without any LD_ environment variable. It creates the session, sends the task, reads the event stream, and turns the events into text, tool calls, changed files, token usage, permission requests, and questions. It answers permissions and questions, and it stops OpenCode when the run ends. The agent runs shell commands without approvals. OpenCode's rules deny files outside the project, web access, sub-agents, and a few commands such as git push. The agent asks the user only with the question tool. Nothing uses the package yet. The wizard step comes in the next change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atornsii
added this pull request to stack #902
October 20, 2026 15:48
This was referenced Oct 20, 2026
atornsii
marked this pull request as ready for review
October 20, 2026 18:13
atornsii
requested review from
zakk-verrilli-ld
and removed request for
a team
October 20, 2026 18:13
…d map every client SDK Close now sends a final error event and closes Events, if the run did not finish. A reader of Events no longer waits forever. The child environment now sets OPENCODE_SERVER_USERNAME, so a value in the user's shell does not break the basic auth. CredentialEnvVar now covers every client-side and mobile SDK ID and alias that the installer and the templates accept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rns/agent-1-opencode-adapter
The prompt for flutter-client-sdk now also names LAUNCHDARKLY_CLIENT_SIDE_ID for an app that runs on the web. The error of a stopped run now uses active voice, and two comments now follow the sentence limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the
internal/setup/agentpackage, which runs one OpenCode session for a setup task. Nothing uses it yet. PR 2 adds the wizard step.What it does
opencode servein the project folder on127.0.0.1, with a random password for each run (OPENCODE_SERVER_PASSWORD) and without anyLD_environment variable.POST /permission/{id}/reply) and questions (POST /question/{id}/replyor/reject), and stops OpenCode when the run ends.The agent runs shell commands without approvals. OpenCode's rules (in
OPENCODE_CONFIG_CONTENT) deny files outside the project, web access, sub-agents,git commit,git push,git reset,sudo, andrm -rfon absolute paths. The agent asks the user only with the question tool. The task tells the agent to read the SDK credential from an environment variable, so no key goes into a prompt.Testing
Unit tests cover the event decoder, the stream reader, the prompt, the environment filter, the permission rules, and the version check. A fake OpenCode HTTP server tests the run: the task, the events, permission replies, question answers, and a stream that ends early. The event and request formats come from the OpenCode v1.19.3 SDK types, and the adapter ran end to end against OpenCode 1.19.3 in local tests.
Diagram
Blue boxes are new files, orange boxes are changed files, dashed boxes are files from an earlier PR, and purple boxes are outside ldcli. A solid arrow goes from the caller to the code that it calls. A dashed arrow shows data that moves without a direct call.
agent.gois the contract that the wizard uses:Task,Config,Event, and theRunnerandRuninterfaces.opencode.goimplementsRunnerand connects the other files. WhenStartruns, it gets the permission rules fromopencode_config.goand startsopencode servewithserver.go.server.gouseschildEnvto remove everyLD_variable from the child environment. Thenopencode.gocreates a session, subscribes to events, and sends the task fromprompt.gothroughclient.go.events.goreads the SSE stream and turns it intoEventvalues for the run's channel.This PR adds only new files. Nothing calls the package until #895.
Stack
This is one of six PRs for the
ldcli setupagent. Review and merge them in order, after #877 (Go 1.26):They replace #876 and #878.
🤖 Generated with Claude Code
Note
Overview
Adds
internal/setup/agent, a new OpenCode-backed runner forldcli setupthat is not wired into the CLI yet (follow-up PRs will add the wizard step).The package defines
Runner/RunAPIs (Task,Event, permissions, questions) and anOpenCodeimplementation that spawnsopencode serveon loopback with a per-run password, stripsLD_*env vars from the child process, and injects permission rules viaOPENCODE_CONFIG_CONTENT(allow read/edit/bash with denials for git push/commit, sudo, destructiverm, web, and paths outside the project). It creates a session, sends a built prompt that tells the agent to read SDK credentials from env vars (never ldcli tokens), streams SSE into typed events, and supports replying to permissions/questions.Tests cover prompt/credential mapping, env filtering, config rules, version checks, SSE/event decoding, and HTTP integration with a fake OpenCode server.
Reviewed by Cursor Bugbot for commit a6fafd5. Bugbot is set up for automated code reviews on this repo. Configure here.