Skip to content

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

Let users delete legacy btw cards

klarkxyc74fe174e04a
diff --git a/docs/plans/2026-10-21-btw.md b/docs/plans/2026-10-21-btw.md
index 6df44b02..53aa34f5 100644
--- a/docs/plans/2026-10-21-btw.md
+++ b/docs/plans/2026-10-21-btw.md
@@ -49,7 +49,7 @@ Bot 之间也有反方向「拉」事实的需求(我需要对方掌握的事
### 旧的 `/btw` 卡片
-- `/btw` 命令移除,输入 `/btw` 按普通文本发出。已有问答卡片留在原处只读展示:已关闭回合的卡片挂在回合尾,回合还开着或找不到所属回合的卡片挂在输入框上方的泊位;不提供取消。
+- `/btw` 命令移除,输入 `/btw` 按普通文本发出。已有问答卡片留在原处,内容只读:已关闭回合的卡片挂在回合尾,回合还开着或找不到所属回合的卡片挂在输入框上方的泊位。卡片头提供删除入口;删除只移除这张卡片及其持久化记录,不在升级时自动清空或迁移。
## 不做什么
@@ -72,3 +72,4 @@ Bot 之间也有反方向「拉」事实的需求(我需要对方掌握的事
- 2026-10-23:评审反馈(#413):去掉 btw 自定的输出上限(2000 token),改用路由自身的上限——思考与答案共享输出预算,自定的低上限会让思考模型的 btw 经常以截断失败收场。卡片每 Bot 20 条的上限维持不变。
- 2026-10-23:去掉条数、字数和并发上限,卡片按分段存文件。
- 2026-10-24:/btw 改成侧边栏里的 Side chat(#489):`/side` 开常驻侧边对话,一个 Bot 可有多条,侧栏标签页管理;追问带同一条对话已答完的问答对,每次提问仍取新快照;收起面板保留,关标签页才删除;旧 /btw 卡片原地只读。
+- 2026-10-25:旧 /btw 卡片保留内容只读,但允许用户逐张删除(#550);不再让无处归位的旧卡片永久占据输入框上方。
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 11627b2b..1fecfa24 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -851,12 +851,12 @@ var ZH = {
"Deleted group chat": "已删除的群聊",
"Group chat": "群聊",
"Own chat": "单聊",
- "Side question": "旁路问答",
"Side chat": "侧边对话",
"New browser tab": "新建浏览器页",
Terminal: "终端",
Files: "文件树",
"Close side chat": "关闭侧边对话",
+ "Delete side chat": "删除侧边对话",
"Ask without interrupting": "不打断当前工作,顺便问一句",
"Ask about the work so far": "问问目前做到哪了",
"Answering…": "正在回答…",
@@ -1625,6 +1625,7 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards
dismissQuestion: (sessionId) => after(call2("dismiss-question", { sessionId })),
answerView: (sessionId, viewId, action, values) => after(call2("view-reply", { sessionId: partFor(sessionId), viewId, action, values })),
dismissView: (sessionId) => after(call2("dismiss-view", { sessionId: partFor(sessionId) })),
+ deleteBtw: (sessionId, cardId) => after(call2("btw-delete", { sessionId, cardId })),
answerApproval: (id, choice) => after(call2("approval-answer", { id, choice })),
stopMemberWork: (roomId, botId) => after(call2("stop-member-work", { roomId, botId })),
// Values go out in these requests and never come back in a response.
@@ -3431,6 +3432,7 @@ div:has(> nav [class*="_marks"]){display:none!important}
.bt-btw-time,.bt-btw-status{flex:none;color:var(--bt-ink-3);font-size:11px;line-height:14px;font-variant-numeric:tabular-nums}
.bt-btw-cancel{margin-left:auto}
.bt-btw-cancel:disabled{opacity:.55;cursor:default}
+.bt-btw-delete{flex:none;margin:-4px}
.bt-btw-note{margin:4px 0 0;color:var(--bt-ink-3);font-size:12px;line-height:16px}
.bt-btw-body{margin-top:6px}
.bt-btw-answer{font-size:14px;line-height:20px}
@@ -6925,8 +6927,9 @@ function stampOf(card) {
const time = Number.isFinite(card.finishedAt) ? card.finishedAt : card.createdAt;
return Number.isFinite(time) ? time : void 0;
}
-function BtwCardView({ card, compact: compact2 = false }) {
+function BtwCardView({ card, compact: compact2 = false, sessionId, actions, onDeleted }) {
const [open, setOpen] = (0, import_react11.useState)(card?.status !== "answering");
+ const [deleting, setDeleting] = (0, import_react11.useState)(false);
(0, import_react11.useEffect)(() => {
if (card?.status && card.status !== "answering") setOpen(true);
}, [card?.status]);
@@ -6935,6 +6938,18 @@ function BtwCardView({ card, compact: compact2 = false }) {
const answer = typeof card.answer === "string" ? card.answer : "";
const when3 = stampOf(card);
const answering = card.status === "answering";
+ const remove = async () => {
+ if (deleting) return;
+ setDeleting(true);
+ try {
+ const result = await actions.deleteBtw(card.partId ?? sessionId, card.id);
+ if (result?.deleted) onDeleted?.(card.id);
+ else setDeleting(false);
+ } catch (error) {
+ actions.reportError(error, "btw-delete");
+ setDeleting(false);
+ }
+ };
return (0, import_react11.createElement)(
"div",
{
@@ -6942,7 +6957,7 @@ function BtwCardView({ card, compact: compact2 = false }) {
"data-open": open || void 0,
"data-status": card.status,
role: "region",
- "aria-label": t("Side question")
+ "aria-label": t("Side chat")
},
(0, import_react11.createElement)(
"div",
@@ -6960,7 +6975,17 @@ function BtwCardView({ card, compact: compact2 = false }) {
),
when3 !== void 0 ? (0, import_react11.createElement)("time", { className: "bt-btw-time", dateTime: new Date(when3).toISOString() }, messageClock(when3)) : null,
answering ? (0, import_react11.createElement)("span", { className: "bt-shimmer" }, t("Answering…")) : null,
- card.status === "cancelled" ? (0, import_react11.createElement)("span", { className: "bt-btw-status" }, t("Cancelled")) : null
+ card.status === "cancelled" ? (0, import_react11.createElement)("span", { className: "bt-btw-status" }, t("Cancelled")) : null,
+ (0, import_react11.createElement)("button", {
+ type: "button",
+ className: "bt-icon-btn bt-btw-delete",
+ disabled: deleting,
+ "aria-label": t("Delete side chat"),
+ title: t("Delete side chat"),
+ onClick: () => {
+ void remove();
+ }
+ }, (0, import_react11.createElement)(CloseIcon))
),
(0, import_react11.createElement)("p", { className: "bt-btw-note" }, t("Answered from progress so far; nothing was run")),
open ? (0, import_react11.createElement)(
@@ -6994,14 +7019,14 @@ function BtwDock({ sessionId, useRoster, actions }) {
const facts = useTurnFacts(sessionId, actions);
const cards = dockCards(sessionCards(roster, sessionId), facts);
if (cards.length === 0) return null;
- return (0, import_react11.createElement)("div", { className: "bt-btw-dock" }, cards.map((card) => (0, import_react11.createElement)(BtwCardView, { key: card.id, card, compact: true })));
+ return (0, import_react11.createElement)("div", { className: "bt-btw-dock" }, cards.map((card) => (0, import_react11.createElement)(BtwCardView, { key: card.id, card, compact: true, sessionId, actions })));
}
function BtwTurnTail({ turn, sessionId, useRoster, actions }) {
const roster = useRoster((value) => value);
const facts = useTurnFacts(sessionId, actions);
const cards = tailCards(sessionCards(roster, sessionId), turn, facts?.turns);
if (cards.length === 0) return null;
- return (0, import_react11.createElement)("div", { className: "bt-btw-stack" }, cards.map((card) => (0, import_react11.createElement)(BtwCardView, { key: card.id, card })));
+ return (0, import_react11.createElement)("div", { className: "bt-btw-stack" }, cards.map((card) => (0, import_react11.createElement)(BtwCardView, { key: card.id, card, sessionId, actions })));
}
// src/client/cells.js
@@ -7493,6 +7518,10 @@ function EarlierParts({ sessionId, roster, actions }) {
observer.observe(node);
return () => observer.disconnect();
}, [view.cursor, view.loading, view.failed]);
+ const removeBtw = (cardId) => setView((current) => ({
+ ...current,
+ pages: current.pages.map((page) => ({ ...page, btw: page.btw.filter((card) => card?.id !== cardId) }))
+ }));
const items = [];
for (const page of view.pages) items.push(...withBtwRows(page.items, page.btw));
return (0, import_react12.createElement)(
@@ -7503,11 +7532,11 @@ function EarlierParts({ sessionId, roster, actions }) {
{ ref: top, className: "bt-earlier-top" },
view.loading ? (0, import_react12.createElement)(Shimmer, null, t("Loading earlier messages…")) : view.failed ? (0, import_react12.createElement)("button", { type: "button", className: "bt-soft", onClick: () => load(view.cursor) }, t("Couldn’t load earlier messages · Retry")) : view.cursor ? (0, import_react12.createElement)("button", { type: "button", className: "bt-soft", onClick: () => load(view.cursor) }, t("Load earlier")) : null
),
- (0, import_react12.createElement)(ChatRows, { items, sessionId, roster, actions }),
+ (0, import_react12.createElement)(ChatRows, { items, sessionId, roster, actions, onBtwDelete: removeBtw }),
(0, import_react12.createElement)(PartLine, { time: view.startedAt })
);
}
-function ChatRows({ items, sessionId, roster, actions, useUi, clock: clock4 = false }) {
+function ChatRows({ items, sessionId, roster, actions, useUi, clock: clock4 = false, onBtwDelete }) {
const selfId = roster.byId[sessionId]?.id;
const rows2 = [];
for (const item of items) {
@@ -7520,7 +7549,7 @@ function ChatRows({ items, sessionId, roster, actions, useUi, clock: clock4 = fa
let before;
return rows2.flatMap((row, index) => {
const key = rows2.length - index;
- const shown = chatRow(row, key, { sessionId, selfId, roster, actions, useUi });
+ const shown = chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelete });
if (row.kind === "divider") {
before = void 0;
return [shown];
@@ -7530,7 +7559,7 @@ function ChatRows({ items, sessionId, roster, actions, useUi, clock: clock4 = fa
return pause ? [(0, import_react12.createElement)("div", { key: `${key}:clock`, className: "bt-time-sep", role: "separator" }, clockLabel(row.time)), shown] : [shown];
});
}
-function chatRow(row, key, { sessionId, selfId, roster, actions, useUi }) {
+function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelete }) {
switch (row.kind) {
case "divider":
return (0, import_react12.createElement)(PartLine, { key, time: row.time });
@@ -7547,7 +7576,7 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi }) {
return speaker ? (0, import_react12.createElement)(import_react12.Fragment, { key }, (0, import_react12.createElement)(SpeakerHead, { bot: speaker, time: row.time }), bubbles) : bubbles;
}
case "btw":
- return (0, import_react12.createElement)(BtwCardView, { key, card: row.card, actions });
+ return (0, import_react12.createElement)(BtwCardView, { key, card: row.card, sessionId, actions, onDeleted: onBtwDelete });
case "event": {
if (row.role === "report") return (0, import_react12.createElement)(GroupEvent, { key, prefix: t("Replies from"), room: roster.roomsById[row.roomId], name: t("a group chat"), roster, actions });
const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };
diff --git a/ds-bot/src/client/btw.js b/ds-bot/src/client/btw.js
index c13b257f..c8f119d2 100644
--- a/ds-bot/src/client/btw.js
+++ b/ds-bot/src/client/btw.js
@@ -1,7 +1,9 @@
-// The earlier `/btw` aside cards, kept read-only where they already appear.
+// The earlier `/btw` aside cards. Their contents are read-only; the user can
+// delete a card when it is no longer wanted.
import { createElement as h, useEffect, useState } from 'react'
import { MarkdownText } from './dsh-primitives.js'
import { hostText, t } from './i18n.js'
+import { CloseIcon } from './icons.js'
import { messageClock } from './text.js'
import { dockCards, sessionCards, tailCards } from './btw-model.js'
@@ -18,8 +20,9 @@ function stampOf(card) {
return Number.isFinite(time) ? time : undefined
}
-export function BtwCardView({ card, compact = false }) {
+export function BtwCardView({ card, compact = false, sessionId, actions, onDeleted }) {
const [open, setOpen] = useState(card?.status !== 'answering')
+ const [deleting, setDeleting] = useState(false)
useEffect(() => {
if (card?.status && card.status !== 'answering') setOpen(true)
}, [card?.status])
@@ -28,12 +31,24 @@ export function BtwCardView({ card, compact = false }) {
const answer = typeof card.answer === 'string' ? card.answer : ''
const when = stampOf(card)
const answering = card.status === 'answering'
+ const remove = async () => {
+ if (deleting) return
+ setDeleting(true)
+ try {
+ const result = await actions.deleteBtw(card.partId ?? sessionId, card.id)
+ if (result?.deleted) onDeleted?.(card.id)
+ else setDeleting(false)
+ } catch (error) {
+ actions.reportError(error, 'btw-delete')
+ setDeleting(false)
+ }
+ }
return h('div', {
className: compact ? 'bt-btw bt-btw-compact' : 'bt-btw',
'data-open': open || undefined,
'data-status': card.status,
role: 'region',
- 'aria-label': t('Side question'),
+ 'aria-label': t('Side chat'),
},
h('div', { className: 'bt-btw-head' },
h('button', {
@@ -44,7 +59,11 @@ export function BtwCardView({ card, compact = false }) {
h('span', { className: 'bt-btw-q' }, question)),
when !== undefined ? h('time', { className: 'bt-btw-time', dateTime: new Date(when).toISOString() }, messageClock(when)) : null,
answering ? h('span', { className: 'bt-shimmer' }, t('Answering…')) : null,
- card.status === 'cancelled' ? h('span', { className: 'bt-btw-status' }, t('Cancelled')) : null),
+ card.status === 'cancelled' ? h('span', { className: 'bt-btw-status' }, t('Cancelled')) : null,
+ h('button', {
+ type: 'button', className: 'bt-icon-btn bt-btw-delete', disabled: deleting,
+ 'aria-label': t('Delete side chat'), title: t('Delete side chat'), onClick: () => { void remove() },
+ }, h(CloseIcon))),
h('p', { className: 'bt-btw-note' }, t('Answered from progress so far; nothing was run')),
open ? h('div', { className: 'bt-btw-body' },
card.status === 'failed' ? h('p', { className: 'bt-btw-fail' }, failureText(card)) : null,
@@ -68,13 +87,13 @@ function useTurnFacts(sessionId, actions) {
}
// Cards whose turn is still open, or that no closed turn owns, sit in the
-// composer dock. Read-only like the rest: no new cards can arrive.
+// composer dock. No new cards can arrive, and old ones leave when deleted.
export function BtwDock({ sessionId, useRoster, actions }) {
const roster = useRoster(value => value)
const facts = useTurnFacts(sessionId, actions)
const cards = dockCards(sessionCards(roster, sessionId), facts)
if (cards.length === 0) return null
- return h('div', { className: 'bt-btw-dock' }, cards.map(card => h(BtwCardView, { key: card.id, card, compact: true })))
+ return h('div', { className: 'bt-btw-dock' }, cards.map(card => h(BtwCardView, { key: card.id, card, compact: true, sessionId, actions })))
}
export function BtwTurnTail({ turn, sessionId, useRoster, actions }) {
@@ -82,5 +101,5 @@ export function BtwTurnTail({ turn, sessionId, useRoster, actions }) {
const facts = useTurnFacts(sessionId, actions)
const cards = tailCards(sessionCards(roster, sessionId), turn, facts?.turns)
if (cards.length === 0) return null
- return h('div', { className: 'bt-btw-stack' }, cards.map(card => h(BtwCardView, { key: card.id, card })))
+ return h('div', { className: 'bt-btw-stack' }, cards.map(card => h(BtwCardView, { key: card.id, card, sessionId, actions })))
}
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 81377b96..439eba8b 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -476,6 +476,10 @@ function EarlierParts({ sessionId, roster, actions }) {
observer.observe(node)
return () => observer.disconnect()
}, [view.cursor, view.loading, view.failed])
+ const removeBtw = cardId => setView(current => ({
+ ...current,
+ pages: current.pages.map(page => ({ ...page, btw: page.btw.filter(card => card?.id !== cardId) })),
+ }))
const items = []
for (const page of view.pages) items.push(...withBtwRows(page.items, page.btw))
return h('div', { className: 'bt-earlier', role: 'feed', 'aria-label': t('Earlier messages'), 'aria-busy': view.loading },
@@ -483,14 +487,14 @@ function EarlierParts({ sessionId, roster, actions }) {
view.loading ? h(Shimmer, null, t('Loading earlier messages…'))
: view.failed ? h('button', { type: 'button', className: 'bt-soft', onClick: () => load(view.cursor) }, t('Couldn’t load earlier messages · Retry'))
: view.cursor ? h('button', { type: 'button', className: 'bt-soft', onClick: () => load(view.cursor) }, t('Load earlier')) : null),
- h(ChatRows, { items, sessionId, roster, actions }),
+ h(ChatRows, { items, sessionId, roster, actions, onBtwDelete: removeBtw }),
h(PartLine, { time: view.startedAt }))
}
// A Bot chat's entries as the host lists them (the `earlier` and `chat` endpoints): the
// Bot's messages in a row are one block, and a thin line marks where a part begins.
// `clock` adds the time separators: one above the first entry, and one after each pause.
-export function ChatRows({ items, sessionId, roster, actions, useUi, clock = false }) {
+export function ChatRows({ items, sessionId, roster, actions, useUi, clock = false, onBtwDelete }) {
const selfId = roster.byId[sessionId]?.id
const rows = []
for (const item of items) {
@@ -504,7 +508,7 @@ export function ChatRows({ items, sessionId, roster, actions, useUi, clock = fal
return rows.flatMap((row, index) => {
// Pages are prepended, so a row keeps its distance from the end.
const key = rows.length - index
- const shown = chatRow(row, key, { sessionId, selfId, roster, actions, useUi })
+ const shown = chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelete })
// A part's first entry shows its time under the part's line, as a chat's first one does.
if (row.kind === 'divider') {
before = undefined
@@ -517,7 +521,7 @@ export function ChatRows({ items, sessionId, roster, actions, useUi, clock = fal
}
// `useUi` gives a block its reactions and its Reply tool.
-function chatRow(row, key, { sessionId, selfId, roster, actions, useUi }) {
+function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelete }) {
switch (row.kind) {
case 'divider': return h(PartLine, { key, time: row.time })
case 'user': return h(EarlierUser, { key, row })
@@ -529,7 +533,7 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi }) {
const speaker = layoutOf(roster.prefs) === 'flat' ? roster.byId[selfId] : undefined
return speaker ? h(Fragment, { key }, h(SpeakerHead, { bot: speaker, time: row.time }), bubbles) : bubbles
}
- case 'btw': return h(BtwCardView, { key, card: row.card, actions })
+ case 'btw': return h(BtwCardView, { key, card: row.card, sessionId, actions, onDeleted: onBtwDelete })
case 'event': {
if (row.role === 'report') return h(GroupEvent, { key, prefix: t('Replies from'), room: roster.roomsById[row.roomId], name: t('a group chat'), roster, actions })
const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 3eb93caa..14d971e9 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -803,12 +803,12 @@ const ZH = {
'Deleted group chat': '已删除的群聊',
'Group chat': '群聊',
'Own chat': '单聊',
- 'Side question': '旁路问答',
'Side chat': '侧边对话',
'New browser tab': '新建浏览器页',
Terminal: '终端',
Files: '文件树',
'Close side chat': '关闭侧边对话',
+ 'Delete side chat': '删除侧边对话',
'Ask without interrupting': '不打断当前工作,顺便问一句',
'Ask about the work so far': '问问目前做到哪了',
'Answering…': '正在回答…',
diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.js
index a6f607f0..29dbf03f 100644
--- a/ds-bot/src/client/styles.js
+++ b/ds-bot/src/client/styles.js
@@ -1118,6 +1118,7 @@ div:has(> nav [class*="_marks"]){display:none!important}
.bt-btw-time,.bt-btw-status{flex:none;color:var(--bt-ink-3);font-size:11px;line-height:14px;font-variant-numeric:tabular-nums}
.bt-btw-cancel{margin-left:auto}
.bt-btw-cancel:disabled{opacity:.55;cursor:default}
+.bt-btw-delete{flex:none;margin:-4px}
.bt-btw-note{margin:4px 0 0;color:var(--bt-ink-3);font-size:12px;line-height:16px}
.bt-btw-body{margin-top:6px}
.bt-btw-answer{font-size:14px;line-height:20px}
diff --git a/ds-bot/src/client/team-actions.js b/ds-bot/src/client/team-actions.js
index d8ada868..1b96ac5f 100644
--- a/ds-bot/src/client/team-actions.js
+++ b/ds-bot/src/client/team-actions.js
@@ -97,6 +97,7 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, hel
dismissQuestion: sessionId => after(call('dismiss-question', { sessionId })),
answerView: (sessionId, viewId, action, values) => after(call('view-reply', { sessionId: partFor(sessionId), viewId, action, values })),
dismissView: sessionId => after(call('dismiss-view', { sessionId: partFor(sessionId) })),
+ deleteBtw: (sessionId, cardId) => after(call('btw-delete', { sessionId, cardId })),
answerApproval: (id, choice) => after(call('approval-answer', { id, choice })),
stopMemberWork: (roomId, botId) => after(call('stop-member-work', { roomId, botId })),
// Values go out in these requests and never come back in a response.
diff --git a/ds-bot/src/host/btw.js b/ds-bot/src/host/btw.js
index ab0303ba..c4d5a59a 100644
--- a/ds-bot/src/host/btw.js
+++ b/ds-bot/src/host/btw.js
@@ -1,5 +1,5 @@
// Aside cards (btw) are the earlier single-shot aside: the ask path is gone,
-// but existing cards stay where they are and stay readable. This file keeps
+// but existing cards stay readable until the user deletes them. This file keeps
// their files, their turn placement, and the shared snapshot/model-call
// helpers that side chats (side.js) use.
// Cards live in a file per Bot and part (<home>/btw/<botId>/<partId>.json), not
@@ -210,6 +210,7 @@ export function install(rt) {
const cards = new Map()
const reading = new Map()
let writing = Promise.resolve()
+ let deleting = Promise.resolve()
const listOf = (botId, partId) => cards.get(botId)?.get(partId) ?? []
@@ -251,7 +252,10 @@ export function install(rt) {
}
try {
const parsed = JSON.parse(await readFile(partFile(botId, partId), 'utf8'))
- if (Array.isArray(parsed)) list = parsed.filter(card => card !== null && typeof card === 'object' && !Array.isArray(card))
+ if (Array.isArray(parsed)) {
+ list = parsed.filter(card => card !== null && typeof card === 'object' && !Array.isArray(card))
+ .map(card => ({ ...card, botId, partId }))
+ }
} catch (error) {
if (error?.code !== 'ENOENT') rt.warn('ds-bot: unreadable btw cards %s: %s', partFile(botId, partId), error?.code ?? error)
}
@@ -316,8 +320,33 @@ export function install(rt) {
return view
}
- // Plugin unload; only the queued file write has to finish.
+ // Deleting a card removes only that saved aside. The whole read-modify-write
+ // is queued so two cards deleted together cannot restore each other. A state
+ // save afterwards bumps the revision, so every window polls the new lists.
+ function btwDelete({ sessionId, cardId }) {
+ const run = deleting.then(async () => {
+ const { botId } = locatePrivate(rt, sessionId, "Side chat is only available in a Bot's private chat.")
+ const list = await readPart(botId, sessionId)
+ const next = list.filter(card => card?.id !== cardId)
+ if (next.length === list.length) return { deleted: false }
+ const byBot = cards.get(botId)
+ byBot.set(sessionId, next)
+ try {
+ await writePart(botId, sessionId)
+ } catch (error) {
+ byBot.set(sessionId, list)
+ throw error
+ }
+ await rt.save()
+ return { deleted: true }
+ })
+ deleting = run.catch(() => {})
+ return run
+ }
+
+ // Plugin unload; queued deletes and their file writes have to finish.
async function btwDispose() {
+ await deleting
await writing
}
@@ -339,5 +368,5 @@ export function install(rt) {
}
}
- Object.assign(rt, { btwDispose, btwView, btwPartCards: readPart })
+ Object.assign(rt, { btwDelete, btwDispose, btwView, btwPartCards: readPart })
}
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index 83064f3f..0b7c8eb3 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -417,6 +417,11 @@ export function install(rt) {
}, AbortSignal.timeout(30_000))
return ok(true)
}
+ case 'btw-delete': {
+ if (typeof body.sessionId !== 'string' || body.sessionId === '' || typeof body.cardId !== 'string' || body.cardId === '') return fail('Nothing to delete', 'bot/invalid')
+ await rt.load()
+ return ok(await rt.btwDelete({ sessionId: body.sessionId, cardId: body.cardId }))
+ }
// Side chats in the Bot's panel: each question is an aside on a fresh
// snapshot of this Bot's private chat; the earlier finished pairs of
// that chat ride along. Nothing is written into the Session.
diff --git a/ds-bot/test/btw-client.test.js b/ds-bot/test/btw-client.test.js
index dfc4b4ed..b64373b6 100644
--- a/ds-bot/test/btw-client.test.js
+++ b/ds-bot/test/btw-client.test.js
@@ -268,7 +268,7 @@ test('a card whose turn is not loaded stays in the trailing block', () => {
// BtwDock, bundled and rendered with a minimal React stand-in: the dock is the
// composer slot for cards whose turn is still open or matches nothing closed.
-// Old cards are read-only, so the dock shows no Cancel.
+// Old cards have no Cancel, but their delete action removes the saved aside.
import { fileURLToPath } from 'node:url'
import { runInNewContext } from 'node:vm'
import { build } from 'esbuild'
@@ -309,15 +309,37 @@ const findIn = (node, match, out = []) => {
return out
}
-test('an open-turn card renders in the dock without a Cancel button', () => {
+test('an open-turn card renders a delete action in the dock', async () => {
const card = { id: 'c1', partId: 's', status: 'done', question: 'q?', answer: 'a.', atSeq: null, createdAt: 1, finishedAt: 2 }
const roster = { ready: true, btwCards: { bot: [card] }, byId: { s: { id: 'bot', sessionId: 's' } }, roomsById: {} }
- const actions = { turnFacts: () => ({ turns: new Map(), openTurn: { seq: 1 } }), watchTurns: () => () => {} }
+ const sent = []
+ const removed = []
+ const actions = {
+ turnFacts: () => ({ turns: new Map(), openTurn: { seq: 1 } }),
+ watchTurns: () => () => {},
+ deleteBtw: (sessionId, cardId) => { sent.push([sessionId, cardId]); return Promise.resolve({ deleted: true }) },
+ reportError: error => { throw error },
+ }
const tree = BtwDock({ sessionId: 's', useRoster: select => select(roster), actions })
assert.equal(findIn(tree, node => node.props?.className === 'bt-btw-dock').length, 1)
// The card component sits in the tree as a vnode; render it to see the card.
const [cardNode] = findIn(tree, node => typeof node.type === 'function' && node.props?.card?.id === 'c1')
- const view = cardNode.type(cardNode.props)
+ const view = cardNode.type({ ...cardNode.props, onDeleted: id => removed.push(id) })
assert.equal(view.props.className, 'bt-btw bt-btw-compact')
+ assert.equal(view.props['aria-label'], 'Side chat')
assert.equal(findIn(view, node => node.props?.className === 'bt-btw-cancel').length, 0)
+ const [button] = findIn(view, node => node.props?.className === 'bt-icon-btn bt-btw-delete')
+ assert.ok(button)
+ assert.equal(button.props['aria-label'], 'Delete side chat')
+ button.props.onClick()
+ await new Promise(resolve => setImmediate(resolve))
+ assert.deepEqual(sent, [['s', 'c1']])
+ assert.deepEqual(removed, ['c1'])
+
+ actions.deleteBtw = () => Promise.resolve({ deleted: false })
+ const staleView = cardNode.type({ ...cardNode.props, onDeleted: id => removed.push(id) })
+ const [staleButton] = findIn(staleView, node => node.props?.className === 'bt-icon-btn bt-btw-delete')
+ staleButton.props.onClick()
+ await new Promise(resolve => setImmediate(resolve))
+ assert.deepEqual(removed, ['c1'])
})
diff --git a/ds-bot/test/btw.test.js b/ds-bot/test/btw.test.js
index 7dbf8cb3..6a7f0b78 100644
--- a/ds-bot/test/btw.test.js
+++ b/ds-bot/test/btw.test.js
@@ -91,8 +91,8 @@ function projectionRegistry(ctx) {
}
}
-// The ask path is gone; saved cards stay where they were, read-only. `btw`
-// seeds card files: { botId: { partId: [cards] } }.
+// The ask path is gone; saved cards stay readable until deleted. `btw` seeds
+// card files: { botId: { partId: [cards] } }.
async function setup({ state = team(), messages, seq = 4, events, foreignLock = false, btw = {} } = {}) {
const home = mkdtempSync(join(tmpdir(), 'dsb-btw-'))
writeFileSync(join(home, 'state.json'), JSON.stringify(state))
@@ -208,6 +208,65 @@ test('a saved card rides the current part\'s view, whole and read-only', async (
assert.equal(saved.revision, 3)
})
+test('a user deletes saved cards from current and earlier parts', async (t) => {
+ const env = await setup({
+ btw: {
+ b1: {
+ 's-now': [
+ { id: 'first', botId: 'b1', partId: 's-now', atSeq: 3, question: 'Now?', answer: 'Yes.', status: 'done', createdAt: 10, finishedAt: 11 },
+ { id: 'second', botId: 'b1', partId: 's-now', atSeq: 2, question: 'Earlier?', answer: 'Yes.', status: 'done', createdAt: 9, finishedAt: 10 },
+ ],
+ 's-old': [{ id: 'old', botId: 'b1', partId: 's-old', atSeq: 1, question: 'Before?', answer: 'Yes.', status: 'done', createdAt: 5, finishedAt: 6 }],
+ },
+ },
+ })
+ t.after(() => env.stop())
+ const revision = env.rt.state.revision
+ const deleted = await env.call('btw-delete', { sessionId: 's-now', cardId: 'first' })
+ assert.deepEqual(deleted, { ok: true, value: { deleted: true } })
+ assert.deepEqual(cardsOf(env.rt).map(card => card.id), ['second'])
+ assert.deepEqual(cardsFile(env.home).map(card => card.id), ['second'])
+ assert.equal(env.rt.state.revision, revision + 1)
+ const view = await env.call('state', { since: revision })
+ assert.equal(view.ok, true)
+ assert.equal(view.value.unchanged, undefined)
+ assert.deepEqual(view.value.btwCards.b1.map(card => card.id), ['second'])
+
+ const wrongPart = await env.call('btw-delete', { sessionId: 's-old', cardId: 'second' })
+ assert.deepEqual(wrongPart, { ok: true, value: { deleted: false } })
+ assert.deepEqual(cardsFile(env.home).map(card => card.id), ['second'])
+ assert.equal(env.rt.state.revision, revision + 1)
+
+ const old = await env.call('btw-delete', { sessionId: 's-old', cardId: 'old' })
+ assert.deepEqual(old, { ok: true, value: { deleted: true } })
+ assert.deepEqual(cardsFile(env.home, 'b1', 's-old'), [])
+ assert.deepEqual(cardsOf(env.rt).map(card => card.id), ['second'])
+ assert.equal(env.rt.state.revision, revision + 2)
+
+ const again = await env.call('btw-delete', { sessionId: 's-now', cardId: 'first' })
+ assert.deepEqual(again, { ok: true, value: { deleted: false } })
+ assert.equal(env.rt.state.revision, revision + 2)
+ const invalid = await env.call('btw-delete', { sessionId: 's-now' })
+ assert.equal(invalid.ok, false)
+ assert.equal(invalid.error.code, 'bot/invalid')
+ assert.equal(env.requests.length, 0)
+ assert.equal(env.session.writes, 0)
+})
+
+test('concurrent deletes in one part keep both removals', async (t) => {
+ const card = (id, at) => ({ id, botId: 'b1', partId: 's-now', atSeq: at, question: `${id}?`, answer: 'Yes.', status: 'done', createdAt: at, finishedAt: at + 1 })
+ const env = await setup({ btw: { b1: { 's-now': [card('a', 1), card('b', 2), card('c', 3)] } } })
+ t.after(() => env.stop())
+ const [a, b] = await Promise.all([
+ env.call('btw-delete', { sessionId: 's-now', cardId: 'a' }),
+ env.call('btw-delete', { sessionId: 's-now', cardId: 'b' }),
+ ])
+ assert.deepEqual(a, { ok: true, value: { deleted: true } })
+ assert.deepEqual(b, { ok: true, value: { deleted: true } })
+ assert.deepEqual(cardsOf(env.rt).map(item => item.id), ['c'])
+ assert.deepEqual(cardsFile(env.home).map(item => item.id), ['c'])
+})
+
test('a restart marks an aside that was still answering as failed', async (t) => {
const env = await setup({
btw: {
@@ -265,6 +324,10 @@ test('a second host does not fail an aside the writer is still answering', async
assert.equal(saved.revision, 3)
assert.equal(env.rt.state.revision, 3)
assert.equal(env.notices(), 0)
+ const deleted = await env.call('btw-delete', { sessionId: 's-now', cardId: 'old' })
+ assert.equal(deleted.ok, false)
+ assert.equal(deleted.error.code, 'bot/read-only')
+ assert.equal(cardsFile(env.home).length, 2)
})
test('deleting a Bot removes its card files', async (t) => {