geneseed 6.0.0 → 6.0.1

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 (37) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/SHIPPED.md +1 -1
  3. package/docs/concepts/agents.md +2 -0
  4. package/harness.config.json +1 -1
  5. package/js/README.md +1 -0
  6. package/js/hosts/native.mjs +27 -12
  7. package/js/web/agent-models-api.mjs +172 -0
  8. package/js/web/routes.mjs +5 -1
  9. package/package.json +1 -1
  10. package/web/dist/assets/{ActiveLoops-DOJCPPPc.js → ActiveLoops-6p44eD86.js} +1 -1
  11. package/web/dist/assets/{Activity-bUSPM3Dl.js → Activity-CIgrq5R1.js} +1 -1
  12. package/web/dist/assets/{ActivityDetail-AHRoXeFN.js → ActivityDetail-Brqv1u4f.js} +1 -1
  13. package/web/dist/assets/{Bonsai-B5XY9pid.js → Bonsai-8NtlFrPO.js} +1 -1
  14. package/web/dist/assets/{CopyButton-C0wwRR9H.js → CopyButton-BHqKgdjJ.js} +1 -1
  15. package/web/dist/assets/{Dashboard-DPAA96EI.js → Dashboard-CoveJ_-U.js} +2 -2
  16. package/web/dist/assets/{Docs-CpGDq165.js → Docs-C1jzrFnD.js} +1 -1
  17. package/web/dist/assets/{Factories-cNhETa5Q.js → Factories-D5pLnt5S.js} +1 -1
  18. package/web/dist/assets/{GreenhouseView-DO3ADmT9.js → GreenhouseView-ofAQ-V5h.js} +1 -1
  19. package/web/dist/assets/Installs-DpWgyT5j.js +3 -0
  20. package/web/dist/assets/{JournalView--W-Lw_V9.js → JournalView-CsuN3_B-.js} +1 -1
  21. package/web/dist/assets/{Kits-ChfehxY6.js → Kits-P4xspDuN.js} +1 -1
  22. package/web/dist/assets/{Laws-CNxYmV36.js → Laws-DK3OwGDl.js} +1 -1
  23. package/web/dist/assets/{LibRows-CiPvsRYB.js → LibRows-CGO25X3D.js} +1 -1
  24. package/web/dist/assets/Library-e-94YED6.js +3 -0
  25. package/web/dist/assets/{Loops-DAblKkyq.js → Loops-C9DSBj-A.js} +1 -1
  26. package/web/dist/assets/{OperatorHudView-QtSaSyYm.js → OperatorHudView-Cc8mlViW.js} +1 -1
  27. package/web/dist/assets/{Personal-DxSGv638.js → Personal-DVh2jYPO.js} +1 -1
  28. package/web/dist/assets/{Settings-CgTbhvRv.js → Settings-CknBI-Fx.js} +1 -1
  29. package/web/dist/assets/{Tabs-Cf4X1hdz.js → Tabs-C30JrkJH.js} +1 -1
  30. package/web/dist/assets/api-DxwG8y94.js +1 -0
  31. package/web/dist/assets/index-CUJ8AaAF.css +1 -0
  32. package/web/dist/assets/{index-B_pTwZra.js → index-MB7E-va_.js} +3 -3
  33. package/web/dist/index.html +3 -3
  34. package/web/dist/assets/Installs-D3dDyq10.js +0 -3
  35. package/web/dist/assets/Library-BxQvbwVU.js +0 -3
  36. package/web/dist/assets/api-CZ-x0iWG.js +0 -1
  37. package/web/dist/assets/index-CzfImiYb.css +0 -1
package/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ label. For the capability ↔ spec map, see [SHIPPED.md](SHIPPED.md).
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [6.0.1] — 2026-11-18
12
+
13
+ ### Added
14
+
15
+ - **The console sets the sub-agent model tiers.** On a Claude Code install, the Installs panel has a *Model tiers* switch (off or auto) beside the context window, kept by the same rebuild. With auto on, an editor shows the models of the standard and light tiers (an empty field means inherit; strong is always your session model) and saves them into `agent-overrides.json` key by key: your other keys are kept, and a file that does not parse is refused, never rewritten. It says a rebuild applies the change and offers it, and shows the Bedrock/Vertex alias warning when the console's own environment has it. In the Library, each agent shows its tier, the model it resolves to on that install and why, and a field to pin a model (an empty pin removes only `model`). New `GET` and `POST /api/agent-models`. The precedence (pin, then the map, then the tier default, then inherit) now lives in one function, `claudeAgentModel`, which the emit and the console both use.
16
+
17
+ ### Fixed
18
+
19
+ - **Console text fields follow the theme.** A text input with no page-specific style (the new tier and pin fields, the profile and onboarding fields) showed the browser's white box in the dark theme. It now has the select's look and keeps its focus outline.
20
+
11
21
  ## [6.0.0] — 2026-11-17
12
22
 
13
23
  ### Added
package/SHIPPED.md CHANGED
@@ -20,7 +20,7 @@ historical references, not files distributed with the repo.
20
20
  > **On version numbers.** [`harness.config.json`](harness.config.json)'s `version` is a
21
21
  > human-readable label only. The canonical identity of an installed harness is the
22
22
  > **source fingerprint** stamped in `.geneseed-version` (see `geneseed version`), not the
23
- > string. Current label: **6.0.0**.
23
+ > string. Current label: **6.0.1**.
24
24
 
25
25
  ## Capabilities
26
26
 
@@ -46,6 +46,8 @@ By default nothing changes: every agent runs on your session model. A build with
46
46
 
47
47
  Two settings of yours steer it, both in `agent-overrides.json`. A `tiers` map renames the models (`{ "tiers": { "standard": "opus", "light": "claude-haiku-4-5" } }`; an empty value means inherit), and an `agents.<name>.model` pin beats its tier, a stronger model included. The build always writes the alias. On Bedrock or Vertex, Claude Code maps an alias through `ANTHROPIC_DEFAULT_SONNET_MODEL` or `ANTHROPIC_DEFAULT_HAIKU_MODEL`; without it, it uses its built-in model id, which may not exist in your cloud project. With `CLAUDE_CODE_USE_BEDROCK` or `CLAUDE_CODE_USE_VERTEX` set and the variable missing, `geneseed doctor` tells you to pin it.
48
48
 
49
+ The web console sets all of this. On a Claude Code install, the Installs panel has a **Model tiers** switch and, while it is on, an editor for the two models; the Library shows each agent's tier, the model it resolves to and a pin field. Both write `agent-overrides.json` and change only the keys they name; a file that does not parse is refused. The model is written into the agent files at emit, so a save takes effect at the next rebuild, which the panel offers.
50
+
49
51
  ### Agents learn too
50
52
 
51
53
  When a subagent finishes, the hook copies each `spec-feedback:` line its report ends with into a notes file, with no model call. The line picks its scope with one question: is it true in any repo, or only here? A flaw of the spec is true in any repo: `[agent]` goes into the machine notes, `agent-notes/<name>.md` under `~/.config/geneseed/notes/` (a `[general]` line into `agent-notes/_general.md` there, which every agent reads). A fact true only in this repo is tagged `[agent:project]` and goes into `notebook/agent-notes/<name>.md` at the project root, one folder for every host (in a linked worktree, the main checkout's); a `[general:project]` line goes into `notebook/agent-notes/_general.md`, which every agent reads in that repo. The agent reads the machine notes and then the project notes first at its next dispatch; where they disagree, the project notes win. So a flaw it reported is in front of it until the user folds the fix into the source. See [Hooks](hooks.md). (Not on Bob, which has no subagent-finished event: there the caller copies the line into the machine or the project file.)
@@ -2,5 +2,5 @@
2
2
  "_comment": "version is a human-readable release label only; the canonical identity of an installed harness is the source fingerprint stamped in .geneseed-version (see `harness version`), not this string.",
3
3
  "theme": "neutral",
4
4
  "product": "Geneseed",
5
- "version": "6.0.0"
5
+ "version": "6.0.1"
6
6
  }
package/js/README.md CHANGED
@@ -282,6 +282,7 @@ the deployed harness as JSON.
282
282
  | `api.mjs` | The dashboard and settings reads: overview, recent, themes, setup, doctor, diff, installs, excludes, loops |
283
283
  | `update-check.mjs` | Is a newer release on npm? Answers from memory, refreshes in the background (a day when it got an answer, an hour when it did not), `null` on any failure, never asked under `node --test` |
284
284
  | `gates-api.mjs` | `GET /api/gates`: gate asks per rule per day over 30 days, read off every installed harness's `notebook/gates.jsonl` (the Overview's sparklines) |
