Skip to content

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

Count the work clock from the start of the turn

Fei2411f388fc765579
diff --git a/ds-bot/client.js b/ds-bot/client.js
index f741c477..484938ff 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -1690,6 +1690,11 @@ function relativeShort(ms) {
if (diff < 30 * 864e5) return t("{n} d", { n: Math.floor(diff / 864e5) });
return new Date(ms).toLocaleDateString(dateLocale(), { month: "short", day: "numeric" });
}
+function elapsedLabel(ms) {
+ const total = Math.max(0, Math.floor(ms / 1e3));
+ const hours = Math.floor(total / 3600);
+ return `${hours > 0 ? `${hours}h ` : ""}${total >= 60 ? `${Math.floor(total / 60) % 60}m ` : ""}${total % 60}s`;
+}
var contentText = (content) => (content ?? []).filter((block) => block?.type === "text").map((block) => block.text).join("\n");
var HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/;
var currentPart = (bot) => bot.sessionId ?? bot.id;
@@ -2932,7 +2937,7 @@ header[class*="_header"] .bt-head{flex:1 1 auto;width:100%}
.bt-typing-text{display:flex;align-items:center;flex:1 1 auto;min-width:0;animation:bt-typing-label .22s ease-out .2s backwards}
.bt-typing-label{display:inline-flex;align-items:center;gap:6px;min-width:0;animation:bt-typing-label .22s ease-out backwards}
.bt-typing-label>.bt-shimmer{font-size:14px;line-height:22px;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
-.bt-typing-time{flex-shrink:0;font-size:12px;line-height:22px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}
+.bt-typing-time{flex-shrink:0;margin-left:6px;font-size:12px;line-height:22px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}
@keyframes bt-typing-in{from{opacity:0;transform:scale(.9)}}
@keyframes bt-typing-out{from{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.92);filter:blur(3px)}}
@keyframes bt-typing-label{from{opacity:0;filter:blur(5px);transform:translateY(3px)}}
@@ -4693,6 +4698,20 @@ function TurnTailCell({ turn: location2, sessionId, useTurnClock, useUi, actions
function Shimmer({ children }) {
return (0, import_react7.createElement)("span", { className: "bt-shimmer" }, children);
}
+function Elapsed({ at, className }) {
+ const [now, setNow] = (0, import_react7.useState)(Date.now);
+ (0, import_react7.useEffect)(() => {
+ let timer = 0;
+ const tick = () => {
+ const time = Date.now();
+ setNow(time);
+ timer = setTimeout(tick, 1e3 - ((time - at) % 1e3 + 1e3) % 1e3);
+ };
+ tick();
+ return () => clearTimeout(timer);
+ }, [at]);
+ return (0, import_react7.createElement)("span", { className }, `· ${elapsedLabel(Math.max(1e3, now - at))}`);
+}
var PHRASES = {
thinking: ["Thinking about it", "Weighing the options", "Working out a plan", "Sorting out the details"],
working: ["On it", "Busy with it", "Moving ahead", "Taking care of it", "Making headway"]
@@ -4995,14 +5014,6 @@ var import_react8 = require("react");
var import_react_dom2 = require("react-dom");
var PHRASE_HOLD_MS = 800;
var drawPhrase = (pool) => t(pool[Math.min(pool.length - 1, Math.floor(Math.random() * pool.length))]);
-function elapsedLabel(ms) {
- const seconds = Math.max(0, Math.floor(ms / 1e3));
- if (seconds < 60) return `${seconds}s`;
- const minutes = Math.floor(seconds / 60);
- if (minutes < 60) return seconds % 60 === 0 ? `${minutes}m` : `${minutes}m ${seconds % 60}s`;
- const hours = Math.floor(minutes / 60);
- return minutes % 60 === 0 ? `${hours}h` : `${hours}h ${minutes % 60}m`;
-}
function useRunningHost(active) {
const [host, setHost] = (0, import_react8.useState)(null);
(0, import_react8.useEffect)(() => {
@@ -5075,9 +5086,13 @@ function useRowEntrances(replacing) {
};
}, []);
}
-function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, useSession, actions }) {
+function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, useSession, useWork, actions }) {
const roster = useRoster((value) => value);
const running = useSessionStatus((map) => map.get(sessionId)?.running === true);
+ const turnAt = useWork?.((work) => work.turns?.[sessionId]);
+ const runAt = (0, import_react8.useRef)(0);
+ if (!running) runAt.current = 0;
+ else if (runAt.current === 0) runAt.current = Date.now();
const liveKey = useLive((state) => JSON.stringify(state[sessionId] ?? {}));
const pendingInput = useSession((snapshot) => Math.max(0, ...(snapshot?.pendingSubmissions ?? []).filter((sub) => sub.placement !== "queued").map((sub) => sub.time)));
const bot = roster.byId[sessionId];
@@ -5139,16 +5154,8 @@ function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, us
if (!running) actions.clearLive(sessionId);
}, [running, sessionId]);
useRowEntrances(() => leaving.current || Date.now() - endedAt.current < 300);
- const [now, setNow] = (0, import_react8.useState)(Date.now);
- (0, import_react8.useEffect)(() => {
- if (phase !== "in") return void 0;
- setNow(Date.now());
- const timer = setInterval(() => setNow(Date.now()), 1e3);
- return () => clearInterval(timer);
- }, [phase]);
const host = useRunningHost(running);
if (!host || phase === null || !shown) return null;
- const elapsed = now - shown.at >= 1e3 ? elapsedLabel(now - shown.at) : null;
return (0, import_react_dom2.createPortal)((0, import_react8.createElement)(
"div",
{ className: "bt-typing", "data-exiting": phase === "out" ? "" : void 0, "aria-hidden": true },
@@ -5156,12 +5163,8 @@ function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, us
(0, import_react8.createElement)(
"span",
{ className: "bt-typing-text" },
- (0, import_react8.createElement)(
- "span",
- { key: `${shown.key}:${shown.at}`, className: "bt-typing-label" },
- (0, import_react8.createElement)(Shimmer, null, `${shown.text}…`),
- elapsed ? (0, import_react8.createElement)("span", { className: "bt-typing-time" }, `· ${elapsed}`) : null
- )
+ (0, import_react8.createElement)("span", { key: `${shown.key}:${shown.at}`, className: "bt-typing-label" }, (0, import_react8.createElement)(Shimmer, null, `${shown.text}…`)),
+ (0, import_react8.createElement)(Elapsed, { at: Math.max(turnAt ?? runAt.current, inputAt), className: "bt-typing-time" })
)
), host);
}
@@ -5972,7 +5975,7 @@ function MemoryNotice({ shown }) {
(0, import_react10.createElement)("span", { className: "bt-pill-mem-in", ref: inner }, (0, import_react10.createElement)("span", { className: "bt-pill-mem-ico" }, (0, import_react10.createElement)(MemoryIcon)), label)
);
}
-function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, actions }) {
+function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, useWork, actions }) {
const roster = useRoster((value) => value);
const title = useSessions((list) => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? "");
const firstTurns = useSessions((list) => {
@@ -6036,7 +6039,7 @@ function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSe
),
(0, import_react10.createElement)("span", { className: "bt-sr", role: "status" }, memoryNotice ? t("Memory updated") : ""),
(0, import_react10.createElement)(NewMessagePills, { key: sessionId, sessionId, useSessions, useUi, useTurnClock }),
- (0, import_react10.createElement)(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, actions }),
+ (0, import_react10.createElement)(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, useWork, actions }),
// DSH's way into its right sidebar sits in the session header this pill replaces.
actions.hasRightSidebar?.() ? (0, import_react10.createElement)("button", { type: "button", className: "bt-icon-btn bt-head-side", "data-bt-right-sidebar": "", "aria-label": t("Show or hide the right sidebar"), title: t("Right sidebar"), onClick: () => actions.toggleRightSidebar() }, (0, import_react10.createElement)(SidePanelIcon)) : null
);
@@ -11660,17 +11663,12 @@ function MemberDock({ sessionId, useRoster, useWork, actions }) {
)
);
}
-function useNow2(active) {
- const [now, setNow] = (0, import_react32.useState)(Date.now);
- (0, import_react32.useEffect)(() => {
- if (!active) return void 0;
- setNow(Date.now());
- const timer = setInterval(() => setNow(Date.now()), 1e3);
- return () => clearInterval(timer);
- }, [active]);
- return now;
-}
-var since = (now, at) => typeof at === "number" && now - at >= 1e3 ? ` · ${elapsedLabel(now - at)}` : "";
+var stateLine = (className, at, ...what) => (0, import_react32.createElement)(
+ "span",
+ { className },
+ (0, import_react32.createElement)("span", { className: "bt-member-what" }, ...what),
+ typeof at === "number" ? (0, import_react32.createElement)(Elapsed, { at, className: "bt-member-time" }) : null
+);
function ApprovalCard({ approval, bot, actions }) {
const [busy, setBusy] = (0, import_react32.useState)(false);
const answer = (choice) => {
@@ -11696,17 +11694,11 @@ function ApprovalCard({ approval, bot, actions }) {
)
);
}
-function MemberState({ entry, bot, room: room2, roster, now }) {
- if (entry?.state === "ask") return (0, import_react32.createElement)("span", { className: "bt-member-state bt-mw-ask" }, `${t("Waiting for your approval")}${since(now, entry.approvals[0].at)}`);
- if (entry?.state !== "work") return bot.role ? (0, import_react32.createElement)("span", { className: "bt-member-state" }, bot.role) : null;
+function MemberState({ entry, bot, room: room2, roster }) {
+ if (entry?.state === "ask") return stateLine("bt-member-state bt-mw-ask", entry.approvals[0].at, t("Waiting for your approval"));
+ if (entry?.state !== "work") return bot.role ? stateLine("bt-member-state", void 0, bot.role) : null;
const where = entry.doing.roomId === room2.id ? "" : entry.doing.roomId ? t("in {name}", { name: roster.roomsById[entry.doing.roomId]?.name ?? t("a group chat") }) : t("in its own chat");
- return (0, import_react32.createElement)(
- "span",
- { className: "bt-member-state" },
- (0, import_react32.createElement)(Shimmer, null, `${workPhrase(entry.doing)}…`),
- where ? ` ${where}` : "",
- since(now, entry.doing.since)
- );
+ return stateLine("bt-member-state", entry.doing.since, (0, import_react32.createElement)(Shimmer, null, `${workPhrase(entry.doing)}…`), where ? ` ${where}` : "");
}
function StopMemberWork({ entry, bot, room: room2, actions }) {
const [stopping, setStopping] = (0, import_react32.useState)(false);
@@ -11723,9 +11715,7 @@ function MemberApprovals({ entry, bot, actions }) {
}
function useMemberWork(room2, useWork) {
const work = useWork?.((value) => value) ?? NO_WORK;
- const entries2 = room2 ? memberWork(room2, work) : [];
- const now = useNow2(entries2.some((entry) => entry.state !== "idle"));
- return { entries: entries2, now };
+ return { entries: room2 ? memberWork(room2, work) : [] };
}
var MEMBER_CSS = `
.bt-mw-dock{display:flex;justify-content:center;margin:0 auto 8px;pointer-events:none}
@@ -11758,7 +11748,9 @@ body[data-ds-dark-theme] .bt-mw-ask{color:#f0b84a}
.bt-member-line{display:flex;align-items:center;gap:6px;min-width:0}
.bt-member-name{min-width:0;font-size:14px;line-height:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.bt-member-line>.bt-tag{font-size:11px;line-height:15px;padding:0 5px}
-.bt-member-state{min-width:0;font-size:12px;line-height:16px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.bt-member-state{display:flex;min-width:0;font-size:12px;line-height:16px;color:var(--bt-ink-3);white-space:nowrap}
+.bt-member-what{min-width:0;overflow:hidden;text-overflow:ellipsis}
+.bt-member-time{flex:none;margin-left:.3em;font-variant-numeric:tabular-nums}
.bt-member-state.bt-mw-ask{color:#b7791f}
body[data-ds-dark-theme] .bt-member-state.bt-mw-ask{color:#f0b84a}
.bt-member-stop{flex:none;height:26px;padding:0 11px;border:0;border-radius:13px;background:var(--bt-main);box-shadow:inset 0 0 0 .5px var(--bt-line-2);color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer;transition:background-color .12s ease,color .12s ease,${spring(SPRING_TAP, "scale")}}
@@ -11926,7 +11918,7 @@ function MemberPile({ room: room2, roster }) {
);
}
var markOf = (entry) => entry?.state === "ask" ? "alert" : entry?.state === "work" ? workState(entry.doing) : "idle";
-function MemberRow({ member, entry, room: room2, roster, actions, now }) {
+function MemberRow({ member, entry, room: room2, roster, actions }) {
return (0, import_react33.createElement)(
"div",
{ role: "listitem", className: "bt-member" },
@@ -11946,7 +11938,7 @@ function MemberRow({ member, entry, room: room2, roster, actions, now }) {
(0, import_react33.createElement)("span", { className: "bt-member-name" }, member.name),
room2.admin === member.id ? (0, import_react33.createElement)("span", { className: "bt-tag" }, t("Admin")) : null
),
- (0, import_react33.createElement)(MemberState, { entry, bot: member, room: room2, roster, now })
+ (0, import_react33.createElement)(MemberState, { entry, bot: member, room: room2, roster })
)
),
(0, import_react33.createElement)(StopMemberWork, { entry, bot: member, room: room2, actions })
@@ -11956,7 +11948,7 @@ function MemberRow({ member, entry, room: room2, roster, actions, now }) {
}
function GroupOverview({ room: room2, roster, actions, usage, useWork, openSettings }) {
const members = room2.members.map((id) => roster.byId[id]).filter(Boolean);
- const { entries: entries2, now } = useMemberWork(room2, useWork);
+ const { entries: entries2 } = useMemberWork(room2, useWork);
return [
room2.notice ? (0, import_react33.createElement)(About, { key: "notice", title: "Notice", text: room2.notice }) : (0, import_react33.createElement)("button", { key: "notice", type: "button", className: "bt-more", onClick: openSettings }, t("Add a notice in group settings")),
(0, import_react33.createElement)(
@@ -11969,8 +11961,7 @@ function GroupOverview({ room: room2, roster, actions, usage, useWork, openSetti
entry: entries2.find((item) => item.id === member.id),
room: room2,
roster,
- actions,
- now
+ actions
})))
),
(0, import_react33.createElement)(
@@ -13821,7 +13812,7 @@ var USER_MESSAGE_CSS = `
`;
// src/client/approval-notices.js
-function noticeApprovals({ work, roster, shownSession, openSession, since: since2 = Date.now() }) {
+function noticeApprovals({ work, roster, shownSession, openSession, since = Date.now() }) {
const told = /* @__PURE__ */ new Set();
const notify = () => {
const approvals = work.getSnapshot().approvals ?? [];
@@ -13832,7 +13823,7 @@ function noticeApprovals({ work, roster, shownSession, openSession, since: since
for (const entry of approvals) {
if (told.has(entry.id)) continue;
told.add(entry.id);
- if ((entry.at ?? 0) < since2) continue;
+ if ((entry.at ?? 0) < since) continue;
const place = entry.roomId ?? entry.sessionId;
if (document.visibilityState === "visible" && shownSession() === place) continue;
const { byId, roomsById } = roster.getSnapshot();
diff --git a/ds-bot/src/client/activity-row.js b/ds-bot/src/client/activity-row.js
index 3827ad17..c219ec67 100644
--- a/ds-bot/src/client/activity-row.js
+++ b/ds-bot/src/client/activity-row.js
@@ -1,7 +1,7 @@
import { createElement as h, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import { BotMark, RoomAvatar } from './mark.js'
-import { Shimmer, PHRASES } from './cells.js'
+import { Elapsed, Shimmer, PHRASES } from './cells.js'
import { reducedMotion } from './motion.js'
import { t } from './i18n.js'
@@ -12,14 +12,6 @@ import { t } from './i18n.js'
const PHRASE_HOLD_MS = 800
const drawPhrase = pool => t(pool[Math.min(pool.length - 1, Math.floor(Math.random() * pool.length))])
-export function elapsedLabel(ms) {
- const seconds = Math.max(0, Math.floor(ms / 1000))
- if (seconds < 60) return `${seconds}s`
- const minutes = Math.floor(seconds / 60)
- if (minutes < 60) return seconds % 60 === 0 ? `${minutes}m` : `${minutes}m ${seconds % 60}s`
- const hours = Math.floor(minutes / 60)
- return minutes % 60 === 0 ? `${hours}h` : `${hours}h ${minutes % 60}m`
-}
export { reducedMotion }
function useRunningHost(active) {
@@ -83,9 +75,15 @@ function useRowEntrances(replacing) {
}, [])
}
-export function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, useSession, actions }) {
+export function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, useSession, useWork, actions }) {
const roster = useRoster(value => value)
const running = useSessionStatus(map => map.get(sessionId)?.running === true)
+ const turnAt = useWork?.(work => work.turns?.[sessionId])
+ // Until the host reports the turn's start, the clock counts from when this window
+ // saw the run begin.
+ const runAt = useRef(0)
+ if (!running) runAt.current = 0
+ else if (runAt.current === 0) runAt.current = Date.now()
const liveKey = useLive(state => JSON.stringify(state[sessionId] ?? {}))
// A queued message waits for the next turn, so only a transcript or steering
// send counts as fresh input.
@@ -153,20 +151,11 @@ export function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useL
useEffect(() => { if (!running) actions.clearLive(sessionId) }, [running, sessionId])
// Only rows that take the activity row's place grow out of it.
useRowEntrances(() => leaving.current || Date.now() - endedAt.current < 300)
- const [now, setNow] = useState(Date.now)
- useEffect(() => {
- if (phase !== 'in') return undefined
- setNow(Date.now())
- const timer = setInterval(() => setNow(Date.now()), 1000)
- return () => clearInterval(timer)
- }, [phase])
const host = useRunningHost(running)
if (!host || phase === null || !shown) return null
- const elapsed = now - shown.at >= 1000 ? elapsedLabel(now - shown.at) : null
return createPortal(h('div', { className: 'bt-typing', 'data-exiting': phase === 'out' ? '' : undefined, 'aria-hidden': true },
bot ? h(BotMark, { bot, size: 28, state: markState.current, live: true, pokeable: true }) : h(RoomAvatar, { room, roster, size: 28 }),
h('span', { className: 'bt-typing-text' },
- h('span', { key: `${shown.key}:${shown.at}`, className: 'bt-typing-label' },
- h(Shimmer, null, `${shown.text}…`),
- elapsed ? h('span', { className: 'bt-typing-time' }, `· ${elapsed}`) : null))), host)
+ h('span', { key: `${shown.key}:${shown.at}`, className: 'bt-typing-label' }, h(Shimmer, null, `${shown.text}…`)),
+ h(Elapsed, { at: Math.max(turnAt ?? runAt.current, inputAt), className: 'bt-typing-time' }))), host)
}
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 1129c4a5..02d8aa2c 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -2,7 +2,7 @@ import { createElement as h, Fragment, useEffect, useLayoutEffect, useMemo, useR
import { createPortal } from 'react-dom'
import { MarkdownText } from './dsh-primitives.js'
import { inkText } from './inks.js'
-import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, isRelayContext, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts } from './text.js'
+import { linkMentions, mentionTarget, dayLabel, contentText, stripHeader, isHiddenTurn, isRelayContext, relaysBefore, relayPart, commRunOf, toolName, toolArgs, reminderPrompts, elapsedLabel } from './text.js'
import { SmileIcon, ReplyIcon, DotsIcon, CheckIcon, DownloadIcon, CopyIcon, MemoryIcon } from './icons.js'
import { colorOf, toolState, BotMark, RoomAvatar } from './mark.js'
import { AnsweredCell, SettledQuestion, PendingQuestion } from './questions.js'
@@ -556,6 +556,23 @@ export function Shimmer({ children }) {
return h('span', { className: 'bt-shimmer' }, children)
}
+// The time since `at`, from 1s. It ticks on its own whole seconds, so its parent does
+// not render again each second.
+export function Elapsed({ at, className }) {
+ const [now, setNow] = useState(Date.now)
+ useEffect(() => {
+ let timer = 0
+ const tick = () => {
+ const time = Date.now()
+ setNow(time)
+ timer = setTimeout(tick, 1000 - (((time - at) % 1000) + 1000) % 1000)
+ }
+ tick()
+ return () => clearTimeout(timer)
+ }, [at])
+ return h('span', { className }, `· ${elapsedLabel(Math.max(1000, now - at))}`)
+}
+
// Status phrases. A running tool names what it does; otherwise one
// phrase is drawn from the pool each time the activity changes.
export const PHRASES = {
diff --git a/ds-bot/src/client/details-drawer.js b/ds-bot/src/client/details-drawer.js
index 39472e11..399a2f9e 100644
--- a/ds-bot/src/client/details-drawer.js
+++ b/ds-bot/src/client/details-drawer.js
@@ -133,7 +133,7 @@ const markOf = entry => (entry?.state === 'ask' ? 'alert' : entry?.state === 'wo
// One member: its mark, name and what it is doing on one surface that opens its chat;
// Stop beside it while it works here, and the approvals it waits on below.
-function MemberRow({ member, entry, room, roster, actions, now }) {
+function MemberRow({ member, entry, room, roster, actions }) {
return h('div', { role: 'listitem', className: 'bt-member' },
h('div', { className: 'bt-member-row' },
h('button', { type: 'button', className: 'bt-member-open', title: t("Open {name}'s chat", { name: member.name }), onClick: () => actions.openSession(member.id) },
@@ -142,7 +142,7 @@ function MemberRow({ member, entry, room, roster, actions, now }) {
h('span', { className: 'bt-member-line' },
h('span', { className: 'bt-member-name' }, member.name),
room.admin === member.id ? h('span', { className: 'bt-tag' }, t('Admin')) : null),
- h(MemberState, { entry, bot: member, room, roster, now }))),
+ h(MemberState, { entry, bot: member, room, roster }))),
h(StopMemberWork, { entry, bot: member, room, actions })),
h(MemberApprovals, { entry, bot: member, actions }))
}
@@ -151,7 +151,7 @@ function MemberRow({ member, entry, room, roster, actions, now }) {
// made in its settings.
function GroupOverview({ room, roster, actions, usage, useWork, openSettings }) {
const members = room.members.map(id => roster.byId[id]).filter(Boolean)
- const { entries, now } = useMemberWork(room, useWork)
+ const { entries } = useMemberWork(room, useWork)
return [
room.notice
? h(About, { key: 'notice', title: 'Notice', text: room.notice })
@@ -159,7 +159,7 @@ function GroupOverview({ room, roster, actions, usage, useWork, openSettings })
h('div', { key: 'members' },
h('div', { className: 'bt-section-title' }, t('Members · {count}', { count: members.length })),
h('div', { className: 'bt-members', role: 'list' }, members.map(member => h(MemberRow, {
- key: member.id, member, entry: entries.find(item => item.id === member.id), room, roster, actions, now,
+ key: member.id, member, entry: entries.find(item => item.id === member.id), room, roster, actions,
})))),
h('div', { key: 'mode' }, h('div', { className: 'bt-section-title' }, t('Who answers')),
h('div', { className: 'bt-kv' }, h('span', null, t(ROOM_MODES.find(([id]) => id === shownMode(room, roster))?.[1] ?? 'Everyone')))),
diff --git a/ds-bot/src/client/header.js b/ds-bot/src/client/header.js
index cf8bccb5..4279bd26 100644
--- a/ds-bot/src/client/header.js
+++ b/ds-bot/src/client/header.js
@@ -42,7 +42,7 @@ function MemoryNotice({ shown }) {
h('span', { className: 'bt-pill-mem-in', ref: inner }, h('span', { className: 'bt-pill-mem-ico' }, h(MemoryIcon)), label))
}
-export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, actions }) {
+export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus, useSession, useActivity, useMemoryNews, useTurnClock, useUi, useLive, useWork, actions }) {
const roster = useRoster(value => value)
const title = useSessions(list => list.byId[sessionId]?.displayTitle ?? list.byId[sessionId]?.title ?? '')
const firstTurns = useSessions((list) => {
@@ -102,7 +102,7 @@ export function HeaderPill({ sessionId, useRoster, useSessions, useSessionStatus
h('span', { className: 'bt-pill-go', 'aria-hidden': true }, h(GoArrow))),
h('span', { className: 'bt-sr', role: 'status' }, memoryNotice ? t('Memory updated') : ''),
h(NewMessagePills, { key: sessionId, sessionId, useSessions, useUi, useTurnClock }),
- h(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, actions }),
+ h(ActivityIndicator, { key: `activity:${sessionId}`, sessionId, useRoster, useSessionStatus, useSession, useLive, useWork, actions }),
// DSH's way into its right sidebar sits in the session header this pill replaces.
actions.hasRightSidebar?.()
? h('button', { type: 'button', className: 'bt-icon-btn bt-head-side', 'data-bt-right-sidebar': '', 'aria-label': t('Show or hide the right sidebar'), title: t('Right sidebar'), onClick: () => actions.toggleRightSidebar() }, h(SidePanelIcon))
diff --git a/ds-bot/src/client/member-status.js b/ds-bot/src/client/member-status.js
index a63d6fd1..b7d199c9 100644
--- a/ds-bot/src/client/member-status.js
+++ b/ds-bot/src/client/member-status.js
@@ -1,12 +1,9 @@
-import { createElement as h, useEffect, useLayoutEffect, useRef, useState } from 'react'
+import { createElement as h, useLayoutEffect, useRef, useState } from 'react'
import { BotMark, toolState } from './mark.js'
-import { Shimmer, workPhrase } from './cells.js'
-import { elapsedLabel } from './activity-row.js'
+import { Elapsed, Shimmer, workPhrase } from './cells.js'
import { SPRING_SHAPE, SPRING_TAP, spring, useLinger } from './motion.js'
import { t } from './i18n.js'
-export { elapsedLabel }
-
// -------------------------------------------------------------------------
// What a group's members are doing: above the group's composer, one capsule for the
// members at work or waiting for an approval; above a Bot's own composer, one for the
@@ -126,18 +123,10 @@ export function MemberDock({ sessionId, useRoster, useWork, actions }) {
model.doing ? h('span', { className: 'bt-mw-doing' }, h(Shimmer, null, model.doing)) : null))))
}
-function useNow(active) {
- const [now, setNow] = useState(Date.now)
- useEffect(() => {
- if (!active) return undefined
- setNow(Date.now())
- const timer = setInterval(() => setNow(Date.now()), 1000)
- return () => clearInterval(timer)
- }, [active])
- return now
-}
-
-const since = (now, at) => (typeof at === 'number' && now - at >= 1000 ? ` · ${elapsedLabel(now - at)}` : '')
+// The clock stays whole at the end; only what comes before it is cut.
+const stateLine = (className, at, ...what) => h('span', { className },
+ h('span', { className: 'bt-member-what' }, ...what),
+ typeof at === 'number' ? h(Elapsed, { at, className: 'bt-member-time' }) : null)
function ApprovalCard({ approval, bot, actions }) {
const [busy, setBusy] = useState(false)
@@ -161,14 +150,13 @@ function ApprovalCard({ approval, bot, actions }) {
}
// A member's second line in the group's details: what it is doing and where, or its role.
-export function MemberState({ entry, bot, room, roster, now }) {
- if (entry?.state === 'ask') return h('span', { className: 'bt-member-state bt-mw-ask' }, `${t('Waiting for your approval')}${since(now, entry.approvals[0].at)}`)
- if (entry?.state !== 'work') return bot.role ? h('span', { className: 'bt-member-state' }, bot.role) : null
+export function MemberState({ entry, bot, room, roster }) {
+ if (entry?.state === 'ask') return stateLine('bt-member-state bt-mw-ask', entry.approvals[0].at, t('Waiting for your approval'))
+ if (entry?.state !== 'work') return bot.role ? stateLine('bt-member-state', undefined, bot.role) : null
const where = entry.doing.roomId === room.id ? ''
: entry.doing.roomId ? t('in {name}', { name: roster.roomsById[entry.doing.roomId]?.name ?? t('a group chat') })
: t('in its own chat')
- return h('span', { className: 'bt-member-state' },
- h(Shimmer, null, `${workPhrase(entry.doing)}…`), where ? ` ${where}` : '', since(now, entry.doing.since))
+ return stateLine('bt-member-state', entry.doing.since, h(Shimmer, null, `${workPhrase(entry.doing)}…`), where ? ` ${where}` : '')
}
// Work in this group can be stopped from its details, since the user cannot reach the
@@ -192,9 +180,7 @@ export function MemberApprovals({ entry, bot, actions }) {
export function useMemberWork(room, useWork) {
const work = useWork?.(value => value) ?? NO_WORK
- const entries = room ? memberWork(room, work) : []
- const now = useNow(entries.some(entry => entry.state !== 'idle'))
- return { entries, now }
+ return { entries: room ? memberWork(room, work) : [] }
}
export const MEMBER_CSS = `
@@ -228,7 +214,9 @@ body[data-ds-dark-theme] .bt-mw-ask{color:#f0b84a}
.bt-member-line{display:flex;align-items:center;gap:6px;min-width:0}
.bt-member-name{min-width:0;font-size:14px;line-height:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.bt-member-line>.bt-tag{font-size:11px;line-height:15px;padding:0 5px}
-.bt-member-state{min-width:0;font-size:12px;line-height:16px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.bt-member-state{display:flex;min-width:0;font-size:12px;line-height:16px;color:var(--bt-ink-3);white-space:nowrap}
+.bt-member-what{min-width:0;overflow:hidden;text-overflow:ellipsis}
+.bt-member-time{flex:none;margin-left:.3em;font-variant-numeric:tabular-nums}
.bt-member-state.bt-mw-ask{color:#b7791f}
body[data-ds-dark-theme] .bt-member-state.bt-mw-ask{color:#f0b84a}
.bt-member-stop{flex:none;height:26px;padding:0 11px;border:0;border-radius:13px;background:var(--bt-main);box-shadow:inset 0 0 0 .5px var(--bt-line-2);color:var(--bt-ink-2);font:inherit;font-size:12px;cursor:pointer;transition:background-color .12s ease,color .12s ease,${spring(SPRING_TAP, 'scale')}}
diff --git a/ds-bot/src/client/styles.js b/ds-bot/src/client/styles.js
index f1207e26..e0ab6b95 100644
--- a/ds-bot/src/client/styles.js
+++ b/ds-bot/src/client/styles.js
@@ -875,7 +875,7 @@ header[class*="_header"] .bt-head{flex:1 1 auto;width:100%}
.bt-typing-text{display:flex;align-items:center;flex:1 1 auto;min-width:0;animation:bt-typing-label .22s ease-out .2s backwards}
.bt-typing-label{display:inline-flex;align-items:center;gap:6px;min-width:0;animation:bt-typing-label .22s ease-out backwards}
.bt-typing-label>.bt-shimmer{font-size:14px;line-height:22px;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
-.bt-typing-time{flex-shrink:0;font-size:12px;line-height:22px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}
+.bt-typing-time{flex-shrink:0;margin-left:6px;font-size:12px;line-height:22px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}
@keyframes bt-typing-in{from{opacity:0;transform:scale(.9)}}
@keyframes bt-typing-out{from{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.92);filter:blur(3px)}}
@keyframes bt-typing-label{from{opacity:0;filter:blur(5px);transform:translateY(3px)}}
diff --git a/ds-bot/src/client/text.js b/ds-bot/src/client/text.js
index c59f621d..b4bc637a 100644
--- a/ds-bot/src/client/text.js
+++ b/ds-bot/src/client/text.js
@@ -45,6 +45,13 @@ export function relativeShort(ms) {
return new Date(ms).toLocaleDateString(dateLocale(), { month: 'short', day: 'numeric' })
}
+// A running clock: "8s", "1m 8s", "1h 2m 8s", in every language.
+export function elapsedLabel(ms) {
+ const total = Math.max(0, Math.floor(ms / 1000))
+ const hours = Math.floor(total / 3600)
+ return `${hours > 0 ? `${hours}h ` : ''}${total >= 60 ? `${Math.floor(total / 60) % 60}m ` : ''}${total % 60}s`
+}
+
export const contentText = content => (content ?? []).filter(block => block?.type === 'text').map(block => block.text).join('\n')
export const HEADER = /^\[(Message from|Reply from|Group chat|Group post from|Bot team setup|Handoff · part|Secret card)[^\]]*\]\n?/
export const currentPart = bot => bot.sessionId ?? bot.id
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index b880f38f..f5199243 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -70,10 +70,11 @@ export function install(rt) {
// What changes without a new revision, sent with every state answer. `memoryNews`:
// per Bot, its latest memory change; `memoryReviews`: memory reviews waiting or
// running; `work`: per Bot, the turn it runs and its tool; per group, the members whose
- // turn there runs; the approvals waiting; and per Bot, who it waits for to hand back work.
+ // turn there runs; the approvals waiting; per Bot, who it waits for to hand back work;
+ // and per Session, when its running turn began.
const live = () => ({
activity: rt.activityView(),
- work: { bots: rt.workView(), rooms: rt.roomWorkView(), approvals: rt.approvalsView(), waiting: rt.waitingView?.() ?? {} },
+ work: { bots: rt.workView(), rooms: rt.roomWorkView(), approvals: rt.approvalsView(), waiting: rt.waitingView?.() ?? {}, turns: rt.turnsView?.() ?? {} },
memoryNews: rt.memoryNews(),
memoryReviews: rt.memoryReviews(),
connectors: rt.connectorsView(),
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index 0576e8e7..141ba8e2 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -298,6 +298,11 @@ export function install(rt) {
return bots
}
+ // Per Session, when its running turn began.
+ const turnsView = () => Object.fromEntries([...live]
+ .filter(([, entry]) => entry.turn !== undefined && entry.since !== undefined)
+ .map(([id, entry]) => [id, entry.since]))
+
// Per group, the members whose turn there is running or who move on to a fresh part;
// the round's current speaker is marked, since its round shows it.
const roomWorkView = () => {
@@ -627,5 +632,5 @@ export function install(rt) {
}
})
- Object.assign(rt, { live, liveOf, roomWaiters, roomProgress, roomInbox, activityView, workView, roomWorkView, callDetail, doingOf, stopRoomTurn, releaseBot })
+ Object.assign(rt, { live, liveOf, roomWaiters, roomProgress, roomInbox, activityView, workView, roomWorkView, turnsView, callDetail, doingOf, stopRoomTurn, releaseBot })
}
diff --git a/ds-bot/test/elapsed.test.js b/ds-bot/test/elapsed.test.js
new file mode 100644
index 00000000..460eee2d
--- /dev/null
+++ b/ds-bot/test/elapsed.test.js
@@ -0,0 +1,14 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { elapsedLabel } from '../src/client/text.js'
+
+test('the work clock counts seconds, then minutes and seconds, then hours, minutes and seconds', () => {
+ assert.equal(elapsedLabel(-5_000), '0s')
+ assert.equal(elapsedLabel(1_000), '1s')
+ assert.equal(elapsedLabel(59_999), '59s')
+ assert.equal(elapsedLabel(60_000), '1m 0s')
+ assert.equal(elapsedLabel(68_400), '1m 8s')
+ assert.equal(elapsedLabel(3_599_000), '59m 59s')
+ assert.equal(elapsedLabel(3_600_000), '1h 0m 0s')
+ assert.equal(elapsedLabel(3_723_000), '1h 2m 3s')
+})
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index 6aa3a9bb..ee54fbeb 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -602,6 +602,20 @@ test('the team view says what a member is doing in the call\'s own words', async
assert.deepEqual(['said', 'note'].map(key => later.work.bots.a[key]), ['先把 JDK 下下来。', 'Download JDK 21'])
})
+test('the team view says when each Session\'s running turn began, for the clock at its tail', async (t) => {
+ const host = await start(t)
+ const before = Date.now()
+ host.emit('gb', 'turn/start', { turn: 1 })
+ host.emit('gb', 'tool/call', { callId: 'k1', name: 'pwsh', arguments: '{}' })
+ const { value } = await host.call('state', {})
+ assert.deepEqual(Object.keys(value.work.turns), ['gb'])
+ assert.ok(value.work.turns.gb >= before && value.work.turns.gb <= Date.now())
+ assert.equal(value.work.turns.gb, value.work.bots.b.since)
+ host.emit('gb', 'tool/result', { callId: 'k1' })
+ host.emit('gb', 'turn/end', { turn: 1, reason: { kind: 'completed' } })
+ assert.deepEqual((await host.call('state', {})).value.work.turns, {})
+})
+
// 公开#124: a Bot deleted while it worked stayed "thinking" until DSH restarted, and the
// Bot that had asked it something never heard back.
test('deleting a working Bot clears its activity and tells the Bots waiting for its reply', async (t) => {
diff --git a/ds-bot/test/member-status.test.js b/ds-bot/test/member-status.test.js
index 580d55f8..ca5e6854 100644
--- a/ds-bot/test/member-status.test.js
+++ b/ds-bot/test/member-status.test.js
@@ -22,7 +22,7 @@ runInNewContext(bundle.outputFiles[0].text, {
return platform[name]
},
})
-const { busyMembers, summaryText, MemberDock, MemberState, elapsedLabel } = module.exports
+const { busyMembers, summaryText, MemberDock, MemberState } = module.exports
// Values from the bundle's realm compare by content only.
const plain = value => JSON.parse(JSON.stringify(value))
// The dock's capsule in an element tree.
@@ -93,18 +93,13 @@ test('the capsule says what a member does in its call\'s own words, and that it
assert.equal(label({ tool: 'pwsh', said: '解压 Ghidra,顺便写脚本。', note: 'Expand-Archive' }), 'Anvil · 解压 Ghidra,顺便写脚本…')
})
-test('elapsedLabel counts seconds first, then minutes and seconds, then hours', () => {
- assert.equal(elapsedLabel(0), '0s')
- assert.equal(elapsedLabel(1_000), '1s')
- assert.equal(elapsedLabel(59_999), '59s')
- assert.equal(elapsedLabel(60_000), '1m')
- assert.equal(elapsedLabel(61_000), '1m 1s')
- assert.equal(elapsedLabel(125_000), '2m 5s')
- assert.equal(elapsedLabel(3_599_000), '59m 59s')
- assert.equal(elapsedLabel(3_600_000), '1h')
- assert.equal(elapsedLabel(3_900_000), '1h 5m')
- const stateText = (entry, now) => MemberState({ entry, bot: { id: 'a', name: 'Anvil' }, room: { id: 'r1' }, roster: team, now }).children.map(child => (typeof child === 'string' ? child : child.children.join(''))).join('')
- assert.equal(stateText({ state: 'work', doing: { roomId: 'r1', tool: 'pwsh', since: 1_000 } }, 1_500), 'Running shell commands…')
- assert.equal(stateText({ state: 'work', doing: { roomId: 'r1', tool: 'pwsh', since: 1_000 } }, 9_000), 'Running shell commands… · 8s')
- assert.equal(stateText({ state: 'ask', approvals: [{ at: 1_000 }] }, 75_000), 'Waiting for your approval · 1m 14s')
+test('a member\'s line runs a clock from its turn\'s start or its approval\'s', () => {
+ // The clock renders as `{since}` here; it ticks on its own.
+ const flat = node => (node === null || node === '' ? '' : typeof node === 'string' ? node
+ : node.props.at !== undefined ? `{${node.props.at}}` : node.children.map(flat).join(''))
+ const stateText = entry => flat(MemberState({ entry, bot: { id: 'a', name: 'Anvil' }, room: { id: 'r1' }, roster: team }))
+ assert.equal(stateText({ state: 'work', doing: { roomId: 'r1', tool: 'pwsh', since: 1_000 } }), 'Running shell commands…{1000}')
+ assert.equal(stateText({ state: 'work', doing: { roomId: 'r2', tool: 'pwsh', since: 1_000 } }), 'Running shell commands… in Docs{1000}')
+ assert.equal(stateText({ state: 'ask', approvals: [{ at: 2_000 }] }), 'Waiting for your approval{2000}')
+ assert.equal(flat(MemberState({ entry: { state: 'idle' }, bot: { id: 'a', name: 'Anvil', role: 'Writer' }, room: { id: 'r1' }, roster: team })), 'Writer')
})