Files
loki/widget/suggestions.ts
CatoandClaude 8757d532b6 feat(widget): fixes go as one change, watch sees what taps do, ◎ shows Loki (#1112)
The owner, on loki.orangecat.ch from a phone (2026-10-09): "if it proposes
five fixes and I click fix, where is it going? … how do I keep track?",
"I don't know when it's noticing something", "it should be easy to draw
its attention", and the panel still had a lot going on.

- Suggested changes are ONE decision (widget/suggestions.ts): every row
  ticked, a tap unticks, "Build these 3 as one change →" files one note —
  one agent, one PR, one row in Your changes. It used to be a Build per
  row: N runs queued in the project's one lane with nothing saying so.
  The owner's builds start without a confirmation card ("Edit first"
  opens it); a visitor's still confirm.
- Your changes: one summary line that opens ("1 building · 1 in line ·
  1 live"); each row is its own link. A change waiting behind another
  reads "In line" (owner-view.ts), not "Starting".
- Watch sees what a tap DID: for 1.5 s after a tap on a button or link it
  waits for the page to change, ask the server or navigate, notes which
  ("↳ It asked the server"), and says at once — after one tap, not three
  — when nothing visibly happened.
- ◎ beside the launcher while watching: point at anything on the page,
  the panel opens with it attached.
- Phone sheet (widget/sheet.ts): drag the top up for full screen, down to
  peek at the page, further to put it away.
- Shorter greeting.
- Tests: widget-suggestions, widget-sheet, widget-changes (summary, In
  line), widget-thoughts (results); watch-browser covers the tap results
  and the one-change build. Unit 360/360; watch/embed/host-avoid browser
  suites pass locally.


Claude-Session: https://claude.ai/code/session_011L2dmcydDLYAiNQwK4XcF4

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-09 05:33:56 -07:00

85 lines
3.3 KiB
TypeScript

/**
* Loki's suggested changes, as ONE decision.
*
* Each suggestion used to carry its own "Build this →". Five taps started five
* agents, each with its own pull request, queued one behind the other in the
* project's lane — and nothing on the screen said so. "If it proposes five
* different fixes and I click fix, where is it going? … how do I keep track?"
* (owner, heidi.orangecat.ch, 2026-10-09).
*
* Now the list is a selection — every suggestion ticked to start, a tap
* unticks — and there is one action: build what is ticked as one change. One
* agent, one pull request, one row in Your changes. Pure parts are tested in
* scripts/test/widget-suggestions.ts.
*/
import { h } from "./dom";
/** The ticked suggestions as one request the builder can act on. */
export function combineChanges(items: readonly string[]): string {
if (items.length === 1) return items[0];
return `Make these changes on this page, together:\n${items.map((t, i) => `${i + 1}. ${t}`).join("\n")}`;
}
/** The action's words for this many ticked, for the owner or a visitor. */
export function buildLabel(count: number, owner: boolean): string {
if (count === 0) return "Tick what to build";
if (!owner) return count === 1 ? "Send to builder →" : `Send these ${count} to the builder →`;
return count === 1 ? "Build this →" : `Build these ${count} as one change →`;
}
export function suggestionBox(opts: {
items: readonly string[];
owner: boolean;
/** Build (owner) or send (visitor) the combined request. */
onBuild: (text: string) => void;
/** Owner only: open the request to edit it before it starts. */
onEdit: (text: string) => void;
}): HTMLElement {
const box = h("div", "changes");
box.appendChild(h("div", "changes-title", "Suggested changes"));
const ticked = opts.items.map(() => true);
const go = h("button", "change-send");
go.type = "button";
const edit = h("button", "act change-edit", "Edit first");
edit.type = "button";
const chosen = () => opts.items.filter((_, i) => ticked[i]);
const sync = () => {
const n = chosen().length;
go.textContent = buildLabel(n, opts.owner);
go.disabled = n === 0;
edit.style.display = n > 0 ? "" : "none";
};
opts.items.forEach((text, i) => {
const row = h("button", "change on");
row.type = "button";
row.setAttribute("role", "checkbox");
row.setAttribute("aria-checked", "true");
row.append(h("span", "change-tick"), h("span", "change-text", text));
// A single suggestion needs no ticking — the row is the whole decision.
if (opts.items.length > 1)
row.addEventListener("click", () => {
ticked[i] = !ticked[i];
row.classList.toggle("on", ticked[i]);
row.setAttribute("aria-checked", String(ticked[i]));
sync();
});
box.appendChild(row);
});
if (opts.items.length === 1) box.classList.add("single");
go.addEventListener("click", () => {
const items = chosen();
if (items.length) opts.onBuild(combineChanges(items));
});
edit.addEventListener("click", () => {
const items = chosen();
if (items.length) opts.onEdit(combineChanges(items));
});
const foot = h("div", "changes-foot");
// "Edit first" is the owner's: a visitor's send already opens the card.
if (opts.owner) foot.append(edit);
foot.append(go);
box.appendChild(foot);
sync();
return box;
}