Skip to content

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

Keep the first run's copy and the update notices clear of the start window

AdamPlatin1236dd0ff9e99a2
diff --git a/app/README.md b/app/README.md
index be97b525..34f9d30a 100644
--- a/app/README.md
+++ b/app/README.md
@@ -81,9 +81,9 @@ Linux gets one AppImage for every distribution — it runs on any glibc system,
## Updates
-The installed app on Windows updates itself with electron-updater (`src/updates.mjs`), and so does an AppImage on Linux (`APPIMAGE` is set then). At its start and every 4 hours it reads `latest.yml` (Windows) or `latest-linux.yml` (AppImage) of the newest GitHub release, which names the installer and its sha512. It downloads that installer in the background and checks its sha512. When the download is done, a dialog on the window asks whether to restart now: then the app stops its Host and runs the installer, which opens the app again. Otherwise the installer runs when the app quits.
+The installed app on Windows updates itself with electron-updater (`src/updates.mjs`), and so does an AppImage on Linux (`APPIMAGE` is set then). At its start and every 4 hours it reads `latest.yml` (Windows) or `latest-linux.yml` (AppImage) of the newest GitHub release, which names the installer and its sha512. It downloads that installer in the background and checks its sha512. When the download is done, a dialog on the team window asks whether to restart now (a download that is done during the start waits for the team window): then the app stops its Host and runs the installer, which opens the app again. Otherwise the installer runs when the app quits.
-The checks start before the Host (after a first start's import), so that a version whose Host does not start can still update. When the start fails, the app waits up to 15 seconds for the newest check. When it found a newer version, the error box says so; after the box the app waits for the download, then installs it and opens again.
+The checks start before the Host (after a first start's import), so that a version whose Host does not start can still update. When the start fails, the start window shows its failure page, and the app waits up to 15 seconds for the newest check. When it found a newer version, a box on the failure page says so; after the box the app waits for the download, then installs it and opens again, unless the user has tried again meanwhile. On macOS and for a deb, the release page opens after the box instead.
On macOS, the app checks GitHub's releases at start and every 4 hours. It asks once per version, after that release's zip for this Mac is attached. A Linux deb works the same way, except that it waits for the `linux-amd64` deb (Debian's name for x64). Stable installs ignore prereleases; prerelease installs can see them. Download opens the release page; Later closes the dialog. The app does not install the update itself. `DS_BOT_UPDATE_URL` on macOS and for a deb points to a JSON list like the `releases` API response. A release needs `tag_name`, an HTTPS `html_url`, and the machine's package in `assets`.
diff --git a/app/src/main.mjs b/app/src/main.mjs
index 507f3aad..a63505f8 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -21,7 +21,7 @@ import { CAPTION_HEIGHT, cssColor, micaAvailable, nativeThemeSource } from './wi
const IPC = {
caption: 'ds-bot:caption-colors', nativeTheme: 'ds-bot:native-theme', fullscreen: 'ds-bot:fullscreen',
dataLocation: 'ds-bot:data-location', moveData: 'ds-bot:move-data', teamWorkspace: 'ds-bot:team-workspace',
- ready: 'ds-bot:ready', focus: 'ds-bot:focus',
+ ready: 'ds-bot:ready', motion: 'ds-bot:motion',
browserAcquire: 'ds-bot:browser-acquire', browserRelease: 'ds-bot:browser-release', browserForget: 'ds-bot:browser-forget',
browserViewChanged: 'ds-bot:browser-view-changed', browserViewCreate: 'ds-bot:browser-view-create',
browserViewSync: 'ds-bot:browser-view-sync', browserViewPlace: 'ds-bot:browser-view-place',
@@ -107,7 +107,7 @@ if (canonical !== undefined) {
page: join(here, 'start', 'start.html'), preload: join(here, 'preload.cjs'), icon: iconFile, mica, devTools: !app.isPackaged,
// On Windows the locale is known only once the app is ready.
lang: () => (app.getLocale().toLowerCase().startsWith('zh') ? 'zh' : 'en'), motion: readStartFrame(frameFile).motion,
- version: app.getVersion(), log: logs, mainWindow: () => mainWindow,
+ version: app.getVersion(), program: [dirname(process.execPath), process.resourcesPath, app.getAppPath()], log: logs, mainWindow: () => mainWindow,
onRetry: () => { retry().catch(fail) },
onReload: () => { mainWindow?.webContents.reload() },
// Closing the start window before the hand-off quits, as closing the team window does.
@@ -205,10 +205,13 @@ function run() {
boot(mine).catch((error) => { if (mine === attempt) void fail(error) })
}
-// The engine starts again after a failure or the 180 s question; the places stay.
+// The engine starts again after a failure or the 180 s question; the places stay. A first run's
+// copy goes on to its end first: an engine started beside it would run on a half-copied team.
async function retry() {
attempt += 1
failed = false
+ await copying?.catch(() => {})
+ if (copyAbort.signal.aborted || stopping) return
const old = host
host = undefined
await old?.stop().catch((error) => { console.error(error) })
@@ -233,7 +236,7 @@ async function boot(mine) {
// Also the check that the data folder can be written.
mkdirSync(profileDir(), { recursive: true })
startWindow.done('data')
- const engine = await startEngine()
+ const engine = await startEngine(mine)
if (engine === undefined || mine !== attempt) return
startWindow.done('engine')
await mainCreated
@@ -251,12 +254,14 @@ const hostOutput = (stream, chunk) => {
}
function newHost() {
+ // A Host of an attempt that a retry has replaced no longer stands for the start.
+ const mine = attempt
return new HostProcess({
entry: join(here, 'host.mjs'),
cwd: profileDir(),
env: { ...process.env, DSH_HOME: places.dataDir, DS_BOT_PORT: String(port), DS_BOT_APP: '1', DS_BOT_USER_DSH_HOME: userDshHome(), ...(places.workspace ? { DS_BOT_WORKSPACE: places.workspace } : {}) },
pnpm: pnpmEntry(),
- onFailure: fail,
+ onFailure: (error) => { if (mine === attempt) void fail(error) },
output: hostOutput,
})
}
@@ -268,16 +273,21 @@ function newCheck(home, list) {
return new HostProcess({ entry: join(here, 'host.mjs'), cwd, env: { ...process.env, DSH_HOME: home, DS_BOT_CHECK: list }, pnpm: pnpmEntry(), onFailure: () => {}, output: hostOutput })
}
-/** @returns {Promise<{ url: string } | undefined>} the Host's launch URL; none when the app quits during the copy */
-async function startEngine() {
+/**
+ * @returns {Promise<{ url: string } | undefined>} the Host's launch URL; none when the app quits
+ * during the copy, or when a retry during the copy starts the engine itself
+ */
+async function startEngine(mine) {
if (pendingImport !== undefined) {
const where = { ...places, import: pendingImport }
pendingImport = undefined
- copying = copyTeam(where, copyAbort.signal)
+ // The copy's time is not the engine's: the start's clock stands still, and the 180 s
+ // question with it.
+ copying = startWindow.asking(copyTeam(where, copyAbort.signal))
const copied = await copying
copying = undefined
if (copied === 'quit') app.exit(0)
- if (copied !== undefined) return undefined
+ if (copied !== undefined || mine !== attempt) return undefined
}
// Not during the import, which a restart would cut short; before the Host, so that an
// update can still come when this version's Host does not start.
@@ -306,7 +316,15 @@ function handleIpc() {
const fixed = Boolean(process.env.DS_BOT_HOME)
// The team view has mounted (ds-bot calls dsBotApp.ready()): the start window hands over.
ipcMain.on(IPC.ready, (event) => { if (fromWindow(event)) startWindow.ready() })
- ipcMain.on(IPC.focus, (event) => { if (fromWindow(event)) focusWindow() })
+ // The start window takes the app's theme and the Bot animation tier at the next start, before
+ // the team view has loaded; Mica and the caption buttons follow the theme at once.
+ ipcMain.on(IPC.nativeTheme, (event, source) => {
+ const value = nativeThemeSource(source)
+ if (!fromWindow(event) || value === undefined) return
+ nativeTheme.themeSource = value
+ writeStartFrame(frameFile, { themeSource: value })
+ })
+ ipcMain.on(IPC.motion, (event, tier) => { if (fromWindow(event)) writeStartFrame(frameFile, { motion: tier }) })
ipcMain.handle(IPC.dataLocation, (event) => {
assertWindow(event)
return { path: places.dataDir, fixed }
@@ -426,14 +444,6 @@ function handleIpc() {
ipcMain.on(IPC.caption, (event, color, symbolColor) => {
if (fromWindow(event) && cssColor(color) && cssColor(symbolColor)) mainWindow.setTitleBarOverlay({ color, symbolColor })
})
- // Mica and the caption buttons follow the app's theme, not only the system's; the start
- // window takes it at the next start, before the team view has loaded.
- ipcMain.on(IPC.nativeTheme, (event, source) => {
- const value = nativeThemeSource(source)
- if (!fromWindow(event) || value === undefined) return
- nativeTheme.themeSource = value
- writeStartFrame(frameFile, { themeSource: value })
- })
}
}
@@ -611,16 +621,19 @@ function startUpdates() {
return undefined
}
+// The update questions wait for the team window: the start window goes at the hand-off, and a
+// question on it would go with it. After a failed start, fail() takes the update over.
+const afterHandoff = async () => { await startWindow.teamShown; return !failed }
+
async function askRestart(version) {
- // After a failed start, fail() installs the update itself.
- if (failed) return false
+ if (failed || !await afterHandoff()) return false
const t = localeText(UPDATE_TEXT)
const { response } = await dialog.showMessageBox(owner(), { type: 'info', title: 'DeepSeek Bot', message: t.ready(version), detail: t.readyDetail, buttons: [t.restart, t.later], defaultId: 0, cancelId: 1, noLink: true })
return response === 0
}
async function askDownload(version) {
- if (failed) return false
+ if (failed || !await afterHandoff()) return false
const t = localeText(UPDATE_TEXT)
const { response } = await dialog.showMessageBox(owner(), { type: 'info', title: 'DeepSeek Bot', message: t.available(version), detail: t.availableDetail, buttons: [t.download, t.later], defaultId: 0, cancelId: 1, noLink: true })
return response === 0
@@ -721,8 +734,9 @@ function openOutside(url) {
}
// The start window shows the failure page and stays. A new version may fix what keeps this one
-// from starting: one that installs itself does so once it is downloaded, unless the user has
-// tried again meanwhile; a release page (macOS, a Linux deb) waits for the page's update row.
+// from starting; until the page has its update row, a box on it says what comes: the release
+// page opens (macOS, a Linux deb), or the version that installs itself does so once it is
+// downloaded, unless the user has tried again meanwhile.
async function fail(error) {
console.error(error)
if (failed || stopping) return
@@ -731,8 +745,10 @@ async function fail(error) {
startWindow.fail(error, startKind())
const found = await Promise.race([updates?.latest() ?? null, sleep(UPDATE_CHECK_WAIT_MS).then(() => null)])
if (!found || mine !== attempt) return
+ const t = localeText(UPDATE_TEXT)
+ await dialog.showMessageBox(owner(), { type: 'info', title: 'DeepSeek Bot', message: found.page ? t.onFailurePage(found.version) : t.onFailure(found.version) })
if (found.page) {
- console.log(`DeepSeek Bot: ${found.version} is out: ${found.page}`)
+ if (!process.env.DS_BOT_HOME) await shell.openExternal(found.page)
return
}
if (await Promise.race([found.downloaded, sleep(UPDATE_DOWNLOAD_WAIT_MS).then(() => false)]) && failed && mine === attempt) await updates.install()
diff --git a/app/src/preload.cjs b/app/src/preload.cjs
index 4413ac4e..28a7e7ec 100644
--- a/app/src/preload.cjs
+++ b/app/src/preload.cjs
@@ -20,7 +20,6 @@ if (startPage !== undefined) {
ready = true
ipcRenderer.send('ds-bot:ready')
},
- focus: () => { ipcRenderer.send('ds-bot:focus') },
// DS Bot's settings show and move the app's data location through this.
dataLocation: () => ipcRenderer.invoke('ds-bot:data-location'),
moveData: (workspace) => ipcRenderer.invoke('ds-bot:move-data', typeof workspace === 'string' ? workspace : undefined),
@@ -31,6 +30,12 @@ if (startPage !== undefined) {
// The app's own updater, for the About row's state and buttons.
updates: updatesBridge(),
})
+ // A preload runs before the document root exists.
+ const loaded = (run) => {
+ if (document.readyState === 'loading') window.addEventListener('DOMContentLoaded', run, { once: true })
+ else run()
+ }
+ loaded(reportLook)
const caption = process.argv.find(value => value.startsWith('--ds-bot-caption='))
if (caption !== undefined) {
ipcRenderer.on('ds-bot:fullscreen', (_event, fullscreen) => {
@@ -39,13 +44,30 @@ if (startPage !== undefined) {
if (fullscreen) root.dataset.fullscreen = 'true'
else delete root.dataset.fullscreen
})
- const start = () => { frameless(caption.slice('--ds-bot-caption='.length), process.argv.includes('--ds-bot-mica')) }
- // A preload runs before the document root exists.
- if (document.readyState === 'loading') window.addEventListener('DOMContentLoaded', start, { once: true })
- else start()
+ loaded(() => { frameless(caption.slice('--ds-bot-caption='.length), process.argv.includes('--ds-bot-mica')) })
}
}
+// The app's theme (DSH's) and the Bot animation tier (ds-bot's), which the start window takes
+// at the next start.
+function reportLook() {
+ const root = document.documentElement
+ const sent = {}
+ const send = (channel, value) => {
+ if (value === null || value === sent[channel]) return
+ sent[channel] = value
+ ipcRenderer.send(channel, value)
+ }
+ const report = () => {
+ send('ds-bot:native-theme', root.getAttribute('data-ds-theme-source'))
+ send('ds-bot:motion', document.body?.getAttribute('data-bt-motion') ?? null)
+ }
+ const observer = new MutationObserver(report)
+ observer.observe(root, { attributeFilter: ['data-ds-theme-source'] })
+ if (document.body !== null) observer.observe(document.body, { attributeFilter: ['data-bt-motion'] })
+ report()
+}
+
// The main process sends the whole state on every change; a page that subscribes late, or again,
// gets the last one first.
function startBridge() {
@@ -144,15 +166,6 @@ function frameless(height, mica) {
// DSH keeps the dialog mask off the caption band, which then stays bright above a dimmed
// page; here the band is part of the page, so the mask covers it too.
root.style.setProperty('--dsh-frame-chrome-top', '0px')
- let theme
- const sendTheme = () => {
- const value = root.getAttribute('data-ds-theme-source')
- if (value === null || value === theme) return
- theme = value
- ipcRenderer.send('ds-bot:native-theme', value)
- }
- new MutationObserver(sendTheme).observe(root, { attributeFilter: ['data-ds-theme-source'] })
- sendTheme()
captionColors(mica)
}