Skip to content

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

Refuse the show_view calls the card cannot honor

Fei2411e41f44a15daa
diff --git a/ds-bot/README.md b/ds-bot/README.md
index 7380e526..72a173b4 100644
--- a/ds-bot/README.md
+++ b/ds-bot/README.md
@@ -11,7 +11,7 @@ Tested with dsh `0.2.1-rc.2` (Web) and `0.2.0-rc.2` (Web and Desktop).
- **Long-lived Bots**: each Bot is a dsh Session in the "DS Bot" workspace, with its own name, role, instructions and model.
- **Working folders**: a Bot can work in a folder you choose instead of the team workspace, and a group chat can set one folder for all its members there. Pick it in the Bot's settings or details panel or in the group's settings, or ask a Bot (`update_bot`, `update_group`). After a change, the chat goes on in a fresh part that starts in the new folder. When a Bot sets a folder outside the team workspace, or adds a Bot to a group that works in one, it asks for your approval if those Bots can only write in their folder. Folders that hold dsh data (`$DSH_HOME`, the team's data) are refused. The team workspace itself moves in Settings > General > Locations; Bots and groups that work there go on in a fresh part in the new folder, and the old folder keeps its files.
- **Permission presets**: each Bot runs with its own dsh permission preset (Read only, Workspace or Full access), set in its details panel. A group chat can run all its members with one preset there, in place of their own: turn on **Same for every member** under Permissions in the group's settings. Only you set permissions; Bots cannot change them.
-- **Bots work together**: `message_bot` sends a message to another Bot, `create_bot` and `update_bot` add and set up Bots, and `ask_user` asks you a question without blocking the other Bots.
+- **Bots work together**: `message_bot` sends a message to another Bot, `create_bot` and `update_bot` add and set up Bots, and `ask_user` asks you a question without blocking the other Bots. `show_view` draws a card in a Bot's own chat — text, metrics, tables, progress, choices, confirmations and short forms; an interactive card waits for your answer.
- **Group chats**: members speak one at a time, and each one reads the latest messages first. A message can `@Name` a member to pass the turn on; type `@` to pick one from a list. **+ → Reference a chat** adds another Bot's chat to a message as context, and in a group the members who answer get it. A member with nothing new to add stays quiet (`[PASS]`). Each member has its own hidden Session per group, so a group never reads a Bot's private chat.
- **Roles and permissions**:
diff --git a/ds-bot/client.js b/ds-bot/client.js
index c9b60a50..a57ad711 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -3816,6 +3816,20 @@ function validateView(view) {
const error = checkNode(view, "view", 1, ctx);
return error === void 0 ? { ok: true, interactive: ctx.interactive } : { ok: false, error };
}
+function checkShownView(title, view) {
+ let bytes;
+ try {
+ bytes = viewBytes(title, view);
+ } catch {
+ return { error: "The view is not JSON data." };
+ }
+ if (bytes > VIEW_BYTE_LIMIT) return { error: `The view is ${bytes} bytes; the limit is ${VIEW_BYTE_LIMIT}.` };
+ const named = String(title ?? "").trim();
+ if (named === "") return { error: "Give the view a title." };
+ const checked = validateView(view);
+ if (!checked.ok) return { error: checked.error };
+ return { title: named, interactive: checked.interactive };
+}
function checkNode(node, path, depth, ctx) {
if (!isRecord(node)) return `${path}: expected a component object`;
if (depth > MAX_DEPTH) return `${path}: ${depth} levels exceeds the limit of ${MAX_DEPTH}`;
@@ -3927,6 +3941,7 @@ function checkForm(node, path, ctx) {
if (key !== "id" && key !== "label" && key !== "placeholder") return `${at}.${key}: unknown property ${quoted(key)}; allowed: id, label, placeholder`;
}
if (typeof field.id !== "string" || field.id === "") return `${at}.id: expected a non-empty string`;
+ if (field.id === "__proto__") return `${at}.id: "__proto__" cannot be an id`;
if (seen.has(field.id)) return `${at}.id: duplicate field id ${quoted(field.id)}`;
seen.add(field.id);
if (typeof field.label !== "string") return `${at}.label: expected a string`;
@@ -3941,6 +3956,7 @@ function checkProgress(node, path) {
}
function checkId(node, path, ctx) {
if (typeof node.id !== "string" || node.id === "") return `${path}.id: expected a non-empty string`;
+ if (node.id === "__proto__") return `${path}.id: "__proto__" cannot be an id`;
if (ctx.ids.has(node.id)) return `${path}.id: duplicate id ${quoted(node.id)}`;
ctx.ids.add(node.id);
return void 0;
@@ -4026,12 +4042,6 @@ var mdLabels = () => ({ code: { copyLabel: t("Copy"), copiedLabel: t("Copied") }
var optionsOf2 = (node) => (Array.isArray(node?.options) ? node.options : []).map((option) => typeof option === "string" ? { label: option } : option).filter((option) => option !== null && typeof option === "object" && option.label !== void 0);
var fieldsOf = (node) => (Array.isArray(node?.fields) ? node.fields : []).filter((field) => field !== null && typeof field === "object" && field.id !== void 0);
var cellText2 = (value) => value === null || value === void 0 ? "" : typeof value === "object" ? JSON.stringify(value) : String(value);
-var INTERACTIVE2 = /* @__PURE__ */ new Set(["options", "confirm", "form"]);
-var hasInteractive = (node) => {
- if (node === null || typeof node !== "object") return false;
- if (INTERACTIVE2.has(node.type)) return true;
- return (Array.isArray(node.children) ? node.children : []).some(hasInteractive);
-};
var countType = (node, type) => {
if (node === null || typeof node !== "object") return 0;
const children = Array.isArray(node.children) ? node.children : [];
@@ -4303,10 +4313,11 @@ function WidgetCell({ sessionId, callId, args, done, isError, roster, actions, h
}
if (done && isError) return (0, import_react6.createElement)("span", { className: "bt-q-gone", hidden: true });
const blueprint = normalizeView(args?.("view"));
- if (args?.("await_reply") === true || hasInteractive(blueprint) || blueprint === null || typeof blueprint !== "object") {
+ const shown = checkShownView(args?.("title"), blueprint);
+ if (shown.error !== void 0 || shown.interactive || args?.("await_reply") === true) {
return (0, import_react6.createElement)("span", { className: "bt-q-gone", hidden: true });
}
- return (0, import_react6.createElement)("div", { className: "bt-q-inline" }, (0, import_react6.createElement)(WidgetCard, { title: args?.("title") ?? "", view: blueprint }));
+ return (0, import_react6.createElement)("div", { className: "bt-q-inline" }, (0, import_react6.createElement)(WidgetCard, { title: shown.title, view: blueprint }));
}
function WidgetDock({ sessionId, useRoster, useCards, useHeldCards, actions }) {
const view = useRoster((value) => value.views?.[sessionId]);
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 51ce74e2..535019ff 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -13,7 +13,7 @@ import { ComposerPlus, ComposerVoice, menuIcons } from './composer.js'
import { CHATS_SOURCE, atSources } from './at-menu.js'
import { VOICE_BUNDLE } from './speech.js'
import { sameVersion } from './dsh-offer.js'
-import { AnsweredCell, QuestionCard, QuestionDock } from './questions.js'
+import { QuestionCard, QuestionDock } from './questions.js'
import { AnsweredReply, WidgetDock, WIDGET_CSS } from './widget-cell.js'
import { installHeaderNavigation } from './header-navigation.js'
import { AssistantCell, TriggerCell, TurnProcessCell, Nothing, TurnTailCell, ToolCell } from './cells.js'
diff --git a/ds-bot/src/client/widget-cell.js b/ds-bot/src/client/widget-cell.js
index 590b2d3e..f62801d7 100644
--- a/ds-bot/src/client/widget-cell.js
+++ b/ds-bot/src/client/widget-cell.js
@@ -2,9 +2,10 @@ import { createElement as h, Fragment, useId, useRef, useState } from 'react'
import { MarkdownText } from './dsh-primitives.js'
import { CheckIcon, CloseIcon } from './icons.js'
import { t } from './i18n.js'
-import { historyLoading } from './text.js'
import { AnsweredCell, keyLetter, useOptionKeys } from './questions.js'
-import { normalizeView } from '../shared/views.js'
+import { useDockHold } from './card-hold.js'
+import { heldCardKey } from './sources.js'
+import { checkShownView, normalizeView } from '../shared/views.js'
// -------------------------------------------------------------------------
// View cards (show_view): a Bot draws a small declarative blueprint — text,
@@ -22,12 +23,6 @@ const fieldsOf = node => (Array.isArray(node?.fields) ? node.fields : [])
.filter(field => field !== null && typeof field === 'object' && field.id !== undefined)
const cellText = value => (value === null || value === undefined ? '' : typeof value === 'object' ? JSON.stringify(value) : String(value))
-const INTERACTIVE = new Set(['options', 'confirm', 'form'])
-const hasInteractive = (node) => {
- if (node === null || typeof node !== 'object') return false
- if (INTERACTIVE.has(node.type)) return true
- return (Array.isArray(node.children) ? node.children : []).some(hasInteractive)
-}
const countType = (node, type) => {
if (node === null || typeof node !== 'object') return 0
const children = Array.isArray(node.children) ? node.children : []
@@ -206,6 +201,7 @@ function WidgetCard({ title, view, onSubmit, onDismiss, raised = false, settled
// pending question it hides on submit and comes back if the reply fails.
export function PendingView({ sessionId, view, actions, inline }) {
const [answered, setAnswered] = useState(null)
+ const hold = useDockHold(sessionId, 'view', view.id, actions, inline)
if (answered === view.id) return null
const onSubmit = (action, values) => {
setAnswered(view.id)
@@ -215,14 +211,15 @@ export function PendingView({ sessionId, view, actions, inline }) {
setAnswered(view.id)
void actions.dismissView(sessionId)
}
- return h('div', { className: inline ? 'bt-q-inline' : 'bt-q-dock' },
+ return h('div', { className: inline ? 'bt-q-inline' : 'bt-q-dock', onFocusCapture: hold, onPointerDownCapture: hold },
h(WidgetCard, { key: view.id, title: view.title ?? '', view: view.view, onSubmit, onDismiss, raised: !inline }))
}
// The show_view call in the transcript.
-export function WidgetCell({ sessionId, callId, args, done, isError, roster, actions }) {
+export function WidgetCell({ sessionId, callId, args, done, isError, roster, actions, heldCards }) {
const record = roster.views?.[sessionId]
if (record !== undefined && record.callId === callId) {
+ if (heldCards?.[heldCardKey('view', record.id)] > 0) return null
return h(PendingView, { sessionId, view: record, actions, inline: true })
}
// A refused call (bad blueprint) drew no card; don't render an empty one.
@@ -230,21 +227,24 @@ export function WidgetCell({ sessionId, callId, args, done, isError, roster, act
// Display-only cards draw from the recorded call arguments, which keep the
// provider's encoding: unwrap it the same way the host does before storing.
const blueprint = normalizeView(args?.('view'))
- // Answered, dismissed or replaced: a card that awaited a reply leaves no gap
- // where it was (same as ask_user). A display-only view stays as content.
- if (args?.('await_reply') === true || hasInteractive(blueprint) || blueprint === null || typeof blueprint !== 'object') {
+ const shown = checkShownView(args?.('title'), blueprint)
+ // 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?.('await_reply') === true) {
return h('span', { className: 'bt-q-gone', hidden: true })
}
- return h('div', { className: 'bt-q-inline' }, h(WidgetCard, { title: args?.('title') ?? '', view: blueprint }))
+ return h('div', { className: 'bt-q-inline' }, h(WidgetCard, { title: shown.title, view: blueprint }))
}
// Views asked by a call the transcript does not draw wait above the composer,
// mirroring the question dock.
-export function WidgetDock({ sessionId, useRoster, useCards, useSession, actions }) {
+export function WidgetDock({ sessionId, useRoster, useCards, useHeldCards, actions }) {
const view = useRoster(value => value.views?.[sessionId])
const drawn = useCards?.(state => state[sessionId]?.[view?.callId] > 0) === true
- const loading = useSession?.(historyLoading) === true
- if (view === undefined || (view.callId && (drawn || loading))) return null
+ const held = useHeldCards?.(state => state[sessionId]?.[heldCardKey('view', view?.id)] > 0) === true
+ if (view === undefined || (view.callId && drawn && !held)) return null
return h(PendingView, { sessionId, view, actions, inline: false })
}
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index d04985a5..e3f13bcc 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -7,7 +7,7 @@ import { within } from './folders.js'
import { absoluteLinks } from './links.js'
import { unquote } from './text.js'
import { mentionSpans } from '../shared/mentions.js'
-import { normalizeView, validateView, VIEW_BYTE_LIMIT, viewBytes } from '../shared/views.js'
+import { normalizeView, checkShownView } from '../shared/views.js'
export const output = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] }
export const GROUP_REF = { type: 'string', required: true, description: 'Exact group chat name from list_bots' }
@@ -611,7 +611,7 @@ export function install(rt) {
additionalProperties: true,
description: 'One component { type, ...props, children? }. type is stack (children, 1 to 16), text ({ text }), metric ({ label, value, tone? }), table ({ columns: [{ key, label }], rows }), options ({ id, options: [{ label, description? }], multi? }), confirm ({ id, confirmLabel?, cancelLabel? }), form ({ id, fields: [{ id, label, placeholder? }], submitLabel? }), or progress ({ label?, percent }).',
},
- await_reply: { type: 'boolean', description: 'Wait for the user to submit the card. Defaults to true when the view has options, confirm, or form, and to false otherwise. A display-only view cannot wait.' },
+ await_reply: { type: 'boolean', description: 'Wait for the user to submit the card. A view with options, confirm, or form always waits; a display-only view cannot.' },
},
output,
async execute(args, exec) {
@@ -620,14 +620,11 @@ export function install(rt) {
if (rt.groupOwners.has(id)) return 'View cards only work in your own chat. In a group, ask in your message instead.'
if (!rt.chatOwners.has(id)) return `Only Bots on the team can use show_view. Use ${BLOCKING_QUESTION_TOOL} if it is available in this session, or ask the user in your reply.`
const view = normalizeView(args.view)
- let bytes
- try { bytes = viewBytes(args.title, view) } catch { return 'The view is not JSON data.' }
- if (bytes > VIEW_BYTE_LIMIT) return `The view is ${bytes} bytes; the limit is ${VIEW_BYTE_LIMIT}.`
- const title = String(args.title ?? '').trim()
- if (title === '') return 'Give the view a title.'
- const checked = validateView(view)
- if (!checked.ok) return checked.error
+ const checked = checkShownView(args.title, view)
+ if (checked.error !== undefined) return checked.error
+ const title = checked.title
if (!checked.interactive && args.await_reply === true) return 'This view has nothing to submit; call show_view with await_reply: false.'
+ if (checked.interactive && args.await_reply === false) return 'This view has controls to submit, so it waits for the user\'s answer; call show_view without await_reply: false.'
const awaitReply = args.await_reply ?? checked.interactive
if (!awaitReply) return 'The view is on screen.'
// A hidden Bot-to-Bot turn shows none of its calls, so its card goes to the
diff --git a/ds-bot/src/shared/views.js b/ds-bot/src/shared/views.js
index df89716a..dcbfcdb3 100644
--- a/ds-bot/src/shared/views.js
+++ b/ds-bot/src/shared/views.js
@@ -67,6 +67,19 @@ export function validateView(view) {
return error === undefined ? { ok: true, interactive: ctx.interactive } : { ok: false, error }
}
+// What show_view checks before it shows a view: the same answer on the host and
+// in the client. `view` is already normalized; the trimmed title comes back.
+export function checkShownView(title, view) {
+ let bytes
+ try { bytes = viewBytes(title, view) } catch { return { error: 'The view is not JSON data.' } }
+ if (bytes > VIEW_BYTE_LIMIT) return { error: `The view is ${bytes} bytes; the limit is ${VIEW_BYTE_LIMIT}.` }
+ const named = String(title ?? '').trim()
+ if (named === '') return { error: 'Give the view a title.' }
+ const checked = validateView(view)
+ if (!checked.ok) return { error: checked.error }
+ return { title: named, interactive: checked.interactive }
+}
+
function checkNode(node, path, depth, ctx) {
if (!isRecord(node)) return `${path}: expected a component object`
if (depth > MAX_DEPTH) return `${path}: ${depth} levels exceeds the limit of ${MAX_DEPTH}`
@@ -185,6 +198,7 @@ function checkForm(node, path, ctx) {
if (key !== 'id' && key !== 'label' && key !== 'placeholder') return `${at}.${key}: unknown property ${quoted(key)}; allowed: id, label, placeholder`
}
if (typeof field.id !== 'string' || field.id === '') return `${at}.id: expected a non-empty string`
+ if (field.id === '__proto__') return `${at}.id: "__proto__" cannot be an id`
if (seen.has(field.id)) return `${at}.id: duplicate field id ${quoted(field.id)}`
seen.add(field.id)
if (typeof field.label !== 'string') return `${at}.label: expected a string`
@@ -201,6 +215,9 @@ function checkProgress(node, path) {
function checkId(node, path, ctx) {
if (typeof node.id !== 'string' || node.id === '') return `${path}.id: expected a non-empty string`
+ // A `__proto__` id would write through to a plain object's prototype where the
+ // answer is kept, losing it silently.
+ if (node.id === '__proto__') return `${path}.id: "__proto__" cannot be an id`
if (ctx.ids.has(node.id)) return `${path}.id: duplicate id ${quoted(node.id)}`
ctx.ids.add(node.id)
return undefined
diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.js
index f60792db..e1b98af4 100644
--- a/ds-bot/test/tool-cells.test.js
+++ b/ds-bot/test/tool-cells.test.js
@@ -34,7 +34,7 @@ const timers = new Set()
const module = { exports: {} }
runInNewContext(outputFiles[0].text, {
module, exports: module.exports,
- document: { hidden: false },
+ document: { hidden: false }, TextEncoder,
setTimeout: (fn) => { const timer = { fn }; timers.add(timer); return timer },
clearTimeout: timer => timers.delete(timer),
require: (name) => {
@@ -497,3 +497,22 @@ test('a reaction on a group post stays on that post, also after it draws again',
reactOf(draw(first))('👍')
assert.deepEqual([chips(draw(first)), chips(draw(sameTurn)), chips(draw(later))], [0, 0, 1])
})
+
+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) => {
+ assert.ok(find(node, each => each.props?.className === 'bt-q-gone') !== undefined, 'the call leaves the hidden mark')
+ assert.equal(text(node), '')
+ }
+ // Refusals the host returned as text reach the cell as a done call; the shared
+ // check hides them so the model's retry stays the only card.
+ gone(cell(' ', { type: 'text', text: 'hi' }))
+ gone(cell('Card', { type: 'nope' }))
+ gone(cell('x'.repeat(8192), { type: 'text', text: 'hi' }))
+ gone(cell('Pick', { type: 'options', id: 'o', options: [{ label: 'A' }] }))
+ gone(cell('Meter', { type: 'metric', label: 'Done', value: '3' }, { await_reply: true }))
+ const card = cell(' Status ', { type: 'metric', label: 'Done', value: '3' })
+ const title = find(card, node => node.props?.className === 'bt-q-title')
+ assert.ok(title !== undefined)
+ assert.equal(text(title), 'Status')
+})
diff --git a/ds-bot/test/view-reply.test.js b/ds-bot/test/view-reply.test.js
index 3aa11c0b..f5c28680 100644
--- a/ds-bot/test/view-reply.test.js
+++ b/ds-bot/test/view-reply.test.js
@@ -95,6 +95,19 @@ test('show_view registers an interactive card, refuses a group and a display-onl
assert.equal(waiting.concluded, false)
assert.equal((await team()).views['writer-now'], undefined)
+ // An interactive card cannot be told not to wait: refused, nothing stored.
+ const skipped = await show('writer-now', { title: 'Pick', view: CHOICES, await_reply: false })
+ assert.equal(skipped.text, 'This view has controls to submit, so it waits for the user\'s answer; call show_view without await_reply: false.')
+ assert.equal(skipped.concluded, false)
+ assert.equal((await team()).views['writer-now'], undefined)
+
+ // `__proto__` is no id: the answer object would lose the value to its prototype.
+ const protoCall = await show('writer-now', { title: 'Pick', view: { ...CHOICES, id: '__proto__' } })
+ assert.equal(protoCall.text, 'view.id: "__proto__" cannot be an id')
+ const protoField = await show('writer-now', { title: 'Ask', view: { type: 'form', id: 'ask', fields: [{ id: '__proto__', label: 'Name' }] } })
+ assert.equal(protoField.text, 'view.fields[0].id: "__proto__" cannot be an id')
+ assert.equal((await team()).views['writer-now'], undefined)
+
const shown = await show('writer-now', { title: 'Meter', view: METER })
assert.equal(shown.text, 'The view is on screen.')
assert.equal(shown.concluded, false)
diff --git a/ds-bot/test/views.test.js b/ds-bot/test/views.test.js
index 232d685d..5f3762d8 100644
--- a/ds-bot/test/views.test.js
+++ b/ds-bot/test/views.test.js
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
-import { normalizeView, validateView, validateViewAnswer, VIEW_BYTE_LIMIT, viewBytes, viewSummary } from '../src/shared/views.js'
+import { checkShownView, normalizeView, validateView, validateViewAnswer, VIEW_BYTE_LIMIT, viewBytes, viewSummary } from '../src/shared/views.js'
const text = (value = 'hello') => ({ type: 'text', text: value })
const metric = (label = '进度', value = '70%') => ({ type: 'metric', label, value })
@@ -94,6 +94,23 @@ test('validateView enforces table, options, form, depth, node, and id limits', (
assert.match(validateView(dup).error, /view\.children\[1\]\.id: duplicate id "same"/)
const many = stack(...Array.from({ length: 17 }, () => text()))
assert.match(validateView(many).error, /expected 1 to 16 children; got 17/)
+
+ // `__proto__` is no id, as a component or a field: the answer would write to a
+ // plain object's prototype instead of its fields.
+ assert.equal(validateView(options('__proto__')).error, 'view.id: "__proto__" cannot be an id')
+ assert.equal(validateView(confirm('__proto__')).error, 'view.id: "__proto__" cannot be an id')
+ assert.equal(validateView({ type: 'form', id: 'ask', fields: [{ id: '__proto__', label: 'Name' }] }).error, 'view.fields[0].id: "__proto__" cannot be an id')
+})
+
+test('checkShownView runs the call\'s own checks and names the card and its kind', () => {
+ assert.deepEqual(checkShownView(' Status ', text()), { title: 'Status', interactive: false })
+ assert.deepEqual(checkShownView('Pick', options()), { title: 'Pick', interactive: true })
+ assert.equal(checkShownView(' ', text()).error, 'Give the view a title.')
+ assert.equal(checkShownView('Card', { type: 'nope' }).error, 'view.type: unknown component "nope"; allowed: stack, text, metric, table, options, confirm, form, progress')
+ assert.equal(checkShownView('Card', undefined).error, 'view: expected a component object')
+ const room = VIEW_BYTE_LIMIT - viewBytes('', text())
+ assert.equal(checkShownView('x'.repeat(room + 1), text()).error, `The view is ${VIEW_BYTE_LIMIT + 1} bytes; the limit is ${VIEW_BYTE_LIMIT}.`)
+ assert.equal(checkShownView('Card', { get type() { throw new Error('no') } }).error, 'The view is not JSON data.')
})
test('viewBytes counts the blueprint JSON plus the title in UTF-8', () => {