Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/goxf-portable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ name: GOXF Portable
# only the newest 5 dev prereleases (and tags) are kept
# manual dispatch → run artifact only
# Assets per release (read by src/main/goxfUpdater.ts):
# BotArk-Portable-<v>-win-x64.zip full program folder (+ empty BotArk-Data)
# manifest-BotArk-Portable-<v>-win-x64.json every program file: path, sha256, size (BotArk-Data excluded)
# BotArk-Portable-<v>-win-x64.zip full program folder (+ .botark-portable marker)
# manifest-BotArk-Portable-<v>-win-x64.json every program file: path, sha256, size (BotArkData excluded)
# patch-BotArk-Portable-<v>-win-x64.zip the whole resources/ folder; applied file-by-file when the
# runtime (everything outside resources/) matches the manifest
# *Portable*.exe single-exe build
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
env:
CSC_IDENTITY_AUTO_DISCOVERY: 'false'
run: npx electron-builder --config electron-builder.config.cjs --win portable dir --x64 --publish never
- name: Zip the unpacked folder (BotArk-Data inside marks it portable) + delta manifest and patch
- name: Zip the unpacked folder (.botark-portable marks it portable) + delta manifest and patch
shell: pwsh
run: |
$ver = $env:GOXF_TAG.Substring(1)
Expand All @@ -146,8 +146,9 @@ jobs:
Compress-Archive -Path release/win-unpacked/resources -DestinationPath "release/patch-$name.zip"
$root = Join-Path $env:RUNNER_TEMP $name
Copy-Item -Recurse release/win-unpacked $root
New-Item -ItemType Directory -Path (Join-Path $root 'BotArk-Data') | Out-Null
Set-Content -Encoding utf8 -Path (Join-Path $root 'BotArk-Data/README.txt') -Value 'BotArk portable data folder. Keep it next to BotArk.exe; copy the whole folder to move BotArk with your accounts.'
# Upstream's marker: data goes to BotArkData next to BotArk.exe (created on first start).
# No empty BotArkData folder: an update from an old build must not shadow its BotArk-Data.
Set-Content -Encoding utf8 -Path (Join-Path $root '.botark-portable') -Value 'BotArk portable: data lives in BotArkData next to BotArk.exe. Copy the whole folder to move BotArk with your accounts.'
Compress-Archive -Path $root -DestinationPath "release/$name.zip"
- name: Publish fork release
if: github.event_name == 'push'
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## 机器与身份
- 云电脑:写代码、跑门槛、开 PR。
- 一台本地 Windows 机器,身份 = 开发:只做真机事项(运行、zip 便携版自更新 BotArk-Data\update.log、perf.log、真实账号登录)。路径、通道见服务器。测试包解压到单独目录,用它自己的 BotArk-Data;命令用绝对路径。
- 一台本地 Windows 机器,身份 = 开发:只做真机事项(运行、zip 便携版自更新 BotArkData\update.log、perf.log、真实账号登录)。路径、通道见服务器。测试包解压到单独目录,用它自己的 BotArkData;命令用绝对路径。

## 发版
见 skills/release:合并即出测试版并报版本号;正式版先升 goxfBuild、打 tag,要用户同意。
Expand All @@ -24,7 +24,7 @@
设计规范 docs/goxf-design.md。界面改动先出效果图(skills/ui-mock),用户说「开工」才写代码。

