Skip to content

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

Read every chat of the team with the pinned DSH before the first-run copy

Fei24112aab5d59b65e
diff --git a/app/README.md b/app/README.md
index 079f5bfc..a14cc359 100644
--- a/app/README.md
+++ b/app/README.md
@@ -27,7 +27,7 @@ On macOS, Electron's default `userData` directory for `productName` "DeepSeek Bo
At its first start the app asks, in system dialogs, for the data location (`~/.ds-bot` by default) and the folder for the files that Bots make (`~/DeepSeek Bot`), and keeps the answer in `locations.json` in its own data. Neither folder may be inside the other or inside the user's DSH data.
-When the user's DSH (`DSH_HOME`, else `~/.dsh`) has a Bot team, the app offers to copy it (`src/import.mjs`). It only reads there. Before the copy it checks that no running DSH holds the team and that no chat is in a newer session format than the pinned DSH reads, and it starts the Host once on the new data location, so that DSH does not register the copied Sessions' folders as projects. The copy takes `bot/` (without its lock, turns in flight and workspace), every Session the team names, the attachments, `.credentials.yaml`, `.env`, the model rows of one profile's `cordis.patch.yml`, and the old team workspace's files, which go into the new folder without replacing a file there. `bot/imported.json` records it. At its next turn, each Bot and group moves on to a fresh part in the new folder.
+When the user's DSH (`DSH_HOME`, else `~/.dsh`) has a Bot team, the app offers to copy it (`src/import.mjs`). It only reads there. Before the copy it checks that no running DSH holds the team and that no chat is in a newer session format than the pinned DSH reads. Then the pinned DSH reads each chat once: a newer DSH can write records that the pinned one refuses in the same format. It reads a throwaway copy in the data location, with a profile of its own (`import-check`: `dsh-base` and `dsh-web-app`, without `ds-bot`), and removes the copy afterwards. A chat that a newer DSH wrote stops the copy as a newer format does; a damaged one does not, since the user's DSH cannot read it either. Then the app starts the Host once on the new data location, so that DSH does not register the copied Sessions' folders as projects. The copy takes `bot/` (without its lock, turns in flight and workspace), every Session the team names, the attachments, `.credentials.yaml`, `.env`, the model rows of one profile's `cordis.patch.yml`, and the old team workspace's files, which go into the new folder without replacing a file there. `bot/imported.json` records it. At its next turn, each Bot and group moves on to a fresh part in the new folder.
The Host reads model settings and keys the way DSH does: environment variables such as `DEEPSEEK_API_KEY`, and `.env` and `.credentials.yaml` in the data location. DSH's settings in the window set up model providers and their keys; DSH keeps the providers in the profile's `cordis.patch.yml` and the keys in `.credentials.yaml`.
@@ -45,7 +45,7 @@ At every start the Host puts these three bundles at the head of the profile's bu
## Check a change
-`npm test` checks the composition of the profile, the import on throwaway folders, and that every package the app runs on is a dependency (see [Package](#package)).
+`npm test` checks the composition of the profile, the import on throwaway folders, the first-run check on a chat with a record that the pinned DSH does not know, and that every package the app runs on is a dependency (see [Package](#package)).
`scripts/shot.mjs` starts the app on throwaway folders, saves a screenshot of its window, prints the page text, closes the window the way a user does and waits until the app exits. Use the mock model of the plugin, `../ds-bot/dev/mock-llm.mjs` (`MOCK_PORT=<port> node ../ds-bot/dev/mock-llm.mjs`).
@@ -109,8 +109,9 @@ The script serves a releases list with one release of that version that has this
| `src/main.mjs` | Main process: one instance, the `dsh-app://app` scheme (DSH's Web front end, and everything else forwarded to the Host), the window and its boot data |
| `src/preload.cjs` | Hands the window the boot data that DSH's Web front end needs |
| `src/host-process.mjs` | Starts the Host in Electron's Node mode and owns its exit |
-| `src/host.mjs` | The Host: boots the profile with `runProfile()` and reports the launch URL and the page injections |
-| `src/profile.mjs` | The profile: its name, its bundles, and its creation and update |
+| `src/host.mjs` | The Host: boots the profile with `runProfile()` and reports the launch URL and the page injections; for the first-run check (`DS_BOT_CHECK`), the chats it cannot read |
+| `src/profile.mjs` | The profiles: the app's own and the first-run check's, their bundles, and their creation and update |
+| `src/session-check.mjs` | Which chats the pinned DSH refuses because a newer DSH wrote them |
| `src/first-run.mjs` | The first start's dialogs: the two folders and the offer to import |
| `src/import.mjs` | The import of a Bot team from the user's DSH |
| `src/updates.mjs` | The Windows installer updates and macOS release-page checks |
diff --git a/app/src/first-run.mjs b/app/src/first-run.mjs
index 745efc11..7d0efb51 100644
--- a/app/src/first-run.mjs
+++ b/app/src/first-run.mjs
@@ -1,7 +1,7 @@
// The first start: where the app keeps its data and the Bots' files, and whether it copies the
// Bot team of the user's own DSH. The answers are kept in the app's own data.
import { app, dialog } from 'electron'
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
+import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { homedir } from 'node:os'
import { dirname, join } from 'node:path'
import { findTeam, newerSessions, teamInUse, userDshHome, within } from './import.mjs'
@@ -51,6 +51,12 @@ 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 })
+const locationsFile = () => join(app.getPath('userData'), 'locations.json')
+
+/** Ask for the places and the copy again at the next start, as after quitting the first start. */
+export function forgetLocations() {
+ rmSync(locationsFile(), { force: true })
+}
function pick(title, current) {
const picked = dialog.showOpenDialogSync({ title, defaultPath: existsSync(current) ? current : dirname(current), properties: ['openDirectory', 'createDirectory', 'promptToCreate'] })
@@ -108,7 +114,7 @@ function offerImport(t, dataDir) {
*/
export function chooseLocations() {
if (process.env.DS_BOT_HOME) return { dataDir: process.env.DS_BOT_HOME, workspace: process.env.DS_BOT_WORKSPACE || undefined }
- const file = join(app.getPath('userData'), 'locations.json')
+ const file = locationsFile()
if (existsSync(file)) {
const saved = JSON.parse(readFileSync(file, 'utf8'))
return { dataDir: saved.dataDir, workspace: saved.workspace }
diff --git a/app/src/host-process.mjs b/app/src/host-process.mjs
index 819462bd..18d5b3db 100644
--- a/app/src/host-process.mjs
+++ b/app/src/host-process.mjs
@@ -27,7 +27,10 @@ export class HostProcess {
*/
constructor(options) { this.#options = options }
- /** @returns {Promise<{ url: string, injections: unknown[] }>} the Host's launch URL and index injections */
+ /**
+ * @returns {Promise<{ url: string, injections: unknown[] } | { unreadable: string[] }>} the Host's launch URL
+ * and index injections; for the first-run check, the Sessions it cannot read
+ */
start() {
this.#ready ??= new Promise((resolve, reject) => {
const { entry, cwd, env, pnpm } = this.#options
@@ -44,6 +47,7 @@ export class HostProcess {
})
child.on('message', (message) => {
if (message?.type === 'ready') resolve({ url: message.url, injections: message.injections })
+ else if (message?.type === 'checked') resolve({ unreadable: message.unreadable })
else if (message?.type === 'fatal') this.#fail(new Error(message.message), reject)
})
child.once('error', (error) => { this.#fail(error, reject) })
diff --git a/app/src/host.mjs b/app/src/host.mjs
index 9d3e93da..9d5bd0ea 100644
--- a/app/src/host.mjs
+++ b/app/src/host.mjs
@@ -1,10 +1,13 @@
// The Host: the shell runs this file in Electron's Node mode. It boots the app's own `ds-bot` profile
-// on a loopback port and reports the launch URL over IPC.
+// on a loopback port and reports the launch URL over IPC. With DS_BOT_CHECK, the path of a JSON list
+// of Session ids, it boots the first-run check's profile instead and reports which of them it cannot read.
// Follows DeepSeek Harness apps/desktop-host/src/index.ts (MIT); see NOTICE.
+import { readFileSync } from 'node:fs'
import { inspect } from 'node:util'
import { loadLayeredEnv, reportSkippedBundles } from '@deepseek-ai/dsh-app-boot'
import { runProfile } from '@deepseek-ai/dsh/profile-boot'
-import { INSTALL_ANCHOR, loadAppProfile, PROFILE } from './profile.mjs'
+import { CHECK_PROFILE, INSTALL_ANCHOR, loadAppProfile, loadCheckProfile, PROFILE } from './profile.mjs'
+import { unreadableSessions } from './session-check.mjs'
const MAX_FATAL_DIAGNOSTIC_CHARS = 64 * 1024
@@ -15,11 +18,12 @@ const send = (message) => new Promise((resolve, reject) => {
async function main() {
const pnpm = process.argv[2]
- const profile = loadAppProfile()
+ const check = process.env.DS_BOT_CHECK || undefined
+ const profile = check === undefined ? loadAppProfile() : loadCheckProfile()
reportSkippedBundles('dsh', profile)
const application = runProfile({
environment: loadLayeredEnv('dsh'),
- profile: PROFILE,
+ profile: check === undefined ? PROFILE : CHECK_PROFILE,
resolvedProfile: { profile, installAnchor: INSTALL_ANCHOR },
patchFiles: [],
args: ['--no-open', '--port', '0'],
@@ -38,6 +42,12 @@ async function main() {
process.on('message', (message) => { if (message?.type === 'shutdown') void stop() })
process.once('disconnect', () => { void stop() })
const { ctx } = await application
+ if (check !== undefined) {
+ const persistence = ctx.get('sessionPersistence')
+ if (persistence === undefined) throw new Error(`The profile in ${profile.dir} does not store Sessions.`)
+ await send({ type: 'checked', unreadable: await unreadableSessions(persistence, JSON.parse(readFileSync(check, 'utf8'))) })
+ return
+ }
const [webServer, connection] = [ctx.get('webServer'), ctx.get('connection')]
// A profile patch can turn these rows off; then the window has nothing to talk to.
if (webServer === undefined || connection === undefined) throw new Error(`The profile in ${profile.dir} does not start the engine's web server and connection.`)
diff --git a/app/src/import.mjs b/app/src/import.mjs
index 1edca0c0..ee140c46 100644
--- a/app/src/import.mjs
+++ b/app/src/import.mjs
@@ -105,6 +105,17 @@ function sessionDirs(from, ids) {
return { found, missing }
}
+async function copySessionDirs(from, to, sessions) {
+ for (const { id, group } of sessions) await cp(join(from, 'sessions', group, id), join(to, 'sessions', group, id), { recursive: true })
+}
+
+/** Copy the team's Sessions into the DSH home `to`, as they lie in `from`. @returns {Promise<string[]>} their ids */
+export async function copySessions(from, team, to) {
+ const { found } = sessionDirs(from, sessionIdsOf(team))
+ await copySessionDirs(from, to, found)
+ return found.map(({ id }) => id)
+}
+
const logVersion = name => parseSessionFormatLogFilename(name.replace(/\.(zstd|zst|gz|br)$/u, ''))
/** The Sessions whose log is in a newer format than the pinned DSH reads. */
@@ -154,7 +165,7 @@ export async function importTeam({ from, to, workspace, profile, dsh }) {
team.agents = {}
await writeFile(join(stage, 'bot', 'state.json'), JSON.stringify(team, null, 2))
const { found: sessions, missing } = sessionDirs(from, sessionIdsOf(found.team))
- for (const { id, group } of sessions) await cp(join(from, 'sessions', group, id), join(stage, 'sessions', group, id), { recursive: true })
+ await copySessionDirs(from, stage, sessions)
if (existsSync(join(from, 'attachments'))) await cp(join(from, 'attachments'), join(stage, 'attachments'), { recursive: true })
await mkdir(workspace, { recursive: true })
diff --git a/app/src/main.mjs b/app/src/main.mjs
index 8becab73..810c3623 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -2,16 +2,18 @@
// The dsh-app scheme, the request forwarding and the WebSocket header rewrite follow
// DeepSeek Harness apps/desktop/src/main.ts (MIT); see NOTICE.
import { app, BrowserWindow, dialog, ipcMain, Menu, nativeTheme, protocol, session, shell } from 'electron'
-import { mkdirSync } from 'node:fs'
+import { mkdirSync, writeFileSync } from 'node:fs'
+import { rm } from 'node:fs/promises'
import { createRequire } from 'node:module'
import { dirname, join } 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 { chooseLocations, localeText, text } from './first-run.mjs'
+import { chooseLocations, forgetLocations, localeText, text } from './first-run.mjs'
import { HostProcess } from './host-process.mjs'
-import { importTeam } from './import.mjs'
+import { copySessions, findTeam, importTeam } from './import.mjs'
+import { CHECK_PROFILE, PROFILE } from './profile.mjs'
import { UPDATE_TEXT, watchReleases, watchUpdates } from './updates.mjs'
import { APP_ORIGIN, authenticateWebHost, forwardWebRequest, serveWebDocument } from './web.mjs'
@@ -65,17 +67,29 @@ function stopHost() {
function start() {
const where = chooseLocations()
if (where.quit) { app.exit(0); return }
- const profileDir = join(where.dataDir, 'profiles', 'ds-bot')
+ const pnpm = join(app.getAppPath(), 'node_modules', 'pnpm', 'bin', 'pnpm.mjs')
+ 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_APP: '1', ...(where.workspace ? { DS_BOT_WORKSPACE: where.workspace } : {}) },
- pnpm: join(app.getAppPath(), 'node_modules', 'pnpm', 'bin', 'pnpm.mjs'),
+ pnpm,
onFailure: fail,
})
+ // 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 }, pnpm, onFailure: () => {} })
+ }
const ready = (async () => {
- if (where.import) await copyTeam(where, newHost)
+ if (where.import && await copyTeam(where, newHost, newCheck) === 'quit') {
+ forgetLocations()
+ app.exit(0)
+ // The window may be waiting for the Host; it goes away with the app.
+ 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.
updates = startUpdates()
@@ -122,7 +136,16 @@ function start() {
// The Host starts once on the new data location first: DSH then sets up its project list
// without the copied Sessions' folders, so the old team's folders are not offered as projects.
-async function copyTeam(where, newHost) {
+// Before that, the app's own DSH reads every chat of the team once: a newer DSH can write
+// records that this one refuses while the log format stays the same. Such a chat stops the
+// copy, as a newer log format does; 'quit' means the user updates DeepSeek Bot first.
+async function copyTeam(where, newHost, newCheck) {
+ const unreadable = await checkTeam(where, newCheck)
+ if (unreadable > 0) {
+ const t = text()
+ const { response } = await dialog.showMessageBox({ type: 'warning', title: 'DeepSeek Bot', noLink: true, message: t.newer(unreadable), buttons: [t.quit, t.startEmpty], defaultId: 0, cancelId: 0 })
+ return response === 0 ? 'quit' : undefined
+ }
host = newHost()
try {
await host.start()
@@ -137,6 +160,34 @@ async function copyTeam(where, newHost) {
} finally {
mainWindow?.setProgressBar(-1)
}
+ return undefined
+}
+
+// A copy of the chats in a DSH home of its own, so that nothing of the check stays in the data.
+async function checkTeam(where, newCheck) {
+ const home = join(where.dataDir, `.import-check-${String(Date.now())}`)
+ try {
+ const found = findTeam(where.import.from)
+ const ids = found === undefined ? [] : await copySessions(where.import.from, found.team, home)
+ if (ids.length === 0) return 0
+ mainWindow?.setProgressBar(2)
+ const list = join(home, 'check.json')
+ writeFileSync(list, JSON.stringify(ids))
+ const check = newCheck(home, list)
+ try {
+ const { unreadable } = await check.start()
+ if (unreadable.length > 0) console.warn(`DeepSeek Bot: this DSH cannot read ${unreadable.join(', ')}`)
+ return unreadable.length
+ } finally {
+ await check.stop()
+ }
+ } catch (error) {
+ console.error('DeepSeek Bot: the chats were not checked before the copy:', error)
+ return 0
+ } finally {
+ mainWindow?.setProgressBar(-1)
+ await rm(home, { recursive: true, force: true, maxRetries: 5 }).catch((error) => { console.error(error) })
+ }
}
// Windows updates itself; macOS asks to download the new version. Throwaway runs check only a
diff --git a/app/src/profile.mjs b/app/src/profile.mjs
index d7f04110..846a6b3e 100644
--- a/app/src/profile.mjs
+++ b/app/src/profile.mjs
@@ -5,6 +5,10 @@ import { initProfile, loadProfileDirectory, readProfileManifest, resolveProfileD
export const PROFILE = 'ds-bot'
// DSH's shared core, DSH's web front end (the window), then the Bot team. Bundles the user installs follow.
export const BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', 'ds-bot']
+// The first-run check reads a copy of the team's chats without the Bot team running on them.
+// DSH reads a log the same way whatever the profile mounts.
+export const CHECK_PROFILE = 'import-check'
+export const CHECK_BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']
// Bundles that earlier builds of the app put in its profile: the engine layer of its own window (../engine).
const RETIRED_BUNDLES = ['deepseek-bot-engine']
// The app's own manifest is the installation: DSH imports plugins only from the installation's dependency
@@ -32,8 +36,19 @@ export function loadAppProfile() {
const dir = resolveProfileDir(PROFILE)
initProfile(dir, BUNDLES)
claimBundles(dir)
+ return loadOwnBundles(dir, BUNDLES)
+}
+
+/** The profile of the first-run check, under the current DSH_HOME. */
+export function loadCheckProfile() {
+ const dir = resolveProfileDir(CHECK_PROFILE)
+ initProfile(dir, CHECK_BUNDLES)
+ return loadOwnBundles(dir, CHECK_BUNDLES)
+}
+
+function loadOwnBundles(dir, bundles) {
const profile = loadProfileDirectory('dsh', dir, INSTALL_ANCHOR)
- const lost = profile.skippedBundles.filter(({ packageName }) => BUNDLES.includes(packageName))
+ const lost = profile.skippedBundles.filter(({ packageName }) => bundles.includes(packageName))
if (lost.length > 0) throw new Error(`The app could not load its own bundles:\n${lost.map(({ packageName, reason }) => `${packageName}: ${reason}`).join('\n')}`)
return profile
}
diff --git a/app/src/session-check.mjs b/app/src/session-check.mjs
new file mode 100644
index 00000000..395b104c
--- /dev/null
+++ b/app/src/session-check.mjs
@@ -0,0 +1,26 @@
+// The first-run import reads every chat of the team once, with the app's own DSH, before it copies it.
+
+/**
+ * The Sessions that this DSH refuses to read because a newer DSH wrote them. A damaged log is
+ * not one of them: the user's own DSH cannot read it either, so it does not stop the import.
+ * @param {{ open: (id: string, access: 'read') => Promise<{ read: () => Promise<unknown>, close: () => Promise<void> }> }} persistence
+ * @param {string[]} ids
+ * @returns {Promise<string[]>}
+ */
+export async function unreadableSessions(persistence, ids) {
+ const unreadable = []
+ for (const id of ids) {
+ try {
+ const handle = await persistence.open(id, 'read')
+ try {
+ await handle.read()
+ } finally {
+ await handle.close()
+ }
+ } catch (error) {
+ if (error?.name === 'SessionFormatUnsupportedError') unreadable.push(id)
+ else console.warn(`DeepSeek Bot: could not read ${id} while checking the team: ${error instanceof Error ? error.message : String(error)}`)
+ }
+ }
+ return unreadable
+}
diff --git a/app/test/import.test.mjs b/app/test/import.test.mjs
index 70c49093..5d841fad 100644
--- a/app/test/import.test.mjs
+++ b/app/test/import.test.mjs
@@ -6,7 +6,7 @@ import { homedir, tmpdir } from 'node:os'
import { dirname, join, relative } from 'node:path'
import { after, before, describe, test } from 'node:test'
import { parse } from 'yaml'
-import { findTeam, importTeam, newerSessions, sessionIdsOf, teamInUse, userDshHome } from '../src/import.mjs'
+import { copySessions, findTeam, importTeam, newerSessions, sessionIdsOf, teamInUse, userDshHome } from '../src/import.mjs'
const write = (path, text) => {
mkdirSync(dirname(path), { recursive: true })
@@ -157,6 +157,16 @@ describe('finding the team', () => {
assert.deepEqual(sessionIdsOf(TEAM), ['session-a', 'session-a2', 'session-b', 'session-g', 'session-gone', 'session-g0'])
})
+ test('copies only the Sessions of the team for the check, and changes nothing in the old home', async () => {
+ const oldTree = treeHash(from)
+ const home = join(root, 'check')
+ const ids = await copySessions(from, TEAM, home)
+ assert.deepEqual(ids.toSorted(), TEAM_SESSIONS.map(([, id]) => id).toSorted())
+ for (const [group, id] of TEAM_SESSIONS) assert.equal(readFileSync(join(home, 'sessions', group, id, 'session.v4.jsonl.zstd'), 'utf8'), id)
+ assert.equal(existsSync(join(home, 'sessions', '--team--', 'session-other')), false)
+ assert.equal(treeHash(from), oldTree)
+ })
+
test('finds Sessions written in a newer format than the pinned DSH reads', () => {
assert.deepEqual(newerSessions(from, TEAM), [])
write(join(from, 'sessions', '--site--', 'session-b', 'session.v99.jsonl.zstd'), 'newer')
diff --git a/app/test/session-check.test.mjs b/app/test/session-check.test.mjs
new file mode 100644
index 00000000..cfca91b9
--- /dev/null
+++ b/app/test/session-check.test.mjs
@@ -0,0 +1,70 @@
+import assert from 'node:assert/strict'
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { dirname, join } from 'node:path'
+import { after, before, describe, test } from 'node:test'
+import { fileURLToPath } from 'node:url'
+import { zstdCompressSync } from 'node:zlib'
+import { HostProcess } from '../src/host-process.mjs'
+import { CHECK_PROFILE } from '../src/profile.mjs'
+import { unreadableSessions } from '../src/session-check.mjs'
+
+const named = (name, message) => Object.assign(new Error(message), { name })
+
+describe('unreadableSessions', () => {
+ test('names only the Sessions that a newer DSH wrote, and closes every handle it opens', async () => {
+ const closed = []
+ const failures = {
+ newer: named('SessionFormatUnsupportedError', 'unknown to this harness'),
+ damaged: named('SessionPersistenceCorruptionError', 'damaged frame'),
+ }
+ const persistence = {
+ open: async (id, access) => {
+ assert.equal(access, 'read')
+ if (id === 'gone') throw named('SessionPersistenceNotFoundError', 'no such Session')
+ return {
+ read: async () => { if (failures[id]) throw failures[id] },
+ close: async () => { closed.push(id) },
+ }
+ },
+ }
+ assert.deepEqual(await unreadableSessions(persistence, ['fine', 'newer', 'damaged', 'gone']), ['newer'])
+ assert.deepEqual(closed, ['fine', 'newer', 'damaged'])
+ })
+})
+
+// The first-run check's own Host on two Sessions in its log format: one that it reads, and
+// one with a required record that it does not know.
+describe('the first-run check', () => {
+ let home, unreadable
+ before(async () => {
+ home = mkdtempSync(join(tmpdir(), 'ds-bot-app-check-'))
+ const log = (id, events) => {
+ const header = { type: 'session', version: 4, id, createdAt: Date.now(), isSeeded: false, delegationDepth: 0, agentPreset: 'standard' }
+ const file = join(home, 'sessions', '_no-cwd', id, 'session.v4.jsonl.zstd')
+ mkdirSync(dirname(file), { recursive: true })
+ writeFileSync(file, Buffer.concat([header, ...events].map(row => zstdCompressSync(Buffer.from(`${JSON.stringify(row)}\n`)))))
+ }
+ log('session-known', [])
+ log('session-newer', [{ type: 'future/feature', seq: 0, time: Date.now(), data: {} }])
+ const list = join(home, 'check.json')
+ writeFileSync(list, JSON.stringify(['session-known', 'session-newer']))
+ const cwd = join(home, 'profiles', CHECK_PROFILE)
+ mkdirSync(cwd, { recursive: true })
+ const app = dirname(dirname(fileURLToPath(import.meta.url)))
+ const check = new HostProcess({
+ entry: join(app, 'src', 'host.mjs'), cwd, env: { ...process.env, DSH_HOME: home, DS_BOT_CHECK: list },
+ pnpm: join(app, 'node_modules', 'pnpm', 'bin', 'pnpm.mjs'), onFailure: () => {},
+ })
+ try {
+ ({ unreadable } = await check.start())
+ } finally {
+ await check.stop()
+ }
+ }, { timeout: 180_000 })
+ after(() => { rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })
+
+ test('reports the Session with a record that this DSH does not know', () => {
+ assert.deepEqual(unreadable, ['session-newer'])
+ })
+})