A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Give a folded cut code block its own copy control, bound to the whole block
Fei241167417c125b16
diff --git a/app/ui/src/primitives.js b/app/ui/src/primitives.jsindex 0e006c00..f453b55b 100644--- a/app/ui/src/primitives.js+++ b/app/ui/src/primitives.js@@ -8,6 +8,12 @@ import { MENTION_ORIGIN } from '../../../ds-bot/src/client/text.js'// The DSH Agent's mark. The app has no DSH Agent, so nothing asks for it.export const FishLogo = () => null+// writeClipboard in the plugin is DSH's (navigator.clipboard with an execCommand+// fallback off-HTTPS); the window keeps the same contract.+export const writeClipboard = text => (navigator.clipboard === undefined+ ? Promise.resolve(document.execCommand('copy', false, text))+ : navigator.clipboard.writeText(text).then(() => true, () => false))+const plugins = [remarkGfm]function CodeBlock({ children, labels }) {diff --git a/ds-bot/client.js b/ds-bot/client.jsindex c5e44b4a..eeaaeef5 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -2757,6 +2757,8 @@ html[data-windows-titlebar]:not([data-fullscreen]) :is(.bt-pane,.bt-panel)::befo.bt-exchange .bt-dialog-log{max-width:none;margin:0;padding:39px max(16px,calc((100% - 960px)/2)) 116px;scrollbar-width:thin}.bt-exchange .bt-tools{display:none}.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}.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}@@ -7284,6 +7286,11 @@ var ALWAYS = { chars: -1, lines: 0 };var PREVIEW_LINES = 10;var PREVIEW_CHARS = 600;var FENCE = /^ {0,3}(`{3,}|~{3,})/;+var CLOSE = /^ {0,3}(`{3,}|~{3,})\s*$/;+var closes = (line, open) => {+ const marker = CLOSE.exec(line)?.[1];+ return marker !== void 0 && marker[0] === open[0] && marker.length >= open.length;+};function cutAt(text, end) {const code = text.charCodeAt(end - 1);return text.slice(0, code >= 55296 && code <= 56319 ? end - 1 : end);@@ -7304,17 +7311,17 @@ function openedFence(lines) {if (open === null) {open = marker;openLine = i;- } else if (marker[0] === open[0] && marker.length >= open.length) open = null;+ } else if (closes(lines[i], open)) open = null;}return open === null ? null : { marker: open, line: openLine };}function blockCode(body, fenceLine, open) {const lines = body.split("\n");+ const indent = /^ */.exec(lines[fenceLine])[0].length;const code = [];for (let i = fenceLine + 1; i < lines.length; i += 1) {- const marker = FENCE.exec(lines[i])?.[1];- if (marker !== void 0 && marker[0] === open[0] && marker.length >= open.length) break;- code.push(lines[i]);+ if (closes(lines[i], open)) break;+ code.push(lines[i].replace(new RegExp(`^ {0,${indent}}`), ""));}return code.join("\n");}@@ -7723,6 +7730,20 @@ function Bubbles({ texts: texts2, roster, selfId, actions, streaming, sessionId,}));}+function FoldCodeCopy({ code, actions }) {+ const [copied, setCopied] = (0, import_react16.useState)(false);+ const copy2 = () => {+ void (0, import_dsh_client_ui_primitives.writeClipboard)(code).then((ok) => {+ if (!ok) {+ actions?.reportError?.(new Error("Could not copy the code block"), "copy");+ return;+ }+ setCopied(true);+ setTimeout(() => setCopied(false), 1e3);+ }, () => actions?.reportError?.(new Error("Could not copy the code block"), "copy"));+ };+ 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));+}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 key = msgKey ? `${msgKey}:${index}` : void 0;@@ -7734,22 +7755,10 @@ 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 copyFolded = (event) => {- if (code === void 0 || !(event.target instanceof Element)) return;- const button = event.target.closest("button");- const label = button?.getAttribute("aria-label");- if (!button || !/copyButton/i.test(button.className ?? "") && label !== t("Copy") && label !== t("Copied")) return;- let holder = button.parentElement;- while (holder !== null && holder !== row.current && holder.querySelector("pre") === null) holder = holder.parentElement;- const pres = row.current?.querySelectorAll("pre") ?? [];- if (holder?.querySelector("pre") !== pres[pres.length - 1] || pres.length === 0) return;- event.preventDefault();- event.stopPropagation();- void navigator.clipboard?.writeText(code);- };+ const area = code === void 0 ? body : (0, import_react16.createElement)("div", { className: "bt-fold-code" }, body, (0, import_react16.createElement)(FoldCodeCopy, { code, actions }));return (0, import_react16.createElement)("div",- { ref: row, className: "bt-msg", onClick: tapTools, onClickCapture: copyFolded },+ { ref: row, className: "bt-msg", onClick: tapTools },(0, import_react16.createElement)("div",{ className: "bt-msg-line" },@@ -7757,7 +7766,7 @@ function Bubble({ text, index, roster, selfId, actions, sessionId, msgKey, menti(0, import_react16.createElement)("div",{ className: "bt-bubble", "data-folded": folded || void 0 },- control ? (0, import_react16.createElement)("div", { className: "bt-fold-body" }, body) : body,+ control ? (0, import_react16.createElement)("div", { className: "bt-fold-body" }, area) : area,control),live ? null : (0, import_react16.createElement)(MessageTools, { text: folded ? text : shown, name: roster.byId[selfId]?.name ?? t("Bot"), sessionId, react: key ? (emoji) => actions.toggleReaction(msgKey, index, emoji) : void 0, actions, open: toolsOpen })@@ -8121,27 +8130,14 @@ var scrollParent = (node) => {}return null;};-function EarlierUser({ row }) {+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 box = (0, import_react16.useRef)(null);- const copyFolded = (event) => {- if (code === void 0 || !(event.target instanceof Element)) return;- const button = event.target.closest("button");- const label = button?.getAttribute("aria-label");- if (!button || !/copyButton/i.test(button.className ?? "") && label !== t("Copy") && label !== t("Copied")) return;- let holder = button.parentElement;- while (holder !== null && holder !== box.current && holder.querySelector("pre") === null) holder = holder.parentElement;- const pres = box.current?.querySelectorAll("pre") ?? [];- if (holder?.querySelector("pre") !== pres[pres.length - 1] || pres.length === 0) return;- event.preventDefault();- event.stopPropagation();- void navigator.clipboard?.writeText(code);- };- return (0, import_react16.createElement)("div", { className: "bt-urow", ref: box, onClickCapture: copyFolded }, (0, import_react16.createElement)(+ const area = code === void 0 ? body : (0, import_react16.createElement)("div", { className: "bt-fold-code" }, body, (0, import_react16.createElement)(FoldCodeCopy, { code, actions }));+ return (0, import_react16.createElement)("div", { className: "bt-urow" }, (0, import_react16.createElement)("div",{ className: "bt-ububble", "data-folded": folded || void 0 },- control ? (0, import_react16.createElement)("div", { className: "bt-fold-body" }, body) : body,+ control ? (0, import_react16.createElement)("div", { className: "bt-fold-body" }, area) : area,control,row.images ? (0, import_react16.createElement)("span", { className: "bt-uimages" }, row.images === 1 ? t("1 image") : t("{count} images", { count: row.images })) : null));@@ -8248,7 +8244,7 @@ function chatRow(row, key, { sessionId, selfId, roster, actions, useUi, onBtwDelcase "divider":return (0, import_react16.createElement)(PartLine, { key, time: row.time });case "user":- return (0, import_react16.createElement)(EarlierUser, { key, row });+ return (0, import_react16.createElement)(EarlierUser, { key, row, actions });case "answer":return (0, import_react16.createElement)(AnsweredReply, { key, node: { data: row } });// A display-only view replays from the blueprint the host kept on the call.diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.jsindex 712e90bb..3173cc86 100644--- a/ds-bot/src/client/cells.js+++ b/ds-bot/src/client/cells.js@@ -1,6 +1,6 @@import { createElement as h, Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'import { createPortal } from 'react-dom'-import { MarkdownText } from './dsh-primitives.js'+import { MarkdownText, writeClipboard } from './dsh-primitives.js'import { inkText } from './inks.js'import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, isRelayContext, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts, elapsedLabel, clockLabel, messageClock } from './text.js'import { SmileIcon, ReplyIcon, DotsIcon, CheckIcon, DownloadIcon, CopyIcon, MemoryIcon } from './icons.js'@@ -53,6 +53,21 @@ export function Bubbles({ texts, roster, selfId, actions, streaming, sessionId,}))}+// 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.+function FoldCodeCopy({ code, actions }) {+ const [copied, setCopied] = useState(false)+ const copy = () => {+ void writeClipboard(code).then((ok) => {+ if (!ok) { actions?.reportError?.(new Error('Could not copy the code block'), 'copy'); return }+ setCopied(true); setTimeout(() => setCopied(false), 1000)+ }, () => actions?.reportError?.(new Error('Could not copy the code block'), 'copy'))+ }+ 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))+}+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 key = msgKey ? `${msgKey}:${index}` : undefined@@ -66,32 +81,16 @@ 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)}- // The copy button inside a folded message's last code block would copy only- // the part the preview kept; write the whole block instead. On capture, so- // the Markdown's own copy handler never sees the click.- const copyFolded = (event) => {- if (code === undefined || !(event.target instanceof Element)) return- const button = event.target.closest('button')- // The code block's copy control is the copyButton in its banner; its label- // varies by the DSH version, so match the class, with the label as a spare.- const label = button?.getAttribute('aria-label')- if (!button || (!/copyButton/i.test(button.className ?? '') && label !== t('Copy') && label !== t('Copied'))) return- // The copy control may sit inside the `pre` or in the chrome wrapping it:- // the nearest ancestor of the button that holds a `pre` is its block, and- // only the last block in a folded preview is the cut one.- let holder = button.parentElement- while (holder !== null && holder !== row.current && holder.querySelector('pre') === null) holder = holder.parentElement- const pres = row.current?.querySelectorAll('pre') ?? []- if (holder?.querySelector('pre') !== pres[pres.length - 1] || pres.length === 0) return- event.preventDefault()- event.stopPropagation()- void navigator.clipboard?.writeText(code)- }- return h('div', { ref: row, className: 'bt-msg', onClick: tapTools, onClickCapture: copyFolded },+ // 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 }))+ return h('div', { ref: row, className: 'bt-msg', onClick: tapTools },h('div', { className: 'bt-msg-line' },lead,h('div', { className: 'bt-bubble', 'data-folded': folded || undefined },- control ? h('div', { className: 'bt-fold-body' }, body) : body,+ control ? h('div', { className: 'bt-fold-body' }, area) : area,control),live ? null : h(MessageTools, { text: folded ? text : shown, name: roster.byId[selfId]?.name ?? t('Bot'), sessionId, react: key ? emoji => actions.toggleReaction(msgKey, index, emoji) : undefined, actions, open: toolsOpen })),picked.length ? h('div', { className: 'bt-reacts' }, picked.map(emoji => h('button', {@@ -428,25 +427,12 @@ const scrollParent = (node) => {return null}-function EarlierUser({ row }) {+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 box = useRef(null)- const copyFolded = (event) => {- if (code === undefined || !(event.target instanceof Element)) return- const button = event.target.closest('button')- const label = button?.getAttribute('aria-label')- if (!button || (!/copyButton/i.test(button.className ?? '') && label !== t('Copy') && label !== t('Copied'))) return- let holder = button.parentElement- while (holder !== null && holder !== box.current && holder.querySelector('pre') === null) holder = holder.parentElement- const pres = box.current?.querySelectorAll('pre') ?? []- if (holder?.querySelector('pre') !== pres[pres.length - 1] || pres.length === 0) return- event.preventDefault()- event.stopPropagation()- void navigator.clipboard?.writeText(code)- }- return h('div', { className: 'bt-urow', ref: box, onClickCapture: copyFolded }, h('div', { className: 'bt-ububble', 'data-folded': folded || undefined },- control ? h('div', { className: 'bt-fold-body' }, body) : body,+ const area = code === undefined ? body : h('div', { className: 'bt-fold-code' }, body, h(FoldCodeCopy, { code, 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,row.images ? h('span', { className: 'bt-uimages' }, row.images === 1 ? t('1 image') : t('{count} images', { count: row.images })) : null))}@@ -560,7 +546,7 @@ export function ChatRows({ items, sessionId, roster, actions, useUi, clock = falfunction 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 })+ case 'user': return h(EarlierUser, { key, row, actions })case 'answer': return h(AnsweredReply, { key, node: { data: row } })// 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 })diff --git a/ds-bot/src/client/dsh-primitives.js b/ds-bot/src/client/dsh-primitives.jsindex 993a98b7..d91fd348 100644--- a/ds-bot/src/client/dsh-primitives.js+++ b/ds-bot/src/client/dsh-primitives.js@@ -1,3 +1,3 @@// The DSH interface primitives the Bot views draw with. The desktop app's window does not// load DSH's interface; its build puts its own module in place of this one.-export { FishLogo, MarkdownText } from '@deepseek-ai/dsh-client-ui-primitives'+export { FishLogo, MarkdownText, writeClipboard } from '@deepseek-ai/dsh-client-ui-primitives'diff --git a/ds-bot/src/client/fold.js b/ds-bot/src/client/fold.jsindex 3817e288..6db00a96 100644--- a/ds-bot/src/client/fold.js+++ b/ds-bot/src/client/fold.js@@ -10,6 +10,13 @@ const ALWAYS = { chars: -1, lines: 0 }const PREVIEW_LINES = 10const PREVIEW_CHARS = 600const FENCE = /^ {0,3}(`{3,}|~{3,})/+// A closing fence is bare: a marker line carrying an info string (` ```js `) inside+// an open block is content, never a close.+const CLOSE = /^ {0,3}(`{3,}|~{3,})\s*$/+const closes = (line, open) => {+ const marker = CLOSE.exec(line)?.[1]+ return marker !== undefined && marker[0] === open[0] && marker.length >= open.length+}// Cuts `text` at `end` code units, backing up one when the last character is a// high surrogate so an emoji is not split in half.@@ -38,21 +45,22 @@ function openedFence(lines) {const marker = FENCE.exec(lines[i])?.[1]if (marker === undefined) continueif (open === null) { open = marker; openLine = i }- else if (marker[0] === open[0] && marker.length >= open.length) open = null+ else if (closes(lines[i], open)) open = null}return open === null ? null : { marker: open, line: openLine }}// The block a preview's cut fence opens, read whole from the unfolded text: the// lines between the fence and its close (or the end when it never closes), so a-// copy of the partly shown block does not stop at the fold.+// copy of the partly shown block does not stop at the fold. An indented opening+// fence indents its content the same way, and that indent is not the block's.function blockCode(body, fenceLine, open) {const lines = body.split('\n')+ const indent = /^ */.exec(lines[fenceLine])[0].lengthconst code = []for (let i = fenceLine + 1; i < lines.length; i += 1) {- const marker = FENCE.exec(lines[i])?.[1]- if (marker !== undefined && marker[0] === open[0] && marker.length >= open.length) break- code.push(lines[i])+ if (closes(lines[i], open)) break+ code.push(lines[i].replace(new RegExp(`^ {0,${indent}}`), ''))}return code.join('\n')}diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.jsindex eac6ea54..4f5ae40f 100644--- a/ds-bot/src/client/styles.js+++ b/ds-bot/src/client/styles.js@@ -367,6 +367,8 @@ html[data-windows-titlebar]:not([data-fullscreen]) :is(.bt-pane,.bt-panel)::befo.bt-exchange .bt-dialog-log{max-width:none;margin:0;padding:39px max(16px,calc((100% - 960px)/2)) 116px;scrollbar-width:thin}.bt-exchange .bt-tools{display:none}.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}.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 714e8580..3ea21825 100644--- a/ds-bot/test/fold.test.js+++ b/ds-bot/test/fold.test.js@@ -165,6 +165,19 @@ test('a folded preview also yields the whole code block it cut', () => {assert.equal(render('short', { whole: { length: 300_000 } }).code, undefined)})+// #718: a close is bare — a marker line with an info string inside a block is+// content — and an indented fence's indent is not part of the block's code.+test('the copied block follows Markdown fence rules', () => {+ const inner = `${lines(15)}\n\`\`\`literal\n${lines(15)}`+ assert.equal(foldView(`\`\`\`js\n${inner}\n\`\`\`\nafter`).code, inner)+ // Indent the opening fence up to three spaces: the same indent leaves the code.+ const padded = lines(30).split('\n').map(line => ` ${line}`).join('\n')+ assert.equal(foldView(` \`\`\`\n${padded}\n \`\`\``).code, lines(30))+ // A close padded with trailing spaces still closes; a longer marker does too.+ assert.equal(foldView(`\`\`\`\n${lines(30)}\n\`\`\` \nafter`).code, lines(30))+ assert.equal(foldView(`\`\`\`\n${lines(30)}\n\`\`\`\`\nafter`).code, lines(30))+})+test('a streaming text never folds', () => {fresh()assert.equal(render(lines(40), { live: true }).control, null)