A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Draw a folded message's cut code block without the host's copy control
Fei2411ed57c87f4d0c
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex eeaaeef5..d69e4d24 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -2759,6 +2759,10 @@ html[data-windows-titlebar]:not([data-fullscreen]) :is(.bt-pane,.bt-panel)::befo.bt-fold{display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 10px;margin-top:4px;white-space:normal}.bt-fold-code{position:relative}.bt-fold-code>.bt-tool{position:absolute;right:6px;bottom:6px}+/* The part of a cut code block the preview keeps, drawn by DS Bot so the host's+ Markdown draws no copy control of its own for it. */+.bt-fold-code>.bt-fold-pre{margin:0;padding:10px 12px;border-radius:10px;background:color-mix(in srgb,var(--bt-ink) 5%,transparent);font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;line-height:20px;overflow-x:auto}+.bt-fold-code>*+.bt-fold-pre{margin-top:6px}.bt-fold-note{font-size:12px;line-height:16px;color:var(--bt-ink-3)}[data-folded] .bt-fold-body{-webkit-mask-image:linear-gradient(to bottom,#000 calc(100% - 40px),transparent);mask-image:linear-gradient(to bottom,#000 calc(100% - 40px),transparent)}.bt-ubody .bt-fold .bt-more,.bt-ububble .bt-fold .bt-more,.bt-ubody .bt-fold-note,.bt-ububble .bt-fold-note{color:inherit;opacity:.7}@@ -7344,8 +7348,16 @@ function foldView(text, limit = FOLD_AT, markdown = true) {if (opened === null) return { head };const lines = head.split("\n");lines[opened.line] = opened.marker;- return { head: `${lines.join("\n")}-${opened.marker}`, code: blockCode(body, opened.line, opened.marker) };+ return {+ head: `${lines.join("\n")}+${opened.marker}`,+ // The markdown before the block and the part of the block the preview+ // keeps: the half block is drawn outside the host's Markdown, whose own+ // copy control would hold only the part shown.+ prose: lines.slice(0, opened.line).join("\n"),+ codeHead: lines.slice(opened.line + 1).join("\n"),+ code: blockCode(body, opened.line, opened.marker)+ };}function foldPreview(text, limit = FOLD_AT, markdown = true) {return foldView(text, limit, markdown)?.head ?? null;@@ -7358,6 +7370,7 @@ function useFold(text, { limit = FOLD_AT, whole, live = false, markdown = true }const view = (0, import_react14.useMemo)(() => live ? null : foldView(text, cut ? ALWAYS : limit, markdown), [text, live, limit, markdown, cut]);if (view === null) return { shown: text, control: null };const code = cut ? void 0 : view.code;+ const shown = code === void 0 ? view.head : view.prose;const count = (cut ? whole.length : text.length).toLocaleString();if (!open) {const show2 = async () => {@@ -7366,7 +7379,7 @@ function useFold(text, { limit = FOLD_AT, whole, live = false, markdown = true }setRead("loading");setRead(await whole.load() ?? { whole: false });};- return { shown: view.head, folded: true, code, control: (0, import_react14.createElement)("span", { className: "bt-fold" }, (0, import_react14.createElement)("button", { type: "button", className: "bt-more", onClick: show2 }, t("Show all · {count} characters", { count }))) };+ return { shown, folded: true, code, codeHead: view.codeHead, control: (0, import_react14.createElement)("span", { className: "bt-fold" }, (0, import_react14.createElement)("button", { type: "button", className: "bt-more", onClick: show2 }, t("Show all · {count} characters", { count }))) };}const loaded = typeof read?.text === "string" ? read : void 0;const note = !cut || read === void 0 || read === "loading" || loaded?.whole ? null : loaded !== void 0 && loaded.text.length > text.length ? t("Showing the first {count} characters", { count: loaded.text.length.toLocaleString() }) : t("Only the start of this message is kept here");@@ -7744,10 +7757,17 @@ function FoldCodeCopy({ code, actions }) {};return (0, import_react16.createElement)("button", { type: "button", className: "bt-tool bt-fold-copy", "aria-label": copied ? t("Copied") : t("Copy"), title: copied ? t("Copied") : t("Copy"), onClick: copy2 }, copied ? (0, import_react16.createElement)(CheckIcon) : (0, import_react16.createElement)(CopyIcon));}+var foldArea = (body, code, codeHead, actions) => code === void 0 ? body : (0, import_react16.createElement)(+ "div",+ { className: "bt-fold-code" },+ body,+ (0, import_react16.createElement)("pre", { className: "bt-fold-pre" }, (0, import_react16.createElement)("code", null, codeHead)),+ (0, import_react16.createElement)(FoldCodeCopy, { code, actions })+);function Bubble({ text, index, roster, selfId, actions, sessionId, msgKey, mentions, fold, picked, live, lead, whole }) {- const { shown, folded, control, code } = useFold(text, { limit: fold, whole, live });+ const { shown, folded, control, code, codeHead } = useFold(text, { limit: fold, whole, live });const key = msgKey ? `${msgKey}:${index}` : void 0;- const body = (0, import_react16.createElement)(import_dsh_client_ui_primitives.MarkdownText, { text: linkMentions(shown, roster.bots, selfId), streaming: live, labels: mdLabels3(), variant: "compact", fileMentions: mentions });+ const body = shown === "" ? null : (0, import_react16.createElement)(import_dsh_client_ui_primitives.MarkdownText, { text: linkMentions(shown, roster.bots, selfId), streaming: live, labels: mdLabels3(), variant: "compact", fileMentions: mentions });const row = (0, import_react16.useRef)(null);const [toolsOpen, setToolsOpen] = (0, import_react16.useState)(false);useDismiss(toolsOpen, () => setToolsOpen(false), [row]);@@ -7755,7 +7775,7 @@ function Bubble({ text, index, roster, selfId, actions, sessionId, msgKey, mentiif (!noHover() || event.target instanceof Element && event.target.closest("a,button,input,textarea,select,pre,code,[role=button],[role=link]")) return;setToolsOpen((value) => !value);};- const area = code === void 0 ? body : (0, import_react16.createElement)("div", { className: "bt-fold-code" }, body, (0, import_react16.createElement)(FoldCodeCopy, { code, actions }));+ const area = foldArea(body, code, codeHead, actions);return (0, import_react16.createElement)("div",{ ref: row, className: "bt-msg", onClick: tapTools },@@ -8131,9 +8151,9 @@ var scrollParent = (node) => {return null;};function EarlierUser({ row, actions }) {- const { shown, folded, control, code } = useFold(row.text ?? "");- const body = row.text ? (0, import_react16.createElement)(import_dsh_client_ui_primitives.MarkdownText, { text: shown, labels: mdLabels3(), variant: "compact" }) : null;- const area = code === void 0 ? body : (0, import_react16.createElement)("div", { className: "bt-fold-code" }, body, (0, import_react16.createElement)(FoldCodeCopy, { code, actions }));+ const { shown, folded, control, code, codeHead } = useFold(row.text ?? "");+ const body = row.text && shown !== "" ? (0, import_react16.createElement)(import_dsh_client_ui_primitives.MarkdownText, { text: shown, labels: mdLabels3(), variant: "compact" }) : null;+ const area = foldArea(body, code, codeHead, actions);return (0, import_react16.createElement)("div", { className: "bt-urow" }, (0, import_react16.createElement)("div",{ className: "bt-ububble", "data-folded": folded || void 0 },diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 3173cc86..ec413cfe 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -68,10 +68,20 @@ function FoldCodeCopy({ code, actions }) {return h('button', { type: 'button', className: 'bt-tool bt-fold-copy', 'aria-label': copied ? t('Copied') : t('Copy'), title: copied ? t('Copied') : t('Copy'), onClick: copy }, copied ? h(CheckIcon) : h(CopyIcon))}+// A folded message's last code block shows only its start. The start is not+// given to the host's Markdown — its block would carry a copy bound to the+// part shown — so DS Bot draws the part itself, with a copy bound to the+// whole block. `body` renders the markdown before the block.+const foldArea = (body, code, codeHead, actions) => (code === undefined ? body+ : h('div', { className: 'bt-fold-code' },+ body,+ h('pre', { className: 'bt-fold-pre' }, h('code', null, codeHead)),+ h(FoldCodeCopy, { code, actions })))+function Bubble({ text, index, roster, selfId, actions, sessionId, msgKey, mentions, fold, picked, live, lead, whole }) {- const { shown, folded, control, code } = useFold(text, { limit: fold, whole, live })+ const { shown, folded, control, code, codeHead } = useFold(text, { limit: fold, whole, live })const key = msgKey ? `${msgKey}:${index}` : undefined- const body = h(MarkdownText, { text: linkMentions(shown, roster.bots, selfId), streaming: live, labels: mdLabels(), variant: 'compact', fileMentions: mentions })+ const body = shown === '' ? null : h(MarkdownText, { text: linkMentions(shown, roster.bots, selfId), streaming: live, labels: mdLabels(), variant: 'compact', fileMentions: mentions })const row = useRef(null)// Touch has no hover: a tap on the bubble opens its tools, a tap elsewhere// closes them. Interactive targets keep their own meaning.@@ -81,11 +91,7 @@ function Bubble({ text, index, roster, selfId, actions, sessionId, msgKey, mentiif (!noHover() || event.target instanceof Element && event.target.closest('a,button,input,textarea,select,pre,code,[role=button],[role=link]')) returnsetToolsOpen(value => !value)}- // A folded message's last code block shows only its start; DS Bot draws its own- // copy control for it, bound to the whole block. DSH's and the app's copy- // buttons live in the block's banner and their markup differs, so none of- // theirs is intercepted or cloned.- const area = code === undefined ? body : h('div', { className: 'bt-fold-code' }, body, h(FoldCodeCopy, { code, actions }))+ const area = foldArea(body, code, codeHead, actions)return h('div', { ref: row, className: 'bt-msg', onClick: tapTools },h('div', { className: 'bt-msg-line' },lead,@@ -428,9 +434,9 @@ const scrollParent = (node) => {}function EarlierUser({ row, actions }) {- const { shown, folded, control, code } = useFold(row.text ?? '')- const body = row.text ? h(MarkdownText, { text: shown, labels: mdLabels(), variant: 'compact' }) : null- const area = code === undefined ? body : h('div', { className: 'bt-fold-code' }, body, h(FoldCodeCopy, { code, actions }))+ const { shown, folded, control, code, codeHead } = useFold(row.text ?? '')+ const body = row.text && shown !== '' ? h(MarkdownText, { text: shown, labels: mdLabels(), variant: 'compact' }) : null+ const area = foldArea(body, code, codeHead, actions)return h('div', { className: 'bt-urow' }, h('div', { className: 'bt-ububble', 'data-folded': folded || undefined },control ? h('div', { className: 'bt-fold-body' }, area) : area,control,diff --git a/ds-bot/src/client/fold.js b/ds-bot/src/client/fold.jsindex 6db00a96..040b5017 100644--- a/ds-bot/src/client/fold.js+++ b/ds-bot/src/client/fold.js@@ -94,7 +94,15 @@ export function foldView(text, limit = FOLD_AT, markdown = true) {// expansion remounts its subtree looking like a no-op.const lines = head.split('\n')lines[opened.line] = opened.marker- return { head: `${lines.join('\n')}\n${opened.marker}`, code: blockCode(body, opened.line, opened.marker) }+ return {+ head: `${lines.join('\n')}\n${opened.marker}`,+ // The markdown before the block and the part of the block the preview+ // keeps: the half block is drawn outside the host's Markdown, whose own+ // copy control would hold only the part shown.+ prose: lines.slice(0, opened.line).join('\n'),+ codeHead: lines.slice(opened.line + 1).join('\n'),+ code: blockCode(body, opened.line, opened.marker),+ }}export function foldPreview(text, limit = FOLD_AT, markdown = true) {@@ -118,8 +126,11 @@ export function useFold(text, { limit = FOLD_AT, whole, live = false, markdown =if (view === null) return { shown: text, control: null }// `code` is the whole block the preview's last code fence opens, for a copy// that must not stop at the fold; only the full text can supply it, so a- // message kept only in part has none.+ // message kept only in part has none. When there is one, `shown` holds just+ // the markdown before the block and `codeHead` the part of it the preview+ // keeps, so the cell draws the half block itself.const code = cut ? undefined : view.code+ const shown = code === undefined ? view.head : view.proseconst count = (cut ? whole.length : text.length).toLocaleString()if (!open) {const show = async () => {@@ -128,7 +139,7 @@ export function useFold(text, { limit = FOLD_AT, whole, live = false, markdown =setRead('loading')setRead(await whole.load() ?? { whole: false })}- return { shown: view.head, folded: true, code, control: h('span', { className: 'bt-fold' }, h('button', { type: 'button', className: 'bt-more', onClick: show }, t('Show all · {count} characters', { count }))) }+ return { shown, folded: true, code, codeHead: view.codeHead, control: h('span', { className: 'bt-fold' }, h('button', { type: 'button', className: 'bt-more', onClick: show }, t('Show all · {count} characters', { count }))) }}const loaded = typeof read?.text === 'string' ? read : undefinedconst note = !cut || read === undefined || read === 'loading' || loaded?.whole ? nulldiff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.jsindex 4f5ae40f..06524a8e 100644--- a/ds-bot/src/client/styles.js+++ b/ds-bot/src/client/styles.js@@ -369,6 +369,10 @@ html[data-windows-titlebar]:not([data-fullscreen]) :is(.bt-pane,.bt-panel)::befo.bt-fold{display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 10px;margin-top:4px;white-space:normal}.bt-fold-code{position:relative}.bt-fold-code>.bt-tool{position:absolute;right:6px;bottom:6px}+/* The part of a cut code block the preview keeps, drawn by DS Bot so the host's+ Markdown draws no copy control of its own for it. */+.bt-fold-code>.bt-fold-pre{margin:0;padding:10px 12px;border-radius:10px;background:color-mix(in srgb,var(--bt-ink) 5%,transparent);font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;line-height:20px;overflow-x:auto}+.bt-fold-code>*+.bt-fold-pre{margin-top:6px}.bt-fold-note{font-size:12px;line-height:16px;color:var(--bt-ink-3)}[data-folded] .bt-fold-body{-webkit-mask-image:linear-gradient(to bottom,#000 calc(100% - 40px),transparent);mask-image:linear-gradient(to bottom,#000 calc(100% - 40px),transparent)}.bt-ubody .bt-fold .bt-more,.bt-ububble .bt-fold .bt-more,.bt-ubody .bt-fold-note,.bt-ububble .bt-fold-note{color:inherit;opacity:.7}diff --git a/ds-bot/test/fold.test.js b/ds-bot/test/fold.test.jsindex 3ea21825..a050ab62 100644--- a/ds-bot/test/fold.test.js+++ b/ds-bot/test/fold.test.js@@ -152,6 +152,10 @@ test('a folded preview also yields the whole code block it cut', () => {const view = foldView(`Here:\n\`\`\`js\n${inner}\n\`\`\`\nafter`)assert.equal(view.head, `Here:\n\`\`\`\n${lines(8)}\n\`\`\``)assert.equal(view.code, inner)+ // The markdown before the block, and the part of the block the preview keeps:+ // the half block is drawn by DS Bot, so the host's copy control never sees it.+ assert.equal(view.prose, 'Here:')+ assert.equal(view.codeHead, lines(8))// A block that never closes yields to the end of the text.assert.equal(foldView(`\`\`\`js\n${inner}`).code, inner)// No fence is cut: nothing extra to copy.@@ -160,7 +164,10 @@ test('a folded preview also yields the whole code block it cut', () => {assert.equal(closed.code, undefined)// The folded state hands the code to the caller; a cut message cannot.fresh()- assert.equal(render(`Here:\n\`\`\`js\n${inner}\n\`\`\``, {}).code, inner)+ const folded = render(`Here:\n\`\`\`js\n${inner}\n\`\`\``, {})+ assert.equal(folded.code, inner)+ assert.equal(folded.shown, 'Here:')+ assert.equal(folded.codeHead, lines(8))fresh()assert.equal(render('short', { whole: { length: 300_000 } }).code, undefined)})diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.jsindex 18780147..32e59bfe 100644--- a/ds-bot/test/tool-cells.test.js+++ b/ds-bot/test/tool-cells.test.js@@ -9,7 +9,7 @@ import { build } from 'esbuild'const { outputFiles } = await build({stdin: {contents: [- "export { ToolCell, TriggerCell, callTree, stackReplies } from './src/client/cells.js'",+ "export { ToolCell, TriggerCell, callTree, stackReplies, Bubbles } from './src/client/cells.js'","export { QuestionDock } from './src/client/questions.js'","export { SecretDock } from './src/client/secret-card.js'","export { countCards } from './src/client/sources.js'",@@ -36,6 +36,9 @@ const react = {useSyncExternalStore: (subscribe, getSnapshot) => getSnapshot(),}const timers = new Set()+// The markdown the host's renderer is given, and what DS Bot's copy controls write.+const markdownTexts = []+const copiedTexts = []const module = { exports: {} }runInNewContext(outputFiles[0].text, {module, exports: module.exports,@@ -45,11 +48,16 @@ runInNewContext(outputFiles[0].text, {require: (name) => {if (name === 'react') return reactif (name === 'react-dom') return { createPortal: node => node }- if (name === '@deepseek-ai/dsh-client-ui-primitives') return { MarkdownText: ({ text }) => text }+ if (name === '@deepseek-ai/dsh-client-ui-primitives') {+ return {+ MarkdownText: ({ text }) => { markdownTexts.push(text); return text },+ writeClipboard: text => { copiedTexts.push(text); return Promise.resolve(true) },+ }+ }throw new Error(`Unexpected platform module ${name}`)},})-const { ToolCell, TriggerCell, callTree, stackReplies, QuestionDock, SecretDock, countCards, ViewMenuList, WidgetView } = module.exports+const { ToolCell, TriggerCell, callTree, stackReplies, Bubbles, QuestionDock, SecretDock, countCards, ViewMenuList, WidgetView } = module.exports// Runs the effects collected since the last render; returns the cleanups.const mount = () => {@@ -853,3 +861,36 @@ test('a view works its formulas out, draws a chart, and keeps html in a sandboxeassert.ok(frame.props.srcDoc.indexOf('Content-Security-Policy') < frame.props.srcDoc.indexOf('<b>hi</b>'), 'the policy comes before the markup')assert.equal(frame.props.title, 'A greeting')})++// #718: a folded message's cut code block is drawn by DS Bot, so no copy control+// exists that holds only the part shown; DS Bot's own is bound to the whole+// block, and a short block keeps the host's normal rendering and copy.+test('a folded code block leaves no copy of only its shown part', async () => {+ const inner = Array.from({ length: 40 }, (_, index) => `line ${index + 1}`).join('\n')+ const bubble = (texts) => expand(Bubbles({+ texts, roster: team(), selfId: chief.id, sessionId: chief.id, actions: {},+ useUi: select => select({ reactions: {} }),+ }))+ const copyOf = node => findAll(node, item => item.type === 'button' && typeof item.props?.className === 'string' && item.props.className.includes('bt-fold-copy'))++ markdownTexts.length = 0+ copiedTexts.length = 0+ const out = bubble([`Here:\n\`\`\`js\n${inner}\n\`\`\``])+ // The markdown the host renders holds no fence, so it can draw no copy of the part.+ assert.ok(markdownTexts.length > 0 && markdownTexts.every(given => !given.includes('```')))+ // DS Bot draws the part the preview keeps, and its copy holds the whole block.+ assert.equal(text(find(out, item => item.type === 'pre')), 'line 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8')+ const [copy] = copyOf(out)+ assert.equal(copyOf(out).length, 1)+ copy.props.onClick()+ await Promise.resolve()+ assert.deepEqual(copiedTexts, [inner])++ // A short block goes to the host whole, with the host's own copy and none of ours.+ markdownTexts.length = 0+ copiedTexts.length = 0+ const short = bubble(['```js\none\n```'])+ assert.ok(markdownTexts.some(given => given.includes('```js')))+ assert.equal(copyOf(short).length, 0)+ effects = []+})