Skip to content

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

Steer queued messages with Enter on an empty Bot composer

Fei24119a788c4fcebc
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 1dcae995..33d324ab 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -218,6 +218,8 @@ var ZH = {
// Header
"Message {name}": "给 {name} 发消息",
Message: "发消息",
+ "Press Enter to steer queued messages": "按 Enter 插话发送排队的消息",
+ "Couldn’t steer the queued messages. Try again.": "插话发送失败,请重试。",
"View conversation details": "查看对话详情",
"1 new message": "1 条新消息",
"{count} new messages": "{count} 条新消息",
@@ -11267,6 +11269,24 @@ function NewMessagePills({ sessionId, useSessions, useUi, useTurnClock }) {
);
}
+// src/client/enter-steer.js
+var steerable = (input) => input !== void 0 && input.phase === "plain" && input.draft.trim() === "" && input.attachmentIds.length === 0 && input.queue.some((message) => message.source?.kind === "user");
+var enterSteers = (event, input) => event.key === "Enter" && !event.shiftKey && !event.ctrlKey && !event.metaKey && !event.altKey && !event.getModifierState?.("AltGraph") && !event.isComposing && event.keyCode !== 229 && !event.repeat && steerable(input);
+var steerQueued = async (session) => {
+ try {
+ const queued = session.projections.faceOf("inbox").getSnapshot()?.["next-turn"] ?? [];
+ for (const item of queued) {
+ if (item.source?.kind !== "user") continue;
+ const result = await session.updateQueue(item.id, { kind: "steer" });
+ if (result.ok) continue;
+ return result.error.code === "session/steer-unavailable" || result.error.code === "session/queue-item-not-found" ? "done" : "failed";
+ }
+ return "done";
+ } catch {
+ return "failed";
+ }
+};
+
// src/client/composer.js
var import_react23 = require("react");
var import_react_dom5 = require("react-dom");
@@ -11392,13 +11412,18 @@ function menuIcons(roster) {
return marks.get(id);
};
}
-function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
+function ComposerPlus({ sessionId, inputActions, useInput, useRoster, actions }) {
const roster = useRoster((value) => value);
const [open, setOpen] = (0, import_react23.useState)(null);
const [shown, leaving] = useLinger(open, 120);
const button = (0, import_react23.useRef)(null);
const menu = (0, import_react23.useRef)(null);
const tick = useViewport();
+ const inputNow = (0, import_react23.useRef)(void 0);
+ const ready = useInput?.((state) => {
+ inputNow.current = state;
+ return steerable(state);
+ }) === true;
(0, import_react23.useEffect)(() => {
if (!open) return void 0;
const onDown = (event) => {
@@ -11417,6 +11442,34 @@ function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
window.removeEventListener("keydown", onKey, true);
};
}, [open]);
+ (0, import_react23.useEffect)(() => {
+ const card = button.current?.closest("[data-composer-card]");
+ if (!ready || card === null || card === void 0) return void 0;
+ card.style.setProperty("--bt-placeholder", JSON.stringify(t("Press Enter to steer queued messages")));
+ return () => card.style.removeProperty("--bt-placeholder");
+ });
+ (0, import_react23.useEffect)(() => {
+ let steering = false;
+ const onKey = (event) => {
+ if (steering || event.defaultPrevented || open) return;
+ const target2 = event.target;
+ if (typeof target2?.closest !== "function") return;
+ const card = button.current?.closest("[data-composer-card]");
+ if (card === null || card === void 0 || target2.closest("[data-composer-card]") !== card) return;
+ if (target2.closest("[contenteditable=true]") === null) return;
+ if (target2.closest("[data-composer-composing]")) return;
+ if (target2.ownerDocument?.querySelector('[role="listbox"]')) return;
+ if (!enterSteers(event, inputNow.current)) return;
+ event.preventDefault();
+ event.stopPropagation();
+ steering = true;
+ void Promise.resolve(actions.steerQueued(sessionId)).finally(() => {
+ steering = false;
+ });
+ };
+ window.addEventListener("keydown", onKey, true);
+ return () => window.removeEventListener("keydown", onKey, true);
+ }, [open, sessionId]);
const place = (0, import_react23.useMemo)(() => {
if (!shown || !button.current) return null;
const rect = button.current.getBoundingClientRect();
@@ -21965,6 +22018,13 @@ function apply(ctx) {
};
}
};
+ actions.steerQueued = async (sessionId) => {
+ const session = ctx.sessions.binding(sessionId)?.session;
+ if (session === void 0) return;
+ if (await steerQueued(session) === "failed") {
+ actions.reportError(new Error(t("Couldn’t steer the queued messages. Try again.")), "steer-queue");
+ }
+ };
actions.canOpenTerminal = () => ctx.get("sidebarRight") !== void 0 && ctx.get("sidebarRightTabs")?.get("terminal") !== void 0;
actions.newTerminal = () => {
actions.closePanel();
diff --git a/ds-bot/src/client/composer.js b/ds-bot/src/client/composer.js
index 406d4a20..a5dfa809 100644
--- a/ds-bot/src/client/composer.js
+++ b/ds-bot/src/client/composer.js
@@ -6,6 +6,7 @@ import { BotMark } from './mark.js'
import { useLinger, useViewport, viewBottom } from './motion.js'
import { t } from './i18n.js'
import { insertComposerNewline, sendsOnEnter } from './enter-key.js'
+import { enterSteers, steerable } from './enter-steer.js'
// -------------------------------------------------------------------------
// Composer: dictation mic and the voice-chat button. The shell's send
@@ -117,13 +118,17 @@ export function menuIcons(roster) {
// menu, whose plan, permission, model and compact rows reach past what DS Bot keeps
// for its Bots; "/" still opens that menu. Files go through the shell's own file
// input beside it.
-export function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
+export function ComposerPlus({ sessionId, inputActions, useInput, useRoster, actions }) {
const roster = useRoster(value => value)
const [open, setOpen] = useState(null)
const [shown, leaving] = useLinger(open, 120)
const button = useRef(null)
const menu = useRef(null)
const tick = useViewport()
+ // The selector runs on every input change, so inputNow stays live for the key
+ // handler while `ready` re-renders only when steerability flips.
+ const inputNow = useRef(undefined)
+ const ready = useInput?.((state) => { inputNow.current = state; return steerable(state) }) === true
useEffect(() => {
if (!open) return undefined
const onDown = (event) => { if (![button.current, menu.current].some(node => node?.contains(event.target))) setOpen(null) }
@@ -132,6 +137,34 @@ export function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
window.addEventListener('keydown', onKey, true)
return () => { window.removeEventListener('mousedown', onDown, true); window.removeEventListener('keydown', onKey, true) }
}, [open])
+ // No deps: the "+" can mount after this effect first ran, and the card swap on a
+ // session switch must pick the placeholder up again.
+ useEffect(() => {
+ const card = button.current?.closest('[data-composer-card]')
+ if (!ready || card === null || card === undefined) return undefined
+ card.style.setProperty('--bt-placeholder', JSON.stringify(t('Press Enter to steer queued messages')))
+ return () => card.style.removeProperty('--bt-placeholder')
+ })
+ useEffect(() => {
+ let steering = false
+ const onKey = (event) => {
+ if (steering || event.defaultPrevented || open) return
+ const target = event.target
+ if (typeof target?.closest !== 'function') return
+ const card = button.current?.closest('[data-composer-card]')
+ if (card === null || card === undefined || target.closest('[data-composer-card]') !== card) return
+ if (target.closest('[contenteditable=true]') === null) return
+ if (target.closest('[data-composer-composing]')) return
+ if (target.ownerDocument?.querySelector('[role="listbox"]')) return
+ if (!enterSteers(event, inputNow.current)) return
+ event.preventDefault()
+ event.stopPropagation()
+ steering = true
+ void Promise.resolve(actions.steerQueued(sessionId)).finally(() => { steering = false })
+ }
+ window.addEventListener('keydown', onKey, true)
+ return () => window.removeEventListener('keydown', onKey, true)
+ }, [open, sessionId])
// Hooks stay above the early return below: the roster may not know the Bot yet, and a
// render that skips a hook breaks the composer's slot when the roster arrives.
// Anchored to the "+" each render: the visible viewport can move (on-screen
diff --git a/ds-bot/src/client/enter-steer.js b/ds-bot/src/client/enter-steer.js
new file mode 100644
index 00000000..33784e3b
--- /dev/null
+++ b/ds-bot/src/client/enter-steer.js
@@ -0,0 +1,37 @@
+// Plain Enter on an empty composer while the Bot works submits nothing in the
+// shell. DS Bot reads it as "steer my queued messages into the running turn" —
+// the queue dock's steer button for every queued row at once (#839).
+
+// The composer can steer: idle draft, no text, no attachments, and at least one
+// queued message of the user's own. Team deliveries and replies also sit in the
+// queue and stay there.
+export const steerable = input => input !== undefined
+ && input.phase === 'plain'
+ && input.draft.trim() === ''
+ && input.attachmentIds.length === 0
+ && input.queue.some(message => message.source?.kind === 'user')
+
+export const enterSteers = (event, input) => event.key === 'Enter'
+ && !event.shiftKey && !event.ctrlKey && !event.metaKey && !event.altKey
+ && !event.getModifierState?.('AltGraph')
+ && !event.isComposing && event.keyCode !== 229 && !event.repeat
+ && steerable(input)
+
+// Steers the user's queued messages in FIFO order, like the queue dock's steer
+// button per row. An Agent that stopped between read and steer
+// (session/steer-unavailable) or a row it already claimed
+// (session/queue-item-not-found) converges silently; anything else reports.
+export const steerQueued = async (session) => {
+ try {
+ const queued = session.projections.faceOf('inbox').getSnapshot()?.['next-turn'] ?? []
+ for (const item of queued) {
+ if (item.source?.kind !== 'user') continue
+ const result = await session.updateQueue(item.id, { kind: 'steer' })
+ if (result.ok) continue
+ return result.error.code === 'session/steer-unavailable' || result.error.code === 'session/queue-item-not-found' ? 'done' : 'failed'
+ }
+ return 'done'
+ } catch {
+ return 'failed'
+ }
+}
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 92e235b2..4db4af37 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -183,6 +183,8 @@ const ZH = {
// Header
'Message {name}': '给 {name} 发消息',
Message: '发消息',
+ 'Press Enter to steer queued messages': '按 Enter 插话发送排队的消息',
+ 'Couldn’t steer the queued messages. Try again.': '插话发送失败,请重试。',
'View conversation details': '查看对话详情',
'1 new message': '1 条新消息',
'{count} new messages': '{count} 条新消息',
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 1bba75df..dd2ba78f 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -39,6 +39,7 @@ import { noteLeft, setUnread, sharedMap, toggleReaction } from './shared-map.js'
import { freePriority, groupsFor, readMode, surfaceGroups, writeMode } from './surface.js'
import { installLocale, language, t } from './i18n.js'
import { noteClientError, quietly } from './diagnostics.js'
+import { steerQueued } from './enter-steer.js'
import { RIGHTBAR_ATTRIBUTES, columnOpened, createSwitchWindow, drawerOpened, rightColumnOpen } from './right-panel.js'
import { ErrorToast, FEEDBACK_CSS } from './feedback.js'
import { ABOUT_CSS } from './about.js'
@@ -769,6 +770,15 @@ export function apply(ctx) {
return () => {}
}
}
+ // Enter on an empty composer while the Bot works sends the user's queued
+ // messages into the running turn (the "+" owns the key; #839).
+ actions.steerQueued = async (sessionId) => {
+ const session = ctx.sessions.binding(sessionId)?.session
+ if (session === undefined) return
+ if (await steerQueued(session) === 'failed') {
+ actions.reportError(new Error(t('Couldn’t steer the queued messages. Try again.')), 'steer-queue')
+ }
+ }
// A terminal tab in DSH's right column, only where the terminal plugin
// registered its type and the column face is there.
actions.canOpenTerminal = () => ctx.get('sidebarRight') !== undefined && ctx.get('sidebarRightTabs')?.get('terminal') !== undefined
diff --git a/ds-bot/test/composer-plus.test.js b/ds-bot/test/composer-plus.test.js
index d01e49b8..9122dc0c 100644
--- a/ds-bot/test/composer-plus.test.js
+++ b/ds-bot/test/composer-plus.test.js
@@ -34,6 +34,7 @@ function render(roster) {
hooks = 0
const tree = ComposerPlus({
sessionId: 'chief', useRoster: select => select(roster),
+ useInput: select => select({ phase: 'plain', draft: '', attachmentIds: [], queue: [] }),
actions: { canReferenceChat: () => false },
})
return { tree, hooks }
diff --git a/ds-bot/test/enter-steer.test.js b/ds-bot/test/enter-steer.test.js
new file mode 100644
index 00000000..0719a847
--- /dev/null
+++ b/ds-bot/test/enter-steer.test.js
@@ -0,0 +1,104 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { enterSteers, steerable, steerQueued } from '../src/client/enter-steer.js'
+
+const input = (over = {}) => ({ phase: 'plain', draft: '', attachmentIds: [], queue: [{ id: 'm1', source: { kind: 'user' } }], ...over })
+const event = (over = {}) => ({ key: 'Enter', ...over })
+
+test('plain Enter on an empty composer with the user\'s queue steers', () => {
+ assert.equal(enterSteers(event(), input()), true)
+ assert.equal(enterSteers(event(), input({ draft: ' \n\t ' })), true)
+ assert.equal(steerable(input()), true)
+})
+
+test('modifiers, IME and key repeat pass Enter through', () => {
+ for (const over of [
+ { key: 'a' },
+ { shiftKey: true },
+ { ctrlKey: true },
+ { metaKey: true },
+ { altKey: true },
+ { getModifierState: key => key === 'AltGraph' },
+ { isComposing: true },
+ { keyCode: 229 },
+ { repeat: true },
+ ]) {
+ assert.equal(enterSteers(event(over), input()), false, JSON.stringify(over))
+ }
+})
+
+test('a non-empty draft, attachments, a busy phase or no user queue stay put', () => {
+ for (const over of [
+ { draft: 'hello' },
+ { attachmentIds: ['a1'] },
+ { phase: 'submitting' },
+ { phase: 'adjudicating' },
+ { phase: 'claimed' },
+ { queue: [] },
+ { queue: [{ id: 'm1', source: { kind: 'bot' } }, { id: 'm2', source: { kind: 'user-question-reply' } }] },
+ { queue: [{ id: 'm1' }] },
+ ]) {
+ assert.equal(enterSteers(event(), input(over)), false, JSON.stringify(over))
+ assert.equal(steerable(input(over)), false, JSON.stringify(over))
+ }
+ assert.equal(steerable(undefined), false)
+})
+
+const session = (queued, results = []) => {
+ const calls = []
+ return {
+ calls,
+ projections: { faceOf: () => ({ getSnapshot: () => ({ 'next-turn': queued }) }) },
+ updateQueue: async (id, action) => {
+ calls.push([id, action])
+ const next = results.length === 0 ? { ok: true } : results.shift()
+ if (next instanceof Error) throw next
+ return next
+ },
+ }
+}
+
+test('steerQueued steers only the user\'s own rows in FIFO order', async () => {
+ const queued = [
+ { id: 'u1', source: { kind: 'user' } },
+ { id: 'b1', source: { kind: 'bot' } },
+ { id: 'u2', source: { kind: 'user' } },
+ { id: 'r1', source: { kind: 'user-question-reply' } },
+ { id: 'u3', source: { kind: 'user' } },
+ ]
+ const s = session(queued)
+ assert.equal(await steerQueued(s), 'done')
+ assert.deepEqual(s.calls, [['u1', { kind: 'steer' }], ['u2', { kind: 'steer' }], ['u3', { kind: 'steer' }]])
+})
+
+test('steerQueued converges silently on a stale queue or a stopped Agent', async () => {
+ for (const code of ['session/steer-unavailable', 'session/queue-item-not-found']) {
+ const s = session(
+ [{ id: 'u1', source: { kind: 'user' } }, { id: 'u2', source: { kind: 'user' } }],
+ [{ ok: true }, { ok: false, error: { code } }],
+ )
+ assert.equal(await steerQueued(s), 'done', code)
+ assert.deepEqual(s.calls, [['u1', { kind: 'steer' }], ['u2', { kind: 'steer' }]])
+ }
+})
+
+test('steerQueued reports other failures', async () => {
+ const s = session(
+ [{ id: 'u1', source: { kind: 'user' } }, { id: 'u2', source: { kind: 'user' } }],
+ [{ ok: false, error: { code: 'session/gone' } }],
+ )
+ assert.equal(await steerQueued(s), 'failed')
+ assert.deepEqual(s.calls, [['u1', { kind: 'steer' }]])
+ const rejecting = session([{ id: 'u1', source: { kind: 'user' } }], [new Error('offline')])
+ assert.equal(await steerQueued(rejecting), 'failed')
+})
+
+test('steerQueued on an empty or other-source queue calls nothing', async () => {
+ for (const queued of [[], [{ id: 'b1', source: { kind: 'bot' } }]]) {
+ const s = session(queued)
+ assert.equal(await steerQueued(s), 'done')
+ assert.deepEqual(s.calls, [])
+ }
+ const empty = { projections: { faceOf: () => ({ getSnapshot: () => undefined }) }, updateQueue: () => assert.fail() }
+ assert.equal(await steerQueued(empty), 'done')
+})