@jmanuelcorral/bond-app 0.1.6 → 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.
@@ -27,6 +27,7 @@ import {
27
27
  deliverRun, nudgeRun, finishRun, approveHubFixes, deleteTicket, getDeletePreview,
28
28
  columnCounts, filterOptions, filterCards, issueChip, validateNewTicket, createTicket, AGENTS, TICKET_MODES, TEAM_ENGINES,
29
29
  cleanRepoChips, listAssignedIssues, issueTicketId, searchRepos, listRepoIssues, searchJiraIssues, resetIssueProviderState, needsWizard, timeoutLabel,
30
+ searchPullRequests, resolvePullRequest, parsePrSearchInput, formatSourceError,
30
31
  } from "./model.js";
31
32
  import { stateColor, UI, settingsOverlay, createOverlay, markColor } from "./brand.js";
32
33
 
@@ -143,9 +144,9 @@ export default class BondBoard extends View {
143
144
  this.pickedIssue = null;
144
145
  this.carryBody = true; // lleva el cuerpo de la issue a la historia salvo que se desmarque
145
146
  this.bondify = true; // bondifica el repo si no lo está salvo que se desmarque (P4, D-U)
146
- // Plan bond-app-ajustes-imagen P4: «Docker en el run». Se pre-marca si el repo trae
147
- // devcontainer, salvo que la persona ya lo haya tocado.
148
- this.docker = false;
147
+ // «Docker en el run»: marcado por defecto (decisión 2026-11-25: se trabaja casi siempre
148
+ // con devcontainers); la persona lo desmarca para un ticket concreto.
149
+ this.docker = true;
149
150
  this.dockerTouched = false;
150
151
  this.devcontainerRepo = null; // "owner/repo" con devcontainer detectado
151
152
  this.devcontainerChecked = null; // último "owner/repo@base" consultado
@@ -183,6 +184,22 @@ export default class BondBoard extends View {
183
184
  // Alta en tres bloques (Qué · Dónde · Quién; decisión 2026-11-24): la historia se ve y
184
185
  // se edita; el repo se elige aparte de la issue, con favoritos, recientes, GitHub y Azure.
185
186
  this.source = "github"; // github | jira | manual
187
+ this.createKind = "scratch"; // scratch | pr
188
+ this.prQuery = InputState.new({ placeholder: "buscar PR abierta (texto o owner/repo) o pegar URL de PR o rama" });
189
+ this.prQuery.on("change", (_e, cx) => this.searchPrsSoon(cx));
190
+ this.prResults = null;
191
+ this.prSearching = false;
192
+ this.prSearchErrors = {};
193
+ this.prSearchFor = null;
194
+ // Filtros de la búsqueda de PRs: host (todas | github | azure) y de quién (todas | assigned | author).
195
+ this.prHost = "todas";
196
+ this.prMine = "todas";
197
+ this.prResolving = false;
198
+ this.prResolvingUrl = null;
199
+ this.prResolveError = null;
200
+ this.prDisabled = {};
201
+ this.pickedPr = null;
202
+ this.prChoosing = true;
186
203
  this.choosing = true; // la lista de issues abierta (al elegir una se pliega)
187
204
  this.story = TextareaState.new({ placeholder: "qué tiene que hacer el agente: lo lee como primer mensaje" });
188
205
  this.story.set_rows(4);
@@ -427,17 +444,29 @@ export default class BondBoard extends View {
427
444
  const repoUrl = this.repoSel?.url ?? v("repo");
428
445
  const reposText = this.listRepos.map((r) => r.url).join("\n");
429
446
  const storyText = String(this.story.value() ?? "");
430
- const check = validateNewTicket({
431
- title: v("title"), issue: v("issue"), mode: this.mode, repo: repoUrl, repos: reposText, hub: v("hub"),
432
- base: v("base"), model: modelVal, agent: this.agent, team_engine: this.team_engine, budget: v("budget"), timeout: v("timeout"),
433
- // Desmarcado con issue que trae cuerpo = story "" explícita (el agente arranca sin
434
- // historia); sin issue o sin cuerpo = undefined (comportamiento heredado).
435
- // The story is what the box holds: emptied on purpose with an issue = "" (the agent
436
- // starts without it); nothing typed and no issue = undefined (legacy behaviour).
437
- story: storyText.trim() ? storyText : this.pickedIssue ? "" : undefined,
438
- bondify: this.bondify,
439
- docker: this.docker,
440
- });
447
+ const check = this.createKind === "pr"
448
+ ? validateNewTicket({
449
+ kind: "pr",
450
+ source_pr_url: this.pickedPr?.url ?? "",
451
+ is_hub: Boolean(this.pickedPr?.is_hub),
452
+ hub_url: !this.pickedPr?.is_hub && this.pickedPrHub ? this.pickedPrHub : undefined,
453
+ title: v("title"), model: modelVal, agent: this.agent, team_engine: this.team_engine,
454
+ budget: v("budget"), timeout: v("timeout"),
455
+ story: storyText.trim() ? storyText : this.pickedPr ? "" : undefined,
456
+ bondify: this.bondify,
457
+ docker: this.docker,
458
+ })
459
+ : validateNewTicket({
460
+ title: v("title"), issue: v("issue"), mode: this.mode, repo: repoUrl, repos: reposText, hub: v("hub"),
461
+ base: v("base"), model: modelVal, agent: this.agent, team_engine: this.team_engine, budget: v("budget"), timeout: v("timeout"),
462
+ // Desmarcado con issue que trae cuerpo = story "" explícita (el agente arranca sin
463
+ // historia); sin issue o sin cuerpo = undefined (comportamiento heredado).
464
+ // The story is what the box holds: emptied on purpose with an issue = "" (the agent
465
+ // starts without it); nothing typed and no issue = undefined (legacy behaviour).
466
+ story: storyText.trim() ? storyText : this.pickedIssue ? "" : undefined,
467
+ bondify: this.bondify,
468
+ docker: this.docker,
469
+ });
441
470
  this.errors = check.errors;
442
471
  this.error = null;
443
472
  if (!check.ok) {
@@ -453,8 +482,8 @@ export default class BondBoard extends View {
453
482
  setShared(REFRESH_KEY, Date.now());
454
483
  closeOverlay(p.overlay);
455
484
  } catch (e) {
456
- // The API's own validation (e.g. an agent the runner image doesn't carry).
457
- this.error = String(e?.message ?? e);
485
+ // The API's own validation (e.g. an agent the runner image doesn't carry, or source_*).
486
+ this.error = formatSourceError(e);
458
487
  this.busy = false;
459
488
  cx.notify();
460
489
  }
@@ -477,6 +506,13 @@ export default class BondBoard extends View {
477
506
  this.searchReposOn(cx);
478
507
  cx.stop_propagation();
479
508
  }
509
+ if (e.key === "enter" && this.view === "create" && this.createKind === "pr") {
510
+ const q = String(this.prQuery.value() ?? "").trim();
511
+ if (/^https?:\/\//.test(q)) {
512
+ this.resolvePr(q, cx);
513
+ cx.stop_propagation();
514
+ }
515
+ }
480
516
  }
481
517
 
482
518
  // ---- board actions ----
@@ -1562,6 +1598,134 @@ export default class BondBoard extends View {
1562
1598
  .when(Boolean(error), (el) => el.child(div().text_size(UI.text.small).text_color(t.blocked).child(error)));
1563
1599
  }
1564
1600
 
1601
+ /** P3: search open PRs in GitHub and Azure DevOps. */
1602
+ searchPrs(cx, q, repo = "") {
1603
+ const host = this.prHost === "todas" ? "" : this.prHost;
1604
+ const mine = this.prMine === "todas" ? "" : this.prMine;
1605
+ const key = `${repo}\0${q}\0${host}\0${mine}`;
1606
+ this.prSearchFor = key;
1607
+ this.prSearching = true;
1608
+ this.prResolveError = null;
1609
+ cx.notify();
1610
+ cx.spawn(async (cx) => {
1611
+ try {
1612
+ const res = await searchPullRequests(api, { q, repo, host, mine });
1613
+ if (this.prSearchFor !== key) return;
1614
+ this.prResults = Array.isArray(res?.items) ? res.items : [];
1615
+ this.prSearchErrors = res?.errors ?? {};
1616
+ } catch (e) {
1617
+ if (this.prSearchFor !== key) return;
1618
+ this.prSearchErrors = { api: String(e?.message ?? e) };
1619
+ }
1620
+ this.prSearching = false;
1621
+ cx.notify();
1622
+ });
1623
+ }
1624
+
1625
+ /** P3: debounced PR search on typing; pasted URLs wait for «Usar URL» or Enter. */
1626
+ searchPrsSoon(cx) {
1627
+ const raw = String(this.prQuery.value() ?? "").trim();
1628
+ cx.notify();
1629
+ if (/^https?:\/\//.test(raw)) return;
1630
+ const { q, repo } = parsePrSearchInput(raw);
1631
+ const key = `${repo}\0${q}\0${this.prHost === "todas" ? "" : this.prHost}\0${this.prMine === "todas" ? "" : this.prMine}`;
1632
+ if (key === this.prSearchFor) return;
1633
+ cx.spawn(async (cx) => {
1634
+ await cx.sleep(350);
1635
+ const now = String(this.prQuery.value() ?? "").trim();
1636
+ if (now !== raw || /^https?:\/\//.test(now)) return;
1637
+ this.searchPrs(cx, q, repo);
1638
+ });
1639
+ }
1640
+
1641
+ /** P3/P5: resolve a PR or branch URL, validate it (no forks/closed) and fill Qué/Dónde. */
1642
+ resolvePr(url, cx) {
1643
+ const target = String(url ?? "").trim();
1644
+ if (!target) return;
1645
+ this.prResolving = true;
1646
+ this.prResolvingUrl = target;
1647
+ this.prResolveError = null;
1648
+ cx.notify();
1649
+ cx.spawn(async (cx) => {
1650
+ try {
1651
+ const info = await resolvePullRequest(api, target);
1652
+ if (info?.is_fork || (info?.state && info.state !== "open")) {
1653
+ const reason = info.is_fork
1654
+ ? "fork, solo lectura"
1655
+ : info.state === "merged" ? "mergeada" : "cerrada";
1656
+ this.prDisabled = { ...this.prDisabled, [target]: reason, ...(info.url ? { [info.url]: reason } : {}) };
1657
+ this.prResolveError = formatSourceError(info.is_fork ? "source_fork" : "source_closed");
1658
+ } else {
1659
+ this.pickedPr = info;
1660
+ this.pickedPrHub = info.is_hub
1661
+ ? (info.hub?.url ?? info.repo_url ?? "")
1662
+ : (Array.isArray(info.hubs) && info.hubs.length > 0 ? (info.hub?.url ?? info.hubs[0].url) : "");
1663
+ this.prChoosing = false;
1664
+ this.prResolveError = null;
1665
+ this.fields.title.set_value(info.title || info.head || "");
1666
+ this.story.set_value(String(info.body ?? ""));
1667
+ this.errors = {};
1668
+ }
1669
+ } catch (e) {
1670
+ this.prResolveError = formatSourceError(e);
1671
+ }
1672
+ this.prResolving = false;
1673
+ this.prResolvingUrl = null;
1674
+ cx.notify();
1675
+ });
1676
+ }
1677
+
1678
+ /** P5: pick one of the hubs proposed for a repo PR (or none for single-repo). */
1679
+ selectPrHub(hubUrl, cx) {
1680
+ const pr = this.pickedPr;
1681
+ if (!pr || pr.is_hub) return;
1682
+ this.pickedPrHub = hubUrl || "";
1683
+ if (!hubUrl || pr.hub?.url === hubUrl) {
1684
+ cx.notify();
1685
+ return;
1686
+ }
1687
+ this.prHubLoading = true;
1688
+ cx.notify();
1689
+ cx.spawn(async (cx) => {
1690
+ try {
1691
+ const updated = await resolvePullRequest(api, pr.url, hubUrl);
1692
+ if (this.pickedPr?.url === pr.url && this.pickedPrHub === hubUrl && updated?.hub) {
1693
+ this.pickedPr = { ...this.pickedPr, hub: updated.hub };
1694
+ }
1695
+ } catch {}
1696
+ this.prHubLoading = false;
1697
+ cx.notify();
1698
+ });
1699
+ }
1700
+
1701
+ createPrRow(pr, picked = false) {
1702
+ const t = theme();
1703
+ const disabledReason = this.prDisabled?.[pr.url]
1704
+ || (pr.is_fork ? "fork, solo lectura" : pr.state && pr.state !== "open" ? (pr.state === "merged" ? "mergeada" : "cerrada") : null);
1705
+ const disabled = Boolean(disabledReason);
1706
+ const resolvingThis = this.prResolving && this.prResolvingUrl === pr.url;
1707
+ const label = pr.number ? `#${pr.number}` : (pr.head ? "rama" : "PR");
1708
+ let row = h_flex().id(`pr-row-${slug(pr.url || `${pr.repo_label}-${pr.number}`)}`)
1709
+ .h(30).px(8).gap(8).items_center().rounded(UI.radius).min_w(0)
1710
+ .bg(picked ? t.selected : t.background).border_1().border_color(picked ? t.accent : t.background);
1711
+ if (!disabled && !picked) {
1712
+ row = row.cursor_pointer().hover((s) => s.bg(t.hover)).on_click((_e, cx) => this.resolvePr(pr.url, cx));
1713
+ }
1714
+ return row
1715
+ .child(this.hostBadge(pr.host))
1716
+ .child(div().w(48).flex_none().text_size(12).font_semibold().text_color(disabled ? t.dim : t.accent).child(label))
1717
+ .child(div().flex_1().min_w(0).truncate().text_size(12.5).font_family(UI.fontSans)
1718
+ .text_color(disabled ? t.dim : t.foreground).child(String(pr.title || pr.head || pr.url || "")))
1719
+ .when(Boolean(pr.repo_label), (el) => el.child(div().flex_none().text_size(UI.text.small).text_color(t.dim).child(String(pr.repo_label))))
1720
+ .when(Boolean(pr.is_hub), (el) => el.child(div().flex_none().px(6).h(18).rounded(4).flex().items_center().border_1().border_color(t.accent)
1721
+ .text_size(10).text_color(t.accent).child("hub")))
1722
+ .when(Boolean(pr.draft) && !disabled, (el) => el.child(div().flex_none().px(6).h(18).rounded(4).flex().items_center().border_1().border_color(t.border)
1723
+ .text_size(10).text_color(t.muted).child("borrador")))
1724
+ .when(resolvingThis, (el) => el.child(div().flex_none().text_size(UI.text.small).text_color(t.dim).child("resolviendo…")))
1725
+ .when(disabled, (el) => el.child(div().flex_none().px(6).h(18).rounded(4).flex().items_center().border_1().border_color(t.blocked)
1726
+ .text_size(10).text_color(t.blocked).child(disabledReason)));
1727
+ }
1728
+
1565
1729
  hostBadge(host) {
1566
1730
  const t = theme();
1567
1731
  const azure = host === "azure";
@@ -1604,6 +1768,64 @@ export default class BondBoard extends View {
1604
1768
 
1605
1769
  createWhat() {
1606
1770
  const t = theme();
1771
+ const e = this.errors ?? {};
1772
+ if (this.createKind === "pr") {
1773
+ const rows = [];
1774
+ if (this.pickedPr && !this.prChoosing) {
1775
+ rows.push(h_flex().gap(8).items_center()
1776
+ .child(div().flex_1().min_w(0).child(this.createPrRow(this.pickedPr, true)))
1777
+ .child(this.button("pr-change", "Cambiar", "plain", () => { this.prChoosing = true; })));
1778
+ } else {
1779
+ const q = String(this.prQuery.value() ?? "").trim();
1780
+ const looksUrl = /^https?:\/\//.test(q);
1781
+ const list = this.prResults ?? [];
1782
+ const loading = this.prSearching || this.prResolving;
1783
+ const errList = Object.entries(this.prSearchErrors ?? {}).map(([k, v]) => ({
1784
+ host: k,
1785
+ text: `${k === "azure" ? "Azure" : k === "github" ? "GitHub" : "API"}: ${formatSourceError(v)}`,
1786
+ notConfigured: String(v).endsWith("_not_configured"),
1787
+ }));
1788
+ rows.push(h_flex().gap(6).items_center()
1789
+ .child(div().flex_1().child(Input.new(this.prQuery).h(28).px(8).rounded(UI.radius).border_1().border_color(t.input).bg(t.background).text_size(12)))
1790
+ .when(looksUrl, (el) => el.child(this.button("pr-use-url", this.prResolving ? "Resolviendo…" : "Usar URL", "plain", (cx) => this.resolvePr(q, cx)))));
1791
+ // Filtros: dónde (GitHub / Azure) y de quién (asignadas a mí / mías). Cambiarlos repite la búsqueda.
1792
+ const refilter = (cx) => {
1793
+ if (looksUrl) return;
1794
+ const { q: words, repo } = parsePrSearchInput(q);
1795
+ this.searchPrs(cx, words, repo);
1796
+ };
1797
+ const hostChip = (id, label) => this.choice(`prh-${id}`, label, this.prHost === id, (cx) => { if (this.prHost === id) return; this.prHost = id; refilter(cx); });
1798
+ const mineChip = (id, label) => this.choice(`prm-${id}`, label, this.prMine === id, (cx) => { if (this.prMine === id) return; this.prMine = id; refilter(cx); });
1799
+ rows.push(h_flex().gap(12).items_center().flex_wrap()
1800
+ .child(h_flex().gap(4).child(hostChip("todas", "Todas")).child(hostChip("github", "GitHub")).child(hostChip("azure", "Azure")))
1801
+ .child(div().w(1).h(16).bg(t.border))
1802
+ .child(h_flex().gap(4).child(mineChip("todas", "Todas")).child(mineChip("assigned", "Asignadas a mí")).child(mineChip("author", "Mías"))));
1803
+ rows.push(v_flex().id("pr-list").max_h(150).overflow_y_scrollbar().gap(1)
1804
+ .when(loading, (el) => el.child(div().px(6).py(3).text_size(UI.text.small).text_color(t.dim).child(this.prResolving ? "Resolviendo URL…" : "Buscando PRs…")))
1805
+ .when(Boolean(this.prResolveError), (el) => el.child(div().px(6).py(3).text_size(UI.text.small).text_color(t.blocked).child(this.prResolveError)))
1806
+ .children(errList.map((err) => h_flex().gap(8).items_center().px(6).py(2)
1807
+ .child(div().flex_1().text_size(UI.text.small).text_color(t.blocked).child(err.text))
1808
+ .when(err.notConfigured && (err.host === "github" || err.host === "azure"), (el) =>
1809
+ el.child(this.button(`pr-open-settings-${err.host}`, "Abrir Ajustes", "plain", () => openOverlay(settingsOverlay({ section: err.host })))))))
1810
+ .when(!loading && !this.prResolveError && errList.length === 0 && list.length === 0, (el) => el.child(div().px(6).py(3).text_size(UI.text.small).text_color(t.dim)
1811
+ .child("No hay PRs abiertas que coincidan: busca por texto, owner/repo o pega la URL de una PR o rama")))
1812
+ .children(list.slice(0, 40).map((pr) => this.createPrRow(pr))));
1813
+ }
1814
+ rows.push(h_flex().gap(10).items_start()
1815
+ .child(v_flex().flex_1().gap(3).child(div().text_size(UI.text.small).font_medium().text_color(t.muted).child("Título"))
1816
+ .child(Input.new(this.fields.title).h(30).px(9).rounded(UI.radius).border_1().border_color(e.title ? t.blocked : t.input).bg(t.background).text_size(12.5))
1817
+ .when(Boolean(e.title), (el) => el.child(div().text_size(UI.text.small).text_color(t.blocked).child(e.title)))));
1818
+ const storyHint = this.pickedPr
1819
+ ? (this.pickedPr.kind === "pr" && this.pickedPr.number ? `desde PR #${this.pickedPr.number}` : `desde rama ${this.pickedPr.head}`)
1820
+ : "elige una PR o rama";
1821
+ rows.push(v_flex().gap(3)
1822
+ .child(h_flex().items_center()
1823
+ .child(div().flex_1().text_size(UI.text.small).font_medium().text_color(t.muted).child("Historia (lo que lee el agente; editable)"))
1824
+ .child(div().text_size(UI.text.small).text_color(t.dim).child(storyHint)))
1825
+ .child(Textarea.new(this.story).h(80).p(8).rounded(UI.radius).border_1().border_color(t.input).bg(t.background).text_size(12)));
1826
+ return this.createBlock(1, "Qué", "de qué PR o rama parte el ticket", rows, e.source_pr_url);
1827
+ }
1828
+
1607
1829
  const lq = (s) => String(s ?? "").trim().toLowerCase().split(/\s+/).filter(Boolean);
1608
1830
  const has = (text, words) => words.every((w) => String(text).toLowerCase().includes(w));
1609
1831
  const src = (id, label) => this.choice(`src-${id}`, label, this.source === id, () => {
@@ -1647,7 +1869,6 @@ export default class BondBoard extends View {
1647
1869
  .children(list.slice(0, 40).map((it) => this.createIssueRow(it))));
1648
1870
  }
1649
1871
  }
1650
- const e = this.errors ?? {};
1651
1872
  rows.push(h_flex().gap(10).items_start()
1652
1873
  .child(v_flex().flex_1().gap(3).child(div().text_size(UI.text.small).font_medium().text_color(t.muted).child("Título"))
1653
1874
  .child(Input.new(this.fields.title).h(30).px(9).rounded(UI.radius).border_1().border_color(e.title ? t.blocked : t.input).bg(t.background).text_size(12.5))
@@ -1663,6 +1884,53 @@ export default class BondBoard extends View {
1663
1884
  createWhere() {
1664
1885
  const t = theme();
1665
1886
  const e = this.errors ?? {};
1887
+ if (this.createKind === "pr") {
1888
+ const pr = this.pickedPr;
1889
+ if (!pr) {
1890
+ return this.createBlock(2, "Dónde", "repo, rama y base fijados por la PR", [
1891
+ div().text_size(UI.text.small).text_color(t.dim).child("Elige primero una PR o pega su URL arriba: el repo, la rama y la base salen de ella."),
1892
+ ], null);
1893
+ }
1894
+ const hubs = Array.isArray(pr.hubs) ? pr.hubs : [];
1895
+ const activeHub = pr.is_hub || Boolean(this.pickedPrHub);
1896
+ const hubInfo = activeHub && pr.hub && (!this.pickedPrHub || pr.hub.url === this.pickedPrHub || pr.is_hub) ? pr.hub : null;
1897
+ const rows = [
1898
+ h_flex().id("pr-where-repo").h(30).px(8).gap(8).items_center().rounded(UI.radius).bg(t.selected).border_1().border_color(t.accent).min_w(0)
1899
+ .child(this.hostBadge(pr.host))
1900
+ .child(div().flex_1().min_w(0).truncate().text_size(12.5).child(String(pr.repo_label || pr.repo_url || "")))
1901
+ .when(Boolean(pr.is_hub), (el) => el.child(div().id("pr-where-hub").flex_none().px(6).h(18).rounded(4).flex().items_center()
1902
+ .border_1().border_color(t.accent).text_size(10).font_semibold().text_color(t.accent).child("hub"))),
1903
+ h_flex().id("pr-where-branch").gap(8).items_center().px(2)
1904
+ .child(div().text_size(UI.text.small).font_medium().text_color(t.muted).child("Rama fija:"))
1905
+ .child(div().flex_1().min_w(0).truncate().text_size(12).text_color(t.foreground).child(`${pr.head} → ${pr.base}`)),
1906
+ ];
1907
+ if (!pr.is_hub && hubs.length > 0) {
1908
+ rows.push(v_flex().id("pr-hub-selector").gap(4).pt(2)
1909
+ .child(div().text_size(UI.text.small).font_medium().text_color(t.muted).child("Hub"))
1910
+ .child(h_flex().gap(6).flex_wrap()
1911
+ .children(hubs.map((h) => this.choice(`pr-hub-${slug(h.url)}`, h.name || h.url, this.pickedPrHub === h.url, (cx) => this.selectPrHub(h.url, cx))))
1912
+ .child(this.choice("pr-hub-none", "Ninguno (solo este repo)", !this.pickedPrHub, (cx) => this.selectPrHub("", cx)))));
1913
+ }
1914
+ if (this.prHubLoading) {
1915
+ rows.push(div().px(2).text_size(UI.text.small).text_color(t.dim).child("Consultando repos del hub…"));
1916
+ } else if (hubInfo && Array.isArray(hubInfo.repos) && hubInfo.repos.length > 0) {
1917
+ rows.push(v_flex().id("pr-hub-repos").gap(3).px(8).py(6).rounded(UI.radius).bg(t.raised).border_1().border_color(t.border)
1918
+ .child(div().text_size(UI.text.small).font_medium().text_color(t.muted).child(`Repos del hub (${hubInfo.repos.length})`))
1919
+ .children(hubInfo.repos.map((r) => {
1920
+ const prNum = r.pr_url ? /\/(?:pull|pullrequest)\/([0-9]+)/.exec(r.pr_url)?.[1] : null;
1921
+ const statusText = r.pr_url
1922
+ ? `${prNum ? `PR #${prNum}` : "PR abierta"} · rama ${pr.head}`
1923
+ : r.branch_exists
1924
+ ? `rama ${pr.head}`
1925
+ : `sin rama: base ${r.base}`;
1926
+ const statusColor = r.pr_url ? t.accent : r.branch_exists ? t.foreground : t.dim;
1927
+ return h_flex().id(`pr-hub-repo-${slug(r.name)}`).gap(8).items_center().min_w(0)
1928
+ .child(div().flex_1().min_w(0).truncate().text_size(12).text_color(t.foreground).child(r.name))
1929
+ .child(div().flex_none().text_size(UI.text.small).text_color(statusColor).child(statusText));
1930
+ })));
1931
+ }
1932
+ return this.createBlock(2, "Dónde", "repo, rama y base fijados por la PR", rows, null);
1933
+ }
1666
1934
  // Un repo o un hub: se elige igual; si trae hub.toml, el alta lo detecta y pasa a modo hub.
1667
1935
  const rows = [];
1668
1936
  {
@@ -1750,7 +2018,7 @@ export default class BondBoard extends View {
1750
2018
  .child(h_flex().gap(10)
1751
2019
  .child(div().w(110).child(this.field("Timeout min (0 = sin)", Input.new(this.fields.timeout).h(30).px(9).rounded(UI.radius).border_1().border_color(e.timeout ? t.blocked : t.input).bg(t.background).text_size(12.5), e.timeout)))
1752
2020
  .when(CONFIG.costs, (el) => el.child(div().w(110).child(this.field("Tope USD", Input.new(this.fields.budget).h(30).px(9).rounded(UI.radius).border_1().border_color(e.budget ? t.blocked : t.input).bg(t.background).text_size(12.5), e.budget)))))
1753
- .when(this.mode !== "repo", (el) => el.child(this.field("Motor de equipo", h_flex().gap(6).flex_wrap()
2021
+ .when(this.mode !== "repo" || Boolean(this.createKind === "pr" && (this.pickedPr?.is_hub || this.pickedPrHub)), (el) => el.child(this.field("Motor de equipo", h_flex().gap(6).flex_wrap()
1754
2022
  .children(TEAM_ENGINES.map((en) => this.choice(`engine-${en.id}`, en.label, this.team_engine === en.id, () => { this.team_engine = en.id; }))), null)));
1755
2023
  rows.push(box);
1756
2024
  }
@@ -1759,6 +2027,33 @@ export default class BondBoard extends View {
1759
2027
 
1760
2028
  createSummary() {
1761
2029
  const t = theme();
2030
+ if (this.createKind === "pr") {
2031
+ const pr = this.pickedPr;
2032
+ if (!pr) {
2033
+ return h_flex().id("create-summary").gap(8).items_center().px(14).py(9).rounded(UI.radius).bg(t.raised).border_1().border_color(t.border).text_size(12).min_w(0)
2034
+ .child(div().flex_none().text_color(t.dim).child("elige una PR o rama"))
2035
+ .child(div().flex_none().text_color(t.dim).child("·"))
2036
+ .child(div().flex_none().child(this.agent));
2037
+ }
2038
+ const prLabel = pr.kind === "pr" && pr.number ? `PR #${pr.number} · rama ${pr.head} → ${pr.base}` : `rama ${pr.head} → ${pr.base}`;
2039
+ const isHub = Boolean(pr.is_hub || this.pickedPrHub);
2040
+ const hubName = pr.is_hub
2041
+ ? (pr.hub?.name || pr.repo_label || pr.repo_url)
2042
+ : (pr.hubs?.find((h) => h.url === this.pickedPrHub)?.name || pr.hub?.name || this.pickedPrHub);
2043
+ const where = pr.is_hub
2044
+ ? `${pr.repo_label || pr.repo_url} (hub)`
2045
+ : this.pickedPrHub
2046
+ ? `${pr.repo_label || pr.repo_url} · hub ${hubName}`
2047
+ : (pr.repo_label || pr.repo_url);
2048
+ return h_flex().id("create-summary").gap(8).items_center().px(14).py(9).rounded(UI.radius).bg(t.raised).border_1().border_color(t.border).text_size(12).min_w(0)
2049
+ .child(div().flex_none().text_color(t.accent).font_semibold().child(prLabel))
2050
+ .child(div().flex_none().text_color(t.dim).child("·"))
2051
+ .child(this.hostBadge(pr.host))
2052
+ .child(div().flex_1().min_w(0).truncate().child(where))
2053
+ .when(isHub, (el) => el.child(div().flex_none().text_color(t.accent).child("hub")))
2054
+ .child(div().flex_none().text_color(t.dim).child("·"))
2055
+ .child(div().flex_none().child(this.agent));
2056
+ }
1762
2057
  const it = this.pickedIssue;
1763
2058
  const what = it ? (it.key ?? (it.number ? `#${it.number}` : "issue")) : this.source === "manual" ? "historia a mano" : "sin issue";
1764
2059
  const where = this.mode === "hub" ? (this.repoSel?.label ? `${this.repoSel.label} (hub)` : String(this.fields.hub.value() ?? "") || "hub sin elegir")
@@ -1783,6 +2078,20 @@ export default class BondBoard extends View {
1783
2078
  .child(div().flex_1().text_size(UI.text.title + 2).font_family(UI.fontSans).font_semibold().child("Nuevo ticket"))
1784
2079
  .child(div().text_size(UI.text.small).text_color(t.dim).child("Esc")))
1785
2080
  .child(v_flex().id("create-body").flex_1().min_h(0).px(16).py(12).gap(10).overflow_y_scrollbar()
2081
+ .child(h_flex().id("create-kind").gap(6).items_center()
2082
+ .child(this.choice("kind-scratch", "De cero", this.createKind === "scratch", () => {
2083
+ this.createKind = "scratch";
2084
+ this.errors = {};
2085
+ this.error = null;
2086
+ }))
2087
+ .child(this.choice("kind-pr", "Desde una PR", this.createKind === "pr", (cx) => {
2088
+ this.createKind = "pr";
2089
+ this.errors = {};
2090
+ this.error = null;
2091
+ if (this.prResults === null && !this.prSearching) {
2092
+ this.searchPrs(cx, "", "");
2093
+ }
2094
+ })))
1786
2095
  .child(this.createWhat()).child(this.createWhere()).child(this.createWho()))
1787
2096
  .child(v_flex().flex_none().gap(8).px(16).py(12).border_t_1().border_color(t.border)
1788
2097
  .child(this.createSummary())
@@ -387,7 +387,12 @@ export async function approveHubFixes(api, runId) {
387
387
  /** "Estimated cost" shown before launching: the run's budget cap and timeout. */
388
388
  export function launchSummary(ticket) {
389
389
  const budget = Number(ticket?.budget_usd || 0).toFixed(2);
390
- return `Coste estimado: hasta $${budget} USD (tope del run) · ${timeoutLabel(ticket?.timeout_minutes)} · 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;
391
396
  }
392
397
 
393
398
  /** «sin timeout» for 0 or nothing (the default), «timeout N min» otherwise. */
@@ -481,6 +486,9 @@ export function validateNewTicket(form) {
481
486
  if (!title) errors.title = "Pon un título";
482
487
  else if (title.length > 200) errors.title = "Máximo 200 caracteres";
483
488
 
489
+ const sourcePrUrl = String(f.source_pr_url ?? "").trim();
490
+ const fromPr = f.kind === "pr" || Boolean(sourcePrUrl);
491
+
484
492
  // El botón «Lista de repos» ya no se ofrece en el dialog (TICKET_MODES), pero el modo
485
493
  // sigue siendo válido: la funcionalidad de equipo por lista de repos se conserva.
486
494
  const mode = ["repo", "list", "hub"].includes(f.mode) ? f.mode : "repo";
@@ -488,19 +496,29 @@ export function validateNewTicket(form) {
488
496
  if (!AGENTS.includes(agent)) errors.agent = `Agente desconocido: ${agent}`;
489
497
 
490
498
  const base = String(f.base ?? "").trim();
491
- if (base && !BRANCH.test(base)) errors.base = "Rama no válida";
499
+ if (!fromPr && base && !BRANCH.test(base)) errors.base = "Rama no válida";
492
500
 
493
501
  const model = agent === "pi" && f.model ? String(f.model).trim() : null;
494
502
 
495
503
  const body = { title, agent };
496
504
  body.bondify = f.bondify !== undefined ? Boolean(f.bondify) : true;
497
- // Plan bond-app-ajustes-imagen P4: only sent when ticked (privileged container).
498
- if (f.docker === true) body.docker = true;
505
+ // «Docker en el run»: on unless unticked (decision 2026-11-25); always sent explicitly.
506
+ body.docker = f.docker !== false;
499
507
  if (model) body.model = model;
500
- if (mode !== "repo" && f.team_engine) {
508
+ if ((mode !== "repo" || f.is_hub || Boolean(f.hub_url)) && f.team_engine) {
501
509
  body.team_engine = f.team_engine === "herdr" ? "herdr" : "hc";
502
510
  }
503
- 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") {
504
522
  const url = String(f.repo ?? "").trim();
505
523
  if (!GITHUB_URL.test(url) && !AZURE_URL.test(url)) {
506
524
  errors.repo = "URL de GitHub (https://github.com/org/repo) o de Azure Repos (https://dev.azure.com/org/proyecto/_git/repo)";
@@ -664,3 +682,53 @@ export async function getDeletePreview(api, ticketId) {
664
682
  export function needsWizard(state) {
665
683
  return Boolean(state) && state.complete === false && state.setup_done === false;
666
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
+ }