web: shared chat stars, pipeline mini graphs and agent questions

- Persist chat stars in the operator-session registry (chat_star) so every
  browser/device shows the same Starred group; migrate old local stars once.
- Add a compact pipeline graph shape to list responses and draw a lightweight
  list miniature; replace the cryptic id/version line with the stage count.
- Surface OpenCode form questions as a chat card (chat_answer), replay a
  pending form to late subscribers, and notify for background questions.
- Make the mobile dock's Search cell equal to every destination, keep the
  tab row visible with 100svh, and let Source use the full pane height.
- Let a fresh sign-in auto-connect to its own origin; use a Lax session cookie
  with Expires so Remember me survives app/link launches.
- Keep shipped starters and the skill agnostic: no repository paths, project
  areas or personal device commands; add Diagnose/Fix and Research starters.
- Refresh the installed skill and document the new browser conventions.
This commit is contained in:
2026-10-20 03:11:37 +01:00
parent caae8a8038
commit 526c19fc21
46 changed files with 1547 additions and 611 deletions
+199 -12
View File
@@ -4,7 +4,7 @@
// in chat.js and markdown.js; this module owns the DOM and the chat wire wiring.
import { h } from "../dom.js";
import { writeChatStars } from "../chatStars.js";
import { readChatStars, writeChatStars } from "../chatStars.js";
import { describeError } from "../format.js";
import { SHELL_OUTPUT_LIMIT, newChatOperationId } from "../repository.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
@@ -371,6 +371,23 @@ async function loadChatSessions(force = false) {
renderContent();
try {
const listed = await repo.chatSessions();
// One-time migration from the old local-only stars: upload this device's
// saved set, then let the server's shared set be authoritative everywhere.
const localStars = readChatStars();
if (localStars.size) {
for (const id of localStars) {
const session = listed.find((entry) => entry.id === id);
if (!session || session.starred) continue;
try {
const updated = await repo.starChat(id, true);
if (updated) Object.assign(session, updated);
} catch {
// Keep going: a missing session or a transient failure must not block
// the rest of the list.
}
}
writeChatStars(new Set());
}
// Keep this page's own verification chats, which the server intentionally
// never returns, at the head of the in-memory list (memory-only; see
// chatEphemeralIds). Everything else is the server's list, in its order.
@@ -379,6 +396,7 @@ async function loadChatSessions(force = false) {
state.chatEphemeralIds.has(session.id) && !listed.some((entry) => entry.id === session.id),
);
state.chatSessions = [...held, ...listed];
syncChatStarsFromSessions();
state.chatLoaded = true;
rt.touchView?.("chat");
// Fold this device's seen state in: the active chat has been read, and every
@@ -670,6 +688,26 @@ async function answerPermission(sessionId, requestId, decision) {
}
}
/**
* Answer the agent's pending question. The answer map is keyed by the form
* field's own key and mirrors OpenCode's form.reply body; the resolved form
* arrives on the stream and clears the card for every watching client.
*/
async function answerChatQuestion(sessionId, form, answers) {
if (!form?.id) return;
try {
await repo.answerChatForm(sessionId, form.id, answers);
const current = state.chatThreads.get(sessionId);
if (current?.form && current.form.id === form.id) {
setThread(sessionId, { form: { ...current.form, resolved: true } });
}
renderContent();
} catch (error) {
state.actionError = describeError(error);
renderContent();
}
}
/**
* The reconnect repair (C5): re-attach the open chat's stream and replace its
* conversation with the newest history page wholesale. Everything the gap could
@@ -884,10 +922,17 @@ async function reopenChatSession(id) {
}
/** Apply the echoed session (or the local closed flag) to the held row. */
function syncChatStarsFromSessions(sessions = state.chatSessions) {
state.chatStars = new Set(
(sessions ?? []).filter((session) => session.starred === true).map((session) => session.id),
);
}
function applyChatSessionUpdate(id, updated, closed) {
state.chatSessions = state.chatSessions.map((session) =>
session.id === id ? { ...session, ...(updated ?? {}), closed } : session,
);
syncChatStarsFromSessions();
}
// ---------------------------------------------------------------------------
@@ -1596,13 +1641,24 @@ function chatEmpty(message) {
return h("div", { class: "empty" }, h("span", { class: "muted", text: message }));
}
/** Toggle one session's local star, then repaint the list in its new order. */
function toggleChatStar(id) {
const next = new Set(state.chatStars ?? []);
if (next.has(id)) next.delete(id);
else next.add(id);
state.chatStars = next;
writeChatStars(next);
/** Toggle one session's shared star on the server, then repaint its group. */
async function toggleChatStar(id) {
const wasStarred = state.chatStars?.has?.(id) === true;
state.chatSessions = state.chatSessions.map((session) =>
session.id === id ? { ...session, starred: !wasStarred } : session,
);
syncChatStarsFromSessions();
renderContent();
try {
const updated = await repo.starChat(id, !wasStarred);
if (updated) applyChatSessionUpdate(id, updated, updated.closed === true);
} catch (error) {
state.chatSessions = state.chatSessions.map((session) =>
session.id === id ? { ...session, starred: wasStarred } : session,
);
syncChatStarsFromSessions();
state.actionError = describeError(error);
}
renderContent();
}
@@ -1891,7 +1947,11 @@ function renderChatConversation() {
// answer. While it is actionable the chat pane offers a jump control and the
// running indicator stands down (a turn blocked on a decision is not generating).
const approval = approvalCard(thread?.permission, thread?.permissionAnswer);
const awaiting = approval?.actionable === true;
const form =
thread?.form && thread.form.resolved !== true && thread.form.cancelled !== true
? thread.form
: null;
const awaiting = approval?.actionable === true || form != null;
const bar = h("div", { class: "chat-bar" });
const titles = h("div", { class: "chat-bar-titles" });
@@ -1942,11 +2002,11 @@ function renderChatConversation() {
// blocked on a decision is not generating, so neither the spinner nor its clock
// shows. The composer's Stop control stays governed by thread.running.
const running = thread?.running === true && !awaiting;
if (rows.length === 0 && notices.length === 0 && !running && !approval) {
if (rows.length === 0 && notices.length === 0 && !running && !approval && !form) {
pane.append(h("div", { class: "chat-transcript-empty muted", text: CONVERSATION_EMPTY }));
} else {
pane.append(
renderChatTranscript(state.chatActiveId, rows, { notices, running, now: Date.now(), approval }),
renderChatTranscript(state.chatActiveId, rows, { notices, running, now: Date.now(), approval, form }),
);
}
if (thread?.error && thread?.loaded) {
@@ -2187,7 +2247,7 @@ function renderBackgroundTaskDetail(thread, shell) {
function renderChatTranscript(
sessionId,
rows,
{ notices = [], running = false, now = Date.now(), approval = null } = {},
{ notices = [], running = false, now = Date.now(), approval = null, form = null } = {},
) {
const wrap = h("div", { class: "chat-transcript-wrap" });
const transcript = h("div", {
@@ -2219,6 +2279,7 @@ function renderChatTranscript(
// after the running indicator when it is shown — so the pane's jump control
// and a fresh card both land at the end.
if (approval) transcript.append(renderChatApproval(sessionId, approval));
if (form) transcript.append(renderChatQuestion(sessionId, form));
wrap.append(transcript);
wrap.append(
h("button", {
@@ -2303,6 +2364,132 @@ function renderChatApproval(sessionId, card) {
return node;
}
/**
* The agent's structured question (OpenCode form with kind=question). Each form
* field is rendered with its options (single-select buttons or multi-select
* toggles) and, when the field is free-form or allows Other, a text input.
* Answers stay local until Send answer; the tool call is paused until then.
*/
function renderChatQuestion(sessionId, form) {
const node = h("div", {
class: "chat-question",
id: "chatQuestion",
"data-form-id": form.id,
});
const head = h("div", { class: "chat-question-head" });
head.append(h("div", { class: "chat-question-title", text: form.title || "Question" }));
head.append(
h("div", { class: "chat-question-status muted", text: "The agent is waiting for your answer." }),
);
node.append(head);
const answers = {};
const parts = [];
for (const field of form.fields ?? []) {
const key = String(field.key ?? "");
if (key === "") continue;
const options = Array.isArray(field.options) ? field.options : [];
const multi = field.type === "multiselect";
const part = h("div", { class: "chat-question-field" });
part.append(
h("div", { class: "chat-question-label", text: field.title || field.description || key }),
);
if (field.description && field.description !== field.title) {
part.append(h("div", { class: "chat-question-desc muted", text: field.description }));
}
if (options.length) {
const rows = h("div", { class: "chat-question-options" });
const buttons = [];
const chosen = () => (multi ? (Array.isArray(answers[key]) ? answers[key] : []) : [answers[key]].filter(Boolean));
const paint = () => {
const selected = new Set(chosen());
for (const button of buttons) {
const on = selected.has(button.dataset.value);
button.classList.toggle("selected", on);
button.setAttribute("aria-pressed", on ? "true" : "false");
}
};
for (const option of options) {
const value = String(option.value ?? option.label ?? "");
if (value === "") continue;
const button = h(
"button",
{
class: "chat-question-option",
type: "button",
"data-value": value,
"aria-pressed": "false",
text: option.label || value,
},
option.description
? h("span", { class: "chat-question-option-desc", text: option.description })
: null,
);
button.addEventListener("click", () => {
if (multi) {
const next = new Set(chosen());
if (next.has(value)) next.delete(value);
else next.add(value);
answers[key] = [...next];
} else {
answers[key] = value;
}
paint();
});
buttons.push(button);
rows.append(button);
}
part.append(rows);
}
if (field.custom === true || options.length === 0) {
const input = h("input", {
class: "chat-question-input",
type: "text",
placeholder: options.length ? "Type another answer" : "Your answer",
autocomplete: "off",
});
input.addEventListener("input", () => {
const value = input.value.trim();
if (value === "") delete answers[key];
else answers[key] = value;
});
part.append(input);
}
parts.push(part);
}
node.append(...parts);
const error = h("div", { class: "chat-question-error", role: "alert", hidden: true });
node.append(error);
const controls = h("div", { class: "chat-question-controls" });
const submit = h("button", {
class: "primary chat-question-submit",
type: "button",
text: "Send answer",
});
let sent = false;
submit.addEventListener("click", () => {
if (sent) return;
const missing = (form.fields ?? []).some((field) => {
if (!field.required) return false;
const value = answers[field.key];
return Array.isArray(value) ? value.length === 0 : !value;
});
if (missing) {
error.hidden = false;
error.textContent = "Answer the required questions before sending.";
return;
}
sent = true;
submit.disabled = true;
submit.textContent = "Sending…";
answerChatQuestion(sessionId, form, answers);
});
controls.append(submit);
node.append(controls);
return node;
}
/**
* The app's amber outlined Shield (`Icons.Outlined.Shield`): an inline SVG stroked
* with `currentColor` so the palette's warn hue actually tints it, unlike the