agent-dag 1.29.2 → 1.30.0

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.
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>agents-deck</title>
7
7
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext y='84' font-size='84'%3E%E2%97%89%3C/text%3E%3C/svg%3E" />
8
- <script type="module" crossorigin src="/assets/index-C7r26eKG.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-CgugXiGZ.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-BLOOP_Fy.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-dag",
3
- "version": "1.29.2",
3
+ "version": "1.30.0",
4
4
  "description": "Live deck of Claude Code and Codex agents — watch parallel subagents fork, call tools, and return on one calm canvas. Also available as npx ccdeck and npx agent-dag.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -13,10 +13,11 @@
13
13
  // means the deck cannot 429 the user's account, cannot burn a refresh token,
14
14
  // and cannot lose a login. Switching shells out to `cswap` rather than
15
15
  // reimplementing the lock protocol its correctness depends on.
16
- import { readFile } from "node:fs/promises";
16
+ import { readFile, writeFile, mkdir } from "node:fs/promises";
17
17
  import { cswapBin, cswapVersion, installHint } from "./cswap-install.mjs";
18
18
  import { run, runDetached } from "./exec.mjs";
19
- import { join } from "node:path";
19
+ import { dirname, join } from "node:path";
20
+ import { existsSync } from "node:fs";
20
21
  import { homedir, platform } from "node:os";
21
22
 
22
23
  // claude-swap keeps its store under XDG on Linux and in the home directory
@@ -220,3 +221,79 @@ export function switchClaudeAccount(accountNum) {
220
221
  return { ok: false, reason, output: (r.stderr || r.stdout).trim().slice(0, 500) };
221
222
  });
222
223
  }
224
+
225
+
226
+ /**
227
+ * Register the account already signed in, the first time and only the first
228
+ * time.
229
+ *
230
+ * A fresh install leaves claude-swap with an empty store, so the panel comes up
231
+ * saying "no accounts added yet" and telling the user to run `cswap add`
232
+ * themselves — for the account they are already using, on the machine they are
233
+ * already on. Running it for them is the difference between the panel working
234
+ * and the panel being a to-do item.
235
+ *
236
+ * `cswap add` takes no arguments, prompts for nothing, and does not sign
237
+ * anyone in: it records the Claude Code session that already exists. Even so it
238
+ * is bounded tightly, because it writes to a credential store:
239
+ *
240
+ * - only when the store holds no accounts at all, so nothing can be
241
+ * overwritten or reordered;
242
+ * - only once ever, marked on disk, so a user who deliberately removes their
243
+ * last account does not get it added back on the next launch;
244
+ * - never when AGENTS_DECK_NO_INSTALL=1.
245
+ *
246
+ * Failure is normal and quiet: on a machine where Claude Code has never signed
247
+ * in there is nothing to record.
248
+ */
249
+ const SEED_MARKER = join(homedir(), ".agents-deck", ".cswap-seeded");
250
+
251
+ /**
252
+ * How many accounts a sequence.json holds.
253
+ *
254
+ * claude-swap writes `accounts` as an object keyed by slot number — {"2": {…},
255
+ * "3": {…}} — not as a list. An Array.isArray guard here read that as "no
256
+ * accounts" and ran `cswap add` against a populated store, which is exactly
257
+ * what the guard existed to prevent. Both shapes are accepted now, and
258
+ * anything unrecognised counts as -1: unknown is not the same as empty, and
259
+ * only a confident zero may lead to a write.
260
+ */
261
+ export function accountCount(seq) {
262
+ const a = seq?.accounts;
263
+ if (Array.isArray(a)) return a.length;
264
+ if (a && typeof a === "object") return Object.keys(a).length;
265
+ if (a == null && seq && typeof seq === "object") return 0; // store exists, no accounts yet
266
+ return -1; // unreadable — do nothing
267
+ }
268
+
269
+ export async function seedFirstAccount() {
270
+ if (process.env.AGENTS_DECK_NO_INSTALL === "1") return { state: "skipped" };
271
+ if (existsSync(SEED_MARKER)) return { state: "already-tried" };
272
+
273
+ // Empty store only. A store with accounts in it is the user's, not ours, and
274
+ // a store we cannot parse is treated the same way.
275
+ // No file at all is the fresh install this exists for; a file that will not
276
+ // parse is a store in an unknown state. readJson answers null to both, so
277
+ // they are told apart before deciding, because they call for opposite
278
+ // decisions — seed, and keep well away.
279
+ const seqPath = join(backupRoot(), "sequence.json");
280
+ const before = existsSync(seqPath) ? accountCount(await readJson(seqPath)) : 0;
281
+ if (before > 0) return { state: "has-accounts", count: before };
282
+ if (before < 0) return { state: "unreadable-store" };
283
+
284
+ // Mark before running, not after: if `cswap add` half-succeeds or the process
285
+ // dies mid-way, the retry-forever loop is the worse outcome.
286
+ try {
287
+ await mkdir(dirname(SEED_MARKER), { recursive: true });
288
+ await writeFile(SEED_MARKER, new Date().toISOString());
289
+ } catch { /* best-effort — worst case it is attempted again */ }
290
+
291
+ const r = await run(await cswapBin(), ["add"], { timeout: 60_000 });
292
+ if (!r.ok) {
293
+ return { state: "failed", detail: (r.stderr || r.stdout).trim().slice(0, 200) };
294
+ }
295
+
296
+ invalidateClaudeAccountsCache();
297
+ const count = existsSync(seqPath) ? accountCount(await readJson(seqPath)) : 0;
298
+ return count > 0 ? { state: "added", count } : { state: "nothing-to-add" };
299
+ }