feat: a green check confirms a send and info notices fade after 3 s

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-20 10:06:17 +01:00
1 parent 0fad0a2e4e
commit 56be86391b
5 files changed
+126 -15

No files matched your search

@@ -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
@@ -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()
@@ -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";
}