Skip to content

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

Update the installed desktop app from GitHub releases

Fei241148e965e48bb7
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index 0c7dccd6..7a82729b 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -31,3 +31,10 @@ mac:
target: dmg
icon: assets/icon.png
category: public.app-category.productivity
+# Where the installed app looks for updates (app-update.yml in the package). The build writes
+# latest.yml beside the installer; the release workflow attaches both to the GitHub release,
+# so the build itself never publishes (--publish never).
+publish:
+ provider: github
+ owner: Fei2411
+ repo: DeepSeek-Bot
diff --git a/app/package-lock.json b/app/package-lock.json
index 2729f40c..33931836 100644
--- a/app/package-lock.json
+++ b/app/package-lock.json
@@ -42,6 +42,7 @@
"@deepseek-ai/dsh-util-workspace-path": "0.2.0-rc.2",
"@deepseek-ai/dsh-workflow": "0.2.0-rc.2",
"ds-bot": "file:../ds-bot",
+ "electron-updater": "6.8.10",
"pnpm": "11.7.0",
"yaml": "2.9.1"
},
@@ -8734,7 +8735,6 @@
"version": "9.7.0",
"resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.7.0.tgz",
"integrity": "sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw==",
- "dev": true,
"license": "MIT",
"dependencies": {
"debug": "^4.3.4",
@@ -8748,7 +8748,6 @@
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
- "dev": true,
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
@@ -8766,7 +8765,6 @@
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
- "dev": true,
"license": "MIT"
},
"node_modules/builder-util/node_modules/agent-base": {
@@ -9683,6 +9681,34 @@
"mime": "^2.5.2"
}
},
+ "node_modules/electron-updater": {
+ "version": "6.8.10",
+ "resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-6.8.10.tgz",
+ "integrity": "sha512-6ZSwTUoBNtI1f9Pp8y6zCigD8LKV18Rb1+1A7sZzvKvA17o2sqSqKmm0t6uvKeF+HZqA4vsmw4qq0JSS241USQ==",
+ "license": "MIT",
+ "dependencies": {
+ "builder-util-runtime": "9.7.0",
+ "fs-extra": "^10.1.0",
+ "js-yaml": "^4.1.0",
+ "lazy-val": "^1.0.5",
+ "lodash.escaperegexp": "^4.1.2",
+ "lodash.isequal": "^4.5.0",
+ "semver": "~7.7.3",
+ "tiny-typed-emitter": "^2.1.0"
+ }
+ },
+ "node_modules/electron-updater/node_modules/semver": {
+ "version": "7.7.4",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
+ "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
+ "license": "ISC",
+ "bin": {
+ "semver": "bin/semver.js"
+ },
+ "engines": {
+ "node": ">=10"
+ }
+ },
"node_modules/electron-winstaller": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/electron-winstaller/-/electron-winstaller-5.4.0.tgz",
@@ -10170,7 +10196,6 @@
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
"integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
- "dev": true,
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.2.0",
@@ -10510,7 +10535,6 @@
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
- "dev": true,
"license": "ISC"
},
"node_modules/has-flag": {
@@ -11093,7 +11117,6 @@
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
"integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
- "dev": true,
"license": "MIT",
"dependencies": {
"universalify": "^2.0.0"
@@ -11163,7 +11186,6 @@
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz",
"integrity": "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==",
- "dev": true,
"license": "MIT"
},
"node_modules/lightningcss": {
@@ -11446,6 +11468,19 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/lodash.escaperegexp": {
+ "version": "4.1.2",
+ "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
+ "integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==",
+ "license": "MIT"
+ },
+ "node_modules/lodash.isequal": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
+ "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
+ "deprecated": "This package is deprecated. Use require('node:util').isDeepStrictEqual instead.",
+ "license": "MIT"
+ },
"node_modules/long": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz",
@@ -13965,7 +14000,6 @@
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz",
"integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==",
- "dev": true,
"license": "BlueOak-1.0.0",
"engines": {
"node": ">=11.0.0"
@@ -14520,6 +14554,12 @@
"integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==",
"license": "MIT"
},
+ "node_modules/tiny-typed-emitter": {
+ "version": "2.1.0",
+ "resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz",
+ "integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==",
+ "license": "MIT"
+ },
"node_modules/tinyglobby": {
"version": "0.2.17",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
@@ -14776,7 +14816,6 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
"integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">= 10.0.0"
diff --git a/app/package.json b/app/package.json
index c808b748..a763e5a9 100644
--- a/app/package.json
+++ b/app/package.json
@@ -11,8 +11,8 @@
"scripts": {
"build": "vite build",
"start": "electron .",
- "pack": "electron-builder --dir",
- "dist": "electron-builder",
+ "pack": "electron-builder --dir --publish never",
+ "dist": "electron-builder --publish never",
"check-packed": "node scripts/check-packed.mjs",
"shot": "node scripts/shot.mjs",
"icon": "node scripts/icon.mjs",
@@ -52,6 +52,7 @@
"@deepseek-ai/dsh-util-workspace-path": "0.2.0-rc.2",
"@deepseek-ai/dsh-workflow": "0.2.0-rc.2",
"ds-bot": "file:../ds-bot",
+ "electron-updater": "6.8.10",
"pnpm": "11.7.0",
"yaml": "2.9.1"
},
diff --git a/app/src/first-run.mjs b/app/src/first-run.mjs
index 3919faf6..388f6f40 100644
--- a/app/src/first-run.mjs
+++ b/app/src/first-run.mjs
@@ -44,7 +44,8 @@ const TEXT = {
failed: message => `团队没有复制成功:${message}\n\nDeepSeek Bot 会用一个新团队开始。DeepSeek Harness 里的团队没有变化。`,
},
}
-export const text = () => (app.getLocale().toLowerCase().startsWith('zh') ? TEXT.zh : TEXT.en)
+export const localeText = table => (app.getLocale().toLowerCase().startsWith('zh') ? table.zh : table.en)
+export const text = () => localeText(TEXT)
const PROFILE_NAMES = { desktop: 'DSH Desktop', web: 'DSH Web' }
const ask = options => dialog.showMessageBoxSync({ title: 'DeepSeek Bot', noLink: true, ...options })
diff --git a/app/src/main.mjs b/app/src/main.mjs
index 36670fb4..5dedd8d8 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -7,9 +7,11 @@ import { createRequire } from 'node:module'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { getDshRuntimeVersion } from '@deepseek-ai/dsh-app-boot'
-import { chooseLocations, text } from './first-run.mjs'
+import electronUpdater from 'electron-updater'
+import { chooseLocations, localeText, text } from './first-run.mjs'
import { HostProcess } from './host-process.mjs'
import { importTeam } from './import.mjs'
+import { UPDATE_TEXT, watchUpdates } from './updates.mjs'
import { APP_ORIGIN, authenticateWebHost, forwardWebRequest, serveWebDocument } from './web.mjs'
// DSH writes dsh-app://app/ into workspace file URLs and Markdown file links, so the window keeps that scheme.
@@ -31,6 +33,7 @@ protocol.registerSchemesAsPrivileged([{
let mainWindow
let host
let hostState
+let hostStop
let stopping = false
let stopped = false
let failed = false
@@ -44,12 +47,17 @@ if (!app.requestSingleInstanceLock()) {
if (stopped || host === undefined) return
event.preventDefault()
if (stopping) return
- stopping = true
- host.stop().catch((error) => { console.error(error) }).finally(() => { stopped = true; app.quit() })
+ void stopHost().then(() => { app.quit() })
})
app.whenReady().then(start).catch(fail)
}
+function stopHost() {
+ stopping = true
+ hostStop ??= (host?.stop() ?? Promise.resolve()).catch((error) => { console.error(error) }).finally(() => { stopped = true })
+ return hostStop
+}
+
function start() {
const where = chooseLocations()
if (where.quit) { app.exit(0); return }
@@ -70,6 +78,7 @@ function start() {
return hostState
})()
ready.catch(fail)
+ ready.then(startUpdates, () => {})
protocol.handle(SCHEME, (request) => {
const url = new URL(request.url)
@@ -124,6 +133,22 @@ async function copyTeam(where, newHost) {
}
}
+// The installed app on Windows updates itself. A run on throwaway folders (DS_BOT_HOME) checks
+// only the feed it is given (DS_BOT_UPDATE_URL) and never asks, so the update waits for the quit.
+function startUpdates() {
+ const feed = process.env.DS_BOT_UPDATE_URL || undefined
+ const throwaway = Boolean(process.env.DS_BOT_HOME)
+ if (!app.isPackaged || process.platform !== 'win32' || (throwaway && feed === undefined)) return
+ watchUpdates({ updater: electronUpdater.autoUpdater, feed, ask: throwaway ? undefined : askRestart, beforeInstall: stopHost })
+}
+
+async function askRestart(version) {
+ const t = localeText(UPDATE_TEXT)
+ const options = { type: 'info', title: 'DeepSeek Bot', message: t.ready(version), detail: t.readyDetail, buttons: [t.restart, t.later], defaultId: 0, cancelId: 1, noLink: true }
+ const { response } = await (mainWindow ? dialog.showMessageBox(mainWindow, options) : dialog.showMessageBox(options))
+ return response === 0
+}
+
function createWindow() {
mainWindow = new BrowserWindow({
width: 1320, height: 860, minWidth: 720, minHeight: 480,
diff --git a/app/src/updates.mjs b/app/src/updates.mjs
new file mode 100644
index 00000000..f9b1d53f
--- /dev/null
+++ b/app/src/updates.mjs
@@ -0,0 +1,54 @@
+// Updates of the installed app on Windows. electron-updater reads latest.yml of the newest
+// GitHub release, downloads the installer in the background and checks its sha512. When the
+// download is done, the window asks whether to restart now; otherwise the installer runs at
+// the next quit.
+
+export const UPDATE_TEXT = {
+ en: {
+ ready: version => `DeepSeek Bot ${version} is ready to install.`,
+ readyDetail: 'Restart now to update, or it is installed the next time you quit.',
+ restart: 'Restart now', later: 'Later',
+ },
+ zh: {
+ ready: version => `DeepSeek Bot ${version} 已经下载好。`,
+ readyDetail: '现在重启就能更新;不重启的话,下次退出时安装。',
+ restart: '立即重启', later: '稍后',
+ },
+}
+
+const CHECK_EVERY_MS = 4 * 60 * 60_000
+
+/**
+ * @param {{
+ * updater: import('electron-updater').AppUpdater,
+ * beforeInstall: () => Promise<void>,
+ * ask?: (version: string) => Promise<boolean>,
+ * feed?: string,
+ * log?: Pick<Console, 'info' | 'error'>,
+ * }} options `ask` answers whether to restart now; without it the update waits for the next
+ * quit. `beforeInstall` stops the Host, which runs from the files the installer replaces.
+ * `feed` is a folder URL with a latest.yml, in place of the GitHub releases.
+ * @returns {() => void} stops the checks
+ */
+export function watchUpdates({ updater, beforeInstall, ask, feed, log = console }) {
+ updater.autoDownload = true
+ updater.autoInstallOnAppQuit = true
+ if (feed) updater.setFeedURL({ provider: 'generic', url: feed })
+ let asked
+ updater.on('update-downloaded', ({ version }) => {
+ log.info(`DeepSeek Bot: update ${version} downloaded`)
+ if (ask === undefined || asked === version) return
+ asked = version
+ void ask(version).then(async (now) => {
+ if (!now) return
+ await beforeInstall()
+ updater.quitAndInstall(true, true)
+ }).catch((error) => { log.error(`DeepSeek Bot: update ${version} not installed: ${error instanceof Error ? error.message : String(error)}`) })
+ })
+ updater.on('error', (error) => { log.error(`DeepSeek Bot: update failed: ${error instanceof Error ? error.message : String(error)}`) })
+ // A failed check or download also comes as an 'error' event.
+ const check = () => { updater.checkForUpdates().then(result => result?.downloadPromise?.catch(() => {}), () => {}) }
+ check()
+ const timer = setInterval(check, CHECK_EVERY_MS)
+ return () => { clearInterval(timer) }
+}
diff --git a/app/test/updates.test.mjs b/app/test/updates.test.mjs
new file mode 100644
index 00000000..fa2b8a72
--- /dev/null
+++ b/app/test/updates.test.mjs
@@ -0,0 +1,107 @@
+import assert from 'node:assert/strict'
+import { EventEmitter } from 'node:events'
+import { describe, test } from 'node:test'
+import { setTimeout as sleep } from 'node:timers/promises'
+import { watchUpdates } from '../src/updates.mjs'
+
+// electron-updater's AppUpdater, as far as the app uses it.
+class FakeUpdater extends EventEmitter {
+ checks = 0
+ feeds = []
+ installs = []
+ failCheck = false
+ checkForUpdates() {
+ this.checks += 1
+ if (!this.failCheck) return Promise.resolve(null)
+ const error = new Error('offline')
+ this.emit('error', error)
+ return Promise.reject(error)
+ }
+ setFeedURL(options) { this.feeds.push(options) }
+ quitAndInstall(...args) { this.installs.push(args) }
+}
+
+const quietLog = () => {
+ const lines = []
+ return { lines, info: (line) => { lines.push(line) }, error: (line) => { lines.push(line) } }
+}
+
+describe('watchUpdates', () => {
+ test('downloads in the background, installs at the quit, and checks at once', (t) => {
+ const updater = new FakeUpdater()
+ t.after(watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() }))
+ assert.equal(updater.autoDownload, true)
+ assert.equal(updater.autoInstallOnAppQuit, true)
+ assert.equal(updater.checks, 1)
+ assert.deepEqual(updater.feeds, [])
+ })
+
+ test('reads a given feed in place of the GitHub releases', (t) => {
+ const updater = new FakeUpdater()
+ t.after(watchUpdates({ updater, beforeInstall: async () => {}, feed: 'http://127.0.0.1:8080/', log: quietLog() }))
+ assert.deepEqual(updater.feeds, [{ provider: 'generic', url: 'http://127.0.0.1:8080/' }])
+ })
+
+ test('asks once per downloaded version, and on restart stops the Host before the installer runs', async (t) => {
+ const updater = new FakeUpdater()
+ const steps = []
+ const asked = []
+ t.after(watchUpdates({
+ updater, log: quietLog(),
+ ask: async (version) => { asked.push(version); return true },
+ beforeInstall: async () => { await sleep(10); steps.push('host stopped') },
+ }))
+ updater.quitAndInstall = (...args) => { steps.push(['install', ...args]) }
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ await sleep(50)
+ assert.deepEqual(asked, ['0.1.9'])
+ assert.deepEqual(steps, ['host stopped', ['install', true, true]])
+ })
+
+ test('leaves the update for the next quit when the user says later, or when it may not ask', async (t) => {
+ for (const ask of [async () => false, undefined]) {
+ const updater = new FakeUpdater()
+ const log = quietLog()
+ let stopped = false
+ t.after(watchUpdates({ updater, ask, log, beforeInstall: async () => { stopped = true } }))
+ updater.emit('update-downloaded', { version: '0.1.9' })
+ await sleep(20)
+ assert.deepEqual(updater.installs, [])
+ assert.equal(stopped, false)
+ assert.deepEqual(log.lines, ['DeepSeek Bot: update 0.1.9 downloaded'])
+ }
+ })
+
+ test('logs a failed check and does not throw', async (t) => {
+ const updater = new FakeUpdater()
+ updater.failCheck = true
+ const log = quietLog()
+ t.after(watchUpdates({ updater, beforeInstall: async () => {}, log }))
+ await sleep(10)
+ assert.deepEqual(log.lines, ['DeepSeek Bot: update failed: offline'])
+ })
+
+ test('a failed download, which electron-updater also reports as an error, is not left unhandled', async (t) => {
+ const unhandled = []
+ const note = (error) => { unhandled.push(error) }
+ process.on('unhandledRejection', note)
+ t.after(() => { process.off('unhandledRejection', note) })
+ const updater = new FakeUpdater()
+ updater.checkForUpdates = () => Promise.resolve({ downloadPromise: Promise.reject(new Error('sha512 checksum mismatch')) })
+ t.after(watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() }))
+ await sleep(20)
+ assert.deepEqual(unhandled, [])
+ })
+
+ test('checks again every few hours until stopped', (t) => {
+ t.mock.timers.enable({ apis: ['setInterval'] })
+ const updater = new FakeUpdater()
+ const stop = watchUpdates({ updater, beforeInstall: async () => {}, log: quietLog() })
+ t.mock.timers.tick(4 * 60 * 60_000)
+ assert.equal(updater.checks, 2)
+ stop()
+ t.mock.timers.tick(8 * 60 * 60_000)
+ assert.equal(updater.checks, 2)
+ })
+})