Skip to content

An open-source, faster Devin alternative

TypeScript

feat(cli): print agent URL after deploy

Igor Zalutskid398ee656ad2
diff --git a/cmd/oc/internal/commands/agent_deploy.go b/cmd/oc/internal/commands/agent_deploy.go
index 56c25327..c123805a 100644
--- a/cmd/oc/internal/commands/agent_deploy.go
+++ b/cmd/oc/internal/commands/agent_deploy.go
@@ -2,6 +2,7 @@ package commands
import (
"fmt"
+ "io"
"io/fs"
"os"
"path/filepath"
@@ -10,6 +11,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/opensandbox/opensandbox/cmd/oc/internal/client"
+ "github.com/opensandbox/opensandbox/cmd/oc/internal/config"
"github.com/spf13/cobra"
)
@@ -150,6 +152,30 @@ func revisionNumber(cmd *cobra.Command, sc *client.Client, id, revisionID string
return 0
}
+// loadDeployHandoff fetches the public URL only for human-readable output. A
+// successful deployment stays successful if this convenience read fails; the
+// user can still retrieve the URL with `oc agent get`.
+func loadDeployHandoff(cmd *cobra.Command, sc *client.Client, id string) Agent {
+ agent := Agent{ID: id}
+ if err := sc.Get(cmd.Context(), "/v3/agents/"+id, &agent); err != nil {
+ return Agent{ID: id}
+ }
+ if agent.ID == "" {
+ agent.ID = id
+ }
+ return agent
+}
+
+func printDeployHandoff(w io.Writer, agent Agent) {
+ if agent.ID == "" || agent.InvokeURL == "" {
+ return
+ }
+ manageURL := strings.TrimRight(config.DefaultAPIURL, "/") + "/agents/" + agent.ID
+ fmt.Fprintf(w, "Agent URL: %s\n", agent.InvokeURL)
+ fmt.Fprintf(w, "Invoke: oc agent invoke %s --data '{\"message\":\"Hello\"}'\n", agent.ID)
+ fmt.Fprintf(w, "Manage: %s\n", manageURL)
+}
+
// ── async deployment polling ──
func terminalState(s string) bool {
@@ -261,7 +287,7 @@ var agentDeployCmd = &cobra.Command{
// A fresh agent with no skills: `create` already produced the first
// revision (the deploy) — don't append a redundant identical one.
if created && len(skills) == 0 {
- var a Agent
+ a := Agent{ID: id}
_ = sc.Get(cmd.Context(), "/v3/agents/"+id, &a)
n := 0
if a.ActiveRevision != nil {
@@ -269,6 +295,7 @@ var agentDeployCmd = &cobra.Command{
}
printer.Print(map[string]interface{}{"agent_id": id, "revision": n, "state": "ready", "active": true}, func() {
fmt.Printf("Deployed %s — revision %d (active)\n", a.Name, n)
+ printDeployHandoff(printer.W, a)
})
return nil
}
@@ -299,6 +326,10 @@ var agentDeployCmd = &cobra.Command{
printer.Print(d, func() { fmt.Printf("Deploy failed: %s\n", deployFailMsg(d)) })
return &ExitError{Code: 1}
}
+ handoff := Agent{}
+ if !jsonOutput && d.State == "ready" {
+ handoff = loadDeployHandoff(cmd, sc, id)
+ }
printer.Print(d, func() {
if d.State == "ready" {
n := revisionNumber(cmd, sc, id, d.RevisionID)
@@ -307,6 +338,7 @@ var agentDeployCmd = &cobra.Command{
status = "active"
}
fmt.Printf("Deployed revision %d — %s\n", n, status)
+ printDeployHandoff(printer.W, handoff)
} else {
fmt.Printf("Deployment %s: %s\n", d.ID, d.State)
}
diff --git a/cmd/oc/internal/commands/agent_deploy_flue.go b/cmd/oc/internal/commands/agent_deploy_flue.go
index 0814adf8..9d4498b9 100644
--- a/cmd/oc/internal/commands/agent_deploy_flue.go
+++ b/cmd/oc/internal/commands/agent_deploy_flue.go
@@ -118,6 +118,10 @@ func deployFlue(cmd *cobra.Command, sc *client.Client, dir string, m *manifest,
printer.Print(d, func() { fmt.Printf("Deploy failed: %s\n", deployFailMsg(d)) })
return &ExitError{Code: 1}
}
+ handoff := Agent{}
+ if !jsonOutput && d.State == "ready" {
+ handoff = loadDeployHandoff(cmd, sc, id)
+ }
printer.Print(d, func() {
n := revisionNumber(cmd, sc, id, d.RevisionID)
status := "staged"
@@ -125,6 +129,7 @@ func deployFlue(cmd *cobra.Command, sc *client.Client, dir string, m *manifest,
status = "active"
}
fmt.Printf("Deployed revision %d — %s (%s)\n", n, status, shortDigest(digest))
+ printDeployHandoff(printer.W, handoff)
})
return nil
}
diff --git a/cmd/oc/internal/commands/agent_deploy_flue_test.go b/cmd/oc/internal/commands/agent_deploy_flue_test.go
index 51f7b8ac..7dce3ac3 100644
--- a/cmd/oc/internal/commands/agent_deploy_flue_test.go
+++ b/cmd/oc/internal/commands/agent_deploy_flue_test.go
@@ -67,6 +67,11 @@ func (f *fakeCP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case r.Method == "POST" && r.URL.Path == "/v3/agents":
_ = json.NewDecoder(r.Body).Decode(&f.createBody)
writeJSON(map[string]any{"id": fakeAgentID, "name": "e2e-flue", "model": "anthropic/claude-sonnet-5", "runtime": "flue"})
+ case r.Method == "GET" && r.URL.Path == "/v3/agents/"+fakeAgentID:
+ writeJSON(map[string]any{
+ "id": fakeAgentID, "name": "e2e-flue", "model": "anthropic/claude-sonnet-5", "runtime": "flue",
+ "invoke_url": "https://agt-0123456789abcdef01234567.agents.opencomputer.dev",
+ })
case r.Method == "PUT" && r.URL.Path == "/v3/agents/"+fakeAgentID+"/config":
_ = json.NewDecoder(r.Body).Decode(&f.configPutBody)
writeJSON(map[string]any{
@@ -161,11 +166,22 @@ func TestDeployFlueDoEndToEnd(t *testing.T) {
prev := printer
printer = output.New(false)
+ var humanOutput bytes.Buffer
+ printer.W = &humanOutput
defer func() { printer = prev }()
if err := deployFlue(cmd, sc, dir, m, false); err != nil {
t.Fatalf("deployFlue: %v", err)
}
+ for _, want := range []string{
+ "Agent URL: https://agt-0123456789abcdef01234567.agents.opencomputer.dev\n",
+ "Invoke: oc agent invoke " + fakeAgentID + " --data '{\"message\":\"Hello\"}'\n",
+ "Manage: https://app.opencomputer.dev/agents/" + fakeAgentID + "\n",
+ } {
+ if !strings.Contains(humanOutput.String(), want) {
+ t.Errorf("human deploy output missing %q:\n%s", want, humanOutput.String())
+ }
+ }
// Agent created as flue, no prompt.
if f.createBody["runtime"] != "flue" {
diff --git a/cmd/oc/internal/commands/agent_deploy_handoff_test.go b/cmd/oc/internal/commands/agent_deploy_handoff_test.go
new file mode 100644
index 00000000..ea7201c1
--- /dev/null
+++ b/cmd/oc/internal/commands/agent_deploy_handoff_test.go
@@ -0,0 +1,88 @@
+package commands
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/opensandbox/opensandbox/cmd/oc/internal/client"
+ "github.com/opensandbox/opensandbox/cmd/oc/internal/output"
+ "github.com/spf13/cobra"
+)
+
+func TestAgentDeployFreshAgentPrintsPublicHandoff(t *testing.T) {
+ const agentID = "agt_abcdef0123456789abcdef01"
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ switch {
+ case r.Method == http.MethodGet && r.URL.Path == "/v3/agents":
+ _ = json.NewEncoder(w).Encode(map[string]any{"data": []any{}})
+ case r.Method == http.MethodPost && r.URL.Path == "/v3/agents":
+ _ = json.NewEncoder(w).Encode(map[string]any{
+ "id": agentID, "name": "triage", "model": "anthropic/claude-sonnet-4", "runtime": "claude",
+ })
+ case r.Method == http.MethodGet && r.URL.Path == "/v3/agents/"+agentID:
+ _ = json.NewEncoder(w).Encode(map[string]any{
+ "id": agentID, "name": "triage", "model": "anthropic/claude-sonnet-4", "runtime": "claude",
+ "invoke_url": "https://agt-abcdef0123456789abcdef01.agents.opencomputer.dev",
+ "active_revision": map[string]any{"id": "rev_1", "number": 1, "digest": "sha256:test"},
+ })
+ default:
+ http.Error(w, "unexpected "+r.Method+" "+r.URL.Path, http.StatusNotFound)
+ }
+ }))
+ defer server.Close()
+
+ dir := t.TempDir()
+ if err := os.WriteFile(filepath.Join(dir, "agent.toml"), []byte("name = \"triage\"\nmodel = \"anthropic/claude-sonnet-4\"\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(dir, "prompt.md"), []byte("Be concise.\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ cmd := &cobra.Command{}
+ cmd.Flags().String("agent", "", "")
+ cmd.Flags().Bool("no-activate", false, "")
+ sc := client.NewSessionsAPI(server.URL, "test-key")
+ cmd.SetContext(client.WithSessionsClient(context.Background(), sc))
+
+ previousPrinter, previousJSON := printer, jsonOutput
+ var humanOutput bytes.Buffer
+ printer = output.New(false)
+ printer.W = &humanOutput
+ jsonOutput = false
+ defer func() {
+ printer = previousPrinter
+ jsonOutput = previousJSON
+ }()
+
+ if err := agentDeployCmd.RunE(cmd, []string{dir}); err != nil {
+ t.Fatalf("agent deploy: %v", err)
+ }
+
+ got := humanOutput.String()
+ for _, want := range []string{
+ "Agent URL: https://agt-abcdef0123456789abcdef01.agents.opencomputer.dev",
+ "Invoke: oc agent invoke " + agentID + " --data '{\"message\":\"Hello\"}'",
+ "Manage: https://app.opencomputer.dev/agents/" + agentID,
+ } {
+ if !strings.Contains(got, want) {
+ t.Errorf("human deploy output missing %q:\n%s", want, got)
+ }
+ }
+}
+
+func TestPrintDeployHandoffOmitsIncompleteAgent(t *testing.T) {
+ var output bytes.Buffer
+ printDeployHandoff(&output, Agent{ID: "agt_abcdef0123456789abcdef01"})
+ if output.Len() != 0 {
+ t.Fatalf("unexpected output without invoke URL: %q", output.String())
+ }
+}