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
24 changes: 19 additions & 5 deletions app/slices/agent/components/agent/workspace/Sheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ const failedKey = computed(() => {
:data-tone="indicator.tone"
:aria-label="$t('sheet.turn_line')"
>
<span :key="turn.phase" class="agent-sheet__turn-flip flex min-w-0 items-baseline gap-1.5">
<!-- Clipped to its own room: what does not fit is cut, never drawn
over the clock beside it (RANCH-5). -->
<span :key="turn.phase" class="agent-sheet__turn-flip flex max-h-[1lh] min-w-0 flex-wrap items-baseline gap-x-1.5 overflow-hidden">
<!-- May shorten with an ellipsis: with another agent's name in
it the line can be longer than the room beside the toolbar. -->
<span
Expand All @@ -340,15 +342,21 @@ const failedKey = computed(() => {
<span v-else class="min-w-0 truncate" :title="turn.stepLabel ?? undefined" data-turn-step>
{{ turn.stepLabel }}
</span>
<!-- The count of steps gives way first (RANCH-5): where it does
not fit whole beside the word it wraps to a second line,
which is clipped, so it is left out and never cut in half.
The marks on the ring say the same. -->
<template v-if="turn.phase === 'done' && turn.stepsDone > 0">
<span aria-hidden="true">·</span>
<span class="shrink-0 uppercase" data-turn-steps>
{{ $t('sheet.phase_steps', turn.stepsDone) }}
<span class="agent-sheet__turn-extra inline-flex shrink-0 items-baseline gap-1.5 whitespace-nowrap">
<span aria-hidden="true">·</span>
<span class="uppercase" data-turn-steps>
{{ $t('sheet.phase_steps', turn.stepsDone) }}
</span>
</span>
</template>
</span>
<template v-if="turnTime">
<span aria-hidden="true">·</span>
<span class="agent-sheet__turn-sep" aria-hidden="true">·</span>
<span class="shrink-0 tabular-nums" data-turn-clock>{{ turnTime }}</span>
</template>
<template v-else-if="turnSince">
Expand Down Expand Up @@ -885,6 +893,12 @@ html[data-motion='off'] .agent-sheet__turn-flip {
colour says it) and gives up its word, which stays in the page for a
screen reader. */
@container (max-width: 520px) {
/* Beside the toolbar there is room for the word and the clock and little
else (RANCH-5): the dot between them goes, the gap alone parts them, so
a six-letter word is not cut for the sake of a separator. */
.agent-sheet__turn-sep {
display: none;
}
.agent-sheet__status {
gap: 0;
padding: 0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ranch",
"version": "0.3.128",
"version": "0.3.129",
"private": true,
"packageManager": "bun@1.4.4",
"workspaces": [
Expand Down
1 change: 1 addition & 0 deletions specs/041-agent-turn-indicators/e2e/all.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SCRIPTS = [
{ name: "fleet-many", story: "us4", title: "The list: several agents at work at once" },
{ name: "orbit", story: "us5", title: "The orbit map: the fleet at work" },
{ name: "a2a", story: "us6", title: "One agent asks another" },
{ name: "fit", story: "fit", title: "The header status line fits its room" },
{ name: "calm", story: "us7", title: "Quiet with the agent; motion can be paused" },
{ name: "tab", story: "us8", title: "The browser tab says the agent is done" },
];
Expand Down
150 changes: 150 additions & 0 deletions specs/041-agent-turn-indicators/e2e/fit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// RANCH-5: the status line of the agent header fits its room.
//
// node specs/041-agent-turn-indicators/e2e/fit.mjs
//
// On a phone the line "Done · 2 steps · 0:16" drew the count of steps over
// the clock. This plays one turn at a phone's width and at a desktop's and,
// at every phase, measures the pieces of the line: no piece may lie over
// another, and none may reach past the line itself or under the toolbar.
// Pictures of each phase go to E2E_OUT.
import {
AGENTS,
PHONE,
WIDE,
check,
checkClean,
close,
control,
headerTurn,
launch,
login,
nextFrame,
openChat,
send,
shot,
sleep,
summary,
turnReady,
} from "./lib.mjs";

const A = AGENTS.A;

/**
* The pieces of the status line that are drawn, as boxes, and what is wrong
* with them: pairs that overlap, and pieces that reach outside the line or
* under a control of the header.
*/
const measure = (page) =>
page.evaluate(() => {
const line = document.querySelector("[data-turn-phase]");
if (!line) return { pieces: 0, faults: ["no status line"] };
const boxOf = (el) => {
const r = el.getBoundingClientRect();
return { left: r.left, right: r.right, top: r.top, bottom: r.bottom };
};
// What a person can see of a piece: its own box, cut to every ancestor
// that clips, up to the line.
const seen = (el) => {
const box = boxOf(el);
for (let up = el.parentElement; up && line.contains(up); up = up.parentElement) {
if (getComputedStyle(up).overflowX === "visible") continue;
const clip = boxOf(up);
box.left = Math.max(box.left, clip.left);
box.right = Math.min(box.right, clip.right);
// A piece that wrapped below a one-line box is not drawn at all.
box.top = Math.max(box.top, clip.top);
box.bottom = Math.min(box.bottom, clip.bottom);
}
return box;
};
const pieces = [];
const walker = document.createTreeWalker(line, NodeFilter.SHOW_ELEMENT);
for (let el = walker.nextNode(); el; el = walker.nextNode()) {
if (el.children.length > 0) continue;
if (!(el.textContent ?? "").trim()) continue;
if (getComputedStyle(el).display === "none") continue;
const box = seen(el);
if (box.right - box.left < 0.5 || box.bottom - box.top < 2) continue;
const cut = el.scrollWidth > el.clientWidth + 1;
pieces.push({ text: el.textContent.trim().slice(0, 24), box, cut });
}
const faults = [];
for (let i = 0; i < pieces.length; i++) {
for (let j = i + 1; j < pieces.length; j++) {
const a = pieces[i].box;
const b = pieces[j].box;
const overlap = Math.min(a.right, b.right) - Math.max(a.left, b.left);
if (overlap > 1) faults.push(`"${pieces[i].text}" lies over "${pieces[j].text}"`);
}
}
const own = boxOf(line);
const sheet = line.closest(".agent-sheet");
const controls = sheet ? Array.from(sheet.querySelectorAll("button")) : [];
for (const piece of pieces) {
if (piece.box.right > own.right + 1) faults.push(`"${piece.text}" reaches past the line`);
for (const button of controls) {
const b = boxOf(button);
const across = Math.min(piece.box.right, b.right) - Math.max(piece.box.left, b.left);
const down = Math.min(piece.box.bottom, b.bottom) - Math.max(piece.box.top, b.top);
if (across > 1 && down > 1) {
faults.push(`"${piece.text}" runs under a control`);
break;
}
}
}
return {
pieces: pieces.length,
faults,
shown: pieces.map((piece) => piece.text),
cut: pieces.filter((piece) => piece.cut).map((piece) => piece.text),
};
});

async function phase(page, width, name, note) {
const turn = await headerTurn(page);
const fit = await measure(page);
check(`${width} px, ${name}: the line is drawn (${turn.phase})`, fit.pieces > 0, true);
check(`${width} px, ${name}: nothing lies over anything`, fit.faults, []);
await shot(page, "fit", name, note);
}

async function walk(viewport) {
const width = viewport.width;
const page = await login("app", "owner", viewport);
await openChat(page, A.id);
await control("/drop", { agent: "A" });
await send(page, "Move Ivanov's booking #steps");
await turnReady("A");
await nextFrame("A"); // typing
await phase(page, width, "waiting", "Waiting for the agent");
await nextFrame("A"); // a step begins
await phase(page, width, "step", "A step, in the agent's own words");
await nextFrame("A"); // it ends
await nextFrame("A"); // the second begins
await nextFrame("A"); // and ends
await nextFrame("A"); // text arrives
await phase(page, width, "writing", "Writing");
await control("/finish", { agent: "A" });
await sleep(1500);
const done = await headerTurn(page);
check(`${width} px: the turn is done`, done.phase, "done");
await phase(page, width, "done", "Done: the word, the count of steps where there is room, the clock");
// The clock must be there whatever else gave way: it is the receipt.
check(`${width} px, done: the clock is shown`, Boolean(done.clock), true);
// The word is short and must be whole; the count of steps is either
// whole or absent, never half a word.
const end = await measure(page);
check(`${width} px, done: nothing is cut in half`, end.cut, []);
console.log(` ${width} px shows: ${end.shown.join(" ")}`);
checkClean(`${width} px`, page);
await page.context().close();
}

await launch();
try {
await walk(PHONE);
await walk(WIDE);
} finally {
await close();
}
process.exit(summary() ? 1 : 0);
Loading