A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Relaunch a packaged app on its canonical exe path
Fei2411221de53b5eca
diff --git a/app/scripts/check-packed.mjs b/app/scripts/check-packed.mjsindex 96f96d78..a0ecfc4a 100644--- a/app/scripts/check-packed.mjs+++ b/app/scripts/check-packed.mjs@@ -4,7 +4,7 @@// Usage: node scripts/check-packed.mjs [app executable] [screenshot.png]// The executable defaults to the one that `npm run pack` or `npm run dist` writes into dist-pack/.import { spawn, spawnSync } from 'node:child_process'-import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'import { setTimeout as sleep } from 'node:timers/promises'@@ -26,7 +26,7 @@ if (!existsSync(executable)) {process.exit(2)}-const work = mkdtempSync(join(tmpdir(), 'ds-bot-packed-'))+const work = realpathSync.native(mkdtempSync(join(realpathSync.native(tmpdir()), 'ds-bot-packed-')))mkdirSync(join(work, 'home'))const children = []diff --git a/app/src/canonical-path.mjs b/app/src/canonical-path.mjsnew file mode 100644index 00000000..e12bcb6c--- /dev/null+++ b/app/src/canonical-path.mjs@@ -0,0 +1,15 @@+import { realpathSync } from 'node:fs'++// The path Windows hands the packaged app can carry 8.3 short names or junctions: the+// same exe then reads as a different path, so the single-instance lock compares unlike+// strings and every absolute path the Host builds (profile includes, plugin roots) mixes+// short and long forms. Callers relaunch on the returned path; undefined means execPath+// is already canonical (or cannot be resolved).+export function canonicalExecPath(execPath, realpath = realpathSync.native) {+ try {+ const real = realpath(execPath)+ return real === execPath ? undefined : real+ } catch {+ return undefined+ }+}diff --git a/app/src/main.mjs b/app/src/main.mjsindex b08aff3f..3f09ffd1 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -10,6 +10,7 @@ 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 { canonicalExecPath } from './canonical-path.mjs'import { chooseLocations, localeText, programFolder, saveLocations, text } from './first-run.mjs'import { hostPort } from './host-port.mjs'import { HostProcess } from './host-process.mjs'@@ -51,7 +52,14 @@ let choosinglet copyingconst copyAbort = new AbortController()-if (!app.requestSingleInstanceLock()) {+// A packaged app started through an 8.3 short path or a junction restarts once on the+// canonical path: the lock below and every path the Host sees then agree with the long+// form, and the profile patch layer stops mixing the two.+const canonical = app.isPackaged ? canonicalExecPath(process.execPath) : undefined+if (canonical !== undefined) {+ app.relaunch({ execPath: canonical, args: process.argv.slice(1) })+ app.exit(0)+} else if (!app.requestSingleInstanceLock()) {app.exit(0)} else {app.on('second-instance', focusWindow)diff --git a/app/test/canonical-path.test.mjs b/app/test/canonical-path.test.mjsnew file mode 100644index 00000000..846b4dfc--- /dev/null+++ b/app/test/canonical-path.test.mjs@@ -0,0 +1,20 @@+import assert from 'node:assert/strict'+import { realpathSync } from 'node:fs'+import { test } from 'node:test'+import { canonicalExecPath } from '../src/canonical-path.mjs'++test('an already-canonical path needs no relaunch', () => {+ assert.equal(canonicalExecPath('C:\\App\\bot.exe', () => 'C:\\App\\bot.exe'), undefined)+})++test('a short or linked path returns the canonical one', () => {+ assert.equal(canonicalExecPath('C:\\APPS~1\\bot.exe', () => 'C:\\App Data\\bot.exe'), 'C:\\App Data\\bot.exe')+})++test('a path that cannot be resolved keeps the caller going', () => {+ assert.equal(canonicalExecPath('X:\\gone\\bot.exe', () => { throw new Error('ENOENT') }), undefined)+})++test('the default realpath leaves the running exe alone', () => {+ assert.ok(canonicalExecPath(process.execPath) === undefined || canonicalExecPath(process.execPath) === realpathSync.native(process.execPath))+})