Compare commits

...
10 Commits
Author SHA1 Message Date
FactorandOvis Fast 75025c2406 feat: close button in the history panel header
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:35:50 +01:00
FactorandOvis Fast 02d579c8b8 feat: search field of the history panel stands out (recess, focus border, magnifier)
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:34:00 +01:00
FactorandClaude Opus 5.5 44521e478d docs: final report reflects auto-fit composer height
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 12:24:11 +01:00
FactorandOvis Fast 406f00f0e4 feat: composer block fits its content, keeps a height the person dragged to
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:23:06 +01:00
FactorandClaude Opus 5.5 360d93f589 docs: final report update after post-review fixes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 12:20:35 +01:00
FactorandOvis Fast 568db3d02d fix: composer content sits at the bottom edge of its block
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:20:00 +01:00
FactorandOvis Fast e6afb3ebf9 fix: an answer to a blocked agent goes ahead of the queue
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:19:54 +01:00
FactorandClaude Opus 5.5 f3250e594e docs: final report for unified prompt
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-19 12:13:05 +01:00
FactorandOvis Fast d0dda5b670 chore: refresh stale comments, drop dead passKey
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:10:53 +01:00
FactorandOvis Fast dfe5101451 fix: validation messages stay in the composer, toast only for send/hc errors
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
2026-11-19 12:10:32 +01:00
9 changed files with 508 additions and 81 deletions

No files matched your search

