diff --git a/herdr/herdr-composer/RECIPE.md b/herdr/herdr-composer/RECIPE.md index 5961596..3174b8f 100644 --- a/herdr/herdr-composer/RECIPE.md +++ b/herdr/herdr-composer/RECIPE.md @@ -68,7 +68,7 @@ panel and otherwise, with an empty field and a working agent, stops the agent (`hc interrupt`; the queue is held and nothing goes out on its own). Up/Down/Tab move and accept in the suggestion menu; without a menu Up/Down move the cursor between lines. -**Sending.** Idle or done: out at once ("Wysłano do terminala."). Blocked: out at once with +**Sending.** Idle or done: out at once (a green check on the send button for 1.5 s). Blocked: out at once with `--force` (an answer), ahead of the queue. Working: into the queue ("Następna tura"). When the turn ends (working or blocked, then idle or done) the first queued message counts down "Wysyłam za 3 s" (button "Anuluj" holds it) and goes out; the next waits for the diff --git a/herdr/herdr-composer/mods/herdr-composer/delivery.js b/herdr/herdr-composer/mods/herdr-composer/delivery.js index 52fb572..331280c 100644 --- a/herdr/herdr-composer/mods/herdr-composer/delivery.js +++ b/herdr/herdr-composer/mods/herdr-composer/delivery.js @@ -13,7 +13,7 @@ // for a plain shell with no agent, and also when it fails. Neither the exit // code nor those fields say whether the agent got the message. Therefore: // - ok:true means "the text was pasted and Enter pressed", NOT "the agent -// received it" - the UI says "Wysłano do terminala"; +// received it" - the UI shows a green check on the send button; // - the only failure is a non-zero exit code (its stderr becomes the notice); // - every `--json` call checks the payload for an "error" field, because `hc` // exits 0 even on error (measured: `hc wait t3 --json` for a missing diff --git a/herdr/herdr-composer/mods/herdr-composer/main.js b/herdr/herdr-composer/mods/herdr-composer/main.js index 802fd0d..d22e46d 100644 --- a/herdr/herdr-composer/mods/herdr-composer/main.js +++ b/herdr/herdr-composer/mods/herdr-composer/main.js @@ -20,8 +20,8 @@ // an empty field (`hc interrupt`). // // `hc send` does not confirm a delivery - it pastes the text and presses -// Enter. The composer says "Wysłano do terminala" and takes the confirmation -// from the agent's status. +// Enter. The composer shows a green check on the send button for a moment and +// takes the confirmation from the agent's status. import { View, div, image } from "gpui-kit"; import { v_flex, h_flex, TextareaState, Textarea, InputState, Input, Popover, ScrollHandle, VirtualListScrollHandle } from "gpui-base"; @@ -122,6 +122,9 @@ import { isManualResize, statusText, targetAgent, + noticeExpired, + SENT_MS, + NOTICE_MS, } from "./view.js"; /** The placeholder of the field. */ @@ -188,6 +191,13 @@ export default class Composer extends View { this.draftLoading = new Set(); this.draftTimer = null; + // The green check on the send button after a send (until `sentUntil`, ms + // since the epoch) and the timers that redraw the composer when it is over + // (`sentTimer`) and that clear an `info` notice (`noticeTimer`). + this.sentUntil = 0; + this.sentTimer = null; + this.noticeTimer = null; + // Attachments: the message that waits for the answer to "this agent may // not take images" (null when nothing waits), and whether the file dialog // is open. @@ -1080,7 +1090,7 @@ export default class Composer extends View { this.closePanel(); this.textarea.replace(hit.item.text); this.syncFieldAfterReplace(); - this.notice("Wstawiono w miejscu kursora — nic nie zostało wysłane."); + this.notice("Wstawiono w miejscu kursora — nic nie zostało wysłane.", "info", cx); cx.notify(); } @@ -1725,9 +1735,10 @@ export default class Composer extends View { ? "Wiadomość wstrzymana — czeka na „Wyślij teraz”." : "Agent czeka na Ciebie — wiadomość czeka na „Wyślij teraz”.", mode === "hold" ? undefined : "error", + cx, ); } else { - this.notice("Wiadomość w kolejce — następna tura."); + this.notice("Wiadomość w kolejce — następna tura.", "info", cx); } cx.notify(); } @@ -1765,7 +1776,7 @@ export default class Composer extends View { this.state = reduce(this.state, { type: "settle", agent: key, id, outcome: "sent" }); this.persistQueue(key); this.gates.set(key, closeGate(this.gateFor(key))); - this.notice("Wysłano do terminala."); + this.flashSent(cx); } else { this.state = reduce(this.state, { type: "settle", @@ -1960,7 +1971,7 @@ export default class Composer extends View { if (result.sent > 0) { this.gates.set(key, closeGate(this.gateFor(key))); - this.notice("Wysłano do terminala."); + this.flashSent(cx); } else if (claimed && !sent) { this.notice("Wiadomość nie poszła do terminala.", "error"); } @@ -1969,7 +1980,7 @@ export default class Composer extends View { // the entry left the queue, so it is sent. const outcome = claimed ? failedHookOutcome(this.state.queue[key], claimed) : "uncertain"; if (outcome === "sent") { - this.notice("Wysłano do terminala."); + this.flashSent(cx); } else { if (claimed) { this.state = reduce(this.state, { @@ -2031,7 +2042,7 @@ export default class Composer extends View { this.persistQueue(key); // The gate closes again: the next message waits for the next turn. this.gates.set(key, closeGate(this.gateFor(key))); - this.notice("Wysłano do terminala."); + this.flashSent(cx); } else { this.state = reduce(this.state, { type: "settle", @@ -2193,7 +2204,7 @@ export default class Composer extends View { this.state = reduce(this.state, { type: "hold_all", agent: key }); this.gates.set(key, closeGate(this.gateFor(key))); this.persistQueue(key); - this.notice("Przerwano agenta. Kolejka wstrzymana — nic nie wyśle się samo."); + this.notice("Przerwano agenta. Kolejka wstrzymana — nic nie wyśle się samo.", "info", cx); cx.notify(); cx.spawn(async (cx) => { @@ -2705,13 +2716,52 @@ export default class Composer extends View { // Levels: "info"; "problem" - red in the composer, no toast (what the // person did: an empty text, a duplicate file); "error" - red and a toast // (a send or an `hc` call that failed). - this.state = reduce(this.state, { type: "notice", notice: { text, level } }); + const notice = { text, level }; + this.state = reduce(this.state, { type: "notice", notice }); if (level === "error") { notify({ title: "Composer", body: text, level: "error" }); } + + // An `info` notice fades after NOTICE_MS. The timer clears only the notice + // it was set for (noticeExpired): a later one is left alone. Without a + // `cx` there is no timer - that notice stays until the next one. + if (this.noticeTimer) { + this.noticeTimer.cancel(); + this.noticeTimer = null; + } + if (level === "info" && cx) { + this.noticeTimer = cx.timer.after(NOTICE_MS, (cx) => { + this.noticeTimer = null; + if (noticeExpired(this.state.notice, notice)) { + this.state = reduce(this.state, { type: "notice", notice: null }); + cx.notify(); + } + }); + } cx?.notify(); } + /** + * A message went to the terminal: the send button shows a green check for + * SENT_MS (a second send renews it) and the old `info` notice is cleared. + */ + flashSent(cx) { + this.sentUntil = Date.now() + SENT_MS; + if (this.sentTimer) { + this.sentTimer.cancel(); + this.sentTimer = null; + } + this.sentTimer = cx.timer.after(SENT_MS, (cx) => { + this.sentTimer = null; + cx.notify(); + }); + + if (this.state.notice?.level === "info") { + this.state = reduce(this.state, { type: "notice", notice: null }); + } + cx.notify(); + } + /** An id of its own - the queue and the attachments count on it. */ newId() { this.counter += 1; @@ -3166,7 +3216,13 @@ export default class Composer extends View { .child(div().w(1).h(18).flex_none().bg(t.border)) .child(this.renderDock(t, active)) .child(this.renderChip(t, agent, status, files.length)) - .child(stop ? this.renderStop(t, agent) : this.renderSend(t, agent, over)), + .child( + Date.now() < this.sentUntil + ? this.renderSent(t) + : stop + ? this.renderStop(t, agent) + : this.renderSend(t, agent, over), + ), ].filter(Boolean), ); } @@ -3268,7 +3324,7 @@ export default class Composer extends View { if (action === "insert") { this.textarea.replace(button.text); this.syncFieldAfterReplace(); - this.notice("Wstawiono w miejscu kursora — nic nie zostało wysłane."); + this.notice("Wstawiono w miejscu kursora — nic nie zostało wysłane.", "info", cx); cx.notify(); return; } @@ -3505,6 +3561,19 @@ export default class Composer extends View { ); } + /** The green check that confirms a send; it takes the place of the button for a moment. */ + renderSent(t) { + return div() + .id("composer-sent") + .size(32) + .rounded(999) + .bg(t.done) + .flex() + .items_center() + .justify_center() + .child(div().text_size(13).font_semibold().text_color(t.solid_foreground).child("✓")); + } + /** The button that stops the agent. */ renderStop(t, agent) { return div() diff --git a/herdr/herdr-composer/mods/herdr-composer/view.js b/herdr/herdr-composer/mods/herdr-composer/view.js index 748e57c..3098c7e 100644 --- a/herdr/herdr-composer/mods/herdr-composer/view.js +++ b/herdr/herdr-composer/mods/herdr-composer/view.js @@ -609,3 +609,23 @@ export function fieldBackground(theme, panelBackground) { } return best ?? panelBackground; } + +/** How long the green check stays on the send button after a send, ms. */ +export const SENT_MS = 1500; + +/** How long an `info` notice stays under the card, ms. */ +export const NOTICE_MS = 3000; + +/** + * Is it time to clear the notice? Only the very notice the timer was set for, + * and only an `info` one: another notice that came in the meantime (even with + * the same text) is none of this timer's business, and a `problem` or an + * `error` stays until something replaces it. + * + * @param {{level?:string}|null} current - the notice of the state now + * @param {{level?:string}} scheduled - the notice the timer was set for + * @returns {boolean} + */ +export function noticeExpired(current, scheduled) { + return current !== null && current === scheduled && scheduled.level === "info"; +} diff --git a/tests/view.test.mjs b/tests/view.test.mjs index 7f15b76..4aa07cf 100644 --- a/tests/view.test.mjs +++ b/tests/view.test.mjs @@ -2,7 +2,7 @@ import test from "node:test"; import assert from "node:assert/strict"; import { targetAgent, agentKey, agentName, agentStatus, createGate, gatePasses, openGate, closeGate, - isPlainEnter, statusText, queueLabel, applySuggestion, insertedNewline, + isPlainEnter, statusText, queueLabel, applySuggestion, insertedNewline, noticeExpired, } from "../herdr/herdr-composer/mods/herdr-composer/view.js"; const agents = [{ address: "t1", app: "claude-code" }, { address: "a2" }]; @@ -165,3 +165,25 @@ test("fieldBackground: the darkest color the theme has, darker than the panel", assert.equal(fieldBackground({}, "#2a2c31"), "#2a2c31"); assert.equal(fieldBackground({ background: "nope" }, "#2a2c31"), "#2a2c31"); }); + +test("noticeExpired: the same info notice expires", () => { + const info = { text: "a", level: "info" }; + assert.equal(noticeExpired(info, info), true); +}); + +test("noticeExpired: another notice with the same text is not touched", () => { + const scheduled = { text: "a", level: "info" }; + assert.equal(noticeExpired({ text: "a", level: "info" }, scheduled), false); +}); + +test("noticeExpired: a problem or an error stays, and so does an info that was replaced by one", () => { + const problem = { text: "b", level: "problem" }; + const error = { text: "c", level: "error" }; + assert.equal(noticeExpired(problem, problem), false); + assert.equal(noticeExpired(error, error), false); + assert.equal(noticeExpired(problem, { text: "a", level: "info" }), false); +}); + +test("noticeExpired: no current notice is nothing to clear", () => { + assert.equal(noticeExpired(null, { text: "a", level: "info" }), false); +});