@jmanuelcorral/bond-app 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +280 -23
  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 +4 -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 +308 -327
  11. package/app/mods/bond-agents/model.js +376 -5
  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 +4 -0
  16. package/app/mods/bond-board/main.js +1000 -449
  17. package/app/mods/bond-board/model.js +170 -28
  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 +4 -0
  30. package/app/mods/bond-settings/main.js +1216 -272
  31. package/app/mods/bond-settings/mod.json +1 -1
  32. package/app/mods/bond-status/api.js +35 -0
  33. package/app/mods/bond-status/brand.js +53 -2
  34. package/app/mods/bond-status/config.js +4 -0
  35. package/app/mods/bond-status/main.js +37 -15
  36. package/app/mods/bond-status/model.js +19 -1
  37. package/app/mods/bond-tabs/brand.js +53 -2
  38. package/app/mods/bond-tabs/main.js +45 -3
  39. package/app/mods/bond-titlebar/brand.js +53 -2
  40. package/app/mods/bond-titlebar/main.js +85 -29
  41. package/app/mods/bond-titlebar/version.js +3 -0
  42. package/app/themes/bond-dark.json +5 -5
  43. package/app/themes/bond-light.json +5 -5
  44. package/package.json +1 -1
  45. package/runner/Dockerfile +16 -2
  46. package/runner/SPIKE-BOND.md +6 -2
  47. package/runner/entrypoint.sh +16 -0
  48. package/runner/setup.sh +439 -8
  49. package/runner/versions.env +32 -1
  50. package/scripts/app-install.ts +322 -27
  51. package/src/cli.ts +562 -21
  52. package/src/config.ts +15 -3
  53. package/src/core/agy-login.ts +683 -0
  54. package/src/core/delivery.ts +125 -6
  55. package/src/core/doctor.ts +748 -0
  56. package/src/core/hub-session.ts +108 -91
  57. package/src/core/hub.ts +40 -8
  58. package/src/core/orchestrator.ts +1481 -187
  59. package/src/core/paths.ts +107 -0
  60. package/src/core/permissions.ts +143 -0
  61. package/src/core/pr-source.ts +147 -0
  62. package/src/core/repo-host.ts +60 -0
  63. package/src/core/service-windows.ts +180 -0
  64. package/src/core/service.ts +861 -0
  65. package/src/core/setup-install.ts +1380 -0
  66. package/src/core/setup.ts +62 -1
  67. package/src/core/watchdog.ts +6 -6
  68. package/src/db/database.ts +54 -7
  69. package/src/db/settings-repo.ts +332 -7
  70. package/src/db/ticket-repo.ts +73 -25
  71. package/src/index.ts +4 -4
  72. package/src/runner/azure-devops-client.ts +273 -0
  73. package/src/runner/docker-client.ts +93 -9
  74. package/src/runner/github-client.ts +148 -3
  75. package/src/runner/hc-client.ts +33 -5
  76. package/src/runner/image-builder.ts +123 -5
  77. package/src/runner/jira-client.ts +368 -0
  78. package/src/runner/tool-catalog.ts +84 -0
  79. package/src/server/app.ts +467 -8
  80. package/src/types.ts +140 -2
@@ -3,11 +3,11 @@
3
3
 
4
4
  /** Board columns, in order: label and the ticket statuses each one shows (P7: 5 fixed columns). */
5
5
  export const COLUMNS = [
6
- { id: "ready", label: "Ready", states: ["ready", "queued", "analyzing"] },
7
- { id: "running", label: "Running", states: ["running", "verifying"] },
8
- { id: "waiting", label: "Waiting", states: ["waiting", "blocked"] },
9
- { id: "finished", label: "Finished", states: ["finished", "pr_ready"] },
10
- { id: "error", label: "Error", states: ["failed", "error"] },
6
+ { id: "ready", label: "Listos", states: ["ready", "queued", "analyzing"] },
7
+ { id: "running", label: "En curso", states: ["running", "verifying"] },
8
+ { id: "waiting", label: "En espera", states: ["waiting", "blocked"] },
9
+ { id: "finished", label: "Terminados", states: ["finished", "pr_ready"] },
10
+ { id: "error", label: "Con error", states: ["failed", "error"] },
11
11
  ];
12
12
 
13
13
  /** Run states that hold a container (and an hc session once running). */
@@ -18,8 +18,17 @@ export const POLL_MS = 3000;
18
18
 
19
19
  /** `https://github.com/org/repo(.git)` -> `org/repo`. */
