Skip to content

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

Merge dev into feat/windows-onboarding-m4-start-window

Fei24112336b86c85de
diff --cc app/src/import.mjs
index b3d45851,de230039..fc7525c3
--- a/app/src/import.mjs
+++ b/app/src/import.mjs
@@@ -136,44 -139,46 +148,74 @@@ const isNewer = (from, { id, group }) =
/** The Sessions whose log is in a newer format than the pinned DSH reads. */
export function newerSessions(from, team) {
const { found } = sessionDirs(from, sessionIdsOf(team))
- return found.filter(({ id, group }) => readdirSync(join(from, 'sessions', group, id))
- .some(name => (logVersion(name) ?? 0) > sessionFormatCatalog.currentVersion)).map(({ id }) => id)
+ return found.filter(session => isNewer(from, session)).map(({ id }) => id)
+ }
+
+ /**
+ * Copy into the data location `to` the Sessions its team names that are not there, from the DSH
+ * home the team was imported from. Imports before 0.2.3 left out each group's own Session, and
+ * such a group does not open (#551). Each Session is put together beside the data and moved in
+ * whole; one this DSH cannot read stays where it is. Nothing in the old home changes.
+ * @param {string} to @param {AbortSignal} [signal]
+ * @returns {Promise<{ copied: string[], newer: string[] }>} the ids copied, and those left for their newer format
+ */
+ export async function restoreSessions(to, signal) {
+ const record = join(to, 'bot', 'imported.json')
+ const statePath = join(to, 'bot', 'state.json')
+ const none = { copied: [], newer: [] }
+ if (!existsSync(record) || !existsSync(statePath)) return none
+ const { from } = readJson(record)
+ if (typeof from !== 'string' || resolve(from) === resolve(to)) return none
+ for (const name of readdirSync(to).filter(entry => /^\.restore-\d+$/u.test(entry))) {
+ await rm(join(to, name), { recursive: true, force: true })
+ }
+ const { missing } = sessionDirs(to, sessionIdsOf(readJson(statePath)))
+ const { found } = sessionDirs(from, missing)
+ const newer = found.filter(session => isNewer(from, session))
+ const sessions = found.filter(session => !newer.includes(session))
+ if (sessions.length > 0) {
+ const stage = join(to, `.restore-${String(Date.now())}`)
+ await copySessionDirs(from, stage, sessions, signal)
+ await moveSessionDirs(stage, to, sessions, signal)
+ await rm(stage, { recursive: true, force: true })
+ }
+ return { copied: sessions.map(({ id }) => id), newer: newer.map(({ id }) => id) }
}
+// The Host's first start on the data location writes a .credentials.yaml of its own: the browser
+// session grant of the connection plugin, under client-connection/. A file with nothing else in
+// it holds no key of the user's.
+async function onlyHostRecords(file) {
+ let document
+ try {
+ document = parse(await readFile(file, 'utf8')) ?? {}
+ } catch {
+ // A file that does not read as DSH's is the user's to fix, not ours to replace.
+ return false
+ }
+ if (typeof document !== 'object' || Array.isArray(document)) return false
+ const { version, refs, records, ...other } = document
+ return (version === undefined || version === 1) && Object.keys(other).length === 0
+ && Object.keys(refs ?? {}).length === 0
+ && Object.keys(records ?? {}).every(key => key.startsWith('client-connection/'))
+}
+
+// A key file the data location has already is the user's own, saved there since, and stays;
+// a .credentials.yaml that only the Host wrote is not.
+// Returns 'copied', 'kept', or undefined when the old home has none.
async function copyKey(from, to, name) {
const source = join(from, name)
- if (!existsSync(source)) return false
- await cp(source, join(to, name))
- if (process.platform !== 'win32') await chmod(join(to, name), 0o600)
- return true
+ if (!existsSync(source)) return undefined
+ const target = join(to, name)
+ const replace = name === '.credentials.yaml' && existsSync(target) && await onlyHostRecords(target)
+ try {
+ await cp(source, target, { force: replace, errorOnExist: !replace })
+ } catch (error) {
+ if (error?.code === 'ERR_FS_CP_EEXIST') return 'kept'
+ throw error
+ }
+ if (process.platform !== 'win32') await chmod(target, 0o600)
+ return 'copied'
}
async function writeModelRows(to, rows) {
diff --cc app/src/main.mjs
index 545baedf,b630e96a..217c11ca
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@@ -12,15 -8,24 +12,19 @@@ import { release } from 'node:os
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
import { setTimeout as sleep } from 'node:timers/promises'
import { fileURLToPath } from 'node:url'
-import { getDshRuntimeVersion } from '@deepseek-ai/dsh-app-boot'
-import electronUpdater from 'electron-updater'
-import { BotBrowserGuests, partitionOf } from './bot-browser.mjs'
-import { BotViews, isBotId } from './bot-views.mjs'
-import { importFromBrowser, listSources } from './browser-sources.mjs'
-import { applyCookies, CookieImports } from './cookie-import.mjs'
-import { parseCookieFile } from './cookie-parse.mjs'
-import { downloadSaver } from './downloads.mjs'
import { canonicalExecPath } from './canonical-path.mjs'
-import { chooseLocations, localeText, programFolder, saveLocations, text } from './first-run.mjs'
import { configureIdentity } from './legacy.mjs'
import { hostPort } from './host-port.mjs'
+ import { HostProcess } from './host-process.mjs'
+ import { copySessions, findTeam, importTeam, restoreSessions, teamInUse, userDshHome } from './import.mjs'
+import { captureStdio, LogFile } from './logs.mjs'
+ import { copyData, moveProblem } from './move-data.mjs'
+import { currentRootOf, driveOf, formatBytes, freeSpace, isEmptyTree, pickFrom, placeOf, rootOf } from './place.mjs'
+ import { CHECK_PROFILE, PROFILE } from './profile.mjs'
import { createShell, SHELL_TEXT } from './shell.mjs'
-import { UPDATE_TEXT, watchReleases, watchUpdates } from './updates.mjs'
+import { readStartFrame, writeStartFrame } from './start-frame.mjs'
+import { explainOf, StartWindow } from './start-window.mjs'
+import { langOf } from './start/text.mjs'
import { createDeferredPrompt } from './update-prompt.mjs'
import { CAPTION_HEIGHT, cssColor, micaAvailable, nativeThemeSource } from './window-frame.mjs'
@@@ -218,335 -176,66 +222,340 @@@ function stopHost()
return hostStop
}
+// A throwaway run (DS_BOT_HOME) asks nothing and shows what a later start shows.
+const startKind = () => (process.env.DS_BOT_HOME || existsSync(join(app.getPath('userData'), 'locations.json')) ? 'later' : 'first')
+
async function start() {
- choosing = new AbortController()
- const where = await chooseLocations(choosing.signal).finally(() => { choosing = undefined })
- if (where.quit) { app.exit(0); return }
- places = { dataDir: where.dataDir, workspace: where.workspace }
- const port = await hostPort(join(app.getPath('userData'), 'host-port.json'))
- origin = `http://127.0.0.1:${String(port)}`
- const pnpm = join(app.getAppPath(), 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
- const runtimeDir = app.isPackaged ? process.resourcesPath : join(here, '..', 'build', 'runtime')
- const profileDir = join(where.dataDir, 'profiles', PROFILE)
- mkdirSync(profileDir, { recursive: true })
- const newHost = () => new HostProcess({
- entry: join(here, 'host.mjs'),
- cwd: profileDir,
- env: { ...process.env, DSH_HOME: where.dataDir, DS_BOT_PORT: String(port), DS_BOT_APP: '1', DS_BOT_USER_DSH_HOME: userDshHome(), DS_BOT_RUNTIME_DIR: runtimeDir, ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },
- pnpm,
- onFailure: fail,
+ setMenu()
+ nativeTheme.themeSource = readStartFrame(frameFile).themeSource
+ // A packaged app has the icon in its bundle; Electron's own run shows Electron's.
+ if (process.platform === 'darwin' && !app.isPackaged) app.dock?.setIcon(iconFile)
+ await prepare()
+ run()
+}
+
+// What the boot needs; a retry after a failure here does what is still missing.
+async function prepare() {
+ // Before the windows: the team window's page is told the Host's origin.
+ if (port === undefined) {
+ port = await hostPort(join(app.getPath('userData'), 'host-port.json'))
+ origin = `http://127.0.0.1:${String(port)}`
+ }
+ startWindow.open(startKind())
+ if (browserGuests === undefined) {
+ await loadModules()
+ handleIpc()
+ }
+ // The team window is made once the start window has painted, already on its final rect, and
+ // made again when it is gone for good (a cancelled shutdown kept the app without one), so
+ // that the next engine has a window to load into.
+ if (mainCreated === undefined || (await mainCreated, mainWindow === undefined)) mainCreated = startWindow.painted.then(createWindow)
+}
+
+async function loadModules() {
+ const [browser, views, sources, cookies, cookieFiles, downloads, firstRun, hostProcess, imports, moves, profile, updatesModule, boot, updater] = await Promise.all([
+ import('./bot-browser.mjs'), import('./bot-views.mjs'), import('./browser-sources.mjs'), import('./cookie-import.mjs'),
+ import('./cookie-parse.mjs'), import('./downloads.mjs'), import('./first-run.mjs'), import('./host-process.mjs'),
+ import('./import.mjs'), import('./move-data.mjs'), import('./profile.mjs'), import('./updates.mjs'),
+ import('@deepseek-ai/dsh-app-boot'), import('electron-updater'),
+ ])
+ ;({ BotBrowserGuests, partitionOf } = browser)
+ ;({ BotViews, isBotId } = views)
+ ;({ importFromBrowser, listSources } = sources)
+ ;({ applyCookies, CookieImports } = cookies)
+ ;({ parseCookieFile } = cookieFiles)
+ ;({ downloadSaver } = downloads)
+ ;({ chooseLocations, defaultPlaces, pickRoot, programFolder, saveLocations, teamIn, teamsAt, tx } = firstRun)
+ ;({ HostProcess } = hostProcess)
+ ;({ copySessions, findTeam, importTeam, teamInUse, userDshHome } = imports)
+ ;({ copyData, moveProblem } = moves)
+ ;({ CHECK_PROFILE, PROFILE } = profile)
+ ;({ watchReleases, watchUpdates } = updatesModule)
+ ;({ getDshRuntimeVersion } = boot)
+ electronUpdater = updater.default
+ browserGuests = new BotBrowserGuests({ session, origin: () => origin, devTools: !app.isPackaged })
+ botViews = new BotViews({
+ window: () => mainWindow, WebContentsView, guests: browserGuests, origin: () => origin, devTools: !app.isPackaged,
+ statePath: join(app.getPath('userData'), 'bot-views.json'),
+ onChange: state => mainWindow?.webContents.send(IPC.browserViewChanged, state),
})
- // A failed check is not a failed start: start() rejects, and the copy goes on unchecked.
- const newCheck = (home, list) => {
- const cwd = join(home, 'profiles', CHECK_PROFILE)
- mkdirSync(cwd, { recursive: true })
- return new HostProcess({ entry: join(here, 'host.mjs'), cwd, env: { ...process.env, DSH_HOME: home, DS_BOT_CHECK: list, DS_BOT_RUNTIME_DIR: runtimeDir }, pnpm, onFailure: () => {} })
+ cookieImports = new CookieImports()
+}
+
+function run() {
+ const mine = (attempt += 1)
+ 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. 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() {
+ const mine = (attempt += 1)
+ forgetHost()
+ failed = false
+ proposed = undefined
+ restarting = true
+ try {
+ await copying?.catch(() => {})
+ if (copyAbort.signal.aborted || stopping || mine !== attempt) return
+ await stopOld()
+ if (stopping || mine !== attempt) return
+ await prepare()
+ } finally {
+ restarting = false
}
- const ready = (async () => {
- let copied
- if (where.import) {
- copying = copyTeam(where, newHost, newCheck, copyAbort.signal)
- copied = await copying
- copying = undefined
+ if (!stopping && mine === attempt) run()
+}
+
+// The handshake of the Host that goes: a window rebuilt before the next engine answers must not
+// load against a Host that is stopped, nor take its cookie for the new one's.
+function forgetHost() {
+ hostReady = false
+ bootstrap = undefined
+}
+
+// The Host stays known while it stops, so that a quit meanwhile waits for it.
+async function stopOld(options) {
+ const old = host
+ if (old === undefined) return
+ await old.stop(options).catch((error) => { console.error(error) })
+ if (host === old) host = undefined
+}
+
+// The dialogs of the first run belong to the start window and stop its clock.
+const ui = () => ({ owner: () => startWindow.owner(), asking: answer => startWindow.asking(answer) })
+
+// The data folder (with the first run's question on a first start), the engine, then the team
+// view in the hidden team window.
+async function boot(mine) {
+ if (places === undefined) {
+ const first = startWindow.kind === 'first'
+ if (first) {
+ const teams = teamsAt()
+ startWindow.explain(explainOf(teams))
+ // A reinstall goes on with its data where it is; a new or copied team can still move.
+ if (teams.team === undefined) tellPlace(defaultPlaces().dataDir)
}
+ choosing = new AbortController()
+ const where = await chooseLocations(choosing.signal, ui()).finally(() => { choosing = undefined })
+ if (where.quit) { app.exit(0); return }
+ setPlaces({ dataDir: where.dataDir, workspace: where.workspace })
+ pendingImport = where.import
+ if (first) startWindow.explain(explainOf({ offered: where.offered === true, team: teamIn(where.dataDir) }))
+ }
+ // Also the check that the data folder can be written.
+ mkdirSync(profileDir(), { recursive: true })
+ startWindow.done('data')
+ const engine = await startEngine(mine)
+ if (engine === undefined || mine !== attempt) return
+ startWindow.done('engine')
+ await mainCreated
+ if (mine !== attempt || mainWindow === undefined) return
+ startWindow.teamLoading()
+ // The launch URL trades its token for the Host's cookie and goes on to the page. The cookie
+ // is there once that load came through. The token is good for one browser only: it is spent
+ // as soon as a window carries it. Each engine has a token of its own.
+ const win = mainWindow
+ launchUrl = engine.url
+ tokenSpent = true
+ hostReady = false
+ bootstrap = win.loadURL(engine.url).then(() => {
+ if (mine === attempt) hostReady = true
+ return true
+ }).catch(() => false)
+}
+
+function setPlaces(next) {
+ places = next
+ const root = currentRootOf(places.dataDir, places.workspace)
+ made = { dataDir: !existsSync(places.dataDir), workspace: places.workspace !== undefined && !existsSync(places.workspace), root: root !== undefined && !existsSync(root) }
+}
+
+// The line on the start page that says where the data goes and how much room is there, and the
+// short drive's note for the first 10 s (start-window §2, §4).
+function tellPlace(dataDir) {
+ const free = freeSpace(dataDir)
+ startWindow.place(placeOf(dataDir, { free }))
+ const drive = driveOf(dataDir)
+ startWindow.hint(drive !== undefined && free !== undefined && free < SHORT_DRIVE_BYTES ? { drive, free: formatBytes(free) } : undefined)
+}
+
+// 「换个位置…」 on the start page and 〔重新选〕 on its cards: the system picker, then the root rule
+// (windows-onboarding §3, 一个位置). The root is used at once when it is the folder picked; a
+// layer the app added is confirmed on the 「会放在…」 card; a place that cannot be used says why.
+// A cancelled picker leaves things as they were: the line, or the card it came from. Not during
+// the first run's copy, whose team would be left behind.
+async function changePlace() {
+ if (startWindow.kind !== 'first' || places === undefined || choosing !== undefined || copying !== undefined || picking || restarting || stopping || failed) return
+ picking = true
+ try {
+ // One wait for the picker and what follows it: a team view that becomes ready meanwhile
+ // hands over only once the start knows where it goes on.
+ await startWindow.asking(pickAndPlace())
+ } finally {
+ picking = false
+ }
+}
+
+// A cancelled picker, or the place the data is in now, is no change: the line stays, and a card
+// that led here goes, since the start goes on where it was.
+async function pickAndPlace() {
+ const picked = await pickRoot(pickFrom(places.dataDir), copyAbort.signal, ui())
+ if (stopping || startWindow.owner() === undefined) return
+ const root = picked === undefined ? { same: true } : rootOf(picked, { dshHome: userDshHome(), program: app.isPackaged ? programFolder() : undefined, current: places })
+ if (root.same) {
+ proposed = undefined
+ startWindow.card(undefined)
+ return
+ }
+ if (root.reason !== undefined) {
+ console.log(`DS Bot: the place ${root.at} cannot be used (${root.reason})`)
+ proposed = undefined
+ startWindow.card({ kind: 'rejected', reason: root.reason, path: root.at })
+ return
+ }
+ if (root.added) {
+ proposed = root
+ startWindow.card({ kind: 'picked', path: root.root })
+ return
+ }
+ await startOver(root)
+}
+
+async function placeAnswer(value) {
+ if (value !== 'use' || proposed === undefined || picking || restarting) return
+ const root = proposed
+ proposed = undefined
+ await startOver(root)
+}
+
+// The start begins again in the root R (start-window §7): the whale sinks at once, the engine
+// that may be up on the default folder stops, what this start made there goes, and the boot runs
+// again. The places are saved at once: the import question has been answered by now.
+async function startOver(root) {
+ const mine = (attempt += 1)
+ forgetHost()
+ failed = false
+ proposed = undefined
+ restarting = true
+ try {
+ // restart() also takes the card away, without letting a held hand-off of the old engine go;
+ // the line names the new place from here on. The Host on the old folder is ended at once:
+ // neither its boot nor an orderly shutdown of a folder about to go is of any use, and either
+ // would keep the whale under water for up to 10 s.
+ startWindow.restart()
+ tellPlace(root.dataDir)
+ await stopOld({ now: true })
+ if (stopping || mine !== attempt) return
+ await removeMade()
+ if (stopping || mine !== attempt) return
+ setPlaces({ dataDir: root.dataDir, workspace: root.workspace })
+ saveLocations(places)
+ console.log(`DS Bot: the data goes to ${places.dataDir}`)
+ } finally {
+ restarting = false
+ }
+ run()
+}
+
+// What this start made at the place it leaves: the data folder it created (the engine may have
+// put a blank team there), the team workspace while nothing has been written into it, and the
+// root above them once it is empty.
+async function removeMade() {
+ const gone = []
+ if (made.dataDir && existsSync(places.dataDir)) gone.push(places.dataDir)
+ if (made.workspace && existsSync(places.workspace) && isEmptyTree(places.workspace)) gone.push(places.workspace)
+ for (const folder of gone) await rm(folder, { recursive: true, force: true, maxRetries: 5 }).catch((error) => { console.error(error) })
+ const root = currentRootOf(places.dataDir, places.workspace)
+ if (made.root && root !== undefined && existsSync(root) && isEmptyTree(root)) await rm(root, { recursive: true, force: true, maxRetries: 5 }).catch((error) => { console.error(error) })
+}
+
+const profileDir = () => join(places.dataDir, 'profiles', PROFILE)
+const pnpmEntry = () => join(app.getAppPath(), 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
+const hostOutput = (stream, chunk) => {
+ logs.write('engine', chunk)
+ rawOutput[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(), DS_BOT_RUNTIME_DIR: app.isPackaged ? process.resourcesPath : join(here, '..', 'build', 'runtime'), ...(places.workspace ? { DS_BOT_WORKSPACE: places.workspace } : {}) },
+ pnpm: pnpmEntry(),
+ onFailure: (error) => { if (mine === attempt) void fail(error) },
+ output: hostOutput,
+ })
+}
+
+// A failed check is not a failed start: start() rejects, and the copy goes on unchecked.
+function newCheck(home, list) {
+ const cwd = join(home, 'profiles', CHECK_PROFILE)
+ mkdirSync(cwd, { recursive: true })
+ 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, 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
+ // The team is about to live here; moving it is Settings' job (the data move).
+ startWindow.place(undefined)
+ // 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)
- // The window may be waiting for the Host; it goes away with the app.
- if (copied !== undefined) return new Promise(() => {})
- // 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.
+ 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.
+ if (!updatesStarted) {
+ updatesStarted = true
updates = startUpdates()
updates?.subscribe((state) => { mainWindow?.webContents.send(IPC.appUpdateChanged, state) })
- }
- host = newHost()
- host.onMessage(message => {
- if (message?.type !== 'ds-bot:browser-endpoint' || typeof message.id !== 'string' || !isBotId(message.botId)) return
- const downloadRoots = message.downloadRoots
- if (!Array.isArray(downloadRoots) || downloadRoots.length > 4 || !Array.from(downloadRoots).every(root => typeof root === 'string' && isAbsolute(root))) {
- host?.send({ type: 'ds-bot:browser-endpoint-response', id: message.id, error: 'Could not create the browser endpoint.' })
- return
- }
- void botViews.endpoint(message.botId, { downloadRoots }).then(url => {
- host?.send({ type: 'ds-bot:browser-endpoint-response', id: message.id, url })
- }).catch(() => host?.send({ type: 'ds-bot:browser-endpoint-response', id: message.id, error: 'Could not create the browser endpoint.' }))
- })
- return host.start()
- }
+
- function handleIpc() {
+ // Before the Host, which reads the Sessions.
+ await restoreSessions(where.dataDir).then(({ copied, newer }) => {
+ if (copied.length > 0) console.log(`DS Bot: copied ${copied.join(', ')}, which the import left out`)
+ if (newer.length > 0) console.warn(`DS Bot: this DSH cannot read ${newer.join(', ')}, which the import left out`)
+ }, (error) => { console.error('DS Bot: the Sessions the import left out were not copied:', error) })
+ host = newHost()
+ host.onMessage(message => {
+ if (message?.type !== 'ds-bot:browser-endpoint' || typeof message.id !== 'string' || !isBotId(message.botId)) return
+ const downloadRoots = message.downloadRoots
+ if (!Array.isArray(downloadRoots) || downloadRoots.length > 4 || !Array.from(downloadRoots).every(root => typeof root === 'string' && isAbsolute(root))) {
+ host?.send({ type: 'ds-bot:browser-endpoint-response', id: message.id, error: 'Could not create the browser endpoint.' })
+ return
+ }
+ void botViews.endpoint(message.botId, { downloadRoots }).then(url => {
+ host?.send({ type: 'ds-bot:browser-endpoint-response', id: message.id, url })
+ }).catch(() => host?.send({ type: 'ds-bot:browser-endpoint-response', id: message.id, error: 'Could not create the browser endpoint.' }))
+ })
+ return host.start()
+ })()
+ ready.catch(fail)
++
// A throwaway run (DS_BOT_HOME) keeps its folders where it was told.
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() })
+ // 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 }
diff --cc ds-bot/client.js
index 23fabcc4,35cb2386..cd6415bd
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@@ -14140,25 -13800,104 +14150,104 @@@ function changeLine(change)
if (change.op === "edit") return t("Updated: {text}", { text });
return change.scope === "team" ? t("Added to team memory: {text}", { text }) : t("Added: {text}", { text });
}
+ function historyLine(row) {
+ const text = row.text.length > 120 ? `${row.text.slice(0, 120)}…` : row.text;
+ if (row.op === "remove") return row.scope === "team" ? t("Removed from team memory: {text}", { text }) : t("Removed: {text}", { text });
+ if (row.op === "replace") return t("Updated: {text}", { text });
+ return row.scope === "team" ? t("Added to team memory: {text}", { text }) : t("Added: {text}", { text });
+ }
+ function HistoryRow({ row, undo, now }) {
- const [confirming, setConfirming] = (0, import_react31.useState)(false);
- const [busy, setBusy] = (0, import_react31.useState)(false);
- (0, import_react31.useEffect)(() => {
++ const [confirming, setConfirming] = (0, import_react32.useState)(false);
++ const [busy, setBusy] = (0, import_react32.useState)(false);
++ (0, import_react32.useEffect)(() => {
+ if (!confirming) return void 0;
+ const timer = setTimeout(() => setConfirming(false), 3e3);
+ return () => clearTimeout(timer);
+ }, [confirming]);
+ const when3 = ago(Date.parse(row.time), now) ?? t("just now");
+ const meta = [when3, row.by === "user" ? t("by you") : t("by {name}", { name: row.by })].join(" · ");
+ const click = async () => {
+ if (!confirming) {
+ setConfirming(true);
+ return;
+ }
+ setBusy(true);
+ if (!await undo(row)) setBusy(false);
+ };
- return (0, import_react31.createElement)(
++ return (0, import_react32.createElement)(
+ "li",
+ { className: "bt-mem-entry", "data-busy": busy || void 0 },
- (0, import_react31.createElement)(
++ (0, import_react32.createElement)(
+ "div",
+ { className: "bt-mem-entry-copy" },
- (0, import_react31.createElement)("span", { className: "bt-mem-entry-text" }, historyLine(row)),
- (0, import_react31.createElement)("span", { className: "bt-mem-entry-meta" }, meta)
++ (0, import_react32.createElement)("span", { className: "bt-mem-entry-text" }, historyLine(row)),
++ (0, import_react32.createElement)("span", { className: "bt-mem-entry-meta" }, meta)
+ ),
- row.restored ? (0, import_react31.createElement)("span", { className: "bt-mem-undone" }, t("Undone")) : (0, import_react31.createElement)("button", {
++ row.restored ? (0, import_react32.createElement)("span", { className: "bt-mem-undone" }, t("Undone")) : (0, import_react32.createElement)("button", {
+ type: "button",
+ className: "bt-mem-remove",
+ "data-confirm": confirming || void 0,
+ disabled: busy,
+ "aria-label": confirming ? t("Click again to undo") : t("Undo this change"),
+ title: confirming ? void 0 : t("Undo this change"),
+ onClick: click
+ }, t("Undo"))
+ );
+ }
+ function History({ owner, actions, undo, now }) {
- const [rows2, setRows] = (0, import_react31.useState)(null);
- const [more, setMore] = (0, import_react31.useState)(null);
- const [paging, setPaging] = (0, import_react31.useState)(false);
- const load = (0, import_react31.useCallback)(async (before) => {
++ const [rows2, setRows] = (0, import_react32.useState)(null);
++ const [more, setMore] = (0, import_react32.useState)(null);
++ const [paging, setPaging] = (0, import_react32.useState)(false);
++ const load = (0, import_react32.useCallback)(async (before) => {
+ const page = await actions.memoryHistory(owner.id, before);
+ setRows(before === void 0 ? page.rows : [...rows2 ?? [], ...page.rows]);
+ setMore(page.more);
+ }, [owner.id, rows2]);
- (0, import_react31.useEffect)(() => {
++ (0, import_react32.useEffect)(() => {
+ void load();
+ }, [owner.id]);
+ const reload = async () => {
+ setRows(null);
+ setMore(null);
+ await load();
+ };
+ const undoRow = async (row) => await undo(row) ? reload() : false;
+ const moreClick = async () => {
+ setPaging(true);
+ try {
+ await load(more);
+ } finally {
+ setPaging(false);
+ }
+ };
- if (rows2 === null) return (0, import_react31.createElement)(Skeleton);
- if (rows2.length === 0) return (0, import_react31.createElement)("div", { className: "bt-mem-none" }, t("No changes yet"));
- return (0, import_react31.createElement)(
++ if (rows2 === null) return (0, import_react32.createElement)(Skeleton);
++ if (rows2.length === 0) return (0, import_react32.createElement)("div", { className: "bt-mem-none" }, t("No changes yet"));
++ return (0, import_react32.createElement)(
+ "div",
+ { className: "bt-mem-entries" },
- (0, import_react31.createElement)("ul", { className: "bt-mem-list" }, rows2.map((row) => (0, import_react31.createElement)(HistoryRow, { key: row.id, row, undo: undoRow, now }))),
- more ? (0, import_react31.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: paging, onClick: () => void moreClick() }, t("Load more")) : null
++ (0, import_react32.createElement)("ul", { className: "bt-mem-list" }, rows2.map((row) => (0, import_react32.createElement)(HistoryRow, { key: row.id, row, undo: undoRow, now }))),
++ more ? (0, import_react32.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: paging, onClick: () => void moreClick() }, t("Load more")) : null
+ );
+ }
function Reply({ answer, dismiss }) {
- return (0, import_react31.createElement)(
+ return (0, import_react32.createElement)(
"div",
{ className: "bt-mem-reply", role: "status" },
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)(
"div",
{ className: "bt-mem-reply-head" },
- (0, import_react31.createElement)("span", { className: "bt-mem-reply-asked" }, answer.asked),
- answer.pending ? null : (0, import_react31.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Dismiss"), onClick: dismiss }, (0, import_react31.createElement)(CloseIcon))
+ (0, import_react32.createElement)("span", { className: "bt-mem-reply-asked" }, answer.asked),
+ answer.pending ? null : (0, import_react32.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Dismiss"), onClick: dismiss }, (0, import_react32.createElement)(CloseIcon))
),
- answer.pending ? (0, import_react31.createElement)("div", { className: "bt-mem-reply-text bt-shimmer" }, t("Thinking…")) : answer.error ? (0, import_react31.createElement)("div", { className: "bt-mem-reply-text bt-danger" }, hostText(answer.error)) : (0, import_react31.createElement)(
- import_react31.Fragment,
+ answer.pending ? (0, import_react32.createElement)("div", { className: "bt-mem-reply-text bt-shimmer" }, t("Thinking…")) : answer.error ? (0, import_react32.createElement)("div", { className: "bt-mem-reply-text bt-danger" }, hostText(answer.error)) : (0, import_react32.createElement)(
+ import_react32.Fragment,
null,
- answer.reply ? (0, import_react31.createElement)("div", { className: "bt-mem-reply-text" }, answer.reply) : null,
- answer.changes.length > 0 ? (0, import_react31.createElement)("ul", { className: "bt-mem-changes" }, answer.changes.map((change, index) => (0, import_react31.createElement)(
+ answer.reply ? (0, import_react32.createElement)("div", { className: "bt-mem-reply-text" }, answer.reply) : null,
+ answer.changes.length > 0 ? (0, import_react32.createElement)("ul", { className: "bt-mem-changes" }, answer.changes.map((change, index) => (0, import_react32.createElement)(
"li",
{ key: index, "data-ok": change.ok || void 0 },
- change.ok ? (0, import_react31.createElement)(CheckIcon) : (0, import_react31.createElement)(CloseIcon),
- (0, import_react31.createElement)("span", null, changeLine(change))
+ change.ok ? (0, import_react32.createElement)(CheckIcon) : (0, import_react32.createElement)(CloseIcon),
+ (0, import_react32.createElement)("span", null, changeLine(change))
))) : null
)
);
@@@ -14279,52 -14031,57 +14381,57 @@@ function MemoryDialog({ owner, actions
const when3 = view?.summary ? ago(view.summary.at, now) : null;
const status = view === null ? "" : page === "entries" ? count === 1 ? t("1 entry") : t("{count} entries", { count }) : view.summarizing && view.summary ? t("Updating…") : view.summary && view.fresh ? when3 ? t("Updated {time}", { time: when3 }) : t("Updated just now") : "";
const busy = answer?.pending === true;
- return (0, import_react31.createElement)(
+ return (0, import_react32.createElement)(
"div",
{ className: "bt-mem-layer", "data-leaving": leaving || void 0 },
- (0, import_react31.createElement)("div", { className: "bt-scrim bt-mem-scrim", onMouseDown: close }),
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)("div", { className: "bt-scrim bt-mem-scrim", onMouseDown: close }),
+ (0, import_react32.createElement)(
"div",
{ className: "bt-mem", role: "dialog", "aria-modal": true, "aria-label": t("{name}'s memory", { name: owner.name }) },
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)(
"div",
{ className: "bt-mem-head" },
- page === "entries" ? (0, import_react32.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Back to the summary"), onClick: backToSummary }, (0, import_react32.createElement)(ChevronLeftIcon)) : null,
- (0, import_react32.createElement)("h2", null, page === "entries" ? t("All entries") : t("Memory summary")),
- (0, import_react32.createElement)("span", { className: "bt-mem-status" }, page === "summary" ? [owner.name, status].filter(Boolean).join(" · ") : status),
- page === "summary" ? null : (0, import_react31.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Back to the summary"), onClick: backToSummary }, (0, import_react31.createElement)(ChevronLeftIcon)),
- (0, import_react31.createElement)("h2", null, page === "entries" ? t("All entries") : page === "history" ? t("Change history") : t("Memory summary")),
- (0, import_react31.createElement)("span", { className: "bt-mem-status" }, page === "summary" ? [owner.name, status].filter(Boolean).join(" · ") : page === "entries" ? status : ""),
- (0, import_react31.createElement)("span", { className: "bt-mem-head-gap" }),
- (0, import_react31.createElement)("button", { ref: dotsRef, type: "button", className: "bt-icon-btn", "aria-label": t("Memory options"), "aria-haspopup": "menu", "aria-expanded": menu, onClick: () => setMenu((value) => !value) }, (0, import_react31.createElement)(DotsIcon)),
- (0, import_react31.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Close memory"), onClick: close }, (0, import_react31.createElement)(CloseIcon)),
- menuShown ? (0, import_react31.createElement)(
++ page === "summary" ? null : (0, import_react32.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Back to the summary"), onClick: backToSummary }, (0, import_react32.createElement)(ChevronLeftIcon)),
++ (0, import_react32.createElement)("h2", null, page === "entries" ? t("All entries") : page === "history" ? t("Change history") : t("Memory summary")),
++ (0, import_react32.createElement)("span", { className: "bt-mem-status" }, page === "summary" ? [owner.name, status].filter(Boolean).join(" · ") : page === "entries" ? status : ""),
+ (0, import_react32.createElement)("span", { className: "bt-mem-head-gap" }),
+ (0, import_react32.createElement)("button", { ref: dotsRef, type: "button", className: "bt-icon-btn", "aria-label": t("Memory options"), "aria-haspopup": "menu", "aria-expanded": menu, onClick: () => setMenu((value) => !value) }, (0, import_react32.createElement)(DotsIcon)),
+ (0, import_react32.createElement)("button", { type: "button", className: "bt-icon-btn", "aria-label": t("Close memory"), onClick: close }, (0, import_react32.createElement)(CloseIcon)),
+ menuShown ? (0, import_react32.createElement)(
"div",
{ ref: menuRef, className: "bt-menu bt-mem-menu", role: "menu", "aria-label": t("Memory options"), "data-leaving": menuLeaving || void 0 },
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)(
"button",
{ type: "button", role: "menuitem", onClick: openEntries },
- (0, import_react31.createElement)("span", { className: "bt-menu-label" }, t("All entries")),
- (0, import_react31.createElement)("span", { className: "bt-menu-hint" }, String(count))
+ (0, import_react32.createElement)("span", { className: "bt-menu-label" }, t("All entries")),
+ (0, import_react32.createElement)("span", { className: "bt-menu-hint" }, String(count))
),
- (0, import_react31.createElement)(
++ (0, import_react32.createElement)(
+ "button",
+ { type: "button", role: "menuitem", onClick: openHistory },
- (0, import_react31.createElement)("span", { className: "bt-menu-label" }, t("Change history"))
++ (0, import_react32.createElement)("span", { className: "bt-menu-label" }, t("Change history"))
+ ),
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)(
"button",
{ type: "button", role: "menuitem", disabled: count === 0 || view?.summarizing, onClick: regenerate },
- (0, import_react31.createElement)("span", { className: "bt-menu-label" }, t("Regenerate summary"))
+ (0, import_react32.createElement)("span", { className: "bt-menu-label" }, t("Regenerate summary"))
)
) : null
),
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)(
"div",
{ className: "bt-mem-body" },
- error ? (0, import_react31.createElement)("div", { className: "bt-error", role: "alert", style: { padding: 0 } }, hostText(error)) : null,
- view === null ? error ? null : (0, import_react31.createElement)(Skeleton) : page === "entries" ? (0, import_react31.createElement)(Entries, { owner, view, remove }) : page === "history" ? (0, import_react31.createElement)(History, { owner, actions, undo, now }) : (0, import_react31.createElement)(Summary, { owner, view, regenerate })
+ error ? (0, import_react32.createElement)("div", { className: "bt-error", role: "alert", style: { padding: 0 } }, hostText(error)) : null,
- view === null ? error ? null : (0, import_react32.createElement)(Skeleton) : page === "entries" ? (0, import_react32.createElement)(Entries, { owner, view, remove }) : (0, import_react32.createElement)(Summary, { owner, view, regenerate })
++ view === null ? error ? null : (0, import_react32.createElement)(Skeleton) : page === "entries" ? (0, import_react32.createElement)(Entries, { owner, view, remove }) : page === "history" ? (0, import_react32.createElement)(History, { owner, actions, undo, now }) : (0, import_react32.createElement)(Summary, { owner, view, regenerate })
),
- (0, import_react31.createElement)(
+ (0, import_react32.createElement)(
"div",
{ className: "bt-mem-foot" },
- answer ? (0, import_react31.createElement)(Reply, { answer, dismiss: () => setAnswer(null) }) : null,
- (0, import_react31.createElement)(
+ answer ? (0, import_react32.createElement)(Reply, { answer, dismiss: () => setAnswer(null) }) : null,
+ (0, import_react32.createElement)(
"form",
{ className: "bt-mem-ask", onSubmit: ask },
- (0, import_react31.createElement)("input", {
+ (0, import_react32.createElement)("input", {
ref: inputRef,
className: "bt-mem-input",
value: text,