## 红线
- 不碰用户自己在用的 BotArk 和它的 BotArk-Data;不动用户已开的窗口,不碰桌面 1。
- 不碰用户自己在用的 BotArk 和它的 BotArkData(旧版叫 BotArk-Data);不动用户已开的窗口,不碰桌面 1。
- 不用用户的真实账号替他发消息、开项目,测试前先问。
- 服务器只读取,改动要用户同意。
- 例外(用户 2026-11-28 定):服务器地址和 root 账号名可以出现在本公开仓库;令牌、密码、真实数据仍不进仓库。
Expand Down
2 changes: 1 addition & 1 deletion electron-builder.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = {
artifactName: '${productName}-${version}-${arch}.${ext}'
},
win: {
// GOXF fork: + portable (data lives in <exe dir>/BotArk-Data, see src/main/goxfPortable.ts).
// GOXF fork: + portable (data lives in <exe dir>/BotArkData, see src/main/goxfPortable.ts).
target: [
{ target: 'nsis', arch: ['x64'] },
{ target: 'portable', arch: ['x64'] }
Expand Down
6 changes: 6 additions & 0 deletions handoff/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@

## 2026-11-29 采用通用对接规范
- 规则进 AGENTS.md,交接拆成 state / decisions / log,项目技能进 skills/,私密信息和机器身份放服务器 /root/ops/projects/botark.md。理由:任何 AI 只发开场白就能接手,内容不丢、不乱。

## 2026-11-30 便携版改用上游实现
- 数据目录判定用上游 `portableDataDir.ts`(`--user-data-dir` / `BotArkData` / `.botark-portable`),`goxfPortable.ts` 只做薄壳并仍是第一个 import,额外锁 sessionData。
- 旧 `BotArk-Data` 启动时原地改名为 `BotArkData`(新目录不存在或只有 README 才改;两边都有数据则不动、用新的;改名失败则本次直接用旧目录)。理由:用户要跟上游,数据不能丢。
- 自用更新器、zip 文件夹版、增量补丁、goxf 产物名保留;过渡期更新器两个名字都当数据目录保留。zip 包改放 `.botark-portable` 标记,不再带空数据文件夹(防止旧版更新时空文件夹挡住旧数据)。
- 退回 v0.17.1-goxf 及更早:先退出,把 `BotArkData` 改回 `BotArk-Data`(目录里有说明文件)。
4 changes: 2 additions & 2 deletions scripts/goxf-manifest.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
// GOXF fork: delta-update manifest for the portable folder (read by src/main/goxfUpdater.ts).
// Usage: node scripts/goxf-manifest.mjs <programDir> <version> <out.json>
// Lists every file under programDir except BotArk-Data: { path (forward slashes), sha256, size }.
// Lists every file under programDir except the data folder (BotArkData, old BotArk-Data): { path (forward slashes), sha256, size }.
import { createHash } from 'node:crypto'
import { createReadStream, readdirSync, statSync, writeFileSync } from 'node:fs'
import { join, relative, sep } from 'node:path'
Expand All @@ -26,7 +26,7 @@ for (const entry of readdirSync(dir, { recursive: true, withFileTypes: true }))
if (!entry.isFile()) continue
const full = join(entry.parentPath ?? entry.path, entry.name)
const path = relative(dir, full).split(sep).join('/')
if (path === 'BotArk-Data' || path.startsWith('BotArk-Data/')) continue
if (/^(BotArkData|BotArk-Data)(\/|$)/.test(path)) continue
files.push({ path, sha256: await sha256(full), size: statSync(full).size })
}
if (files.length === 0) throw new Error(`no files under ${dir}`)
Expand Down
2 changes: 1 addition & 1 deletion src/main/goxfMihomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* GOXF fork: the user-installed Mihomo kernel and its processes.
*
* - Kernel: pinned official asset (goxfMihomoAssets), SHA-256 checked, unpacked
* into userData/mihomo/bin (portable: BotArk-Data). Never on PATH, never
* into userData/mihomo/bin (portable: BotArkData). Never on PATH, never
* downloaded without the user pressing a button.
* - Processes: one per Mihomo-served pool entry, loopback mixed inbound with
* random credentials, loopback controller with a random secret. The config goes
Expand Down
2 changes: 1 addition & 1 deletion src/main/goxfPerf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* GOXF fork only: startup time + memory log for portable builds.
* Writes to <BotArk-Data>/perf.log so a real Windows run gives numbers
* Writes to <BotArkData>/perf.log so a real Windows run gives numbers
* before we optimize memory or speed. No-op outside portable mode.
*/
import { appendFileSync, statSync, renameSync } from 'node:fs'
Expand Down
77 changes: 46 additions & 31 deletions src/main/goxfPortable.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
/**
* GOXF fork only: portable mode.
* GOXF fork: portable mode, on upstream's resolver (src/main/portableDataDir.ts).
*
* electron-builder's portable launcher extracts the app to a temp dir and sets
* PORTABLE_EXECUTABLE_DIR = folder holding the portable .exe
* PORTABLE_EXECUTABLE_FILE = full path of the portable .exe
* When present, keep all data (accounts, sessions, persist: partitions) in
* <exe dir>/BotArk-Data so it travels with the exe.
* Upstream picks the data folder: --user-data-dir, then <exe dir>/BotArkData for
* electron-builder's portable exe (PORTABLE_EXECUTABLE_DIR), then a BotArkData
* folder or .botark-portable marker next to BotArk.exe (zip build), then the
* legacy bothub folder, else the default. Before that, an old fork BotArk-Data
* folder is renamed to BotArkData (goxfPortableMigrate.ts).
*
* Imported FIRST in src/main/index.ts so it runs before any module touches
* userData and before app ready (setPath after ready does not move sessions).
*/
import { existsSync, mkdirSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { dirname } from 'node:path'
import { app } from 'electron'
import { resolveUserDataDir } from './portableDataDir'
import { migrateLegacyPortableDir, type PortableMigration } from './goxfPortableMigrate'

const DATA_DIR_NAME = 'BotArk-Data'

/**
* Zip build (unpacked folder): no launcher env, so a `BotArk-Data` folder
* shipped next to BotArk.exe is the portable marker.
*/
function zipPortableDir(): string | null {
if (!app.isPackaged) return null
const dir = dirname(process.execPath)
return existsSync(join(dir, DATA_DIR_NAME)) ? dir : null
function programDir(): string | null {
const launcherDir = (process.env.PORTABLE_EXECUTABLE_DIR || '').trim()
if (launcherDir) return launcherDir
return app.isPackaged && process.platform !== 'darwin' ? dirname(app.getPath('exe')) : null
}

export const PORTABLE_DIR = (process.env.PORTABLE_EXECUTABLE_DIR || '').trim() || zipPortableDir()
const anchor = programDir()
export const PORTABLE_MIGRATION: PortableMigration = anchor ? migrateLegacyPortableDir(anchor) : { kind: 'none' }

// Unit tests import this module with a stubbed electron; there is nothing to resolve then.
const hasElectronApp = typeof app?.getPath === 'function'
const resolution = !hasElectronApp
? { source: 'default' as const, dir: '', warning: undefined }
: PORTABLE_MIGRATION.kind === 'failed'
? { source: 'portable' as const, dir: PORTABLE_MIGRATION.legacy, warning: undefined }
: resolveUserDataDir({
argv: process.argv,
env: process.env,
platform: process.platform,
execPath: process.execPath,
exePath: app.getPath('exe'),
appDataPath: app.getPath('appData'),
defaultUserDataPath: app.getPath('userData')
})
if (resolution.warning) console.warn(resolution.warning)
if (PORTABLE_MIGRATION.kind !== 'none') console.warn('[goxf] portable data folder:', JSON.stringify(PORTABLE_MIGRATION))

/** Where accounts, sessions and the goxf logs live in a portable build; null otherwise. */
export const PORTABLE_DATA_DIR = resolution.source === 'portable' ? resolution.dir : null
/** Program folder the self-updater replaces (Windows portable builds only). */
export const PORTABLE_DIR = PORTABLE_DATA_DIR && process.platform === 'win32' ? dirname(PORTABLE_DATA_DIR) : null
/** Only set for the single-exe build; the zip build cannot self-replace. */
export const PORTABLE_FILE = (process.env.PORTABLE_EXECUTABLE_FILE || '').trim() || null
export const PORTABLE_DATA_DIR = PORTABLE_DIR ? join(PORTABLE_DIR, DATA_DIR_NAME) : null

export function isPortable(): boolean {
return PORTABLE_DIR !== null
return PORTABLE_DATA_DIR !== null
}

if (PORTABLE_DATA_DIR) {
try {
mkdirSync(PORTABLE_DATA_DIR, { recursive: true })
app.setPath('userData', PORTABLE_DATA_DIR)
// Session data (cookies, IndexedDB, Partitions/<persist:name>) defaults to
// userData; pin it explicitly so every persist: partition lands here too.
app.setPath('sessionData', PORTABLE_DATA_DIR)
} catch (error) {
console.error('[goxf] portable data dir unavailable, using default userData:', error)
}
if (hasElectronApp) try {
app.setPath('userData', resolution.dir)
// Session data (cookies, IndexedDB, Partitions/<persist:name>) defaults to
// userData; pin it explicitly so every persist: partition lands here too.
app.setPath('sessionData', resolution.dir)
} catch (error) {
console.error('[goxf] could not set the data folder, using default userData:', error)
}
64 changes: 64 additions & 0 deletions src/main/goxfPortableMigrate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync, existsSync, readFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { migrateLegacyPortableDir, RENAMED_NOTE } from './goxfPortableMigrate'

const dirs: string[] = []
const program = () => {
const dir = mkdtempSync(join(tmpdir(), 'goxf-migrate-'))
dirs.push(dir)
return dir
}
afterEach(() => {
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true })
})

const seed = (dir: string, file = 'accounts.json') => {
mkdirSync(join(dir, 'Partitions'), { recursive: true })
writeFileSync(join(dir, file), '{"a":1}')
}

describe('migrateLegacyPortableDir', () => {
it('does nothing without an old BotArk-Data', () => {
const root = program()
expect(migrateLegacyPortableDir(root)).toEqual({ kind: 'none' })
expect(readdirSync(root)).toEqual([])
})

it('renames BotArk-Data to BotArkData and leaves a note', () => {
const root = program()
seed(join(root, 'BotArk-Data'))
expect(migrateLegacyPortableDir(root)).toMatchObject({ kind: 'renamed' })
expect(existsSync(join(root, 'BotArk-Data'))).toBe(false)
expect(readFileSync(join(root, 'BotArkData', 'accounts.json'), 'utf8')).toBe('{"a":1}')
expect(existsSync(join(root, 'BotArkData', 'Partitions'))).toBe(true)
expect(existsSync(join(root, 'BotArkData', RENAMED_NOTE))).toBe(true)
})

it('replaces an empty BotArkData (or one with only a README)', () => {
const root = program()
seed(join(root, 'BotArk-Data'))
mkdirSync(join(root, 'BotArkData'))
writeFileSync(join(root, 'BotArkData', 'README.txt'), 'x')
expect(migrateLegacyPortableDir(root)).toMatchObject({ kind: 'renamed' })
expect(existsSync(join(root, 'BotArkData', 'accounts.json'))).toBe(true)
expect(existsSync(join(root, 'BotArkData', 'README.txt'))).toBe(false)
})

it('leaves both alone when both hold data', () => {
const root = program()
seed(join(root, 'BotArk-Data'))
seed(join(root, 'BotArkData'), 'other.json')
expect(migrateLegacyPortableDir(root)).toMatchObject({ kind: 'both' })
expect(existsSync(join(root, 'BotArk-Data', 'accounts.json'))).toBe(true)
expect(existsSync(join(root, 'BotArkData', 'other.json'))).toBe(true)
})

it('is a no-op on the second start', () => {
const root = program()
seed(join(root, 'BotArk-Data'))
migrateLegacyPortableDir(root)
expect(migrateLegacyPortableDir(root)).toEqual({ kind: 'none' })
})
})
66 changes: 66 additions & 0 deletions src/main/goxfPortableMigrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* GOXF fork only: one-time move of the old portable data folder to upstream's name.
*
* Fork builds up to v0.17.1-goxf kept portable data in <program dir>/BotArk-Data;
* upstream (v0.18.0, src/main/portableDataDir.ts) uses <program dir>/BotArkData.
* Runs before upstream's resolver so it finds the data under the new name.
* Rename only (same folder, no copy). Rolling back to an old fork build means
* renaming the folder back; RENAMED_NOTE inside says so.
*/
import { existsSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'

export const LEGACY_DATA_DIRNAME = 'BotArk-Data'
export const DATA_DIRNAME = 'BotArkData'
export const RENAMED_NOTE = '从 BotArk-Data 改名而来.txt'

export type PortableMigration =
| { kind: 'none' }
| { kind: 'renamed'; from: string; to: string }
/** Both folders hold data: nothing moved, the new one is used. */
| { kind: 'both'; legacy: string; current: string }
/** The rename failed (e.g. files in use); this run uses the old folder as is. */
| { kind: 'failed'; legacy: string; error: string }

const isDir = (p: string) => {
try {
return statSync(p).isDirectory()
} catch {
return false
}
}

/** Empty, or only what a package ships in it (a README). */
function isEmptyDataDir(dir: string): boolean {
try {
return readdirSync(dir).every((name) => /^readme(\.txt|\.md)?$/i.test(name))
} catch {
return false
}
}

export function migrateLegacyPortableDir(programDir: string): PortableMigration {
const legacy = join(programDir, LEGACY_DATA_DIRNAME)
if (!isDir(legacy)) return { kind: 'none' }
const current = join(programDir, DATA_DIRNAME)
if (existsSync(current)) {
if (!isDir(current) || !isEmptyDataDir(current)) return { kind: 'both', legacy, current }
}
try {
// An empty BotArkData (e.g. brought by a package) gives way to the real data.
if (existsSync(current)) rmSync(current, { recursive: true, force: true })
renameSync(legacy, current)
} catch (error) {
return { kind: 'failed', legacy, error: error instanceof Error ? error.message : String(error) }
}
try {
writeFileSync(
join(current, RENAMED_NOTE),
`${new Date().toISOString()} BotArk 把数据文件夹 BotArk-Data 改名为 BotArkData(跟随上游便携版)。\r\n` +
'如需退回 v0.17.1-goxf 及更早版本,先退出 BotArk,再把本文件夹改回 BotArk-Data。\r\n'
)
} catch {
/* the note is optional */
}
return { kind: 'renamed', from: legacy, to: current }
}
2 changes: 1 addition & 1 deletion src/main/goxfSessionCookieLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { accountPartitionName, sessionOnly, toSetDetails } from './goxfSessionCo

describe('accountPartitionName', () => {
it('accepts account partitions by storage path or bare name', () => {
expect(accountPartitionName('C:\\BotArk-Data\\Partitions\\bothub-account-acc_1'.replace(/\\/g, '/'))).toBe('bothub-account-acc_1')
expect(accountPartitionName('C:\\BotArkData\\Partitions\\bothub-account-acc_1'.replace(/\\/g, '/'))).toBe('bothub-account-acc_1')
expect(accountPartitionName('bothub-account-x-2')).toBe('bothub-account-x-2')
})
it('skips other partitions and the default session', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/main/goxfUpdateHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HELPER_SOURCE, type HelperJob } from './goxfUpdateHelper'
function setup(): { root: string; app: string; data: string; job: Omit<HelperJob, 'mode'> } {
const root = mkdtempSync(join(tmpdir(), 'botark-helper-'))
const app = join(root, 'BotArk')
const data = join(app, 'BotArk-Data')
const data = join(app, 'BotArkData')
mkdirSync(join(app, 'resources'), { recursive: true })
mkdirSync(data)
writeFileSync(join(app, 'BotArk.exe'), 'old exe')
Expand All @@ -30,7 +30,7 @@ function setup(): { root: string; app: string; data: string; job: Omit<HelperJob
zipFile: join(app, '.botark-update.zip'),
stageDir: join(app, '.botark-update-stage'),
backupDir: join(app, '.botark-update-old'),
keep: ['BotArk-Data', '.botark-update-stage', '.botark-update-old', '.botark-update.zip']
keep: ['BotArkData', 'BotArk-Data', '.botark-update-stage', '.botark-update-old', '.botark-update.zip']
}
}
}
Expand All @@ -45,7 +45,7 @@ function run(root: string, job: HelperJob): string {
}

describe('update helper', () => {
it('full: replaces the app, keeps BotArk-Data, writes ready, drops the lock and zip', () => {
it('full: replaces the app, keeps BotArkData, writes ready, drops the lock and zip', () => {
const { root, app, data, job } = setup()
const src = join(job.stageDir, 'BotArk')
mkdirSync(join(src, 'resources'), { recursive: true })
Expand Down
Loading
Loading