geneseed 5.1.1 → 5.2.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/SHIPPED.md +1 -1
  3. package/adapters/opencode/README.md +4 -3
  4. package/adapters/opencode/plugins/geneseed-context.js +26 -19
  5. package/adapters/opencode/plugins/geneseed-guard.js +112 -7
  6. package/bin/geneseed-cli.mjs +3 -0
  7. package/docs/concepts/exclusions.md +1 -1
  8. package/docs/concepts/host-matrix.md +1 -1
  9. package/docs/guides/setup-doctrines.md +1 -1
  10. package/docs/understand/enforced-vs-asked.md +1 -1
  11. package/harness.config.json +1 -1
  12. package/js/README.md +6 -4
  13. package/js/build/args.mjs +7 -1
  14. package/js/build/bundle.mjs +122 -23
  15. package/js/build/driver.mjs +32 -12
  16. package/js/build/emit-claude.mjs +2 -1
  17. package/js/build/emit-common.mjs +2 -2
  18. package/js/build/emit-opencode.mjs +22 -10
  19. package/js/build/export.mjs +431 -0
  20. package/js/build/generate.mjs +3 -0
  21. package/js/build/source.mjs +6 -1
  22. package/js/cli-table.json +99 -0
  23. package/js/hosts/hooks-done.mjs +8 -2
  24. package/js/hosts/hooks.mjs +105 -4
  25. package/js/hosts/hosts.mjs +2 -4
  26. package/js/hosts/installs.mjs +28 -0
  27. package/js/hosts/loss.mjs +19 -2
  28. package/js/hosts/native.mjs +30 -2
  29. package/js/hosts/owned.mjs +55 -1
  30. package/js/hosts/ownership-gate.mjs +5 -5
  31. package/js/hosts/settings.mjs +83 -33
  32. package/js/lib/managed-block.mjs +74 -0
  33. package/js/maintain/uninstall.mjs +57 -14
  34. package/js/web/actions.mjs +3 -0
  35. package/js/web/api.mjs +4 -1
  36. package/package.json +1 -1
  37. package/web/dist/assets/{Activity-CpkBwpu7.js → Activity-DlQ30znB.js} +1 -1
  38. package/web/dist/assets/{ActivityDetail-DTPziZWM.js → ActivityDetail-CG0mn5fW.js} +1 -1
  39. package/web/dist/assets/{Bonsai-hiG_gGNU.js → Bonsai-DSwUbavu.js} +1 -1
  40. package/web/dist/assets/{CopyButton-DUIUfNp6.js → CopyButton-BzRQz7k2.js} +1 -1
  41. package/web/dist/assets/{Dashboard-Dnw6EyX7.js → Dashboard-Ce3UOsxJ.js} +2 -2
  42. package/web/dist/assets/{Docs-BEET_l16.js → Docs-CisVnYqv.js} +1 -1
  43. package/web/dist/assets/{Factories-D6KXkfWw.js → Factories-Dq5oW4CU.js} +1 -1
  44. package/web/dist/assets/{GreenhouseView-BKxy5apE.js → GreenhouseView-y9WAfcc_.js} +1 -1
  45. package/web/dist/assets/Installs-m4GElwFW.js +3 -0
  46. package/web/dist/assets/{JournalView-ChFitHjo.js → JournalView-DeBLRNGc.js} +1 -1
  47. package/web/dist/assets/{Kits-CcR-OlwQ.js → Kits-DJYVAnyE.js} +1 -1
  48. package/web/dist/assets/{Laws-B1s5idOg.js → Laws-CNpc_8ZV.js} +1 -1
  49. package/web/dist/assets/{LibRows-BZgdbI1l.js → LibRows-RO5bvXth.js} +1 -1
  50. package/web/dist/assets/{Library-x6TkkEVF.js → Library-Dg0ScciC.js} +1 -1
  51. package/web/dist/assets/{Loops-BH93KKxn.js → Loops-CjEdo-NG.js} +1 -1
  52. package/web/dist/assets/{OperatorHudView-BO0aIKPL.js → OperatorHudView-2ujVMjq1.js} +1 -1
  53. package/web/dist/assets/{Personal-CE_0Vhh0.js → Personal-D0yS7ahT.js} +1 -1
  54. package/web/dist/assets/{Settings-CbpZvVN_.js → Settings-DEN0U8QI.js} +1 -1
  55. package/web/dist/assets/{Tabs-C2oW7oEj.js → Tabs-But5R6_r.js} +1 -1
  56. package/web/dist/assets/{index-BQwOmbor.js → index-Ck42AbRX.js} +2 -2
  57. package/web/dist/assets/{index-CuIop_pO.css → index-PG_ukkh6.css} +1 -1
  58. package/web/dist/index.html +2 -2
  59. package/web/dist/assets/Installs-CnFVlVD0.js +0 -3
@@ -35,6 +35,7 @@
35
35
  */
36
36
  import { existsSync, mkdirSync, renameSync, rmSync, unlinkSync } from 'node:fs';
37
37
  import path from 'node:path';
38
+ import { blockDelimiters, blockSpan } from '../lib/managed-block.mjs';
38
39
  import { readText, writeText, isOsError } from '../lib/fs.mjs';
