dsh-agy-link 0.6.8 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.9 (2026-11-09)
4
+
5
+ ### English
6
+
7
+ - **Fix(pool): `pool.json` can no longer be torn by two writers, and a corrupt file recovers from a last-good snapshot instead of emptying the pool (issue #90).**
8
+ - Persists used a single fixed `.pool.json.tmp`, so two host processes writing at once could overwrite/truncate each other and leave a half-written file that `load()` could only discard — the UI then showed an empty account pool. Writes now go through a tmp name unique per writer (pid + random), a JSON round-trip validation, and `rename` with retries.
9
+ - Every successful persist also refreshes `pool.json.last-good`. If the primary file is unparsable, `load()` keeps the forensic `pool.json.corrupt-<ts>` copy **and** restores the last-good snapshot (`recoveredFromLastGood` is observable for diagnostics) before falling back to defaults.
10
+
11
+ ### 中文
12
+
13
+ - **修复(pool):两个写者同时持久化不再撕裂 `pool.json`,损坏时会从 last-good 快照恢复而不是把账号池清空(issue #90)。**
14
+ - 持久化过去固定用 `.pool.json.tmp`,两个宿主进程同时写会互相覆盖/截断,留下半截文件,`load()` 只能丢弃——UI 表现为「账号全没了」。现在写入改为**每写者唯一**的 tmp 名(pid + 随机)、写后 JSON 往返校验、`rename` 重试。
15
+ - 每次成功持久化同时刷新 `pool.json.last-good`;主文件无法解析时,`load()` 先保留 `pool.json.corrupt-<ts>` 取证副本,**再**恢复 last-good 快照(`recoveredFromLastGood` 可供诊断),两者都失败才回落默认池。
16
+
17
+ **Full Changelog**: https://github.com/amlyczz/dsh-agy-link/compare/v0.6.8...v0.6.9
18
+
3
19
  ## 0.6.8 (2026-11-08)
4
20
 
5
21
  ### English
package/dist/index.js CHANGED
@@ -4380,6 +4380,29 @@ function detectSystemProxy(platform = process.platform) {
4380
4380
  expiresAt: now + 3e5
4381
4381
  };
4382
4382
  }
4383
+ /**
4384
+ * Write `body` to `file` without ever publishing a torn snapshot: a tmp name
4385
+ * unique per writer (pid + random), a JSON round-trip check, then `rename`
4386
+ * with retries. Two host processes persisting at once used to collide on one
4387
+ * fixed `.pool.json.tmp` and silently truncate the pool (2026-11-04).
4388
+ */
4389
+ function writeJsonAtomic(file, body) {
4390
+ const dir = dirname(file);
4391
+ const tmp = join(dir, "." + basename(file) + "." + process.pid + "." + Math.random().toString(36).slice(2, 8) + ".tmp");
4392
+ writeFileSync(tmp, body, "utf8");
4393
+ JSON.parse(readFileSync(tmp, "utf8"));
4394
+ let lastErr;
4395
+ for (let attempt = 0; attempt < 3; attempt++) try {
4396
+ renameSync(tmp, file);
4397
+ return;
4398
+ } catch (e) {
4399
+ lastErr = e;
4400
+ }
4401
+ try {
4402
+ unlinkSync(tmp);
4403
+ } catch {}
4404
+ throw lastErr;
4405
+ }
4383
4406
  function defaultPoolDir(home = homedir()) {
4384
4407
  if (process.env.DSH_STATE_DIR) return join(process.env.DSH_STATE_DIR, "agy-accounts");
4385
4408
  const idx = home.replace(/\\/g, "/").indexOf("/.dsh/agy-accounts/");
@@ -4409,6 +4432,8 @@ var AccountPoolManager = class {
4409
4432
  authStrikes = /* @__PURE__ */ new Map();
4410
4433
  /** Serialized snapshot of the last successful persist/load; skips no-op writes. */
4411
4434
  persistedJson = "";
4435
+ /** True when load() had to fall back to pool.json.last-good (observable for diagnostics). */
4436
+ recoveredFromLastGood = false;
4412
4437
  constructor(baseDir = defaultPoolDir()) {
4413
4438
  this.baseDir = baseDir;
4414
4439
  this.file = join(baseDir, "pool.json");
@@ -4427,9 +4452,22 @@ var AccountPoolManager = class {
4427
4452
  return this.baseDir;
4428
4453
  }
4429
4454
  load() {
4455
+ const primary = this.readPoolFile(this.file);
4456
+ if (primary) return primary;
4430
4457
  try {
4431
- if (existsSync(this.file)) {
4432
- const raw = readFileSync(this.file, "utf8");
4458
+ if (existsSync(this.file)) copyFileSync(this.file, this.file + ".corrupt-" + Date.now());
4459
+ } catch {}
4460
+ const lastGood = this.readPoolFile(this.file + ".last-good");
4461
+ if (lastGood) {
4462
+ this.recoveredFromLastGood = true;
4463
+ return lastGood;
4464
+ }
4465
+ return defaultPoolData();
4466
+ }
4467
+ readPoolFile(file) {
4468
+ try {
4469
+ if (existsSync(file)) {
4470
+ const raw = readFileSync(file, "utf8");
4433
4471
  const parsed = JSON.parse(raw);
4434
4472
  if (parsed && Array.isArray(parsed.accounts)) {
4435
4473
  parsed.accounts = parsed.accounts.filter((acc) => acc && typeof acc === "object" && acc.type !== "gemini-web");
@@ -4453,12 +4491,8 @@ var AccountPoolManager = class {
4453
4491
  };
4454
4492
  }
4455
4493
  }
4456
- } catch {
4457
- try {
4458
- if (existsSync(this.file)) copyFileSync(this.file, this.file + ".corrupt-" + Date.now());
4459
- } catch {}
4460
- }
4461
- return defaultPoolData();
4494
+ } catch {}
4495
+ return null;
4462
4496
  }
4463
4497
  persist() {
4464
4498
  const serialized = JSON.stringify(this.data);
@@ -4482,11 +4516,13 @@ var AccountPoolManager = class {
4482
4516
  try {
4483
4517
  mkdirSync(dirname(this.file), { recursive: true });
4484
4518
  if (serialized === this.persistedJson && merged === this.data) return;
4485
- const tmp = join(dirname(this.file), ".pool.json.tmp");
4486
- writeFileSync(tmp, JSON.stringify(merged, null, 2), "utf8");
4487
- renameSync(tmp, this.file);
4519
+ const body = JSON.stringify(merged, null, 2);
4520
+ writeJsonAtomic(this.file, body);
4488
4521
  this.persistedJson = JSON.stringify(merged);
4489
4522
  if (merged !== this.data) this.data = merged;
4523
+ try {
4524
+ writeJsonAtomic(this.file + ".last-good", body);
4525
+ } catch {}
4490
4526
  } catch (e) {
4491
4527
  try {
4492
4528
  console.error("[dsh-agy-link] pool persist failed: " + String(e));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agy-link",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "Google Antigravity (agy CLI) models for DeepSeek Harness — stream Gemini/Claude/GPT-OSS subscriptions into DSH with thinking, tool activity, token usage and in-GUI Google OAuth login.",
5
5
  "type": "module",
6
6
  "license": "MIT",