A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Map a link into the old data through another link into the copy
Fei2411f7ed7bef8bde
diff --git a/app/src/move-data.mjs b/app/src/move-data.mjsindex 3b7d7069..427a8188 100644--- a/app/src/move-data.mjs+++ b/app/src/move-data.mjs@@ -2,7 +2,7 @@// one and takes its name only once it is whole, so a copy that stopped or failed leaves nothing// that looks like data. The old folder stays as it was.import { existsSync, readdirSync, realpathSync, statSync } from 'node:fs'-import { cp, lstat, mkdir, readlink, rename, rm, rmdir, stat, symlink, writeFile } from 'node:fs/promises'+import { cp, lstat, mkdir, readlink, realpath, rename, rm, rmdir, stat, symlink, writeFile } from 'node:fs/promises'import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'import { within } from './import.mjs'@@ -52,11 +52,14 @@ const escaped = text => text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')// junctions, which hold absolute paths, without special rights.async function relink(source, path, roots, to) {const text = (await readlink(source)).replace(/^\\\\\?\\/u, '')- const target = resolve(dirname(source), text)+ const written = resolve(dirname(source), text)+ // Through another link the target can lead inside the old folder too.+ const physical = await realpath(written).catch(() => written)+ const target = roots.some(folder => within(written, folder)) ? written : physicalconst root = roots.find(folder => within(target, folder))const folder = (await stat(source).catch(() => undefined))?.isDirectory() === trueconst windows = process.platform === 'win32'- const inside = root === undefined ? target : join(to, relative(root, target))+ const inside = root === undefined ? written : join(to, relative(root, target))await symlink(root !== undefined && !isAbsolute(text) && !(windows && folder) ? text : inside, path, folder ? (windows ? 'junction' : 'dir') : 'file')}diff --git a/app/test/move-data.test.mjs b/app/test/move-data.test.mjsindex 19e8395a..f5b42b24 100644--- a/app/test/move-data.test.mjs+++ b/app/test/move-data.test.mjs@@ -114,6 +114,9 @@ test('links in the data lead inside the copy, not back into the old folder', asysymlinkSync(join(from, 'sessions'), join(from, 'bot', 'absolute'), folderLink)write(join(root, 'elsewhere', 'file.txt'), 'x')symlinkSync(join(root, 'elsewhere'), join(from, 'bot', 'outside'), folderLink)+ // Into the data through another link.+ symlinkSync(from, join(root, 'data-alias'), folderLink)+ symlinkSync(join(root, 'data-alias', 'sessions'), join(from, 'bot', 'chained'), folderLink)if (process.platform !== 'win32') {symlinkSync(join('..', 'sessions'), join(from, 'bot', 'relative'), 'dir')symlinkSync(join('..', '..', 'elsewhere'), join(from, 'bot', 'relative-outside'), 'dir')@@ -124,6 +127,7 @@ test('links in the data lead inside the copy, not back into the old folder', asyconst target = name => readlinkSync(join(to, 'bot', name)).replace(/^\\\\\?\\/u, '').replace(/[\\/]+$/u, '')assert.equal(target('absolute'), join(to, 'sessions'))assert.equal(target('outside'), join(root, 'elsewhere'))+ assert.equal(target('chained'), join(to, 'sessions'))if (process.platform !== 'win32') {assert.equal(target('relative'), join('..', 'sessions'))assert.equal(target('relative-outside'), join(root, 'elsewhere'))