39
40
  import {
40
41
  jsonDumps, jsonDumpsCompact, jsonDumpsIndent, parseJson, deepEquals, formatRepr,
@@ -272,6 +273,10 @@ function defaultPermission(doctrines = null, excluded = [], deletionGate = true)
272
273
  const OWNED_BASH = ['git commit*', 'git push*',
273
274
  ...PUSH_CHAIN.flatMap(([keys]) => keys)];
274
275
 
276
+ /** The verdict Geneseed itself writes for each owned key — what "still reads as ours" means. */
277
+ const OWNED_VERDICT = new Map([['git commit*', 'ask'], ['git push*', 'ask']]);
278
+ for (const [keys, verdict] of PUSH_CHAIN) for (const k of /** @type {string[]} */ (keys)) OWNED_VERDICT.set(k, /** @type {string} */ (verdict));
279
+
275
280
  /**
276
281
  * Bring an ALREADY-WRITTEN `permission` block back into line with the pack selection, and
277
282
  * touch nothing else. Returns `[changed, stranded]` — whether anything moved, and the owned
@@ -293,16 +298,27 @@ const OWNED_BASH = ['git commit*', 'git push*',
293
298
  * thing to want, and the value Geneseed writes precisely because it is the obvious one — had
294
299
  * it DELETED by a pack-off build.
295
300
  *
296
- * NOTHING ON DISK RECORDS PROVENANCE, and none of the candidates survived contact: the value
297
- * is what a user would write too; the carrier's `Active packs:` marker is rewritten by this
298
- * same emit BEFORE `mergeOpencodeJson` runs (`emitOpencodeGlobalRender` writes AGENT.md at the
299
- * top and wires the config at the bottom), so it answers with the NEW selection and would
300
- * licence every removal; and a per-install ownership record would be a new marker file joining
301
- * the owned set, the reversal markers and the deletion corpus — a much larger change than the
302
- * defect. So removal is CONSERVATIVE: an unwanted owned key that is already on disk stays, and
303
- * is reported to the caller as `stranded` so the user is told rather than left to discover it.
301
+ * THE RECORD IS THE MANIFEST'S `bash_gates` (5.2.0), the `bash` twin of `skill_denies` and
302
+ * `edit_asks`: the keys an emit itself ADDED, because they were absent when it ran. `record` is
303
+ * the previous manifest's list, as a Set, updated in place. A key that was already there, at
304
+ * any value, is the user's and is never claimed — the value is what a user would write too, and
305
+ * the carrier's `Active packs:` marker cannot stand in for a record either: this same emit
306
+ * rewrites it BEFORE `mergeOpencodeJson` runs, so it answers with the NEW selection and would
307
+ * licence every removal. (This docblock once ruled the record out as "a new marker file"; the
308
+ * manifest has since carried two such records, so it is one more key, not one more file.)
309
+ *
310
+ * So an unwanted owned key goes only when BOTH hold: it is recorded, and it still reads
311
+ * Geneseed's own verdict (`OWNED_VERDICT`) — the record licenses taking back our entry, not
312
+ * whatever a user has since put under that key. Anything else stays and is reported as
313
+ * `stranded`, so the user is told rather than left to discover it.
314
+ *
315
+ * `pruneAll` (`--prune-gates`) IS THE USER SAYING "THEY ARE YOURS" for an install that predates
316
+ * the record: every `opencode.json` written before 5.2.0 has the gates and no `bash_gates`, so
317
+ * without it they would be stranded for good. For that one build it stands in for the record;
318
+ * the value check stays, so an entry the user re-scoped is still kept. One-shot: no marker
319
+ * records it and no rebuild replays it.
304
320
  *
305
- * That leaves a gate wired for a rule this build does not make binding, which is the
321
+ * A stranded gate is wired for a rule this build does not make binding, which is the
306
322
  * FAIL-CLOSED direction — the boundary asks for a confirmation the constitution no longer
307
323
  * compels, exactly as the commit skill's own consent step does with the pack off. The unsafe
308
324
  * direction, a rule with no gate behind it, cannot occur here. A FRESH file is unaffected:
@@ -319,10 +335,11 @@ const OWNED_BASH = ['git commit*', 'git push*',
319
335
  * Returns a third element, `opaque`: the shape reason wiring was impossible, or `null`. The
320
336
  * caller warns on it. This is the one branch where the boundary can end up with NO Geneseed
321
337
  * gate at all while the constitution states the rule — the unsafe direction — so it must not
322
- * also be the silent one.
338
+ * also be the silent one. `removed` collects the keys taken back, for the commented-`.jsonc`
339
+ * branch, which cannot write and has to name them instead.
323
340
  * @returns {[boolean, string[], string | null]}
324
341
  */
325
- function reconcileOpencodePermission(perm, want) {
342
+ function reconcileOpencodePermission(perm, want, record = new Set(), pruneAll = false, removed = []) {
326
343
  // A `permission` that is not an object, or whose `bash` is not one — OpenCode also accepts a
327
344
  // bare `"bash": "allow"` — is a shape this function has no owned keys inside of. Leaving it
328
345
  // exactly as found is the whole point; rewriting it into a map would DELETE a blanket policy
@@ -335,12 +352,23 @@ function reconcileOpencodePermission(perm, want) {
335
352
  const bash = fresh ? {} : get(perm, 'bash');
336
353
  let changed = false;
337
354
  const stranded = [];
355
+ let addedAny = false;
338
356
  for (const k of OWNED_BASH) {
339
357
  if (has(want.bash, k)) {
340
- if (!has(bash, k)) { bash[k] = want.bash[k]; changed = true; }
341
- } else if (has(bash, k)) stranded.push(k);
358
+ if (!has(bash, k)) { bash[k] = want.bash[k]; changed = addedAny = true; record.add(k); }
359
+ } else if (has(bash, k)) {
360
+ if ((record.has(k) || pruneAll) && bash[k] === OWNED_VERDICT.get(k)) {
361
+ delete bash[k];
362
+ removed.push(k);
363
+ changed = true;
364
+ } else stranded.push(k);
365
+ // Taken back, or re-scoped by the user since: either way no longer ours to remember.
366
+ record.delete(k);
367
+ } else record.delete(k);
342
368
  }
343
- if (changed && fresh) perm.bash = bash;
369
+ if (addedAny && fresh) perm.bash = bash;
370
+ // The last gate out takes the map with it, as uninstall drops an emptied `permission.skill`.
371
+ if (removed.length && !fresh && !Object.keys(bash).length) delete perm.bash;
344
372
  return [changed, stranded, null];
345
373
  }
346
374
 
@@ -619,9 +647,12 @@ export function atomicWriteJson(p, config) {
619
647
  * `result.skillsAdded` is set to the `permission.skill` denies this call added ONLY when the
620
648
  * file on disk now matches what it computed (written, or nothing to change). Left unset on
621
649
  * every path that wrote nothing — unreadable, not an object, commented `.jsonc`, write
622
- * failure — so the caller keeps its previous record rather than claiming denies never written. */
650
+ * failure — so the caller keeps its previous record rather than claiming denies never written.
651
+ * `result.bashGates` (the next `bash_gates`, from `oldGates`) follows the same rule.
652
+ * `pruneGates` is `--prune-gates`: see `reconcileOpencodePermission`. */
623
653
  export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [], skillNames = [],
624
- staleSkillNames = [], result = {}, deletionGate = true, editAsks = [], oldEdit = null) {
654
+ staleSkillNames = [], result = {}, deletionGate = true, editAsks = [], oldEdit = null,
655
+ oldGates = [], pruneGates = false) {
625
656
  const target = opencodeTarget(p);
626
657
  let config = { $schema: OPENCODE_SCHEMA, instructions: [] };
627
658
  const { state, data, hadComments, error } = loadJsonObject(target);
@@ -655,11 +686,16 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
655
686
  let skillOpaque = null;
656
687
  let permIsObject = true;
657
688
  const added = [];
689
+ const gates = new Set(oldGates);
690
+ const gatesRemoved = [];
691
+ let permOther = false; // a `permission.skill` or `.edit` change, as opposed to a bash gate's
658
692
  // The edit record is a copy, filled in place, and handed back only on the paths that wrote.
659
693
  const edit = { asks: [...((oldEdit && oldEdit.asks) || [])], shorthand: (oldEdit && oldEdit.shorthand) || null };
660
694
  let editNote = null;
661
695
  if (addPerm) {
662
696
  config.permission = defaultPermission(doctrines, excluded, deletionGate);
697
+ gates.clear();
698
+ for (const k of Object.keys(config.permission.bash)) gates.add(k);
663
699
  if (skillNames.length) {
664
700
  config.permission.skill = defaultSkillPermission(skillNames);
665
701
  added.push(...skillNames);
@@ -669,7 +705,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
669
705
  const perm = get(config, 'permission');
670
706
  permIsObject = isDict(perm);
671
707
  [permChanged, stranded, opaque] = reconcileOpencodePermission(perm,
672
- defaultPermission(doctrines, excluded, deletionGate));
708
+ defaultPermission(doctrines, excluded, deletionGate), gates, pruneGates, gatesRemoved);
673
709
  // Independent of the `bash` shape: a `permission.bash` the build cannot wire into must
674
710
  // not also block the UNRELATED `permission.skill` key from being reconciled.
675
711
  if (permIsObject) {
@@ -680,6 +716,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
680
716
  let editChanged;
681
717
  [editChanged, editNote] = reconcileOpencodeEditPermission(perm, editAsks, edit);
682
718
  permChanged = permChanged || editChanged;
719
+ permOther = skillChanged || editChanged;
683
720
  }
684
721
  }
685
722
  // The shape said no. This is the direction the residue warning above is NOT — a rule stated
@@ -713,8 +750,9 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
713
750
  process.stderr.write(`[geneseed] WARN: ${path.basename(target)} keeps `
714
751
  + `${stranded.map((k) => jsonDumps(k)).join(', ')} under "permission".bash — the `
715
752
  + 'rule behind those gates (a doctrine, or the deletion gate) is off in this build, but '
716
- + 'Geneseed cannot tell its own entry from one you wrote, so it removes neither. Delete '
717
- + 'them by hand if you want them gone.\n');
753
+ + 'Geneseed has no record that it wrote them, so it leaves them. Run this build once '
754
+ + 'with --prune-gates to remove those still set as Geneseed writes them, or delete them '
755
+ + 'by hand.\n');
718
756
  }
719
757
  if (editNote) {
720
758
  process.stderr.write(`[geneseed] WARN: "permission"."edit" in ${path.basename(target)} `
@@ -730,9 +768,20 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
730
768
  if (!addInstr && !permChanged && !addLsp && !addDepth) {
731
769
  result.skillsAdded = added;
732
770
  result.editRecord = edit;
771
+ result.bashGates = [...gates];
733
772
  return target;
734
773
  }
735
774
  if (path.extname(target) === '.jsonc' && hadComments) {
775
+ // Named, since this branch cannot take them out; `bash_gates` keeps its old value (the
776
+ // caller's rule for a merge that wrote nothing), so they are still ours on the next emit.
777
+ if (gatesRemoved.length) {
778
+ process.stderr.write(`[geneseed] WARN: ${path.basename(target)} has comments, so it is `
779
+ + 'not rewritten: remove these from its "permission".bash by hand — the rule behind '
780
+ + `them is off in this build: ${gatesRemoved.map((k) => jsonDumps(k)).join(', ')}.\n`);
781
+ // Nothing but removals: the paste-in advice below is for what a file is MISSING.
782
+ const gateAdds = [...gates].some((k) => !oldGates.includes(k));
783
+ if (!addInstr && !addPerm && !gateAdds && !permOther && !addLsp && !addDepth) return target;
784
+ }
736
785
  // ⚠ THE TWO CASES GIVE OPPOSITE ADVICE, and telling a file that HAS a `permission` key to
737
786
  // add one is how the first cut of this got it wrong. `add` = there is no block, here is the
738
787
  // whole one; `reconcile` = there is a block and it is missing gates this build wires, and
@@ -752,6 +801,7 @@ export function mergeOpencodeJson(p, agentPath, doctrines = null, excluded = [],
752
801
  atomicWriteJson(target, config);
753
802
  result.skillsAdded = added;
754
803
  result.editRecord = edit;
804
+ result.bashGates = [...gates];
755
805
  } catch (e) {
756
806
  if (!isOsError(e)) throw e;
757
807
  process.stderr.write(`[geneseed] WARN: could not write ${target} (${e.message}) — `
@@ -1350,7 +1400,8 @@ export function settingsIntegrityCheck(p, managed, expect = 'present') {
1350
1400
  return flush();
1351
1401
  }
1352
1402
 
1353
- const delimiters = (blockId) => [`<!-- BEGIN ${blockId} -->`, `<!-- END ${blockId} -->`];
1403
+ // Where the block is: `blockSpan` (js/lib/managed-block.mjs), shared with the hook-side readers.
1404
+ const delimiters = blockDelimiters;
1354
1405
 
1355
1406
  /**
1356
1407
  * `_build_settings._managed_block_write` — 'created' | 'updated' | 'merged'.
@@ -1365,10 +1416,9 @@ export function managedBlockWrite(p, content, blockId = 'GENESEED') {
1365
1416
  return 'created';
1366
1417
  }
1367
1418
  const existing = readText(p);
1368
- if (existing.includes(begin) && existing.includes(end)) {
1369
- const pre = existing.split(begin)[0];
1370
- const post = existing.slice(existing.indexOf(end) + end.length);
1371
- writeText(p, pre + block + lstripNewlines(post));
1419
+ const span = blockSpan(existing, blockId);
1420
+ if (span) {
1421
+ writeText(p, existing.slice(0, span[0]) + block + lstripNewlines(existing.slice(span[1])));
1372
1422
  return 'updated';
1373
1423
  }
1374
1424
  const sep = existing.endsWith('\n') ? '' : '\n';
@@ -1383,12 +1433,11 @@ export function managedBlockRemove(p, blockId = 'GENESEED', whole = false) {
1383
1433
  unlinkSync(p);
1384
1434
  return;
1385
1435
  }
1386
- const [begin, end] = delimiters(blockId);
1387
1436
  const existing = readText(p);
1388
- if (!existing.includes(begin) || !existing.includes(end)) return;
1389
- const pre = existing.split(begin)[0];
1390
- const post = existing.slice(existing.indexOf(end) + end.length);
1391
- const rest = stripWhitespace(`${stripTrailingNewlines(pre)}\n${lstripNewlines(post)}`);
1437
+ const span = blockSpan(existing, blockId);
1438
+ if (!span) return;
1439
+ const rest = stripWhitespace(`${stripTrailingNewlines(existing.slice(0, span[0]))}\n`
1440
+ + `${lstripNewlines(existing.slice(span[1]))}`);
1392
1441
  if (rest) writeText(p, `${rest}\n`);
1393
1442
  else unlinkSync(p);
1394
1443
  }
@@ -1414,11 +1463,12 @@ export function opencodeSentinelWrite(cfgDir) {
1414
1463
  /** `_build_settings._managed_block_read` — the block's inner content, or null. */
1415
1464
  export function managedBlockRead(p, blockId = 'GENESEED') {
1416
1465
  if (!existsSync(p)) return null;
1417
- const [begin, end] = delimiters(blockId);
1418
1466
  const text = readText(p);
1419
- if (!text.includes(begin) || !text.includes(end)) return null;
1420
- const inner = text.slice(text.indexOf(begin) + begin.length);
1421
- return stripNewlines(inner.slice(0, inner.indexOf(end)));
1467
+ const span = blockSpan(text, blockId);
1468
+ if (!span) return null;
1469
+ // Between the two marker lines; an empty block has one newline, which is both ends.
1470
+ const block = text.slice(span[0], span[1]);
1471
+ return stripNewlines(block.slice(block.indexOf('\n') + 1, Math.max(block.lastIndexOf('\n'), 0)));
1422
1472
  }
1423
1473
 
1424
1474
  /** `str.lstrip("\n")`; the one copy — `native.mjs` and `opencode.mjs` import it from here. */
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The managed block: the `<!-- BEGIN GENESEED -->` … `<!-- END GENESEED -->` span Geneseed keeps
3
+ * inside a file the user co-owns (`CLAUDE.md`, `AGENTS.md`).
4
+ *
5
+ * ONE DEFINITION OF WHERE IT IS, for the writer (`js/hosts/settings.mjs`) and for every reader
6
+ * on the hook path (`js/hosts/hosts.mjs`, `js/hosts/ownership-gate.mjs`). They used to be five
7
+ * copies of one regex, because the hook path may not import `settings.mjs`, and when the writer
8
+ * learnt to read a marker only as a whole line the readers went on matching it anywhere. No
9
+ * imports at all, so the hook path pays nothing for it.
10
+ *
11
+ * The two OpenCode plugins cannot import this (a plugin is one self-contained file), so each
12
+ * carries `BLOCK_RE` below by value; `tests/unit/managed_block.test.mjs` holds the copies equal.
13
+ *
14
+ * A MARKER IS A WHOLE LINE. The block is written with each marker alone on its line, so that is
15
+ * the only shape read back. Matching the marker text anywhere took a user's sentence ABOUT the
16
+ * block ("everything below the `<!-- BEGIN GENESEED -->` line is generated") for the block's
17
+ * start: the next emit replaced everything from that sentence down to the real END, the user's
18
+ * own rules with it, and said nothing.
19
+ *
20
+ * THE PAIR IS the first END line with a BEGIN line above it, and the LAST such BEGIN. A lone
21
+ * BEGIN left higher up (a hand-deleted block's first line) therefore stays the user's text, with
22
+ * whatever they wrote under it. A file with no such pair has no block.
23
+ */
24
+ export const blockDelimiters = (blockId = 'GENESEED') => [`<!-- BEGIN ${blockId} -->`, `<!-- END ${blockId} -->`];
25
+
26
+ /**
27
+ * `[start, stop]`: from the first character of the BEGIN line to the last of the END line (no
28
+ * line ending), or null. Trailing blanks and a `\r` after a marker are allowed: a hook reads
29
+ * the file raw, and on Windows the line ends `\r\n`.
30
+ */
31
+ export function blockSpan(text, blockId = 'GENESEED') {
32
+ const [begin, end] = blockDelimiters(blockId);
33
+ let at = 0;
34
+ let start = -1;
35
+ for (const line of text.split('\n')) {
36
+ const bare = line.replace(/[ \t\r]+$/, '');
37
+ if (bare === begin) start = at;
38
+ else if (bare === end && start >= 0) return [start, at + bare.length];
39
+ at += line.length + 1;
40
+ }
41
+ return null;
42
+ }
43
+
44
+ /** The block, markers included, or `''` when the text has none. */
45
+ export function blockOf(text, blockId = 'GENESEED') {
46
+ const span = blockSpan(text, blockId);
47
+ return span ? text.slice(span[0], span[1]) : '';
48
+ }
49
+
50
+ /** The text with every block removed: what is left is the user's own. */
51
+ export function withoutBlocks(text, blockId = 'GENESEED') {
52
+ let out = text;
53
+ for (let span = blockSpan(out, blockId); span; span = blockSpan(out, blockId)) {
54
+ out = out.slice(0, span[0]) + out.slice(span[1]);
55
+ }
56
+ return out;
57
+ }
58
+
59
+ /**
60
+ * How many whole-line markers the text holds, BEGIN and END together. The carrier gate asks when
61
+ * an edit changes this as well as when it changes the block: a marker line added outside the
62
+ * block changes nothing a reader reads today, and is still an edit to the fence itself.
63
+ */
64
+ export function markerLines(text, blockId = 'GENESEED') {
65
+ const pair = blockDelimiters(blockId);
66
+ return text.split('\n').filter((line) => pair.includes(line.replace(/[ \t\r]+$/, ''))).length;
67
+ }
68
+
69
+ /**
70
+ * The same rule as one regex, for the OpenCode plugins, which cannot import this file: a BEGIN
71
+ * line, lazily to the first END line. It differs from `blockSpan` on one input only, a lone
72
+ * BEGIN line above a real block, where it starts at the lone one; a plugin only reads.
73
+ */
74
+ export const BLOCK_RE_SOURCE = '^<!-- BEGIN GENESEED -->[ \\t]*\\r?\\n[\\s\\S]*?^<!-- END GENESEED -->[ \\t]*\\r?$';
@@ -59,7 +59,9 @@ import {
59
59
  resolvePath, settingsFile,
60
60
  } from '../hosts/hosts.mjs';
61
61
  import { mcpCommented, mcpLoad } from '../hosts/mcp.mjs';
62
- import { hashesOf, ownedState, ownedWithin, recordedDenies, recordedEdit } from '../hosts/owned.mjs';
62
+ import {
63
+ SRC_DIRS_MARKER, bundleFiles, hashesOf, ownedState, ownedWithin, recordedDenies, recordedEdit,
64
+ } from '../hosts/owned.mjs';
63
65
  import {
64
66
  atomicWriteJson, managedBlockRead, managedBlockRemove, managedBlockWrite,
65
67
  loadJsonObject, mergeClaudeSettings, opencodeTarget, OPENCODE_SENTINEL, opencodeSentinelWrite,
@@ -405,11 +407,26 @@ export function installAgentEntryOf(instr) {
405
407
  /**
406
408
  * Reverse a per-repo OpenCode emit.
407
409
  *
408
- * Two shapes, and which one runs is decided by the manifest's PRESENCE. With one,
409
- * `.opencode/` is unlinked file by file so a hand-added agent or plugin under it survives;
410
- * without one — a pre-manifest legacy install — the directory goes whole. The portable bundle
411
- * dirs beside it (`laws`/`agents`/`skills`) are deleted whole EITHER WAY, because the plain
412
- * `build()` step wipes and rewrites them every run regardless of what the manifest says.
410
+ * ONLY WHAT THE EMIT RECORDED IS REMOVED, in both halves. `.opencode/` is unlinked file by file
411
+ * off its manifest, so a hand-added agent or plugin under it survives. The portable bundle
412
+ * beside it is unlinked file by file off the bundle's own list (`bundleFiles`,
413
+ * `js/build/bundle.mjs`), so the user's own `agents/`, `skills/`, `laws/` or `AGENT.md` at the
414
+ * repository root survive too. Both halves used to delete by directory, and a repository that
415
+ * had such folders before the install lost them.
416
+ *
417
+ * `userOnly` names the watched directories this reversal emptied of everything recorded and
418
+ * that still exist: what is left in them is the user's. `installUninstall` does not count them
419
+ * as survivors. Counting them reported INCOMPLETE and advised a retry, with the manifest already
420
+ * unlinked, and the retry then read `.opencode/` as a pre-manifest install and removed it whole.
421
+ *
422
+ * WITHOUT A RECORD the old shape still runs, for an install an older build made: no manifest
423
+ * means `.opencode/` goes whole, and no bundle list means `laws`/`agents`/`skills` and
424
+ * `AGENT.md` go whole. Two conditions fence it. The root must carry a bundle's own marker
425
+ * (`.geneseed-theme` or the version file), the test `build` uses: `installState` calls a bare
426
+ * `.opencode/` directory an install, and without the marker this reversal took a repository
427
+ * Geneseed had already left, or never entered, for a pre-manifest install. And a root that has
428
+ * the bundle list was made by a build that also writes the manifest, so a missing manifest
429
+ * there is not a pre-manifest install and `.opencode/` is left alone.
413
430
  *
414
431
  * The entry is read BEFORE AGENT.md is deleted. Reading it after would find the wire
415
432
  * describing a file that no longer exists, which the fallback would then paper over with the
@@ -421,8 +438,11 @@ function opencodeProjectUninstall(root, force = false) {
421
438
  let failed = [];
422
439
  let kept = [];
423
440
  let man = null;
441
+ const userOnly = [];
424
442
  const oc = path.join(root, '.opencode');
425
443
  const manifestPath = path.join(oc, GLOBAL_MANIFEST);
444
+ const listed = bundleFiles(root);
445
+ const legacy = isFile(path.join(root, '.geneseed-theme')) || isFile(path.join(root, VERSION_MARKER));
426
446
  if (isFile(manifestPath)) {
427
447
  man = claudeReadManifest(oc);
428
448
  [removed, failed, kept] = unlinkOwned(oc, ownedOf(man), '.opencode/', hashesOf(man), force);
@@ -434,22 +454,41 @@ function opencodeProjectUninstall(root, force = false) {
434
454
  if (!failed.length) {
435
455
  unlinkQuiet(manifestPath);
436
456
  if (isDir(oc) && isEmptyDir(oc)) rmdirQuiet(oc);
457
+ else if (isDir(oc)) userOnly.push(oc);
437
458
  } else {
438
459
  warnMarkersKept();
439
460
  }
440
461
  } else if (isDir(oc)) {
441
- rmtreeQuiet(oc);
442
- removed += 1;
462
+ if (listed || !legacy) userOnly.push(oc);
463
+ else { rmtreeQuiet(oc); removed += 1; }
443
464
  }
444
- for (const d of ['laws', 'agents', 'skills']) {
445
- const p = path.join(root, d);
446
- if (isDir(p)) { rmtreeQuiet(p); removed += 1; }
465
+ if (listed) {
466
+ const [n, bundleFailed] = unlinkOwned(root, listed, '', {}, true);
467
+ removed += n;
468
+ if (bundleFailed.length) {
469
+ warnSurvivors(bundleFailed);
470
+ failed = failed.concat(bundleFailed);
471
+ } else {
472
+ unlinkQuiet(path.join(root, SRC_DIRS_MARKER));
473
+ for (const d of ['laws', 'agents', 'skills']) {
474
+ if (isDir(path.join(root, d))) userOnly.push(path.join(root, d));
475
+ }
476
+ }
477
+ } else if (legacy) {
478
+ for (const d of ['laws', 'agents', 'skills']) {
479
+ const p = path.join(root, d);
480
+ if (isDir(p)) { rmtreeQuiet(p); removed += 1; }
481
+ }
482
+ const am = path.join(root, 'AGENT.md');
483
+ if (isFile(am)) { unlinkQuiet(am); removed += 1; }
484
+ } else {
485
+ for (const d of ['laws', 'agents', 'skills']) {
486
+ if (isDir(path.join(root, d))) userOnly.push(path.join(root, d));
487
+ }
447
488
  }
448
- const am = path.join(root, 'AGENT.md');
449
- if (isFile(am)) { unlinkQuiet(am); removed += 1; }
450
489
  const unmerged = unmergeOpencodeJson(path.join(root, 'opencode.json'), entry,
451
490
  man ? recordedDenies(man) : [], man ? recordedEdit(man) : null);
452
- const result = { removed, unmerged, archived: null };
491
+ const result = { removed, unmerged, archived: null, userOnly };
453
492
  if (failed.length) result.failed = failed;
454
493
  if (kept.length) result.kept = kept;
455
494
  return result;
@@ -536,7 +575,11 @@ export function installUninstall(root, host = 'opencode', scope = 'global', memo
536
575
  // `kept` rels are spelled relative to the reversal's own base: the cfg dir for the Claude
537
576
  // family, the root for OpenCode (whose project reversal already prefixes `.opencode/`).
538
577
  const keptAbs = new Set(kept.map((r) => path.join(CLAUDE_STYLE.includes(host) ? data : root, r)));
578
+ // `userOnly`: a reversal that removed by record names the watched dirs it left holding only
579
+ // the user's files (`opencodeProjectUninstall`).
580
+ const userOnly = new Set(summary.userOnly || []);
539
581
  const survivors = ownedDirsFor(root, host, scope, data).filter((d) => existsSync(d)
582
+ && !userOnly.has(d)
540
583
  && !(keptAbs.size && readdirSync(d, { recursive: true, withFileTypes: true })
541
584
  .every((e) => e.isDirectory() || keptAbs.has(path.join(e.parentPath, e.name)))));
542
585
  const withKept = (o) => (kept.length ? { ...o, kept } : o);
@@ -786,6 +786,9 @@ export function apiInstallCmd(state, body) {
786
786
  const argv = setupBuildArgs(theme || 'neutral', emit, out, out, fp, pos, mode, doctrines,
787
787
  PACK_ORDER, excludeRules, trust, excludedSkillsOfDir(root, host), gates,
788
788
  kits ?? kitsOfDir(root, host), sharedTier);
789
+ // `--force` only on a literal `true`: the panel's "Replace with Geneseed's copies", which
790
+ // names the files first. It is this one build's instruction and is never recorded.
791
+ if (bget(body, 'force') === true) argv.push('--force');
789
792
  return { cmd: [process.execPath, path.join(ROOT, 'bin', 'build-driver.mjs'), ...argv] };
790
793
  }
791
794
 
package/js/web/api.mjs CHANGED
@@ -23,7 +23,7 @@ import { CLAUDE_STYLE, VERSION_MARKER } from '../hosts/hosts.mjs';
23
23
  import { factCount } from '../hosts/memory-files.mjs';
24
24
  import { autostartState } from '../hosts/shim.mjs';
25
25
  import {
26
- footprintOfDir, gatesOfDir, installState, installTargets, modeOfDir,
26
+ footprintOfDir, gatesOfDir, installState, installTargets, leftoversOf, modeOfDir,
27
27
  trustOfDir, sharedTierOfDir,
28
28
  postureOfDir, readJsonMaybe, readMaybe, themeOfDir,
29
29
  } from '../hosts/installs.mjs';
@@ -228,6 +228,9 @@ export function apiInstalls(state) {
228
228
  trust: trustOfDir(root, host),
229
229
  // A project install's switch for reading the machine tier (a global install owns it).
230
230
  sharedTier: scope === 'global' ? false : sharedTierOfDir(root, host),
231
+ // Files here that are the user's where Geneseed ships one, and retired leftovers: what a
232
+ // forced rebuild would replace or remove (`leftoversOf`). Read off the emit's own record.
233
+ leftovers: leftoversOf(root, host, scope),
231
234
  // The install a request naming none reads (`defaultView`): the console's pickers start on it.
232
235
  default: !!def && samePath(viewCfg(host, scope, root), def[0]),
233
236
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "//": "Every field here is argued and gated in tests/unit/package_manifest.test.mjs. `files`, `bin`, `exports` and `engines` each have a test that fails when reality drifts from this file; `version` mirrors harness.config.json and is gated too. Read that docblock before editing this one.",
3
3
  "name": "geneseed",
4
- "version": "5.1.1",
4
+ "version": "5.2.0",
5
5
  "description": "A portable, theme-able harness you implant once and use everywhere to grow a disciplined AI coding agent.",
6
6
  "keywords": [
7
7
  "ai",
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-C1iE8mnY.js";import{t as r}from"./api-DLDVY3K-.js";import{s as i}from"./motion-RlUl1osO.js";import{A as a,B as o,D as s,Et as c,F as l,G as u,I as d,L as f,N as p,O as m,P as h,R as g,bt as _,it as v,j as y,k as b,ot as ee,rt as te,u as ne,wt as x}from"./index-BQwOmbor.js";import{t as S}from"./EmptyState-CY5Pm2xy.js";import{_ as C,a as w,c as T,f as E,g as D,h as O,i as k,l as A,m as re,n as j,o as M,p as N,r as P,s as F,t as I,u as L,v as R}from"./Bonsai-hiG_gGNU.js";import{t as ie}from"./usePoll-o8ul-Sog.js";var z=e(t(),1),B=n(),V=4,H=56*V,U=24,W=165,G=188,K=(e,t)=>e>0?Math.max(1,Math.floor((e-32+U)/(H+U))):Math.max(1,t),q=e=>e.status===`blocked`?`bad`:l(e)?`warn`:e.status===`busy`?`ok`:``,J=e=>{let t=A(e);return t==null?null:Math.round(t*100)};function Y(e,t,n){let r=s[e.status]||s.idle,i=t.pads.filter(e=>e.key!=null),a=t.pads.reduce((e,t)=>e+t.files.length,0)+t.fallen.reduce((e,t)=>e+t.files.length,0),o=J(e);return[`${e.title||y(e.cwd)||e.session_id}, ${e.chip||e.host||`unknown host`}, ${r.label}${e.phase?`, ${e.phase}`:``}`,`${e.turns||0} turns${o==null?``:`, context ${o} %`}${e.compactions?`, ${e.compactions} compactions`:``}`,i.length?`${i.length} sub-agent${i.length===1?``:`s`} running: ${i.map(e=>`${e.type||`agent`} (${e.files.length} file${e.files.length===1?``:`s`})`).join(`, `)}`:``,t.fallen.length?`${t.fallen.length} finished`:``,`${a} file${a===1?``:`s`} changed`,n.length?`shares ${n.length} file${n.length===1?``:`s`} with another session`:``,e.error?`error: ${e.error}`:``].filter(Boolean).join(`. `)}function X({s:e,t,mine:n}){let r=J(e);return(0,B.jsxs)(`div`,{className:`card gd-card`,children:[(0,B.jsxs)(`dl`,{className:`gd-facts`,children:[e.model&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{children:`model`}),(0,B.jsx)(`dd`,{className:`mono`,children:e.model})]}),(0,B.jsx)(`dt`,{children:`turns`}),(0,B.jsx)(`dd`,{children:e.turns||0}),(0,B.jsx)(`dt`,{children:`context`}),(0,B.jsx)(`dd`,{children:r==null?`unknown`:`${r} %`}),(0,B.jsx)(`dt`,{children:`compactions`}),(0,B.jsx)(`dd`,{children:e.compactions||0})]}),t.fallen.length>0&&(0,B.jsxs)(`div`,{className:`dim act-xs`,children:[`finished: `,t.fallen.map(e=>`${e.type||`agent`} (${e.files.length})`).join(`, `)]}),n.map(e=>(0,B.jsxs)(`div`,{className:`act-xs ${e.kind===`same-worktree`?`t-bad`:`t-warn`}`,children:[`same file`,e.kind===`same-worktree`?``:`, other worktree`,`: `,e.path]},`${e.kind}:${e.path}`))]})}function Z({s:e,worktree:t,sakura:n,mine:r,pad:i,onHover:a}){let o=R(e,n),c=(0,z.useMemo)(()=>E(e,{sakura:n}),[o]),u=s[e.status]||s.idle,d=Array.isArray(e.loops)?e.loops[0]:null,f=e.status!==`idle`,p=F(e),m=e.title||y(e.cwd)||e.session_id,h=J(e),g=(0,z.useRef)(null),_=(0,z.useCallback)(e=>a(p,e,Q(g.current)),[a,p]);return(0,B.jsxs)(`a`,{ref:g,className:`gd-tree${l(e)?` gd-needs`:``}`,href:e.href||L(e.session_id),"aria-label":Y(e,c,r),"data-sid":e.session_id,onMouseEnter:e=>a(p,null,Q(e.currentTarget)),onMouseLeave:()=>a(null,null),onFocus:e=>a(p,null,Q(e.currentTarget)),onBlur:()=>a(null,null),onKeyDown:e=>k(e,c.pads.length,i,_),children:[(0,B.jsx)(P,{t:c,pad:i,swaying:f,onPad:_,px:V}),(0,B.jsxs)(`div`,{className:`gd-cap`,children:[(0,B.jsx)(`div`,{className:`gd-title`,title:m,children:m}),(0,B.jsxs)(`div`,{className:`row wrap gd-pills`,children:[(0,B.jsx)(`span`,{className:`badge mono`,title:`The install this session runs in`,children:e.chip||e.host||`?`}),(0,B.jsx)(`span`,{className:`badge ${q(e)}`,children:u.label}),t&&(0,B.jsxs)(`span`,{className:`badge mono`,children:[`⎇ `,t]}),d&&(0,B.jsxs)(`span`,{className:`badge`,children:[`↻ `,d.title,d.iteration==null?``:` ${d.iteration}`]}),e.attribution===!1&&(0,B.jsx)(`span`,{className:`badge`,title:`attribution unavailable on ${e.host}`,children:`no attrib.`})]}),(0,B.jsxs)(`div`,{className:`mono gd-meta`,children:[e.turns||0,` turns`,h==null?``:` · ${h}%`]})]})]})}function ae({pairs:e,count:t}){if(!e.length)return null;let n=t*H+(t-1)*U,r=e=>e*(H+U)+H/2;return(0,B.jsx)(`svg`,{className:`gd-threads`,width:n,height:56*V+20,"aria-hidden":`true`,children:e.map(({a:e,b:t,kind:n})=>{let[i,a]=e<t?[e,t]:[t,e],o=`gd-thread ${n===`same-worktree`?`red`:`amber`}`;if(a-i===1){let e=r(i)+30,t=r(a)-30,n=(e+t)/2;return(0,B.jsxs)(`g`,{className:o,children:[(0,B.jsx)(`path`,{d:`M${e} ${W} C${n} 179 ${n} 159 ${t} 169`}),(0,B.jsx)(`path`,{d:`M${e} 169 C${n} 159 ${n} 179 ${t} ${W}`})]},`${i}-${a}`)}return(0,B.jsx)(`g`,{className:o,children:(0,B.jsx)(`path`,{d:`M${r(i)} ${G} Q${(r(i)+r(a))/2} 222 ${r(a)} ${G}`})},`${i}-${a}`)})})}var Q=e=>e.offsetLeft;function oe({sessions:e,collisions:t}){let[n,r]=(0,z.useState)(M),[i,a]=(0,z.useState)(()=>new Set),o=()=>{let e=!n;r(e);try{window.localStorage.setItem(j,e?`1`:`0`)}catch{}},s=Array.isArray(t)?t:[],c=T(N(e)).map(e=>i.has(e.key)?{...e,collapsed:!1}:e),l=c.filter(e=>e.collapsed),u=e=>D(e,s);return(0,B.jsxs)(`section`,{className:`gd`,"aria-label":`Garden`,children:[(0,B.jsxs)(`div`,{className:`row between wrap gap-8 gd-head`,children:[(0,B.jsxs)(`span`,{className:`dim act-sm`,children:[e.length,` tree`,e.length===1?``:`s`,` · `,c.length,` `,c.length===1?`shelf`:`shelves`,` · a tree opens its session; hover or focus shows its details, and a tap or the arrow keys walk its pads`]}),(0,B.jsx)(`button`,{type:`button`,className:n?`chip-f on`:`chip-f`,"aria-pressed":n,onClick:o,children:`Pink blossom`})]}),l.length>0&&(0,B.jsx)(`div`,{className:`row wrap gap-8 gd-chips`,role:`group`,"aria-label":`Folded shelves`,children:l.map(e=>(0,B.jsxs)(`button`,{type:`button`,className:`chip-f`,"aria-expanded":!1,onClick:()=>a(t=>new Set(t).add(e.key)),children:[e.name,` · `,e.trees.length]},e.key))}),c.filter(e=>!e.collapsed).map(e=>(0,B.jsx)(se,{sh:e,sakura:n,cols:s,mineOf:u},e.key))]})}function se({sh:e,sakura:t,cols:n,mineOf:r}){let[i,a]=(0,z.useState)({sid:null,pad:null,x:0}),o=(0,z.useCallback)((e,t,n)=>a(r=>({sid:e,pad:t,x:n??(r.sid===e?r.x:0)})),[]),s=(0,z.useRef)(null),[c,l]=(0,z.useState)(0);(0,z.useLayoutEffect)(()=>{let e=s.current,t=()=>l(e.clientWidth);if(t(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t);let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let u=K(c,e.trees.length),d=C(e.trees,n),f=[];for(let t=0;t<e.trees.length;t+=u)f.push(t);let p=e.trees.findIndex(e=>F(e.s)===i.sid),m=p<0?null:e.trees[p].s,h=m?E(m,{sakura:t}):null,g=h&&i.pad!=null?h.pads[i.pad]:null,_=e.trees.length;return(0,B.jsxs)(`section`,{className:`gd-shelf`,"aria-label":`${e.name} shelf`,ref:s,children:[f.map(n=>{let a=e.trees.slice(n,n+u),s=n+a.length,c=d.filter(e=>e.a>=n&&e.a<s&&e.b>=n&&e.b<s).map(e=>({...e,a:e.a-n,b:e.b-n}));return(0,B.jsxs)(`div`,{className:`gd-row`,children:[(0,B.jsx)(`div`,{className:`gd-plank`,children:n===0&&(0,B.jsxs)(`h3`,{className:`gd-plate`,children:[e.name,` · `,_,` session`,_===1?``:`s`]})}),a.map(({s:e,worktree:n})=>(0,B.jsx)(Z,{s:e,worktree:n,sakura:t,mine:r(F(e)),pad:F(e)===i.sid?i.pad:null,onHover:o},F(e))),(0,B.jsx)(ae,{pairs:c,count:a.length}),m&&p>=n&&p<s&&(0,B.jsx)(`div`,{className:`gd-info`,"aria-hidden":`true`,style:{left:Math.max(0,i.x)},children:g?(0,B.jsx)(I,{pad:g}):(0,B.jsx)(X,{s:m,t:h,mine:r(F(m))})})]},n)}),(0,B.jsx)(`span`,{className:`sr-only`,role:`status`,children:w(g)})]})}var $=e=>e.catch(()=>null);function ce({s:e}){let t=(0,z.useId)(),n=e.todos,r=h(e);return(0,B.jsxs)(`a`,{className:`card pad-md act-card`,href:e.href||L(e.session_id),"aria-labelledby":`${t}-t ${t}-st`,"aria-describedby":r?`${t}-c`:void 0,children:[(0,B.jsxs)(m,{s:e,id:t,heading:e.title||y(e.cwd)||e.session_id,children:[e.chip&&(0,B.jsx)(`span`,{className:`badge mono`,title:`The install this session runs in`,children:e.chip}),(0,B.jsx)(_,{name:`chevron`,className:`glyph act-chev`})]}),n&&n.total>0&&(0,B.jsx)(`div`,{className:`act-foot`,children:(0,B.jsxs)(`span`,{className:`row gap-8 dim act-sm`,children:[(0,B.jsx)(a,{done:n.done,total:n.total}),`plan `,n.done,`/`,n.total]})}),(0,B.jsxs)(`div`,{className:`dim mono act-updated`,children:[`updated `,x(e.updated_at),` ago`]})]})}var le={blocked:`is blocked`,"waiting-input":`waits for your answer`};function ue(e,t){if(!Array.isArray(t))return``;let n=t.filter(l),r=e.current;return e.current=new Set(n.map(e=>`${F(e)}:${e.status}`)),r?n.filter(e=>!r.has(`${F(e)}:${e.status}`)).map(e=>`${e.title||y(e.cwd)||e.session_id} ${le[e.status]}`).join(`. `):``}var de=[[`all`,`All`],[`needs`,`Needs you`],[`runs`,`Runs`],[`gates`,`Gate asks`]];function fe(){let e=new URLSearchParams(window.location.hash.split(`?`)[1]||``),t=e.get(`f`);return{f:de.some(([e])=>e===t)?t:`all`,host:e.get(`host`)||``,project:e.get(`project`)||``,v:e.get(`v`)===`list`?`list`:`garden`}}function pe(e){let t=new URLSearchParams;e.f!==`all`&&t.set(`f`,e.f),e.v===`list`&&t.set(`v`,`list`),e.host&&t.set(`host`,e.host),e.project&&t.set(`project`,e.project);let n=t.toString();window.history.replaceState(null,``,`#/activity${n?`?${n}`:``}`)}function me({enabled:e,installs:t,onToggle:n}){let r=re(t);return(0,B.jsxs)(`section`,{className:`card pad-md act-track`,"aria-labelledby":`act-track-h`,children:[(0,B.jsx)(_,{name:`activity`,className:`glyph act-fixed`}),(0,B.jsxs)(`div`,{className:`act-grow`,children:[(0,B.jsx)(`h2`,{id:`act-track-h`,className:`act-track-title`,children:e?`Live sessions are on`:`Live sessions are off`}),!e&&(0,B.jsx)(`p`,{className:`dim act-sm act-track-p`,children:`Runs and gate asks below come from the job log and the gate ledger. Turn tracking on to see what each session is doing now.`})]}),(0,B.jsxs)(`ul`,{className:`stack gap-8 act-fixed act-sm`,"aria-label":`Tracking per install`,children:[t.length===0&&(0,B.jsx)(`li`,{className:`dim`,children:`No active install to track.`}),t.map((e,t)=>(0,B.jsxs)(`li`,{className:`row gap-10`,children:[(0,B.jsxs)(`span`,{id:`act-track-l${t}`,title:e.path,children:[`Track live sessions in `,(0,B.jsx)(`span`,{className:`mono`,children:r.get(e.install)})]}),(0,B.jsx)(`div`,{className:`sw-toggle${e.enabled?` on`:``}`,role:`switch`,"aria-checked":e.enabled,"aria-labelledby":`act-track-l${t}`,tabIndex:0,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.key===` `&&t.preventDefault(),n(e))}})]},e.install))]})]})}function he({jobs:e,loading:t}){let n=typeof e?.cap==`number`?e.cap:void 0,r=d(e?.jobs,{days:14,cap:n}),i=g(r.map(e=>e.nodata?`-`:e.n).join(`,`),`scaleY`),a=Math.max(1,...r.map(e=>e.n)),o=r.reduce((e,t)=>e+t.n,0),s=r.find(e=>!e.nodata),c=r.some(e=>e.nodata),l=`Runs per day: ${r.filter(e=>e.n).map(e=>`${e.n} on ${f(e.key)}`).join(`, `)||`none`}.`+(c?s?` Days before ${f(s.key)} are older than the runs the log keeps.`:` No run is in the log yet.`:``);return(0,B.jsxs)(`section`,{className:`card pad-md act-stat`,"aria-labelledby":`act-runs-h`,children:[(0,B.jsxs)(`div`,{className:`act-stat-head`,children:[(0,B.jsx)(`h2`,{id:`act-runs-h`,className:`act-lbl`,children:`Runs per day · 14 days`}),e&&(0,B.jsx)(`span`,{className:`act-big`,children:o})]}),t?(0,B.jsx)(v,{label:`Reading the job log…`}):e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`act-runs`,role:`img`,"aria-label":l,ref:i,children:r.map(e=>e.nodata?(0,B.jsx)(`i`,{className:`nodata`},e.key):e.n?(0,B.jsx)(`i`,{"data-sweep":!0,style:{height:`${e.n/a*100}%`},title:`${f(e.key)}: ${e.n}`},e.key):(0,B.jsx)(`i`,{className:`zero`},e.key))}),(0,B.jsxs)(`div`,{className:`mono act-axis`,"aria-hidden":`true`,children:[(0,B.jsx)(`span`,{children:f(r[0].key)}),(0,B.jsx)(`span`,{children:f(r[7].key)}),(0,B.jsx)(`span`,{children:`today`})]}),c&&(0,B.jsxs)(`span`,{className:`dim act-xs`,children:[`Hatched: older than the runs the log keeps`,n?` (last ${n})`:``,`.`]})]}):(0,B.jsx)(`p`,{className:`dim act-sm`,children:`The job log could not be read.`})]})}function ge({rows:e,gates:t,loading:n}){let r=e.reduce((e,t)=>e+t.n,0);return(0,B.jsxs)(`section`,{className:`card pad-md act-stat`,"aria-labelledby":`act-gates-h`,children:[(0,B.jsxs)(`div`,{className:`act-stat-head`,children:[(0,B.jsx)(`h2`,{id:`act-gates-h`,className:`act-lbl`,children:`Gate asks by rule · 30 days`}),t&&(0,B.jsx)(`span`,{className:`act-big`,children:r})]}),n?(0,B.jsx)(v,{label:`Reading the gate ledger…`}):e.length?(0,B.jsx)(`ul`,{className:`gate-rows`,children:e.slice(0,6).map((e,t)=>(0,B.jsxs)(`li`,{children:[(0,B.jsxs)(`span`,{className:`act-ell`,children:[e.name,` `,(0,B.jsx)(`span`,{className:`mono dim act-xs`,children:e.rule})]}),(0,B.jsx)(b,{vals:e.per_day,i:t,sweep:!0}),(0,B.jsx)(`span`,{className:`mono`,children:e.n})]},e.rule))}):(0,B.jsx)(`p`,{className:`dim act-sm`,children:t?`No gate asked in 30 days.`:`The gate ledger could not be read.`})]})}var _e={done:[`ok`,`done`],failed:[`bad`,`failed`],running:[``,`running`]};function ve({job:e,longest:t}){let n=o(e),r=e.duration?Math.round(e.duration*10)/10:0,[i,a]=_e[e.status]||[``,e.status||`…`],s=e.status===`running`?`Still running`:r?`Took ${r} second${r===1?``:`s`}`:`No duration`,c=e.started?new Date(e.started*1e3).toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):`—`;return(0,B.jsxs)(`li`,{className:`act-row`,children:[(0,B.jsx)(`span`,{className:`mono dim act-xs`,children:c}),(0,B.jsx)(_,{name:`play`,className:`glyph act-glyph`}),(0,B.jsxs)(`span`,{className:`act-what`,children:[(0,B.jsx)(`span`,{className:`act-row-title`,children:n.verb}),n.scope&&(0,B.jsx)(`span`,{className:`dim act-xs act-ell`,title:n.command,children:n.scope})]}),(0,B.jsx)(`span`,{className:`act-dur`,role:`img`,"aria-label":s,children:(0,B.jsx)(`span`,{"data-sweep":!0,style:{width:t>0?`${(e.duration||0)/t*100}%`:`0%`}})}),(0,B.jsx)(`span`,{className:`badge ${i}`,children:a})]})}function ye({gate:e}){return(0,B.jsxs)(`li`,{className:`act-row gate`,children:[(0,B.jsx)(`span`,{className:`mono dim act-xs`,children:`—`}),(0,B.jsx)(_,{name:`rule`,className:`glyph act-glyph t-warn`}),(0,B.jsxs)(`span`,{className:`act-what`,children:[(0,B.jsx)(`span`,{className:`act-row-title`,children:e.title}),(0,B.jsx)(`span`,{className:`dim act-xs`,children:`Gate ledger`})]}),(0,B.jsx)(`span`,{className:`act-dur-none`,"aria-hidden":`true`}),(0,B.jsx)(`span`,{className:`badge warn`,children:`asked`})]})}var be=5,xe=(e,t)=>[...new Set([...e.filter(Boolean),t].filter(Boolean))];function Se(){let[e,t]=(0,z.useState)(null),[n,a]=(0,z.useState)(``),[o,s]=(0,z.useState)(fe),[d,f]=(0,z.useState)(!1),[m,h]=(0,z.useState)(``),_=(0,z.useRef)(null),b=e=>{let t={...o,...e};s(t),pe(t)};ie(e=>r.activity().then(n=>{if(e()){t(n),a(``);let e=ue(_,n?.activity);e&&h(t=>t===e?e+`\xA0`:e)}},t=>{e()&&a(t.message)}),2e3,[]);let x=c(()=>$(r.jobs()),[]),C=c(()=>$(r.gates()),[]),w=c(()=>$(r.catalog(`laws`)),[]),T=!e||e.enabled!==!1,E=Array.isArray(e?.installs)?e.installs:[],D=O(e?.activity,E).sort((e,t)=>e.session_id<t.session_id?-1:+(e.session_id>t.session_id)),k=i(),A=T&&e?D.filter(l).length:null,re=new Set(D.map(F)),j=o.v===`list`?O(e?.ended,E).filter(e=>!re.has(F(e))):[],M=xe([...D,...j].map(e=>e.host),o.host),N=xe([...D,...j].map(e=>y(e.cwd)),o.project),P=o.host&&o.project?`host or project`:o.host?`host`:o.project?`project`:``,I=e=>(!o.host||e.host===o.host)&&(!o.project||y(e.cwd)===o.project),L=D.filter(e=>I(e)&&(o.f!==`needs`||l(e))),R=o.f===`all`||o.f===`needs`,V=o.f===`all`&&T?j.filter(I):[],H=d?V:V.slice(0,be),U=!P&&(o.f===`all`||o.f===`runs`),W=!P&&(o.f===`all`||o.f===`gates`),G=x.data?.jobs||[],K=ne(C.data,w.data),q=p(G,K,C.data?.days).map(e=>({...e,runs:U?e.runs:[],gate:W?e.gate:null})).filter(e=>e.runs.length||e.gate),J=Math.max(0,...G.map(e=>e.duration||0)),Y=g(q.flatMap(e=>e.runs.map(e=>`${e.id}:${e.duration}`)).join(`,`),`scaleX`),X=async e=>{let n=!e.enabled;try{let i=await r.activityToggle(n,{host:e.host,path:e.path});if(i.ok===!1){a(i.error||`Could not change tracking`);return}let o=t=>i.enabled?t||[]:(t||[]).flatMap(t=>{let n=(t.installs||[t.install]).filter(t=>t!==e.install);return n.length?[{...t,install:n[0],installs:n}]:[]});t(t=>{let n=(t?.installs||[]).map(t=>t.install===e.install?{...t,enabled:i.enabled}:t);return{...t||{},installs:n,enabled:n.length===0||n.some(e=>e.enabled),activity:o(t?.activity),ended:o(t?.ended)}}),a(``)}catch(e){a(e.message)}},Z=(e,t,n)=>(0,B.jsxs)(`span`,{className:`row gap-8 act-sm`,children:[(0,B.jsx)(`label`,{htmlFor:`act-f-${e}`,children:t}),(0,B.jsxs)(`select`,{id:`act-f-${e}`,className:`sel`,value:o[e],disabled:n.length===0,title:n.length===0?`No source carries a ${e} yet`:void 0,onChange:t=>b({[e]:t.target.value}),children:[(0,B.jsxs)(`option`,{value:``,children:[`All `,e===`host`?`hosts`:`projects`]}),n.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})]});return(0,B.jsxs)(`div`,{className:`page-fill`,children:[(0,B.jsx)(u,{title:`Activity`,sub:`What your agents ran, what the gates asked, and which sessions are waiting on you.`}),(0,B.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,children:m}),n&&(0,B.jsx)(`div`,{className:`act-gap`,children:(0,B.jsx)(te,{error:n})}),e&&(0,B.jsx)(me,{enabled:T,installs:E,onToggle:X}),(0,B.jsxs)(`div`,{className:`act-today`,children:[(0,B.jsx)(he,{jobs:x.data,loading:x.loading}),(0,B.jsx)(ge,{rows:K,gates:C.data,loading:C.loading}),(0,B.jsxs)(`section`,{className:`card pad-md act-stat`,"aria-labelledby":`act-wait-h`,children:[(0,B.jsx)(`h2`,{id:`act-wait-h`,className:`act-lbl`,children:`Waiting on you`}),!e&&!n?(0,B.jsx)(v,{}):e?(0,B.jsxs)(B.Fragment,{children:[T?(0,B.jsxs)(`span`,{className:`act-big act-wait`,children:[A,` `,(0,B.jsx)(`span`,{className:`dim act-sm`,children:A===1?`session`:`sessions`})]}):null,(0,B.jsx)(`p`,{className:`dim act-sm`,children:T?`A session that waits on an approval or on your answer counts here.`:`Turn tracking on to count the sessions that wait on you.`})]}):(0,B.jsx)(`p`,{className:`dim act-sm`,children:`The sessions could not be read.`})]})]}),(0,B.jsxs)(`div`,{className:`row wrap gap-8 act-filters`,children:[(0,B.jsx)(`div`,{role:`group`,"aria-label":`Filter`,className:`row wrap gap-8`,children:de.map(([e,t])=>(0,B.jsxs)(`button`,{type:`button`,className:o.f===e?`chip-f on`:`chip-f`,"aria-pressed":o.f===e,onClick:()=>b({f:e}),children:[t,e===`needs`&&A>0?(0,B.jsxs)(`span`,{className:`mono`,children:[` `,A]}):null]},e))}),Z(`host`,`Host`,M),Z(`project`,`Project`,N),(0,B.jsx)(ee,{"aria-label":`Live sessions view`,children:[[`list`,`List`],[`garden`,`Garden`]].map(([e,t])=>(0,B.jsx)(`button`,{type:`button`,className:o.v===e?`on`:``,"aria-pressed":o.v===e,onClick:()=>b({v:e}),children:t},e))})]}),P&&o.f!==`needs`&&(0,B.jsxs)(`p`,{className:`dim act-sm`,children:[`Runs and gate asks carry no `,P,`; showing sessions only.`]}),R&&(e?!T&&o.f!==`needs`?null:L.length===0?o.f===`needs`?(0,B.jsx)(S,{title:`Nothing waits on you`}):(0,B.jsx)(S,{title:`No active sessions`,children:`Start an agent session and it appears here.`}):o.v===`garden`?(0,B.jsx)(oe,{sessions:L,collisions:e.collisions}):(0,B.jsx)(`div`,{className:`stack gap-12 act-live`,ref:k,children:L.map(e=>(0,B.jsx)(`div`,{"data-flip":F(e),children:(0,B.jsx)(ce,{s:e})},F(e)))}):(0,B.jsx)(v,{label:`Reading live sessions…`})),V.length>0&&(0,B.jsxs)(`section`,{className:`stack gap-12 act-live act-ended`,"aria-labelledby":`act-ended-h`,children:[(0,B.jsx)(`h2`,{id:`act-ended-h`,className:`act-lbl`,children:`Recently ended`}),H.map(e=>(0,B.jsx)(`div`,{children:(0,B.jsx)(ce,{s:e})},F(e))),V.length>be&&(0,B.jsx)(`button`,{type:`button`,className:`btn ghost sm`,"aria-expanded":d,onClick:()=>f(e=>!e),children:d?`Show fewer`:`Show all ${V.length}`})]}),o.f!==`needs`&&(0,B.jsx)(`section`,{"aria-label":`Feed`,className:`stack gap-16 act-feed`,ref:Y,children:q.map(e=>(0,B.jsxs)(`section`,{className:`card act-day`,children:[(0,B.jsxs)(`h3`,{className:`act-day-h`,children:[(0,B.jsx)(`span`,{children:e.title}),(0,B.jsx)(`span`,{className:`mono dim`,children:e.sum})]}),(0,B.jsxs)(`ul`,{className:`act-rows`,children:[e.runs.map(e=>(0,B.jsx)(ve,{job:e,longest:J},e.id)),e.gate&&(0,B.jsx)(ye,{gate:e.gate})]})]},e.key))})]})}export{Se as default};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-C1iE8mnY.js";import{t as r}from"./api-DLDVY3K-.js";import{s as i}from"./motion-RlUl1osO.js";import{A as a,B as o,D as s,Et as c,F as l,G as u,I as d,L as f,N as p,O as m,P as h,R as g,bt as _,it as v,j as y,k as b,ot as ee,rt as te,u as ne,wt as x}from"./index-Ck42AbRX.js";import{t as S}from"./EmptyState-CY5Pm2xy.js";import{_ as C,a as w,c as T,f as E,g as D,h as O,i as k,l as A,m as re,n as j,o as M,p as N,r as P,s as F,t as I,u as L,v as R}from"./Bonsai-DSwUbavu.js";import{t as ie}from"./usePoll-o8ul-Sog.js";var z=e(t(),1),B=n(),V=4,H=56*V,U=24,W=165,G=188,K=(e,t)=>e>0?Math.max(1,Math.floor((e-32+U)/(H+U))):Math.max(1,t),q=e=>e.status===`blocked`?`bad`:l(e)?`warn`:e.status===`busy`?`ok`:``,J=e=>{let t=A(e);return t==null?null:Math.round(t*100)};function Y(e,t,n){let r=s[e.status]||s.idle,i=t.pads.filter(e=>e.key!=null),a=t.pads.reduce((e,t)=>e+t.files.length,0)+t.fallen.reduce((e,t)=>e+t.files.length,0),o=J(e);return[`${e.title||y(e.cwd)||e.session_id}, ${e.chip||e.host||`unknown host`}, ${r.label}${e.phase?`, ${e.phase}`:``}`,`${e.turns||0} turns${o==null?``:`, context ${o} %`}${e.compactions?`, ${e.compactions} compactions`:``}`,i.length?`${i.length} sub-agent${i.length===1?``:`s`} running: ${i.map(e=>`${e.type||`agent`} (${e.files.length} file${e.files.length===1?``:`s`})`).join(`, `)}`:``,t.fallen.length?`${t.fallen.length} finished`:``,`${a} file${a===1?``:`s`} changed`,n.length?`shares ${n.length} file${n.length===1?``:`s`} with another session`:``,e.error?`error: ${e.error}`:``].filter(Boolean).join(`. `)}function X({s:e,t,mine:n}){let r=J(e);return(0,B.jsxs)(`div`,{className:`card gd-card`,children:[(0,B.jsxs)(`dl`,{className:`gd-facts`,children:[e.model&&(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`dt`,{children:`model`}),(0,B.jsx)(`dd`,{className:`mono`,children:e.model})]}),(0,B.jsx)(`dt`,{children:`turns`}),(0,B.jsx)(`dd`,{children:e.turns||0}),(0,B.jsx)(`dt`,{children:`context`}),(0,B.jsx)(`dd`,{children:r==null?`unknown`:`${r} %`}),(0,B.jsx)(`dt`,{children:`compactions`}),(0,B.jsx)(`dd`,{children:e.compactions||0})]}),t.fallen.length>0&&(0,B.jsxs)(`div`,{className:`dim act-xs`,children:[`finished: `,t.fallen.map(e=>`${e.type||`agent`} (${e.files.length})`).join(`, `)]}),n.map(e=>(0,B.jsxs)(`div`,{className:`act-xs ${e.kind===`same-worktree`?`t-bad`:`t-warn`}`,children:[`same file`,e.kind===`same-worktree`?``:`, other worktree`,`: `,e.path]},`${e.kind}:${e.path}`))]})}function Z({s:e,worktree:t,sakura:n,mine:r,pad:i,onHover:a}){let o=R(e,n),c=(0,z.useMemo)(()=>E(e,{sakura:n}),[o]),u=s[e.status]||s.idle,d=Array.isArray(e.loops)?e.loops[0]:null,f=e.status!==`idle`,p=F(e),m=e.title||y(e.cwd)||e.session_id,h=J(e),g=(0,z.useRef)(null),_=(0,z.useCallback)(e=>a(p,e,Q(g.current)),[a,p]);return(0,B.jsxs)(`a`,{ref:g,className:`gd-tree${l(e)?` gd-needs`:``}`,href:e.href||L(e.session_id),"aria-label":Y(e,c,r),"data-sid":e.session_id,onMouseEnter:e=>a(p,null,Q(e.currentTarget)),onMouseLeave:()=>a(null,null),onFocus:e=>a(p,null,Q(e.currentTarget)),onBlur:()=>a(null,null),onKeyDown:e=>k(e,c.pads.length,i,_),children:[(0,B.jsx)(P,{t:c,pad:i,swaying:f,onPad:_,px:V}),(0,B.jsxs)(`div`,{className:`gd-cap`,children:[(0,B.jsx)(`div`,{className:`gd-title`,title:m,children:m}),(0,B.jsxs)(`div`,{className:`row wrap gd-pills`,children:[(0,B.jsx)(`span`,{className:`badge mono`,title:`The install this session runs in`,children:e.chip||e.host||`?`}),(0,B.jsx)(`span`,{className:`badge ${q(e)}`,children:u.label}),t&&(0,B.jsxs)(`span`,{className:`badge mono`,children:[`⎇ `,t]}),d&&(0,B.jsxs)(`span`,{className:`badge`,children:[`↻ `,d.title,d.iteration==null?``:` ${d.iteration}`]}),e.attribution===!1&&(0,B.jsx)(`span`,{className:`badge`,title:`attribution unavailable on ${e.host}`,children:`no attrib.`})]}),(0,B.jsxs)(`div`,{className:`mono gd-meta`,children:[e.turns||0,` turns`,h==null?``:` · ${h}%`]})]})]})}function ae({pairs:e,count:t}){if(!e.length)return null;let n=t*H+(t-1)*U,r=e=>e*(H+U)+H/2;return(0,B.jsx)(`svg`,{className:`gd-threads`,width:n,height:56*V+20,"aria-hidden":`true`,children:e.map(({a:e,b:t,kind:n})=>{let[i,a]=e<t?[e,t]:[t,e],o=`gd-thread ${n===`same-worktree`?`red`:`amber`}`;if(a-i===1){let e=r(i)+30,t=r(a)-30,n=(e+t)/2;return(0,B.jsxs)(`g`,{className:o,children:[(0,B.jsx)(`path`,{d:`M${e} ${W} C${n} 179 ${n} 159 ${t} 169`}),(0,B.jsx)(`path`,{d:`M${e} 169 C${n} 159 ${n} 179 ${t} ${W}`})]},`${i}-${a}`)}return(0,B.jsx)(`g`,{className:o,children:(0,B.jsx)(`path`,{d:`M${r(i)} ${G} Q${(r(i)+r(a))/2} 222 ${r(a)} ${G}`})},`${i}-${a}`)})})}var Q=e=>e.offsetLeft;function oe({sessions:e,collisions:t}){let[n,r]=(0,z.useState)(M),[i,a]=(0,z.useState)(()=>new Set),o=()=>{let e=!n;r(e);try{window.localStorage.setItem(j,e?`1`:`0`)}catch{}},s=Array.isArray(t)?t:[],c=T(N(e)).map(e=>i.has(e.key)?{...e,collapsed:!1}:e),l=c.filter(e=>e.collapsed),u=e=>D(e,s);return(0,B.jsxs)(`section`,{className:`gd`,"aria-label":`Garden`,children:[(0,B.jsxs)(`div`,{className:`row between wrap gap-8 gd-head`,children:[(0,B.jsxs)(`span`,{className:`dim act-sm`,children:[e.length,` tree`,e.length===1?``:`s`,` · `,c.length,` `,c.length===1?`shelf`:`shelves`,` · a tree opens its session; hover or focus shows its details, and a tap or the arrow keys walk its pads`]}),(0,B.jsx)(`button`,{type:`button`,className:n?`chip-f on`:`chip-f`,"aria-pressed":n,onClick:o,children:`Pink blossom`})]}),l.length>0&&(0,B.jsx)(`div`,{className:`row wrap gap-8 gd-chips`,role:`group`,"aria-label":`Folded shelves`,children:l.map(e=>(0,B.jsxs)(`button`,{type:`button`,className:`chip-f`,"aria-expanded":!1,onClick:()=>a(t=>new Set(t).add(e.key)),children:[e.name,` · `,e.trees.length]},e.key))}),c.filter(e=>!e.collapsed).map(e=>(0,B.jsx)(se,{sh:e,sakura:n,cols:s,mineOf:u},e.key))]})}function se({sh:e,sakura:t,cols:n,mineOf:r}){let[i,a]=(0,z.useState)({sid:null,pad:null,x:0}),o=(0,z.useCallback)((e,t,n)=>a(r=>({sid:e,pad:t,x:n??(r.sid===e?r.x:0)})),[]),s=(0,z.useRef)(null),[c,l]=(0,z.useState)(0);(0,z.useLayoutEffect)(()=>{let e=s.current,t=()=>l(e.clientWidth);if(t(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t);let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let u=K(c,e.trees.length),d=C(e.trees,n),f=[];for(let t=0;t<e.trees.length;t+=u)f.push(t);let p=e.trees.findIndex(e=>F(e.s)===i.sid),m=p<0?null:e.trees[p].s,h=m?E(m,{sakura:t}):null,g=h&&i.pad!=null?h.pads[i.pad]:null,_=e.trees.length;return(0,B.jsxs)(`section`,{className:`gd-shelf`,"aria-label":`${e.name} shelf`,ref:s,children:[f.map(n=>{let a=e.trees.slice(n,n+u),s=n+a.length,c=d.filter(e=>e.a>=n&&e.a<s&&e.b>=n&&e.b<s).map(e=>({...e,a:e.a-n,b:e.b-n}));return(0,B.jsxs)(`div`,{className:`gd-row`,children:[(0,B.jsx)(`div`,{className:`gd-plank`,children:n===0&&(0,B.jsxs)(`h3`,{className:`gd-plate`,children:[e.name,` · `,_,` session`,_===1?``:`s`]})}),a.map(({s:e,worktree:n})=>(0,B.jsx)(Z,{s:e,worktree:n,sakura:t,mine:r(F(e)),pad:F(e)===i.sid?i.pad:null,onHover:o},F(e))),(0,B.jsx)(ae,{pairs:c,count:a.length}),m&&p>=n&&p<s&&(0,B.jsx)(`div`,{className:`gd-info`,"aria-hidden":`true`,style:{left:Math.max(0,i.x)},children:g?(0,B.jsx)(I,{pad:g}):(0,B.jsx)(X,{s:m,t:h,mine:r(F(m))})})]},n)}),(0,B.jsx)(`span`,{className:`sr-only`,role:`status`,children:w(g)})]})}var $=e=>e.catch(()=>null);function ce({s:e}){let t=(0,z.useId)(),n=e.todos,r=h(e);return(0,B.jsxs)(`a`,{className:`card pad-md act-card`,href:e.href||L(e.session_id),"aria-labelledby":`${t}-t ${t}-st`,"aria-describedby":r?`${t}-c`:void 0,children:[(0,B.jsxs)(m,{s:e,id:t,heading:e.title||y(e.cwd)||e.session_id,children:[e.chip&&(0,B.jsx)(`span`,{className:`badge mono`,title:`The install this session runs in`,children:e.chip}),(0,B.jsx)(_,{name:`chevron`,className:`glyph act-chev`})]}),n&&n.total>0&&(0,B.jsx)(`div`,{className:`act-foot`,children:(0,B.jsxs)(`span`,{className:`row gap-8 dim act-sm`,children:[(0,B.jsx)(a,{done:n.done,total:n.total}),`plan `,n.done,`/`,n.total]})}),(0,B.jsxs)(`div`,{className:`dim mono act-updated`,children:[`updated `,x(e.updated_at),` ago`]})]})}var le={blocked:`is blocked`,"waiting-input":`waits for your answer`};function ue(e,t){if(!Array.isArray(t))return``;let n=t.filter(l),r=e.current;return e.current=new Set(n.map(e=>`${F(e)}:${e.status}`)),r?n.filter(e=>!r.has(`${F(e)}:${e.status}`)).map(e=>`${e.title||y(e.cwd)||e.session_id} ${le[e.status]}`).join(`. `):``}var de=[[`all`,`All`],[`needs`,`Needs you`],[`runs`,`Runs`],[`gates`,`Gate asks`]];function fe(){let e=new URLSearchParams(window.location.hash.split(`?`)[1]||``),t=e.get(`f`);return{f:de.some(([e])=>e===t)?t:`all`,host:e.get(`host`)||``,project:e.get(`project`)||``,v:e.get(`v`)===`list`?`list`:`garden`}}function pe(e){let t=new URLSearchParams;e.f!==`all`&&t.set(`f`,e.f),e.v===`list`&&t.set(`v`,`list`),e.host&&t.set(`host`,e.host),e.project&&t.set(`project`,e.project);let n=t.toString();window.history.replaceState(null,``,`#/activity${n?`?${n}`:``}`)}function me({enabled:e,installs:t,onToggle:n}){let r=re(t);return(0,B.jsxs)(`section`,{className:`card pad-md act-track`,"aria-labelledby":`act-track-h`,children:[(0,B.jsx)(_,{name:`activity`,className:`glyph act-fixed`}),(0,B.jsxs)(`div`,{className:`act-grow`,children:[(0,B.jsx)(`h2`,{id:`act-track-h`,className:`act-track-title`,children:e?`Live sessions are on`:`Live sessions are off`}),!e&&(0,B.jsx)(`p`,{className:`dim act-sm act-track-p`,children:`Runs and gate asks below come from the job log and the gate ledger. Turn tracking on to see what each session is doing now.`})]}),(0,B.jsxs)(`ul`,{className:`stack gap-8 act-fixed act-sm`,"aria-label":`Tracking per install`,children:[t.length===0&&(0,B.jsx)(`li`,{className:`dim`,children:`No active install to track.`}),t.map((e,t)=>(0,B.jsxs)(`li`,{className:`row gap-10`,children:[(0,B.jsxs)(`span`,{id:`act-track-l${t}`,title:e.path,children:[`Track live sessions in `,(0,B.jsx)(`span`,{className:`mono`,children:r.get(e.install)})]}),(0,B.jsx)(`div`,{className:`sw-toggle${e.enabled?` on`:``}`,role:`switch`,"aria-checked":e.enabled,"aria-labelledby":`act-track-l${t}`,tabIndex:0,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.key===` `&&t.preventDefault(),n(e))}})]},e.install))]})]})}function he({jobs:e,loading:t}){let n=typeof e?.cap==`number`?e.cap:void 0,r=d(e?.jobs,{days:14,cap:n}),i=g(r.map(e=>e.nodata?`-`:e.n).join(`,`),`scaleY`),a=Math.max(1,...r.map(e=>e.n)),o=r.reduce((e,t)=>e+t.n,0),s=r.find(e=>!e.nodata),c=r.some(e=>e.nodata),l=`Runs per day: ${r.filter(e=>e.n).map(e=>`${e.n} on ${f(e.key)}`).join(`, `)||`none`}.`+(c?s?` Days before ${f(s.key)} are older than the runs the log keeps.`:` No run is in the log yet.`:``);return(0,B.jsxs)(`section`,{className:`card pad-md act-stat`,"aria-labelledby":`act-runs-h`,children:[(0,B.jsxs)(`div`,{className:`act-stat-head`,children:[(0,B.jsx)(`h2`,{id:`act-runs-h`,className:`act-lbl`,children:`Runs per day · 14 days`}),e&&(0,B.jsx)(`span`,{className:`act-big`,children:o})]}),t?(0,B.jsx)(v,{label:`Reading the job log…`}):e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`act-runs`,role:`img`,"aria-label":l,ref:i,children:r.map(e=>e.nodata?(0,B.jsx)(`i`,{className:`nodata`},e.key):e.n?(0,B.jsx)(`i`,{"data-sweep":!0,style:{height:`${e.n/a*100}%`},title:`${f(e.key)}: ${e.n}`},e.key):(0,B.jsx)(`i`,{className:`zero`},e.key))}),(0,B.jsxs)(`div`,{className:`mono act-axis`,"aria-hidden":`true`,children:[(0,B.jsx)(`span`,{children:f(r[0].key)}),(0,B.jsx)(`span`,{children:f(r[7].key)}),(0,B.jsx)(`span`,{children:`today`})]}),c&&(0,B.jsxs)(`span`,{className:`dim act-xs`,children:[`Hatched: older than the runs the log keeps`,n?` (last ${n})`:``,`.`]})]}):(0,B.jsx)(`p`,{className:`dim act-sm`,children:`The job log could not be read.`})]})}function ge({rows:e,gates:t,loading:n}){let r=e.reduce((e,t)=>e+t.n,0);return(0,B.jsxs)(`section`,{className:`card pad-md act-stat`,"aria-labelledby":`act-gates-h`,children:[(0,B.jsxs)(`div`,{className:`act-stat-head`,children:[(0,B.jsx)(`h2`,{id:`act-gates-h`,className:`act-lbl`,children:`Gate asks by rule · 30 days`}),t&&(0,B.jsx)(`span`,{className:`act-big`,children:r})]}),n?(0,B.jsx)(v,{label:`Reading the gate ledger…`}):e.length?(0,B.jsx)(`ul`,{className:`gate-rows`,children:e.slice(0,6).map((e,t)=>(0,B.jsxs)(`li`,{children:[(0,B.jsxs)(`span`,{className:`act-ell`,children:[e.name,` `,(0,B.jsx)(`span`,{className:`mono dim act-xs`,children:e.rule})]}),(0,B.jsx)(b,{vals:e.per_day,i:t,sweep:!0}),(0,B.jsx)(`span`,{className:`mono`,children:e.n})]},e.rule))}):(0,B.jsx)(`p`,{className:`dim act-sm`,children:t?`No gate asked in 30 days.`:`The gate ledger could not be read.`})]})}var _e={done:[`ok`,`done`],failed:[`bad`,`failed`],running:[``,`running`]};function ve({job:e,longest:t}){let n=o(e),r=e.duration?Math.round(e.duration*10)/10:0,[i,a]=_e[e.status]||[``,e.status||`…`],s=e.status===`running`?`Still running`:r?`Took ${r} second${r===1?``:`s`}`:`No duration`,c=e.started?new Date(e.started*1e3).toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):`—`;return(0,B.jsxs)(`li`,{className:`act-row`,children:[(0,B.jsx)(`span`,{className:`mono dim act-xs`,children:c}),(0,B.jsx)(_,{name:`play`,className:`glyph act-glyph`}),(0,B.jsxs)(`span`,{className:`act-what`,children:[(0,B.jsx)(`span`,{className:`act-row-title`,children:n.verb}),n.scope&&(0,B.jsx)(`span`,{className:`dim act-xs act-ell`,title:n.command,children:n.scope})]}),(0,B.jsx)(`span`,{className:`act-dur`,role:`img`,"aria-label":s,children:(0,B.jsx)(`span`,{"data-sweep":!0,style:{width:t>0?`${(e.duration||0)/t*100}%`:`0%`}})}),(0,B.jsx)(`span`,{className:`badge ${i}`,children:a})]})}function ye({gate:e}){return(0,B.jsxs)(`li`,{className:`act-row gate`,children:[(0,B.jsx)(`span`,{className:`mono dim act-xs`,children:`—`}),(0,B.jsx)(_,{name:`rule`,className:`glyph act-glyph t-warn`}),(0,B.jsxs)(`span`,{className:`act-what`,children:[(0,B.jsx)(`span`,{className:`act-row-title`,children:e.title}),(0,B.jsx)(`span`,{className:`dim act-xs`,children:`Gate ledger`})]}),(0,B.jsx)(`span`,{className:`act-dur-none`,"aria-hidden":`true`}),(0,B.jsx)(`span`,{className:`badge warn`,children:`asked`})]})}var be=5,xe=(e,t)=>[...new Set([...e.filter(Boolean),t].filter(Boolean))];function Se(){let[e,t]=(0,z.useState)(null),[n,a]=(0,z.useState)(``),[o,s]=(0,z.useState)(fe),[d,f]=(0,z.useState)(!1),[m,h]=(0,z.useState)(``),_=(0,z.useRef)(null),b=e=>{let t={...o,...e};s(t),pe(t)};ie(e=>r.activity().then(n=>{if(e()){t(n),a(``);let e=ue(_,n?.activity);e&&h(t=>t===e?e+`\xA0`:e)}},t=>{e()&&a(t.message)}),2e3,[]);let x=c(()=>$(r.jobs()),[]),C=c(()=>$(r.gates()),[]),w=c(()=>$(r.catalog(`laws`)),[]),T=!e||e.enabled!==!1,E=Array.isArray(e?.installs)?e.installs:[],D=O(e?.activity,E).sort((e,t)=>e.session_id<t.session_id?-1:+(e.session_id>t.session_id)),k=i(),A=T&&e?D.filter(l).length:null,re=new Set(D.map(F)),j=o.v===`list`?O(e?.ended,E).filter(e=>!re.has(F(e))):[],M=xe([...D,...j].map(e=>e.host),o.host),N=xe([...D,...j].map(e=>y(e.cwd)),o.project),P=o.host&&o.project?`host or project`:o.host?`host`:o.project?`project`:``,I=e=>(!o.host||e.host===o.host)&&(!o.project||y(e.cwd)===o.project),L=D.filter(e=>I(e)&&(o.f!==`needs`||l(e))),R=o.f===`all`||o.f===`needs`,V=o.f===`all`&&T?j.filter(I):[],H=d?V:V.slice(0,be),U=!P&&(o.f===`all`||o.f===`runs`),W=!P&&(o.f===`all`||o.f===`gates`),G=x.data?.jobs||[],K=ne(C.data,w.data),q=p(G,K,C.data?.days).map(e=>({...e,runs:U?e.runs:[],gate:W?e.gate:null})).filter(e=>e.runs.length||e.gate),J=Math.max(0,...G.map(e=>e.duration||0)),Y=g(q.flatMap(e=>e.runs.map(e=>`${e.id}:${e.duration}`)).join(`,`),`scaleX`),X=async e=>{let n=!e.enabled;try{let i=await r.activityToggle(n,{host:e.host,path:e.path});if(i.ok===!1){a(i.error||`Could not change tracking`);return}let o=t=>i.enabled?t||[]:(t||[]).flatMap(t=>{let n=(t.installs||[t.install]).filter(t=>t!==e.install);return n.length?[{...t,install:n[0],installs:n}]:[]});t(t=>{let n=(t?.installs||[]).map(t=>t.install===e.install?{...t,enabled:i.enabled}:t);return{...t||{},installs:n,enabled:n.length===0||n.some(e=>e.enabled),activity:o(t?.activity),ended:o(t?.ended)}}),a(``)}catch(e){a(e.message)}},Z=(e,t,n)=>(0,B.jsxs)(`span`,{className:`row gap-8 act-sm`,children:[(0,B.jsx)(`label`,{htmlFor:`act-f-${e}`,children:t}),(0,B.jsxs)(`select`,{id:`act-f-${e}`,className:`sel`,value:o[e],disabled:n.length===0,title:n.length===0?`No source carries a ${e} yet`:void 0,onChange:t=>b({[e]:t.target.value}),children:[(0,B.jsxs)(`option`,{value:``,children:[`All `,e===`host`?`hosts`:`projects`]}),n.map(e=>(0,B.jsx)(`option`,{value:e,children:e},e))]})]});return(0,B.jsxs)(`div`,{className:`page-fill`,children:[(0,B.jsx)(u,{title:`Activity`,sub:`What your agents ran, what the gates asked, and which sessions are waiting on you.`}),(0,B.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,children:m}),n&&(0,B.jsx)(`div`,{className:`act-gap`,children:(0,B.jsx)(te,{error:n})}),e&&(0,B.jsx)(me,{enabled:T,installs:E,onToggle:X}),(0,B.jsxs)(`div`,{className:`act-today`,children:[(0,B.jsx)(he,{jobs:x.data,loading:x.loading}),(0,B.jsx)(ge,{rows:K,gates:C.data,loading:C.loading}),(0,B.jsxs)(`section`,{className:`card pad-md act-stat`,"aria-labelledby":`act-wait-h`,children:[(0,B.jsx)(`h2`,{id:`act-wait-h`,className:`act-lbl`,children:`Waiting on you`}),!e&&!n?(0,B.jsx)(v,{}):e?(0,B.jsxs)(B.Fragment,{children:[T?(0,B.jsxs)(`span`,{className:`act-big act-wait`,children:[A,` `,(0,B.jsx)(`span`,{className:`dim act-sm`,children:A===1?`session`:`sessions`})]}):null,(0,B.jsx)(`p`,{className:`dim act-sm`,children:T?`A session that waits on an approval or on your answer counts here.`:`Turn tracking on to count the sessions that wait on you.`})]}):(0,B.jsx)(`p`,{className:`dim act-sm`,children:`The sessions could not be read.`})]})]}),(0,B.jsxs)(`div`,{className:`row wrap gap-8 act-filters`,children:[(0,B.jsx)(`div`,{role:`group`,"aria-label":`Filter`,className:`row wrap gap-8`,children:de.map(([e,t])=>(0,B.jsxs)(`button`,{type:`button`,className:o.f===e?`chip-f on`:`chip-f`,"aria-pressed":o.f===e,onClick:()=>b({f:e}),children:[t,e===`needs`&&A>0?(0,B.jsxs)(`span`,{className:`mono`,children:[` `,A]}):null]},e))}),Z(`host`,`Host`,M),Z(`project`,`Project`,N),(0,B.jsx)(ee,{"aria-label":`Live sessions view`,children:[[`list`,`List`],[`garden`,`Garden`]].map(([e,t])=>(0,B.jsx)(`button`,{type:`button`,className:o.v===e?`on`:``,"aria-pressed":o.v===e,onClick:()=>b({v:e}),children:t},e))})]}),P&&o.f!==`needs`&&(0,B.jsxs)(`p`,{className:`dim act-sm`,children:[`Runs and gate asks carry no `,P,`; showing sessions only.`]}),R&&(e?!T&&o.f!==`needs`?null:L.length===0?o.f===`needs`?(0,B.jsx)(S,{title:`Nothing waits on you`}):(0,B.jsx)(S,{title:`No active sessions`,children:`Start an agent session and it appears here.`}):o.v===`garden`?(0,B.jsx)(oe,{sessions:L,collisions:e.collisions}):(0,B.jsx)(`div`,{className:`stack gap-12 act-live`,ref:k,children:L.map(e=>(0,B.jsx)(`div`,{"data-flip":F(e),children:(0,B.jsx)(ce,{s:e})},F(e)))}):(0,B.jsx)(v,{label:`Reading live sessions…`})),V.length>0&&(0,B.jsxs)(`section`,{className:`stack gap-12 act-live act-ended`,"aria-labelledby":`act-ended-h`,children:[(0,B.jsx)(`h2`,{id:`act-ended-h`,className:`act-lbl`,children:`Recently ended`}),H.map(e=>(0,B.jsx)(`div`,{children:(0,B.jsx)(ce,{s:e})},F(e))),V.length>be&&(0,B.jsx)(`button`,{type:`button`,className:`btn ghost sm`,"aria-expanded":d,onClick:()=>f(e=>!e),children:d?`Show fewer`:`Show all ${V.length}`})]}),o.f!==`needs`&&(0,B.jsx)(`section`,{"aria-label":`Feed`,className:`stack gap-16 act-feed`,ref:Y,children:q.map(e=>(0,B.jsxs)(`section`,{className:`card act-day`,children:[(0,B.jsxs)(`h3`,{className:`act-day-h`,children:[(0,B.jsx)(`span`,{children:e.title}),(0,B.jsx)(`span`,{className:`mono dim`,children:e.sum})]}),(0,B.jsxs)(`ul`,{className:`act-rows`,children:[e.runs.map(e=>(0,B.jsx)(ve,{job:e,longest:J},e.id)),e.gate&&(0,B.jsx)(ye,{gate:e.gate})]})]},e.key))})]})}export{Se as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-C1iE8mnY.js";import{t as r}from"./api-DLDVY3K-.js";import{F as i,G as a,M as o,O as s,bt as c,it as l,j as u,rt as d,wt as f}from"./index-BQwOmbor.js";import{t as p}from"./EmptyState-CY5Pm2xy.js";import{a as m,d as h,f as g,i as _,l as v,o as y,r as b,t as x,v as S}from"./Bonsai-hiG_gGNU.js";import{t as C}from"./usePoll-o8ul-Sog.js";var w=e(t(),1),T=n();function E(e){return e.kind===`tool`?e.status===`error`?`bad`:e.status===`completed`?`ok`:`acc`:{retry:`warn`,error:`bad`,subtask:`acc`,text:`acc`}[e.kind]||``}function D({rec:e}){let t=e.who===`you`,n=[];t||(e.kind===`tool`&&e.ms!=null&&n.push(`${(e.ms/1e3).toFixed(1)}s`),e.kind===`step`&&(e.tokens&&n.push(`${o(e.tokens)} tok`),e.cost&&n.push(`$${e.cost.toFixed(2)}`)),e.kind===`subtask`&&e.agent&&n.unshift(e.agent));let r=!t&&(e.kind===`text`||e.kind===`thinking`||e.kind===`step`),i=t?e.text:e.label||e.snippet||e.kind;return(0,T.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,T.jsx)(`span`,{className:`badge act-who ${t?``:`acc`}`,children:t?`you`:`agent`}),(0,T.jsxs)(`div`,{className:`act-grow act-sm`,children:[!t&&(0,T.jsx)(`span`,{className:`feed-dot act-inline-dot ${E(e)||`acc`}`}),e.kind===`thinking`&&(0,T.jsx)(`span`,{className:`dim`,children:`thinking: `}),r?(0,T.jsx)(`span`,{className:`dim`,children:i}):t?i:(0,T.jsx)(`b`,{children:i}),e.error&&(0,T.jsxs)(`span`,{className:`dim`,children:[`: `,e.error]})]}),n.length>0&&(0,T.jsx)(`span`,{className:`dim mono act-xs act-fixed`,children:n.join(` · `)}),e.t?(0,T.jsx)(`time`,{className:`mono dim act-xs act-fixed`,dateTime:new Date(e.t).toISOString(),title:`${f(e.t/1e3)} ago`,children:new Date(e.t).toTimeString().slice(0,8)}):null]})}function O({turns:e}){return!e||e.length===0?(0,T.jsx)(`div`,{className:`dim act-sm`,children:`No conversation captured yet.`}):(0,T.jsx)(`div`,{className:`stack gap-12`,children:e.map((e,t)=>{let n=e.role===`user`;return(0,T.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,T.jsx)(`span`,{className:`badge act-who ${n?``:`acc`}`,children:n?`you`:`agent`}),(0,T.jsx)(`div`,{className:`act-min act-sm${n?``:` muted`}`,children:e.text})]},t)})})}var k=5;function A({s:e}){let[t]=(0,w.useState)(y),[n,r]=(0,w.useState)(null),a=!!e.ended,o=a?{...e,status:i(e)?`busy`:e.status,error:null}:e,s=S(o,t),c=(0,w.useMemo)(()=>g(o,{sakura:t}),[s]),l=(0,w.useCallback)(e=>r(e),[]),u=v(e),d=Number(e.turns)||0,f=Number(e.compactions)||0,p=[`${d} turn${d===1?``:`s`}`,`context ${u==null?`unknown`:`${Math.round(u*100)} %`}`,`${f} compaction${f===1?``:`s`}`,`sub-agents: ${c.pads.filter(e=>e.key!=null).length} ${a?`unfinished`:`running`}, ${c.fallen.length} finished`].join(` · `),h=n==null?null:c.pads[n];return(0,T.jsxs)(`div`,{className:`card pad-md act-mt gd-detail${!a&&i(e)?` gd-needs`:``}`,children:[(0,T.jsx)(`div`,{role:`group`,tabIndex:0,"aria-label":`Bonsai pads, arrow keys walk them`,onKeyDown:e=>_(e,c.pads.length,n,l),children:(0,T.jsx)(b,{t:c,pad:n,swaying:!a&&e.status!==`idle`,onPad:l,px:k,label:`Bonsai of this session${a?`, ended`:``}: ${p}`})}),(0,T.jsxs)(`div`,{className:`stack gap-8 act-min`,children:[a&&(0,T.jsx)(`span`,{className:`dim act-xs`,children:`ended`}),(0,T.jsx)(`div`,{className:`dim act-sm`,children:p}),(0,T.jsx)(`span`,{className:`sr-only`,role:`status`,children:m(h)}),h?(0,T.jsx)(x,{pad:h}):(0,T.jsx)(`div`,{className:`dim act-xs`,children:`Hover or tap a pad, or use the arrow keys, for its files.`})]})]})}function j({sid:e}){let{sid:t,install:n}=h(e,window.location.hash),[i,o]=(0,w.useState)(null),[m,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(!1),x=(0,w.useId)();C(e=>_?void 0:r.activityDetail(t,n).then(t=>{e()&&(o(t),g(``),v(!1))},t=>{e()&&(t.status===404?v(!0):g(t.message))}),2e3,[t,_]);let S=(0,T.jsxs)(`a`,{className:`btn ghost sm act-back`,href:`#/activity`,children:[(0,T.jsx)(c,{name:`arrow`}),` Activity`]});if(_)return(0,T.jsxs)(`div`,{className:`page-fill`,children:[S,(0,T.jsx)(p,{title:`Session ended`,action:(0,T.jsx)(`a`,{href:`#/activity`,children:`Back to Activity`}),children:`It's no longer live.`})]});if(!i)return(0,T.jsxs)(`div`,{className:`page-fill`,children:[S,m?(0,T.jsx)(d,{error:m}):(0,T.jsx)(l,{label:`Loading session…`})]});let E=i.session,k=E.files,j=E.todos,M=!!(k&&k.items&&k.items.length>0),N=!!(j&&j.items&&j.items.length>0),P=i.conversation||[],F=i.timeline||[],I=[...P.filter(e=>e.role===`user`).map(e=>({who:`you`,text:e.text,t:e.t||0})),...F.map(e=>({...e,who:`agent`}))].sort((e,t)=>(e.t||0)-(t.t||0));return(0,T.jsxs)(`div`,{className:`page-fill`,children:[S,(0,T.jsx)(a,{title:E.title||u(E.cwd)||E.session_id,sub:E.cwd?(0,T.jsx)(`span`,{className:`mono act-cwd`,title:E.cwd,children:E.cwd}):null}),m&&(0,T.jsx)(`div`,{className:`act-gap`,children:(0,T.jsx)(d,{error:m})}),(0,T.jsxs)(`div`,{className:`card pad-md`,children:[(0,T.jsx)(s,{s:E}),(0,T.jsxs)(`div`,{className:`dim act-updated`,children:[`updated `,f(E.updated_at),` ago`]})]}),(0,T.jsx)(A,{s:E}),(M||N)&&(0,T.jsxs)(`div`,{className:`grid gap-12 act-panels${M&&N?` two`:``}`,children:[M&&(0,T.jsxs)(`div`,{className:`card pad-md`,children:[(0,T.jsx)(`div`,{className:`card-head`,children:(0,T.jsxs)(`h2`,{children:[`Files touched `,(0,T.jsxs)(`span`,{className:`dim`,children:[`(`,k.count,`)`]})]})}),(0,T.jsx)(`div`,{className:`stack act-list`,children:k.items.map(e=>(0,T.jsxs)(`div`,{className:`row between gap-12 act-sm`,children:[(0,T.jsx)(`span`,{className:`mono act-ell act-grow`,title:e.file,children:e.file}),(0,T.jsxs)(`span`,{className:`act-fixed`,children:[(0,T.jsxs)(`span`,{className:`t-good`,children:[`+`,e.additions]}),` `,(0,T.jsxs)(`span`,{className:`t-bad`,children:[`−`,e.deletions]})]})]},e.file))})]}),N&&(0,T.jsxs)(`div`,{className:`card pad-md`,children:[(0,T.jsx)(`div`,{className:`card-head`,children:(0,T.jsxs)(`h2`,{children:[`Plan`,` `,(0,T.jsxs)(`span`,{className:`dim`,children:[`(`,j.done,`/`,j.total,`)`]})]})}),(0,T.jsx)(`div`,{className:`stack act-list`,children:j.items.map((e,t)=>(0,T.jsxs)(`div`,{className:`row gap-8 act-sm`,children:[(0,T.jsx)(`span`,{className:`feed-dot ${e.status===`completed`?`ok`:e.status===`in_progress`?`acc`:``}`}),(0,T.jsx)(`span`,{className:e.status===`completed`?`act-done`:void 0,children:e.content})]},t))})]})]}),(0,T.jsxs)(`div`,{className:`card pad-md act-mt`,children:[(0,T.jsxs)(`div`,{className:`card-head act-tl-head`,children:[(0,T.jsx)(`h2`,{children:`Timeline`}),F.length>0&&(0,T.jsx)(`button`,{className:`btn ghost sm`,"aria-expanded":y,"aria-controls":x,onClick:()=>b(e=>!e),children:y?`Show conversation`:`Show full stream (${I.length})`})]}),(0,T.jsx)(`div`,{id:x,children:y?(0,T.jsx)(`div`,{className:`stack gap-12`,children:I.map((e,t)=>(0,T.jsx)(D,{rec:e},t))}):(0,T.jsx)(O,{turns:P})})]})]})}export{A as SessionTree,j as default};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-C1iE8mnY.js";import{t as r}from"./api-DLDVY3K-.js";import{F as i,G as a,M as o,O as s,bt as c,it as l,j as u,rt as d,wt as f}from"./index-Ck42AbRX.js";import{t as p}from"./EmptyState-CY5Pm2xy.js";import{a as m,d as h,f as g,i as _,l as v,o as y,r as b,t as x,v as S}from"./Bonsai-DSwUbavu.js";import{t as C}from"./usePoll-o8ul-Sog.js";var w=e(t(),1),T=n();function E(e){return e.kind===`tool`?e.status===`error`?`bad`:e.status===`completed`?`ok`:`acc`:{retry:`warn`,error:`bad`,subtask:`acc`,text:`acc`}[e.kind]||``}function D({rec:e}){let t=e.who===`you`,n=[];t||(e.kind===`tool`&&e.ms!=null&&n.push(`${(e.ms/1e3).toFixed(1)}s`),e.kind===`step`&&(e.tokens&&n.push(`${o(e.tokens)} tok`),e.cost&&n.push(`$${e.cost.toFixed(2)}`)),e.kind===`subtask`&&e.agent&&n.unshift(e.agent));let r=!t&&(e.kind===`text`||e.kind===`thinking`||e.kind===`step`),i=t?e.text:e.label||e.snippet||e.kind;return(0,T.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,T.jsx)(`span`,{className:`badge act-who ${t?``:`acc`}`,children:t?`you`:`agent`}),(0,T.jsxs)(`div`,{className:`act-grow act-sm`,children:[!t&&(0,T.jsx)(`span`,{className:`feed-dot act-inline-dot ${E(e)||`acc`}`}),e.kind===`thinking`&&(0,T.jsx)(`span`,{className:`dim`,children:`thinking: `}),r?(0,T.jsx)(`span`,{className:`dim`,children:i}):t?i:(0,T.jsx)(`b`,{children:i}),e.error&&(0,T.jsxs)(`span`,{className:`dim`,children:[`: `,e.error]})]}),n.length>0&&(0,T.jsx)(`span`,{className:`dim mono act-xs act-fixed`,children:n.join(` · `)}),e.t?(0,T.jsx)(`time`,{className:`mono dim act-xs act-fixed`,dateTime:new Date(e.t).toISOString(),title:`${f(e.t/1e3)} ago`,children:new Date(e.t).toTimeString().slice(0,8)}):null]})}function O({turns:e}){return!e||e.length===0?(0,T.jsx)(`div`,{className:`dim act-sm`,children:`No conversation captured yet.`}):(0,T.jsx)(`div`,{className:`stack gap-12`,children:e.map((e,t)=>{let n=e.role===`user`;return(0,T.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,T.jsx)(`span`,{className:`badge act-who ${n?``:`acc`}`,children:n?`you`:`agent`}),(0,T.jsx)(`div`,{className:`act-min act-sm${n?``:` muted`}`,children:e.text})]},t)})})}var k=5;function A({s:e}){let[t]=(0,w.useState)(y),[n,r]=(0,w.useState)(null),a=!!e.ended,o=a?{...e,status:i(e)?`busy`:e.status,error:null}:e,s=S(o,t),c=(0,w.useMemo)(()=>g(o,{sakura:t}),[s]),l=(0,w.useCallback)(e=>r(e),[]),u=v(e),d=Number(e.turns)||0,f=Number(e.compactions)||0,p=[`${d} turn${d===1?``:`s`}`,`context ${u==null?`unknown`:`${Math.round(u*100)} %`}`,`${f} compaction${f===1?``:`s`}`,`sub-agents: ${c.pads.filter(e=>e.key!=null).length} ${a?`unfinished`:`running`}, ${c.fallen.length} finished`].join(` · `),h=n==null?null:c.pads[n];return(0,T.jsxs)(`div`,{className:`card pad-md act-mt gd-detail${!a&&i(e)?` gd-needs`:``}`,children:[(0,T.jsx)(`div`,{role:`group`,tabIndex:0,"aria-label":`Bonsai pads, arrow keys walk them`,onKeyDown:e=>_(e,c.pads.length,n,l),children:(0,T.jsx)(b,{t:c,pad:n,swaying:!a&&e.status!==`idle`,onPad:l,px:k,label:`Bonsai of this session${a?`, ended`:``}: ${p}`})}),(0,T.jsxs)(`div`,{className:`stack gap-8 act-min`,children:[a&&(0,T.jsx)(`span`,{className:`dim act-xs`,children:`ended`}),(0,T.jsx)(`div`,{className:`dim act-sm`,children:p}),(0,T.jsx)(`span`,{className:`sr-only`,role:`status`,children:m(h)}),h?(0,T.jsx)(x,{pad:h}):(0,T.jsx)(`div`,{className:`dim act-xs`,children:`Hover or tap a pad, or use the arrow keys, for its files.`})]})]})}function j({sid:e}){let{sid:t,install:n}=h(e,window.location.hash),[i,o]=(0,w.useState)(null),[m,g]=(0,w.useState)(``),[_,v]=(0,w.useState)(!1),[y,b]=(0,w.useState)(!1),x=(0,w.useId)();C(e=>_?void 0:r.activityDetail(t,n).then(t=>{e()&&(o(t),g(``),v(!1))},t=>{e()&&(t.status===404?v(!0):g(t.message))}),2e3,[t,_]);let S=(0,T.jsxs)(`a`,{className:`btn ghost sm act-back`,href:`#/activity`,children:[(0,T.jsx)(c,{name:`arrow`}),` Activity`]});if(_)return(0,T.jsxs)(`div`,{className:`page-fill`,children:[S,(0,T.jsx)(p,{title:`Session ended`,action:(0,T.jsx)(`a`,{href:`#/activity`,children:`Back to Activity`}),children:`It's no longer live.`})]});if(!i)return(0,T.jsxs)(`div`,{className:`page-fill`,children:[S,m?(0,T.jsx)(d,{error:m}):(0,T.jsx)(l,{label:`Loading session…`})]});let E=i.session,k=E.files,j=E.todos,M=!!(k&&k.items&&k.items.length>0),N=!!(j&&j.items&&j.items.length>0),P=i.conversation||[],F=i.timeline||[],I=[...P.filter(e=>e.role===`user`).map(e=>({who:`you`,text:e.text,t:e.t||0})),...F.map(e=>({...e,who:`agent`}))].sort((e,t)=>(e.t||0)-(t.t||0));return(0,T.jsxs)(`div`,{className:`page-fill`,children:[S,(0,T.jsx)(a,{title:E.title||u(E.cwd)||E.session_id,sub:E.cwd?(0,T.jsx)(`span`,{className:`mono act-cwd`,title:E.cwd,children:E.cwd}):null}),m&&(0,T.jsx)(`div`,{className:`act-gap`,children:(0,T.jsx)(d,{error:m})}),(0,T.jsxs)(`div`,{className:`card pad-md`,children:[(0,T.jsx)(s,{s:E}),(0,T.jsxs)(`div`,{className:`dim act-updated`,children:[`updated `,f(E.updated_at),` ago`]})]}),(0,T.jsx)(A,{s:E}),(M||N)&&(0,T.jsxs)(`div`,{className:`grid gap-12 act-panels${M&&N?` two`:``}`,children:[M&&(0,T.jsxs)(`div`,{className:`card pad-md`,children:[(0,T.jsx)(`div`,{className:`card-head`,children:(0,T.jsxs)(`h2`,{children:[`Files touched `,(0,T.jsxs)(`span`,{className:`dim`,children:[`(`,k.count,`)`]})]})}),(0,T.jsx)(`div`,{className:`stack act-list`,children:k.items.map(e=>(0,T.jsxs)(`div`,{className:`row between gap-12 act-sm`,children:[(0,T.jsx)(`span`,{className:`mono act-ell act-grow`,title:e.file,children:e.file}),(0,T.jsxs)(`span`,{className:`act-fixed`,children:[(0,T.jsxs)(`span`,{className:`t-good`,children:[`+`,e.additions]}),` `,(0,T.jsxs)(`span`,{className:`t-bad`,children:[`−`,e.deletions]})]})]},e.file))})]}),N&&(0,T.jsxs)(`div`,{className:`card pad-md`,children:[(0,T.jsx)(`div`,{className:`card-head`,children:(0,T.jsxs)(`h2`,{children:[`Plan`,` `,(0,T.jsxs)(`span`,{className:`dim`,children:[`(`,j.done,`/`,j.total,`)`]})]})}),(0,T.jsx)(`div`,{className:`stack act-list`,children:j.items.map((e,t)=>(0,T.jsxs)(`div`,{className:`row gap-8 act-sm`,children:[(0,T.jsx)(`span`,{className:`feed-dot ${e.status===`completed`?`ok`:e.status===`in_progress`?`acc`:``}`}),(0,T.jsx)(`span`,{className:e.status===`completed`?`act-done`:void 0,children:e.content})]},t))})]})]}),(0,T.jsxs)(`div`,{className:`card pad-md act-mt`,children:[(0,T.jsxs)(`div`,{className:`card-head act-tl-head`,children:[(0,T.jsx)(`h2`,{children:`Timeline`}),F.length>0&&(0,T.jsx)(`button`,{className:`btn ghost sm`,"aria-expanded":y,"aria-controls":x,onClick:()=>b(e=>!e),children:y?`Show conversation`:`Show full stream (${I.length})`})]}),(0,T.jsx)(`div`,{id:x,children:y?(0,T.jsx)(`div`,{className:`stack gap-12`,children:I.map((e,t)=>(0,T.jsx)(D,{rec:e},t))}):(0,T.jsx)(O,{turns:P})})]})]})}export{A as SessionTree,j as default};