Skip to content
Open
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
14 changes: 14 additions & 0 deletions docs/agent-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Or copy the folders in `skills/` to `~/.claude/skills/` for Claude Code (`$CLAUD
| `jun tool send <id> <text>` / `jun tool send <id> -` | Submits the text to the agent in the terminal, or holds it while the user is typing there. Prints nothing, `sent, not started yet` or `held: …`. |
| `jun tool message [--title <title>] [--kind <kind>] [--link <resource>] <text>`, or `-` for the text | Shows the text to the user, in [Messages](agents-view.md#messages). Prints the message's id. |
| `jun tool message update <id> [--kind <kind>] [--task <id>] [<text>]`, or `-` for the text | Changes the message's kind or task, adds a reply, or any of them. Prints nothing. |
| `jun tool message delete <id>` | Takes the message out, as one sent by mistake. Prints nothing. |
| `jun tool message` | The messages, as a JSON array, the latest first |
| `jun tool goal [--all \| --state <state>…] [--match <text>]` / `goal <id>` | The [goals](#goal-and-task), as a JSON array, each followed by those under it / a goal with those above it and its tasks |
| `jun tool goal add …` / `goal update <id> …` / `goal delete <id>` | Adds a goal and prints its id / changes it / takes it out. The others print nothing. |
Expand Down Expand Up @@ -235,6 +236,19 @@ Opening another terminal gives it the focus, so you are then with that terminal:
- **Who may update**: any terminal of Jun, whoever sent the message. Outside Jun's terminals it is refused.
- **A message that does not exist** is status 1, as is one Jun no longer keeps.

#### Deleting a message

`message delete` takes a message out of Messages, for one sent by mistake or by a loop gone wrong. The user can do the same in [Messages](agents-view.md#messages).

```sh
"$JUN_BIN" tool message delete 12
```

- **A matter handled is no mistake**: make its message `done`, for the user to read, rather than deleting it.
- **Its number** is not given again: the next message still gets the next number, and `update` or `delete` of `12` is then status 1, as for a message that does not exist.
- **Only the message goes**: the terminal, Diff, file or project it links to stays as it was, and so does its task.
- **Who may delete**: any terminal of Jun, whoever sent the message. Outside Jun's terminals it is refused.

#### Reading messages back

`message` with nothing after it lists them, for instance to find what still waits for the user:
Expand Down
1 change: 1 addition & 0 deletions docs/agents-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The **Agents** view, in Global, shows every coding agent running in Jun's termin
- A long text shows four lines and a message its last three replies. **Show more** opens it where it is, and **Show less** folds it.
- Messages, like Agents and Tasks, keep the size of Jun's own text, whatever the [text size](shortcuts.md#text-size) of terminals.
- **Tab** from the title of Messages, past its ⋯ if it has one, reaches the list: **↑** and **↓** move through it, **↩** acts as a click, and **→** and **←** open and fold a long text.
- **Delete** in a message's context menu, or **⌫** on the row chosen, takes the message out at once, with no question: a message lasts only until Jun quits anyway. The choice goes to the message below, or above for the last one. What it links to stays, and its number is not given again. Agents delete one with [`jun tool message delete`](agent-tools.md#deleting-a-message).
- Messages last until Jun quits. It keeps the last 500.

Global shows its views together, without tabs:
Expand Down
27 changes: 27 additions & 0 deletions internal/app/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,33 @@ func (a *app) toolUpdateMessage(req tool.Request, callers []int) error {
return nil
}

// toolDeleteMessage takes a message out, as the user does in Messages.
func (a *app) toolDeleteMessage(req tool.Request, callers []int) error {
if _, err := a.toolCaller(callers, req.Caller); err != nil {
return err
}
if !a.deleteMessage(req.Message) {
return fmt.Errorf("no message %d", req.Message)
}
return nil
}

// deleteMessage takes the message out, and reports whether there was one.
// Its number stays used. Its row chosen, the choice goes to the next older
// row, or the newer one past the last; the list follows any other.
func (a *app) deleteMessage(id uint64) bool {
i := slices.IndexFunc(a.messages, func(m message) bool { return m.ID == id })
if i < 0 {
return false
}
row := len(a.messages) - 1 - i
a.messages = slices.Delete(a.messages, i, i+1)
if row == a.messageSelected {
a.messagesList.Choose(min(row, len(a.messages)-1))
}
return true
}

// checkTask tells whether the task a message is about is there: none is.
func (a *app) checkTask(id int) error {
if _, ok := a.goals.Task(id); id != 0 && !ok {
Expand Down
83 changes: 83 additions & 0 deletions internal/app/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,89 @@ func TestARefusedUpdateChangesNothing(t *testing.T) {
}
}

func deleteMessage(a *app, from []int, id uint64) tool.Response {
return a.uiAnswers(tool.Request{Op: tool.OpDeleteMessage, Message: id}, from)[tool.OpDeleteMessage]()
}

func TestAMessageSentByMistakeGoes(t *testing.T) {
a, _, sessions := agentsApp(t)
shell := shellOf(t, sessions[0])
say(t, a, sessions[0], "Oldest")
mistake := say(t, a, sessions[0], "By mistake").Created
say(t, a, sessions[0], "Newest")
if resp := deleteMessage(a, nil, mistake); !strings.HasPrefix(resp.Error, "caller is not a terminal of this Jun") {
t.Fatalf("from outside Jun: %q", resp.Error)
}
if resp := deleteMessage(a, shell, mistake); resp.Error != "" {
t.Fatal(resp.Error)
}
if got := messageTexts(a); !slices.Equal(got, []string{"Newest", "Oldest"}) {
t.Fatalf("rows %v", got)
}
gone := fmt.Sprintf("no message %d", mistake)
if resp := deleteMessage(a, shell, mistake); resp.Error != gone {
t.Fatalf("deleted twice: %q", resp.Error)
}
if resp := update(t, a, sessions[0], tool.Request{Message: mistake, Text: "x"}); resp.Error != gone {
t.Fatalf("updated once gone: %q", resp.Error)
}
if id := say(t, a, sessions[0], "Next").Created; id != mistake+2 {
t.Fatalf("the next message is M%d", id)
}
}

// The menu and ⌫ take a message out; the choice goes to the next older
// row, or the newer one past the last, and stays with a message that
// stays.
func TestTheUserDeletesAMessage(t *testing.T) {
a, tt, sessions := agentsApp(t)
a.state.GlobalVisible = true
for _, text := range []string{"Oldest", "Older", "Middle", "Newer", "Newest"} {
say(t, a, sessions[0], text)
}
tt.Frame()
if err := tt.RightClick("Newer"); err != nil {
t.Fatal(err)
}
if err := tt.ChooseMenuItem("Delete"); err != nil {
t.Fatalf("%v in %q", err, tt.Menu())
}
tt.Frame()
if got := messageTexts(a); !slices.Equal(got, []string{"Newest", "Middle", "Older", "Oldest"}) {
t.Fatalf("rows %v", got)
}
a.focusRegion(a.state.Global.ID)
tt.Frame()
tt.Key(ui.Super, ui.Key3)
tt.Frame()
tt.Key(0, ui.KeyTab)
tt.Frame()
for range 2 {
tt.Key(0, ui.KeyDown)
tt.Frame()
}
tt.Key(0, ui.KeyBackspace)
tt.Frame()
if got := messageTexts(a); !slices.Equal(got, []string{"Newest", "Older", "Oldest"}) || a.messageSelected != 1 {
t.Fatalf("rows %v, row %d chosen", got, a.messageSelected)
}
shell := shellOf(t, sessions[0])
if resp := deleteMessage(a, shell, a.messages[len(a.messages)-1].ID); resp.Error != "" {
t.Fatal(resp.Error)
}
tt.Frame()
if got := messageTexts(a); !slices.Equal(got, []string{"Older", "Oldest"}) || a.messageSelected != 0 {
t.Fatalf("the choice left its message: row %d", a.messageSelected)
}
tt.Key(0, ui.KeyDown)
tt.Frame()
tt.Key(0, ui.KeyDelete)
tt.Frame()
if got := messageTexts(a); !slices.Equal(got, []string{"Older"}) || a.messageSelected != 0 {
t.Fatalf("past the last: rows %v, row %d chosen", got, a.messageSelected)
}
}

func TestAMessageKeepsItsLatestReplies(t *testing.T) {
a, _, sessions := agentsApp(t)
id := say(t, a, sessions[0], "Busy").Created
Expand Down
34 changes: 26 additions & 8 deletions internal/app/messages_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (a *app) messagesView(c *ui.Context) {
}

// messageList keeps the keyboard on the list: its rows take no focus, so
// ↩, → and ← always act on the row chosen, which a click chooses too.
// ↩, →, ← and ⌫ always act on the row chosen, which a click chooses too.
// A message goes once the list is built, whose rows it would move.
func (a *app) messageList(c *ui.Context) {
at := func(row int) message { return a.messages[len(a.messages)-1-row] }
st := &a.messagesList
Expand All @@ -53,16 +54,26 @@ func (a *app) messageList(c *ui.Context) {
st.KeepOffset = first == 0 // the latest shows as it comes; scrolled away, the rows stay
st.Label = func(row int) string { return at(row).name() }
now := time.Now()
clicked := false
clicked, deleted := false, uint64(0)
list := ui.List(c, st, len(a.messages), func(row int) {
if a.messageRow(c, at(row), now, row == a.messageSelected) {
m := at(row)
click, remove := a.messageRow(c, m, now, row == a.messageSelected)
if click {
a.messageSelected, clicked = row, true
}
if remove {
deleted = m.ID
}
}).Gap(8).Dividers(1, a.theme.Border).Grow(1).FillWidth()
if clicked {
list.Focus()
c.Invalidate()
}
if deleted != 0 {
a.deleteMessage(deleted)
c.Invalidate()
return
}
chosen := a.messageSelected
if chosen < 0 || chosen >= len(a.messages) {
return
Expand All @@ -80,10 +91,15 @@ func (a *app) messageList(c *ui.Context) {
a.setMessageWhole(m.ID, false)
c.Invalidate()
}
if list.Shortcut(0, ui.KeyBackspace) || list.Shortcut(0, ui.KeyDelete) {
a.deleteMessage(m.ID)
c.Invalidate()
}
}

// messageRow reports a click on the row or on its fold control.
func (a *app) messageRow(c *ui.Context, m message, now time.Time, chosen bool) (clicked bool) {
// messageRow reports a click on the row or on its fold control, and Delete
// chosen in its menu.
func (a *app) messageRow(c *ui.Context, m message, now time.Time, chosen bool) (clicked, deleted bool) {
width, size := a.messagesWidth-2*(messagePadding+messageBorder), a.messageSize()
textWidth := width
if m.Title == "" {
Expand All @@ -95,7 +111,9 @@ func (a *app) messageRow(c *ui.Context, m message, now time.Time, chosen bool) (
if m.Link != nil && m.Link.Kind == tool.TargetTerminal && terminal.ID(m.Link.ID) == a.peek.id {
border = a.theme.Accent
}
row := ui.Column(c).FillWidth().Gap(4).Padding(6, messagePadding).Radius(6).Border(messageBorder, border)
row := ui.Column(c).FillWidth().Gap(4).Padding(6, messagePadding).Radius(6).Border(messageBorder, border).ContextMenu(func(menu *ui.Menu) {
deleted = menu.Item(a.text("Delete", "删除")).Chosen()
})
if m.Task != 0 && m.Task == a.selectedTask {
row.Background(a.taskTint())
}
Expand All @@ -121,9 +139,9 @@ func (a *app) messageRow(c *ui.Context, m message, now time.Time, chosen bool) (
}
if live && row.Clicked() {
a.openMessage(m, row.ClickModifiers()&ui.Super != 0)
return true
return true, deleted
}
return clicked
return clicked, deleted
}

// messageFoot closes the row with its tag, fold control and age, and
Expand Down
1 change: 1 addition & 0 deletions internal/app/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func (a *app) uiAnswers(req tool.Request, callers []int) map[tool.Op]func() tool
},
tool.OpMessages: func() tool.Response { return tool.Response{Messages: a.toolMessages()} },
tool.OpUpdateMessage: func() tool.Response { return outcome(a.toolUpdateMessage(req, callers)) },
tool.OpDeleteMessage: func() tool.Response { return outcome(a.toolDeleteMessage(req, callers)) },
tool.OpRun: func() tool.Response { return started(a.toolRun(req, callers)) },
tool.OpLoop: func() tool.Response { return started(a.toolLoop(req, callers)) },
tool.OpLoops: func() tool.Response { return tool.Response{Loops: a.toolLoops()} },
Expand Down
7 changes: 6 additions & 1 deletion internal/tool/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const usage = "usage: jun tool help | terminals | watch |\n" +
" terminals update <id> [--name <name>] [--every <every>] [--at <HH:MM>] [--text <text>] [--no-timer] |\n" +
" screen <id> [--lines N] | open <target> [--in <perspective>] [--peek] | close <target> | back | forward |\n" +
" send <id> <text> | send <id> - | message [--title <title>] [--kind <kind>] [--link <resource>] [<text|->] |\n" +
" message | message update <id> [--kind <kind>] [--task <id>] [<text|->] |\n" +
" message | message update <id> [--kind <kind>] [--task <id>] [<text|->] | message delete <id> |\n" +
" goal [--all | --state <state>…] [--match <text>] | goal <id> | goal add … <title> | goal update <id> … | goal delete <id> |\n" +
" task [--all | --state <state>…] [--owner <role>] [--project <name>] [--goal <id>] [--match <text>] |\n" +
" task <id> | task add --goal <id> … <title> | task update <id> … | task delete <id> |\n" +
Expand Down Expand Up @@ -177,6 +177,11 @@ Sending:
it, or any of them: ask becoming done tells the user it is handled. A reply moves
the message to the top; a message keeps its last 50. Any terminal
may, whoever sent it. No such message is status 1. Prints nothing.
jun tool message delete <id>
Takes the message out, for one sent by mistake. A matter handled
is no mistake: make its message done, for the user to read. Its
number is not given again. Any terminal may, whoever sent it. No
such message is status 1. Prints nothing.
jun tool message
The messages, the latest first, as a JSON array: id, time, kind,
title, text, project, link, as --link takes it, task, and replies,
Expand Down
7 changes: 7 additions & 0 deletions internal/tool/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ func parseMessage(args []string, stdin io.Reader) (Request, error) {
if args[0] == "update" && len(args) > 1 {
return parseUpdateMessage(args[1:], stdin)
}
if args[0] == "delete" && len(args) > 1 {
id, err := strconv.ParseUint(args[1], 10, 64)
if err != nil || id == 0 || len(args) > 2 {
return Request{}, errors.New("message delete takes one id, a positive integer")
}
return Request{Op: OpDeleteMessage, Message: id}, nil
}
req := Request{Op: OpMessage}
flags := map[string]func(string) error{
"--title": func(title string) error {
Expand Down
4 changes: 3 additions & 1 deletion internal/tool/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
// OpUpdateMessage adds a reply to the message of Request.Message, or
// changes its kind, or both.
OpUpdateMessage Op = "update-message"
OpDeleteMessage Op = "delete-message" // takes out the message of Request.Message
OpRun Op = "run"
OpLoop Op = "loop" // registers one
OpLoops Op = "loops" // lists them
Expand Down Expand Up @@ -269,7 +270,8 @@ type Request struct {
Text string `json:"text,omitempty"` // send: to submit, its line breaks kept; message: to show; update-terminal: the timer's
Title string `json:"title,omitempty"` // message
Kind MessageKind `json:"kind,omitempty"` // message, none being MessageInfo; update-message, none leaving it
// Message is the ID of the message update-message changes.
// Message is the ID of the message update-message changes, or
// delete-message takes out.
Message uint64 `json:"message,omitempty"`
// Command is the shell command line run and loop run, in Dir, an
// absolute path.
Expand Down
8 changes: 8 additions & 0 deletions internal/tool/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestMainUsage(t *testing.T) {
{"roles", "--open", "x"}, {"roles", "--team"}, {"roles", "--team", "a", "b"}, {"roles", "--team", "42"},
{"join"}, {"join", "0"}, {"join", "x"}, {"join", "1", "2"}, {"leave", "1"},
{"message", "--task", "0", "hi"}, {"message", "update", "3", "--task", "x"},
{"message", "delete", "0"}, {"message", "delete", "x"}, {"message", "delete", "7", "8"},
{"goal", "0"}, {"goal", "x"}, {"goal", "--all", "--state", "open"}, {"goal", "--state", "later"}, {"goal", "--owner", "a"},
{"goal", "add"}, {"task", "update"}, {"goal", "add", "x"}, {"goal", "add", "--outcome", "o"}, {"goal", "add", "--outcome", "o", "a", "b"}, {"goal", "add", "--goal", "1", "--outcome", "o", "x"},
{"goal", "add", "--outcome", "a\nb", "x"}, {"goal", "add", "--outcome", "o", "--link", "terminal:3", "x"}, {"goal", "add", "--outcome", "o", "--parent", "-1", "x"},
Expand Down Expand Up @@ -324,6 +325,12 @@ func TestToolsAnswerOverTheSocket(t *testing.T) {
if code, _, _ := run(path, "message", "update"); code != 0 {
t.Fatalf("the one word update is a text: %d", code)
}
if code, out, _ := run(path, "message", "delete", "7"); code != 0 || out != "" {
t.Fatalf("delete: %d %q", code, out)
}
if code, _, _ := run(path, "message", "delete"); code != 0 {
t.Fatalf("the one word delete is a text: %d", code)
}
if code, _, _ := run(path, "message", "--title", "Done"); code != 0 {
t.Fatalf("message with a title alone: %d", code)
}
Expand Down Expand Up @@ -399,6 +406,7 @@ func TestToolsAnswerOverTheSocket(t *testing.T) {
{Op: OpMessage, Title: "Asks", Kind: MessageAsk, Target: &Target{Kind: TargetTerminal, ID: 3}, Text: "It waits"},
{Op: OpMessages}, {Op: OpUpdateMessage, Message: 7, Kind: MessageDone, Text: "Answered"}, {Op: OpUpdateMessage, Message: 7, Kind: MessageDone},
{Op: OpUpdateMessage, Message: 7, Text: "a\nb"}, {Op: OpMessage, Text: "update"},
{Op: OpDeleteMessage, Message: 7}, {Op: OpMessage, Text: "delete"},
{Op: OpMessage, Title: "Done"}, {Op: OpMessage, Text: "-- deploy failed"}, {Op: OpMessage, Title: "Quiet"}, {Op: OpMessage, Text: "a\nb"},
{Op: OpRun, Command: "codex --full-auto", Dir: here, Open: true},
{Op: OpRun, Command: "codex", Project: "Web"}, {Op: OpRun, Command: "codex", Project: "web", Dir: filepath.Join(here, "sub")},
Expand Down
4 changes: 3 additions & 1 deletion skills/jun-tools/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ When a command fails, its error says what to do next: follow it.
| `back` / `forward` | Steps through where the user has been |
| `message [--title <t>] [--kind ask\|warn\|done\|info] [--link <resource>] <text>` / `… -` | Tells the user, in Messages in Global, without disturbing them, and prints the message's id; `-` reads standard input, and with a title the text may go |
| `message update <id> [--kind <kind>] [--task <id>] [<text>]` / `… -` | Changes the message's kind or task, adds the text as a reply, or any of them |
| `message delete <id>` | Takes the message out of Messages, for one sent by mistake; its number is not given again |
| `message` | The messages as JSON, the latest first: `id`, `time`, `kind`, `title`, `text`, `project`, `link`, `task`, `replies` |
| `goal [--all \| --state <state>…] [--match <text>]` / `goal <id>` | The user's goals as JSON, each followed by those under it / a goal with those above it and its tasks |
| `goal add [--parent <id>] --outcome <outcome> [--due <date>] [--period <period>] [--link <resource>] [--text <text>\|-] <title>` | Adds a goal; prints its id |
Expand Down Expand Up @@ -174,11 +175,12 @@ Give `--link` whenever the message is about something: without it, the message i
printf '%s\n' "$long_message" | "$JUN_BIN" tool message --link "file:report.md" -
```

**Follow a message up.** `message` prints the id; the user sees `12` as `M12`, and may call it that. A message is one matter: `ask` means the user has something to do, so when they have done it, make it `done`. Add what happens next as replies, rather than new messages. A reply moves the message to the top. Any terminal may update any message.
**Follow a message up.** `message` prints the id; the user sees `12` as `M12`, and may call it that. A message is one matter: `ask` means the user has something to do, so when they have done it, make it `done`. Add what happens next as replies, rather than new messages. A reply moves the message to the top. Any terminal may update any message. Delete only one sent by mistake, such as a wrong link or a loop that repeated itself; a matter handled stays, as `done`, for the user to read. A deleted message's number is not given again.

```sh
"$JUN_BIN" tool message update 12 --kind done 'You agreed; it goes on.'
"$JUN_BIN" tool message update 12 'PR #53 is open, the tests pass.'
"$JUN_BIN" tool message delete 13 # sent by mistake
"$JUN_BIN" tool message | jq -c '.[] | select(.kind == "ask")' # what still waits for the user
```

Expand Down