GeezerVison is showing github.com — fix: `run --attach` agent validation (#11812) · chuckchen/opencode@109ea17
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/opencode/src/cli/cmd
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/run.ts +39Lines changed: 39 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -555,6 +555,45 @@ export const RunCommand = cmd({ |
555 | 555 | // Validate agent if specified |
556 | 556 | const agent = await (async () => { |
557 | 557 | if (!args.agent) return undefined |
| 558 | + |
| 559 | + // When attaching, validate against the running server instead of local Instance state. |
| 560 | + if (args.attach) { |
| 561 | + const modes = await sdk.app |
| 562 | + .agents(undefined, { throwOnError: true }) |
| 563 | + .then((x) => x.data ?? []) |
| 564 | + .catch(() => undefined) |
| 565 | + |
| 566 | + if (!modes) { |
| 567 | + UI.println( |
| 568 | + UI.Style.TEXT_WARNING_BOLD + "!", |
| 569 | + UI.Style.TEXT_NORMAL, |
| 570 | + `failed to list agents from ${args.attach}. Falling back to default agent`, |
| 571 | + ) |
| 572 | + return undefined |
| 573 | + } |
| 574 | + |
| 575 | + const agent = modes.find((a) => a.name === args.agent) |
| 576 | + if (!agent) { |
| 577 | + UI.println( |
| 578 | + UI.Style.TEXT_WARNING_BOLD + "!", |
| 579 | + UI.Style.TEXT_NORMAL, |
| 580 | + `agent "${args.agent}" not found. Falling back to default agent`, |
| 581 | + ) |
| 582 | + return undefined |
| 583 | + } |
| 584 | + |
| 585 | + if (agent.mode === "subagent") { |
| 586 | + UI.println( |
| 587 | + UI.Style.TEXT_WARNING_BOLD + "!", |
| 588 | + UI.Style.TEXT_NORMAL, |
| 589 | + `agent "${args.agent}" is a subagent, not a primary agent. Falling back to default agent`, |
| 590 | + ) |
| 591 | + return undefined |
| 592 | + } |
| 593 | + |
| 594 | + return args.agent |
| 595 | + } |
| 596 | + |
558 | 597 | const entry = await Agent.get(args.agent) |
559 | 598 | if (!entry) { |
560 | 599 | UI.println( |
|