@jmanuelcorral/bond-app 0.1.4 → 0.1.6

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 (78) hide show
  1. package/README.md +241 -7
  2. package/app/brand/TOKENS.md +5 -5
  3. package/app/layouts/bond.json +10 -14
  4. package/app/mods/bond-agents/api.js +35 -0
  5. package/app/mods/bond-agents/branch.svg +1 -0
  6. package/app/mods/bond-agents/brand.js +53 -2
  7. package/app/mods/bond-agents/config.js +8 -0
  8. package/app/mods/bond-agents/eye-off.svg +1 -0
  9. package/app/mods/bond-agents/eye.svg +1 -0
  10. package/app/mods/bond-agents/main.js +316 -330
  11. package/app/mods/bond-agents/model.js +400 -6
  12. package/app/mods/bond-board/api.js +35 -0
  13. package/app/mods/bond-board/branch.svg +1 -0
  14. package/app/mods/bond-board/brand.js +53 -2
  15. package/app/mods/bond-board/config.js +8 -0
  16. package/app/mods/bond-board/main.js +1054 -366
  17. package/app/mods/bond-board/model.js +138 -17
  18. package/app/mods/bond-pane/close.svg +1 -0
  19. package/app/mods/bond-pane/hide.svg +1 -0
  20. package/app/mods/bond-pane/main.js +103 -0
  21. package/app/mods/bond-pane/mod.json +1 -0
  22. package/app/mods/bond-pane/model.js +18 -0
  23. package/app/mods/bond-pane/split-down.svg +1 -0
  24. package/app/mods/bond-pane/split-right.svg +1 -0
  25. package/app/mods/bond-pane/unzoom.svg +1 -0
  26. package/app/mods/bond-pane/zoom.svg +1 -0
  27. package/app/mods/bond-settings/api.js +35 -0
  28. package/app/mods/bond-settings/brand.js +53 -2
  29. package/app/mods/bond-settings/config.js +8 -0
  30. package/app/mods/bond-settings/main.js +1645 -87
  31. package/app/mods/bond-settings/mod.json +1 -1
  32. package/app/mods/bond-settings/pi-models.js +144 -0
  33. package/app/mods/bond-status/api.js +35 -0
  34. package/app/mods/bond-status/brand.js +53 -2
  35. package/app/mods/bond-status/config.js +8 -0
  36. package/app/mods/bond-status/main.js +37 -15
  37. package/app/mods/bond-status/model.js +19 -1
  38. package/app/mods/bond-tabs/brand.js +53 -2
  39. package/app/mods/bond-tabs/main.js +45 -3
  40. package/app/mods/bond-titlebar/brand.js +53 -2
  41. package/app/mods/bond-titlebar/main.js +115 -55
  42. package/app/mods/bond-titlebar/version.js +3 -0
  43. package/app/themes/bond-dark.json +5 -5
  44. package/app/themes/bond-light.json +5 -5
  45. package/package.json +1 -1
  46. package/runner/Dockerfile +58 -15
  47. package/runner/SPIKE-BOND.md +89 -0
  48. package/runner/build-config/.none +0 -0
  49. package/runner/build-creds/.none +0 -0
  50. package/runner/config.example/README.md +27 -0
  51. package/runner/config.example/pi/models.json +22 -0
  52. package/runner/credentials.example.env +27 -0
  53. package/runner/entrypoint.sh +16 -0
  54. package/runner/setup.sh +927 -0
  55. package/runner/versions.env +61 -0
  56. package/scripts/app-install.ts +64 -1
  57. package/src/cli.ts +53 -3
  58. package/src/config.ts +8 -0
  59. package/src/core/agy-login.ts +682 -0
  60. package/src/core/delivery.ts +3 -1
  61. package/src/core/hub-session.ts +9 -7
  62. package/src/core/orchestrator.ts +1186 -168
  63. package/src/core/repo-host.ts +60 -0
  64. package/src/core/setup.ts +239 -0
  65. package/src/core/watchdog.ts +6 -6
  66. package/src/db/database.ts +55 -1
  67. package/src/db/settings-repo.ts +440 -7
  68. package/src/db/ticket-repo.ts +73 -17
  69. package/src/index.ts +4 -4
  70. package/src/runner/azure-devops-client.ts +163 -0
  71. package/src/runner/docker-client.ts +84 -5
  72. package/src/runner/github-client.ts +146 -0
  73. package/src/runner/hc-client.ts +40 -5
  74. package/src/runner/image-builder.ts +268 -10
  75. package/src/runner/jira-client.ts +368 -0
  76. package/src/runner/tool-catalog.ts +84 -0
  77. package/src/server/app.ts +585 -9
  78. package/src/types.ts +168 -1
@@ -1,18 +1,30 @@
1
1
  // bond-agents: the bond layout's right-hand Agents panel (P7 Ampliación / criterion 8).
2
2
  // Shows per run what the live table showed: agents, repo, state, commits, files,
3
3
  // fetched from GET /api/v1/runs/:id/team-status within the container.
