Skip to content

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

Save the log with the app's own picker

AdamPlatin12397744527345c
diff --git a/app/src/main.mjs b/app/src/main.mjs
index 6a39be37..172a96a3 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -181,7 +181,9 @@ if (canonical !== undefined) {
app.once('will-quit', () => { logs.flush() })
console.log(`DeepSeek Bot ${app.getVersion()} (${process.platform} ${process.arch}), Electron ${process.versions.electron}`)
startWindow = new StartWindow({
- electron: { BrowserWindow, ipcMain, screen, shell: electronShell, clipboard, dialog, nativeTheme, systemPreferences },
+ electron: { BrowserWindow, ipcMain, screen, shell: electronShell, clipboard, nativeTheme, systemPreferences },
+ // 〔保存日志…〕 on the start window's failure cards.
+ saveAs: (win, name) => askPicker(win, { mode: 'save', title: tx('dialog.saveLog'), start: knownFolder('desktop'), name }),
page: join(here, 'start', 'start.html'), preload: join(here, 'preload.cjs'), icon: iconFile, mica, devTools: !app.isPackaged,
css: readFileSync(join(here, 'page-card.css'), 'utf8'),
// On Windows the locale is known only once the app is ready.
diff --git a/app/src/start-window.mjs b/app/src/start-window.mjs
index a097cf1b..8b955750 100644
--- a/app/src/start-window.mjs
+++ b/app/src/start-window.mjs
@@ -290,13 +290,14 @@ export class StartWindow {
/**
* @param {{
- * electron: { BrowserWindow: any, ipcMain: any, screen: any, shell: any, clipboard: any, dialog?: any, nativeTheme: any, systemPreferences: any },
+ * electron: { BrowserWindow: any, ipcMain: any, screen: any, shell: any, clipboard: any, nativeTheme: any, systemPreferences: any },
* page: string, preload: string, icon: string, mica: boolean, devTools: boolean, css?: string,
* lang: () => 'zh' | 'en', motion: string, version: string, program: string[],
* log: { dir: string, tail: (count: number) => string[] },
* mainWindow: () => any,
* onRetry: () => void, onReload: () => void, onClose: () => void,
* onPick?: (value?: string) => void, onAnswer?: (value?: string) => void,
+ * saveAs?: (win: any, name: string) => Promise<string | undefined>,
* onUpdate?: (name: 'installUpdate' | 'manualDownload') => void,
* onImport?: (name: 'importModel' | 'importOption' | 'stopCopy' | 'keepCopying', value: unknown) => void,
* }} options `lang` is asked at each open; `program` names the folders of the app's own files;
@@ -756,14 +757,15 @@ export class StartWindow {
void Promise.resolve(this.#o.electron.clipboard.writeText(text)).catch((error) => { note(`the details were not copied: ${error instanceof Error ? error.message : String(error)}`) })
}
+ // The app's own picker on the page (saveAs), not a system box.
async #saveLog() {
- const { version, electron } = this.#o
- if (!electron.dialog) return
+ const { version, saveAs } = this.#o
+ if (saveAs === undefined) return
const reason = this.#state.failure?.reason ?? 'other'
const text = detailsText({ version, platform: process.platform, arch: process.arch, reason, lines: this.#o.log.tail(SAVED_LINES) })
try {
- const { canceled, filePath } = await electron.dialog.showSaveDialog(this.#window, { defaultPath: 'DeepSeek-Bot-log.txt', filters: [{ name: 'Text', extensions: ['txt'] }] })
- if (canceled || !filePath) return
+ const filePath = await saveAs(this.#window, 'DeepSeek-Bot-log.txt')
+ if (!filePath) return
await writeFile(filePath, text, 'utf8')
note(`the log was saved to ${filePath}`)
} catch (error) {
diff --git a/app/src/start/text.mjs b/app/src/start/text.mjs
index d2d894b9..97b75da1 100644
--- a/app/src/start/text.mjs
+++ b/app/src/start/text.mjs
@@ -153,6 +153,7 @@ export const TEXT = {
'dialog.pickMove': '选择 DeepSeek Bot 数据的新文件夹',
'dialog.pickCookies': '选择 cookie 文件',
'dialog.saveAs': '保存下载的文件',
+ 'dialog.saveLog': '保存日志',
// The app's own picker (preload.cjs showPicker): labels, then what went wrong, in place.
'picker.places': '位置',
'picker.drives': '磁盘',
@@ -336,6 +337,7 @@ export const TEXT = {
'dialog.pickMove': 'Choose a new folder for DeepSeek Bot’s data',
'dialog.pickCookies': 'Choose a cookie file',
'dialog.saveAs': 'Save the download',
+ 'dialog.saveLog': 'Save the log',
'picker.places': 'Places',
'picker.drives': 'Drives',
'picker.home': 'Home',
diff --git a/app/test/start-page.test.mjs b/app/test/start-page.test.mjs
index c2fb0be2..3da579da 100644
--- a/app/test/start-page.test.mjs
+++ b/app/test/start-page.test.mjs
@@ -192,7 +192,7 @@ test('each layer ends its lines as its rule says', () => {
const BARE = new Set(['voice', 'say', 'hint', 'btn', 'foot', 'status', 'picker'])
// Not sentences: picker titles, progress lines and labels.
const NOT_SENTENCES = new Set([
- 'card.update.slow', 'card.update.downloading', 'dialog.pickRoot', 'dialog.pickMove', 'dialog.pickCookies', 'dialog.saveAs',
+ 'card.update.slow', 'card.update.downloading', 'dialog.pickRoot', 'dialog.pickMove', 'dialog.pickCookies', 'dialog.saveAs', 'dialog.saveLog',
'card.copying.step1', 'card.copying.step2', 'card.copying.step3', 'card.copying.eta', 'card.copying.etaSoon',
'card.import.model', 'card.import.optRegen', 'card.import.optSkipWork',
])
@@ -212,7 +212,7 @@ test('each layer ends its lines as its rule says', () => {
assert.match(zh, ends[0], `${key}: zh is not a whole sentence`)
assert.match(en, ends[1], `${key}: en is not a whole sentence`)
}
- if (['dialog.pickRoot', 'dialog.pickMove', 'dialog.pickCookies', 'dialog.saveAs'].includes(key)) {
+ if (['dialog.pickRoot', 'dialog.pickMove', 'dialog.pickCookies', 'dialog.saveAs', 'dialog.saveLog'].includes(key)) {
assert.doesNotMatch(zh, /。$/u, `${key}: a picker title ends with a full stop`)
assert.doesNotMatch(en, /\.$/u, `${key}: a picker title ends with a full stop`)
}
diff --git a/app/test/start-window.test.mjs b/app/test/start-window.test.mjs
index 2f41bf87..6c07c96a 100644
--- a/app/test/start-window.test.mjs
+++ b/app/test/start-window.test.mjs
@@ -324,13 +324,14 @@ function startWindow(t) {
t.mock.method(console, 'log', () => {})
const fake = fakeElectron()
const main = new fake.electron.BrowserWindow({ show: false })
- const calls = { retry: 0, reload: 0, close: 0, pick: [], answer: [], update: [] }
+ const calls = { retry: 0, reload: 0, close: 0, pick: [], answer: [], update: [], saveAs: [], saveTo: undefined }
const start = new StartWindow({
electron: fake.electron, page: join(tmpdir(), 'start', 'start.html'), preload: 'preload.cjs', icon: 'icon.ico', mica: false, devTools: false,
lang: () => 'en', motion: 'normal', version: '0.0.0', program: [], log: { dir: 'logs', tail: () => ['a log line'] },
mainWindow: () => main,
onRetry: () => { calls.retry += 1 }, onReload: () => { calls.reload += 1 }, onClose: () => { calls.close += 1 },
onPick: (value) => { calls.pick.push(value) }, onAnswer: (value) => { calls.answer.push(value) }, onUpdate: (name) => { calls.update.push(name) },
+ saveAs: (win, name) => { calls.saveAs.push(name); return Promise.resolve(calls.saveTo) },
})
const win = () => fake.windows.at(-1)
const page = () => ({ sender: win().webContents, senderFrame: win().webContents.mainFrame })
@@ -361,6 +362,24 @@ test('the start window takes acts only from its own page, each in its own view',
assert.equal(s.calls.retry, 0)
})
+// 〔保存日志…〕 asks the app's own picker (main.mjs saveAs) where, never a system box.
+test('〔保存日志…〕 writes the log where the app\'s picker says, and nothing when it is cancelled', async (t) => {
+ const s = startWindow(t)
+ s.start.open('first')
+ s.start.fail(new Error('The DSH Host stopped (exit 1)'))
+ const dir = mkdtempSync(join(tmpdir(), 'ds-bot-log-'))
+ t.after(() => { rmSync(dir, { recursive: true, force: true }) })
+ assert.equal(s.act('saveLog'), true)
+ await new Promise(resolve => setImmediate(resolve))
+ assert.deepEqual(s.calls.saveAs, ['DeepSeek-Bot-log.txt'])
+ assert.deepEqual(readdirSync(dir), [])
+ s.calls.saveTo = join(dir, 'log.txt')
+ s.act('saveLog')
+ const saved = () => (readdirSync(dir).length > 0 ? readFileSync(join(dir, 'log.txt'), 'utf8') : '')
+ for (let i = 0; i < 500 && !saved().includes('a log line'); i += 1) await new Promise(resolve => setImmediate(resolve))
+ assert.match(saved(), /^DeepSeek Bot 0\.0\.0 \([\s\S]*a log line/u)
+})
+
test('the 180 s question comes on the start\'s clock while the engine is not up', async (t) => {
const s = startWindow(t)
s.start.open('first')