20
20
  export function shortRepo(url) {
21
- const m = /github\.com\/([^/]+\/[^/]+?)(?:\.git)?$/.exec(String(url ?? ""));
22
- return m ? m[1] : String(url ?? "");
21
+ const u = String(url ?? "");
22
+ const m = /github\.com\/([^/]+\/[^/]+?)(?:\.git)?$/.exec(u);
23
+ if (m) return m[1];
24
+ // Azure Repos: «org/project/repo» (dev.azure.com or <org>.visualstudio.com).
25
+ const az = /dev\.azure\.com\/([^/]+)\/([^/]+)\/_git\/([^/]+?)\/?$/.exec(u)
26
+ ?? /\/\/(?:[^@/]+@)?([^./]+)\.visualstudio\.com\/(?:DefaultCollection\/)?([^/]+)\/_git\/([^/]+?)\/?$/.exec(u);
27
+ if (az) {
28
+ const dec = (x) => { try { return decodeURIComponent(x); } catch { return x; } };
29
+ return `${az[1]}/${dec(az[2])}/${dec(az[3]).replace(/\.git$/, "")}`;
30
+ }
31
+ return u;
23
32
  }
24
33
 
25
34
  /**
@@ -225,6 +234,7 @@ export function buildCards(tickets, runs, agentStatus = {}, now = Date.now()) {
225
234
  column: cardColumn(status, run, hcInfo),
226
235
  story: t.story ?? null,
227
236
  issueUrl: t.issue_url ?? null,
237
+ repoUrl: t.repo_url ?? null,
228
238
  run,
229
239
  runState: run?.state ?? null,
230
240
  failureReason: run?.failure_reason ?? null,
@@ -257,6 +267,19 @@ export function buildCards(tickets, runs, agentStatus = {}, now = Date.now()) {
257
267
  });
258
268
  }
259
269
 
270
+ /**
271
+ * The card's issue chip: «VEL-123» for Jira, «#42» for GitHub (with its repo when it is not
272
+ * the ticket's), null without an issue.
273
+ */
274
+ export function issueChip(issueUrl, repoKey = null) {
275
+ const url = String(issueUrl ?? "");
276
+ const jira = /\/browse\/([A-Z][A-Z0-9]+-\d+)/.exec(url);
277
+ if (jira) return { label: jira[1], host: "jira", url };
278
+ const gh = /github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)/.exec(url);
279
+ if (gh) return { label: repoKey && `${gh[1]}/${gh[2]}`.toLowerCase() !== String(repoKey).toLowerCase() ? `${gh[2]}#${gh[3]}` : `#${gh[3]}`, host: "github", url };
280
+ return null;
281
+ }
282
+
260
283
  /** hc's agent status: `{app, state}` (hc 0.1.20) or a bare string (older cores). */