4
- import { View, div } from "gpui-kit";
4
+ import { View, div, svg, image } from "gpui-kit";
5
5
  import { v_flex, h_flex } from "gpui-base";
6
- import { theme, run, shared } from "herdr";
6
+ import { theme, run, shared, setShared, panes, spaces, terminals } from "herdr";
7
7
  import { api } from "./api.js";
8
8
  import { UI, stateColor } from "./brand.js";
9
- import { POLL_MS, SELECTED_RUN_KEY, SELECTED_TICKET_KEY, REFRESH_KEY, LIVE_STATES, buildAgentsSections } from "./model.js";
9
+ import { POLL_MS, SELECTED_RUN_KEY, SELECTED_TICKET_KEY, REFRESH_KEY, LIVE_STATES, buildAgentsSections, isAgentTerminal, HIDDEN_KEY, INIT_TAB, agentIcon, isLeaderRow, rowName, rowRole, rowStats, attentionOf, machineOf, runMachine, readHidden, pruneHidden, planTabs, planPanels, panelBuildSteps, initTabToClose } from "./model.js";
10
+
11
+ // Per-run view mode, shared: { runId: true } for PANELES (E2: one tab of the run's space
12
+ // split in up to MAX_PANELS agents); absent is PESTAÑAS (one tab per agent). The layout
13
+ // file is never rewritten: both modes are native spaces, tabs and splits.
14
+ const PANELS_KEY = "bond.agents.panels";
15
+
16
+ /** A run's state in the board's words (the session header and the cards say the same). */
17
+ const RUN_STATE_ES = {
18
+ ready: "LISTO", queued: "EN COLA", analyzing: "ANALIZANDO", running: "EN CURSO", verifying: "VERIFICANDO",
19
+ waiting: "EN ESPERA", blocked: "EN ESPERA", finished: "TERMINADO", pr_ready: "PR LISTA", failed: "ERROR", error: "ERROR",
20
+ };
10
21
 
