A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Fix Devin Review findings ahead of 0.2.2
Fei24114dff01e3b1a8
diff --git a/app/src/bot-views.mjs b/app/src/bot-views.mjsindex 1ebb1a51..ed49d2c7 100644--- a/app/src/bot-views.mjs+++ b/app/src/bot-views.mjs@@ -262,7 +262,11 @@ export class BotViews {const entry = this.#owned(botId, payload.tabId)const contents = entry.view.webContentsswitch (action) {- case 'navigate': return contents.loadURL(String(payload.url))+ case 'navigate': {+ const url = String(payload.url)+ if (!allowedNavigation(url, this.#origin())) throw new Error('This address is not allowed')+ return contents.loadURL(url)+ }case 'command':if (payload.command === 'back' && contents.canGoBack()) contents.goBack()else if (payload.command === 'forward' && contents.canGoForward()) contents.goForward()@@ -286,6 +290,8 @@ export class BotViews {}this.#views.delete(tabId)this.#dropSaved(botId, tabId)+ // The view leaves the window too: only closing its contents would keep the child view.+ this.#window()?.contentView.removeChildView(entry.view)entry.view.webContents.close()entry.sessions.clear()entry.sessionMaps.clear()diff --git a/app/test/bot-views.test.mjs b/app/test/bot-views.test.mjsindex b3ad9777..d9eabf28 100644--- a/app/test/bot-views.test.mjs+++ b/app/test/bot-views.test.mjs@@ -49,7 +49,7 @@ function fixture({ statePath } = {}) {storageFor(key) { return { partition: `persist:${key}` } },setDownloadHandler(key, handler) { handlers.set(key, handler) },}- const window = { contentView: { addChildView() {} } }+ const window = { contentView: { addChildView() {}, removeChildView() {} } }const manager = new BotViews({ window: () => window, WebContentsView, guests, origin: () => 'http://127.0.0.1:43117', statePath, onChange: change => changes.push(change) })return { manager, handlers, views, changes }}diff --git a/ds-bot/src/host/requests.js b/ds-bot/src/host/requests.jsindex ed6c244e..d153e474 100644--- a/ds-bot/src/host/requests.js+++ b/ds-bot/src/host/requests.js@@ -101,6 +101,21 @@ export function install(rt) {}try {const receipt = await work()+ if (request.unsent === true) {+ // The work decided before anything went out: it is not a delivered+ // receipt, so the request is free to be admitted again. The removal has+ // to be saved before that is true: a leftover pending record stays.+ delete receipts()[request.key]+ try {+ await rt.save({ required: true })+ } catch (error) {+ fresh.outcome = 'uncertain'+ fresh.at = Date.now()+ receipts()[request.key] = fresh+ rt.warn('ds-bot: the removal of the request receipt was not saved: %s', error)+ }+ return receipt+ }fresh.outcome = 'delivered'fresh.receipt = receiptfresh.at = Date.now()diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex f3981fe5..7a7942f8 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -226,7 +226,9 @@ export function install(rt) {const joinable = earlier !== undefined && (toUser || rt.sameWork(earlier.message.source.exchangeId, work))const before = joinable ? bodyOf(earlier.message) : undefinedlet long = await rt.attachLong(before ? `${before.text}\n\n${text}` : text, `Message from ${sender.name}.txt`)- if (long === undefined) return tooLong(text)+ // Nothing went out, so a named request must not take this as a delivered+ // receipt: admitRequest drops the pending record instead, and a retry can send.+ if (long === undefined) { if (request !== undefined) request.unsent = true; return tooLong(text) }const joins = before !== undefined && agent.inbox?.remove?.(earlier.message.id) === trueif (before !== undefined && !joins) long = await rt.attachLong(text, `Message from ${sender.name}.txt`) ?? longconst working = rt.live.get(chat)?.turn !== undefineddiff --git a/ds-bot/src/host/update.js b/ds-bot/src/host/update.jsindex 0b7c619f..a4c7f534 100644--- a/ds-bot/src/host/update.js+++ b/ds-bot/src/host/update.js@@ -256,18 +256,33 @@ export function install(rt) {// With HMR the plugin manager refuses to install a package the profile already// depends on: remove the bundle (which unloads this host) and install it again.if (typeof service.removeBundle !== 'function') return { error: { code: 'not-removable' } }+ // Asked before removal drops this host: the spec that puts the old version+ // back. A registry spec is a range that can resolve to the failed release+ // again, so pin the version that is actually running.+ const oldSpec = await Promise.resolve(installSpecOf(ctx)).catch(() => undefined)+ const previous = typeof oldSpec === 'string' && sourceOf(oldSpec).kind === 'registry' ? `${PKG.name}@${PKG.version}` : oldSpecmark()const removed = await Promise.resolve(service.removeBundle(PKG.name)).catch((error) => { unmark(); throw error })if (removed?.error) {unmark()return { error: removed.error }}+ // The bundle is gone now; a failed install leaves no DS Bot unless the old one goes back.+ const restore = async (failed) => {+ if (typeof previous !== 'string' || previous === '') return failed+ const back = await Promise.resolve(service.installBundle(previous, sourceOf(previous).kind === 'registry' && chosen.registry ? { registry: chosen.registry } : {})).catch(error => ({ error: { code: error?.message ?? 'restore failed' } }))+ if (back?.error) {+ note('ds-bot: could not reinstall %s after the failed update: %s', previous, back.error.diagnostic ?? back.error.code)+ return failed+ }+ return `${failed}; ${previous} was reinstalled`+ }try {const again = await service.installBundle(chosen.spec, options)- if (again?.error) mark(again.error.diagnostic ?? again.error.code ?? 'install failed')+ if (again?.error) mark(await restore(again.error.diagnostic ?? again.error.code ?? 'install failed'))return again} catch (error) {- mark(error?.message ?? error)+ mark(await restore(error?.message ?? String(error)))throw error}})diff --git a/ds-bot/test/update.test.js b/ds-bot/test/update.test.jsindex 89b6f06d..cb096822 100644--- a/ds-bot/test/update.test.js+++ b/ds-bot/test/update.test.js@@ -6,7 +6,7 @@ import { afterEach, test } from 'node:test'import { cleanVersion, install, newer, sourceOf } from '../src/host/update.js'const PKG = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))-const flush = async () => { for (let index = 0; index < 8; index += 1) await Promise.resolve() }+const flush = async () => { for (let index = 0; index < 14; index += 1) await Promise.resolve() }const realFetch = globalThis.fetchafterEach(() => { globalThis.fetch = realFetch })