A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Respect the Enter preference in the new-chat pane
klarkxy746e74dc2d51
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex d05c8a2b..92a28bd8 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -10688,6 +10688,7 @@ function NewMessagePills({ sessionId, useSessions, useUi, useTurnClock }) {}// src/client/enter-key.js+var sendsOnEnter = (prefs) => prefs?.enterToSend !== false;function insertComposerNewline(event, inputActions) {if (event.key !== "Enter" || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey || event.isComposing || event.keyCode === 229 || event.getModifierState?.("AltGraph")) return false;const target = event.target;@@ -10762,7 +10763,7 @@ function useDictation(onText) {return { listening, note, start, stop };}function ComposerVoice({ sessionId, inputActions, actions, useUi, useRoster }) {- const enterToSend = useRoster((state) => state.prefs?.enterToSend !== false);+ const enterToSend = useRoster((state) => sendsOnEnter(state.prefs));const composerRoot = (0, import_react21.useRef)(null);(0, import_react21.useEffect)(() => {const root = composerRoot.current?.closest("[data-composer-card]");@@ -14245,7 +14246,7 @@ ${listed}`, { axis: "y", ...QUICK_EDGES });"aria-label": placeholder,onChange: (event) => setMessage(event.target.value),onKeyDown: (event) => {- if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {+ if (event.key === "Enter" && sendsOnEnter(roster.prefs) && !event.shiftKey && !event.nativeEvent.isComposing) {event.preventDefault();sendMessage();}@@ -20649,8 +20650,15 @@ function listedOpener({ list, open, refresh, current }) {var inject = ["sessions", "uiWorkspace", "uiConversation", "slots", "theme", "layout"];function apply(ctx) {ctx.effect(() => installLocale(ctx.get("locale")), "ds-bot: interface copy");- const roster = createSource(EMPTY_ROSTER);migrateStorage();+ const PREFS_KEY = STORAGE.prefs;+ let savedPrefs = {};+ try {+ savedPrefs = JSON.parse(localStorage.getItem(PREFS_KEY) ?? "{}") ?? {};+ } catch {+ savedPrefs = {};+ }+ const roster = createSource({ ...EMPTY_ROSTER, prefs: savedPrefs });const unreadStore = sharedMap(STORAGE.unread);const reactionStore = sharedMap(STORAGE.reactions);const seenStore = sharedMap(STORAGE.seen);@@ -20717,13 +20725,6 @@ function apply(ctx) {state[id]?.at === entry.at ? state[id] : { ...entry, seen: opening ? 0 : Date.now() }])));};- const PREFS_KEY = STORAGE.prefs;- let savedPrefs = {};- try {- savedPrefs = JSON.parse(localStorage.getItem(PREFS_KEY) ?? "{}") ?? {};- } catch {- savedPrefs = {};- }const writeUnread = (id, value) => {const unread = unreadStore.update((marks) => setUnread(marks, id, value), ui2.getSnapshot().unread);ui2.set((state) => JSON.stringify(state.unread) === JSON.stringify(unread) ? state : { ...state, unread });diff --git a/ds-bot/src/client/composer.js b/ds-bot/src/client/composer.jsindex 470dffe6..88190331 100644--- a/ds-bot/src/client/composer.js+++ b/ds-bot/src/client/composer.js@@ -4,7 +4,7 @@ import { ChatsIcon, ClockIcon, MicIcon, PaperclipIcon, PeopleIcon, PlusIcon, Wavimport { BotMark } from './mark.js'import { useLinger, useViewport, viewBottom } from './motion.js'import { t } from './i18n.js'-import { insertComposerNewline } from './enter-key.js'+import { insertComposerNewline, sendsOnEnter } from './enter-key.js'// -------------------------------------------------------------------------// Composer: dictation mic and the voice-chat button. The shell's send@@ -55,7 +55,7 @@ export function useDictation(onText) {}export function ComposerVoice({ sessionId, inputActions, actions, useUi, useRoster }) {- const enterToSend = useRoster(state => state.prefs?.enterToSend !== false)+ const enterToSend = useRoster(state => sendsOnEnter(state.prefs))const composerRoot = useRef(null)useEffect(() => {const root = composerRoot.current?.closest('[data-composer-card]')diff --git a/ds-bot/src/client/enter-key.js b/ds-bot/src/client/enter-key.jsindex 1bea9489..24b98bdf 100644--- a/ds-bot/src/client/enter-key.js+++ b/ds-bot/src/client/enter-key.js@@ -1,3 +1,8 @@+// Enter submits only while the preference sends on Enter; off, a plain Enter is the+// field's own newline and only the send button submits. Before the roster answers,+// the snapshot's prefs come from the window's cache, so a saved `false` already holds.+export const sendsOnEnter = prefs => prefs?.enterToSend !== false+// Plain Enter can insert a line instead of submitting. Menus, modified shortcuts,// and IME confirmation keep the host composer's own behavior.export function insertComposerNewline(event, inputActions) {diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.jsindex 8d5e99dd..110fff86 100644--- a/ds-bot/src/client/index.js+++ b/ds-bot/src/client/index.js@@ -51,8 +51,13 @@ export const inject = ['sessions', 'uiWorkspace', 'uiConversation', 'slots', 'thexport function apply(ctx) {ctx.effect(() => installLocale(ctx.get('locale')), 'ds-bot: interface copy')- const roster = createSource(EMPTY_ROSTER)migrateStorage()+ // The window's cached prefs stand in until the first pull answers: a saved+ // `enterToSend: false` then already holds, instead of Enter sending meanwhile.+ const PREFS_KEY = STORAGE.prefs+ let savedPrefs = {}+ try { savedPrefs = JSON.parse(localStorage.getItem(PREFS_KEY) ?? '{}') ?? {} } catch { savedPrefs = {} }+ const roster = createSource({ ...EMPTY_ROSTER, prefs: savedPrefs })const unreadStore = sharedMap(STORAGE.unread)const reactionStore = sharedMap(STORAGE.reactions)// When each conversation was last left; a visit compares new turns against it.@@ -144,9 +149,6 @@ export function apply(ctx) {memoryNews.set(state => Object.fromEntries(Object.entries(next).map(([id, entry]) => [id,state[id]?.at === entry.at ? state[id] : { ...entry, seen: opening ? 0 : Date.now() }])))}- const PREFS_KEY = STORAGE.prefs- let savedPrefs = {}- try { savedPrefs = JSON.parse(localStorage.getItem(PREFS_KEY) ?? '{}') ?? {} } catch { savedPrefs = {} }const writeUnread = (id, value) => {const unread = unreadStore.update(marks => setUnread(marks, id, value), ui.getSnapshot().unread)ui.set(state => (JSON.stringify(state.unread) === JSON.stringify(unread) ? state : { ...state, unread }))diff --git a/ds-bot/src/client/new-chat.js b/ds-bot/src/client/new-chat.jsindex fd53a99e..c3c93d0b 100644--- a/ds-bot/src/client/new-chat.js+++ b/ds-bot/src/client/new-chat.js@@ -6,6 +6,7 @@ import { useEscape, usePaneLeft } from './overlay-hooks.js'import { CreateBot } from './create-bot.js'import { QUICK_EDGES, useFlip, useGlide, useMorph } from './motion.js'import { t } from './i18n.js'+import { sendsOnEnter } from './enter-key.js'export function NewChat({ mode, roster, actions }) {const [query, setQuery] = useState('')@@ -173,7 +174,7 @@ export function NewChat({ mode, roster, actions }) {rows: 1, value: message, placeholder, 'aria-label': placeholder,onChange: event => setMessage(event.target.value),onKeyDown: (event) => {- if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); sendMessage() }+ if (event.key === 'Enter' && sendsOnEnter(roster.prefs) && !event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault(); sendMessage() }},}),h('button', { type: 'button', className: 'bt-nc-send', 'aria-label': t('Send message'), disabled: busy || message.trim() === '' || picked.length === 0, onClick: sendMessage }, h(ArrowUpIcon))))))diff --git a/ds-bot/test/new-chat.test.js b/ds-bot/test/new-chat.test.jsnew file mode 100644index 00000000..d5b51563--- /dev/null+++ b/ds-bot/test/new-chat.test.js@@ -0,0 +1,160 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { fileURLToPath } from 'node:url'+import { runInNewContext } from 'node:vm'+import { build } from 'esbuild'++// The pane's message field shares the composer preference: while Enter sends, a plain+// Enter submits; off, it is the field's own newline and only the send button submits.+const { outputFiles } = await build({+ entryPoints: [fileURLToPath(new URL('../src/client/new-chat.js', import.meta.url))],+ bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',+ external: ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'],+})+let current+const slot = (make) => {+ const index = current.index+++ return current.slots[index] ??= make()+}+const effect = (make, deps) => {+ const cell = slot(() => ({}))+ if (!cell.deps || deps === undefined || deps.some((value, index) => value !== cell.deps[index])) {+ current.effects.push(() => { cell.stop?.(); cell.stop = make(); cell.deps = deps })+ }+}+const react = {+ Fragment: 'fragment',+ createElement: (type, props, ...children) => ({ type, props: { ...props, children } }),+ useState: (initial) => {+ const cell = slot(() => ({ value: typeof initial === 'function' ? initial() : initial }))+ return [cell.value, next => { cell.value = typeof next === 'function' ? next(cell.value) : next }]+ },+ useRef: initial => slot(() => ({ current: initial })),+ useEffect: effect, useLayoutEffect: effect,+ useMemo: make => make(),+ useCallback: fn => fn,+}+const module = { exports: {} }+runInNewContext(outputFiles[0].text, {+ module, exports: module.exports,+ require: (name) => {+ if (name === 'react') return react+ if (name === 'react-dom') return { createPortal: node => node }+ if (name === '@deepseek-ai/dsh-client-ui-primitives') return { FishLogo: 'fish', MarkdownText: () => null, writeClipboard: () => {} }+ throw new Error(`no platform module ${name}`)+ },+ window: { addEventListener() {}, removeEventListener() {}, innerWidth: 1200, innerHeight: 800, matchMedia: () => ({ matches: false }) },+ document: { querySelector: () => null, documentElement: { addEventListener() {}, removeEventListener() {} } },+ requestAnimationFrame: () => 0, cancelAnimationFrame() {}, performance: { now: () => 0 },+})+const { NewChat } = module.exports+const mount = (props) => {+ const instance = {+ slots: [], effects: [], props,+ render(next = instance.props) {+ instance.props = next+ instance.index = 0+ current = instance+ const out = NewChat(next)+ current = undefined+ for (const run of instance.effects.splice(0)) run()+ return out+ },+ }+ return instance+}+const all = (node, check) => {+ if (Array.isArray(node)) return node.flatMap(child => all(child, check))+ if (!node || typeof node !== 'object') return []+ return [...(check(node) ? [node] : []), ...all(node.props.children, check)]+}+const text = (node) => {+ if (Array.isArray(node)) return node.map(text).join('')+ if (!node || typeof node !== 'object') return String(node ?? '')+ return text(node.props?.children)+}+const textarea = node => all(node, child => child.type === 'textarea')[0]+const options = node => all(node, child => child.props?.role === 'option')+const enter = (extra = {}) => ({+ key: 'Enter', shiftKey: false, nativeEvent: { isComposing: false }, prevented: false,+ preventDefault() { this.prevented = true }, ...extra,+})+const tick = () => new Promise(resolve => setImmediate(resolve))++// A group pane picks its admin, then the member the typed message goes to. Every+// step awaits: each click runs through the pane's async busy guard before the next+// render reads the new state.+const pane = async ({ ready = true, prefs = {} } = {}) => {+ const calls = { send: [], rooms: [], sessions: [] }+ const bots = [+ { id: 'chief', name: 'Chief', role: 'main' },+ { id: 'worker', name: 'Worker', role: 'helper' },+ ]+ const roster = { ready, prefs, bots, byId: { chief: bots[0], worker: bots[1] }, roomsById: {}, agents: [] }+ const actions = {+ closeOverlay() { calls.closed = (calls.closed ?? 0) + 1 },+ createRoom: async (ids) => { calls.rooms.push(ids); return { id: 'room1' } },+ send: async (id, value) => { calls.send.push([id, value]) },+ openSession: (id) => { calls.sessions.push(id) },+ setFlags: async () => {},+ }+ const view = mount({ mode: 'group', roster, actions })+ const pick = async (name) => {+ const row = options(view.render()).find(child => text(child).includes(name))+ assert.ok(row, `no option for ${name}`)+ row.props.onClick()+ await tick()+ }+ await pick('Chief')+ await pick('Worker')+ textarea(view.render()).props.onChange({ target: { value: 'hello team' } })+ return { view, calls, tree: () => view.render() }+}++test('with Enter sending on, a plain Enter sends the message to the group', async () => {+ const { calls, tree } = await pane({ prefs: { enterToSend: true } })+ const event = enter()+ textarea(tree()).props.onKeyDown(event)+ await tick()+ assert.equal(event.prevented, true)+ assert.deepEqual(JSON.parse(JSON.stringify(calls.rooms)), [['chief', 'worker']])+ assert.deepEqual(JSON.parse(JSON.stringify(calls.send)), [['room1', 'hello team']])+})++test('with Enter sending saved off, a plain Enter is the field\'s own newline', async () => {+ const { calls, tree } = await pane({ prefs: { enterToSend: false } })+ const event = enter()+ textarea(tree()).props.onKeyDown(event)+ await tick()+ assert.equal(event.prevented, false)+ assert.deepEqual(calls.send, [])+ assert.deepEqual(calls.rooms, [])+})++test('a roster still loading keeps a saved off and a first-time default', async () => {+ // The pre-pull roster stays ready:false but already carries the window's saved prefs.+ const saved = await pane({ ready: false, prefs: { enterToSend: false } })+ const off = enter()+ textarea(saved.tree()).props.onKeyDown(off)+ await tick()+ assert.equal(off.prevented, false)+ assert.deepEqual(JSON.parse(JSON.stringify(saved.calls.send)), [])+ // A window with nothing saved keeps the default: Enter sends, it is not stuck off.+ const fresh = await pane({ ready: false, prefs: {} })+ const on = enter()+ textarea(fresh.tree()).props.onKeyDown(on)+ await tick()+ assert.equal(on.prevented, true)+ assert.deepEqual(JSON.parse(JSON.stringify(fresh.calls.send)), [['room1', 'hello team']])+})++test('Shift+Enter and IME confirmation keep their default behavior', async () => {+ for (const extra of [{ shiftKey: true }, { nativeEvent: { isComposing: true } }]) {+ const { calls, tree } = await pane({ prefs: { enterToSend: true } })+ const event = enter(extra)+ textarea(tree()).props.onKeyDown(event)+ await tick()+ assert.equal(event.prevented, false)+ assert.deepEqual(calls.send, [])+ }+})