A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Make a Bot's scheduled tasks easier to inspect
klarkxy8f232624e50b
diff --git a/ds-bot/client.js b/ds-bot/client.jsindex 24d0962b..b71c2937 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -1047,7 +1047,10 @@ var ZH = {"Every weekend at {time}": "每个周末 {time}","On the schedule {expression}": "按计划 {expression}","Next: {time}": "下次 {time}",+ "Overdue: {time}": "已逾期 {time}",Finished: "已结束",+ "Scheduled tasks · {count}": "定时任务 · {count}",+ "Show all": "显示全部","in {name}": "在 {name}","Click again to delete": "再点一次删除","Delete task": "删除任务",@@ -12296,9 +12299,13 @@ function timingText(task) {return "";}}-var nextText = (task) => task.status === "active" ? t("Next: {time}", { time: dayAndTime(Date.parse(task.scheduledAt)) }) : t("Finished");+var nextText = (task) => {+ if (task.state === "overdue" || task.state === void 0 && task.status === "active" && Date.parse(task.scheduledAt) <= Date.now()) return t("Overdue: {time}", { time: dayAndTime(Date.parse(task.scheduledAt)) });+ return task.status === "active" ? t("Next: {time}", { time: dayAndTime(Date.parse(task.scheduledAt)) }) : t("Finished");+};function TaskRow({ task, actions, onView, showBot, roster }) {const [confirming, setConfirming] = (0, import_react27.useState)(false);+ const [expanded, setExpanded] = (0, import_react27.useState)(false);const [busy, setBusy] = (0, import_react27.useState)(false);(0, import_react27.useEffect)(() => {if (!confirming) return void 0;@@ -12319,13 +12326,13 @@ function TaskRow({ task, actions, onView, showBot, roster }) {{ className: "bt-set-row bt-task", "data-done": task.status === "active" ? void 0 : "", "data-busy": busy || void 0 },showBot ? (0, import_react27.createElement)(BotAvatar, { bot: roster.byId[task.botId], size: 28, badge: false, live: false }) : null,(0, import_react27.createElement)(- "span",- { className: "bt-set-copy" },+ "button",+ { type: "button", className: "bt-set-copy bt-task-copy", "aria-expanded": expanded || void 0, onClick: () => setExpanded((open) => !open) },(0, import_react27.createElement)("span", { className: "bt-task-title" }, task.title),(0, import_react27.createElement)("span", { className: "bt-set-hint" }, [timingText(task), room2 ? t("in {name}", { name: room2.name }) : ""].filter(Boolean).join(" · ")),- task.prompt && task.prompt !== task.title ? (0, import_react27.createElement)("span", { className: "bt-task-prompt" }, task.prompt) : null+ task.prompt && task.prompt !== task.title ? (0, import_react27.createElement)("span", { className: "bt-task-prompt", "data-open": expanded || void 0 }, task.prompt) : null),- (0, import_react27.createElement)("span", { className: "bt-task-next" }, nextText(task)),+ (0, import_react27.createElement)("span", { className: "bt-task-next", "data-state": task.state === "overdue" ? "overdue" : void 0 }, nextText(task)),(0, import_react27.createElement)("button", {type: "button",className: "bt-mini bt-task-remove",@@ -12458,7 +12465,8 @@ function AutomationOff({ actions }) {}function SchedulesPage({ roster, actions, start }) {const view = useSchedules(actions);- const [adding, setAdding] = (0, import_react27.useState)(Boolean(start));+ const owner = start?.startsWith("bot:") ? start.slice(4) : start?.startsWith("room:") ? start.slice(5) : null;+ const [adding, setAdding] = (0, import_react27.useState)(Boolean(start) && owner === null);if (view === null) return (0, import_react27.createElement)("div", { className: "bt-set-hint" }, t("Loading…"));if (!view.available) return (0, import_react27.createElement)(AutomationOff, { actions });const shown = (next) => {@@ -12468,9 +12476,14 @@ function SchedulesPage({ roster, actions, start }) {const byChat = [...roster.bots.map((bot) => [bot.id, (0, import_react27.createElement)(BotAvatar, { bot, size: 18, badge: false, live: false }), bot.name, view.tasks.filter((task) => task.botId === bot.id)]),...roster.rooms.map((room2) => [room2.id, (0, import_react27.createElement)(RoomAvatar, { room: room2, roster, size: 18 }), room2.name, view.tasks.filter((task) => task.botId === void 0 && task.roomId === room2.id)])- ].filter(([, , , tasks]) => tasks.length > 0);+ ].filter(([id, , , tasks]) => tasks.length > 0 && (owner === null || id === owner));return [- adding ? (0, import_react27.createElement)(TaskForm, { key: "form", roster, actions, start, onDone: shown, onCancel: () => setAdding(false) }) : (0, import_react27.createElement)("div", { key: "add", className: "bt-actions" }, (0, import_react27.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm bt-with-icon", onClick: () => setAdding(true) }, (0, import_react27.createElement)(PlusIcon), t("New task"))),+ adding ? (0, import_react27.createElement)(TaskForm, { key: "form", roster, actions, start: owner ?? start, onDone: shown, onCancel: () => setAdding(false) }) : (0, import_react27.createElement)(+ "div",+ { key: "add", className: "bt-actions" },+ (0, import_react27.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm bt-with-icon", onClick: () => setAdding(true) }, (0, import_react27.createElement)(PlusIcon), t("New task")),+ owner !== null ? (0, import_react27.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => actions.openSettings("schedules") }, t("Show all")) : null+ ),byChat.length === 0 && !adding ? (0, import_react27.createElement)("div", { key: "none", className: "bt-set-card" }, (0, import_react27.createElement)("div", { className: "bt-set-row" }, (0, import_react27.createElement)("span", { className: "bt-set-hint" }, t("No scheduled tasks yet.")))) : byChat.map(([id, avatar, name, tasks]) => (0, import_react27.createElement)("section",{ key: id, className: "bt-set-section" },@@ -12508,10 +12521,10 @@ function ScheduleSummary({ bot, actions }) {return (0, import_react27.createElement)("div",null,- (0, import_react27.createElement)("div", { className: "bt-section-title" }, t("Scheduled tasks")),+ (0, import_react27.createElement)("div", { className: "bt-section-title" }, tasks.length === 0 ? t("Scheduled tasks") : t("Scheduled tasks · {count}", { count: tasks.length })),tasks.length === 0 ? (0, import_react27.createElement)("button", { type: "button", className: "bt-more", onClick: () => actions.openSettings("schedules", bot.id) }, view?.available === false ? t("Switch on Automation tasks on the Plugins page in Harness settings.") : t("No scheduled tasks yet. Add one")) : (0, import_react27.createElement)("div", { className: "bt-task-list" }, tasks.slice(0, 3).map((task) => (0, import_react27.createElement)("button",- { key: task.id, type: "button", className: "bt-task-line", onClick: () => actions.openSettings("schedules") },+ { key: task.id, type: "button", className: "bt-task-line", onClick: () => actions.openSettings("schedules", `bot:${bot.id}`) },(0, import_react27.createElement)(ClockIcon),(0, import_react27.createElement)("span", { className: "bt-task-line-title" }, task.title),(0, import_react27.createElement)("span", { className: "bt-task-line-when" }, timingText(task))@@ -12524,7 +12537,10 @@ var SCHEDULE_CSS = `.bt-task[data-busy]{opacity:.4}.bt-task-title{font-size:13px;line-height:18px;font-weight:500;overflow-wrap:anywhere}.bt-task-prompt{font-size:12px;line-height:16px;color:var(--bt-ink-2);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}+.bt-task-prompt[data-open]{display:block;-webkit-line-clamp:unset;overflow:visible;overflow-wrap:anywhere;white-space:pre-wrap}+.bt-task-copy{padding:0;border:0;background:none;font:inherit;text-align:left;cursor:pointer}.bt-task-next{flex:none;font-size:12px;line-height:16px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}+.bt-task-next[data-state=overdue]{color:var(--bt-danger)}.bt-task-remove{display:inline-flex;align-items:center;justify-content:center;min-width:26px;height:26px;color:var(--bt-ink-3)}.bt-task-remove svg{width:14px;height:14px}.bt-task-remove[data-confirm]{background:color-mix(in srgb,var(--bt-danger) 10%,transparent);color:var(--bt-danger)}diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex fa328fd3..25299c6b 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -1000,7 +1000,10 @@ const ZH = {'Every weekend at {time}': '每个周末 {time}','On the schedule {expression}': '按计划 {expression}','Next: {time}': '下次 {time}',+ 'Overdue: {time}': '已逾期 {time}',Finished: '已结束',+ 'Scheduled tasks · {count}': '定时任务 · {count}',+ 'Show all': '显示全部','in {name}': '在 {name}','Click again to delete': '再点一次删除','Delete task': '删除任务',diff --git a/ds-bot/src/client/schedules.js b/ds-bot/src/client/schedules.jsindex 8e79ca3d..ca4d0a06 100644--- a/ds-bot/src/client/schedules.js+++ b/ds-bot/src/client/schedules.js@@ -69,10 +69,14 @@ export function timingText(task) {default: return ''}}-const nextText = task => (task.status === 'active' ? t('Next: {time}', { time: dayAndTime(Date.parse(task.scheduledAt)) }) : t('Finished'))+const nextText = (task) => {+ if (task.state === 'overdue' || (task.state === undefined && task.status === 'active' && Date.parse(task.scheduledAt) <= Date.now())) return t('Overdue: {time}', { time: dayAndTime(Date.parse(task.scheduledAt)) })+ return task.status === 'active' ? t('Next: {time}', { time: dayAndTime(Date.parse(task.scheduledAt)) }) : t('Finished')+}function TaskRow({ task, actions, onView, showBot, roster }) {const [confirming, setConfirming] = useState(false)+ const [expanded, setExpanded] = useState(false)const [busy, setBusy] = useState(false)useEffect(() => {if (!confirming) return undefined@@ -87,11 +91,11 @@ function TaskRow({ task, actions, onView, showBot, roster }) {const room = task.roomId ? roster.roomsById[task.roomId] : undefinedreturn h('div', { className: 'bt-set-row bt-task', 'data-done': task.status === 'active' ? undefined : '', 'data-busy': busy || undefined },showBot ? h(BotAvatar, { bot: roster.byId[task.botId], size: 28, badge: false, live: false }) : null,- h('span', { className: 'bt-set-copy' },+ h('button', { type: 'button', className: 'bt-set-copy bt-task-copy', 'aria-expanded': expanded || undefined, onClick: () => setExpanded(open => !open) },h('span', { className: 'bt-task-title' }, task.title),h('span', { className: 'bt-set-hint' }, [timingText(task), room ? t('in {name}', { name: room.name }) : ''].filter(Boolean).join(' · ')),- task.prompt && task.prompt !== task.title ? h('span', { className: 'bt-task-prompt' }, task.prompt) : null),- h('span', { className: 'bt-task-next' }, nextText(task)),+ task.prompt && task.prompt !== task.title ? h('span', { className: 'bt-task-prompt', 'data-open': expanded || undefined }, task.prompt) : null),+ h('span', { className: 'bt-task-next', 'data-state': task.state === 'overdue' ? 'overdue' : undefined }, nextText(task)),h('button', {type: 'button', className: 'bt-mini bt-task-remove', 'data-confirm': confirming || undefined, disabled: busy,'aria-label': confirming ? t('Click again to delete') : t('Delete task'), title: confirming ? undefined : t('Delete task'), onClick: remove,@@ -177,20 +181,26 @@ function AutomationOff({ actions }) {actions.openHarnessSettings ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: actions.openHarnessSettings }, t('Open Harness settings')) : null)}+// A plain `start` opens the create form for that Bot or group chat; the+// `bot:<id>`/`room:<id>` form asks for just that owner's tasks, which is how a+// Bot's own view gets here.export function SchedulesPage({ roster, actions, start }) {const view = useSchedules(actions)- const [adding, setAdding] = useState(Boolean(start))+ const owner = start?.startsWith('bot:') ? start.slice(4) : start?.startsWith('room:') ? start.slice(5) : null+ const [adding, setAdding] = useState(Boolean(start) && owner === null)if (view === null) return h('div', { className: 'bt-set-hint' }, t('Loading…'))if (!view.available) return h(AutomationOff, { actions })const shown = next => { publish(next); setAdding(false) }const byChat = [...roster.bots.map(bot => [bot.id, h(BotAvatar, { bot, size: 18, badge: false, live: false }), bot.name, view.tasks.filter(task => task.botId === bot.id)]),...roster.rooms.map(room => [room.id, h(RoomAvatar, { room, roster, size: 18 }), room.name, view.tasks.filter(task => task.botId === undefined && task.roomId === room.id)]),- ].filter(([, , , tasks]) => tasks.length > 0)+ ].filter(([id, , , tasks]) => tasks.length > 0 && (owner === null || id === owner))return [adding- ? h(TaskForm, { key: 'form', roster, actions, start, onDone: shown, onCancel: () => setAdding(false) })- : h('div', { key: 'add', className: 'bt-actions' }, h('button', { type: 'button', className: 'bt-soft bt-soft-sm bt-with-icon', onClick: () => setAdding(true) }, h(PlusIcon), t('New task'))),+ ? h(TaskForm, { key: 'form', roster, actions, start: owner ?? start, onDone: shown, onCancel: () => setAdding(false) })+ : h('div', { key: 'add', className: 'bt-actions' },+ h('button', { type: 'button', className: 'bt-soft bt-soft-sm bt-with-icon', onClick: () => setAdding(true) }, h(PlusIcon), t('New task')),+ owner !== null ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => actions.openSettings('schedules') }, t('Show all')) : null),byChat.length === 0 && !adding? h('div', { key: 'none', className: 'bt-set-card' }, h('div', { className: 'bt-set-row' }, h('span', { className: 'bt-set-hint' }, t('No scheduled tasks yet.')))): byChat.map(([id, avatar, name, tasks]) => h('section', { key: id, className: 'bt-set-section' },@@ -222,10 +232,10 @@ export function ScheduleSummary({ bot, actions }) {const view = useSchedules(actions)const tasks = view?.available ? view.tasks.filter(task => task.botId === bot.id && task.status === 'active') : []return h('div', null,- h('div', { className: 'bt-section-title' }, t('Scheduled tasks')),+ h('div', { className: 'bt-section-title' }, tasks.length === 0 ? t('Scheduled tasks') : t('Scheduled tasks · {count}', { count: tasks.length })),tasks.length === 0? h('button', { type: 'button', className: 'bt-more', onClick: () => actions.openSettings('schedules', bot.id) }, view?.available === false ? t('Switch on Automation tasks on the Plugins page in Harness settings.') : t('No scheduled tasks yet. Add one'))- : h('div', { className: 'bt-task-list' }, tasks.slice(0, 3).map(task => h('button', { key: task.id, type: 'button', className: 'bt-task-line', onClick: () => actions.openSettings('schedules') },+ : h('div', { className: 'bt-task-list' }, tasks.slice(0, 3).map(task => h('button', { key: task.id, type: 'button', className: 'bt-task-line', onClick: () => actions.openSettings('schedules', `bot:${bot.id}`) },h(ClockIcon), h('span', { className: 'bt-task-line-title' }, task.title), h('span', { className: 'bt-task-line-when' }, timingText(task))))))}@@ -235,7 +245,10 @@ export const SCHEDULE_CSS = `.bt-task[data-busy]{opacity:.4}.bt-task-title{font-size:13px;line-height:18px;font-weight:500;overflow-wrap:anywhere}.bt-task-prompt{font-size:12px;line-height:16px;color:var(--bt-ink-2);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}+.bt-task-prompt[data-open]{display:block;-webkit-line-clamp:unset;overflow:visible;overflow-wrap:anywhere;white-space:pre-wrap}+.bt-task-copy{padding:0;border:0;background:none;font:inherit;text-align:left;cursor:pointer}.bt-task-next{flex:none;font-size:12px;line-height:16px;color:var(--bt-ink-3);font-variant-numeric:tabular-nums;white-space:nowrap}+.bt-task-next[data-state=overdue]{color:var(--bt-danger)}.bt-task-remove{display:inline-flex;align-items:center;justify-content:center;min-width:26px;height:26px;color:var(--bt-ink-3)}.bt-task-remove svg{width:14px;height:14px}.bt-task-remove[data-confirm]{background:color-mix(in srgb,var(--bt-danger) 10%,transparent);color:var(--bt-danger)}diff --git a/ds-bot/src/host/schedules.js b/ds-bot/src/host/schedules.jsindex 02b5f3c5..d42dd38f 100644--- a/ds-bot/src/host/schedules.js+++ b/ds-bot/src/host/schedules.js@@ -93,11 +93,16 @@ export function install(rt) {async function schedulesView() {if (service === null) return { available: false, tasks: [] }+ const now = Date.now()const tasks = []for (const entry of await service.catalog()) {const owner = ownerOf(entry.sessionId)if (!known(owner)) continue- tasks.push({ ...entry, ...owner })+ // The state DSH derives for its own view: a task past its next firing reads+ // overdue; an inactive one is finished. DSH 0.2.1's catalog() carries the+ // status but not this state, so it is derived the same way here.+ const state = entry.status === 'active' ? (now >= Date.parse(entry.scheduledAt) ? 'overdue' : 'scheduled') : 'finished'+ tasks.push({ ...entry, ...owner, state })}return { available: true, tasks }}diff --git a/ds-bot/test/schedules.test.js b/ds-bot/test/schedules.test.jsindex 3491b669..488297fc 100644--- a/ds-bot/test/schedules.test.js+++ b/ds-bot/test/schedules.test.js@@ -45,7 +45,10 @@ function scheduleService() {return record},async list({ sessionId }) { return [...tasks.values()].filter(task => task.sessionId === sessionId).map(task => task.record) },- async catalog() { return [...tasks.values()].map(task => ({ ...task.record, sessionId: task.sessionId, status: 'active' })) },+ async catalog() {+ return [...tasks.values()].map(task => ({ ...task.record, sessionId: task.sessionId, status: task.status ?? 'active' }))+ .sort((a, b) => a.scheduledAt.localeCompare(b.scheduledAt) || a.id.localeCompare(b.id))+ },async delete({ sessionId, id }) {if (tasks.get(id)?.sessionId !== sessionId) return { id, deleted: false, code: 'schedule_not_found' }tasks.delete(id)@@ -87,9 +90,13 @@ test('tasks are created on the Bot’s current part, listed by Bot, and deleted'await schedule.create('w1', { title: 'Old part', prompt: 'x', every_seconds: 3600 })await schedule.create('outside', { title: 'Not ours', prompt: 'x', every_seconds: 3600 })+ // A task past its firing reads overdue; an inactive one is finished.+ schedule.tasks.set('schedule-late', { sessionId: 'w2', record: { id: 'schedule-late', kind: 'at', title: 'Late', prompt: 'x', scheduledAt: '2020-01-01T00:00:00.000Z' } })+ schedule.tasks.set('schedule-done', { sessionId: 'w2', record: { id: 'schedule-done', kind: 'at', title: 'Done', prompt: 'x', scheduledAt: '2020-01-01T00:00:00.000Z' }, status: 'inactive' })const listed = (await call('schedules', {})).valueassert.equal(listed.available, true)- assert.deepEqual(listed.tasks.map(task => [task.title, task.botId]), [['Briefing', 'w1'], ['Old part', 'w1']])+ assert.deepEqual(listed.tasks.map(task => [task.title, task.botId]), [['Done', 'w1'], ['Late', 'w1'], ['Briefing', 'w1'], ['Old part', 'w1']])+ assert.deepEqual(listed.tasks.map(task => task.state), ['finished', 'overdue', 'scheduled', 'scheduled'])const weekly = await call('schedule-create', { target: 'm1', title: 'Week', prompt: 'Plan', when: { kind: 'weekly', time: '18:30', timeZone: 'UTC', weekdays: [5, 1, 1, 9] } })assert.equal(weekly.ok, true)@@ -109,7 +116,7 @@ test('tasks are created on the Bot’s current part, listed by Bot, and deleted'assert.match((await call('schedule-create', { target: 'm1', title: '', prompt: 'y', when: { kind: 'every', minutes: 5 } })).error.message, /name/)const removed = await call('schedule-delete', { sessionId: 'w2', id: created.record.id })- assert.deepEqual(removed.value.tasks.map(task => task.title), ['Old part', 'Week', 'Ping'])+ assert.deepEqual(removed.value.tasks.map(task => task.title), ['Done', 'Late', 'Old part', 'Week', 'Ping'])assert.match((await call('schedule-delete', { sessionId: 'outside', id: 'schedule-3' })).error.message, /No such task/)})