261
284
  export function statusText(status) {
262
285
  if (typeof status === "string") return status || null;
@@ -364,7 +387,18 @@ export async function approveHubFixes(api, runId) {
364
387
  /** "Estimated cost" shown before launching: the run's budget cap and timeout. */
365
388
  export function launchSummary(ticket) {
366
389
  const budget = Number(ticket?.budget_usd || 0).toFixed(2);
367
- return `Coste estimado: hasta $${budget} USD (tope del run) · timeout ${ticket?.timeout_minutes ?? "?"} min · agente ${ticket?.agent ?? "pi"}`;
390
+ const base = `Coste estimado: hasta $${budget} USD (tope del run) · ${timeoutLabel(ticket?.timeout_minutes)} · agente ${ticket?.agent ?? "pi"}`;
391
+ if (ticket?.source_pr_url && ticket?.target_branch) {
392
+ const branch = ticket.base_branch ? `${ticket.target_branch} → ${ticket.base_branch}` : ticket.target_branch;
393
+ return `${base} · rama ${branch}`;
394
+ }
395
+ return base;
396
+ }
397
+
398
+ /** «sin timeout» for 0 or nothing (the default), «timeout N min» otherwise. */
399
+ export function timeoutLabel(minutes) {
400
+ const n = Number(minutes);
401
+ return Number.isFinite(n) && n > 0 ? `timeout ${n} min` : "sin timeout";
368
402
  }
369
403
 
370
404
  // ---- P6: header counters, filters and the new-ticket form ----
@@ -417,12 +451,11 @@ export function filterCards(cards, filter) {
417
451
  }
418
452
 
419
453
  /** Agents a ticket can name (the orchestrator's list, src/db/ticket-repo.ts). */
420
- export const AGENTS = ["pi", "claude", "codex", "opencode", "copilot", "crush", "agy"];
454
+ export const AGENTS = ["pi", "claude", "codex", "copilot", "agy"];
421
455
 
422
- /** Where a new ticket works: one repo, a list of repos (a new hub) or an existing hub. */
456
+ /** Where a new ticket works: one repo or an existing hub. */
423
457
  export const TICKET_MODES = [
424
458
  { id: "repo", label: "Un repo" },
425
- { id: "list", label: "Lista de repos" },
426
459
  { id: "hub", label: "Hub existente" },
427
460
  ];
428
461
 
@@ -436,6 +469,8 @@ export const TEAM_ENGINES = [
436
469
  export const MAX_REPOS = 8;
437
470
 
438
471
  const GITHUB_URL = /^https:\/\/github\.com\/[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+(?:\.git)?$/;
472
+ /** Plan bond-app-azure-jira P1: Azure Repos (dev.azure.com or the older visualstudio.com). */
473
+ const AZURE_URL = /^https:\/\/(?:[A-Za-z0-9][A-Za-z0-9_.-]*@)?(?:dev\.azure\.com\/[A-Za-z0-9][A-Za-z0-9_.-]*|[A-Za-z0-9][A-Za-z0-9_.-]*\.visualstudio\.com(?:\/DefaultCollection)?)\/[A-Za-z0-9_.~%'()+-]+\/_git\/[A-Za-z0-9_.~%'()+-]+\/?$/;
439
474
  const BRANCH = /^(?!-)(?!.*\.\.)(?!.*\/\/)(?!.*@\{)[A-Za-z0-9._/-]{1,200}(?<![./])$/;
440
475
 
441
476
  /**
@@ -451,24 +486,43 @@ export function validateNewTicket(form) {
451
486
  if (!title) errors.title = "Pon un título";
452
487
  else if (title.length > 200) errors.title = "Máximo 200 caracteres";
453
488
 
454
- const mode = TICKET_MODES.some((m) => m.id === f.mode) ? f.mode : "repo";
489
+ const sourcePrUrl = String(f.source_pr_url ?? "").trim();
490
+ const fromPr = f.kind === "pr" || Boolean(sourcePrUrl);
491
+
492
+ // El botón «Lista de repos» ya no se ofrece en el dialog (TICKET_MODES), pero el modo
493
+ // sigue siendo válido: la funcionalidad de equipo por lista de repos se conserva.
494
+ const mode = ["repo", "list", "hub"].includes(f.mode) ? f.mode : "repo";
455
495
  const agent = String(f.agent || "pi");
456
496
  if (!AGENTS.includes(agent)) errors.agent = `Agente desconocido: ${agent}`;
457
497
 
458
498
  const base = String(f.base ?? "").trim();
459
- if (base && !BRANCH.test(base)) errors.base = "Rama no válida";
499
+ if (!fromPr && base && !BRANCH.test(base)) errors.base = "Rama no válida";
460
500
 
461
501
  const model = agent === "pi" && f.model ? String(f.model).trim() : null;
462
502
 
463
503
  const body = { title, agent };
464
504
  body.bondify = f.bondify !== undefined ? Boolean(f.bondify) : true;
505
+ // «Docker en el run»: on unless unticked (decision 2026-11-25); always sent explicitly.
506
+ body.docker = f.docker !== false;
465
507
  if (model) body.model = model;
466
- if (mode !== "repo" && f.team_engine) {
508
+ if ((mode !== "repo" || f.is_hub || Boolean(f.hub_url)) && f.team_engine) {
467
509
  body.team_engine = f.team_engine === "herdr" ? "herdr" : "hc";
468
510
  }
469
- if (mode === "repo") {
511
+ if (fromPr) {
512
+ if (!sourcePrUrl) {
513
+ errors.source_pr_url = "Elige una PR o pega su URL";
514
+ } else if (!/^https:\/\/.+/.test(sourcePrUrl)) {
515
+ errors.source_pr_url = "URL no válida: pega la URL de una PR o rama de GitHub o Azure Repos";
516
+ } else {
517
+ body.source_pr_url = sourcePrUrl;
518
+ const hubUrl = String(f.hub_url ?? "").trim();
519
+ if (hubUrl) body.hub_url = hubUrl;
520
+ }
521
+ } else if (mode === "repo") {
470
522
  const url = String(f.repo ?? "").trim();
471
- if (!GITHUB_URL.test(url)) errors.repo = "URL de GitHub: https://github.com/org/repo";
523
+ if (!GITHUB_URL.test(url) && !AZURE_URL.test(url)) {
524
+ errors.repo = "URL de GitHub (https://github.com/org/repo) o de Azure Repos (https://dev.azure.com/org/proyecto/_git/repo)";
525
+ }
472
526
  body.repo_url = url;
473
527
  if (base) body.base_branch = base;
474
528
  } else if (mode === "list") {
@@ -507,8 +561,10 @@ export function validateNewTicket(form) {
507
561
  const budget = Number(String(f.budget ?? "").replace(",", "."));
508
562
  if (!Number.isFinite(budget) || budget <= 0 || budget > 1000) errors.budget = "Tope en USD: un número mayor que 0 y hasta 1000";
509
563
  else body.budget_usd = budget;
510
- const timeout = Number(f.timeout);
511
- if (!Number.isInteger(timeout) || timeout <= 0 || timeout > 1440) errors.timeout = "Minutos: un entero entre 1 y 1440";
564
+ // Empty or 0: no timeout (the default, decision 2026-11-24); otherwise whole minutes.
565
+ const timeoutText = String(f.timeout ?? "").trim();
566
+ const timeout = timeoutText === "" ? 0 : Number(timeoutText);
567
+ if (!Number.isInteger(timeout) || timeout < 0 || timeout > 1440) errors.timeout = "Minutos: un entero entre 0 (sin timeout) y 1440";
512
568
  else body.timeout_minutes = timeout;
513
569
 
514
570
  const description = String(f.description ?? "").trim();
@@ -520,14 +576,18 @@ export function validateNewTicket(form) {
520
576
  else if (verify.some((c) => c.length > 2000)) errors.verify = "Un comando es demasiado largo";
521
577
  else body.verify_commands = verify;
522
578
 
523
- // La US: el cuerpo de la issue elegida (check mediante); sin esto el agente arranca sin contexto.
524
- const story = String(f.story ?? "").trim();
525
- if (story) body.story = story.slice(0, 8000);
579
+ // La US: el cuerpo de la issue elegida (check mediante). Un "" explícito (check
580
+ // desmarcado a propósito) debe viajar tal cual: distingue «sin historia» de «sin dato».
581
+ if (f.story !== undefined && f.story !== null) {
582
+ body.story = String(f.story).trim().slice(0, 8000);
583
+ }
526
584
 
527
585
  const issueUrl = String(f.issue_url ?? f.issue ?? "").trim();
528
586
  if (issueUrl) {
529
- if (!/^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/issues\/[1-9][0-9]*(?:[#?].*)?$/.test(issueUrl)) {
530
- errors.issue = "URL de GitHub Issue no válida (https://github.com/org/repo/issues/123)";
587
+ const isGh = /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/issues\/[1-9][0-9]*(?:[#?].*)?$/.test(issueUrl);
588
+ const isJira = /^https:\/\/[A-Za-z0-9_-]+\.atlassian\.net\/browse\/[A-Za-z0-9_-]+(?:[#?].*)?$/.test(issueUrl);
589
+ if (!isGh && !isJira) {
590
+ errors.issue = "URL de issue no válida (GitHub o Jira Cloud: https://site.atlassian.net/browse/KEY-123)";
531
591
  } else {
532
592
  body.issue_url = issueUrl;
533
593
  }
@@ -560,14 +620,46 @@ export async function listRepoIssues(api, owner, repo) {
560
620
  return api(`/issues/repo?provider=github&owner=${encodeURIComponent(owner)}&repo=${encodeURIComponent(repo)}`);
561
621
  }
562
622
 
563
- /** D1: the id the backend will give the ticket for this issue (`gh-<owner>-<repo>-<n>`). */
623
+ /** Búsqueda de issues de Jira por texto y/o proyecto */
624
+ export async function searchJiraIssues(api, { q = "", project = "", mine = false } = {}) {
625
+ const params = new URLSearchParams();
626
+ if (q) params.set("q", q);
627
+ if (mine) params.set("mine", "1");
628
+ if (project) params.set("project", project);
629
+ return api(`/issues/jira/search?${params.toString()}`);
630
+ }
631
+
632
+ /** D1: the id the backend will give the ticket for this issue (`gh-<owner>-<repo>-<n>` or `jira-<site>-<key>`). */
564
633
  export function issueTicketId(issue) {
565
634
  const url = String(issue?.url ?? "").trim();
566
635
  const m = /^https:\/\/github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/issues\/([1-9][0-9]*)(?:[#?].*)?$/.exec(url);
567
- if (!m) return null;
568
- const slug = (s) => s.replace(/[^A-Za-z0-9_.-]/g, "-").replace(/^[-.]+|[-.]+$/g, "");
569
- const id = `gh-${slug(m[1])}-${slug(m[2])}-${m[3]}`.replace(/\.{2,}/g, "-");
570
- return id.length <= 80 ? id : null;
636
+ if (m) {
637
+ const slug = (s) => s.replace(/[^A-Za-z0-9_.-]/g, "-").replace(/^[-.]+|[-.]+$/g, "");
638
+ const id = `gh-${slug(m[1])}-${slug(m[2])}-${m[3]}`.replace(/\.{2,}/g, "-");
639
+ return id.length <= 80 ? id : null;
640
+ }
641
+ const j = /^https:\/\/([a-zA-Z0-9_-]+)\.atlassian\.net\/browse\/([a-zA-Z0-9_-]+)(?:[#?].*)?$/.exec(url);
642
+ if (j) {
643
+ const slug = (s) => s.replace(/[^A-Za-z0-9_.-]/g, "-").replace(/^[-.]+|[-.]+$/g, "");
644
+ // El tenant entra en el id: dos sitios pueden compartir claves de proyecto.
645
+ const id = `jira-${slug(j[1].toLowerCase())}-${slug(j[2].toLowerCase())}`.replace(/\.{2,}/g, "-");
646
+ return id.length <= 80 ? id : null;
647
+ }
648
+ return null;
649
+ }
650
+
651
+ /**
652
+ * cambio de proveedor de historia: deja el estado de búsqueda/pools a cero para el
653
+ * proveedor entrante (sin resultados Jira obsoletos ni pools mezclados). Se pasa el
654
+ * propio objeto de la vista; devuelve el mismo para encadenar.
655
+ */
656
+ export function resetIssueProviderState(board) {
657
+ board.assignedPool = null;
658
+ board.issuePanel = null;
659
+ board.issues = null;
660
+ board.reposError = null;
661
+ board.jiraResults = null;
662
+ return board;
571
663
  }
572
664
 
573
665
  /** P7: Delete ticket and tear down all associated resources (container, network, machine, worktrees, branches). */
@@ -590,3 +682,53 @@ export async function getDeletePreview(api, ticketId) {
590
682
  export function needsWizard(state) {
591
683
  return Boolean(state) && state.complete === false && state.setup_done === false;
592
684
  }
685
+
686
+ const SOURCE_ERROR_MESSAGES = {
687
+ source_invalid: "URL no válida: pega la URL de una PR o rama de GitHub o Azure Repos",
688
+ source_not_found: "No se encontró esa PR o rama (o la credencial no tiene acceso)",
689
+ source_fork: "La PR viene de un fork: bond-app no puede hacer push a su rama",
690
+ source_closed: "La PR está cerrada o mergeada: solo se pueden usar PRs abiertas",
691
+ source_azure_hub: "Los hubs de Azure DevOps todavía no se pueden lanzar desde una PR",
692
+ github_not_configured: "GitHub no está configurado: conéctalo en Ajustes",
693
+ azure_not_configured: "Azure DevOps no está configurado: conéctalo en Ajustes",
694
+ github_api_error: "Error al consultar GitHub",
695
+ azure_api_error: "Error al consultar Azure DevOps",
696
+ ticket_invalid: "No se pudo crear el ticket con esa PR (¿ya existe un ticket para ella?)",
697
+ };
698
+
699
+ /** Map API error codes from PR search/resolve/create (`source_*`, `github_*`, `azure_*`) to Spanish. */
700
+ export function formatSourceError(err) {
701
+ const code = String(err?.message ?? err ?? "").trim();
702
+ if (!code) return "Error desconocido";
703
+ if (SOURCE_ERROR_MESSAGES[code]) return SOURCE_ERROR_MESSAGES[code];
704
+ if (code.startsWith("github_api_error")) return "Error al consultar GitHub";
705
+ if (code.startsWith("azure_api_error")) return "Error al consultar Azure DevOps";
706
+ return code;
707
+ }
708
+
709
+ /** Split `owner/repo` (optionally followed by filter words) from a plain search query. */
710
+ export function parsePrSearchInput(raw) {
711
+ const s = String(raw ?? "").trim();
712
+ const m = /^([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)(?:\s+(.*))?$/.exec(s);
713
+ if (m) return { repo: m[1], q: (m[2] ?? "").trim() };
714
+ return { repo: "", q: s };
715
+ }
716
+
717
+ /** P3: search open pull requests in GitHub and Azure DevOps. */
718
+ export async function searchPullRequests(api, { q = "", repo = "", host = "", mine = "" } = {}) {
719
+ const params = new URLSearchParams();
720
+ if (q) params.set("q", q);
721
+ if (repo) params.set("repo", repo);
722
+ // Filtros del alta: host «github» | «azure»; de quién «assigned» (asignadas a mí) | «author» (mías).
723
+ if (host === "github" || host === "azure") params.set("host", host);
724
+ if (mine === "assigned" || mine === "author") params.set("mine", mine);
725
+ const qs = params.toString();
726
+ return api(`/prs/search${qs ? `?${qs}` : ""}`);
727
+ }
728
+
729
+ /** P3/P5: resolve a PR or branch URL (GitHub or Azure Repos) to its metadata (and optional hub). */
730
+ export async function resolvePullRequest(api, url, hubUrl) {
731
+ const params = new URLSearchParams({ url: String(url ?? "").trim() });
732
+ if (hubUrl) params.set("hub_url", String(hubUrl).trim());
733
+ return api(`/prs/resolve?${params.toString()}`);
734
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M4 4l8 8M12 4l-8 8"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"><path d="M2 8s2.2-4 6-4 6 4 6 4-2.2 4-6 4-6-4-6-4z"/><circle cx="8" cy="8" r="1.8"/><path d="M3 13 13 3"/></svg>
@@ -0,0 +1,103 @@
1
+ // bond-pane: the header of each pane in the bond layout, like herdr-app's own: the
2
+ // program's icon, the terminal's name before the agent's (e.g. «kevin · agy», «gru · pi»), the folder,
3
+ // the agent's status, and buttons to split, zoom and close on hover. Props from the app:
4
+ // { pane, terminal }. Click: focus the pane.
5
+ //
6
+ // One difference (plan bond-app-pestanas-paneles, E4): in herdr-app, closing a pane ends its
7
+ // terminal. For an agent of a run (a terminal on another machine) the last button hides it
8
+ // instead: terminal.park, it keeps running, and the Agents panel brings it back with
9
+ // «Sincronizar Terminal». Shells and local terminals close as usual.
10
+
11
+ import { View, div, svg, image } from "gpui-kit";
12
+ import { h_flex } from "gpui-base";
13
+ import { panes, terminals, props, run, theme, home, shared, setShared } from "herdr";
14
+ import { isRunAgent, paneTitle } from "./model.js";
15
+
16
+ const ICONS = "mods/bond-pane";
17
+ // Shared with bond-agents (model.js HIDDEN_KEY) and bond-tabs.
18
+ const HIDDEN_KEY = "bond.agents.hidden";
19
+
20
+ function icon(p, size, color) {
21
+ if (!p?.icon) return null;
22
+ return p.tint ? svg(p.icon).size(size).flex_none().text_color(color) : image(p.icon).w(size).h(size).flex_none();
23
+ }
24
+
25
+ function folder(cwd) {
26
+ if (!cwd) return "";
27
+ const h = home();
28
+ return cwd === h ? "~" : cwd.startsWith(h + "/") ? "~" + cwd.slice(h.length) : cwd;
29
+ }
30
+
31
+ function hide(addr) {
32
+ const cur = shared(HIDDEN_KEY);
33
+ const set = new Set(Array.isArray(cur) ? cur : []);
34
+ set.add(addr);
35
+ setShared(HIDDEN_KEY, [...set].sort());
36
+ run("terminal.park", { terminal: addr });
37
+ }
38
+
39
+ export default class BondPane extends View {
40
+ init() {
41
+ this.hovered = false;
42
+ }
43
+
44
+ me() {
45
+ return (panes() ?? []).find((p) => p.pane === props()?.pane);
46
+ }
47
+
48
+ button(t, id, iconName, title, action) {
49
+ return div()
50
+ .id(id)
51
+ .p(3)
52
+ .rounded(4)
53
+ .text_color(t.dim)
54
+ .hover((s) => s.bg(t.hover).text_color(t.foreground))
55
+ .tooltip(title)
56
+ .on_click((_e, cx) => {
57
+ cx.stop_propagation();
58
+ action();
59
+ })
60
+ .child(svg(`${ICONS}/${iconName}.svg`).size(14));
61
+ }
62
+
63
+ render() {
64
+ const t = theme();
65
+ const p = this.me();
66
+ if (!p) return div();
67
+ const term = p.terminal ? (terminals() ?? []).find((x) => x.address === p.terminal) : null;
68
+ const base = ((p.program?.agent || p.program?.shell) && p.program.name) || p.title || p.program?.name || "shell";
69
+ const name = paneTitle(base, term?.name);
70
+ const pic = icon(p.program, 14, t.dim);
71
+ const st = p.status;
72
+ const pane = p.pane;
73
+ const runAgent = isRunAgent(p.terminal, p.program);
74
+ return h_flex()
75
+ .id(`pane-head-${pane}`)
76
+ .size_full()
77
+ .px(10)
78
+ .gap(8)
79
+ .items_center()
80
+ .bg(t.background)
81
+ .border_b(1)
82
+ .border_color(t.border)
83
+ .text_size(12)
84
+ .on_hover((hovered, cx) => {
85
+ this.hovered = hovered;
86
+ cx.notify();
87
+ })
88
+ .on_click(() => run("pane.focus", { pane }))
89
+ .when(Boolean(pic), (el) => el.child(pic))
90
+ .child(div().flex_none().truncate().max_w(300).font_medium().text_color(t.foreground).child(name))
91
+ .child(div().flex_1().truncate().text_color(t.dim).child(folder(p.cwd)))
92
+ .when(st === "working", (el) => el.child(svg("mods/workspace-chrome/spinner.svg").size(12).flex_none().text_color(t.working).spin(900)))
93
+ .when(st === "blocked", (el) => el.child(div().flex_none().px(6).h(18).flex().items_center().rounded(5).bg(t.blocked + "26").text_size(10.5).font_semibold().text_color(t.blocked).child("Te necesita")))
94
+ .when(st === "done", (el) => el.child(div().size(7).flex_none().rounded(4).bg(t.done)))
95
+ .when(this.hovered, (el) => el
96
+ .child(this.button(t, `bp-r-${pane}`, "split-right", "Dividir a la derecha", () => run("pane.split", { direction: "right", pane })))
97
+ .child(this.button(t, `bp-d-${pane}`, "split-down", "Dividir abajo", () => run("pane.split", { direction: "down", pane })))
98
+ .child(this.button(t, `bp-z-${pane}`, p.zoomed ? "unzoom" : "zoom", p.zoomed ? "Restaurar" : "Ampliar", () => run("pane.zoom", { pane })))
99
+ .child(runAgent
100
+ ? this.button(t, `bp-h-${pane}`, "hide", "Ocultar (el agente sigue vivo)", () => hide(p.terminal))
101
+ : this.button(t, `bp-x-${pane}`, "close", "Cerrar", () => run("pane.close", { pane }))));
102
+ }
103
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "bond · cabecera de panel" }
@@ -0,0 +1,18 @@
1
+ // bond-pane: pure helpers of the pane header (testable without herdr-app).
2
+
3
+ /** An agent of a run: a terminal on another machine (`machine/tN`) running an agent,
4
+ * or the run's orchestrator (`/t1`). */
5
+ export function isRunAgent(terminal, program) {
6
+ const addr = String(terminal ?? "");
7
+ if (!addr.includes("/")) return false;
8
+ return Boolean(program?.agent) || /\/t1$/.test(addr);
9
+ }
10
+
11
+ /** «kevin · agy», «gru · pi»: the terminal's own name (gru, a minion) before its program;
12
+ * just the program when the name says nothing more (hc's `agent`, `tN`, the same word). */
13
+ export function paneTitle(name, termName) {
14
+ const n = String(name ?? "").trim() || "shell";
15
+ const t = String(termName ?? "").trim();
16
+ if (!t || t === n || /^t\d+$/.test(t) || t === "agent") return n;
17
+ return `${t} · ${n}`;
18
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.3"><rect x="2" y="2.5" width="12" height="11" rx="1.5"/><path d="M2 8h12"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.3"><rect x="2" y="2.5" width="12" height="11" rx="1.5"/><path d="M8 2.5v11"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"><path d="M13.5 6.5h-4v-4M2.5 9.5h4v4M9.5 6.5 14 2M6.5 9.5 2 14"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"><path d="M9.5 2.5h4v4M6.5 13.5h-4v-4M13.5 2.5 9 7M2.5 13.5 7 9"/></svg>
@@ -64,6 +64,41 @@ export async function health() {
64
64
  return true;
65
65
  }
66
66
 
67
+ /** Forget the cached token, so the next call reads its file again (Ajustes «Reconectar»). */
68
+ export function resetToken() {
69
+ token = null;
70
+ }
71
+
72
+ /**
73
+ * Why the mods can or cannot talk to the orchestrator, for Ajustes: { state, detail }.
74
+ * state: "ok", "down" (no /health), "no-token" (no token file), "bad-token" (the file's
75
+ * token is not this orchestrator's: usually another --data-dir) or "error".
76
+ */
77
+ export async function diagnose() {
78
+ try {
79
+ await health();
80
+ } catch {
81
+ return { state: "down", detail: `${CONFIG.api} no responde` };
82
+ }
83
+ token = null;
84
+ try {
85
+ await api("/setup");
86
+ return { state: "ok", detail: CONFIG.api };
87
+ } catch (e) {
88
+ const msg = String(e?.message ?? e);
89
+ if (msg.startsWith("no hay token")) return { state: "no-token", detail: msg };
90
+ if (/unauthorized|HTTP 401/i.test(msg)) {
91
+ return { state: "bad-token", detail: `el token de ${tokenPath()} no es el de este orquestador (¿arrancado con otro --data-dir?)` };
92
+ }
93
+ return { state: "error", detail: msg };
94
+ }
95
+ }
96
+
97
+ /** The command that starts this orchestrator (written by app:install), or a default. */
98
+ export function startCommand() {
99
+ return Array.isArray(CONFIG.start) && CONFIG.start.length ? CONFIG.start : ["bond-app", "start"];
100
+ }
101
+
67
102
  /** The API's base URL, for messages. */
68
103
  export function apiUrl() {
69
104
  return CONFIG.api;
@@ -18,6 +18,7 @@ export const UI = {
18
18
  button: 26,
19
19
  folded: 34, // width of a folded (empty) board column
20
20
  columnWidth: 270, // fixed column width
21
+ columnMax: 560, // an open board column is never wider than this
21
22
  fontFamily: "JetBrains Mono",
22
23
  fontSans: "Geist",
23
24
  };
@@ -26,7 +27,7 @@ export const UI = {
26
27
  const STATE_FALLBACK = {
27
28
  ready: "idle",
28
29
  running: "working",
29
- waiting: "blocked",
30
+ waiting: "working",
30
31
  finished: "done",
31
32
  error: "blocked",
32
33
  verifying: "accent",
@@ -41,9 +42,24 @@ const STATE_THEME_KEY = {
41
42
  error: "bond_error",
42
43
  };
43
44
 
45
+ /**
46
+ * Running is green and waiting yellow (2026-11-23: less red on the board). A theme without
47
+ * bond_* colors falls back to herdr's palette, which has neither (its `working` is yellow,
48
+ * `blocked` red): these get fixed hues, [light, dark], AA-safe as fills on either.
49
+ */
50
+ const STATE_HEX = {
51
+ running: ["#047857", "#34d399"],
52
+ waiting: ["#a16207", "#facc15"],
53
+ blocked: ["#a16207", "#facc15"],
54
+ };
55
+
44
56
  /** The color of a board column or state (`ready`, `running`, ...) in theme `t`. */
45
57
  export function stateColor(t, id) {
46
- return t[`bond_${id}`] ?? t[STATE_THEME_KEY[id]] ?? t[STATE_FALLBACK[id]] ?? t.accent;
58
+ const own = t[`bond_${id}`] ?? t[STATE_THEME_KEY[id]];
59
+ if (own) return own;
60
+ const hex = STATE_HEX[id];
61
+ if (hex) return hex[isDark(t) ? 1 : 0];
62
+ return t[STATE_FALLBACK[id]] ?? t.accent;
47
63
  }
48
64
 
49
65
  /** Relative luminance of `#rrggbb[aa]` (WCAG), 0..1. */
@@ -71,3 +87,38 @@ export function logo(t) {
71
87
  wordmarkRatio: 398 / 108,
72
88
  };
73
89
  }
90
+
91
+ /**
92
+ * Ajustes as a modal dialog (plan bond-app-ajustes-imagen P1): what every bond-* mod passes
93
+ * to herdr's openOverlay to open it. `section` picks the section (orchestrator, agents,
94
+ * github, image, advanced); `{ view: "wizard", step }` opens the first-launch walk.
95
+ */
96
+ export function settingsOverlay(props = {}) {
97
+ return { mod: "bond-settings", kind: "dialog", modal: true, width: 820, height: 0.7, props: { view: "settings", ...props } };
98
+ }
99
+
100
+ /**
101
+ * «Nuevo ticket» (Qué · Dónde · Quién): every button that opens it passes this, so the
102
+ * dialog always has its height (its body scrolls; without a height it collapses).
103
+ */
104
+ export function createOverlay() {
105
+ return { mod: "bond-board", kind: "dialog", modal: true, width: 820, height: 0.92, props: { view: "create" } };
106
+ }
107
+
108
+ /**
109
+ * Fixed hues bond uses outside the state palette (host badges, the favorite star, the
110
+ * theme button), [light, dark]: readable on either theme, never a hex that only suits one.
111
+ */
112
+ const MARK_HEX = {
113
+ github: ["#6d28d9", "#a78bfa"],
114
+ azure: ["#0067b8", "#3b9cff"],
115
+ jira: ["#0055cc", "#579dff"],
116
+ star: ["#b45309", "#f5b301"],
117
+ sun: ["#b45309", "#f59e0b"],
118
+ };
119
+
120
+ /** The color of mark `key` (github, azure, jira, star, sun) in theme `t`. */
121
+ export function markColor(t, key) {
122
+ const hex = MARK_HEX[key];
123
+ return hex ? hex[isDark(t) ? 1 : 0] : t.accent;
124
+ }
@@ -9,4 +9,8 @@ export const CONFIG = {
9
9
  // registrando cost_usd, pero la UI no lo muestra hasta que una configuración
10
10
  // en Ajustes lo active. Entonces esto será el valor de esa configuración.
11
11
  costs: false,
12
+ // How to start the orchestrator (Ajustes «Arrancar orquestador»): app:install writes the
13
+ // node and bin/bond-app.js it was installed from, with the port and data dir. null:
14
+ // `bond-app start`.
15
+ start: null,
12
16
  };