11
22
  export default class BondAgents extends View {
12
23
  init(_props, cx) {
13
24
  this.runs = [];
14
25
  this.tickets = [];
15
26
  this.teamStatusByRun = {};
27
+ this.terminalsByRun = {};
16
28
  this.loadError = null;
17
29
  this.selectedRunId = shared(SELECTED_RUN_KEY) ?? null;
18
30
  this.selectedTicketId = shared(SELECTED_TICKET_KEY) ?? null;
@@ -52,24 +64,35 @@ export default class BondAgents extends View {
52
64
  this.tickets = tickets ?? [];
53
65
  this.loadError = null;
54
66
 
55
- // Fetch team status only for the selected run
67
+ // Fetch team status and terminals only for the selected run
56
68
  const statusMap = {};
69
+ const terminalsMap = {};
57
70
  const targetRun = this.selectedRunId
58
71
  ? this.runs.find((r) => r.id === this.selectedRunId)
59
72
  : (this.selectedTicketId ? this.runs.find((r) => r.ticket_id === this.selectedTicketId) : null);
60
73
 
61
74
  if (targetRun) {
62
75
  try {
63
- const res = await api(`/runs/${targetRun.id}/team-status`);
64
- if (Array.isArray(res)) {
65
- statusMap[targetRun.id] = res;
76
+ const [statusRes, termRes] = await Promise.allSettled([
77
+ api(`/runs/${targetRun.id}/team-status`),
78
+ api(`/runs/${targetRun.id}/terminals`),
79
+ ]);
80
+ if (statusRes.status === "fulfilled" && Array.isArray(statusRes.value)) {
81
+ statusMap[targetRun.id] = statusRes.value;
82
+ }
83
+ if (termRes.status === "fulfilled" && Array.isArray(termRes.value)) {
84
+ terminalsMap[targetRun.id] = termRes.value;
66
85
  }
67
86
  } catch {
68
- // Graceful fallback if team status is unavailable
87
+ // Graceful fallback if endpoints are unavailable
69
88
  }
70
89
  }
71
90
 
72
91
  this.teamStatusByRun = statusMap;
92
+ this.terminalsByRun = terminalsMap;
93
+
94
+ // C1: Reconcile view mode idempotently on EVERY refresh
95
+ await this.reconcileView();
73
96
  } catch (e) {
74
97
  this.loadError = String(e?.message ?? e);
75
98
  }
@@ -77,327 +100,290 @@ export default class BondAgents extends View {
77
100
  });
78
101
  }
79
102
 
80
- focusAgent(row) {
81
- if (row.pane) {
82
- try {
83
- run("pane.focus", { pane: row.pane });
84
- } catch {}
103
+ isRunLive(run) {
104
+ if (!run || typeof run !== "object") return false;
105
+ const state = String(run.state || "").toLowerCase();
106
+ return ["running", "waiting", "verifying", "blocked", "analyzing"].includes(state);
107
+ }
108
+
109
+ selectedRun() {
110
+ return this.selectedRunId
111
+ ? this.runs.find((r) => r.id === this.selectedRunId)
112
+ : (this.selectedTicketId ? this.runs.find((r) => r.ticket_id === this.selectedTicketId) : null);
113
+ }
114
+
115
+ runTitle(run) {
116
+ const ticket = this.tickets.find((t) => t.id === run?.ticket_id);
117
+ return String(ticket?.title || run?.id || "run");
118
+ }
119
+
120
+ /** E4: the hidden list, with the dead terminals of `machine` forgotten (saved if it changed). */
121
+ syncHidden(machine, liveAddrs) {
122
+ const current = shared(HIDDEN_KEY);
123
+ const next = pruneHidden(readHidden(current), machine, liveAddrs);
124
+ if (JSON.stringify([...readHidden(current)].sort()) !== JSON.stringify(next)) setShared(HIDDEN_KEY, next);
125
+ return new Set(next);
126
+ }
127
+
128
+ setHidden(addr, hide) {
129
+ const set = readHidden(shared(HIDDEN_KEY));
130
+ if (hide === set.has(addr)) return;
131
+ if (hide) set.add(addr);
132
+ else set.delete(addr);
133
+ setShared(HIDDEN_KEY, [...set].sort());
134
+ }
135
+
136
+ /** E1: show the run's space (its machine's), making it when missing. space.new brings a
137
+ * shell in an INIT_TAB tab that the reconciler closes once the orchestrator has its own. */
138
+ showRunSpace(machine, title) {
139
+ if (!machine) return;
140
+ const sp = (spaces() ?? []).find((s) => s.machine === machine);
141
+ if (sp) {
142
+ if (!sp.active) run("space.select", { id: sp.id });
143
+ } else {
144
+ run("space.new", { machine, name: title, tab: INIT_TAB });
85
145
  }
86
146
  }
87
147
 
88
- agentRow(row, t) {
89
- const toneColor = t[row.style?.tone] ?? t.foreground ?? "#ffffff";
90
- const agentName = String(row.agentName ?? "agente");
91
- const repoLabel = String(row.repoLabel ?? "-");
92
- const icon = String(row.style?.icon ?? "•");
93
- const label = String(row.style?.label ?? "Desconocido");
94
- const ahead = String(row.aheadLabel ?? "-");
95
- const files = String(row.filesLabel ?? "-");
96
- const isLeader = agentName === "hub leader" || repoLabel === "orquestador" || row.agent?.name === "hub leader" || row.path === "/workspace/hub";
97
- const roleTag = isLeader ? "Hub Leader" : "Worker";
98
- const rowBorder = isLeader ? (t.bond_indigo ?? t.accent) : t.border;
99
- const initials = isLeader ? "👑" : agentName.slice(0, 2).toUpperCase();
148
+ /**
149
+ * One reconciler, run on every refresh (C1, E3): the desired view (the run's live agents,
150
+ * its mode, the hidden list) against what really shows (panes() of the run's machine).
151
+ */
152
+ async reconcileView() {
153
+ try {
154
+ const targetRun = this.selectedRun();
155
+ // The selected run's terminals are known only if /terminals answered this refresh.
156
+ const termsKnown = Boolean(targetRun && Array.isArray(this.terminalsByRun[targetRun.id]));
157
+ if (!targetRun || !this.isRunLive(targetRun)) return;
158
+ // /terminals failed this refresh: leave tabs and layout as they are (no churn).
159
+ if (!termsKnown) return;
100
160
 
101
- return v_flex()
102
- .id(`agent-row-${agentName}-${repoLabel}`)
103
- .w_full()
104
- .p(8)
105
- .rounded(UI.radius)
106
- .bg(t.surface)
107
- .border_1()
108
- .border_color(rowBorder)
109
- .gap(6)
110
- .child(
111
- // Header row: Avatar + Name/Role + Worktree + Status badge
112
- h_flex()
113
- .items_start()
114
- .justify_between()
115
- .gap(6)
116
- .child(
117
- h_flex()
118
- .items_center()
119
- .gap(6)
120
- .child(
121
- div()
122
- .size(28)
123
- .rounded(UI.radius)
124
- .bg(isLeader ? t.popover : t.raised)
125
- .border_1()
126
- .border_color(isLeader ? (t.bond_indigo ?? t.accent) : t.border)
127
- .flex()
128
- .items_center()
129
- .justify_center()
130
- .text_size(isLeader ? 11 : UI.text.tiny)
131
- .font_semibold()
132
- .font_family("JetBrains Mono")
133
- .text_color(isLeader ? (t.bond_indigo ?? t.accent) : t.muted)
134
- .child(initials)
135
- )
136
- .child(
137
- v_flex()
138
- .gap(1)
139
- .child(
140
- h_flex()
141
- .items_center()
142
- .gap(4)
143
- .child(
144
- div()
145
- .text_size(UI.text.body)
146
- .font_semibold()
147
- .font_family("JetBrains Mono")
148
- .text_color(t.foreground)
149
- .child(agentName)
150
- )
151
- .child(
152
- div()
153
- .px(4)
154
- .py(0.5)
155
- .rounded(4)
156
- .bg(t.raised)
157
- .border_1()
158
- .border_color(t.border)
159
- .text_size(UI.text.tiny)
160
- .font_family("JetBrains Mono")
161
- .text_color(isLeader ? (t.bond_indigo ?? t.accent) : t.dim)
162
- .child(roleTag)
163
- )
164
- )
165
- .child(
166
- div()
167
- .text_size(UI.text.tiny)
168
- .font_family("JetBrains Mono")
169
- .text_color(t.muted)
170
- .truncate()
171
- .child(repoLabel)
172
- )
173
- )
174
- )
175
- .child(
176
- h_flex()
177
- .gap(3)
178
- .items_center()
179
- .px(5)
180
- .py(1)
181
- .rounded(UI.radius)
182
- .bg(t.raised)
183
- .border_1()
184
- .border_color(t.border)
185
- .text_size(UI.text.tiny)
186
- .font_family("JetBrains Mono")
187
- .text_color(toneColor)
188
- .child(icon)
189
- .child(label)
190
- )
191
- )
192
- // Stats box
193
- .child(
194
- v_flex()
195
- .p(6)
196
- .rounded(UI.radius)
197
- .bg(t.raised)
198
- .border_1()
199
- .border_color(t.border)
200
- .gap(2)
201
- .font_family("JetBrains Mono")
202
- .text_size(UI.text.tiny)
203
- .text_color(t.dim)
204
- .child(
205
- h_flex()
206
- .items_center()
207
- .justify_between()
208
- .child(div().child("Git Worktree:"))
209
- .child(div().font_semibold().text_color(t.working).child(`${ahead} commits · ${files} ficheros`))
210
- )
211
- .when(Boolean(row.branch), (el) =>
212
- el.child(
213
- h_flex()
214
- .items_center()
215
- .justify_between()
216
- .child(div().child("Rama:"))
217
- .child(div().text_color(t.muted).truncate().child(String(row.branch)))
218
- )
219
- )
220
- )
221
- // Question block if waiting
222
- .when(Boolean(row.question), (el) => {
223
- const qText = typeof row.question === "object"
224
- ? String(row.question.text ?? JSON.stringify(row.question))
225
- : String(row.question);
226
- return el.child(
227
- v_flex()
228
- .w_full()
229
- .p(6)
230
- .rounded(UI.radius)
231
- .bg(t.popover)
232
- .border_1()
233
- .border_color(t.bond_waiting ?? t.blocked)
234
- .gap(2)
235
- .font_family("JetBrains Mono")
236
- .child(
237
- div()
238
- .text_size(UI.text.tiny)
239
- .font_semibold()
240
- .text_color(t.bond_waiting ?? t.blocked)
241
- .child("Esperando respuesta:")
242
- )
243
- .child(
244
- div()
245
- .text_size(UI.text.small)
246
- .text_color(t.foreground)
247
- .child(qText)
248
- )
249
- );
250
- })
251
- // Action: focus agent terminal
252
- .when(Boolean(row.pane), (el) =>
253
- el.child(
254
- h_flex()
255
- .justify_end()
256
- .pt(1)
257
- .child(
258
- div()
259
- .text_size(UI.text.tiny)
260
- .font_family("JetBrains Mono")
261
- .text_color(t.accent)
262
- .cursor_pointer()
263
- .hover((s) => s.text_color(t.foreground))
264
- .on_click(() => this.focusAgent(row))
265
- .child("Sincronizar Terminal >")
266
- )
267
- )
268
- );
161
+ const liveTerms = this.terminalsByRun[targetRun.id].filter((t) => {
162
+ if (t.exit_code !== null && t.exit_code !== undefined) return false;
163
+ if (t.state && t.state !== "live") return false;
164
+ return true;
165
+ });
166
+ // C7: only coding agents are shown as tabs or blocks; dev servers/shells are not.
167
+ const agentAddrs = liveTerms.filter(isAgentTerminal).map((t) => t.address);
168
+ const machine = runMachine(targetRun);
169
+ const space = (spaces() ?? []).find((s) => s.machine === machine) ?? null;
170
+ if (!space) {
171
+ // The run is selected but its space is gone (closed, or emptied): make it again.
172
+ this.showRunSpace(machine, this.runTitle(targetRun));
173
+ return;
174
+ }
175
+ const paneList = (panes() ?? []).filter((p) => p?.terminal && machineOf(p.terminal) === machine);
176
+ const hidden = this.syncHidden(machine, liveTerms.map((t) => t.address));
177
+
178
+ const canKeep = Boolean(space?.active);
179
+ const park = (list) => {
180
+ for (const addr of list) {
181
+ try {
182
+ run("terminal.park", { terminal: addr });
183
+ } catch {}
184
+ }
185
+ };
186
+ if (this.isPanels(targetRun.id)) {
187
+ // PANELES (E2): rebuilt in two passes (park now, build on a pass where none shows).
188
+ const plan = planPanels({ machine, agentAddrs, paneList, hidden, canKeep });
189
+ park(plan.park);
190
+ for (const [cmd, args] of panelBuildSteps(plan.build, plan.baseShown)) {
191
+ try {
192
+ run(cmd, args);
193
+ } catch {}
194
+ }
195
+ } else {
196
+ const plan = planTabs({ machine, agentAddrs, paneList, hidden, canKeep });
197
+ park(plan.park);
198
+ for (const addr of plan.keep) {
199
+ try {
200
+ run("terminal.keep", { terminal: addr, place: "tab" });
201
+ } catch {}
202
+ }
203
+ }
204
+ const init = initTabToClose(space, panes() ?? [], machine, agentAddrs);
205
+ if (init) {
206
+ try {
207
+ run("tab.close", { id: init });
208
+ } catch {}
209
+ }
210
+ } catch {}
269
211
  }
270
212
 
213
+ /** «Sincronizar Terminal»: un-hide the agent and bring it to the front, giving it a tab
214
+ * in its run's space when it has no pane (E4) — in PANELES too, for an agent beyond the
215
+ * grid; a hidden one of the grid goes back to it on the next rebuild. terminal.keep only
216
+ * lands in the shown space of its own machine, so that space is shown first. */
217
+ focusAgent(row) {
218
+ if (!row.pane) return;
219
+ const addr = String(row.pane);
220
+ try {
221
+ if (!addr.includes("/")) {
222
+ run("pane.focus", { pane: addr });
223
+ return;
224
+ }
225
+ this.setHidden(addr, false);
226
+ const hasPane = (panes() ?? []).some((p) => p?.terminal === addr);
227
+ if (!hasPane) {
228
+ this.showRunSpace(machineOf(addr), this.runTitle(this.selectedRun()));
229
+ run("terminal.keep", { terminal: addr, place: "tab" });
230
+ }
231
+ run("pane.focus", { terminal: addr });
232
+ } catch {}
233
+ }
234
+
235
+ /** «Ocultar» (E4): the pane goes, the agent keeps running; back only with «Sincronizar». */
236
+ hideAgent(row) {
237
+ const addr = String(row?.pane ?? "");
238
+ if (!addr.includes("/")) return;
239
+ this.setHidden(addr, true);
240
+ try {
241
+ run("terminal.park", { terminal: addr });
242
+ } catch {}
243
+ }
244
+
245
+ panelModes() {
246
+ const m = shared(PANELS_KEY);
247
+ return m && typeof m === "object" ? m : {};
248
+ }
249
+
250
+ isPanels(runId) {
251
+ return Boolean(runId && this.panelModes()[runId]);
252
+ }
253
+
254
+ /** PESTAÑAS <-> PANELES for one run; other runs keep their mode. */
255
+ togglePanels(runId) {
256
+ if (!runId) return;
257
+ const modes = { ...this.panelModes() };
258
+ if (modes[runId]) delete modes[runId];
259
+ else modes[runId] = true;
260
+ setShared(PANELS_KEY, modes);
261
+ this.reconcileView();
262
+ }
263
+
264
+ /** One agent as a list row (lista compacta, 2026-11-23): its icon, name, state with a fixed
265
+ * width (never past the edge), «program · role», stats only when there are some. Click:
266
+ * its terminal; the eye button hides it (or shows it again when hidden). */
267
+ agentRow(row, t, hidden = false) {
268
+ const name = rowName(row);
269
+ const leader = isLeaderRow(row);
270
+ const slug = String(row.pane ?? name).replace(/[^a-zA-Z0-9]/g, "_");
271
+ let program = null;
272
+ try {
273
+ program = row.pane ? (terminals() ?? []).find((x) => x.address === row.pane)?.program ?? null : null;
274
+ } catch {}
275
+ const pic = agentIcon(program, row.agent?.kind || row.agentName);
276
+ // «en espera» in the waiting yellow (its style tone is the red `blocked`); the rest as styled.
277
+ const tone = row.style?.label === "En espera" ? stateColor(t, "waiting") : (t[row.style?.tone] ?? t.dim);
278
+ const stateLabel = String(row.style?.label ?? "—").toLowerCase();
279
+ const stats = rowStats(row);
280
+ const remote = String(row.pane ?? "").includes("/");
281
+ const mono = (el) => el.font_family("JetBrains Mono");
282
+
283
+ const avatar = div().size(26).flex_none().rounded(UI.radius).bg(t.raised).border_1()
284
+ .border_color(leader ? (t.bond_indigo ?? t.accent) : t.border)
285
+ .flex().items_center().justify_center()
286
+ .child(pic
287
+ ? (pic.tint ? svg(pic.icon).size(15).text_color(t.foreground) : image(pic.icon).w(15).h(15))
288
+ : mono(div().text_size(UI.text.tiny).font_semibold().text_color(t.muted)).child(leader ? "👑" : name.slice(0, 2).toUpperCase()));
289
+
290
+ return h_flex().id(`agent-row-${name}-${slug}`).w_full().min_w(0).items_start().gap(8).px(6).py(6)
291
+ .rounded(UI.radius).cursor_pointer().hover((st) => st.bg(t.hover))
292
+ .when(hidden, (el) => el.opacity(0.6))
293
+ .on_click(() => this.focusAgent(row))
294
+ .child(avatar)
295
+ .child(v_flex().flex_1().min_w(0).gap(1)
296
+ .child(h_flex().w_full().min_w(0).items_center().gap(6)
297
+ .child(mono(div().flex_1().min_w(0).truncate().text_size(UI.text.body).font_semibold().text_color(t.foreground)).child(name))
298
+ .child(mono(h_flex().flex_none().items_center().gap(4).text_size(UI.text.tiny).text_color(tone))
299
+ .child(div().size(6).flex_none().rounded(3).bg(tone))
300
+ .child(div().max_w(76).truncate().child(stateLabel))))
301
+ .child(mono(div().w_full().truncate().text_size(UI.text.tiny).text_color(t.dim)).child(rowRole(row)))
302
+ .when(Boolean(stats), (el) => el.child(mono(div().w_full().truncate().text_size(UI.text.tiny).text_color(t.muted)).child(stats))))
303
+ .when(remote, (el) => el.child(
304
+ div().id(`agent-${hidden ? "show" : "hide"}-${slug}`).flex_none().p(3).rounded(4).text_color(t.dim)
305
+ .hover((st) => st.bg(t.raised).text_color(t.foreground))
306
+ .tooltip(hidden ? "Mostrar (vuelve a su pestaña)" : "Ocultar (el agente sigue vivo)")
307
+ .on_click((_e, cx) => {
308
+ cx.stop_propagation();
309
+ if (hidden) this.focusAgent(row);
310
+ else this.hideAgent(row);
311
+ })
312
+ .child(svg(`mods/bond-agents/${hidden ? "eye" : "eye-off"}.svg`).size(14))));
313
+ }
314
+
315
+ /** The run: title (two lines at most), branch and state, the PESTAÑAS | PANELES switch,
316
+ * one attention notice when an agent waits for the person, then the agents and the
317
+ * hidden ones apart. */
271
318
  renderSection(s, t) {
272
- const isSelected = Boolean(s.isSelected);
273
- const color = stateColor(t, s.state) ?? t.foreground ?? "#ffffff";
319
+ const color = stateColor(t, s.state) ?? t.foreground;
320
+ const waitColor = stateColor(t, "waiting");
274
321
  const title = String(s.title ?? s.run?.id ?? s.ticket?.id ?? "Run");
275
- const stateText = String(s.state ?? "").toUpperCase();
322
+ const stateText = RUN_STATE_ES[s.state] ?? String(s.state ?? "").toUpperCase();
323
+ const hiddenSet = readHidden(shared(HIDDEN_KEY));
324
+ const isHidden = (r) => String(r.pane ?? "").includes("/") && hiddenSet.has(String(r.pane));
325
+ const shown = s.rows.filter((r) => !isHidden(r));
326
+ const hiddenRows = s.rows.filter(isHidden);
327
+ const att = attentionOf(shown, s.state === "waiting" ? s.run?.failure_reason : null);
328
+ const panels = Boolean(s.run && this.isPanels(s.run.id));
329
+ const mono = (el) => el.font_family("JetBrains Mono");
330
+ const divider = () => div().w_full().h(1).bg(t.border);
276
331
 
277
- return v_flex()
278
- .id(`agents-section-${s.run?.id ?? s.ticket?.id ?? "run"}`)
279
- .w_full()
280
- .p(8)
281
- .rounded(UI.radiusLg)
282
- .bg(t.chrome)
283
- .border_1()
284
- .border_color(isSelected ? t.ring : t.border)
285
- .gap(6)
286
- .child(
287
- h_flex()
288
- .items_center()
289
- .justify_between()
290
- .p(4)
291
- .border_b(1)
292
- .border_color(t.border)
293
- .child(
294
- div()
295
- .flex_1()
296
- .text_size(UI.text.body)
297
- .font_semibold()
298
- .font_family(UI.fontSans)
299
- .text_color(t.foreground)
300
- .truncate()
301
- .child(title)
302
- )
303
- .child(
304
- div()
305
- .px(6)
306
- .py(1)
307
- .rounded(UI.radius)
308
- .bg(t.raised)
309
- .border_1()
310
- .border_color(color)
311
- .text_size(UI.text.tiny)
312
- .font_family("JetBrains Mono")
313
- .font_semibold()
314
- .text_color(color)
315
- .child(stateText)
316
- )
317
- )
318
- .when(Boolean(s.run?.failure_reason), (el) =>
319
- el.child(
320
- h_flex()
321
- .p(6)
322
- .rounded(UI.radius)
323
- .bg(t.popover)
324
- .border_1()
325
- .border_color(t.border)
326
- .gap(4)
327
- .items_center()
328
- .font_family("JetBrains Mono")
329
- .text_size(UI.text.small)
330
- .child(div().font_semibold().text_color(t.bond_waiting ?? t.blocked).flex_none().child("motivo:"))
331
- .child(div().text_color(t.foreground).truncate().child(String(s.run.failure_reason)))
332
- )
333
- )
332
+ const seg = (id, label, on) => mono(div().id(id).flex_1().py(3).rounded(UI.radius).flex().justify_center()
333
+ .text_size(UI.text.tiny).font_semibold().cursor_pointer()
334
+ .bg(on ? t.surface : t.raised).text_color(on ? t.foreground : t.dim)
335
+ .border_1().border_color(on ? t.border : t.raised)
336
+ .hover((st) => st.text_color(t.foreground))
337
+ .on_click(() => {
338
+ if (!on && s.run) this.togglePanels(s.run.id);
339
+ }))
340
+ .child(label);
341
+
342
+ return v_flex().id(`agents-section-${s.run?.id ?? s.ticket?.id ?? "run"}`).w_full().min_w(0).gap(8)
343
+ // Run header: the title and branch are in the session header beside it; here only the
344
+ // run's state (its title as tooltip) and the PESTAÑAS | PANELES switch.
345
+ .child(v_flex().w_full().min_w(0).gap(5)
346
+ .child(h_flex().id("agents-run-state").w_full().min_w(0).items_center().gap(6).tooltip(title)
347
+ .child(mono(div().flex_1().min_w(0).truncate().text_size(UI.text.tiny).text_color(t.dim)).child("Run"))
348
+ .child(mono(h_flex().flex_none().items_center().gap(4).text_size(UI.text.tiny).font_semibold().text_color(color))
349
+ .child(div().size(6).rounded(3).bg(color))
350
+ .child(stateText)))
351
+ .when(Boolean(s.run), (el) => el.child(h_flex().w_full().p(2).gap(2).rounded(UI.radius).bg(t.raised).border_1().border_color(t.border)
352
+ .child(seg("agents-mode-tabs", "Pestañas", !panels))
353
+ .child(seg("agents-mode-panels", "Paneles", panels)))))
354
+ // One attention notice
355
+ .when(Boolean(att), (el) => el.child(v_flex().w_full().p(8).gap(4).rounded(UI.radius).bg(t.popover).border_1().border_color(waitColor)
356
+ .child(h_flex().items_center().gap(6)
357
+ .child(div().size(7).rounded(4).flex_none().bg(waitColor))
358
+ .child(div().flex_1().min_w(0).truncate().text_size(UI.text.small).font_semibold().font_family(UI.fontSans).text_color(waitColor).child(`${att.name} te necesita`)))
359
+ .when(Boolean(att.text), (sub) => sub.child(div().text_size(UI.text.small).font_family(UI.fontSans).text_color(t.foreground).child(`«${att.text}»`)))
360
+ .when(Boolean(att.row?.pane), (sub) => sub.child(h_flex().justify_end()
361
+ .child(mono(div().id("agents-answer").text_size(UI.text.tiny).font_semibold().text_color(t.accent).cursor_pointer()
362
+ .hover((st) => st.text_color(t.foreground)).on_click(() => this.focusAgent(att.row))).child("Responder →"))))))
363
+ // Why it failed, when nobody is waiting (a waiting run says it in the notice)
364
+ .when(!att && Boolean(s.run?.failure_reason), (el) => el.child(h_flex().w_full().min_w(0).gap(4).items_center()
365
+ .child(mono(div().flex_none().text_size(UI.text.tiny).font_semibold().text_color(color)).child("motivo:"))
366
+ .child(mono(div().flex_1().min_w(0).truncate().text_size(UI.text.tiny).text_color(t.foreground)).child(String(s.run.failure_reason)))))
334
367
  .when(Boolean(s.run?.hub_analysis || s.ticket?.analysis), (el) => {
335
368
  const a = s.run?.hub_analysis || s.ticket?.analysis;
336
369
  const gaps = Array.isArray(a?.gaps) ? a.gaps : [];
337
370
  const fixable = gaps.filter((g) => g?.fix || g?.fixable).length;
338
371
  const isReady = a?.status === "ready";
339
- return el.child(
340
- v_flex()
341
- .p(8)
342
- .rounded(UI.radius)
343
- .bg(t.popover)
344
- .border_1()
345
- .border_color(t.border)
346
- .gap(4)
347
- .font_family("JetBrains Mono")
348
- .text_size(UI.text.small)
349
- .child(
350
- h_flex()
351
- .items_center()
352
- .gap(4)
353
- .child(div().font_semibold().text_color(t.dim).child("bond hub check:"))
354
- .child(
355
- div()
356
- .font_semibold()
357
- .text_color(isReady ? t.working : t.blocked)
358
- .child(isReady ? "análisis: listo" : `${gaps.length} ${gaps.length === 1 ? "hueco" : "huecos"} (${fixable} con arreglo)`)
359
- )
360
- )
361
- .when(gaps.length > 0, (sub) =>
362
- sub.children(
363
- gaps.map((g) =>
364
- div()
365
- .text_size(UI.text.tiny)
366
- .font_family("JetBrains Mono")
367
- .text_color(t.dim)
368
- .child(String(`· ${g?.message || g?.id || "hueco detectado"}${g?.fix || g?.fixable ? " (se arregla solo)" : ""}`))
369
- )
370
- )
371
- )
372
- .when(Boolean(a?.summary), (sub) =>
373
- sub.child(
374
- div()
375
- .text_size(UI.text.tiny)
376
- .font_family("JetBrains Mono")
377
- .text_color(t.dim)
378
- .child(String(`agente de hub: ${a.summary}`))
379
- )
380
- )
381
- );
372
+ return el.child(mono(v_flex().w_full().p(8).gap(3).rounded(UI.radius).bg(t.popover).border_1().border_color(t.border).text_size(UI.text.tiny))
373
+ .child(h_flex().gap(4).items_center()
374
+ .child(div().font_semibold().text_color(t.dim).child("bond hub check:"))
375
+ .child(div().font_semibold().text_color(isReady ? t.working : t.blocked)
376
+ .child(isReady ? "análisis: listo" : `${gaps.length} ${gaps.length === 1 ? "hueco" : "huecos"} (${fixable} con arreglo)`)))
377
+ .children(gaps.map((g) => div().text_color(t.dim).child(String(`· ${g?.message || g?.id || "hueco detectado"}${g?.fix || g?.fixable ? " (se arregla solo)" : ""}`))))
378
+ .when(Boolean(a?.summary), (sub) => sub.child(div().text_color(t.dim).child(String(`agente de hub: ${a.summary}`)))));
382
379
  })
383
- .when(s.rows.length === 0, (el) =>
384
- el.child(
385
- div()
386
- .p(8)
387
- .text_size(UI.text.small)
388
- .font_family("JetBrains Mono")
389
- .text_color(t.dim)
390
- .child("Sin equipo de agentes activo")
391
- )
392
- )
393
- .when(s.rows.length > 0, (el) =>
394
- el.child(
395
- v_flex()
396
- .w_full()
397
- .gap(6)
398
- .children(s.rows.map((r) => this.agentRow(r, t)))
399
- )
400
- );
380
+ .child(divider())
381
+ .when(s.rows.length === 0, (el) => el.child(mono(div().p(6).text_size(UI.text.small).text_color(t.dim)).child("Sin equipo de agentes activo")))
382
+ .when(shown.length > 0, (el) => el.child(v_flex().w_full().gap(2).children(shown.map((r) => this.agentRow(r, t, false)))))
383
+ .when(hiddenRows.length > 0, (el) => el
384
+ .child(divider())
385
+ .child(mono(div().px(6).text_size(UI.text.tiny).font_semibold().text_color(t.dim)).child(`Ocultos (${hiddenRows.length})`))
386
+ .child(v_flex().w_full().gap(2).children(hiddenRows.map((r) => this.agentRow(r, t, true)))));
401
387
  }
402
388
 
403
389
  render() {
@@ -408,9 +394,15 @@ export default class BondAgents extends View {
408
394
  this.tickets,
409
395
  this.selectedRunId,
410
396
  this.teamStatusByRun,
411
- this.selectedTicketId
397
+ this.selectedTicketId,
398
+ this.terminalsByRun
412
399
  );
400
+ const hasRun = Boolean(sections[0]?.run);
413
401
  const activeCount = sections[0]?.rows?.length ?? 0;
402
+ const pillText = hasRun
403
+ ? (activeCount > 0 ? `${activeCount} ${activeCount === 1 ? "activo" : "activos"}` : "1 activo")
404
+ : "Sin run activo";
405
+ const pillActive = hasRun;
414
406
 
415
407
  return v_flex()
416
408
  .id("bond-agents")
@@ -426,18 +418,12 @@ export default class BondAgents extends View {
426
418
  .justify_between()
427
419
  .p(2)
428
420
  .child(
429
- h_flex()
430
- .items_center()
431
- .gap(6)
432
- .child(div().text_size(14).child("👥"))
433
- .child(
434
- div()
435
- .text_size(UI.text.title)
436
- .font_bold()
437
- .font_family(UI.fontSans)
438
- .text_color(t.foreground)
439
- .child("AGENTES")
440
- )
421
+ div()
422
+ .text_size(UI.text.small)
423
+ .font_semibold()
424
+ .font_family(UI.fontSans)
425
+ .text_color(t.muted)
426
+ .child("AGENTES")
441
427
  )
442
428
  .child(
443
429
  h_flex()
@@ -450,12 +436,12 @@ export default class BondAgents extends View {
450
436
  .rounded(12)
451
437
  .bg(t.raised)
452
438
  .border_1()
453
- .border_color(hasSelected && activeCount > 0 ? (t.bond_indigo ?? t.accent) : t.border)
439
+ .border_color(pillActive ? (t.bond_indigo ?? t.accent) : t.border)
454
440
  .text_size(UI.text.tiny)
455
441
  .font_family("JetBrains Mono")
456
442
  .font_semibold()
457
- .text_color(hasSelected && activeCount > 0 ? (t.bond_indigo ?? t.accent) : t.dim)
458
- .child(hasSelected && activeCount > 0 ? `${activeCount} activos` : "Sin run activo")
443
+ .text_color(pillActive ? (t.bond_indigo ?? t.accent) : t.dim)
444
+ .child(pillText)
459
445
  )
460
446
  .child(
461
447
  div()