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:
@@ -12,6 +12,7 @@ import {
|
||||
attentionDismissalSnapshot,
|
||||
attentionEntries,
|
||||
attentionRowDescription,
|
||||
startOfLocalDay,
|
||||
decodeAttentionDismissals,
|
||||
encodeAttentionDismissals,
|
||||
} from "../attention.js";
|
||||
@@ -100,7 +101,7 @@ function renderAttentionBell() {
|
||||
|
||||
/** The number of entries the attention surface currently holds. */
|
||||
function attentionCount() {
|
||||
return attentionEntries(state.runs, state.attentionDismissed).length;
|
||||
return attentionEntries(state.runs, state.attentionDismissed, { since: startOfLocalDay() }).length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +155,7 @@ function renderAttentionSheet() {
|
||||
modal.close("attention-sheet");
|
||||
return;
|
||||
}
|
||||
const entries = attentionEntries(state.runs, state.attentionDismissed);
|
||||
const entries = attentionEntries(state.runs, state.attentionDismissed, { since: startOfLocalDay() });
|
||||
const overlay = h("div", {
|
||||
class: "attention-sheet",
|
||||
role: "dialog",
|
||||
@@ -259,7 +260,7 @@ function renderAttentionRow(entry, labelCounts = null) {
|
||||
function openAttentionSheet() {
|
||||
state.attentionSheetOpen = true;
|
||||
state.attentionSnapshot = attentionDismissalSnapshot(
|
||||
attentionEntries(state.runs, state.attentionDismissed),
|
||||
attentionEntries(state.runs, state.attentionDismissed, { since: startOfLocalDay() }),
|
||||
);
|
||||
render();
|
||||
}
|
||||
|
||||
+199
-12
@@ -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
|
||||
|
||||
@@ -20,10 +20,11 @@ import {
|
||||
runBadge,
|
||||
runBadgeMetaLine,
|
||||
sortPipelines,
|
||||
stageCountText,
|
||||
summaryFields,
|
||||
versionRow,
|
||||
} from "../pipelines.js";
|
||||
import { PIPELINE_GRAPH_EMPTY, mount as mountGraph } from "../graph.js";
|
||||
import { PIPELINE_GRAPH_EMPTY, layoutGraph, mount as mountGraph } from "../graph.js";
|
||||
import { statusIcon } from "../statusIcon.js";
|
||||
import { writeGraphExpanded } from "../graphPrefs.js";
|
||||
|
||||
@@ -236,6 +237,69 @@ function fillPipelineRows(rowsEl) {
|
||||
rowsEl.replaceChildren(...nodes);
|
||||
}
|
||||
|
||||
// A list row's graph is a shape cue, not a reading surface: tiny nodes and
|
||||
// straight routes, no labels or chips. The detail Graph tab is the real one.
|
||||
const MINI_GRAPH_METRICS = Object.freeze({
|
||||
nodeWidth: 26,
|
||||
nodeHeight: 12,
|
||||
hGap: 12,
|
||||
pad: 2,
|
||||
laneSpacing: 8,
|
||||
terminalGap: 8,
|
||||
trackStep: 6,
|
||||
portSpacing: 4,
|
||||
labelCharWidth: 0,
|
||||
labelPadding: 0,
|
||||
labelHeight: 0,
|
||||
labelGap: 0,
|
||||
});
|
||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||
|
||||
/** The pipeline's stages and their stage-to-stage routes, without terminals. */
|
||||
function miniGraphShape(graph) {
|
||||
const stages = graph?.stages ?? [];
|
||||
const keys = new Set(stages.map((stage) => stage.key));
|
||||
return {
|
||||
stages: stages.map((stage) => ({
|
||||
...stage,
|
||||
edges: Object.fromEntries(
|
||||
Object.entries(stage.edges ?? {}).filter(([, target]) => keys.has(target)),
|
||||
),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function renderPipelineMiniGraph(pipeline) {
|
||||
const shape = pipeline.shape ?? pipeline.graph;
|
||||
if (!shape?.stages?.length) return null;
|
||||
const layout = layoutGraph(miniGraphShape(shape), MINI_GRAPH_METRICS);
|
||||
if (!layout.nodes.length || !layout.width || !layout.height) return null;
|
||||
const svg = document.createElementNS(SVG_NS, "svg");
|
||||
svg.setAttribute("class", "pipeline-mini-graph");
|
||||
svg.setAttribute("viewBox", `0 0 ${Math.ceil(layout.width)} ${Math.ceil(layout.height)}`);
|
||||
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.setAttribute("focusable", "false");
|
||||
for (const edge of layout.edges) {
|
||||
if (edge.points.length < 2) continue;
|
||||
const line = document.createElementNS(SVG_NS, "polyline");
|
||||
line.setAttribute("class", "pipeline-mini-edge");
|
||||
line.setAttribute("points", edge.points.map((point) => `${point.x},${point.y}`).join(" "));
|
||||
svg.append(line);
|
||||
}
|
||||
for (const node of layout.nodes) {
|
||||
const rect = document.createElementNS(SVG_NS, "rect");
|
||||
rect.setAttribute("class", "pipeline-mini-node");
|
||||
rect.setAttribute("x", String(node.x));
|
||||
rect.setAttribute("y", String(node.y));
|
||||
rect.setAttribute("width", String(node.width));
|
||||
rect.setAttribute("height", String(node.height));
|
||||
rect.setAttribute("rx", "3");
|
||||
svg.append(rect);
|
||||
}
|
||||
return h("span", { class: "pipeline-mini", "aria-hidden": "true" }, svg);
|
||||
}
|
||||
|
||||
function renderPipelineRow(pipeline, latestRuns, runsKnown, now) {
|
||||
const children = [
|
||||
h(
|
||||
@@ -244,8 +308,15 @@ function renderPipelineRow(pipeline, latestRuns, runsKnown, now) {
|
||||
pipelineGlyph(),
|
||||
h("span", { class: "row-title", text: pipeline.name || `pipeline ${pipeline.id}` }),
|
||||
),
|
||||
h("span", { class: "row-meta", text: pipelineSubtitle(pipeline) }),
|
||||
];
|
||||
const mini = renderPipelineMiniGraph(pipeline);
|
||||
if (mini) children.push(mini);
|
||||
children.push(
|
||||
h("span", {
|
||||
class: "row-meta",
|
||||
text: stageCountText(pipeline.stages ?? pipeline.shape?.stages?.length ?? 0),
|
||||
}),
|
||||
);
|
||||
const updated = pipelineUpdatedLine(pipeline);
|
||||
if (updated) children.push(h("span", { class: "row-meta", text: updated }));
|
||||
if (runsKnown) {
|
||||
|
||||
Reference in New Issue
Block a user