@@ -0,0 +1,33 @@
# Herdr Unified Prompt Experience — raport końcowy (Ovis Opus)
Data: 2026-11-19 · Gałąź: `feature/unified-prompt` · Status: **PARTIALLY_APPROVED** (aktualizacja 2026-11-19: błąd nr 1 naprawiony w e6afb3e, composer przy dolnej krawędzi w 568db3d, blok dopasowany do treści w 406f00f)
## Zrealizowane (z dowodem)
| Funkcja | Dowód |
|---|---|
| Globalny composer w layoucie `ovis-composer`, jedna instancja, bez rekompilacji | `herdr-app status` → `errors: []`, zrzuty |
| Fokus tam, gdzie klik; `Ctrl+Shift+Space`; skróty tylko w `ovis-composer > Input` | GUI (Opus + użytkownik): Esc w oknie nazwy działa |
| Autouzupełnianie `/` `@` ze strzałkami | GUI: ↓↓ → `model` |
| Trwałe drafty per agent + kontrola tożsamości terminala (`created_ms`) | testy jednostkowe |
| Kolejka: odliczanie 3 s + Anuluj, Stop wstrzymuje, Ponów/Edytuj/Usuń, brak podwójnej wysyłki | testy jednostkowe, review |
| Historia + Ulubione (panel, wyszukiwanie z podświetleniem, wstawianie w kursor) | GUI: wpis `19.11 11:59 · herdrMario · Ovis Fast`, „kolor” podświetlone |
| Jeden potok załączników: Ctrl+V obrazu, Drag & Drop, „+” (PowerShell), limit 32 MiB fail-closed, Base64 do PowerShell | GUI: kafelek + miniatura |
| Obraz rzeczywiście dociera do agenta | GUI end-to-end: Claude Code przeczytał PNG i odpowiedział „Pomarańczowy.” |
| Testy | `npm test`: 143/143 |
## Niezależny review
Każde zadanie: review spec + jakość, rundy poprawek, re-review. Review całej gałęzi (Opus): „With fixes” → jedna fala poprawek (9/9 zaadresowane).
## Otwarte (świadomie nienaprawione)
1. ~~**Important:** odpowiedź do agenta `blocked`, gdy w kolejce są wpisy, trafia do kolejki zamiast iść od razu z `--force` (regresja z ostatniej fali). Poprawka jednoliniowa w `finish()`: `busy = draining || (mode !== "now" && status !== "blocked" && queueBlocksDirectSend(...))`. Obejście: Ctrl+Enter.~~ **Naprawione (e6afb3e), test `directSendBlocked`.**
2. Nie sprawdzone w GUI: odpowiedź na pytanie agenta w stanie `blocked`, Drag & Drop, dialog „+”, przełączanie agentów w trakcie pisania.
3. Drobne (lista w ledgerze): `addFiles` cicho porzuca pliki po zmianie agenta; `install.ps1` przerywa, gdy brak `herdr-app` w PATH. (Blok composera dopasowuje się do treści — naprawione w 406f00f.)
## Rekompilacja
Nie była potrzebna. Zmiany poza repo: junction `mods\ovis-composer`, `layouts\ovis-composer.json`, wpis `ctrl-shift-space` w `keys.json` (kopie `.bak-20261119`). Wycofanie: `scripts\install.ps1 -Uninstall`.
## Ryzyka utrzymania
- Herdr nie przeładowuje moda po zmianach za junction → `install.ps1 -Reload`.
- Aktualizacja Herdr może zmienić API modów → `herdr-app check` po aktualizacji.
- Ukrycie pola wpisywania w TUI agenta niemożliwe bez rekompilacji (decyzja A).
+1 -1
View File
@@ -160,7 +160,7 @@
"id": "composer",
"type": "block",
"size": {
"px": 260
"px": 150
},
"min": 120,
"max": 520,
+204 -76
View File
@@ -1,18 +1,23 @@
// main.js - the composer: the visible message bar under the terminal.
//
// The field, the queue above it, the suggestion menu, the attachments, the
// context strip and the agent chip. What needs no GPUI lives in view.js
// (tests/main.test.mjs); the state model is state.js, the sending is
// delivery.js, the suggestions are suggest.js and catalog.js, the limits are
// attachments.js and the persistence is storage.js.
// context strip and the agent pill. What needs no GPUI lives in view.js
// (tests/view.test.mjs); the state model is state.js, the sending is
// delivery.js, the suggestions are suggest.js and catalog.js, the limits and
// the clipboard are attachments.js and clipboard.js, the history is history.js
// (drawn by panel.js) and the persistence is storage.js.
//
// The composer talks to one agent at a time - the focused one. Everything that
// belongs to an agent (the draft, the queue, the attachments) is keyed by the
// agent's address, so switching agents never mixes two of them.
//
// The keyboard belongs to the composer: the terminal only shows. The field
// takes the keyboard back when it loses it, and the shortcuts that belong to
// the agent's own program (Ctrl+C, Esc) are passed on with `hc`.
// Focus follows the click: the composer never takes the keyboard on its own.
// The field has it after a click on it or after Ctrl+Shift+Space (the "focus"
// command); a click in a terminal gives the keys to that terminal. While the
// field has the keyboard its shortcuts (Enter, Ctrl+Enter, Alt+Enter, Esc,
// Ctrl+R, the arrows and Tab of the menu) are bound in the context
// `ovis-composer > Input`. The agent is stopped with the Stop button or Esc on
// 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
@@ -43,7 +48,6 @@ import {
decide,
shouldDrain,
shouldStartCountdown,
queueBlocksDirectSend,
parseSendArgs,
sendNow as sendToTerminal,
} from "./delivery.js";
@@ -89,6 +93,11 @@ import {
queueLabel,
shortPath,
stillSameAgent,
directSendBlocked,
fieldBackground,
blockTargetPx,
shouldResize,
isManualResize,
statusText,
targetAgent,
} from "./view.js";
@@ -108,6 +117,16 @@ const PANEL_MIN_BLOCK = 320;
/** ...to this. */
const PANEL_BLOCK_PX = 360;
/** The padding of the root, per side (px) - the block is the content plus two of them. */
const ROOT_PADDING = 8;
/** The range the layout gives the composer block (`layouts/ovis-composer.json`), px. */
const BLOCK_MIN_PX = 120;
const BLOCK_MAX_PX = 520;
/** The block is resized once the content has been quiet for this long, ms. */
const FIT_DELAY_MS = 120;
/** How many rows the menu of the suggestions shows at most. */
const MENU_LIMIT = 20;
@@ -190,10 +209,20 @@ export default class Composer extends View {
// is picked, where the caret was when it opened, and the history as it was
// read then. Each tab has a search field of its own.
this.panel = null;
this.panelSearchFocused = false;
// The height of the composer block (reported by its root) and the height
// to give back when a panel that made the block taller closes.
this.blockHeight = null;
this.panelRestorePx = null;
// The block is as tall as its content: the height of the content, the
// height this copy ordered last (what it did not order is the person's
// drag), the floor the person dragged to, and the timer that waits for the
// content to settle before the block is resized.
this.contentHeight = null;
this.orderedPx = null;
this.ignoreSizeUntil = 0;
this.fitTimer = null;
this.userMin = storage.loadUserMin(this.store);
this.panelInputs = {
history: InputState.new({ placeholder: "Szukaj w historii…" }),
favorites: InputState.new({ placeholder: "Szukaj w ulubionych…" }),
@@ -206,6 +235,15 @@ export default class Composer extends View {
cx.notify();
});
input.on("submit", (event, cx) => this.panelPick(this.panel?.index ?? 0, cx));
// The border of the search field lights up while it has the keyboard.
input.on("focus", (event, cx) => {
this.panelSearchFocused = true;
cx.notify();
});
input.on("blur", (event, cx) => {
this.panelSearchFocused = false;
cx.notify();
});
}
this.panelScroll = VirtualListScrollHandle.new();
this.favorites = storage.loadFavorites(this.store);
@@ -439,7 +477,7 @@ export default class Composer extends View {
savedAt: Date.now(),
});
} catch (err) {
this.notice(`Nie udało się zapisać szkicu: ${errorText(err)}`, "error");
this.notice(`Nie udało się zapisać szkicu: ${errorText(err)}`, "problem");
}
}
@@ -638,7 +676,7 @@ export default class Composer extends View {
/** The panel opens over the composer; the caret of the field is remembered. */
openPanel(tab = "history") {
if (!this.target()) {
this.notice("Wybierz agenta, aby otworzyć historię.", "error");
this.notice("Wybierz agenta, aby otworzyć historię.", "problem");
return;
}
this.closeMenu();
@@ -675,6 +713,7 @@ export default class Composer extends View {
if (!this.panel) return;
const { caret } = this.panel;
this.panel = null;
this.panelSearchFocused = false;
if (this.panelRestorePx !== null) {
this.resizeBlock(this.panelRestorePx);
this.panelRestorePx = null;
@@ -695,25 +734,102 @@ export default class Composer extends View {
*/
layoutPx() {
if (!Number.isFinite(this.blockHeight)) return null;
let zoom = 1;
return Math.round(this.blockHeight / this.zoomFactor());
}
/** The zoom of the app (1 when it is not known): logical px = layout px times this. */
zoomFactor() {
try {
const value = Number(settings()?.zoom);
if (Number.isFinite(value) && value > 0) zoom = value;
if (Number.isFinite(value) && value > 0) return value;
} catch {
// Unknown zoom: 1, the reported height is taken as it is.
}
return Math.round(this.blockHeight / zoom);
return 1;
}
/** The composer block gets another height (`layout.resize`); a refusal is said, not worked around. */
resizeBlock(px) {
// What is reported in the next moments is the answer to this order, not a
// drag of the border.
this.orderedPx = px;
this.ignoreSizeUntil = Date.now() + 400;
try {
run("layout.resize", { id: "composer", px });
} catch (err) {
this.notice(`Nie udało się zmienić wysokości composera: ${errorText(err)}`, "error");
this.notice(`Nie udało się zmienić wysokości composera: ${errorText(err)}`, "problem");
}
}
/**
* The root reported its size (logical px).
*
* A height this copy did not order is the person dragging the border: it
* becomes the floor (`userMin`, kept across restarts). While the panel is
* open its own logic owns the height.
*/
rootSized(size, cx) {
this.blockHeight = size.height;
if (this.panel) return;
const px = this.layoutPx();
if (px === null) return;
if (this.orderedPx === null) {
// The first height is the layout's own - the point to start from.
this.orderedPx = px;
} else if (Date.now() >= this.ignoreSizeUntil && isManualResize({ reportedPx: px, orderedPx: this.orderedPx })) {
this.userMin = px;
this.orderedPx = px;
try {
storage.saveUserMin(this.store, px);
} catch {
// The floor is not kept across a restart; it still holds for now.
}
}
this.scheduleFit(cx);
}
/** The content (everything but the layers) reported its size. */
contentSized(size, cx) {
this.contentHeight = size.height;
this.scheduleFit(cx);
}
/** The block is fitted once the content has been quiet for 120 ms. */
scheduleFit(cx) {
if (this.fitTimer) {
this.fitTimer.cancel();
this.fitTimer = null;
}
this.fitTimer = cx.timer.after(FIT_DELAY_MS, () => {
this.fitTimer = null;
this.fitBlock();
});
}
/**
* The block takes the height of its content (never below what the person
* dragged it to), when that differs by more than 4 px from what it has. The
* height last ordered is not ordered again, so a resize that comes back as a
* size change does not start another one.
*/
fitBlock() {
if (this.panel || !Number.isFinite(this.contentHeight)) return;
const current = this.layoutPx();
if (current === null) return;
const target = blockTargetPx({
contentHeight: this.contentHeight,
padding: ROOT_PADDING * 2,
zoom: this.zoomFactor(),
userMin: this.userMin,
min: BLOCK_MIN_PX,
max: BLOCK_MAX_PX,
});
if (!shouldResize(current, target) || target === this.orderedPx) return;
this.resizeBlock(target);
}
/** The selection (or the caret) of the field. */
restoreSelection(range) {
try {
@@ -744,6 +860,8 @@ export default class Composer extends View {
query,
index,
input: this.panelInputs[tab],
searchFocused: this.panelSearchFocused,
fieldBackground: fieldBackground(theme(), theme().popover),
scroll: this.panelScroll,
isFavorite: (text) => isFavorite(this.favorites, text),
};
@@ -863,7 +981,7 @@ export default class Composer extends View {
/** The star next to the field: the text of the field is a favourite, or no longer. */
toggleCurrentFavorite(cx) {
if (this.value.trim() === "") {
this.notice("Wpisz tekst, aby dodać go do ulubionych.", "error", cx);
this.notice("Wpisz tekst, aby dodać go do ulubionych.", "problem", cx);
return;
}
this.toggleFavoriteText(this.value, cx);
@@ -874,7 +992,7 @@ export default class Composer extends View {
try {
storage.saveFavorites(this.store, this.favorites);
} catch (err) {
this.notice(`Nie udało się zapisać ulubionych: ${errorText(err)}`, "error");
this.notice(`Nie udało się zapisać ulubionych: ${errorText(err)}`, "problem");
}
if (this.panel) this.panel.index = Math.min(this.panel.index, Math.max(0, this.panelView().state.hits.length - 1));
cx.notify();
@@ -927,20 +1045,13 @@ export default class Composer extends View {
if (handled || String(event.key).toLowerCase() === "escape") cx.stop_propagation();
}
/**
* The menu moves one row up or down.
*
* The arrows come as actions of the mod: the field binds them to the
* movement of the cursor and eats them before they reach the element. The
* cursor goes back to where the menu was opened, so the text does not move
* under the person.
*/
/**
* The up and down arrows.
*
* With the menu open they move the menu; without it they move the cursor
* between the lines of the field - the field of this app version does not do
* that by itself.
* They come as actions of the mod: the field binds them to its own cursor
* movement and eats them before they reach the element. With the menu open
* they move the menu; without it they move the cursor between the lines of
* the field - the field of this app version does not do that by itself.
*/
arrow(step, cx) {
if (!this.hasKeyboard) return;
@@ -959,6 +1070,10 @@ export default class Composer extends View {
this.textarea.set_selected_range({ start: moved, end: moved });
}
/**
* The menu moves one row. The cursor goes back to where the menu was opened,
* so the text does not move under the person.
*/
moveMenu(step, cx) {
if (menuAction(this.hasKeyboard, this.menu, step < 0 ? "up" : "down") !== "menu") return;
const menu = this.menu;
@@ -989,12 +1104,12 @@ export default class Composer extends View {
/** The message goes out, or it waits in the queue. */
submit(text, cx, mode = "auto", force = false) {
if (!this.syncOk(cx)) {
this.notice("Agent się zmienił — wiadomość nie została wysłana. Zostaje w szkicu poprzedniego agenta.", "error", cx);
this.notice("Agent się zmienił — wiadomość nie została wysłana. Zostaje w szkicu poprzedniego agenta.", "problem", cx);
return;
}
const agent = this.target();
if (!agent) {
this.notice("Composer nie ma do kogo pisać — brak agenta.", "error", cx);
this.notice("Composer nie ma do kogo pisać — brak agenta.", "problem", cx);
return;
}
const body = text.trim();
@@ -1002,7 +1117,7 @@ export default class Composer extends View {
const over = overLimit(text);
if (over > 0) {
this.notice(`Limit ${LIMITS.messageChars} znaków · ${over} za dużo`, "error", cx);
this.notice(`Limit ${LIMITS.messageChars} znaków · ${over} za dużo`, "problem", cx);
return;
}
@@ -1012,11 +1127,11 @@ export default class Composer extends View {
if (broken) {
// A file that did not make it to the agent is still in the way - the
// person removes it or fixes it first.
this.notice(`Plik ${broken.name} nie dotarł do agenta — kliknij „Ponów” albo usuń go.`, "error", cx);
this.notice(`Plik ${broken.name} nie dotarł do agenta — kliknij „Ponów” albo usuń go.`, "problem", cx);
return;
}
if (attached.some((file) => file.state === "adding")) {
this.notice("Pliki są jeszcze dodawane do agenta — poczekaj chwilę.", "error", cx);
this.notice("Pliki są jeszcze dodawane do agenta — poczekaj chwilę.", "problem", cx);
return;
}
const files = attached.filter((file) => file.state === "ready");
@@ -1064,9 +1179,14 @@ export default class Composer extends View {
const allowed = mode === "now" || canAutoSend(this.draftReady, key);
// A message that is on the wire, waits in the queue or counts down goes first: the
// new one waits behind it in the queue instead of vanishing or jumping
// the line (Ctrl+Enter is the person's own order and does jump).
const busy =
this.draining.has(key) || (mode !== "now" && queueBlocksDirectSend(this.state.queue[key]));
// the line. Ctrl+Enter is the person's own order and does jump, and so is
// an answer to a blocked agent (see `directSendBlocked`).
const busy = directSendBlocked({
draining: this.draining.has(key),
mode,
status: this.statusOf(agent),
queue: this.state.queue[key],
});
if (decision.kind === "send" && allowed && !busy) {
// The person's own Enter answers an agent that waits for them: it goes
// through even though the agent is blocked (`hc send --force`). Never
@@ -1114,7 +1234,7 @@ export default class Composer extends View {
async sendNow(agent, message, cx, options = {}) {
const key = agentKey(agent);
if (this.draining.has(key)) {
this.notice("Ta wiadomość jest już w locie.", "error", cx);
this.notice("Ta wiadomość jest już w locie.", "problem", cx);
return;
}
this.draining.add(key);
@@ -1371,7 +1491,7 @@ export default class Composer extends View {
async sendQueued(agent, id, cx) {
const key = agentKey(agent);
if (this.draining.has(key)) {
this.notice("Ta wiadomość jest już w locie.", "error", cx);
this.notice("Ta wiadomość jest już w locie.", "problem", cx);
return;
}
@@ -1590,21 +1710,6 @@ export default class Composer extends View {
});
}
/** The shortcut of the agent's own program - the keyboard here is not the terminal's. */
passKey(agent, keys, cx) {
cx.spawn(async (cx) => {
try {
const res = await hc(["keys", agent.address, keys, "--json"]);
if (!hcOk(res)) {
this.notice(`Klawisz nie dotarł do agenta: ${resultError(res, parseJson(res.stdout))}`, "error");
}
} catch {
// The core is gone - the key goes nowhere.
}
cx.notify();
});
}
// --- the suggestions -----------------------------------------------------
/** The caret sits in a `/` or `@` token - the menu looks at it. */
@@ -1744,11 +1849,11 @@ export default class Composer extends View {
this.addFiles(paths.map((path) => ({ path, bytes: null })), "drop", cx);
return;
}
if (measured.dirs.length) this.notice(DIR_NOTICE, "error");
if (measured.dirs.length) this.notice(DIR_NOTICE, "problem");
this.addFiles(measured.files, "drop", cx);
// A path that is not there any more is said, not skipped in silence.
if (measured.missing.length) {
this.notice(`Nie znaleziono pliku: ${measured.missing.map(nameOf).join(", ")}`, "error", cx);
this.notice(`Nie znaleziono pliku: ${measured.missing.map(nameOf).join(", ")}`, "problem", cx);
}
});
}
@@ -1778,7 +1883,7 @@ export default class Composer extends View {
if (!this.syncOk(cx)) return;
const agent = this.target();
if (!agent) {
this.notice("Wybierz agenta — nie ma do kogo dodać pliku.", "error", cx);
this.notice("Wybierz agenta — nie ma do kogo dodać pliku.", "problem", cx);
return;
}
const key = agentKey(agent);
@@ -1793,7 +1898,7 @@ export default class Composer extends View {
fresh.push(entry);
}
if (!fresh.length) {
if ((entries ?? []).length) this.notice("Ten plik jest już dodany.", "error", cx);
if ((entries ?? []).length) this.notice("Ten plik jest już dodany.", "problem", cx);
return;
}
@@ -1811,7 +1916,7 @@ export default class Composer extends View {
// The whole batch may be 100 files at most; every file is judged on its
// own - a file that is too big does not take the good ones with it.
if ((this.state.attachments[key] ?? []).length + files.length > LIMITS.filesPerAction) {
this.notice(`Za dużo plików (limit ${LIMITS.filesPerAction})`, "error", cx);
this.notice(`Za dużo plików (limit ${LIMITS.filesPerAction})`, "problem", cx);
return;
}
@@ -1833,7 +1938,7 @@ export default class Composer extends View {
file: error ? { ...file, state: "error", error } : { ...file, state: "adding" },
});
}
if (problem) this.notice(problem, "error");
if (problem) this.notice(problem, "problem");
this.scheduleDraftSave(cx);
cx.notify();
@@ -1860,13 +1965,13 @@ export default class Composer extends View {
}
if (result.kind === "none") {
this.notice("Schowek nie zawiera tekstu ani obrazu, który można wkleić.", "error");
this.notice("Schowek nie zawiera tekstu ani obrazu, który można wkleić.", "problem");
} else if (result.kind === "error") {
this.notice(`Nie udało się odczytać schowka: ${result.message}`, "error");
this.notice(`Nie udało się odczytać schowka: ${result.message}`, "problem");
} else if (result.kind === "dirs") {
this.notice(DIR_NOTICE, "error");
this.notice(DIR_NOTICE, "problem");
} else {
if (result.dirs.length) this.notice(DIR_NOTICE, "error");
if (result.dirs.length) this.notice(DIR_NOTICE, "problem");
this.addFiles(result.files, "paste", cx);
}
cx.notify();
@@ -1886,7 +1991,7 @@ export default class Composer extends View {
const picked = parsePickerResult(res);
if (picked.length) this.addFiles(picked, "picker", cx);
} catch (err) {
this.notice(`Nie udało się otworzyć okna wyboru plików: ${errorText(err)}`, "error");
this.notice(`Nie udało się otworzyć okna wyboru plików: ${errorText(err)}`, "problem");
} finally {
this.picking = false;
cx.notify();
@@ -1973,7 +2078,7 @@ export default class Composer extends View {
};
storage.saveHistory(this.store, record(storage.loadHistory(this.store), entry));
} catch (err) {
this.notice(`Nie udało się zapisać historii: ${errorText(err)}`, "error");
this.notice(`Nie udało się zapisać historii: ${errorText(err)}`, "problem");
}
}
@@ -1982,7 +2087,7 @@ export default class Composer extends View {
try {
storage.saveQueue(this.store, key, this.state.queue[key] ?? []);
} catch (err) {
this.notice(`Nie udało się zapisać kolejki: ${errorText(err)}`, "error");
this.notice(`Nie udało się zapisać kolejki: ${errorText(err)}`, "problem");
}
}
@@ -1993,6 +2098,9 @@ export default class Composer extends View {
* to show up - the caller says when that happens.
*/
notice(text, level = "info", cx = null) {
// 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 } });
if (level === "error") {
notify({ title: "Composer", body: text, level: "error" });
@@ -2017,9 +2125,7 @@ export default class Composer extends View {
return v_flex()
.id("ovis-composer")
.relative()
.on_size_change((size) => {
this.blockHeight = size.height;
})
.on_size_change((size, cx) => this.rootSized(size, cx))
.track_focus(this.handle)
.key_context(CONTEXT)
.on_key_down((event, cx) => this.key(event, cx))
@@ -2034,18 +2140,34 @@ export default class Composer extends View {
.on_action("ovis-composer.hold", (e, cx) => this.runAction("hold", cx))
.on_action("ovis-composer.escape", (e, cx) => this.runAction("escape", cx))
.size_full()
.p(8)
.p(ROOT_PADDING)
.gap(6)
// The card and the context strip sit at the bottom edge of the block,
// right above the status bar; the menu, the queue and the notices stay
// above the card.
.justify_end()
.bg(t.canvas)
.text_color(t.foreground)
.children(
[
this.renderMenu(t),
this.renderQueue(t, agent, key),
this.renderImageConfirm(t),
this.renderNotice(t),
this.renderCard(t, agent, key, status),
this.renderContext(t, agent),
// The content is measured as it is - `flex_none`, so a block that is
// too low does not squeeze it and hide how much room it needs.
v_flex()
.id("composer-content")
.flex_none()
.w_full()
.gap(6)
.on_size_change((size, cx) => this.contentSized(size, cx))
.children(
[
this.renderMenu(t),
this.renderQueue(t, agent, key),
this.renderImageConfirm(t),
this.renderNotice(t),
this.renderCard(t, agent, key, status),
this.renderContext(t, agent),
].filter(Boolean),
),
this.renderPanelLayer(t),
this.renderPreviewLayer(t),
].filter(Boolean),
@@ -2069,6 +2191,12 @@ export default class Composer extends View {
pick: (key, cx) => this.panelPickKey(key, cx),
toggle: (key, cx) => this.panelToggleKey(key, cx),
clear: (cx) => this.panelClear(cx),
// The close button: what Esc does - the field gets the keyboard, the
// caret and the height of the block back.
close: (cx) => {
this.closePanel();
cx.notify();
},
}),
);
}
@@ -2291,7 +2419,7 @@ export default class Composer extends View {
renderNotice(t) {
const notice = this.state.notice;
if (!notice) return null;
const error = notice.level === "error";
const error = notice.level === "error" || notice.level === "problem";
return div()
.id("composer-notice")
+27
View File
@@ -32,6 +32,8 @@ const TEXT_HEIGHT = 34;
* query: string,
* index: number,
* input: object,
* searchFocused: boolean,
* fieldBackground: string,
* scroll: object,
* isFavorite: (text:string) => boolean,
* }} view
@@ -41,6 +43,7 @@ const TEXT_HEIGHT = 34;
* pick: (key:string, cx:any) => void,
* toggle: (key:string, cx:any) => void,
* clear: (cx:any) => void,
* close: (cx:any) => void,
* }} on
*/
export function renderPanel(t, view, on) {
@@ -83,12 +86,21 @@ function renderTop(t, view, on) {
.children([
renderTab(t, "history", `Historia ${counts.history}`, view.tab === "history", on),
renderTab(t, "favorites", `Ulubione ${counts.favorites}`, view.tab === "favorites", on),
// The search field: a darker recess with a border that lights up while
// the field has the keyboard (the `.hsearch` of the mockup).
h_flex()
.id("composer-panel-search")
.flex_1()
.min_w(0)
.h(30)
.px(10)
.items_center()
.gap(6)
.rounded(8)
.bg(view.fieldBackground)
.border_1()
.border_color(view.searchFocused ? t.accent : t.input)
.child(div().flex_none().text_size(13).text_color(t.dim).child("⌕"))
.child(Input.new(view.input).flex_1().min_w(0).text_size(12.5))
.when(view.query !== "", (el) =>
el.child(
@@ -103,6 +115,21 @@ function renderTop(t, view, on) {
.child("✕"),
),
),
// Close the panel - the same road as Esc.
div()
.id("composer-panel-close")
.size(28)
.flex_none()
.flex()
.items_center()
.justify_center()
.rounded(6)
.text_size(13)
.text_color(t.dim)
.cursor_pointer()
.hover((s) => s.bg(t.hover).text_color(t.foreground))
.on_click((event, cx) => on.close(cx))
.child("✕"),
]);
}
+3 -3
View File
@@ -4,9 +4,9 @@
// never mutates the one it was given, so the model can be tested in plain Node
// (tests/state.test.mjs) and reasoned about without a running app.
//
// Drafts, attachments and the queue are keyed by agent name ("claude-code",
// "codex"): each belongs to the agent it was written for, and switching agents
// must not lose any of them.
// Drafts, attachments and the queue are keyed by the address of the agent
// (`AgentInfo.address`, e.g. "t2"): each belongs to the agent it was written
// for, and switching agents must not lose any of them.
import { onRestart } from "./delivery.js";
+24
View File
@@ -64,6 +64,8 @@ export const KEYS = {
history: "ovis-composer.history",
favorites: "ovis-composer.favorites",
usage: "ovis-composer.usage",
/** The height (layout px) the person dragged the composer to; 0 or none: not set. */
userMin: "ovis-composer.userMin",
/** The queue is per agent: `ovis-composer.queue:<agent>`. */
queue: "ovis-composer.queue",
/** The draft is per agent: `ovis-composer.draft:<agent>`. */
@@ -247,6 +249,28 @@ function toDraft(value) {
};
}
/**
* The height the person dragged the composer block to (layout px). 0 is "not
* set"; anything that is not a positive number is not a height.
*
* @param {Store} store
* @returns {number}
*/
export function loadUserMin(store) {
const value = read(store, KEYS.userMin);
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
}
/**
* @param {Store} store
* @param {number} px - 0 clears it; what is not a number is not written
* @returns {void}
*/
export function saveUserMin(store, px) {
if (typeof px !== "number" || !Number.isFinite(px) || px < 0) return;
write(store, KEYS.userMin, Math.round(px));
}
/**
* How often each command was used - the numbers the ranking of the
* suggestions breaks its ties with (`suggest.rank` reads `item.uses`).
+115 -1
View File
@@ -8,7 +8,7 @@
// belongs to an agent (the draft, the queue, the attachments) is keyed by the
// agent's address, so two Claude Code agents never share a draft.
import { drain, gateAfter } from "./delivery.js";
import { drain, gateAfter, queueBlocksDirectSend } from "./delivery.js";
import { LIMITS } from "./attachments.js";
/**
@@ -495,3 +495,117 @@ export function canAutoSend(ready, key) {
export function stillSameAgent({ before, after, target }) {
return before !== "" && before === after && before === target;
}
/**
* Must a message that could go out now wait behind what is already in flight
* or in the queue?
*
* - a message on the wire always goes first (`draining`);
* - Ctrl+Enter (`mode "now"`) is the person's own order and does not wait;
* - an answer to an agent that is `blocked` does not wait either: the queue
* does not start while the agent waits for the person, so queueing the
* answer would leave the agent waiting for ever - it goes ahead (with
* `--force`) and the queue stays as it is;
* - otherwise it waits when a message is queued or counting down.
*
* @param {{draining:boolean, mode:string, status:string, queue:object[]|undefined}} input
* @returns {boolean}
*/
export function directSendBlocked({ draining, mode, status, queue }) {
if (draining) return true;
if (mode === "now" || status === "blocked") return false;
return queueBlocksDirectSend(queue);
}
// --- the height of the composer block ----------------------------------------
//
// The block is as tall as its content (menu, queue, notices, card, strip),
// unless the person dragged its border: then that height is the floor.
/**
* The height the block should have, in the pixels of the layout.
*
* What the content measures is in logical pixels (layout px times the zoom of
* the app), plus the padding of the root; the floor is what the person dragged
* the block to (`userMin`, 0 for none); the result stays inside the range the
* layout allows.
*
* @param {{contentHeight:number, padding:number, zoom:number, userMin:number, min:number, max:number}} input
* @returns {number}
*/
export function blockTargetPx({ contentHeight, padding, zoom, userMin, min, max }) {
const factor = Number.isFinite(zoom) && zoom > 0 ? zoom : 1;
const need = Math.ceil((contentHeight + padding) / factor);
const wanted = Math.max(need, Number.isFinite(userMin) ? userMin : 0);
return Math.round(Math.min(max, Math.max(min, wanted)));
}
/**
* Is the difference worth a `layout.resize`? Under 5 px it is not: typing and
* the growing of the field must not make the block twitch.
*
* @param {number|null|undefined} current
* @param {number|null|undefined} target
* @param {number} [threshold]
* @returns {boolean}
*/
export function shouldResize(current, target, threshold = 4) {
if (!Number.isFinite(current) || !Number.isFinite(target)) return false;
return Math.abs(current - target) > threshold;
}
/**
* Is a reported height the person's drag?
*
* The composer keeps the height it ordered last (`orderedPx`); a height it did
* not order is somebody dragging the border. Before anything was ordered the
* first height is the layout's own, not a drag.
*
* @param {{reportedPx:number, orderedPx:number|null, tolerance?:number}} input
* @returns {boolean}
*/
export function isManualResize({ reportedPx, orderedPx, tolerance = 3 }) {
if (!Number.isFinite(reportedPx) || !Number.isFinite(orderedPx)) return false;
return Math.abs(reportedPx - orderedPx) > tolerance;
}
// --- colors from the theme -----------------------------------------------------
/**
* How light a color is (0 dark .. 1 light), from `#rgb`, `#rrggbb` or
* `#rrggbbaa`; nothing for what is not such a color.
*
* @param {unknown} color
* @returns {number|null}
*/
export function luminance(color) {
if (typeof color !== "string") return null;
let hex = color.trim();
if (!/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(hex)) return null;
hex = hex.slice(1);
if (hex.length === 3) hex = hex.replace(/./g, "$&$&");
const channel = (at) => parseInt(hex.slice(at, at + 2), 16) / 255;
return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
}
/**
* The background of an input field set into a panel: the darkest color the
* theme names among the usual surfaces, so the field reads as a recess in the
* panel whatever the theme. A theme with none to offer leaves the panel's own.
*
* @param {Record<string,string>} theme - `theme()`
* @param {string} panelBackground - the background of the panel
* @returns {string}
*/
export function fieldBackground(theme, panelBackground) {
let best = null;
let bestLight = Infinity;
for (const key of ["background", "canvas", "pane", "surface", "chrome"]) {
const light = luminance(theme?.[key]);
if (light !== null && light < bestLight) {
best = theme[key];
bestLight = light;
}
}
return best ?? panelBackground;
}
+17
View File
@@ -132,3 +132,20 @@ test("queue roundtrip keeps a countdown entry (restart turns it into held)", ()
saveQueue(store, "a", q);
assert.deepEqual(loadQueue(store, "a"), q);
});
import { loadUserMin, saveUserMin } from "../mod/ovis-composer/storage.js";
test("userMin: the height the person dragged the composer to; 0 is none", () => {
const store = memStore();
assert.equal(loadUserMin(store), 0);
saveUserMin(store, 300);
assert.equal(loadUserMin(store), 300);
saveUserMin(store, 0);
assert.equal(loadUserMin(store), 0);
store.set("ovis-composer.userMin", "x");
assert.equal(loadUserMin(store), 0);
store.set("ovis-composer.userMin", -5);
assert.equal(loadUserMin(store), 0);
saveUserMin(store, NaN);
assert.equal(store.get("ovis-composer.userMin"), -5);
});
+84
View File
@@ -81,3 +81,87 @@ test("stillSameAgent: only when the field and the focus are on one agent", () =>
assert.equal(stillSameAgent({ before: "", after: "", target: "" }), false);
assert.equal(stillSameAgent({ before: "", after: "t2", target: "t2" }), false);
});
import { directSendBlocked } from "../mod/ovis-composer/view.js";
test("directSendBlocked: who must wait behind the queue", () => {
const queue = [{ state: "queued" }];
// an answer to a blocked agent goes ahead of the queue
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "blocked", queue }), false);
// an idle agent with a queue: the new message waits at the end
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue }), true);
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "done", queue }), true);
// Ctrl+Enter is the person's own order
assert.equal(directSendBlocked({ draining: false, mode: "now", status: "idle", queue }), false);
// a message on the wire always goes first
assert.equal(directSendBlocked({ draining: true, mode: "now", status: "blocked", queue: [] }), true);
assert.equal(directSendBlocked({ draining: true, mode: "auto", status: "idle", queue }), true);
// nothing waits
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [] }), false);
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [{ state: "held" }] }), false);
});
import { blockTargetPx, shouldResize, isManualResize } from "../mod/ovis-composer/view.js";
const fit = (over = {}) => ({ contentHeight: 100, padding: 16, zoom: 1.2, userMin: 0, min: 120, max: 520, ...over });
test("blockTargetPx: the content (plus padding) in layout px, clamped to the layout's range", () => {
// (100 + 16) / 1.2 = 96.7 -> 97, under the minimum of 120
assert.equal(blockTargetPx(fit()), 120);
// (300 + 16) / 1.2 = 263.3 -> 264
assert.equal(blockTargetPx(fit({ contentHeight: 300 })), 264);
assert.equal(blockTargetPx(fit({ contentHeight: 5000 })), 520);
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: 1 })), 316);
});
test("blockTargetPx: the height the person dragged to is kept, and content that needs more wins", () => {
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 300 })), 300);
assert.equal(blockTargetPx(fit({ contentHeight: 500, userMin: 300 })), 430);
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 9999 })), 520);
assert.equal(blockTargetPx(fit({ contentHeight: 100, userMin: 0 })), 120);
});
test("blockTargetPx: a zoom that is not a number counts as 1", () => {
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: 0 })), 316);
assert.equal(blockTargetPx(fit({ contentHeight: 300, zoom: NaN })), 316);
});
test("shouldResize: only for a difference over 4 px", () => {
assert.equal(shouldResize(150, 154), false);
assert.equal(shouldResize(150, 155), true);
assert.equal(shouldResize(150, 145), true);
assert.equal(shouldResize(150, 146), false);
assert.equal(shouldResize(null, 150), false);
assert.equal(shouldResize(150, undefined), false);
});
test("isManualResize: a height nobody ordered is the person's drag", () => {
assert.equal(isManualResize({ reportedPx: 200, orderedPx: 200 }), false);
assert.equal(isManualResize({ reportedPx: 202, orderedPx: 200 }), false);
assert.equal(isManualResize({ reportedPx: 260, orderedPx: 200 }), true);
assert.equal(isManualResize({ reportedPx: 100, orderedPx: 200 }), true);
// nothing was ordered yet: the first size is the layout's, not a drag
assert.equal(isManualResize({ reportedPx: 150, orderedPx: null }), false);
assert.equal(isManualResize({ reportedPx: NaN, orderedPx: 200 }), false);
});
import { luminance, fieldBackground } from "../mod/ovis-composer/view.js";
test("luminance: black is darker than grey is darker than white; alpha and rubbish are tolerated", () => {
assert.ok(luminance("#000000") < luminance("#808080"));
assert.ok(luminance("#808080") < luminance("#ffffff"));
assert.equal(luminance("#000000ff"), luminance("#000000"));
assert.equal(luminance("#fff"), luminance("#ffffff"));
assert.equal(luminance("red"), null);
assert.equal(luminance(undefined), null);
});
test("fieldBackground: the darkest color the theme has, darker than the panel", () => {
const theme = { popover: "#2a2c31", background: "#101114", canvas: "#16171a", raised: "#202226", chrome: "#1b1c20" };
assert.equal(fieldBackground(theme, theme.popover), "#101114");
// a theme where the background is lighter than another color: that one wins
assert.equal(fieldBackground({ ...theme, background: "#3a3c41", canvas: "#0c0d0f" }, theme.popover), "#0c0d0f");
// nothing valid: the panel's own color
assert.equal(fieldBackground({}, "#2a2c31"), "#2a2c31");
assert.equal(fieldBackground({ background: "nope" }, "#2a2c31"), "#2a2c31");
});