Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/flashcatcloud/flashduty-cli
go 1.26.0

require (
github.com/flashcatcloud/go-flashduty v0.16.0
github.com/flashcatcloud/go-flashduty v0.16.1
github.com/mattn/go-runewidth v0.0.30
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY=
github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/flashcatcloud/go-flashduty v0.16.0 h1:YHrd9NaJZReWv1u1iUSLh89HNCeFP+ZaL1tBvLFHrA8=
github.com/flashcatcloud/go-flashduty v0.16.0/go.mod h1:YpHiTYXR5NXBI/rGRZfUy537XMkhdCkwA8NW1QoRHwk=
github.com/flashcatcloud/go-flashduty v0.16.1 h1:CzEa53FYKaHI3lpbqnXcdCj5km5SZhH14xDg1OAZvt0=
github.com/flashcatcloud/go-flashduty v0.16.1/go.mod h1:YpHiTYXR5NXBI/rGRZfUy537XMkhdCkwA8NW1QoRHwk=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-runewidth v0.0.30 h1:+KUuiDA4fF0R1p5FeueHefjDm+GIM+kWfFnDjybOPgk=
Expand Down
17 changes: 16 additions & 1 deletion internal/cli/safari_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ The message is sent on the CLI channel (reply-only delivery): the agent answers
through its reply tool and the answers are read with 'safari watch'. If the
server does not accept that channel, the command fails instead of falling back.

Sent to a session whose turn is still running, the message is taken into that
turn at its next step instead of waiting for the turn to finish, and the
running turn answers it.

Follow the answer with:
flashduty safari watch --session-id <session_id> --root-invocation-id <root_invocation_id>

API: POST /safari/session/message, POST /safari/attachment/upload`,
API: POST /safari/session/message, POST /safari/session/get, POST /safari/attachment/upload`,
Example: ` flashduty safari send "why is checkout latency up?"
flashduty safari send --session-id sess_01 --file trace.json "does this match?"
cat question.md | flashduty safari send --team-id 42 --env-kind byoc`,
Expand Down Expand Up @@ -178,6 +182,17 @@ API: POST /safari/session/message, POST /safari/attachment/upload`,
req.EntryKind = safariEntryKind
}

if sessionID != "" {
// A message sent while a turn runs joins that turn at its
// next step instead of waiting for a turn of its own; an
// idle session runs it as an ordinary turn.
info, _, err := ctx.Client.Sessions.ReadInfo(cctx, &flashduty.SessionGetRequest{SessionID: sessionID, Limit: 1})
if err != nil {
return err
}
req.Steering = info.Session.TurnInFlight
}

ack, _, err := ctx.Client.Sessions.WriteMessage(cctx, req)
if err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions internal/cli/safari_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type sendServer struct {
uploadBody string
ackMode string
createCalled map[string]any
turnInFlight bool
}

func newSendServer(t *testing.T, ackMode string) *sendServer {
Expand All @@ -49,6 +50,10 @@ func newSendServer(t *testing.T, ackMode string) *sendServer {
b, _ := io.ReadAll(f)
s.uploadName, s.uploadBody = hdr.Filename, string(b)
reply(map[string]any{"object_key": "attachments/a1/" + hdr.Filename, "mime": "text/plain", "filename": hdr.Filename, "size": len(b), "attachment_id": "a1"})
case "/safari/session/get":
reply(map[string]any{"events": []any{}, "pending_messages": []any{}, "session": map[string]any{
"session_id": "sess-7", "is_running": s.turnInFlight, "turn_in_flight": s.turnInFlight,
}})
case "/safari/session/message":
_ = json.NewDecoder(r.Body).Decode(&s.message)
sid, _ := s.message["session_id"].(string)
Expand Down Expand Up @@ -115,6 +120,25 @@ func TestSafariSendExistingSessionOmitsNewSessionFields(t *testing.T) {
}
}

func TestSafariSendSteersOnlyIntoARunningTurn(t *testing.T) {
for _, running := range []bool{true, false} {
t.Run(map[bool]string{true: "running", false: "idle"}[running], func(t *testing.T) {
saveAndResetGlobals(t)
s := newSendServer(t, "reply_only")
s.turnInFlight = running
if _, err := execCommand("safari", "send", "--session-id", "sess-7", "and the db?"); err != nil {
t.Fatalf("send: %v", err)
}
if strings.Join(s.paths, ",") != "/safari/session/get,/safari/session/message" {
t.Errorf("calls = %v", s.paths)
}
if got, _ := s.message["steering"].(bool); got != running {
t.Errorf("steering = %v, want %v (body %v)", s.message["steering"], running, s.message)
}
})
}
}

func TestSafariSendFilesCreateSessionThenUploadThenMessage(t *testing.T) {
saveAndResetGlobals(t)
s := newSendServer(t, "reply_only")
Expand Down
Loading
Loading