285
+ | `agent-models-api.mjs` | `GET`/`POST /api/agent-models`: one Claude Code install's `tiers` map and per-agent model pins in `agent-overrides.json` (merged key by key, a file that does not parse is refused), with each agent's tier and the model it resolves to (`claudeAgentModel`, the emit's own precedence) |
285
286
  | `usage-api.mjs` | `GET /api/usage`: the 30-day skill and agent call counts across every installed harness, the never-fired list, a fleet-wide `names` list (per-name 30-day counts, installs, daily series, last day seen), and skips lines older than 90 days in each `notebook/usage.jsonl` |
286
287
  | `profiles-api.mjs` | The Profiles tab: `GET /api/profiles` (both sources, the installs that follow each, an apply preview) and the `profile-apply` / `profile-save` jobs, which run the CLI's own verb |
287
288
  | `user-files.mjs` | The fingerprint-guarded editors for `user-rules.md` (incl. memory promotion) and `PROFILE.md`, read and write |
@@ -417,12 +417,10 @@ const WEBFETCH_MARKER = '<!-- webfetch: allow -->';
417
417
  * cannot name tools it has never seen, so a read-only agent in a session with such a server can
418
418
  * still write through it, until this becomes an allowlist (`tools:`).
419
419
  */
420
- function claudeAgentFrontmatter(stem, text, overrides, tierModel = null) {
420
+ function claudeAgentFrontmatter(stem, text, model = null) {
421
421
  const fm = [`name: ${stem}`, `description: ${jsonDumps(agentDescription(text))}`];
422
- const ov = agentOverride(overrides, stem);
423
- // Precedence, highest first (spec D5): the user's pin, then the tier's model, then inherit.
424
- if (isTruthy(ov.model)) fm.push(`model: ${formatValue(ov.model)}`);
425
- else if (tierModel) fm.push(`model: ${formatValue(tierModel)}`);
422
+ // `model` is `claudeAgentModel(...).model`: the one precedence, resolved by the caller.
423
+ if (model) fm.push(`model: ${model}`);
426
424
  if (isReadonly(text)) {
427
425
  const list = ['Write', 'Edit', 'NotebookEdit', 'Agent', 'Task'];
428
426
  if (!text.includes(WEBFETCH_MARKER)) list.push('WebFetch');
@@ -480,7 +478,7 @@ const OVERRIDE_KEYS = ['model', 'temperature', 'variant', 'steps'];
480
478
  * boolean, a list, an object — threw a bare TypeError that aborted the emit with a stack trace
481
479
  * naming nothing the user wrote.
482
480
  */
483
- function overrideProblem(v) {
481
+ export function overrideProblem(v) {
484
482
  if (typeof v === 'string') return /[\r\n\u2028\u2029]/.test(v) ? 'contains a line break' : '';
485
483
  // `parseJson` yields exactly one object `isDict` refuses: its number wrapper.
486
484
  const isNumber = typeof v === 'object' && v !== null && !Array.isArray(v) && !isDict(v);
@@ -492,7 +490,7 @@ function overrideProblem(v) {
492
490
  * `_build_emit._load_agent_overrides`, with every value that would break the frontmatter
493
491
  * dropped and named on stderr — the user's file, so a bad entry is a warning, never an abort.
494
492
  */
495
- export function loadAgentOverrides(base) {
493
+ export function loadAgentOverrides(base, report = warn) {
496
494
  const file = path.join(base, 'agent-overrides.json');
497
495
  let data;
498
496
  try {
@@ -514,7 +512,7 @@ export function loadAgentOverrides(base) {
514
512
  for (const [stem, entry] of Object.entries(agents)) {
515
513
  if (entry === null) continue;
516
514
  if (!isDict(entry)) {
517
- warn(`[geneseed] WARN: ${file}: agents.${stem} is not an object — skipped`);
515
+ report(`[geneseed] WARN: ${file}: agents.${stem} is not an object — skipped`);
518
516
  delete agents[stem];
519
517
  continue;
520
518
  }
@@ -522,7 +520,7 @@ export function loadAgentOverrides(base) {
522
520
  if (!given(entry[key])) continue;
523
521
  const why = overrideProblem(entry[key]);
524
522
  if (!why) continue;
525
- warn(`[geneseed] WARN: ${file}: agents.${stem}.${key} ${why} — skipped`);
523
+ report(`[geneseed] WARN: ${file}: agents.${stem}.${key} ${why} — skipped`);
526
524
  delete entry[key];
527
525
  }
528
526
  }
@@ -579,6 +577,24 @@ export function claudeTierModel(tier, map = {}, env = {}) {
579
577
  return { model: String(value), warning };
580
578
  }
581
579
 
580
+ /**
581
+ * The model one agent gets on Claude Code, and why — THE ONE HOME of the precedence (spec D5),
582
+ * highest first: the user's pin (`agents.<name>.model`), then the `tiers` map, then the tier's
583
+ * default alias, then inherit. The emit writes `model` into the agent's frontmatter
584
+ * (`writeNativeLayer`) and the console shows the same answer (`js/web/agent-models-api.mjs`).
585
+ *
586
+ * `tiers` is `{ map, env }` while `--tiers auto` is on, else null (a pin still applies).
587
+ * `from`: `pin`, `map` (the map names the tier, an empty value included), `default`, `inherit`.
588
+ * `warning` is `claudeTierModel`'s, and only for a model the tier gave: a pinned agent has none.
589
+ */
590
+ export function claudeAgentModel(tier, pin, tiers = null) {
591
+ if (isTruthy(pin)) return { model: formatValue(pin), from: 'pin', warning: null };
592
+ if (!tiers) return { model: null, from: 'inherit', warning: null };
593
+ const { model, warning } = claudeTierModel(tier, tiers.map, tiers.env);
594
+ if (!model) return { model: null, from: 'inherit', warning: null };
595
+ return { model: formatValue(model), from: Object.hasOwn(tiers.map, tier) ? 'map' : 'default', warning };
596
+ }
597
+
582
598
  /**
583
599
  * The user's `tiers` map from `agent-overrides.json` (spec D9): `{ "standard": "<model>",
584
600
  * "light": "<model>" }`. `strong` takes no value and is dropped with a notice, as is any other
@@ -792,8 +808,7 @@ export function writeNativeLayer(items, agentsDir, skillsDir, overrides = null,
792
808
  if (bobDialect) warnBobIgnored(ov);
793
809
  else if (host === 'claude') warnClaudeIgnored(ov);
794
810
  // D11: the build never withholds the alias; the doctor warns about a cloud provider (`tierEnvNotes`).
795
- const tierModelOf = (tier) => (!tiers || host !== 'claude' || bobDialect ? null
796
- : claudeTierModel(tier, tiers.map, tiers.env).model);
811
+ const tiersHere = tiers && host === 'claude' && !bobDialect ? tiers : null;
797
812
  let nAgents = 0;
798
813
  let nSkills = 0;
799
814
  const written = [];
@@ -872,7 +887,7 @@ export function writeNativeLayer(items, agentsDir, skillsDir, overrides = null,
872
887
  let userOnly = false;
873
888
  if (folder === 'agents') {
874
889
  if (bobDialect) fm = bobAgentFrontmatter(stem, text);
875
- else if (host === 'claude') fm = claudeAgentFrontmatter(stem, text, ov, tierModelOf(tier));
890
+ else if (host === 'claude') fm = claudeAgentFrontmatter(stem, text, claudeAgentModel(tier, agentOverride(ov, stem).model, tiersHere).model);
876
891
  else fm = opencodeAgentFrontmatter(stem, text, ov, theme);
877
892
  dest = path.join(agentsDir, `${stem}.md`);
878
893
  body = stripAgentSkillLinks(body);
@@ -0,0 +1,172 @@
1
+ /**
2
+ * The console's view of the sub-agent models — `GET`/`POST /api/agent-models`.
3
+ *
4
+ * What it reads and writes is `agent-overrides.json` of ONE Claude Code install: the `tiers` map
5
+ * (`standard`, `light`) and each agent's `agents.<name>.model` pin. The precedence (pin > map >
6
+ * the tier's default > inherit) is `claudeAgentModel` in `js/hosts/native.mjs`, the same function
7
+ * the emit writes agent frontmatter with, so this page can never promise a model the build will
8
+ * not write. The value validation is `overrideProblem` and the map reader `loadTierMap`, there too.
9
+ *
10
+ * THE FILE IS THE USER'S. A write changes only the keys it names, key by key, in the order the
11
+ * file already has; it refuses a file that does not parse, or a `tiers`/`agents` that is not an
12
+ * object, rather than replace what it cannot read. Nothing here rebuilds: the model is written
13
+ * into the agent files at emit, so a save answers `rebuild: true` and the page offers the rebuild
14
+ * through the install action.
15
+ *
16
+ * A tier's value: a string sets it (`''` is the user choosing inherit, as `loadTierMap` reads it),
17
+ * `null` removes the key (back to the tier's default). A pin: a string sets it, `''` or `null`
18
+ * removes `model` and leaves the rest of the agent's entry alone.
19
+ *
20
+ * Pins and the map are Claude Code's: OpenCode records pins but this page does not edit them, and
21
+ * a host that is not Claude Code answers each agent's tier and no model.
22
+ */
23
+ import path from 'node:path';
24
+
25
+ import { renderAll } from '../build/render.mjs';
26
+ import { loadKits, makeCfg } from '../build/source.mjs';
27
+ import { EMIT_HOST_SCOPE, tiersOfDir } from '../hosts/installs.mjs';
28
+ import {
29
+ CLAUDE_TIER_DEFAULTS, claudeAgentModel, loadAgentOverrides, loadTierMap, overrideProblem,
30
+ } from '../hosts/native.mjs';
31
+ import { isFile, readText, writeTextAtomic } from '../lib/fs.mjs';
32
+ import { formatValue, isDict, isTruthy, jsonDumpsIndent, parseJson } from '../lib/json.mjs';
33
+ import { bget } from './actions.mjs';
34
+
35
+ const FILE = 'agent-overrides.json';
36
+ /** The tiers that take a model; `strong` is the session's own and has no key. */
37
+ const MAP_TIERS = ['standard', 'light'];
38
+ const MAX_MODEL = 200;
39
+
40
+ let tierTable = null;
41
+ /**
42
+ * `Map<agent name, 'strong'|'standard'|'light'>` off the SOURCE: the render strips an agent's
43
+ * `<!-- tier: -->` line from every output, so an installed file cannot say it. Every kit's agents
44
+ * are included, so a kit's seat is not read as `standard` by default. Built once per process.
45
+ */
46
+ export function agentTiers() {
47
+ if (tierTable) return tierTable;
48
+ const out = new Map();
49
+ const { items } = renderAll(makeCfg({ kits: [...loadKits().keys()] }), 'neutral');
50
+ for (const { rel, tier = 'standard' } of items) {
51
+ const m = /^agents\/([^_/][^/]*)\.md$/.exec(rel);
52
+ if (m) out.set(m[1], tier);
53
+ }
54
+ tierTable = out;
55
+ return out;
56
+ }
57
+
58
+ /** `{ exists, data, problem }`: the file parsed as an object, else why it cannot be edited. */
59
+ function readOverrides(dir) {
60
+ const file = path.join(dir, FILE);
61
+ if (!isFile(file)) return { file, exists: false, data: {}, problem: null };
62
+ let data;
63
+ try { data = parseJson(readText(file)); } catch {
64
+ return { file, exists: true, data: null, problem: `${FILE} is not valid JSON (comments are not allowed) — fix it by hand` };
65
+ }
66
+ if (!isDict(data)) return { file, exists: true, data: null, problem: `${FILE} is not a JSON object — fix it by hand` };
67
+ return { file, exists: true, data, problem: null };
68
+ }
69
+
70
+ /** The view's host and the install's directory; `claude` false for every host but Claude Code. */
71
+ function viewOf(state) {
72
+ const [host] = EMIT_HOST_SCOPE.get(state.emit || '') ?? ['opencode'];
73
+ return { host, claude: host === 'claude', dir: state.target };
74
+ }
75
+
76
+ export function apiAgentModels(state, env = process.env) {
77
+ const { host, claude, dir } = viewOf(state);
78
+ const tiers = tiersOfDir(state.root ?? dir, host);
79
+ const known = agentTiers();
80
+ const names = state.inventory.agents.map((a) => a.name);
81
+ if (!claude) {
82
+ return { host, claude, tiers, agents: names.map((name) => ({ name, tier: known.get(name) ?? null })) };
83
+ }
84
+ const { file, problem } = readOverrides(dir);
85
+ // The loaders take a no-op reporter: a console read prints nothing on stderr.
86
+ const quiet = () => {};
87
+ const map = problem ? {} : loadTierMap(dir, quiet);
88
+ const pins = problem ? {} : loadAgentOverrides(dir, quiet);
89
+ const on = tiers === 'auto' ? { map, env } : null;
90
+ const warnings = new Set();
91
+ const agents = names.map((name) => {
92
+ const tier = known.get(name) ?? null;
93
+ const pin = Object.hasOwn(pins, name) && isTruthy(pins[name]?.model) ? formatValue(pins[name].model) : null;
94
+ // A personal agent (no shipped source) is not Geneseed's to tier: only its pin counts.
95
+ const r = claudeAgentModel(tier ?? 'none', pin, tier ? on : null);
96
+ // The alias warning is the tier map's, whether or not the routing is installed yet: the
97
+ // console's editor shows with a picked `auto`, before the rebuild that turns it on.
98
+ const w = tier ? claudeAgentModel(tier, pin, { map, env }).warning : null;
99
+ if (w) warnings.add(w);
100
+ return { name, tier, pin, model: r.model, from: r.from };
101
+ });
102
+ return {
103
+ host, claude, tiers, file: { path: file, problem },
104
+ map: Object.fromEntries(Object.entries(map).map(([k, v]) => [k, formatValue(v)])),
105
+ defaults: { ...CLAUDE_TIER_DEFAULTS },
106
+ warnings: [...warnings], agents,
107
+ };
108
+ }
109
+
110
+ /**
111
+ * Apply one edit to the parsed file in place; the problems found, none applied when there are some.
112
+ * `edit` is `{ tiers?: {standard?, light?}, agents?: {<name>: model} }`, `names` the installed agents.
113
+ */
114
+ export function editOverrides(data, edit, names) {
115
+ const problems = [];
116
+ const asModel = (where, v) => {
117
+ if (v === null) return null;
118
+ if (typeof v !== 'string') { problems.push(`${where}: a model name, or null`); return undefined; }
119
+ const s = v.trim();
120
+ const why = overrideProblem(s);
121
+ if (why) { problems.push(`${where} ${why}`); return undefined; }
122
+ if (s.length > MAX_MODEL) { problems.push(`${where} is longer than ${MAX_MODEL} characters`); return undefined; }
123
+ return s;
124
+ };
125
+ const tiers = isDict(edit.tiers) ? edit.tiers : {};
126
+ const agents = isDict(edit.agents) ? edit.agents : {};
127
+ const tierOps = [];
128
+ for (const [k, v] of Object.entries(tiers)) {
129
+ if (!MAP_TIERS.includes(k)) { problems.push(`tiers.${k} is not a tier that takes a model (${MAP_TIERS.join(', ')})`); continue; }
130
+ const m = asModel(`tiers.${k}`, v);
131
+ if (m !== undefined) tierOps.push([k, m]);
132
+ }
133
+ const pinOps = [];
134
+ for (const [name, v] of Object.entries(agents)) {
135
+ if (name === '__proto__' || !names.includes(name)) { problems.push(`agents.${name} is not an installed agent`); continue; }
136
+ const m = asModel(`agents.${name}.model`, v);
137
+ if (m !== undefined) pinOps.push([name, m === '' ? null : m]);
138
+ }
139
+ if (!tierOps.length && !pinOps.length && !problems.length) problems.push('nothing to save');
140
+ if (tierOps.length && Object.hasOwn(data, 'tiers') && !isDict(data.tiers)) problems.push(`${FILE}: "tiers" is not an object — fix it by hand`);
141
+ if (pinOps.length && Object.hasOwn(data, 'agents') && !isDict(data.agents)) problems.push(`${FILE}: "agents" is not an object — fix it by hand`);
142
+ if (problems.length) return problems;
143
+
144
+ for (const [k, m] of tierOps) {
145
+ if (m === null) { if (isDict(data.tiers)) delete data.tiers[k]; continue; }
146
+ if (!isDict(data.tiers)) data.tiers = {};
147
+ data.tiers[k] = m;
148
+ }
149
+ for (const [name, m] of pinOps) {
150
+ if (m === null) {
151
+ if (isDict(data.agents) && Object.hasOwn(data.agents, name) && isDict(data.agents[name])) delete data.agents[name].model;
152
+ continue;
153
+ }
154
+ if (!isDict(data.agents)) data.agents = {};
155
+ if (!Object.hasOwn(data.agents, name) || !isDict(data.agents[name])) data.agents[name] = {};
156
+ data.agents[name].model = m;
157
+ }
158
+ return [];
159
+ }
160
+
161
+ /** `POST /api/agent-models`: `ok: false` (a 409) when nothing was written, with the reason. */
162
+ export function apiAgentModelsSave(state, body) {
163
+ const { claude, dir } = viewOf(state);
164
+ if (!claude) return { ok: false, error: 'Models are set on Claude Code installs only' };
165
+ const { file, data, problem } = readOverrides(dir);
166
+ if (problem) return { ok: false, error: problem };
167
+ const names = state.inventory.agents.map((a) => a.name);
168
+ const problems = editOverrides(data, { tiers: bget(body, 'tiers'), agents: bget(body, 'agents') }, names);
169
+ if (problems.length) return { ok: false, error: problems.join('; ') };
170
+ writeTextAtomic(file, `${jsonDumpsIndent(data, { ensureAscii: false })}\n`);
171
+ return { ok: true, rebuild: true, ...apiAgentModels(state) };
172
+ }
package/js/web/routes.mjs CHANGED
@@ -28,6 +28,7 @@ import { apiUsage } from './usage-api.mjs';
28
28
  import { apiProfiles } from './profiles-api.mjs';
29
29
  import { fleetSort } from './state.mjs';
30
30
  import { apiGates } from './gates-api.mjs';
31
+ import { apiAgentModels, apiAgentModelsSave } from './agent-models-api.mjs';
31
32
  import { migratePreview } from '../maintain/migrate.mjs';
32
33
  import { apiProfile, apiProfileSave, apiRules, apiRulesDecide, apiRulesMutate, apiRulesPromote } from './user-files.mjs';
33
34
 
@@ -64,6 +65,8 @@ export const POST_ROUTES = new Map([
64
65
  // ever consulted — the same shape as `/api/memory/delete` and `/api/activity` above.
65
66
  ['/api/loops/preset', [apiLoopsPresetMutate, false]],
66
67
  ['/api/autostart', [apiAutostart, true]],
68
+ // The `tiers` map and the per-agent model pins of one Claude Code install's agent-overrides.json.
69
+ ['/api/agent-models', [apiAgentModelsSave, true]],
67
70
  ]);
68
71
 
69
72
  /**
@@ -74,7 +77,7 @@ export const POST_ROUTES = new Map([
74
77
  * are the only actions that read the request's install.
75
78
  */
76
79
  export const VIEW_POSTS = new Set(['/api/activity', '/api/memory/delete', '/api/rules',
77
- '/api/rules/promote', '/api/rules/decide', '/api/profile', '/api/actions/restore', '/api/actions/build']);
80
+ '/api/rules/promote', '/api/rules/decide', '/api/profile', '/api/actions/restore', '/api/actions/build', '/api/agent-models']);
78
81
 
79
82
  /**
80
83
  * The GETs that answer for the whole machine, not one install: they IGNORE a `?host=&path=`
@@ -229,6 +232,7 @@ export const STATE_ROUTES = {
229
232
  // answers — a daemon whose POST worked and whose GET 501'd would have no way to obtain one.
230
233
  '/api/rules': apiRules,
231
234
  '/api/loadout': (state) => apiLoadout(state),
235
+ '/api/agent-models': (state) => apiAgentModels(state),
232
236
  '/api/mcp': apiMcp,
233
237
  '/api/loops': apiLoops,
234
238
  '/api/loops/active': apiLoopsActive,
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": "6.0.0",
4
+ "version": "6.0.1",
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-CZ-x0iWG.js";import{n as i,t as a}from"./usePoll-D5c_qIFZ.js";import{t as o}from"./DataTable-b9zTShqJ.js";var s=e(t(),1),c={x:260,y:190},l=110,u=28,d=14,f=44,p=e=>e*Math.PI/180,m=e=>Math.round(e*10)/10,h=(e,t=l,n=c)=>({x:m(n.x+t*Math.cos(p(e))),y:m(n.y+t*Math.sin(p(e)))}),g=e=>e/l*(180/Math.PI)+3,_=(e,t,n,r=0)=>`M${t.x},${t.y} A${e},${e} 0 ${r} 1 ${n.x},${n.y}`,v=m(h(205).x-6),y=e=>e.length*6.4,b=e=>({x:e.x-y(e.name)/2,y:e.y-7,w:y(e.name),h:14}),x=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h,S=(e,t)=>e.some((n,r)=>[...e.slice(r+1),...t.filter(e=>!e.gate)].some(e=>x(b(n),b(e))));function C(e){return e?.gate===`human`?e.gateOn?.length?`Human gate on ${e.gateOn.join(`, `)}`:`Human gate`:null}function w(e,t=[]){let n=T(e,t,0);if(n.mode!==`ring`)return n;let r=Math.min(...n.entry.map(e=>e.y-30),...n.nodes.map(e=>e.y-e.r-12),...n.inner.map(e=>e.cy-e.r-12),...n.exit?[n.exit.y-24]:[]);return r<0?T(e,t,Math.ceil(-r)):n}function T(e,t,n){let r={x:c.x,y:c.y+n},i=(e,t=l)=>h(e,t,r),a=e=>t.find(t=>t.name===e),o=e=>a(e)?.effect??null,s=e=>C(a(e)),p=e.loops||[],v=p.find(e=>e.iteration);if(!v||v.nodes.length>8)return E(e,o,s);let b=Math.max(...e.nodes.map(e=>p.filter(t=>t.nodes.includes(e)).length)),x=p.filter(e=>e!==v);if(b>3||x.some(e=>!e.nodes.every(e=>v.nodes.includes(e))))return E(e,o,s);let w=v.nodes[0],T=new Set(e.edges.filter(e=>e.to===w).map(e=>e.from)),D=new Map;for(let e of[...x].sort((e,t)=>e.nodes.length-t.nodes.length))for(let t of e.nodes.slice(1))t!==w&&!T.has(t)&&!D.has(t)&&D.set(t,e);let O=v.nodes.filter(e=>!D.has(e));if(O.length<2||x.some(e=>D.has(e.nodes[0])))return E(e,o,s);let k=360/O.length,A=O.map((e,t)=>({name:e,a:-90+t*k,r:u})),j=A.findIndex(e=>o(e.name)===`mutate`);j>=0&&A.splice(j,0,{name:`validate`,a:A[j].a-k/2,r:d,gate:!0});let M=A.map(e=>({name:e.name,...i(e.a),r:e.r,effect:e.gate?null:o(e.name),gate:!!e.gate,inner:!1,human:e.gate?null:s(e.name)})),N=A.map((e,t)=>{let n=A[(t+1)%A.length],r=(t+1===A.length?n.a+360:n.a)-g(n.r)-2,a=e.a+g(e.r);return{d:_(l,i(a),i(r),+(r-a>180)),kind:`ring`}}),P=[],F=new Map;for(let e of x)F.set(e.nodes[0],[...F.get(e.nodes[0])||[],e]);for(let[e,t]of F){let n=A.find(t=>t.name===e),r=i(n.a),a=t.length>1;t.sort((e,t)=>e.nodes.length-t.nodes.length).forEach((e,t)=>{let d=i(n.a+(a?t?18:-18:0),l+(a?54:44)),p=Math.atan2(d.y-r.y,d.x-r.x)*(180/Math.PI),g=e.nodes.filter(t=>D.get(t)===e),v=e=>g.map((t,n)=>({name:t,...h(p+(n-(g.length-1)/2)*e,f,d)})),y=105;for(;y<150&&S(v(y),M);)y+=5;v(y).forEach(({name:e,...t})=>{M.push({name:e,...t,r:u,effect:o(e),gate:!1,inner:!0,human:s(e)})});let b=p+180;N.push({d:_(f,h(b+42,f,d),h(b+138,f,d)),kind:`inner`}),N.push({d:_(f,h(b+222,f,d),h(b+318,f,d)),kind:`inner`});let x=`${e.nodes.join(e.nodes.length===2?` ⇄ `:` → `)} · max ${e.max}`,C={lx:d.x,ly:d.y+f+20,anchor:`middle`};if(a){let e=d.x>=c.x,t=Math.max(f,...g.map(e=>{let t=M.find(t=>t.name===e);return Math.abs(t.x-d.x)+u}));C={lx:m(d.x+(e?t+8:-t-8)),ly:m(d.y+4),anchor:e?`start`:`end`}}P.push({loop:e.name,cx:d.x,cy:d.y,r:f,label:x,...C})})}let I=i(205).y,L=e.nodes.filter(e=>!v.nodes.includes(e)),R=L.map((e,t)=>({name:e,x:40,y:m(I-44*(L.length-1-t)),human:s(e)})),z=e.edges.find(e=>e.to===`$close`)?.from,B=M.find(e=>e.name===z),V=B?{from:z,x:B.x+200,y:B.y-30,d:`M${B.x+u},${B.y-6} C${B.x+90},${B.y-40} ${B.x+170},${B.y-40} ${B.x+200},${B.y-30}`}:null,H=Math.max(540,...M.map(e=>e.x+e.r+8),...V?[V.x+6+y(`close`)+8]:[],...P.map(e=>e.cx+e.r+8),...P.map(e=>e.anchor===`start`?e.lx+y(e.label)+8:e.lx+y(e.label)/2+8)),U=Math.max(300,...M.map(e=>e.y+e.r+12),...P.map(e=>Math.max(e.cy+e.r,e.ly)+12));return{mode:`ring`,width:Math.ceil(H),height:Math.ceil(U),center:{x:r.x,y:r.y,r:l},nodes:M,arcs:N,inner:P,entry:R,exit:V}}function E(e,t,n){let r=e.loops||[],i=e=>36+16*r.filter(t=>t!==e&&t.nodes.every(t=>e.nodes.includes(t))).length,a=Math.max(u,...r.map(i))+30,o=new Map(e.nodes.map((e,t)=>[e,60+t*100])),s=e.nodes.map(e=>({name:e,x:o.get(e),y:a,r:u,effect:t(e),gate:!1,inner:!1,human:n(e)})),c=e.nodes.slice(1).map((t,n)=>({d:`M${o.get(e.nodes[n])+u},${a} L${o.get(t)-u-4},${a}`,kind:`flow`})),l=r.map(e=>{let t=i(e),n=Math.min(...e.nodes.map(e=>o.get(e))),r=Math.max(...e.nodes.map(e=>o.get(e))),s={x:n-t,y:a-t,w:r-n+2*t,h:2*t};return c.push({d:`M${r},${s.y+s.h} L${n+4},${s.y+s.h}`,kind:`flow`}),{loop:e.name,label:`${e.name} · max ${e.max}`,box:s}});return{mode:`flow`,width:60+e.nodes.length*100,height:2*a,center:null,nodes:s,arcs:c,inner:l,entry:[],exit:null}}var D=n();function O({x:e,y:t,label:n}){return(0,D.jsxs)(`g`,{className:`lr-human`,children:[(0,D.jsx)(`title`,{children:n}),(0,D.jsx)(`circle`,{cx:e,cy:t,r:`9`}),(0,D.jsx)(`circle`,{cx:e,cy:t-2.4,r:`2.6`,className:`lr-human-fig`}),(0,D.jsx)(`path`,{d:`M${e-4.6},${t+5.6} a4.6,4.6 0 0 1 9.2,0 Z`,className:`lr-human-fig`})]})}function k({graph:e,bricks:t,onSelect:n,highlight:r}){let i=w(e,t),a=(e.loops||[]).find(e=>e.iteration),o=e=>`${e.name} brick${e.human?`, ${e.human.toLowerCase()}`:``}`,s=e=>t=>{(t.type===`click`||t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n?.(e))};return(0,D.jsxs)(`svg`,{className:`loop-ring`,viewBox:`0 0 ${i.width} ${i.height}`,style:{"--loop-w":`${i.width}px`},role:`group`,"aria-label":`${e.name} loop: ${e.nodes.join(`, `)}`,children:[(0,D.jsx)(`defs`,{children:[`ring`,`inner`,`flow`].map(e=>(0,D.jsx)(`marker`,{id:`lr-arrow-${e}`,markerWidth:`10`,markerHeight:`10`,refX:`7`,refY:`4`,orient:`auto`,children:(0,D.jsx)(`path`,{d:`M0,0 L8,4 L0,8 Z`,className:`lr-head-${e}`})},e))}),i.mode===`ring`&&i.inner.map(e=>(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`circle`,{cx:e.cx,cy:e.cy,r:e.r,className:`lr-inner`}),(0,D.jsx)(`text`,{x:e.lx,y:e.ly,textAnchor:e.anchor,className:`lr-sub lr-good`,children:e.label})]},e.loop)),i.mode===`flow`&&i.inner.map(e=>(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`rect`,{x:e.box.x,y:e.box.y,width:e.box.w,height:e.box.h,rx:`14`,className:`lr-box`}),(0,D.jsx)(`text`,{x:e.box.x+10,y:e.box.y-6,className:`lr-sub lr-good`,children:e.label})]},e.loop)),i.arcs.map((e,t)=>(0,D.jsx)(`path`,{d:e.d,className:`lr-${e.kind}`,markerEnd:`url(#lr-arrow-${e.kind})`},t)),i.entry.length>0&&(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`path`,{d:`M40,${i.entry.at(-1).y} L${v},${i.entry.at(-1).y}`,className:`lr-flow`,markerEnd:`url(#lr-arrow-flow)`}),i.entry.map(e=>(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`text`,{x:e.x,y:e.y-10,className:`lr-lbl`,children:e.name}),(0,D.jsx)(`text`,{x:e.x,y:e.y+18,className:`lr-sub`,children:`setup · 1×`}),e.human?(0,D.jsx)(O,{x:e.x-14,y:e.y-14,label:e.human}):null]},e.name))]}),i.nodes.map(e=>e.gate?(0,D.jsxs)(`g`,{className:`lr-gate`,children:[(0,D.jsx)(`title`,{children:`validate — the engine scores the change before the first mutate step`}),(0,D.jsx)(`circle`,{cx:e.x,cy:e.y,r:e.r}),(0,D.jsx)(`text`,{x:e.x,y:e.y+5,textAnchor:`middle`,children:`⛨`}),(0,D.jsx)(`text`,{x:e.x+20,y:e.y-10,className:`lr-sub lr-warn`,children:`validate`})]},e.name):(0,D.jsxs)(`g`,{className:`lr-node${e.inner?` inner`:``}${e.effect===`mutate`?` mutate`:``}${e.name===r?` current`:``}`,"aria-current":e.name===r?`step`:void 0,...n?{role:`button`,tabIndex:0,"aria-label":o(e),onClick:s(e.name),onKeyDown:s(e.name)}:{role:`img`,"aria-label":`${o(e)}${e.name===r?`, current step`:``}`},children:[(0,D.jsx)(`circle`,{cx:e.x,cy:e.y,r:e.r}),(0,D.jsx)(`text`,{x:e.x,y:e.y+4,textAnchor:`middle`,children:e.name}),e.human?(0,D.jsx)(O,{x:e.x+e.r*.74,y:e.y-e.r*.74,label:e.human}):null]},e.name)),i.exit&&(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`path`,{d:i.exit.d,className:`lr-flow`,markerEnd:`url(#lr-arrow-flow)`}),(0,D.jsx)(`text`,{x:i.exit.x+6,y:i.exit.y+4,className:`lr-lbl`,children:`close`}),(0,D.jsx)(`text`,{x:i.exit.x-90,y:i.exit.y-10,textAnchor:`middle`,className:`lr-sub`,children:`done`})]}),i.center&&a&&(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`text`,{x:i.center.x,y:i.center.y-4,textAnchor:`middle`,className:`lr-title`,children:e.name}),(0,D.jsxs)(`text`,{x:i.center.x,y:i.center.y+16,textAnchor:`middle`,className:`lr-sub lr-acc`,children:[`iterations · max `,a.max]})]})]})}var A=5e3,j=[`prudent`,`balanced`,`aggressive`],M={running:`acc`,awaiting:`warn`,unreadable:`bad`},N=e=>!!e.graph;function P(){let[e,t]=(0,s.useState)(null),[n,o]=(0,s.useState)(null),[c,l]=(0,s.useState)(null),[u,d]=(0,s.useState)(0);return i(e=>r.activeLoops().then(n=>e()&&(t(a(n)),o(null)),t=>e()&&o(t.message)),A,[u]),{loops:e?.loops??null,error:c||n,onPreset:(e,t)=>(l(null),r.setLoopPreset(e,t).then(()=>d(e=>e+1),e=>l(e.message)))}}var F=e=>({key:e,label:e,align:`right`,render:t=>(0,D.jsx)(`span`,{className:`num`,children:t[e]})}),I=[F(`iteration`),{key:`intent`,label:`intent`},F(`declared`),F(`actual`),{key:`decision`,label:`decision`},{key:`tests`,label:`tests`}];function L({history:e}){return e.length?(0,D.jsx)(`div`,{className:`loop-history`,children:(0,D.jsx)(o,{caption:`Iterations`,captionHidden:!0,columns:I,rows:e,rowKey:e=>e.iteration})}):(0,D.jsx)(`p`,{className:`panel-note`,children:`No iteration finished yet.`})}function R({loop:e,bricks:t,onPreset:n}){let r=N(e)?(e.graph.loops||[]).find(e=>e.iteration):null,[i,a]=(0,s.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`reader-tags`,children:[(0,D.jsx)(`span`,{className:`tag acc`,children:`Active loop`}),(0,D.jsx)(`span`,{className:`tag${M[e.status]?` ${M[e.status]}`:``}`,children:e.status})]}),(0,D.jsx)(`h2`,{className:`reader-title`,children:e.title}),(0,D.jsxs)(`p`,{className:`mono dim reader-src`,children:[e.branch,` · `,e.root]}),N(e)?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`p`,{className:`reader-lede`,children:[`Iteration `,e.iteration,r?` / ${r.max}`:``,` · at `,e.node]}),e.awaiting?(0,D.jsxs)(`p`,{className:`loop-run-wait t-warn`,children:[(0,D.jsxs)(`b`,{children:[`Awaiting `,e.awaiting.kind,e.awaiting.kind===`gate`?` at ${e.awaiting.node}`:``]}),` `,`— Answer in the agent's session.`]}):null,(0,D.jsxs)(`label`,{className:`panel-note loop-run-preset`,children:[`preset`,(0,D.jsx)(`select`,{className:`sel`,"aria-label":`Preset for ${e.title}`,value:e.preset,disabled:i,onChange:t=>{a(!0),Promise.resolve(n(e.root,t.target.value)).finally(()=>a(!1))},children:j.map(e=>(0,D.jsx)(`option`,{children:e},e))})]}),(0,D.jsx)(`a`,{href:`#/docs/loop-risk`,children:`What presets mean →`}),(0,D.jsx)(`hr`,{className:`hr`}),(0,D.jsx)(`div`,{className:`loop-graph`,children:(0,D.jsx)(k,{graph:e.graph,bricks:t,highlight:e.node})}),(0,D.jsx)(`h3`,{className:`loop-h2`,children:`Iterations`}),(0,D.jsx)(L,{history:e.history})]}):(0,D.jsx)(`p`,{className:`reader-lede`,children:e.status===`unreadable`?`Its LOOP.md cannot be read, so there is no state to show.`:`Its LOOP.md is gone: the loop closed and its state went with it.`})]})}export{O as a,w as c,P as i,M as n,k as o,N as r,C as s,R as t};
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-DxwG8y94.js";import{n as i,t as a}from"./usePoll-D5c_qIFZ.js";import{t as o}from"./DataTable-b9zTShqJ.js";var s=e(t(),1),c={x:260,y:190},l=110,u=28,d=14,f=44,p=e=>e*Math.PI/180,m=e=>Math.round(e*10)/10,h=(e,t=l,n=c)=>({x:m(n.x+t*Math.cos(p(e))),y:m(n.y+t*Math.sin(p(e)))}),g=e=>e/l*(180/Math.PI)+3,_=(e,t,n,r=0)=>`M${t.x},${t.y} A${e},${e} 0 ${r} 1 ${n.x},${n.y}`,v=m(h(205).x-6),y=e=>e.length*6.4,b=e=>({x:e.x-y(e.name)/2,y:e.y-7,w:y(e.name),h:14}),x=(e,t)=>e.x<t.x+t.w&&t.x<e.x+e.w&&e.y<t.y+t.h&&t.y<e.y+e.h,S=(e,t)=>e.some((n,r)=>[...e.slice(r+1),...t.filter(e=>!e.gate)].some(e=>x(b(n),b(e))));function C(e){return e?.gate===`human`?e.gateOn?.length?`Human gate on ${e.gateOn.join(`, `)}`:`Human gate`:null}function w(e,t=[]){let n=T(e,t,0);if(n.mode!==`ring`)return n;let r=Math.min(...n.entry.map(e=>e.y-30),...n.nodes.map(e=>e.y-e.r-12),...n.inner.map(e=>e.cy-e.r-12),...n.exit?[n.exit.y-24]:[]);return r<0?T(e,t,Math.ceil(-r)):n}function T(e,t,n){let r={x:c.x,y:c.y+n},i=(e,t=l)=>h(e,t,r),a=e=>t.find(t=>t.name===e),o=e=>a(e)?.effect??null,s=e=>C(a(e)),p=e.loops||[],v=p.find(e=>e.iteration);if(!v||v.nodes.length>8)return E(e,o,s);let b=Math.max(...e.nodes.map(e=>p.filter(t=>t.nodes.includes(e)).length)),x=p.filter(e=>e!==v);if(b>3||x.some(e=>!e.nodes.every(e=>v.nodes.includes(e))))return E(e,o,s);let w=v.nodes[0],T=new Set(e.edges.filter(e=>e.to===w).map(e=>e.from)),D=new Map;for(let e of[...x].sort((e,t)=>e.nodes.length-t.nodes.length))for(let t of e.nodes.slice(1))t!==w&&!T.has(t)&&!D.has(t)&&D.set(t,e);let O=v.nodes.filter(e=>!D.has(e));if(O.length<2||x.some(e=>D.has(e.nodes[0])))return E(e,o,s);let k=360/O.length,A=O.map((e,t)=>({name:e,a:-90+t*k,r:u})),j=A.findIndex(e=>o(e.name)===`mutate`);j>=0&&A.splice(j,0,{name:`validate`,a:A[j].a-k/2,r:d,gate:!0});let M=A.map(e=>({name:e.name,...i(e.a),r:e.r,effect:e.gate?null:o(e.name),gate:!!e.gate,inner:!1,human:e.gate?null:s(e.name)})),N=A.map((e,t)=>{let n=A[(t+1)%A.length],r=(t+1===A.length?n.a+360:n.a)-g(n.r)-2,a=e.a+g(e.r);return{d:_(l,i(a),i(r),+(r-a>180)),kind:`ring`}}),P=[],F=new Map;for(let e of x)F.set(e.nodes[0],[...F.get(e.nodes[0])||[],e]);for(let[e,t]of F){let n=A.find(t=>t.name===e),r=i(n.a),a=t.length>1;t.sort((e,t)=>e.nodes.length-t.nodes.length).forEach((e,t)=>{let d=i(n.a+(a?t?18:-18:0),l+(a?54:44)),p=Math.atan2(d.y-r.y,d.x-r.x)*(180/Math.PI),g=e.nodes.filter(t=>D.get(t)===e),v=e=>g.map((t,n)=>({name:t,...h(p+(n-(g.length-1)/2)*e,f,d)})),y=105;for(;y<150&&S(v(y),M);)y+=5;v(y).forEach(({name:e,...t})=>{M.push({name:e,...t,r:u,effect:o(e),gate:!1,inner:!0,human:s(e)})});let b=p+180;N.push({d:_(f,h(b+42,f,d),h(b+138,f,d)),kind:`inner`}),N.push({d:_(f,h(b+222,f,d),h(b+318,f,d)),kind:`inner`});let x=`${e.nodes.join(e.nodes.length===2?` ⇄ `:` → `)} · max ${e.max}`,C={lx:d.x,ly:d.y+f+20,anchor:`middle`};if(a){let e=d.x>=c.x,t=Math.max(f,...g.map(e=>{let t=M.find(t=>t.name===e);return Math.abs(t.x-d.x)+u}));C={lx:m(d.x+(e?t+8:-t-8)),ly:m(d.y+4),anchor:e?`start`:`end`}}P.push({loop:e.name,cx:d.x,cy:d.y,r:f,label:x,...C})})}let I=i(205).y,L=e.nodes.filter(e=>!v.nodes.includes(e)),R=L.map((e,t)=>({name:e,x:40,y:m(I-44*(L.length-1-t)),human:s(e)})),z=e.edges.find(e=>e.to===`$close`)?.from,B=M.find(e=>e.name===z),V=B?{from:z,x:B.x+200,y:B.y-30,d:`M${B.x+u},${B.y-6} C${B.x+90},${B.y-40} ${B.x+170},${B.y-40} ${B.x+200},${B.y-30}`}:null,H=Math.max(540,...M.map(e=>e.x+e.r+8),...V?[V.x+6+y(`close`)+8]:[],...P.map(e=>e.cx+e.r+8),...P.map(e=>e.anchor===`start`?e.lx+y(e.label)+8:e.lx+y(e.label)/2+8)),U=Math.max(300,...M.map(e=>e.y+e.r+12),...P.map(e=>Math.max(e.cy+e.r,e.ly)+12));return{mode:`ring`,width:Math.ceil(H),height:Math.ceil(U),center:{x:r.x,y:r.y,r:l},nodes:M,arcs:N,inner:P,entry:R,exit:V}}function E(e,t,n){let r=e.loops||[],i=e=>36+16*r.filter(t=>t!==e&&t.nodes.every(t=>e.nodes.includes(t))).length,a=Math.max(u,...r.map(i))+30,o=new Map(e.nodes.map((e,t)=>[e,60+t*100])),s=e.nodes.map(e=>({name:e,x:o.get(e),y:a,r:u,effect:t(e),gate:!1,inner:!1,human:n(e)})),c=e.nodes.slice(1).map((t,n)=>({d:`M${o.get(e.nodes[n])+u},${a} L${o.get(t)-u-4},${a}`,kind:`flow`})),l=r.map(e=>{let t=i(e),n=Math.min(...e.nodes.map(e=>o.get(e))),r=Math.max(...e.nodes.map(e=>o.get(e))),s={x:n-t,y:a-t,w:r-n+2*t,h:2*t};return c.push({d:`M${r},${s.y+s.h} L${n+4},${s.y+s.h}`,kind:`flow`}),{loop:e.name,label:`${e.name} · max ${e.max}`,box:s}});return{mode:`flow`,width:60+e.nodes.length*100,height:2*a,center:null,nodes:s,arcs:c,inner:l,entry:[],exit:null}}var D=n();function O({x:e,y:t,label:n}){return(0,D.jsxs)(`g`,{className:`lr-human`,children:[(0,D.jsx)(`title`,{children:n}),(0,D.jsx)(`circle`,{cx:e,cy:t,r:`9`}),(0,D.jsx)(`circle`,{cx:e,cy:t-2.4,r:`2.6`,className:`lr-human-fig`}),(0,D.jsx)(`path`,{d:`M${e-4.6},${t+5.6} a4.6,4.6 0 0 1 9.2,0 Z`,className:`lr-human-fig`})]})}function k({graph:e,bricks:t,onSelect:n,highlight:r}){let i=w(e,t),a=(e.loops||[]).find(e=>e.iteration),o=e=>`${e.name} brick${e.human?`, ${e.human.toLowerCase()}`:``}`,s=e=>t=>{(t.type===`click`||t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n?.(e))};return(0,D.jsxs)(`svg`,{className:`loop-ring`,viewBox:`0 0 ${i.width} ${i.height}`,style:{"--loop-w":`${i.width}px`},role:`group`,"aria-label":`${e.name} loop: ${e.nodes.join(`, `)}`,children:[(0,D.jsx)(`defs`,{children:[`ring`,`inner`,`flow`].map(e=>(0,D.jsx)(`marker`,{id:`lr-arrow-${e}`,markerWidth:`10`,markerHeight:`10`,refX:`7`,refY:`4`,orient:`auto`,children:(0,D.jsx)(`path`,{d:`M0,0 L8,4 L0,8 Z`,className:`lr-head-${e}`})},e))}),i.mode===`ring`&&i.inner.map(e=>(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`circle`,{cx:e.cx,cy:e.cy,r:e.r,className:`lr-inner`}),(0,D.jsx)(`text`,{x:e.lx,y:e.ly,textAnchor:e.anchor,className:`lr-sub lr-good`,children:e.label})]},e.loop)),i.mode===`flow`&&i.inner.map(e=>(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`rect`,{x:e.box.x,y:e.box.y,width:e.box.w,height:e.box.h,rx:`14`,className:`lr-box`}),(0,D.jsx)(`text`,{x:e.box.x+10,y:e.box.y-6,className:`lr-sub lr-good`,children:e.label})]},e.loop)),i.arcs.map((e,t)=>(0,D.jsx)(`path`,{d:e.d,className:`lr-${e.kind}`,markerEnd:`url(#lr-arrow-${e.kind})`},t)),i.entry.length>0&&(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`path`,{d:`M40,${i.entry.at(-1).y} L${v},${i.entry.at(-1).y}`,className:`lr-flow`,markerEnd:`url(#lr-arrow-flow)`}),i.entry.map(e=>(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`text`,{x:e.x,y:e.y-10,className:`lr-lbl`,children:e.name}),(0,D.jsx)(`text`,{x:e.x,y:e.y+18,className:`lr-sub`,children:`setup · 1×`}),e.human?(0,D.jsx)(O,{x:e.x-14,y:e.y-14,label:e.human}):null]},e.name))]}),i.nodes.map(e=>e.gate?(0,D.jsxs)(`g`,{className:`lr-gate`,children:[(0,D.jsx)(`title`,{children:`validate — the engine scores the change before the first mutate step`}),(0,D.jsx)(`circle`,{cx:e.x,cy:e.y,r:e.r}),(0,D.jsx)(`text`,{x:e.x,y:e.y+5,textAnchor:`middle`,children:`⛨`}),(0,D.jsx)(`text`,{x:e.x+20,y:e.y-10,className:`lr-sub lr-warn`,children:`validate`})]},e.name):(0,D.jsxs)(`g`,{className:`lr-node${e.inner?` inner`:``}${e.effect===`mutate`?` mutate`:``}${e.name===r?` current`:``}`,"aria-current":e.name===r?`step`:void 0,...n?{role:`button`,tabIndex:0,"aria-label":o(e),onClick:s(e.name),onKeyDown:s(e.name)}:{role:`img`,"aria-label":`${o(e)}${e.name===r?`, current step`:``}`},children:[(0,D.jsx)(`circle`,{cx:e.x,cy:e.y,r:e.r}),(0,D.jsx)(`text`,{x:e.x,y:e.y+4,textAnchor:`middle`,children:e.name}),e.human?(0,D.jsx)(O,{x:e.x+e.r*.74,y:e.y-e.r*.74,label:e.human}):null]},e.name)),i.exit&&(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`path`,{d:i.exit.d,className:`lr-flow`,markerEnd:`url(#lr-arrow-flow)`}),(0,D.jsx)(`text`,{x:i.exit.x+6,y:i.exit.y+4,className:`lr-lbl`,children:`close`}),(0,D.jsx)(`text`,{x:i.exit.x-90,y:i.exit.y-10,textAnchor:`middle`,className:`lr-sub`,children:`done`})]}),i.center&&a&&(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`text`,{x:i.center.x,y:i.center.y-4,textAnchor:`middle`,className:`lr-title`,children:e.name}),(0,D.jsxs)(`text`,{x:i.center.x,y:i.center.y+16,textAnchor:`middle`,className:`lr-sub lr-acc`,children:[`iterations · max `,a.max]})]})]})}var A=5e3,j=[`prudent`,`balanced`,`aggressive`],M={running:`acc`,awaiting:`warn`,unreadable:`bad`},N=e=>!!e.graph;function P(){let[e,t]=(0,s.useState)(null),[n,o]=(0,s.useState)(null),[c,l]=(0,s.useState)(null),[u,d]=(0,s.useState)(0);return i(e=>r.activeLoops().then(n=>e()&&(t(a(n)),o(null)),t=>e()&&o(t.message)),A,[u]),{loops:e?.loops??null,error:c||n,onPreset:(e,t)=>(l(null),r.setLoopPreset(e,t).then(()=>d(e=>e+1),e=>l(e.message)))}}var F=e=>({key:e,label:e,align:`right`,render:t=>(0,D.jsx)(`span`,{className:`num`,children:t[e]})}),I=[F(`iteration`),{key:`intent`,label:`intent`},F(`declared`),F(`actual`),{key:`decision`,label:`decision`},{key:`tests`,label:`tests`}];function L({history:e}){return e.length?(0,D.jsx)(`div`,{className:`loop-history`,children:(0,D.jsx)(o,{caption:`Iterations`,captionHidden:!0,columns:I,rows:e,rowKey:e=>e.iteration})}):(0,D.jsx)(`p`,{className:`panel-note`,children:`No iteration finished yet.`})}function R({loop:e,bricks:t,onPreset:n}){let r=N(e)?(e.graph.loops||[]).find(e=>e.iteration):null,[i,a]=(0,s.useState)(!1);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`reader-tags`,children:[(0,D.jsx)(`span`,{className:`tag acc`,children:`Active loop`}),(0,D.jsx)(`span`,{className:`tag${M[e.status]?` ${M[e.status]}`:``}`,children:e.status})]}),(0,D.jsx)(`h2`,{className:`reader-title`,children:e.title}),(0,D.jsxs)(`p`,{className:`mono dim reader-src`,children:[e.branch,` · `,e.root]}),N(e)?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`p`,{className:`reader-lede`,children:[`Iteration `,e.iteration,r?` / ${r.max}`:``,` · at `,e.node]}),e.awaiting?(0,D.jsxs)(`p`,{className:`loop-run-wait t-warn`,children:[(0,D.jsxs)(`b`,{children:[`Awaiting `,e.awaiting.kind,e.awaiting.kind===`gate`?` at ${e.awaiting.node}`:``]}),` `,`— Answer in the agent's session.`]}):null,(0,D.jsxs)(`label`,{className:`panel-note loop-run-preset`,children:[`preset`,(0,D.jsx)(`select`,{className:`sel`,"aria-label":`Preset for ${e.title}`,value:e.preset,disabled:i,onChange:t=>{a(!0),Promise.resolve(n(e.root,t.target.value)).finally(()=>a(!1))},children:j.map(e=>(0,D.jsx)(`option`,{children:e},e))})]}),(0,D.jsx)(`a`,{href:`#/docs/loop-risk`,children:`What presets mean →`}),(0,D.jsx)(`hr`,{className:`hr`}),(0,D.jsx)(`div`,{className:`loop-graph`,children:(0,D.jsx)(k,{graph:e.graph,bricks:t,highlight:e.node})}),(0,D.jsx)(`h3`,{className:`loop-h2`,children:`Iterations`}),(0,D.jsx)(L,{history:e.history})]}):(0,D.jsx)(`p`,{className:`reader-lede`,children:e.status===`unreadable`?`Its LOOP.md cannot be read, so there is no state to show.`:`Its LOOP.md is gone: the loop closed and its state went with it.`})]})}export{O as a,w as c,P as i,M as n,k as o,N as r,C as s,R as t};
@@ -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-CZ-x0iWG.js";import{A as i,D as a,E as o,F as s,H as c,L as l,M as u,N as d,O as f,P as p,St as m,T as h,_t as g,et as _,j as v,o as ee,rt as te,tt as y,w as b,wt as x}from"./index-B_pTwZra.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 ne,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-B5XY9pid.js";import{s as re}from"./motion-RlUl1osO.js";import{n as ie,t as ae}from"./usePoll-D5c_qIFZ.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`:u(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=b[e.status]||b.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||f(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),s=(0,z.useMemo)(()=>E(e,{sakura:n}),[o]),c=b[e.status]||b.idle,l=Array.isArray(e.loops)?e.loops[0]:null,d=e.status!==`idle`,p=F(e),m=e.title||f(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${u(e)?` gd-needs`:``}`,href:e.href||L(e.session_id),"aria-label":Y(e,s,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,s.pads.length,i,_),children:[(0,B.jsx)(P,{t:s,pad:i,swaying:d,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:c.label}),t&&(0,B.jsxs)(`span`,{className:`badge mono`,children:[`⎇ `,t]}),l&&(0,B.jsxs)(`span`,{className:`badge`,children:[`↻ `,l.title,l.iteration==null?``:` ${l.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 oe({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 se({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)(ce,{sh:e,sakura:n,cols:s,mineOf:u},e.key))]})}function ce({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)(oe,{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 le({s:e}){let t=(0,z.useId)(),n=e.todos,r=v(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)(h,{s:e,id:t,heading:e.title||f(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)(g,{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 `,m(e.updated_at),` ago`]})]})}var ue={blocked:`is blocked`,"waiting-input":`waits for your answer`};function de(e,t){if(!Array.isArray(t))return``;let n=t.filter(u),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||f(e.cwd)||e.session_id} ${ue[e.status]}`).join(`. `):``}var fe=[[`all`,`All`],[`needs`,`Needs you`],[`runs`,`Runs`],[`gates`,`Gate asks`]];function pe(){let e=new URLSearchParams(window.location.hash.split(`?`)[1]||``),t=e.get(`f`);return{f:fe.some(([e])=>e===t)?t:`all`,host:e.get(`host`)||``,project:e.get(`project`)||``,v:e.get(`v`)===`list`?`list`:`garden`}}function me(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 he({enabled:e,installs:t,onToggle:n}){let r=ne(t);return(0,B.jsxs)(`section`,{className:`card pad-md act-track`,"aria-labelledby":`act-track-h`,children:[(0,B.jsx)(g,{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 ge({jobs:e,loading:t}){let n=typeof e?.cap==`number`?e.cap:void 0,r=d(e?.jobs,{days:14,cap:n}),i=s(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),c=r.find(e=>!e.nodata),l=r.some(e=>e.nodata),u=`Runs per day: ${r.filter(e=>e.n).map(e=>`${e.n} on ${p(e.key)}`).join(`, `)||`none`}.`+(l?c?` Days before ${p(c.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)(y,{label:`Reading the job log…`}):e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`act-runs`,role:`img`,"aria-label":u,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:`${p(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:p(r[0].key)}),(0,B.jsx)(`span`,{children:p(r[7].key)}),(0,B.jsx)(`span`,{children:`today`})]}),l&&(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 _e({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)(y,{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)(o,{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 ve={done:[`ok`,`done`],failed:[`bad`,`failed`],running:[``,`running`]};function ye({job:e,longest:t}){let n=l(e),r=e.duration?Math.round(e.duration*10)/10:0,[i,a]=ve[e.status]||[``,e.status||`…`],o=e.status===`running`?`Still running`:r?`Took ${r} second${r===1?``:`s`}`:`No duration`,s=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:s}),(0,B.jsx)(g,{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":o,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 be({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)(g,{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 xe=5,Se=(e,t)=>[...new Set([...e.filter(Boolean),t].filter(Boolean))];function Ce(){let[e,t]=(0,z.useState)(null),[n,a]=(0,z.useState)(``),[o,l]=(0,z.useState)(pe),[d,p]=(0,z.useState)(!1),[m,h]=(0,z.useState)(``),g=(0,z.useRef)(null),v=e=>{let t={...o,...e};l(t),me(t)};ie(e=>r.activity().then(n=>{if(e()){t(ae(n)),a(``);let e=de(g,n?.activity);e&&h(t=>t===e?e+`\xA0`:e)}},t=>{e()&&a(t.message)}),2e3,[]);let b=x(()=>$(r.jobs()),[]),C=x(()=>$(r.gates()),[]),w=x(()=>$(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=re(),A=T&&e?D.filter(u).length:null,ne=new Set(D.map(F)),j=o.v===`list`?O(e?.ended,E).filter(e=>!ne.has(F(e))):[],M=Se([...D,...j].map(e=>e.host),o.host),N=Se([...D,...j].map(e=>f(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||f(e.cwd)===o.project),L=D.filter(e=>I(e)&&(o.f!==`needs`||u(e))),R=o.f===`all`||o.f===`needs`,V=o.f===`all`&&T?j.filter(I):[],H=d?V:V.slice(0,xe),U=!P&&(o.f===`all`||o.f===`runs`),W=!P&&(o.f===`all`||o.f===`gates`),G=b.data?.jobs||[],K=ee(C.data,w.data),q=i(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=s(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=>v({[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)(c,{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)(_,{error:n})}),e&&(0,B.jsx)(he,{enabled:T,installs:E,onToggle:X}),(0,B.jsxs)(`div`,{className:`act-today`,children:[(0,B.jsx)(ge,{jobs:b.data,loading:b.loading}),(0,B.jsx)(_e,{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)(y,{}):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:fe.map(([e,t])=>(0,B.jsxs)(`button`,{type:`button`,className:o.f===e?`chip-f on`:`chip-f`,"aria-pressed":o.f===e,onClick:()=>v({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)(te,{"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:()=>v({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)(se,{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)(le,{s:e})},F(e)))}):(0,B.jsx)(y,{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)(le,{s:e})},F(e))),V.length>xe&&(0,B.jsx)(`button`,{type:`button`,className:`btn ghost sm`,"aria-expanded":d,onClick:()=>p(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)(ye,{job:e,longest:J},e.id)),e.gate&&(0,B.jsx)(be,{gate:e.gate})]})]},e.key))})]})}export{Ce 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-DxwG8y94.js";import{A as i,D as a,E as o,F as s,H as c,L as l,M as u,N as d,O as f,P as p,St as m,T as h,_t as g,et as _,j as v,o as ee,rt as te,tt as y,w as b,wt as x}from"./index-MB7E-va_.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 ne,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-8NtlFrPO.js";import{s as re}from"./motion-RlUl1osO.js";import{n as ie,t as ae}from"./usePoll-D5c_qIFZ.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`:u(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=b[e.status]||b.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||f(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),s=(0,z.useMemo)(()=>E(e,{sakura:n}),[o]),c=b[e.status]||b.idle,l=Array.isArray(e.loops)?e.loops[0]:null,d=e.status!==`idle`,p=F(e),m=e.title||f(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${u(e)?` gd-needs`:``}`,href:e.href||L(e.session_id),"aria-label":Y(e,s,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,s.pads.length,i,_),children:[(0,B.jsx)(P,{t:s,pad:i,swaying:d,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:c.label}),t&&(0,B.jsxs)(`span`,{className:`badge mono`,children:[`⎇ `,t]}),l&&(0,B.jsxs)(`span`,{className:`badge`,children:[`↻ `,l.title,l.iteration==null?``:` ${l.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 oe({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 se({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)(ce,{sh:e,sakura:n,cols:s,mineOf:u},e.key))]})}function ce({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)(oe,{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 le({s:e}){let t=(0,z.useId)(),n=e.todos,r=v(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)(h,{s:e,id:t,heading:e.title||f(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)(g,{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 `,m(e.updated_at),` ago`]})]})}var ue={blocked:`is blocked`,"waiting-input":`waits for your answer`};function de(e,t){if(!Array.isArray(t))return``;let n=t.filter(u),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||f(e.cwd)||e.session_id} ${ue[e.status]}`).join(`. `):``}var fe=[[`all`,`All`],[`needs`,`Needs you`],[`runs`,`Runs`],[`gates`,`Gate asks`]];function pe(){let e=new URLSearchParams(window.location.hash.split(`?`)[1]||``),t=e.get(`f`);return{f:fe.some(([e])=>e===t)?t:`all`,host:e.get(`host`)||``,project:e.get(`project`)||``,v:e.get(`v`)===`list`?`list`:`garden`}}function me(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 he({enabled:e,installs:t,onToggle:n}){let r=ne(t);return(0,B.jsxs)(`section`,{className:`card pad-md act-track`,"aria-labelledby":`act-track-h`,children:[(0,B.jsx)(g,{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 ge({jobs:e,loading:t}){let n=typeof e?.cap==`number`?e.cap:void 0,r=d(e?.jobs,{days:14,cap:n}),i=s(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),c=r.find(e=>!e.nodata),l=r.some(e=>e.nodata),u=`Runs per day: ${r.filter(e=>e.n).map(e=>`${e.n} on ${p(e.key)}`).join(`, `)||`none`}.`+(l?c?` Days before ${p(c.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)(y,{label:`Reading the job log…`}):e?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(`div`,{className:`act-runs`,role:`img`,"aria-label":u,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:`${p(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:p(r[0].key)}),(0,B.jsx)(`span`,{children:p(r[7].key)}),(0,B.jsx)(`span`,{children:`today`})]}),l&&(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 _e({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)(y,{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)(o,{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 ve={done:[`ok`,`done`],failed:[`bad`,`failed`],running:[``,`running`]};function ye({job:e,longest:t}){let n=l(e),r=e.duration?Math.round(e.duration*10)/10:0,[i,a]=ve[e.status]||[``,e.status||`…`],o=e.status===`running`?`Still running`:r?`Took ${r} second${r===1?``:`s`}`:`No duration`,s=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:s}),(0,B.jsx)(g,{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":o,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 be({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)(g,{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 xe=5,Se=(e,t)=>[...new Set([...e.filter(Boolean),t].filter(Boolean))];function Ce(){let[e,t]=(0,z.useState)(null),[n,a]=(0,z.useState)(``),[o,l]=(0,z.useState)(pe),[d,p]=(0,z.useState)(!1),[m,h]=(0,z.useState)(``),g=(0,z.useRef)(null),v=e=>{let t={...o,...e};l(t),me(t)};ie(e=>r.activity().then(n=>{if(e()){t(ae(n)),a(``);let e=de(g,n?.activity);e&&h(t=>t===e?e+`\xA0`:e)}},t=>{e()&&a(t.message)}),2e3,[]);let b=x(()=>$(r.jobs()),[]),C=x(()=>$(r.gates()),[]),w=x(()=>$(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=re(),A=T&&e?D.filter(u).length:null,ne=new Set(D.map(F)),j=o.v===`list`?O(e?.ended,E).filter(e=>!ne.has(F(e))):[],M=Se([...D,...j].map(e=>e.host),o.host),N=Se([...D,...j].map(e=>f(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||f(e.cwd)===o.project),L=D.filter(e=>I(e)&&(o.f!==`needs`||u(e))),R=o.f===`all`||o.f===`needs`,V=o.f===`all`&&T?j.filter(I):[],H=d?V:V.slice(0,xe),U=!P&&(o.f===`all`||o.f===`runs`),W=!P&&(o.f===`all`||o.f===`gates`),G=b.data?.jobs||[],K=ee(C.data,w.data),q=i(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=s(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=>v({[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)(c,{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)(_,{error:n})}),e&&(0,B.jsx)(he,{enabled:T,installs:E,onToggle:X}),(0,B.jsxs)(`div`,{className:`act-today`,children:[(0,B.jsx)(ge,{jobs:b.data,loading:b.loading}),(0,B.jsx)(_e,{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)(y,{}):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:fe.map(([e,t])=>(0,B.jsxs)(`button`,{type:`button`,className:o.f===e?`chip-f on`:`chip-f`,"aria-pressed":o.f===e,onClick:()=>v({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)(te,{"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:()=>v({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)(se,{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)(le,{s:e})},F(e)))}):(0,B.jsx)(y,{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)(le,{s:e})},F(e))),V.length>xe&&(0,B.jsx)(`button`,{type:`button`,className:`btn ghost sm`,"aria-expanded":d,onClick:()=>p(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)(ye,{job:e,longest:J},e.id)),e.gate&&(0,B.jsx)(be,{gate:e.gate})]})]},e.key))})]})}export{Ce 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-CZ-x0iWG.js";import{H as i,M as a,O as o,St as s,T as c,_t as l,et as u,k as d,tt as f}from"./index-B_pTwZra.js";import{a as p,d as m,f as h,i as g,l as _,o as v,r as y,t as b,v as x}from"./Bonsai-B5XY9pid.js";import{t as S}from"./EmptyState-CY5Pm2xy.js";import{n as C,t as w}from"./usePoll-D5c_qIFZ.js";var T=e(t(),1),E=n();function D(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 O({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(`${d(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,E.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,E.jsx)(`span`,{className:`badge act-who ${t?``:`acc`}`,children:t?`you`:`agent`}),(0,E.jsxs)(`div`,{className:`act-grow act-sm`,children:[!t&&(0,E.jsx)(`span`,{className:`feed-dot act-inline-dot ${D(e)||`acc`}`}),e.kind===`thinking`&&(0,E.jsx)(`span`,{className:`dim`,children:`thinking: `}),r?(0,E.jsx)(`span`,{className:`dim`,children:i}):t?i:(0,E.jsx)(`b`,{children:i}),e.error&&(0,E.jsxs)(`span`,{className:`dim`,children:[`: `,e.error]})]}),n.length>0&&(0,E.jsx)(`span`,{className:`dim mono act-xs act-fixed`,children:n.join(` · `)}),e.t?(0,E.jsx)(`time`,{className:`mono dim act-xs act-fixed`,dateTime:new Date(e.t).toISOString(),title:`${s(e.t/1e3)} ago`,children:new Date(e.t).toTimeString().slice(0,8)}):null]})}function k({turns:e}){return!e||e.length===0?(0,E.jsx)(`div`,{className:`dim act-sm`,children:`No conversation captured yet.`}):(0,E.jsx)(`div`,{className:`stack gap-12`,children:e.map((e,t)=>{let n=e.role===`user`;return(0,E.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,E.jsx)(`span`,{className:`badge act-who ${n?``:`acc`}`,children:n?`you`:`agent`}),(0,E.jsx)(`div`,{className:`act-min act-sm${n?``:` muted`}`,children:e.text})]},t)})})}var A=5;function j({s:e}){let[t]=(0,T.useState)(v),[n,r]=(0,T.useState)(null),i=!!e.ended,o=i?{...e,status:a(e)?`busy`:e.status,error:null}:e,s=x(o,t),c=(0,T.useMemo)(()=>h(o,{sakura:t}),[s]),l=(0,T.useCallback)(e=>r(e),[]),u=_(e),d=Number(e.turns)||0,f=Number(e.compactions)||0,m=[`${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} ${i?`unfinished`:`running`}, ${c.fallen.length} finished`].join(` · `),S=n==null?null:c.pads[n];return(0,E.jsxs)(`div`,{className:`card pad-md act-mt gd-detail${!i&&a(e)?` gd-needs`:``}`,children:[(0,E.jsx)(`div`,{role:`group`,tabIndex:0,"aria-label":`Bonsai pads, arrow keys walk them`,onKeyDown:e=>g(e,c.pads.length,n,l),children:(0,E.jsx)(y,{t:c,pad:n,swaying:!i&&e.status!==`idle`,onPad:l,px:A,label:`Bonsai of this session${i?`, ended`:``}: ${m}`})}),(0,E.jsxs)(`div`,{className:`stack gap-8 act-min`,children:[i&&(0,E.jsx)(`span`,{className:`dim act-xs`,children:`ended`}),(0,E.jsx)(`div`,{className:`dim act-sm`,children:m}),(0,E.jsx)(`span`,{className:`sr-only`,role:`status`,children:p(S)}),S?(0,E.jsx)(b,{pad:S}):(0,E.jsx)(`div`,{className:`dim act-xs`,children:`Hover or tap a pad, or use the arrow keys, for its files.`})]})]})}function M({sid:e}){let{sid:t,install:n}=m(e,window.location.hash),[a,d]=(0,T.useState)(null),[p,h]=(0,T.useState)(``),[g,_]=(0,T.useState)(!1),[v,y]=(0,T.useState)(!1),b=(0,T.useId)();C(e=>g?void 0:r.activityDetail(t,n).then(t=>{e()&&(d(w(t)),h(``),_(!1))},t=>{e()&&(t.status===404?_(!0):h(t.message))}),2e3,[t,g]);let x=(0,E.jsxs)(`a`,{className:`btn ghost sm act-back`,href:`#/activity`,children:[(0,E.jsx)(l,{name:`arrow`}),` Activity`]});if(g)return(0,E.jsxs)(`div`,{className:`page-fill`,children:[x,(0,E.jsx)(S,{title:`Session ended`,action:(0,E.jsx)(`a`,{href:`#/activity`,children:`Back to Activity`}),children:`It's no longer live.`})]});if(!a)return(0,E.jsxs)(`div`,{className:`page-fill`,children:[x,p?(0,E.jsx)(u,{error:p}):(0,E.jsx)(f,{label:`Loading session…`})]});let D=a.session,A=D.files,M=D.todos,N=!!(A&&A.items&&A.items.length>0),P=!!(M&&M.items&&M.items.length>0),F=a.conversation||[],I=a.timeline||[],L=[...F.filter(e=>e.role===`user`).map(e=>({who:`you`,text:e.text,t:e.t||0})),...I.map(e=>({...e,who:`agent`}))].sort((e,t)=>(e.t||0)-(t.t||0));return(0,E.jsxs)(`div`,{className:`page-fill`,children:[x,(0,E.jsx)(i,{title:D.title||o(D.cwd)||D.session_id,sub:D.cwd?(0,E.jsx)(`span`,{className:`mono act-cwd`,title:D.cwd,children:D.cwd}):null}),p&&(0,E.jsx)(`div`,{className:`act-gap`,children:(0,E.jsx)(u,{error:p})}),(0,E.jsxs)(`div`,{className:`card pad-md`,children:[(0,E.jsx)(c,{s:D}),(0,E.jsxs)(`div`,{className:`dim act-updated`,children:[`updated `,s(D.updated_at),` ago`]})]}),(0,E.jsx)(j,{s:D}),(N||P)&&(0,E.jsxs)(`div`,{className:`grid gap-12 act-panels${N&&P?` two`:``}`,children:[N&&(0,E.jsxs)(`div`,{className:`card pad-md`,children:[(0,E.jsx)(`div`,{className:`card-head`,children:(0,E.jsxs)(`h2`,{children:[`Files touched `,(0,E.jsxs)(`span`,{className:`dim`,children:[`(`,A.count,`)`]})]})}),(0,E.jsx)(`div`,{className:`stack act-list`,children:A.items.map(e=>(0,E.jsxs)(`div`,{className:`row between gap-12 act-sm`,children:[(0,E.jsx)(`span`,{className:`mono act-ell act-grow`,title:e.file,children:e.file}),(0,E.jsxs)(`span`,{className:`act-fixed`,children:[(0,E.jsxs)(`span`,{className:`t-good`,children:[`+`,e.additions]}),` `,(0,E.jsxs)(`span`,{className:`t-bad`,children:[`−`,e.deletions]})]})]},e.file))})]}),P&&(0,E.jsxs)(`div`,{className:`card pad-md`,children:[(0,E.jsx)(`div`,{className:`card-head`,children:(0,E.jsxs)(`h2`,{children:[`Plan`,` `,(0,E.jsxs)(`span`,{className:`dim`,children:[`(`,M.done,`/`,M.total,`)`]})]})}),(0,E.jsx)(`div`,{className:`stack act-list`,children:M.items.map((e,t)=>(0,E.jsxs)(`div`,{className:`row gap-8 act-sm`,children:[(0,E.jsx)(`span`,{className:`feed-dot ${e.status===`completed`?`ok`:e.status===`in_progress`?`acc`:``}`}),(0,E.jsx)(`span`,{className:e.status===`completed`?`act-done`:void 0,children:e.content})]},t))})]})]}),(0,E.jsxs)(`div`,{className:`card pad-md act-mt`,children:[(0,E.jsxs)(`div`,{className:`card-head act-tl-head`,children:[(0,E.jsx)(`h2`,{children:`Timeline`}),I.length>0&&(0,E.jsx)(`button`,{className:`btn ghost sm`,"aria-expanded":v,"aria-controls":b,onClick:()=>y(e=>!e),children:v?`Show conversation`:`Show full stream (${L.length})`})]}),(0,E.jsx)(`div`,{id:b,children:v?(0,E.jsx)(`div`,{className:`stack gap-12`,children:L.map((e,t)=>(0,E.jsx)(O,{rec:e},t))}):(0,E.jsx)(k,{turns:F})})]})]})}export{j as SessionTree,M 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-DxwG8y94.js";import{H as i,M as a,O as o,St as s,T as c,_t as l,et as u,k as d,tt as f}from"./index-MB7E-va_.js";import{a as p,d as m,f as h,i as g,l as _,o as v,r as y,t as b,v as x}from"./Bonsai-8NtlFrPO.js";import{t as S}from"./EmptyState-CY5Pm2xy.js";import{n as C,t as w}from"./usePoll-D5c_qIFZ.js";var T=e(t(),1),E=n();function D(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 O({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(`${d(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,E.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,E.jsx)(`span`,{className:`badge act-who ${t?``:`acc`}`,children:t?`you`:`agent`}),(0,E.jsxs)(`div`,{className:`act-grow act-sm`,children:[!t&&(0,E.jsx)(`span`,{className:`feed-dot act-inline-dot ${D(e)||`acc`}`}),e.kind===`thinking`&&(0,E.jsx)(`span`,{className:`dim`,children:`thinking: `}),r?(0,E.jsx)(`span`,{className:`dim`,children:i}):t?i:(0,E.jsx)(`b`,{children:i}),e.error&&(0,E.jsxs)(`span`,{className:`dim`,children:[`: `,e.error]})]}),n.length>0&&(0,E.jsx)(`span`,{className:`dim mono act-xs act-fixed`,children:n.join(` · `)}),e.t?(0,E.jsx)(`time`,{className:`mono dim act-xs act-fixed`,dateTime:new Date(e.t).toISOString(),title:`${s(e.t/1e3)} ago`,children:new Date(e.t).toTimeString().slice(0,8)}):null]})}function k({turns:e}){return!e||e.length===0?(0,E.jsx)(`div`,{className:`dim act-sm`,children:`No conversation captured yet.`}):(0,E.jsx)(`div`,{className:`stack gap-12`,children:e.map((e,t)=>{let n=e.role===`user`;return(0,E.jsxs)(`div`,{className:`row gap-10 act-line`,children:[(0,E.jsx)(`span`,{className:`badge act-who ${n?``:`acc`}`,children:n?`you`:`agent`}),(0,E.jsx)(`div`,{className:`act-min act-sm${n?``:` muted`}`,children:e.text})]},t)})})}var A=5;function j({s:e}){let[t]=(0,T.useState)(v),[n,r]=(0,T.useState)(null),i=!!e.ended,o=i?{...e,status:a(e)?`busy`:e.status,error:null}:e,s=x(o,t),c=(0,T.useMemo)(()=>h(o,{sakura:t}),[s]),l=(0,T.useCallback)(e=>r(e),[]),u=_(e),d=Number(e.turns)||0,f=Number(e.compactions)||0,m=[`${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} ${i?`unfinished`:`running`}, ${c.fallen.length} finished`].join(` · `),S=n==null?null:c.pads[n];return(0,E.jsxs)(`div`,{className:`card pad-md act-mt gd-detail${!i&&a(e)?` gd-needs`:``}`,children:[(0,E.jsx)(`div`,{role:`group`,tabIndex:0,"aria-label":`Bonsai pads, arrow keys walk them`,onKeyDown:e=>g(e,c.pads.length,n,l),children:(0,E.jsx)(y,{t:c,pad:n,swaying:!i&&e.status!==`idle`,onPad:l,px:A,label:`Bonsai of this session${i?`, ended`:``}: ${m}`})}),(0,E.jsxs)(`div`,{className:`stack gap-8 act-min`,children:[i&&(0,E.jsx)(`span`,{className:`dim act-xs`,children:`ended`}),(0,E.jsx)(`div`,{className:`dim act-sm`,children:m}),(0,E.jsx)(`span`,{className:`sr-only`,role:`status`,children:p(S)}),S?(0,E.jsx)(b,{pad:S}):(0,E.jsx)(`div`,{className:`dim act-xs`,children:`Hover or tap a pad, or use the arrow keys, for its files.`})]})]})}function M({sid:e}){let{sid:t,install:n}=m(e,window.location.hash),[a,d]=(0,T.useState)(null),[p,h]=(0,T.useState)(``),[g,_]=(0,T.useState)(!1),[v,y]=(0,T.useState)(!1),b=(0,T.useId)();C(e=>g?void 0:r.activityDetail(t,n).then(t=>{e()&&(d(w(t)),h(``),_(!1))},t=>{e()&&(t.status===404?_(!0):h(t.message))}),2e3,[t,g]);let x=(0,E.jsxs)(`a`,{className:`btn ghost sm act-back`,href:`#/activity`,children:[(0,E.jsx)(l,{name:`arrow`}),` Activity`]});if(g)return(0,E.jsxs)(`div`,{className:`page-fill`,children:[x,(0,E.jsx)(S,{title:`Session ended`,action:(0,E.jsx)(`a`,{href:`#/activity`,children:`Back to Activity`}),children:`It's no longer live.`})]});if(!a)return(0,E.jsxs)(`div`,{className:`page-fill`,children:[x,p?(0,E.jsx)(u,{error:p}):(0,E.jsx)(f,{label:`Loading session…`})]});let D=a.session,A=D.files,M=D.todos,N=!!(A&&A.items&&A.items.length>0),P=!!(M&&M.items&&M.items.length>0),F=a.conversation||[],I=a.timeline||[],L=[...F.filter(e=>e.role===`user`).map(e=>({who:`you`,text:e.text,t:e.t||0})),...I.map(e=>({...e,who:`agent`}))].sort((e,t)=>(e.t||0)-(t.t||0));return(0,E.jsxs)(`div`,{className:`page-fill`,children:[x,(0,E.jsx)(i,{title:D.title||o(D.cwd)||D.session_id,sub:D.cwd?(0,E.jsx)(`span`,{className:`mono act-cwd`,title:D.cwd,children:D.cwd}):null}),p&&(0,E.jsx)(`div`,{className:`act-gap`,children:(0,E.jsx)(u,{error:p})}),(0,E.jsxs)(`div`,{className:`card pad-md`,children:[(0,E.jsx)(c,{s:D}),(0,E.jsxs)(`div`,{className:`dim act-updated`,children:[`updated `,s(D.updated_at),` ago`]})]}),(0,E.jsx)(j,{s:D}),(N||P)&&(0,E.jsxs)(`div`,{className:`grid gap-12 act-panels${N&&P?` two`:``}`,children:[N&&(0,E.jsxs)(`div`,{className:`card pad-md`,children:[(0,E.jsx)(`div`,{className:`card-head`,children:(0,E.jsxs)(`h2`,{children:[`Files touched `,(0,E.jsxs)(`span`,{className:`dim`,children:[`(`,A.count,`)`]})]})}),(0,E.jsx)(`div`,{className:`stack act-list`,children:A.items.map(e=>(0,E.jsxs)(`div`,{className:`row between gap-12 act-sm`,children:[(0,E.jsx)(`span`,{className:`mono act-ell act-grow`,title:e.file,children:e.file}),(0,E.jsxs)(`span`,{className:`act-fixed`,children:[(0,E.jsxs)(`span`,{className:`t-good`,children:[`+`,e.additions]}),` `,(0,E.jsxs)(`span`,{className:`t-bad`,children:[`−`,e.deletions]})]})]},e.file))})]}),P&&(0,E.jsxs)(`div`,{className:`card pad-md`,children:[(0,E.jsx)(`div`,{className:`card-head`,children:(0,E.jsxs)(`h2`,{children:[`Plan`,` `,(0,E.jsxs)(`span`,{className:`dim`,children:[`(`,M.done,`/`,M.total,`)`]})]})}),(0,E.jsx)(`div`,{className:`stack act-list`,children:M.items.map((e,t)=>(0,E.jsxs)(`div`,{className:`row gap-8 act-sm`,children:[(0,E.jsx)(`span`,{className:`feed-dot ${e.status===`completed`?`ok`:e.status===`in_progress`?`acc`:``}`}),(0,E.jsx)(`span`,{className:e.status===`completed`?`act-done`:void 0,children:e.content})]},t))})]})]}),(0,E.jsxs)(`div`,{className:`card pad-md act-mt`,children:[(0,E.jsxs)(`div`,{className:`card-head act-tl-head`,children:[(0,E.jsx)(`h2`,{children:`Timeline`}),I.length>0&&(0,E.jsx)(`button`,{className:`btn ghost sm`,"aria-expanded":v,"aria-controls":b,onClick:()=>y(e=>!e),children:v?`Show conversation`:`Show full stream (${L.length})`})]}),(0,E.jsx)(`div`,{id:b,children:v?(0,E.jsx)(`div`,{className:`stack gap-12`,children:L.map((e,t)=>(0,E.jsx)(O,{rec:e},t))}):(0,E.jsx)(k,{turns:F})})]})]})}export{j as SessionTree,M as default};