Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Keep question, view and skill proposal cards in the chat after they close

Fei2411544bf96603f2
diff --git a/ds-bot/client.js b/ds-bot/client.js
index ab9bdf2b..25292c17 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -153,6 +153,8 @@ var ZH = {
"AGENTS.md update": "AGENTS.md 更新",
Approve: "批准",
Decline: "拒绝",
+ Approved: "已批准",
+ Declined: "已拒绝",
"Save changes": "保存更改",
Edit: "编辑",
"Click again to delete.": "再点一次删除。",
@@ -808,7 +810,9 @@ var ZH = {
"Dismiss question": "关闭问题",
Dismiss: "关闭",
Dismissed: "已关闭",
+ "Answered by message": "已用消息回答",
"Your answer": "你的回答",
+ Options: "选项",
// Views
View: "视图",
Confirm: "确认",
@@ -4930,36 +4934,45 @@ function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false,
foot
);
}
-function SettledQuestion({ question, answer }) {
+var closedLabel = (closed) => t(closed === "replied" ? "Answered by message" : "Dismissed");
+function SettledQuestion({ question, answer, closed }) {
const options = optionsOf(question);
const prompt = question?.question ?? "";
- const chosen = [...answer.selected ?? [], ...answer.custom ? [answer.custom] : []];
- if (chosen.length === 0) {
- return (0, import_react8.createElement)(
- "div",
- { className: "bt-q bt-q-settled bt-q-dismissed", role: "group", "aria-label": prompt },
- (0, import_react8.createElement)(
- "div",
- { className: "bt-q-head" },
- (0, import_react8.createElement)("div", { className: "bt-q-text" }, (0, import_react8.createElement)("p", { className: "bt-q-title" }, prompt)),
- (0, import_react8.createElement)("span", { className: "bt-q-badge" }, t("Dismissed"))
- )
- );
+ const selected = Array.isArray(answer?.selected) ? answer.selected : [];
+ const custom = typeof answer?.custom === "string" ? answer.custom.trim() : "";
+ const answered = closed === void 0 && (selected.length > 0 || custom !== "");
+ const row = (key, label, { letter, description, chosen }) => (0, import_react8.createElement)(
+ "div",
+ { key, className: "bt-q-opt" },
+ letter ? (0, import_react8.createElement)("span", { className: "bt-key", "aria-hidden": true }, letter) : null,
+ (0, import_react8.createElement)(
+ "span",
+ { className: "bt-q-body" },
+ (0, import_react8.createElement)("span", { className: "bt-q-label" }, label),
+ description ? (0, import_react8.createElement)("span", { className: "bt-q-desc" }, description) : null
+ ),
+ chosen ? (0, import_react8.createElement)("span", { className: "bt-q-check", title: t("Selected") }, (0, import_react8.createElement)(CheckIcon)) : null
+ );
+ const rows2 = options.map((option, index) => row(`o-${index}`, option.label, { letter: keyLetter(index), description: option.description, chosen: answered && selected.includes(option.label) }));
+ if (answered) {
+ selected.filter((label) => !options.some((option) => option.label === label)).forEach((label, index) => rows2.push(row(`s-${index}`, label, { chosen: true })));
+ if (custom !== "") rows2.push(row("own", custom, { chosen: true }));
}
return (0, import_react8.createElement)(
"div",
- { className: "bt-q bt-q-settled", role: "group", "aria-label": prompt },
- prompt ? (0, import_react8.createElement)("div", { className: "bt-q-head" }, (0, import_react8.createElement)("div", { className: "bt-q-text" }, (0, import_react8.createElement)("p", { className: "bt-q-title" }, prompt))) : null,
- (0, import_react8.createElement)("div", { className: "bt-q-list", role: "group", "aria-label": t("Your answer") }, chosen.map((label, index) => {
- const optionIndex = options.findIndex((option) => option.label === label);
- return (0, import_react8.createElement)(
+ { className: answered ? "bt-q bt-q-settled" : "bt-q bt-q-settled bt-q-dismissed", role: "group", "aria-label": prompt },
+ (0, import_react8.createElement)(
+ "div",
+ { className: "bt-q-head" },
+ (0, import_react8.createElement)(
"div",
- { key: `${label}-${index}`, className: "bt-q-opt" },
- optionIndex >= 0 ? (0, import_react8.createElement)("span", { className: "bt-key", "aria-hidden": true }, keyLetter(optionIndex)) : null,
- (0, import_react8.createElement)("span", { className: "bt-q-body" }, (0, import_react8.createElement)("span", { className: "bt-q-label" }, label)),
- (0, import_react8.createElement)("span", { className: "bt-q-check", title: t("Selected") }, (0, import_react8.createElement)(CheckIcon))
- );
- }))
+ { className: "bt-q-text" },
+ prompt ? (0, import_react8.createElement)("p", { className: "bt-q-title" }, prompt) : null,
+ question?.detail ? (0, import_react8.createElement)("div", { className: "bt-q-detail" }, question.detail) : null
+ ),
+ answered ? null : (0, import_react8.createElement)("span", { className: "bt-q-badge" }, closedLabel(closed))
+ ),
+ rows2.length > 0 ? (0, import_react8.createElement)("div", { className: "bt-q-list", role: "group", "aria-label": t(answered ? "Your answer" : "Options") }, rows2) : null
);
}
function QuestionCard({ matched }) {
@@ -5014,7 +5027,14 @@ function QuestionDock({ sessionId, useRoster, useCards, useHeldCards, actions })
}
function AnsweredCell({ node }) {
const data = node.data ?? {};
- const questions = Array.isArray(data.questions) ? data.questions : [];
+ let sent = null;
+ try {
+ sent = typeof data.text === "string" ? JSON.parse(data.text) : null;
+ } catch {
+ sent = null;
+ }
+ const asked = Array.isArray(sent?.questions) ? sent.questions.filter((item) => typeof item?.id === "string" && typeof item.question === "string") : [];
+ const questions = (Array.isArray(data.questions) ? data.questions : []).map((question) => ({ ...asked.find((item) => item.id === question.id), ...question }));
if (questions.length === 0) {
return data.text ? (0, import_react8.createElement)("div", { className: "bt-urow" }, (0, import_react8.createElement)("div", { className: "bt-ububble" }, data.text)) : (0, import_react8.createElement)(CellEmpty);
}
@@ -8007,11 +8027,18 @@ function WidgetCell({ sessionId, callId, args, done, isError, roster, actions, h
}
if (done && isError) return (0, import_react15.createElement)(CellEmpty, { className: "bt-q-gone" });
const shown = checkShownView(args?.text?.("title"), args?.value?.("view"));
- if (shown.error !== void 0 || shown.interactive || args?.value?.("await_reply") === true) {
- return (0, import_react15.createElement)(CellEmpty, { className: "bt-q-gone" });
+ if (shown.error !== void 0) return (0, import_react15.createElement)(CellEmpty, { className: "bt-q-gone" });
+ if (shown.interactive || args?.value?.("await_reply") === true) {
+ const closed = callId === void 0 ? void 0 : roster.closedCards?.[sessionId]?.[callId];
+ if (closed === void 0) return (0, import_react15.createElement)(CellEmpty, { className: "bt-q-gone" });
+ return (0, import_react15.createElement)(ClosedView, { title: shown.title, view: shown.view, closed });
}
return (0, import_react15.createElement)("div", { className: "bt-q-inline" }, (0, import_react15.createElement)(Card, { title: shown.title, view: shown.view }));
}
+function ClosedView({ title, view, closed }) {
+ const head = (0, import_react15.createElement)("span", { className: "bt-view-closed" }, (0, import_react15.createElement)("span", { className: "bt-view-closed-title" }, title ?? ""), (0, import_react15.createElement)("span", { className: "bt-q-badge" }, closedLabel(closed)));
+ return (0, import_react15.createElement)("div", { className: "bt-q-inline" }, (0, import_react15.createElement)(Card, { title: head, view, settled: true }));
+}
function WidgetDock({ sessionId, useRoster, useCards, useHeldCards, actions }) {
const view = useRoster((value) => value.views?.[sessionId]);
const drawn = useCards?.((state) => state[sessionId]?.[view?.callId] > 0) === true;
@@ -8073,6 +8100,8 @@ body{
.bt-q-inline .dv-q{margin:0;max-width:min(550px,86%);order:0}
body[data-bt-layout=flat] .bt-q-inline .dv-view{max-width:calc(var(--bt-flat-w,1) * 100%)}
.bt-q-inline:has(>.dv-view-bare){margin:8px 0 12px}
+.bt-view-closed{display:flex;align-items:flex-start;gap:8px}
+.bt-view-closed-title{flex:1 1 0;min-width:0}
/* A row of segmented options is only as wide as its labels; at phone widths a
few longer ones would spill past the card. Let them wrap and let a label wrap
inside its own button instead. */
@@ -9856,6 +9885,9 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDel
return (0, import_react21.createElement)(EarlierUser, { key, row, actions });
case "answer":
return (0, import_react21.createElement)(AnsweredReply, { key, node: { data: row } });
+ // A question or view card closed without an answer on it.
+ case "closed":
+ return row.view === void 0 ? (0, import_react21.createElement)("div", { key, className: "bt-q-inline" }, (0, import_react21.createElement)(SettledQuestion, { question: row.question, closed: row.closed })) : (0, import_react21.createElement)(ClosedView, { key, title: row.title, view: row.view, closed: row.closed });
// A display-only view replays from the blueprint the host kept on the call.
case "view":
return (0, import_react21.createElement)(WidgetCell, { key, sessionId, callId: row.callId, args: { text: (name) => name === "title" ? row.title : void 0, value: (name) => name === "view" ? row.view : void 0 }, done: true, isError: false, roster, actions });
@@ -10354,7 +10386,12 @@ function renderCall(call2, { sessionId, roster, actions, useUi, useWork, findBot
}
case "ask_user": {
const question = roster.questions?.[sessionId];
- if (!question || question.callId !== call2.callId) return (0, import_react21.createElement)(CellEmpty, { className: "bt-q-gone" });
+ if (!question || question.callId !== call2.callId) {
+ const closed = roster.closedCards?.[sessionId]?.[call2.callId];
+ if (closed === void 0) return (0, import_react21.createElement)(CellEmpty, { className: "bt-q-gone" });
+ const asked = { question: arg("question") ?? "", detail: arg("detail"), options: argValue("options") ?? [], multiSelect: argValue("multiSelect") === true };
+ return (0, import_react21.createElement)("div", { className: "bt-q-inline" }, (0, import_react21.createElement)(SettledQuestion, { question: asked, closed }));
+ }
if (heldCards?.[heldCardKey("question", question.id)] > 0) return (0, import_react21.createElement)(CellEmpty);
return (0, import_react21.createElement)(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true, enterToSend: sendsOnEnter(roster.prefs) });
}
@@ -24256,18 +24293,20 @@ function serveBrowserReads({ browsers, post, clientId = globalThis.crypto.random
// src/client/learning-card-model.js
function proposalPlacement(proposal, turns) {
- if (!Number.isFinite(proposal?.at) || typeof turns?.values !== "function") return { kind: "dock" };
- let latest;
- let before;
- for (const location2 of turns.values()) {
- const end = location2?.end?.time;
- if (location2?.status !== "closed" || !Number.isFinite(end)) continue;
- const later = (target) => target === void 0 || end > target.end.time || end === target.end.time && location2.turn > target.turn;
- if (later(latest)) latest = location2;
- if (end <= proposal.at && later(before)) before = location2;
- }
- const turn = (before ?? latest)?.turn;
- return turn === void 0 ? { kind: "dock" } : { kind: "turn", turn };
+ const settled = proposal?.outcome !== void 0;
+ if (!Number.isFinite(proposal?.at) || typeof turns?.values !== "function") return { kind: settled ? "none" : "dock" };
+ const lastBy = (time) => {
+ let found;
+ for (const location2 of turns.values()) {
+ const end = location2?.end?.time;
+ if (location2?.status !== "closed" || !Number.isFinite(end) || end > time) continue;
+ if (found === void 0 || end > found.end.time || end === found.end.time && location2.turn > found.turn) found = location2;
+ }
+ return found;
+ };
+ const turn = (lastBy(proposal.at) ?? lastBy(settled ? proposal.settledAt ?? proposal.at : Infinity))?.turn;
+ if (turn === void 0) return { kind: settled ? "none" : "dock" };
+ return { kind: "turn", turn };
}
function fileLines(text) {
const body = String(text ?? "").replace(/\n+$/, "");
@@ -24322,6 +24361,7 @@ function lineDiff(before, after) {
var import_react56 = require("react");
var failedAnswers = /* @__PURE__ */ new Map();
function ProposalCard({ proposal, initialError = "", onFailure, onResolved, actions }) {
+ const outcome = proposal.outcome;
const [busy, setBusy] = (0, import_react56.useState)(false);
const [error, setError] = (0, import_react56.useState)(initialError);
const busyRef = (0, import_react56.useRef)(false);
@@ -24349,26 +24389,26 @@ function ProposalCard({ proposal, initialError = "", onFailure, onResolved, acti
]);
return (0, import_react56.createElement)(
"section",
- { className: "bt-q bt-learning-card", role: "group", "aria-labelledby": titleId, "aria-busy": busy },
- (0, import_react56.createElement)(ProposalHead, { titleId, icon: PencilIcon, title: t("AGENTS.md update") }),
+ { className: "bt-q bt-learning-card", role: "group", "aria-labelledby": titleId, "aria-busy": busy, "data-outcome": outcome },
+ (0, import_react56.createElement)(ProposalHead, { titleId, icon: PencilIcon, title: t("AGENTS.md update"), outcome }),
(0, import_react56.createElement)(FileBox, { name: "AGENTS.md", path: proposal.folder, state: proposal.exists === false ? "Added" : "Modified", blocks }),
proposal.edits.map((edit, index) => edit.why ? (0, import_react56.createElement)("p", { className: "bt-learning-why", key: index }, edit.why) : null),
error ? (0, import_react56.createElement)("div", { className: "bt-learning-error", role: "alert" }, error) : null,
- (0, import_react56.createElement)(ProposalFoot, { busy, answer })
+ outcome ? null : (0, import_react56.createElement)(ProposalFoot, { busy, answer })
);
}
const oldDetail = update && typeof proposal.previous?.description === "string" && proposal.previous.description !== proposal.description ? proposal.previous.description : void 0;
return (0, import_react56.createElement)(
"section",
- { className: "bt-q bt-learning-card", role: "group", "aria-labelledby": titleId, "aria-busy": busy },
- (0, import_react56.createElement)(ProposalHead, { titleId, title: proposal.name, kind: t(update ? "Skill update" : "New skill"), detail: proposal.description, oldDetail }),
+ { className: "bt-q bt-learning-card", role: "group", "aria-labelledby": titleId, "aria-busy": busy, "data-outcome": outcome },
+ (0, import_react56.createElement)(ProposalHead, { titleId, title: proposal.name, kind: t(update ? "Skill update" : "New skill"), detail: proposal.description, oldDetail, outcome }),
(0, import_react56.createElement)(FileBox, { name: "SKILL.md", path: `skills/${proposal.name}`, state: update ? "Updated" : "Added", blocks: [rows2] }),
proposal.why ? (0, import_react56.createElement)("p", { className: "bt-learning-why" }, proposal.why) : null,
error ? (0, import_react56.createElement)("div", { className: "bt-learning-error", role: "alert" }, error) : null,
- (0, import_react56.createElement)(ProposalFoot, { busy, answer })
+ outcome ? null : (0, import_react56.createElement)(ProposalFoot, { busy, answer })
);
}
-function ProposalHead({ titleId, icon: icon2 = MemoryIcon, title, kind, detail, oldDetail }) {
+function ProposalHead({ titleId, icon: icon2 = MemoryIcon, title, kind, detail, oldDetail, outcome }) {
return (0, import_react56.createElement)(
"div",
{ className: "bt-q-head" },
@@ -24381,7 +24421,7 @@ function ProposalHead({ titleId, icon: icon2 = MemoryIcon, title, kind, detail,
oldDetail ? (0, import_react56.createElement)("p", { className: "bt-learning-description bt-learning-old" }, (0, import_react56.createElement)("del", null, oldDetail)) : null,
detail ? (0, import_react56.createElement)("p", { className: "bt-learning-description" }, detail) : null
),
- (0, import_react56.createElement)("span", { className: "bt-q-badge bt-learning-status" }, (0, import_react56.createElement)("span", { className: "bt-learning-dot", "aria-hidden": true }), t("Awaiting approval"))
+ outcome ? (0, import_react56.createElement)("span", { className: "bt-q-badge" }, t(outcome === "approved" ? "Approved" : "Declined")) : (0, import_react56.createElement)("span", { className: "bt-q-badge bt-learning-status" }, (0, import_react56.createElement)("span", { className: "bt-learning-dot", "aria-hidden": true }), t("Awaiting approval"))
);
}
function ProposalFoot({ busy, answer }) {
@@ -24451,13 +24491,15 @@ function LearningProposals({ turn, dock, sessionId, useRoster, actions }) {
const bot = roster.byId?.[sessionId];
if (!bot || currentPart(bot) !== sessionId) return null;
const proposals = roster.learning?.[bot.id] ?? [];
- const visible = [...proposals];
+ const settled = (roster.learningSettled?.[bot.id] ?? []).filter((entry) => !proposals.some((proposal) => proposal.id === entry.id));
+ const visible = [...settled, ...proposals];
for (const entry of Object.values(failed)) {
- if (entry.proposal.botId === bot.id && !proposals.some((proposal) => proposal.id === entry.proposal.id)) visible.push(entry.proposal);
+ if (entry.proposal.botId === bot.id && !visible.some((proposal) => proposal.id === entry.proposal.id)) visible.push(entry.proposal);
}
for (const entry of failedAnswers.values()) {
if (entry.proposal.botId === bot.id && !proposals.some((proposal) => proposal.id === entry.proposal.id) && !visible.some((proposal) => proposal.id === entry.proposal.id)) visible.push(entry.proposal);
}
+ visible.sort((a, b) => (a.at ?? 0) - (b.at ?? 0));
const cards = visible.filter((proposal) => {
const placement = proposalPlacement(proposal, facts?.turns);
return dock ? placement.kind === "dock" : placement.kind === "turn" && placement.turn === turn?.turn;
@@ -24758,6 +24800,7 @@ function apply(ctx) {
if (value.connectors !== void 0 && JSON.stringify(value.connectors) !== JSON.stringify(current.connectors ?? [])) live2.connectors = value.connectors;
if (value.capabilityStatuses !== void 0 && JSON.stringify(value.capabilityStatuses) !== JSON.stringify(current.capabilityStatuses ?? {})) live2.capabilityStatuses = value.capabilityStatuses;
if (value.learning !== void 0 && JSON.stringify(value.learning) !== JSON.stringify(current.learning ?? {})) live2.learning = value.learning;
+ if (value.learningSettled !== void 0 && JSON.stringify(value.learningSettled) !== JSON.stringify(current.learningSettled ?? {})) live2.learningSettled = value.learningSettled;
if (value.btwCards !== void 0 && JSON.stringify(value.btwCards) !== JSON.stringify(current.btwCards ?? {})) live2.btwCards = value.btwCards;
if (value.sideChats !== void 0 && JSON.stringify(value.sideChats) !== JSON.stringify(current.sideChats ?? {})) live2.sideChats = value.sideChats;
if (value.imStatus !== void 0 && JSON.stringify(value.imStatus) !== JSON.stringify(current.imStatus ?? {})) live2.imStatus = value.imStatus;
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 5831bada..eb468da9 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -9,7 +9,7 @@ import { colorOf, toolState, BotMark, RoomAvatar } from './mark.js'
import { CellEmpty } from './cell-empty.js'
import { sendsOnEnter } from './enter-key.js'
import { SettledQuestion, PendingQuestion } from './questions.js'
-import { AnsweredReply, WidgetCell } from './widget-cell.js'
+import { AnsweredReply, ClosedView, WidgetCell } from './widget-cell.js'
import { SecretToolCell } from './secret-card.js'
import { HandoffCall } from './handoff-card.js'
import { AppAccessCall, ComputerCallRow, ComputerHandoffCall } from './computer.js'
@@ -591,6 +591,10 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDel
case 'divider': return h(PartLine, { key, time: row.time })
case 'user': return h(EarlierUser, { key, row, actions })
case 'answer': return h(AnsweredReply, { key, node: { data: row } })
+ // A question or view card closed without an answer on it.
+ case 'closed': return row.view === undefined
+ ? h('div', { key, className: 'bt-q-inline' }, h(SettledQuestion, { question: row.question, closed: row.closed }))
+ : h(ClosedView, { key, title: row.title, view: row.view, closed: row.closed })
// A display-only view replays from the blueprint the host kept on the call.
case 'view': return h(WidgetCell, { key, sessionId, callId: row.callId, args: { text: name => name === 'title' ? row.title : undefined, value: name => name === 'view' ? row.view : undefined }, done: true, isError: false, roster, actions })
case 'bot': {
@@ -1100,8 +1104,14 @@ function renderCall(call, { sessionId, roster, actions, useUi, useWork, findBot,
}
case 'ask_user': {
const question = roster.questions?.[sessionId]
- // Answered or closed: the card leaves no gap where it was.
- if (!question || question.callId !== call.callId) return h(CellEmpty, { className: 'bt-q-gone' })
+ if (!question || question.callId !== call.callId) {
+ // Dismissed or answered by a message: the card stays here, read-only.
+ // Answered on the card: its reply message carries it, so no gap here.
+ const closed = roster.closedCards?.[sessionId]?.[call.callId]
+ if (closed === undefined) return h(CellEmpty, { className: 'bt-q-gone' })
+ const asked = { question: arg('question') ?? '', detail: arg('detail'), options: argValue('options') ?? [], multiSelect: argValue('multiSelect') === true }
+ return h('div', { className: 'bt-q-inline' }, h(SettledQuestion, { question: asked, closed }))
+ }
if (heldCards?.[heldCardKey('question', question.id)] > 0) return h(CellEmpty)
return h(PendingQuestion, { key: JSON.stringify([sessionId, question.id]), sessionId, question, actions, inline: true, enterToSend: sendsOnEnter(roster.prefs) })
}
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index f6836d1f..412a0eef 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -117,6 +117,8 @@ const ZH = {
'AGENTS.md update': 'AGENTS.md 更新',
Approve: '批准',
Decline: '拒绝',
+ Approved: '已批准',
+ Declined: '已拒绝',
'Save changes': '保存更改',
Edit: '编辑',
'Click again to delete.': '再点一次删除。',
@@ -755,7 +757,9 @@ const ZH = {
'Dismiss question': '关闭问题',
Dismiss: '关闭',
Dismissed: '已关闭',
+ 'Answered by message': '已用消息回答',
'Your answer': '你的回答',
+ Options: '选项',
// Views
View: '视图',
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 6612be03..cf32ff11 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -191,6 +191,7 @@ export function apply(ctx) {
if (value.connectors !== undefined && JSON.stringify(value.connectors) !== JSON.stringify(current.connectors ?? [])) live.connectors = value.connectors
if (value.capabilityStatuses !== undefined && JSON.stringify(value.capabilityStatuses) !== JSON.stringify(current.capabilityStatuses ?? {})) live.capabilityStatuses = value.capabilityStatuses
if (value.learning !== undefined && JSON.stringify(value.learning) !== JSON.stringify(current.learning ?? {})) live.learning = value.learning
+ if (value.learningSettled !== undefined && JSON.stringify(value.learningSettled) !== JSON.stringify(current.learningSettled ?? {})) live.learningSettled = value.learningSettled
if (value.btwCards !== undefined && JSON.stringify(value.btwCards) !== JSON.stringify(current.btwCards ?? {})) live.btwCards = value.btwCards
if (value.sideChats !== undefined && JSON.stringify(value.sideChats) !== JSON.stringify(current.sideChats ?? {})) live.sideChats = value.sideChats
if (value.imStatus !== undefined && JSON.stringify(value.imStatus) !== JSON.stringify(current.imStatus ?? {})) live.imStatus = value.imStatus
diff --git a/ds-bot/src/client/learning-card-model.js b/ds-bot/src/client/learning-card-model.js
index 46dc2622..655ceb6e 100644
--- a/ds-bot/src/client/learning-card-model.js
+++ b/ds-bot/src/client/learning-card-model.js
@@ -1,16 +1,22 @@
+// A waiting card goes after the last turn that ended before it was proposed, else
+// after the latest turn, else to the dock. An answered card stays where it was
+// answered: when no turn ended before it was proposed, after the last one that
+// ended before the answer; it never goes to the dock.
export function proposalPlacement(proposal, turns) {
- if (!Number.isFinite(proposal?.at) || typeof turns?.values !== 'function') return { kind: 'dock' }
- let latest
- let before
- for (const location of turns.values()) {
- const end = location?.end?.time
- if (location?.status !== 'closed' || !Number.isFinite(end)) continue
- const later = target => target === undefined || end > target.end.time || (end === target.end.time && location.turn > target.turn)
- if (later(latest)) latest = location
- if (end <= proposal.at && later(before)) before = location
+ const settled = proposal?.outcome !== undefined
+ if (!Number.isFinite(proposal?.at) || typeof turns?.values !== 'function') return { kind: settled ? 'none' : 'dock' }
+ const lastBy = (time) => {
+ let found
+ for (const location of turns.values()) {
+ const end = location?.end?.time
+ if (location?.status !== 'closed' || !Number.isFinite(end) || end > time) continue
+ if (found === undefined || end > found.end.time || (end === found.end.time && location.turn > found.turn)) found = location
+ }
+ return found
}
- const turn = (before ?? latest)?.turn
- return turn === undefined ? { kind: 'dock' } : { kind: 'turn', turn }
+ const turn = (lastBy(proposal.at) ?? lastBy(settled ? proposal.settledAt ?? proposal.at : Infinity))?.turn
+ if (turn === undefined) return { kind: settled ? 'none' : 'dock' }
+ return { kind: 'turn', turn }
}
export function fileLines(text) {
diff --git a/ds-bot/src/client/learning-card.js b/ds-bot/src/client/learning-card.js
index 61d4a526..1287668b 100644
--- a/ds-bot/src/client/learning-card.js
+++ b/ds-bot/src/client/learning-card.js
@@ -8,7 +8,9 @@ import { spring, SPRING_TAP } from './motion.js'
const failedAnswers = new Map()
+// `proposal.outcome` set: an answered card, read-only, with how it ended.
function ProposalCard({ proposal, initialError = '', onFailure, onResolved, actions }) {
+ const outcome = proposal.outcome
const [busy, setBusy] = useState(false)
const [error, setError] = useState(initialError)
const busyRef = useRef(false)
@@ -36,23 +38,23 @@ function ProposalCard({ proposal, initialError = '', onFailure, onResolved, acti
...(edit.op === 'add' ? [] : editLines(edit.old)).map(line => ({ kind: 'removed', line })),
...(edit.op === 'remove' ? [] : editLines(edit.text)).map(line => ({ kind: 'added', line })),
])
- return h('section', { className: 'bt-q bt-learning-card', role: 'group', 'aria-labelledby': titleId, 'aria-busy': busy },
- h(ProposalHead, { titleId, icon: PencilIcon, title: t('AGENTS.md update') }),
+ return h('section', { className: 'bt-q bt-learning-card', role: 'group', 'aria-labelledby': titleId, 'aria-busy': busy, 'data-outcome': outcome },
+ h(ProposalHead, { titleId, icon: PencilIcon, title: t('AGENTS.md update'), outcome }),
h(FileBox, { name: 'AGENTS.md', path: proposal.folder, state: proposal.exists === false ? 'Added' : 'Modified', blocks }),
proposal.edits.map((edit, index) => edit.why ? h('p', { className: 'bt-learning-why', key: index }, edit.why) : null),
error ? h('div', { className: 'bt-learning-error', role: 'alert' }, error) : null,
- h(ProposalFoot, { busy, answer }))
+ outcome ? null : h(ProposalFoot, { busy, answer }))
}
const oldDetail = update && typeof proposal.previous?.description === 'string' && proposal.previous.description !== proposal.description ? proposal.previous.description : undefined
- return h('section', { className: 'bt-q bt-learning-card', role: 'group', 'aria-labelledby': titleId, 'aria-busy': busy },
- h(ProposalHead, { titleId, title: proposal.name, kind: t(update ? 'Skill update' : 'New skill'), detail: proposal.description, oldDetail }),
+ return h('section', { className: 'bt-q bt-learning-card', role: 'group', 'aria-labelledby': titleId, 'aria-busy': busy, 'data-outcome': outcome },
+ h(ProposalHead, { titleId, title: proposal.name, kind: t(update ? 'Skill update' : 'New skill'), detail: proposal.description, oldDetail, outcome }),
h(FileBox, { name: 'SKILL.md', path: `skills/${proposal.name}`, state: update ? 'Updated' : 'Added', blocks: [rows] }),
proposal.why ? h('p', { className: 'bt-learning-why' }, proposal.why) : null,
error ? h('div', { className: 'bt-learning-error', role: 'alert' }, error) : null,
- h(ProposalFoot, { busy, answer }))
+ outcome ? null : h(ProposalFoot, { busy, answer }))
}
-function ProposalHead({ titleId, icon = MemoryIcon, title, kind, detail, oldDetail }) {
+function ProposalHead({ titleId, icon = MemoryIcon, title, kind, detail, oldDetail, outcome }) {
return h('div', { className: 'bt-q-head' },
h('span', { className: 'bt-learning-icon', 'aria-hidden': true }, h(icon)),
h('div', { className: 'bt-q-text' },
@@ -60,7 +62,9 @@ function ProposalHead({ titleId, icon = MemoryIcon, title, kind, detail, oldDeta
kind ? h('div', { className: 'bt-q-detail' }, kind) : null,
oldDetail ? h('p', { className: 'bt-learning-description bt-learning-old' }, h('del', null, oldDetail)) : null,
detail ? h('p', { className: 'bt-learning-description' }, detail) : null),
- h('span', { className: 'bt-q-badge bt-learning-status' }, h('span', { className: 'bt-learning-dot', 'aria-hidden': true }), t('Awaiting approval')))
+ outcome
+ ? h('span', { className: 'bt-q-badge' }, t(outcome === 'approved' ? 'Approved' : 'Declined'))
+ : h('span', { className: 'bt-q-badge bt-learning-status' }, h('span', { className: 'bt-learning-dot', 'aria-hidden': true }), t('Awaiting approval')))
}
function ProposalFoot({ busy, answer }) {
@@ -108,14 +112,17 @@ function LearningProposals({ turn, dock, sessionId, useRoster, actions }) {
const bot = roster.byId?.[sessionId]
if (!bot || currentPart(bot) !== sessionId) return null
const proposals = roster.learning?.[bot.id] ?? []
- const visible = [...proposals]
+ // Answered cards stay in place, read-only; a waiting copy of the same card wins.
+ const settled = (roster.learningSettled?.[bot.id] ?? []).filter(entry => !proposals.some(proposal => proposal.id === entry.id))
+ const visible = [...settled, ...proposals]
for (const entry of Object.values(failed)) {
- if (entry.proposal.botId === bot.id && !proposals.some(proposal => proposal.id === entry.proposal.id)) visible.push(entry.proposal)
+ if (entry.proposal.botId === bot.id && !visible.some(proposal => proposal.id === entry.proposal.id)) visible.push(entry.proposal)
}
for (const entry of failedAnswers.values()) {
if (entry.proposal.botId === bot.id && !proposals.some(proposal => proposal.id === entry.proposal.id)
&& !visible.some(proposal => proposal.id === entry.proposal.id)) visible.push(entry.proposal)
}
+ visible.sort((a, b) => (a.at ?? 0) - (b.at ?? 0))
const cards = visible.filter(proposal => {
const placement = proposalPlacement(proposal, facts?.turns)
return dock ? placement.kind === 'dock' : placement.kind === 'turn' && placement.turn === turn?.turn
diff --git a/ds-bot/src/client/questions.js b/ds-bot/src/client/questions.js
index 1832f2a1..f6e41a57 100644
--- a/ds-bot/src/client/questions.js
+++ b/ds-bot/src/client/questions.js
@@ -139,26 +139,37 @@ function QuestionView({ question, onAnswer, onDismiss, onInteract, busy = false,
foot)
}
-// The answered card left in the transcript: the chosen rows, muted, with a check.
-export function SettledQuestion({ question, answer }) {
+// How a card closed without an answer on it reads on its badge.
+export const closedLabel = closed => t(closed === 'replied' ? 'Answered by message' : 'Dismissed')
+
+// The settled card left in the transcript, read-only: every option, muted, with a
+// check on the chosen ones and the user's own answer below them. A card closed
+// without an answer (`closed`, or no answer) keeps its options and gets a badge.
+export function SettledQuestion({ question, answer, closed }) {
const options = optionsOf(question)
const prompt = question?.question ?? ''
- const chosen = [...(answer.selected ?? []), ...(answer.custom ? [answer.custom] : [])]
- if (chosen.length === 0) {
- return h('div', { className: 'bt-q bt-q-settled bt-q-dismissed', role: 'group', 'aria-label': prompt },
- h('div', { className: 'bt-q-head' },
- h('div', { className: 'bt-q-text' }, h('p', { className: 'bt-q-title' }, prompt)),
- h('span', { className: 'bt-q-badge' }, t('Dismissed'))))
+ const selected = Array.isArray(answer?.selected) ? answer.selected : []
+ const custom = typeof answer?.custom === 'string' ? answer.custom.trim() : ''
+ const answered = closed === undefined && (selected.length > 0 || custom !== '')
+ const row = (key, label, { letter, description, chosen }) => h('div', { key, className: 'bt-q-opt' },
+ letter ? h('span', { className: 'bt-key', 'aria-hidden': true }, letter) : null,
+ h('span', { className: 'bt-q-body' },
+ h('span', { className: 'bt-q-label' }, label),
+ description ? h('span', { className: 'bt-q-desc' }, description) : null),
+ chosen ? h('span', { className: 'bt-q-check', title: t('Selected') }, h(CheckIcon)) : null)
+ const rows = options.map((option, index) => row(`o-${index}`, option.label, { letter: keyLetter(index), description: option.description, chosen: answered && selected.includes(option.label) }))
+ // A chosen label the options no longer list still shows as chosen.
+ if (answered) {
+ selected.filter(label => !options.some(option => option.label === label)).forEach((label, index) => rows.push(row(`s-${index}`, label, { chosen: true })))
+ if (custom !== '') rows.push(row('own', custom, { chosen: true }))
}
- return h('div', { className: 'bt-q bt-q-settled', role: 'group', 'aria-label': prompt },
- prompt ? h('div', { className: 'bt-q-head' }, h('div', { className: 'bt-q-text' }, h('p', { className: 'bt-q-title' }, prompt))) : null,
- h('div', { className: 'bt-q-list', role: 'group', 'aria-label': t('Your answer') }, chosen.map((label, index) => {
- const optionIndex = options.findIndex(option => option.label === label)
- return h('div', { key: `${label}-${index}`, className: 'bt-q-opt' },
- optionIndex >= 0 ? h('span', { className: 'bt-key', 'aria-hidden': true }, keyLetter(optionIndex)) : null,
- h('span', { className: 'bt-q-body' }, h('span', { className: 'bt-q-label' }, label)),
- h('span', { className: 'bt-q-check', title: t('Selected') }, h(CheckIcon)))
- })))
+ return h('div', { className: answered ? 'bt-q bt-q-settled' : 'bt-q bt-q-settled bt-q-dismissed', role: 'group', 'aria-label': prompt },
+ h('div', { className: 'bt-q-head' },
+ h('div', { className: 'bt-q-text' },
+ prompt ? h('p', { className: 'bt-q-title' }, prompt) : null,
+ question?.detail ? h('div', { className: 'bt-q-detail' }, question.detail) : null),
+ answered ? null : h('span', { className: 'bt-q-badge' }, closedLabel(closed))),
+ rows.length > 0 ? h('div', { className: 'bt-q-list', role: 'group', 'aria-label': t(answered ? 'Your answer' : 'Options') }, rows) : null)
}
export function QuestionCard({ matched }) {
@@ -220,7 +231,12 @@ export function QuestionDock({ sessionId, useRoster, useCards, useHeldCards, act
// answer marked.
export function AnsweredCell({ node }) {
const data = node.data ?? {}
- const questions = Array.isArray(data.questions) ? data.questions : []
+ // The reply text is ds-bot's own payload and keeps each question's options; the
+ // pairs DSH reads out of it may drop them.
+ let sent = null
+ try { sent = typeof data.text === 'string' ? JSON.parse(data.text) : null } catch { sent = null }
+ const asked = Array.isArray(sent?.questions) ? sent.questions.filter(item => typeof item?.id === 'string' && typeof item.question === 'string') : []
+ const questions = (Array.isArray(data.questions) ? data.questions : []).map(question => ({ ...asked.find(item => item.id === question.id), ...question }))
if (questions.length === 0) {
return data.text ? h('div', { className: 'bt-urow' }, h('div', { className: 'bt-ububble' }, data.text)) : h(CellEmpty)
}
diff --git a/ds-bot/src/client/widget-cell.js b/ds-bot/src/client/widget-cell.js
index 80110425..d089bbf3 100644
--- a/ds-bot/src/client/widget-cell.js
+++ b/ds-bot/src/client/widget-cell.js
@@ -2,7 +2,7 @@ import { createElement as h, useRef, useState } from 'react'
import { MarkdownText } from './dsh-primitives.js'
import { CellEmpty } from './cell-empty.js'
import { t } from './i18n.js'
-import { AnsweredCell } from './questions.js'
+import { AnsweredCell, closedLabel } from './questions.js'
import { useDockHold } from './card-hold.js'
import { SettledHandoff } from './handoff-card.js'
import { SettledComputerHandoff } from './computer.js'
@@ -59,15 +59,25 @@ export function WidgetCell({ sessionId, callId, args, done, isError, roster, act
// The args accessor reads strings through `text`; `value` drops them.
const shown = checkShownView(args?.text?.('title'), args?.value?.('view'))
// A call the host refused — a blueprint it would not show, or a reply it cannot
- // wait for — leaves no card; the model's retry then stays the only one. So does
- // a settled interactive call: answered, dismissed or replaced, it leaves no gap
- // where it was (same as ask_user).
- if (shown.error !== undefined || shown.interactive || args?.value?.('await_reply') === true) {
- return h(CellEmpty, { className: 'bt-q-gone' })
+ // wait for — leaves no card; the model's retry then stays the only one. An
+ // answered interactive call leaves no gap either: its reply message carries the
+ // card. Dismissed or answered by a message, the card stays here, read-only.
+ if (shown.error !== undefined) return h(CellEmpty, { className: 'bt-q-gone' })
+ if (shown.interactive || args?.value?.('await_reply') === true) {
+ const closed = callId === undefined ? undefined : roster.closedCards?.[sessionId]?.[callId]
+ if (closed === undefined) return h(CellEmpty, { className: 'bt-q-gone' })
+ return h(ClosedView, { title: shown.title, view: shown.view, closed })
}
return h('div', { className: 'bt-q-inline' }, h(Card, { title: shown.title, view: shown.view }))
}
+// A view closed without an answer on it: settled with nothing chosen, and a badge
+// beside its title for how it closed.
+export function ClosedView({ title, view, closed }) {
+ const head = h('span', { className: 'bt-view-closed' }, h('span', { className: 'bt-view-closed-title' }, title ?? ''), h('span', { className: 'bt-q-badge' }, closedLabel(closed)))
+ return h('div', { className: 'bt-q-inline' }, h(Card, { title: head, view, settled: true }))
+}
+
// Views asked by a call the transcript does not draw wait above the composer,
// mirroring the question dock.
export function WidgetDock({ sessionId, useRoster, useCards, useHeldCards, actions }) {
@@ -132,6 +142,8 @@ body{
.bt-q-inline .dv-q{margin:0;max-width:min(550px,86%);order:0}
body[data-bt-layout=flat] .bt-q-inline .dv-view{max-width:calc(var(--bt-flat-w,1) * 100%)}
.bt-q-inline:has(>.dv-view-bare){margin:8px 0 12px}
+.bt-view-closed{display:flex;align-items:flex-start;gap:8px}
+.bt-view-closed-title{flex:1 1 0;min-width:0}
/* A row of segmented options is only as wide as its labels; at phone widths a
few longer ones would spill past the card. Let them wrap and let a label wrap
inside its own button instead. */
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index a832e690..4627e7fb 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -59,6 +59,7 @@ export function install(rt) {
exchangeTurns: state.exchangeTurns,
questions: state.questions,
views: state.views ?? {},
+ closedCards: state.closedCards ?? {},
// Aside answers of each Bot's current part, newest first. Not part of the
// model-visible history; earlier parts send their cards on their own pages.
btwCards: rt.btwView?.() ?? {},
@@ -89,7 +90,8 @@ export function install(rt) {
computer: rt.computerView?.() ?? { enabled: false },
})
// What changes without a new revision, sent with every state answer. `learning`:
- // each Bot's pending skill proposals. `memoryNews`:
+ // each Bot's pending skill proposals; `learningSettled`: the answered ones of its
+ // current chat part. `memoryNews`:
// per Bot or group chat, its latest memory change; `memoryReviews`: memory reviews waiting or
// running; `work`: per Bot, the turn it runs and its tool; per group, the members whose
// turn there runs; the approvals waiting; per Bot, who it waits for to hand back work;
@@ -100,6 +102,7 @@ export function install(rt) {
memoryNews: rt.memoryNews(),
memoryReviews: rt.memoryReviews(),
learning: rt.learningView(),
+ learningSettled: rt.learningSettledView(),
connectors: rt.connectorsView(),
capabilityStatuses: rt.capabilityStatusesView(),
imStatus: rt.imStatusView?.() ?? {},
@@ -396,6 +399,7 @@ export function install(rt) {
case 'dismiss-question':
await rt.load()
if (rt.own(state.questions, body.sessionId) !== undefined) {
+ rt.closeCard(body.sessionId, state.questions[body.sessionId], 'dismissed')
delete state.questions[body.sessionId]
await rt.save()
}
@@ -403,6 +407,7 @@ export function install(rt) {
case 'dismiss-view':
await rt.load()
if (rt.own(state.views, body.sessionId) !== undefined) {
+ rt.closeCard(body.sessionId, state.views[body.sessionId], 'dismissed')
delete state.views[body.sessionId]
await rt.save()
}
diff --git a/ds-bot/src/host/learning.js b/ds-bot/src/host/learning.js
index 6f0a29c5..73a4601d 100644
--- a/ds-bot/src/host/learning.js
+++ b/ds-bot/src/host/learning.js
@@ -299,7 +299,7 @@ export function install(rt) {
const on = config.learning !== false && config.memory !== false
const view = () => ({})
if (!on) {
- Object.assign(rt, { learningView: view, learningEndpoint: async () => { throw new Error('Learning is turned off on this host') }, learningRun: async () => 0 })
+ Object.assign(rt, { learningView: view, learningSettledView: view, learningEndpoint: async () => { throw new Error('Learning is turned off on this host') }, learningRun: async () => 0 })
return
}
@@ -307,7 +307,9 @@ export function install(rt) {
const path = join(root, 'state.json')
// `pending`: Bot id → chats with a long turn since the last pass. `agentsPending`:
// folder → queued work waiting for AGENTS.md review. `cursors`: newest line read.
- // `proposals`: waiting for the user, by id. `learned`: skill names learned by Bot.
+ // `proposals`: waiting for the user, by id. `settled`: answered ones, by id, with
+ // the outcome; their cards stay in the chat part they were answered in.
+ // `learned`: skill names learned by Bot.
let saved
const data = () => {
if (saved !== undefined) return saved
@@ -320,6 +322,7 @@ export function install(rt) {
saved.pending ??= {}
saved.cursors ??= {}
saved.proposals ??= {}
+ saved.settled ??= {}
saved.declined ??= []
saved.learned ??= {}
saved.agentsPending ??= {}
@@ -658,8 +661,15 @@ export function install(rt) {
const store = data()
const proposal = Object.hasOwn(store.proposals, id) ? store.proposals[id] : undefined
if (proposal === undefined) throw Object.assign(new Error('This proposal is no longer open'), { code: 'bot/stale' })
- if (approve !== true) {
+ // The answered card stays where it was, read-only, with how it ended. A waiting
+ // card shows in the Bot's current chat part, so that is where it stays.
+ const settle = (outcome) => {
delete store.proposals[id]
+ const { saved: _saved, ...kept } = proposal
+ store.settled[id] = { ...kept, sessionId: rt.chatOf(proposal.botId), outcome, settledAt: Date.now() }
+ }
+ if (approve !== true) {
+ settle('declined')
const decline = proposal.kind === 'agents'
? { kind: 'agents', folder: proposal.folder, edits: proposal.edits.map(({ op, text, old }) => ({ op, text, old })), at: Date.now() }
: { name: proposal.name, description: proposal.description, at: Date.now() }
@@ -670,7 +680,7 @@ export function install(rt) {
// A failed approval keeps the card, so the user can still decline it.
if (proposal.kind === 'agents') await applyAgents(proposal)
else await applySkill(proposal)
- delete store.proposals[id]
+ settle('approved')
await persist()
return { applied: true }
}
@@ -763,6 +773,14 @@ export function install(rt) {
for (const entry of Object.values(data().proposals)) (byBot[entry.botId] ??= []).push(entry)
return byBot
}
+ // Per Bot, the answered proposals of its current chat part.
+ const learningSettledView = () => {
+ const byBot = {}
+ for (const entry of Object.values(data().settled)) {
+ if (rt.botOf(entry.botId) !== undefined && entry.sessionId === rt.chatOf(entry.botId)) (byBot[entry.botId] ??= []).push(entry)
+ }
+ return byBot
+ }
const capabilityDelete = rt.capabilityDelete
rt.capabilityDelete = async (...args) => {
@@ -777,5 +795,5 @@ export function install(rt) {
return result
}
- Object.assign(rt, { learningView, learningEndpoint, learningRun: run })
+ Object.assign(rt, { learningView, learningSettledView, learningEndpoint, learningRun: run })
}
diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.js
index 5ef8d6f4..62e0e271 100644
--- a/ds-bot/src/host/parts.js
+++ b/ds-bot/src/host/parts.js
@@ -1342,13 +1342,22 @@ export function install(rt) {
if (event.data?.name === 'group_relay') relayCalls.add(event.data?.callId)
// Hidden turns and refused calls never showed a display card. Interactive
// cards live in the pending dock or on their answer message instead.
- if (event.data?.name === 'show_view' && !hidden.has(event.data?.turn)) {
+ const named = event.data?.name
+ if ((named === 'show_view' || named === 'ask_user') && !hidden.has(event.data?.turn)) {
let args = event.data?.arguments
if (typeof args === 'string') { try { args = JSON.parse(args) } catch { args = undefined } }
+ const callId = event.data?.callId ?? null
+ const closed = callId === null ? undefined : rt.own(rt.own(state.closedCards, partId), callId)
+ if (named === 'ask_user') {
+ if (closed !== undefined) items.push({ kind: 'closed', closed, question: { question: String(args?.question ?? ''), ...(args?.detail ? { detail: String(args.detail) } : {}), options: Array.isArray(args?.options) ? args.options : [], multiSelect: args?.multiSelect === true }, callId, time: event.time })
+ continue
+ }
const view = normalizeView(args?.view)
const shown = checkShownView(args?.title, view)
if (shown.error === undefined && !shown.interactive && args?.await_reply !== true) {
- items.push({ kind: 'view', title: shown.title, view, callId: event.data?.callId ?? null, time: event.time })
+ items.push({ kind: 'view', title: shown.title, view, callId, time: event.time })
+ } else if (shown.error === undefined && closed !== undefined) {
+ items.push({ kind: 'closed', closed, title: shown.title, view, callId, time: event.time })
}
}
continue
diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.js
index 1d8cec21..2d54716b 100644
--- a/ds-bot/src/host/roster.js
+++ b/ds-bot/src/host/roster.js
@@ -713,6 +713,7 @@ export function install(rt) {
for (const part of parts) {
delete state.questions[part]
if (state.views !== undefined) delete state.views[part]
+ if (state.closedCards !== undefined) delete state.closedCards[part]
delete state.exchangeTurns[part]
delete state.switching[part]
}
diff --git a/ds-bot/src/host/store.js b/ds-bot/src/host/store.js
index 34c9a842..87675211 100644
--- a/ds-bot/src/host/store.js
+++ b/ds-bot/src/host/store.js
@@ -19,7 +19,7 @@ export function install(rt) {
const { ctx, home, statePath } = rt
/** @type {{version:1, workspaceId?:string, mainBotIds:string[], bots:Record<string,any>, privateArchives:any[], rooms:Record<string,any>, agents:Record<string,any>, capabilities:{items:Record<string,any>}, exchanges:any[], exchangeTurns:Record<string,number[]>, revision:number}} */
- const state = { version: 1, mainBotIds: [], bots: {}, privateArchives: [], rooms: {}, agents: {}, capabilities: { items: {} }, exchanges: [], exchangeTurns: {}, works: {}, requests: {}, questions: {}, views: {}, prefs: {}, switching: {}, revision: 0 }
+ const state = { version: 1, mainBotIds: [], bots: {}, privateArchives: [], rooms: {}, agents: {}, capabilities: { items: {} }, exchanges: [], exchangeTurns: {}, works: {}, requests: {}, questions: {}, views: {}, closedCards: {}, prefs: {}, switching: {}, revision: 0 }
let loaded = null
let writing = Promise.resolve()
const { warn } = rt
@@ -174,6 +174,7 @@ export function install(rt) {
if (state.works === null || typeof state.works !== 'object' || Array.isArray(state.works)) state.works = {}
if (state.requests === null || typeof state.requests !== 'object' || Array.isArray(state.requests)) state.requests = {}
if (state.views === null || typeof state.views !== 'object' || Array.isArray(state.views)) state.views = {}
+ if (state.closedCards === null || typeof state.closedCards !== 'object' || Array.isArray(state.closedCards)) state.closedCards = {}
// LEGACY: aside cards lived in this file only before the feature shipped;
// they are kept under btw/ per part now. A saved copy is dropped, not moved.
if ('btwCards' in state) {
@@ -516,8 +517,16 @@ export function install(rt) {
return () => savedListeners.delete(listener)
}
+ // A question or view card closed without an answer on the card (dismissed, or
+ // answered by a message) stays in the chat, read-only: by Session, its call id
+ // and how it closed. A card answered on the card shows on its reply message.
+ const closeCard = (sessionId, card, outcome) => {
+ if (typeof card?.callId !== 'string') return
+ state.closedCards[sessionId] = { ...own(state.closedCards, sessionId), [card.callId]: outcome }
+ }
+
Object.assign(rt, {
- state, load, save, refresh, readOnly, own, onSaved,
+ state, load, save, refresh, readOnly, own, onSaved, closeCard,
botOf, roomOf, isMain, chatOf, sessionOfRoom, selfOf, isBotSession,
chatOwners, groupOwners, roomOwners, pastOwners,
groupSessionsOf, dropGroupSession, retireGroupSession, findBot, findRooms, isAdminOf,
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index 641d7b31..c0134646 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -846,10 +846,12 @@ export function install(rt) {
// Any user message answers or supersedes the open question card and view card.
let dropped = false
if (state.questions[id] !== undefined) {
+ rt.closeCard(id, state.questions[id], 'replied')
delete state.questions[id]
dropped = true
}
if (state.views?.[id] !== undefined) {
+ rt.closeCard(id, state.views[id], 'replied')
delete state.views[id]
dropped = true
}
diff --git a/ds-bot/test/card-hold.test.js b/ds-bot/test/card-hold.test.js
index 602e7b09..d7ea75d6 100644
--- a/ds-bot/test/card-hold.test.js
+++ b/ds-bot/test/card-hold.test.js
@@ -545,6 +545,16 @@ test('an answered handoff keeps its title and how it ended, and nothing to press
assert.doesNotMatch(returned.props.children[0].props.className, /bt-q-dismissed/)
})
+// The reply node as DSH 0.2.2-rc.1 builds it from a recorded ask_user answer: its
+// question pairs carry no options, the text still holds ds-bot's payload.
+test('an answered question card reads its options from the reply text when DSH drops them', () => {
+ const text = JSON.stringify({ kind: 'answer_to_pending_question', tool: 'ask_user', callId: 'call-2-1', questions: [{ id: 'q1', question: '接下来先做哪个?', options: [{ label: '写正文' }, { label: '改标题' }, { label: '先停' }], multiSelect: false }], answers: [{ id: 'q1', selected: ['改标题'] }] })
+ const cell = AnsweredCell({ node: { data: { callId: 'call-2-1', outcome: 'answered', text, questions: [{ id: 'q1', question: '接下来先做哪个?' }], answers: [{ id: 'q1', selected: ['改标题'] }] } } })
+ const settled = [cell.props.children].flat(2)[0]
+ assert.deepEqual(plain(settled.props.question.options), [{ label: '写正文' }, { label: '改标题' }, { label: '先停' }])
+ assert.deepEqual(plain(settled.props.answer.selected), ['改标题'])
+})
+
test('answered handoff replies route to their settled row in history and live transcripts', () => {
const fromHistory = AnsweredReply({ node: { data: { handoff: { reason: 'login', note: 'Sign in', outcome: 'returned' } } } })
assert.equal(fromHistory.type, SettledHandoff)
diff --git a/ds-bot/test/feed.test.js b/ds-bot/test/feed.test.js
index d1f01b25..8e42407d 100644
--- a/ds-bot/test/feed.test.js
+++ b/ds-bot/test/feed.test.js
@@ -24,9 +24,9 @@ const TEAM = {
const userMessage = (text, time) => ({ type: 'user/message', time, data: { source: { kind: 'user' }, content: [{ type: 'text', text }] } })
const botMessage = (text, time, turn = 1) => ({ type: 'assistant/message', time, data: { turn, message: { content: [{ type: 'text', text }] } } })
-function start({ pages = {}, services = {} } = {}) {
+function start({ pages = {}, services = {}, team = TEAM } = {}) {
const home = mkdtempSync(join(tmpdir(), 'ds-bot-feed-'))
- writeFileSync(join(home, 'state.json'), JSON.stringify(TEAM))
+ writeFileSync(join(home, 'state.json'), JSON.stringify(team))
const ctx = fakeContext({ services })
ctx.sessionController = {
resolveAgent: async sessionId => ({ agent: { session: { id: sessionId, seq: 100 } } }),
@@ -233,6 +233,25 @@ test('a display view is retained when its part becomes earlier history', async (
assert.deepEqual(page.items, [{ kind: 'view', title: 'Earlier card', view, callId: 'old-view', time: 20 }])
})
+test('a question or view card closed without an answer reads back in earlier history; an answered one does not', async (t) => {
+ const options = [{ label: 'Short' }, { label: 'Long' }]
+ const pick = { type: 'options', id: 'lane', options: [{ label: 'Ship now' }] }
+ const events = [
+ { type: 'tool/call', time: 20, seq: 3, data: { turn: 1, callId: 'q-closed', name: 'ask_user', arguments: JSON.stringify({ question: 'Which draft?', options }) } },
+ { type: 'tool/call', time: 21, seq: 4, data: { turn: 1, callId: 'q-answered', name: 'ask_user', arguments: JSON.stringify({ question: 'Answered', options }) } },
+ { type: 'tool/call', time: 22, seq: 5, data: { turn: 1, callId: 'v-closed', name: 'show_view', arguments: JSON.stringify({ title: 'Pick a lane', view: pick }) } },
+ ]
+ const team = { ...TEAM, closedCards: { m1: { 'q-closed': 'replied', 'v-closed': 'dismissed' } } }
+ const { call, stop } = start({ team, pages: { 'm1:end': { records: events.map(event => ({ event })), hasMore: false } } })
+ t.after(stop)
+ await call('state')
+ const page = (await call('earlier', { sessionId: 'm1c' })).value
+ assert.deepEqual(page.items, [
+ { kind: 'closed', closed: 'replied', question: { question: 'Which draft?', options, multiSelect: false }, callId: 'q-closed', time: 20 },
+ { kind: 'closed', closed: 'dismissed', title: 'Pick a lane', view: pick, callId: 'v-closed', time: 22 },
+ ])
+})
+
test('the run-stats endpoint reads DSH\'s figures for the current part of a Bot\'s chat', async (t) => {
const views = { sessionStats: { turns: 3 }, tokenUsage: { cacheReadTokens: 9 }, contextPressure: { contextWindow: 100 } }
const read = []
diff --git a/ds-bot/test/learning-card.test.js b/ds-bot/test/learning-card.test.js
index 72a0b103..36704ade 100644
--- a/ds-bot/test/learning-card.test.js
+++ b/ds-bot/test/learning-card.test.js
@@ -22,6 +22,15 @@ test('a proposal uses the dock when there are no closed turns', () => {
assert.deepEqual(proposalPlacement({ at: 150 }, new Map([[3, { turn: 3, status: 'open' }]])), { kind: 'dock' })
})
+test('an answered proposal stays where it was answered and never goes to the dock', () => {
+ assert.deepEqual(proposalPlacement({ at: 150, outcome: 'approved', settledAt: 900 }, turns), { kind: 'turn', turn: 1 })
+ // Shown after the latest turn while waiting; answered then, it stays there as later turns end.
+ const later = new Map([...turns, [4, { turn: 4, end: { time: 1000 }, status: 'closed' }]])
+ assert.deepEqual(proposalPlacement({ at: 50, outcome: 'declined', settledAt: 300 }, later), { kind: 'turn', turn: 2 })
+ assert.deepEqual(proposalPlacement({ at: 50 }, later), { kind: 'turn', turn: 4 })
+ assert.deepEqual(proposalPlacement({ at: 150, outcome: 'approved', settledAt: 160 }, new Map()), { kind: 'none' })
+})
+
test('a new skill diff marks every line as added', () => {
assert.deepEqual(lineDiff('', 'a\nb\n'), [
{ kind: 'added', line: 'a', number: 1 },
diff --git a/ds-bot/test/learning.test.js b/ds-bot/test/learning.test.js
index 17d8ea18..0c5db9ce 100644
--- a/ds-bot/test/learning.test.js
+++ b/ds-bot/test/learning.test.js
@@ -845,6 +845,12 @@ test('declined proposals are recorded and included in the next skill request', a
assert.equal(runtime.teamState().capabilities.items['release-checks'], undefined)
assert.equal(runtime.learningState().declined[0].name, 'release-checks')
assert.match(runtime.requests[1].messages[0].content[0].text, /Proposals the user declined[\s\S]*- release-checks: Use when checking a release\./)
+ // The declined card stays in the chat part it was answered in, read-only.
+ const view = (await runtime.call('state')).value
+ assert.equal(view.learning.b2, undefined)
+ assert.deepEqual(view.learningSettled.b2.map(entry => [entry.id, entry.name, entry.outcome, entry.sessionId]), [[proposal.id, 'release-checks', 'declined', 'b2']])
+ assert.equal(typeof view.learningSettled.b2[0].settledAt, 'number')
+ assert.equal((await runtime.call('learning-answer', { id: proposal.id, approve: true })).ok, false)
})
test('an update approval fails if the learned skill description alone changed', async t => {
diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.js
index 88ccf350..4f72a7e0 100644
--- a/ds-bot/test/tool-cells.test.js
+++ b/ds-bot/test/tool-cells.test.js
@@ -11,7 +11,7 @@ const { outputFiles } = await build({
contents: [
"export { ToolCell, TriggerCell, callTree, CellEmpty, Bubbles } from './src/client/cells.js'",
"export { stackReplies } from './src/shared/group-replies.js'",
- "export { QuestionDock } from './src/client/questions.js'",
+ "export { QuestionDock, SettledQuestion } from './src/client/questions.js'",
"export { SecretDock } from './src/client/secret-card.js'",
"export { countCards } from './src/client/sources.js'",
"export { ViewMenuList, WidgetView } from './src/client/widget-cell.js'",
@@ -65,7 +65,7 @@ runInNewContext(outputFiles[0].text, {
throw new Error(`Unexpected platform module ${name}`)
},
})
-const { ToolCell, TriggerCell, callTree, stackReplies, CellEmpty, Bubbles, QuestionDock, SecretDock, countCards, ViewMenuList, WidgetView } = module.exports
+const { ToolCell, TriggerCell, callTree, stackReplies, CellEmpty, Bubbles, QuestionDock, SettledQuestion, SecretDock, countCards, ViewMenuList, WidgetView } = module.exports
// Runs the effects collected since the last render; returns the cleanups.
const mount = () => {
@@ -891,6 +891,38 @@ test('a reaction on a group post stays on that post, also after it draws again',
assert.deepEqual([chips(draw(first)), chips(draw(sameTurn)), chips(draw(later))], [0, 0, 1])
})
+test('a question or view card closed without an answer on it stays at its call, read-only, with how it closed', () => {
+ const asked = { question: 'Which draft?', detail: 'Pick one', options: [{ label: 'Short', description: 'One page' }, 'Long'] }
+ const pick = { title: 'Pick a lane', view: { type: 'options', id: 'lane', options: [{ label: 'Ship now' }, { label: 'One more pass' }] } }
+ const roster = team({ questions: {}, views: {}, closedCards: { [chief.id]: { 'q-dismissed': 'dismissed', 'q-replied': 'replied', 'v-dismissed': 'dismissed' } } })
+ const dismissed = show(call('ask_user', 'q-dismissed', { args: asked }), { roster })
+ assert.equal(find(dismissed, node => node.props?.className === 'bt-q-gone'), undefined)
+ assert.equal(text(find(dismissed, node => node.props?.className === 'bt-q-badge')), 'Dismissed')
+ assert.deepEqual(findAll(dismissed, node => node.props?.className === 'bt-q-label').map(text), ['Short', 'Long'])
+ assert.match(text(dismissed), /Which draft\?.*Pick one.*One page/)
+ assert.equal(find(dismissed, node => node.props?.className === 'bt-q-check'), undefined)
+ assert.equal(find(dismissed, node => node.type === 'button'), undefined)
+ const replied = show(call('ask_user', 'q-replied', { args: asked }), { roster })
+ assert.equal(text(find(replied, node => node.props?.className === 'bt-q-badge')), 'Answered by message')
+ // Answered on the card: the reply message carries the card, the call leaves no gap.
+ const answered = show(call('ask_user', 'q-answered', { args: asked }), { roster })
+ assert.ok(find(answered, node => node.props?.className === 'bt-q-gone') !== undefined)
+ const view = show(call('show_view', 'v-dismissed', { args: pick }), { roster })
+ assert.match(text(view), /Pick a lane.*Dismissed.*Ship now.*One more pass/)
+ assert.ok(find(view, node => typeof node.props?.className === 'string' && node.props.className.includes('dv-q-settled')) !== undefined)
+ assert.equal(find(view, node => node.type === 'button' && !node.props?.disabled), undefined)
+ assert.ok(find(show(call('show_view', 'v-answered', { args: pick }), { roster }), node => node.props?.className === 'bt-q-gone') !== undefined)
+})
+
+test('an answered question card keeps every option, with a check on the chosen one and the own answer below', () => {
+ const question = { id: 'q', question: 'Which draft?', options: [{ label: 'Short' }, { label: 'Long' }, { label: 'None' }] }
+ const out = expand(SettledQuestion({ question, answer: { selected: ['Long'], custom: 'Both, really' } }))
+ const rows = findAll(out, node => node.props?.className === 'bt-q-opt')
+ assert.deepEqual(rows.map(row => text(find(row, node => node.props?.className === 'bt-q-label'))), ['Short', 'Long', 'None', 'Both, really'])
+ assert.deepEqual(rows.map(row => find(row, node => node.props?.className === 'bt-q-check') !== undefined), [false, true, false, true])
+ assert.equal(find(out, node => node.props?.className === 'bt-q-badge'), undefined)
+})
+
test('a show_view call the host refused draws nothing; a display-only card draws with the trimmed title', () => {
const cell = (title, view, extra = {}) => show(call('show_view', 'view-call', { args: { title, view, ...extra } }), { roster: team({ views: {} }) })
const gone = (node) => {
diff --git a/ds-bot/test/view-reply.test.js b/ds-bot/test/view-reply.test.js
index 6b22b5f3..0dd06fe3 100644
--- a/ds-bot/test/view-reply.test.js
+++ b/ds-bot/test/view-reply.test.js
@@ -209,7 +209,7 @@ test('view-reply claims the card, refuses a stale or invalid answer, and restore
assert.equal(again.error.message, 'This view is no longer open')
})
-test('dismiss-view drops the open view and leaves a question card alone', async (t) => {
+test('dismiss-view drops the open view, keeps it as a closed card, and leaves a question card alone', async (t) => {
const { show, call, team, stop } = await start()
t.after(stop)
await rt.teamTools.find(d => d.name === 'list_bots').execute({}, { agent: { id: 'chief' } })
@@ -222,7 +222,20 @@ test('dismiss-view drops the open view and leaves a question card alone', async
const open = await team()
assert.equal(open.views['writer-now'], undefined)
assert.equal(open.questions['writer-now'].question, 'Keep me')
+ assert.deepEqual(open.closedCards, { 'writer-now': { 'call-1': 'dismissed' } })
assert.equal((await call('dismiss-view', { sessionId: 'writer-now' })).ok, true)
+ assert.equal((await call('dismiss-question', { sessionId: 'writer-now' })).ok, true)
+ assert.deepEqual((await team()).closedCards, { 'writer-now': { 'call-1': 'dismissed', 'q-call': 'dismissed' } })
+})
+
+test('an answered view is not kept as a closed card: its reply message carries it', async (t) => {
+ const { show, call, team, stop } = await start()
+ t.after(stop)
+ await rt.teamTools.find(d => d.name === 'list_bots').execute({}, { agent: { id: 'chief' } })
+ await show('writer-now', { title: 'Pick', view: CHOICES })
+ const pending = (await team()).views['writer-now']
+ assert.equal((await call('view-reply', { sessionId: 'writer-now', viewId: pending.id, action: 'pick', values: { selected: ['A'] } })).ok, true)
+ assert.deepEqual((await team()).closedCards, {})
})
test('a user message drops the open question and the open view together', async (t) => {
@@ -240,6 +253,8 @@ test('a user message drops the open question and the open view together', async
const open = await team()
assert.equal(open.questions['writer-now'], undefined)
assert.equal(open.views['writer-now'], undefined)
+ // Both cards stay in the chat as answered by that message.
+ assert.deepEqual(open.closedCards, { 'writer-now': { 'q-call': 'replied', 'call-1': 'replied' } })
})
test('show_view measures the bytes the model sent, before unwrapping the provider encoding', async (t) => {