mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Merge a8fc9098c3 into 83397ebde2
This commit is contained in:
commit
37b2f0c455
4 changed files with 88 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { cmd } from "../cmd"
|
||||
import { tui } from "./app"
|
||||
import { iife } from "@/util/iife"
|
||||
|
||||
export const AttachCommand = cmd({
|
||||
command: "attach <url>",
|
||||
|
|
@ -15,16 +16,58 @@ export const AttachCommand = cmd({
|
|||
type: "string",
|
||||
description: "directory to run in",
|
||||
})
|
||||
.option("model", {
|
||||
type: "string",
|
||||
alias: ["m"],
|
||||
describe: "model to use in the format of provider/model",
|
||||
})
|
||||
.option("continue", {
|
||||
alias: ["c"],
|
||||
describe: "continue the last session",
|
||||
type: "boolean",
|
||||
})
|
||||
.option("session", {
|
||||
alias: ["s"],
|
||||
type: "string",
|
||||
describe: "session id to continue",
|
||||
})
|
||||
.option("prompt", {
|
||||
alias: ["p"],
|
||||
type: "string",
|
||||
describe: "prompt to use",
|
||||
})
|
||||
.option("agent", {
|
||||
type: "string",
|
||||
describe: "agent to use",
|
||||
})
|
||||
.option("title", {
|
||||
type: "string",
|
||||
describe: "title for the session (uses truncated prompt if no value provided)",
|
||||
})
|
||||
.option("command", {
|
||||
type: "string",
|
||||
describe: "the command to run, use prompt for args",
|
||||
}),
|
||||
handler: async (args) => {
|
||||
if (args.dir) process.chdir(args.dir)
|
||||
|
||||
const prompt = await iife(async () => {
|
||||
const piped = !process.stdin.isTTY ? await Bun.stdin.text() : undefined
|
||||
if (!args.prompt) return piped
|
||||
return piped ? piped + "\n" + args.prompt : args.prompt
|
||||
})
|
||||
|
||||
await tui({
|
||||
url: args.url,
|
||||
args: { sessionID: args.session },
|
||||
args: {
|
||||
continue: args.continue,
|
||||
sessionID: args.session,
|
||||
agent: args.agent,
|
||||
model: args.model,
|
||||
prompt,
|
||||
title: args.title,
|
||||
command: args.command,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ export interface Args {
|
|||
prompt?: string
|
||||
continue?: boolean
|
||||
sessionID?: string
|
||||
title?: string
|
||||
command?: string
|
||||
}
|
||||
|
||||
export const { use: useArgs, provider: ArgsProvider } = createSimpleContext({
|
||||
|
|
|
|||
|
|
@ -51,7 +51,9 @@ export function Home() {
|
|||
const args = useArgs()
|
||||
onMount(() => {
|
||||
if (once) return
|
||||
if (route.initialPrompt) {
|
||||
if (args.command) {
|
||||
prompt.set({ input: `/${args.command} ${args.prompt || ""}`.trim(), parts: [] })
|
||||
} else if (route.initialPrompt) {
|
||||
prompt.set(route.initialPrompt)
|
||||
once = true
|
||||
} else if (args.prompt) {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,45 @@ This command will guide you through creating a new agent with a custom system pr
|
|||
|
||||
---
|
||||
|
||||
### attach
|
||||
|
||||
Attach to a running opencode server with a full terminal interface.
|
||||
|
||||
```bash
|
||||
opencode attach <url>
|
||||
```
|
||||
|
||||
This command connects to an existing `opencode serve` or `opencode spawn` instance and provides the full TUI experience, allowing you to interact with the server as if you started opencode directly.
|
||||
|
||||
```bash
|
||||
# Start a headless server in one terminal
|
||||
opencode serve
|
||||
|
||||
# In another terminal, attach with the TUI
|
||||
opencode attach http://localhost:4096
|
||||
```
|
||||
|
||||
This is useful when you want to:
|
||||
|
||||
- Connect to a long-running opencode server
|
||||
- Avoid MCP server cold boot times
|
||||
- Share a server instance across multiple sessions
|
||||
|
||||
#### Flags
|
||||
|
||||
| Flag | Short | Description |
|
||||
| ------------ | ----- | ------------------------------------------------------------------ |
|
||||
| `--dir` | | Directory to run in |
|
||||
| `--model` | `-m` | Model to use in the form of provider/model |
|
||||
| `--continue` | `-c` | Continue the last session |
|
||||
| `--session` | `-s` | Session ID to continue |
|
||||
| `--prompt` | `-p` | Prompt to use |
|
||||
| `--agent` | | Agent to use |
|
||||
| `--title` | | Title for the session (uses truncated prompt if no value provided) |
|
||||
| `--command` | | The command to run, use prompt for args |
|
||||
|
||||
---
|
||||
|
||||
### auth
|
||||
|
||||
Command to manage credentials and login for providers.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue