@botbuddy/cli 1.73.1 → 1.73.3

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.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.73.3
4
+
5
+ - The bb-status band is tidied after its first live look (BOT-3228). It says "project", never "epic": tickets outside the session's project read "no project" or "other project". A failed read is one short, single-spaced note, such as `Couldn't load project · Couldn't load staging`, and a band that had to guess its tickets from the branch says `Guessed from branch`. Badges are a darker shade of their colour with white letters and icons, rounded outside the terminal, and the staging-red banner is the same red badge as the context alarm. Wait badges use plain words (`Staging status`, `Codex review PR 1655`, `Timer`, `Playwright lane 8`). PRs nest under their ticket by indent, with no trunk line, and the band's rows are evenly spaced. The band now reads correctly when Claude's working directory is a subfolder of the worktree. The plugin version moves to 1.4.1, so `bb update` installs it.
6
+
7
+ ## 1.73.2
8
+
9
+ - `bb doctor --fix` keeps the worktree's own BB session. It renews that session in place, fresh or lapsed, and re-checks the stack-lease capability on the same session (`renew_agent_session` with `host` and `worktree`). Before, it registered a new session, which replaced the old one and cut the bb-status band off from the session's tickets and pull requests. A closed session, another Claude session's cache, or a server that returns no capability verdict still gets a new session as before.
10
+
3
11
  ## 1.73.1
4
12
 
5
13
  - A coordinator's bb-status row counts its project the way Linear does: duplicate tickets are left out, like canceled ones, and the row's percent and total follow those counts. Before, a Supply Guard project with four duplicates showed `2 done · … · 4 todo` at 25% instead of 2 of 4 done at 50%.
14
+
6
15
  ## 1.73.0
7
16
 
8
17
  - The bb-status band is redrawn (BOT-3223). Its first line shows a red context badge once the session has used more than 30% of its context, then one badge per active bb wait, such as `⏳ Codex review PR 1655 · 4m ↗`, linking to the wait (three at most, then `+N more`); the line wraps. Below it the epic leads a tree: its tickets nest under it, and each PR nests under the ticket its branch or title names; tickets outside the epic and PRs naming no ticket follow, marked "no epic" or "no ticket". Each row is an id link (`BOT-123 ↗`, `PR 456 ↗`), a coloured status badge in Linear's and GitHub's colours, and the title, with the badges in one column. The band's plugin version moves to 1.4.0, so `bb update` installs it.
@@ -11,7 +11,7 @@
11
11
  "name": "bb-status",
12
12
  "source": "./bb-status",
13
13
  "description": "BB session status above the prompt: tickets, PRs with review counts, epic, staging, context use and active waits, for BotBuddy and Supply Guard sessions",
14
- "version": "1.4.0"
14
+ "version": "1.4.1"
15
15
  },
16
16
  {
17
17
  "name": "bb-session",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bb-status",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "BB session status above the prompt: tickets, PRs with review counts, epic, staging, context use and active waits, live only while the session is on screen.",
5
5
  "author": {
6
6
  "name": "BotBuddy"
@@ -189,3 +189,13 @@ BB_STATUS_PREVIEW_HARNESS_SESSION_ID=<current-harness-uuid> \
189
189
  ```
190
190
 
191
191
  Live receipts for each BOT-3152 criterion are on the ticket.
192
+
193
+ **BOT-3228 polish.** The band says "project", never "epic" ("no project", "other
194
+ project"). Failed reads share one dim note, single-spaced and joined by ` · `
195
+ (`Couldn't load PRs`, `Couldn't load project`, `Couldn't load staging`, and
196
+ `Guessed from branch` when `session_read` is not `ok`). Badges are a darker shade
197
+ of their status colour with white letters and white icons on every surface,
198
+ rounded (`borderStyle: "round"`) outside the terminal; the staging banner is the
199
+ same red badge as the context alarm. PRs nest by indent with no trunk line, and
200
+ rows sit in one column Box with an even `rowGap`. The read runs from the
201
+ worktree root even when Claude's working directory is a subfolder.
@@ -196,6 +196,8 @@ function validSnapshot(value, harness, now) {
196
196
  (value.blockers !== null &&
197
197
  !(value.tenant === "botbuddy" && Array.isArray(value.blockers) && value.blockers.length <= 100)) ||
198
198
  (value.epic_unreadable !== undefined && typeof value.epic_unreadable !== "boolean") ||
199
+ // BOT-3228 AC-3: why the session's own read was not used.
200
+ (value.session_read !== undefined && !["ok", "unavailable", "other_session", "other_tenant", "malformed"].includes(value.session_read)) ||
199
201
  (value.staging != null &&
200
202
  !(
201
203
  typeof value.staging.configured === "boolean" &&
@@ -758,19 +760,37 @@ function statusWidth(spec) {
758
760
  if (!spec.status.length) return spec.icon ? 2 : 0;
759
761
  return 2 + (spec.icon ? 2 : 0) + spec.status.reduce((w, part, i) => w + (i ? 3 : 0) + part.text.length, 0);
760
762
  }
761
- // BOT-3223 AC-3: the status is a badge in the band's own palette (Linear for
762
- // tickets and the epic, GitHub for PRs). On Desktop a tint of the colour behind
763
- // the coloured word, as the web chips draw it; the terminal has no alpha, so
764
- // there the colour fills the badge and the word takes a contrasting ink.
765
- function ink(hex) {
766
- const m = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex || "");
767
- if (!m) return "#ffffff";
768
- const [r, g, b] = m.slice(1).map((x) => parseInt(x, 16) / 255);
769
- return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.55 ? "#1f2328" : "#ffffff";
770
- }
763
+ // BOT-3223 AC-3 / BOT-3228: the status is a badge in the band's palette
764
+ // (Linear for tickets and the project, GitHub for PRs), filled with a darker
765
+ // shade of its colour and lettered in white, on every surface (Jono,
766
+ // 2026-11-14). Each fill holds at least 4.5:1 against white. On graphical
767
+ // surfaces the badge is rounded, as Claude Code draws its own chips.
768
+ const DARK = {
769
+ "#f2c94c": "#8a5a00", // Linear started (yellow)
770
+ "#4cb782": "#1f7a4d", // Linear in review (green)
771
+ "#5e6ad2": "#4b55b8", // Linear done (violet)
772
+ "#95a2b3": "#5b6675", // Linear backlog / todo / canceled (grey)
773
+ "#f2994a": "#a8510c", // Linear project backlog (orange)
774
+ "#1a7f37": "#1a7f37", // GitHub open
775
+ "#59636e": "#59636e", // GitHub draft
776
+ "#8250df": "#8250df", // GitHub merged
777
+ "#cf222e": "#cf222e", // GitHub closed / conflict
778
+ };
771
779
  function badgeColors(hex) {
772
- const solid = surface === "terminal" || !/^#[0-9a-f]{6}$/i.test(hex || "");
773
- return solid ? { bg: hex, fg: ink(hex), muted: ink(hex) } : { bg: hex + "26", fg: hex, muted: ICON.grey };
780
+ const bg = DARK[String(hex || "").toLowerCase()] || "#5b6675";
781
+ return { bg, fg: "#ffffff", muted: "#ffffff" };
782
+ }
783
+ // The status icon, redrawn in the badge's white ink: its colour strokes and
784
+ // fills turn white, and a white mark inside a filled shape (the Done check)
785
+ // takes the badge's fill so it still reads.
786
+ function inked(source, bg) {
787
+ return String(source || "")
788
+ .replace(/#fff\b/g, "@BG@")
789
+ .replace(/#[0-9a-f]{6}\b/gi, "#ffffff")
790
+ .replace(/@BG@/g, bg);
791
+ }
792
+ function rounded() {
793
+ return surface === "terminal" ? {} : { borderStyle: "round" };
774
794
  }
775
795
  function statusBadge(el, key, spec) {
776
796
  if (!spec.status.length) return spec.icon ? [spec.icon] : [];
@@ -780,7 +800,7 @@ function statusBadge(el, key, spec) {
780
800
  if (i) children.push(el.Text({ color: muted, children: [" · "] }));
781
801
  children.push(el.Text({ color: part.muted ? muted : fg, children: [part.text] }));
782
802
  });
783
- return [el.Box({ key, flexDirection: "row", flexShrink: 0, backgroundColor: bg, paddingX: 1, children })];
803
+ return [el.Box({ key, flexDirection: "row", flexShrink: 0, backgroundColor: bg, ...rounded(), borderColor: bg, paddingX: 1, children })];
784
804
  }
785
805
  function bandLine(el, spec, widths, right) {
786
806
  const ids = [];
@@ -826,18 +846,18 @@ function waitBadges(el, key, w, now) {
826
846
  if (!w || !Number.isSafeInteger(w.count) || w.count < 1) return [];
827
847
  const style = pulsing ? { bold: true } : {};
828
848
  const { bg, fg } = badgeColors(ICON.violet);
849
+ const shape = { backgroundColor: bg, ...rounded(), borderColor: bg, paddingX: 1 };
829
850
  // An older BB lists no items: the one count badge, as before.
830
851
  if (!Array.isArray(w.items) || !w.items.length) {
831
852
  const text = waitsText(w, now);
832
- return text ? [el.Box({ key: key + "-waits", flexDirection: "row", flexShrink: 0, backgroundColor: bg, paddingX: 1, children: [el.Text({ color: fg, ...style, children: [text] })] })] : [];
853
+ return text ? [el.Box({ key: key + "-waits", flexDirection: "row", flexShrink: 0, ...shape, children: [el.Text({ color: fg, ...style, children: [text] })] })] : [];
833
854
  }
834
855
  const out = w.items.slice(0, MAX_WAIT_BADGES).map((i) =>
835
856
  el.Box({
836
857
  key: key + "-wait-" + i.id,
837
858
  flexDirection: "row",
838
859
  flexShrink: 0,
839
- backgroundColor: bg,
840
- paddingX: 1,
860
+ ...shape,
841
861
  children: [
842
862
  el.Text({ color: fg, ...style, children: ["⏳ " + i.label + " · " + shortAge(i.created_at, now) + " "] }),
843
863
  el.Link({ href: LINKS.wait(i.id), label: "↗" }),
@@ -852,7 +872,7 @@ function contextLine(el, key, waits = null) {
852
872
  const alarm = contextAlarm(context);
853
873
  if (alarm)
854
874
  children.push(
855
- el.Box({ key: key + "-ctx", flexDirection: "row", flexShrink: 0, backgroundColor: "error", paddingX: 1, children: [el.Text({ color: "#ffffff", bold: true, children: [alarm] })] }),
875
+ el.Box({ key: key + "-ctx", flexDirection: "row", flexShrink: 0, backgroundColor: "error", ...rounded(), borderColor: "error", paddingX: 1, children: [el.Text({ color: "#ffffff", bold: true, children: [alarm] })] }),
856
876
  );
857
877
  children.push(...waitBadges(el, key, waits, currentTime));
858
878
  if (!children.length) return null;
@@ -865,10 +885,14 @@ async function readContext($) {
865
885
  context = null;
866
886
  }
867
887
  }
888
+ // BOT-3228 AC-1: one short, single-spaced note per failed read, joined by " · ".
889
+ // The band says "project", never "epic" (Jono, 2026-11-14).
868
890
  const UNREAD = {
869
- prs: "Couldn't read this session's PRs",
870
- epic: "Couldn't read this session's epic",
871
- staging: "staging: couldn't read",
891
+ prs: "Couldn't load PRs",
892
+ epic: "Couldn't load project",
893
+ staging: "Couldn't load staging",
894
+ // BOT-3228 AC-3: the session's own read was not used; the tickets are a guess.
895
+ session: "Guessed from branch",
872
896
  };
873
897
  // The chip's own age format: minutes, then hours under two days, then days.
874
898
  function shortAge(fromIso, now) {
@@ -883,7 +907,17 @@ function stagingBanner(el, key, since) {
883
907
  flexDirection: "row",
884
908
  columnGap: 1,
885
909
  children: [
886
- el.Text({ color: "error", bold: true, children: ["▲ Staging red" + (since ? " " + shortAge(since, currentTime) : "")] }),
910
+ // BOT-3228: the same red badge, white lettering, as the context alarm.
911
+ el.Box({
912
+ key: key + "-badge",
913
+ flexDirection: "row",
914
+ flexShrink: 0,
915
+ backgroundColor: "error",
916
+ ...rounded(),
917
+ borderColor: "error",
918
+ paddingX: 1,
919
+ children: [el.Text({ color: "#ffffff", bold: true, children: ["▲ Staging red" + (since ? " " + shortAge(since, currentTime) : "")] })],
920
+ }),
887
921
  el.Link({ href: LINKS.staging, label: "Open staging ↗" }),
888
922
  ],
889
923
  });
@@ -919,7 +953,7 @@ function bandLines(el, $, inPane) {
919
953
  key: k("line-ticket-" + t.key),
920
954
  prefix,
921
955
  ids: [{ label: t.key, href: LINKS.ticket(t.key), out: OUT.ticket(s.tenant, t.key) }],
922
- icon: lead(el, "◆", badgeColors(ticketHex(t.status)).fg, "ticket " + t.status, ticketIcon(t.status)),
956
+ icon: lead(el, "◆", "#ffffff", "ticket " + t.status, inked(ticketIcon(t.status), badgeColors(ticketHex(t.status)).bg)),
923
957
  hex: ticketHex(t.status),
924
958
  status: [{ text: t.status }],
925
959
  title: t.title,
@@ -935,7 +969,7 @@ function bandLines(el, $, inPane) {
935
969
  key: k("line-pr-" + p.number),
936
970
  prefix,
937
971
  ids: [{ label: "PR " + p.number, href: LINKS.pr(p.repo, p.number), out: OUT.pr(p.repo, p.number) }],
938
- icon: lead(el, "⎇", badgeColors(hex).fg, "pr " + p.state, prIcon(p.state)),
972
+ icon: lead(el, "⎇", "#ffffff", "pr " + p.state, inked(prIcon(p.state), badgeColors(hex).bg)),
939
973
  hex,
940
974
  status,
941
975
  title: p.title,
@@ -954,7 +988,7 @@ function bandLines(el, $, inPane) {
954
988
  out: s.epic.url,
955
989
  },
956
990
  ],
957
- icon: lead(el, "◇", badgeColors(epicHex(s.epic.state)).fg, "epic " + s.epic.state + " " + s.epic.percent + "%", epicIcon(s.epic.state, s.epic.percent)),
991
+ icon: lead(el, "◇", "#ffffff", "project " + s.epic.state + " " + s.epic.percent + "%", inked(epicIcon(s.epic.state, s.epic.percent), badgeColors(epicHex(s.epic.state)).bg)),
958
992
  hex: epicHex(s.epic.state),
959
993
  status: [{ text: s.epic.percent + "%" }, ...(Number.isSafeInteger(s.epic.total) && s.epic.total > 0 ? [{ text: s.epic.done + "/" + s.epic.total, muted: true }] : [])],
960
994
  // BOT-3213: the project a coordinator session runs, with its tickets by state.
@@ -962,14 +996,15 @@ function bandLines(el, $, inPane) {
962
996
  ? "Coordinating · " + (s.epic.counts ? countsText(s.epic.counts) + " · " : "") + s.epic.name
963
997
  : s.epic.name,
964
998
  });
965
- else if (s.epic_unreadable)
966
- specs.push({ key: k("line-epic"), ids: [], icon: el.Text({ color: "warning", children: ["◇ "] }), status: [], title: UNREAD.epic, dim: true });
967
999
  const keys = s.tickets.map((t) => t.key);
968
1000
  const prsOf = (key) => (s.prs || []).filter((p) => p.ticket === key);
969
1001
  // A ticket whose project BB did not report (an older CLI) stays in the epic.
970
1002
  const inEpic = (t) => !!s.epic && (t.project === undefined || t.project === s.epic.id);
971
1003
  const branch = (last) => (last ? "└─ " : "├─ ");
972
- const stem = (last) => (last ? " " : "│ ");
1004
+ // BOT-3228: no trunk between a ticket's PRs and the next ticket. A row
1005
+ // draws only its own branch, so a wrapped title broke the trunk into stray
1006
+ // dashes (Jono, 2026-11-14); the indent alone nests the PRs.
1007
+ const stem = () => " ";
973
1008
  const epicTickets = s.tickets.filter(inEpic);
974
1009
  epicTickets.forEach((t, i) => {
975
1010
  const last = i === epicTickets.length - 1;
@@ -979,31 +1014,31 @@ function bandLines(el, $, inPane) {
979
1014
  });
980
1015
  for (const t of s.tickets.filter((t) => !inEpic(t))) {
981
1016
  // A ticket in another project is not epic-less (review on #1657).
982
- specs.push(ticketSpec(t, "", !s.epic ? null : t.project ? "other epic" : "no epic"));
1017
+ specs.push(ticketSpec(t, "", !s.epic ? null : t.project ? "other project" : "no project"));
983
1018
  const prs = prsOf(t.key);
984
1019
  prs.forEach((p, j) => specs.push(prSpec(p, branch(j === prs.length - 1))));
985
1020
  }
986
1021
  // BOT-3152 AC-1: no PR means no row; a failed read says so.
987
1022
  if (s.prs) for (const p of s.prs.filter((p) => !keys.includes(p.ticket))) specs.push(prSpec(p, "", "no ticket"));
988
- else
989
- specs.push({
990
- key: k("line-pr"),
991
- ids: [],
992
- icon: el.Text({ color: "warning", children: ["⎇ "] }),
993
- status: [],
994
- title: UNREAD.prs,
995
- dim: true,
996
- });
997
- const widths = {
998
- ids: Math.max(...specs.map((x) => idsWidth(x.ids, x.prefix))),
999
- status: Math.max(...specs.map(statusWidth)),
1000
- };
1023
+ // BOT-3152 AC-1 / BOT-3228 AC-1: a failed read is a note, never an empty
1024
+ // state; every note shares one dim line, joined by a single " · ".
1025
+ const notes = [];
1026
+ if (s.binding === "branch" && s.session_read && s.session_read !== "ok") notes.push(UNREAD.session);
1027
+ if (!s.prs) notes.push(UNREAD.prs);
1028
+ if (s.epic_unreadable) notes.push(UNREAD.epic);
1029
+ // BOT-3152 edge case: unknown staging is its own signal, never a quiet green.
1030
+ if (s.staging == null) notes.push(UNREAD.staging);
1001
1031
  const right = [...tag];
1002
1032
  if (stale()) right.push(el.Text({ color: "warning", children: ["STALE"] }));
1003
- // BOT-3152 edge case: unknown staging is its own signal, never a quiet green.
1004
- if (s.staging == null) right.push(dim(el, UNREAD.staging));
1033
+ if (notes.length) right.push(el.Text({ key: k("line-notes"), dimColor: true, children: [notes.join(" · ")] }));
1005
1034
  if (details) right.push(details);
1006
- const lines = specs.map((spec, i) => bandLine(el, spec, widths, i === 0 ? right : null));
1035
+ const widths = {
1036
+ ids: Math.max(0, ...specs.map((x) => idsWidth(x.ids, x.prefix))),
1037
+ status: Math.max(0, ...specs.map(statusWidth)),
1038
+ };
1039
+ const lines = specs.length
1040
+ ? specs.map((spec, i) => bandLine(el, spec, widths, i === 0 ? right : null))
1041
+ : [el.Box({ key: k("line-notes-only"), flexDirection: "row", columnGap: 1, children: right })];
1007
1042
  // BOT-3223 AC-1: context alarm and wait badges lead, on one wrapping line.
1008
1043
  const ctx = contextLine(el, k("line-context"), s.waits);
1009
1044
  if (ctx) lines.unshift(ctx);
@@ -1114,9 +1149,11 @@ export function register(on) {
1114
1149
  surface = e.surface;
1115
1150
  const theirs = await next(e);
1116
1151
  if (unbound && mode === "live") return theirs;
1152
+ // BOT-3228: one even gap between the band's rows (none in the terminal,
1153
+ // where a row is a line; the surface's small step elsewhere).
1117
1154
  return el.Box({
1118
1155
  flexDirection: "column",
1119
- children: [theirs, ...bandLines(el, $)],
1156
+ children: [theirs, el.Box({ key: "band", flexDirection: "column", rowGap: "xs", children: bandLines(el, $) })],
1120
1157
  });
1121
1158
  });
1122
1159
  on("ui.render", { component: "Pane" }, async ($, e, next) => {
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.73.1",
3
- "source_commit": "d9e320ddead58e283c40a13c2fe5cba020d43d86",
4
- "source_sha256": "2c734fb9885c96d0824c2ed97526bf5524b96ae6d0c77e987d937c5cc902e771",
2
+ "release_version": "1.73.3",
3
+ "source_commit": "1d11f9a0881e212eda6474d158c2d30ca54abfce",
4
+ "source_sha256": "13855ea27a4a26cf5ea2d49ce058d4e8ba459a78d49aa123f351eb8834f67b27",
5
5
  "target": "darwin-arm64",
6
- "sha256": "ebad8ecb4eb6e29d9ef5ce70e2d72a3d41e00492f02206bbc9ea24b4c68efc87"
6
+ "sha256": "756319e58995c75e35175fceda15be53222c72a0cfa831e2edfee2a72ef43786"
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
- "release_version": "1.73.1",
3
- "source_commit": "d9e320ddead58e283c40a13c2fe5cba020d43d86",
4
- "source_sha256": "2c734fb9885c96d0824c2ed97526bf5524b96ae6d0c77e987d937c5cc902e771",
2
+ "release_version": "1.73.3",
3
+ "source_commit": "1d11f9a0881e212eda6474d158c2d30ca54abfce",
4
+ "source_sha256": "13855ea27a4a26cf5ea2d49ce058d4e8ba459a78d49aa123f351eb8834f67b27",
5
5
  "target": "linux-x64",
6
- "sha256": "3eca987215c191a136ec17784bbb4a1e8b326f4ede63564c4427f418a85d0e03"
6
+ "sha256": "2d292e6c266e2f797d39cd409aa103983242eb31d2fd4440f995e5161dcad272"
7
7
  }
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "schema_version": 1,
3
- "release_version": "1.73.1",
4
- "source_commit": "d9e320ddead58e283c40a13c2fe5cba020d43d86",
5
- "source_sha256": "2c734fb9885c96d0824c2ed97526bf5524b96ae6d0c77e987d937c5cc902e771",
3
+ "release_version": "1.73.3",
4
+ "source_commit": "1d11f9a0881e212eda6474d158c2d30ca54abfce",
5
+ "source_sha256": "13855ea27a4a26cf5ea2d49ce058d4e8ba459a78d49aa123f351eb8834f67b27",
6
6
  "targets": {
7
7
  "darwin-arm64": {
8
8
  "goos": "darwin",
9
9
  "goarch": "arm64",
10
10
  "binary": "daemon/bin/darwin-arm64/botbuddy-daemon",
11
- "sha256": "ebad8ecb4eb6e29d9ef5ce70e2d72a3d41e00492f02206bbc9ea24b4c68efc87",
11
+ "sha256": "756319e58995c75e35175fceda15be53222c72a0cfa831e2edfee2a72ef43786",
12
12
  "mode": "0755"
13
13
  },
14
14
  "linux-x64": {
15
15
  "goos": "linux",
16
16
  "goarch": "amd64",
17
17
  "binary": "daemon/bin/linux-x64/botbuddy-daemon",
18
- "sha256": "3eca987215c191a136ec17784bbb4a1e8b326f4ede63564c4427f418a85d0e03",
18
+ "sha256": "2d292e6c266e2f797d39cd409aa103983242eb31d2fd4440f995e5161dcad272",
19
19
  "mode": "0755"
20
20
  }
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/cli",
3
- "version": "1.73.1",
3
+ "version": "1.73.3",
4
4
  "description": "BotBuddy — Swarm coordination CLI for multi-agent workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -289,5 +289,5 @@ export async function doctorAgentAuth({
289
289
  }
290
290
 
291
291
  export function doctorHelp() {
292
- return "bb doctor [--fix] [--print-exports] [--json]\nbb doctor --only git_transport [--remote <name>] [--url <push url>] [--fix] [--json]\n\nChecks the client key, repo binding, cached agent session, this worktree's stack-lease capability (registered host + attested machine), and whether git's SSH push connection carries a keepalive (git_transport). --fix mints a replacement session and (re)establishes the stack-lease capability; --print-exports prints its canonical shell exports. When the client key is unreachable (a Background LaunchAgent cannot read the login Keychain), --fix mints from the tier-2 MCP key exported under the binding's mcp_env name (env only, never Keychain).\n\ngit_transport: git opens the SSH connection BEFORE the pre-push hook runs, so a long hook lets it idle until it is dropped and the push dies (exit 141) after every gate passed. ok = ServerAliveInterval > 0 on the push's ssh; n/a = not an ssh remote; needs_fix / unknown = not provable. --fix sets git config --local core.sshCommand \"ssh -o ServerAliveInterval=20 -o ServerAliveCountMax=60\" only when nothing is configured; an existing GIT_SSH_COMMAND, core.sshCommand or GIT_SSH is never overwritten (the exact edit is printed instead).\n\n--only git_transport runs just that check — no sign-in, no network, well under a second — for a pre-push hook: exit 0 ok/n/a, 3 needs_fix/unknown (remedy on stderr), 4 usage. A hook passes its $1 as --remote and its $2 (the URL this push goes to) as --url; without --url every push URL of the remote (default: the branch's push remote, else origin) is checked.";
292
+ return "bb doctor [--fix] [--print-exports] [--json]\nbb doctor --only git_transport [--remote <name>] [--url <push url>] [--fix] [--json]\n\nChecks the client key, repo binding, cached agent session, this worktree's stack-lease capability (registered host + attested machine), and whether git's SSH push connection carries a keepalive (git_transport). --fix renews this harness session's own BB session in place (keeping its tickets and PRs) and re-attests the stack-lease capability on it, or mints a replacement session when that session is closed or belongs to another harness session; --print-exports prints its canonical shell exports. When the client key is unreachable (a Background LaunchAgent cannot read the login Keychain), --fix mints from the tier-2 MCP key exported under the binding's mcp_env name (env only, never Keychain).\n\ngit_transport: git opens the SSH connection BEFORE the pre-push hook runs, so a long hook lets it idle until it is dropped and the push dies (exit 141) after every gate passed. ok = ServerAliveInterval > 0 on the push's ssh; n/a = not an ssh remote; needs_fix / unknown = not provable. --fix sets git config --local core.sshCommand \"ssh -o ServerAliveInterval=20 -o ServerAliveCountMax=60\" only when nothing is configured; an existing GIT_SSH_COMMAND, core.sshCommand or GIT_SSH is never overwritten (the exact edit is printed instead).\n\n--only git_transport runs just that check — no sign-in, no network, well under a second — for a pre-push hook: exit 0 ok/n/a, 3 needs_fix/unknown (remedy on stderr), 4 usage. A hook passes its $1 as --remote and its $2 (the URL this push goes to) as --url; without --url every push URL of the remote (default: the branch's push remote, else origin) is checked.";
293
293
  }
@@ -319,8 +319,23 @@ export async function selfHealAgentSession({
319
319
  // (same session_id, so its ticket/PR edges keep feeding the bb-status band)
320
320
  // before falling back to a new mint, which would start an unlinked session.
321
321
  // A closed session, another harness's cache, or any renewal failure keeps the
322
- // existing mint path. `force` (doctor --fix) still re-registers to re-attest.
323
- if (!force && current && ownCache && current.session_id && current.agent_id && (renewal || !isFresh(current, now()))) {
322
+ // existing mint path.
323
+ // BOT-3219: `force` (doctor --fix) renews in place too, fresh or lapsed, and
324
+ // re-attests the stack-lease capability on that renewal. Only a renewal that
325
+ // returns a capability verdict replaces the forced mint, so an older server
326
+ // that ignores the attestation fields still gets the re-attesting mint.
327
+ let attest = null;
328
+ if (force && !renewal) {
329
+ const [attestBranch, attestHardware, attestHost] = await Promise.all([branch(), hardwareId(), machineHostFn()]);
330
+ attest = {
331
+ host: attestHost,
332
+ // The same worktree register_agent would attest below.
333
+ worktree: registrationWorktree,
334
+ ...(attestHardware ? { machine_uuid: attestHardware } : {}),
335
+ ...(attestBranch ? { branch: attestBranch } : {}),
336
+ };
337
+ }
338
+ if (current && ownCache && current.session_id && current.agent_id && (renewal || attest || !isFresh(current, now()))) {
324
339
  const { renewHarnessSession } = await import("./session-bootstrap.mjs");
325
340
  const renewedState = await renewHarnessSession({
326
341
  cwd,
@@ -332,8 +347,13 @@ export async function selfHealAgentSession({
332
347
  writeState,
333
348
  // Already inside this worktree's state lock.
334
349
  transaction: (_options, operation) => operation(cwd),
350
+ force: !!attest,
351
+ attest,
335
352
  }).catch(() => null);
336
- if (renewedState?.agent_session_token && (!renewal || renewedState.agent_session_token !== rejectedCredential.token)) {
353
+ const capability = renewedState?.stack_lease_capability;
354
+ const attested = !attest || (capability && typeof capability.status === "string");
355
+ if (attested && renewedState?.agent_session_token && (!renewal || renewedState.agent_session_token !== rejectedCredential.token)) {
356
+ const { checked_at: _checkedAt, ...verdict } = capability ?? {};
337
357
  return withIdentity({
338
358
  token: renewedState.agent_session_token,
339
359
  sessionId: sessionId ?? renewedState.session_id,
@@ -341,7 +361,7 @@ export async function selfHealAgentSession({
341
361
  source: "renewed",
342
362
  mintedWith,
343
363
  ticketSignals: null,
344
- stackLeaseCapability: null,
364
+ stackLeaseCapability: attest ? verdict : null,
345
365
  }, renewedState);
346
366
  }
347
367
  }
@@ -181,6 +181,13 @@ export async function renewHarnessSession({
181
181
  readState = readAgentState,
182
182
  writeState = writeAgentState,
183
183
  transaction = withHarnessBootstrapLock,
184
+ // BOT-3219: `bb doctor --fix` renews a still-fresh session too, so it can
185
+ // re-attest the worktree's stack-lease capability on the SAME session. A
186
+ // fresh session's bearer is reissued unchanged by the server.
187
+ force = false,
188
+ // BOT-3219: { host, worktree, machine_uuid?, branch? } — the server runs the
189
+ // register_agent worktree attestation and returns `stack_lease_capability`.
190
+ attest = null,
184
191
  } = {}) {
185
192
  if (typeof harnessSessionId !== "string" || !harnessSessionId) {
186
193
  throw renewalError("session_identity_mismatch", "renewal requires this harness session's id");
@@ -193,11 +200,20 @@ export async function renewHarnessSession({
193
200
  if (String(cached.harness_session_id ?? "").toLowerCase() !== harness) {
194
201
  throw renewalError("session_identity_mismatch", "the cached session belongs to another harness session");
195
202
  }
196
- if (Date.parse(cached.expires_at) > now()) return cached;
203
+ if (!force && Date.parse(cached.expires_at) > now()) return cached;
204
+ const attestation = attest && typeof attest.host === "string" && attest.host && typeof attest.worktree === "string" && attest.worktree
205
+ ? Object.fromEntries(Object.entries({
206
+ host: attest.host,
207
+ worktree: attest.worktree,
208
+ machine_uuid: attest.machine_uuid,
209
+ branch: attest.branch,
210
+ }).filter(([, value]) => typeof value === "string" && value))
211
+ : {};
197
212
  const response = await call("renew_agent_session", {
198
213
  session_id: cached.session_id,
199
214
  agent_id: cached.agent_id,
200
215
  harness_session_id: harness,
216
+ ...attestation,
201
217
  }, { ...callOptions, ...(cached.tenant ? { tenant: cached.tenant } : {}) });
202
218
  if (!response?.ok || response.isError) {
203
219
  if (response?.auth) throw renewalError("renewal_unauthorized", "run `bb doctor --fix`, or `bb mcp setup` if the MCP key is missing");
@@ -215,14 +231,21 @@ export async function renewHarnessSession({
215
231
  || !(Date.parse(data.expires_at) > now())) {
216
232
  throw renewalError("session_renewal_failed", "renew_agent_session returned a different or unusable session");
217
233
  }
234
+ // BOT-3219: a re-attesting renewal reports ONLY its own verdict; an earlier
235
+ // registration's cached verdict must never stand in for a missing one.
236
+ const { stack_lease_capability: _priorVerdict, ...base } = cached;
218
237
  const state = {
219
- ...cached,
238
+ ...(attestation.host ? base : cached),
220
239
  agent_session_token: data.session_token,
221
240
  minted_at: new Date(now()).toISOString(),
222
241
  expires_at: new Date(Date.parse(data.expires_at)).toISOString(),
223
242
  ...(typeof data.session_token_generation === "string" && data.session_token_generation
224
243
  ? { session_token_generation: data.session_token_generation }
225
244
  : {}),
245
+ // BOT-3219: the re-attested verdict, cached so a plain `bb doctor` reports it.
246
+ ...(data.stack_lease_capability && typeof data.stack_lease_capability.status === "string"
247
+ ? { stack_lease_capability: { ...data.stack_lease_capability, checked_at: new Date(now()).toISOString() } }
248
+ : {}),
226
249
  };
227
250
  await writeState(root, state);
228
251
  return state;
@@ -5,6 +5,7 @@ import { execFile } from "node:child_process";
5
5
  import { promisify } from "node:util";
6
6
  import { join } from "node:path";
7
7
  import { homedir } from "node:os";
8
+ import { findAgentStateRoot } from "./agent-state.mjs";
8
9
  const execFileAsync = promisify(execFile);
9
10
  const UUID =
10
11
  /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
@@ -265,6 +266,17 @@ export async function readStatus({
265
266
  const own = await bb("get_session_status", {});
266
267
  const ownOk =
267
268
  own?.session_id === state.session_id && own?.tenant_id === tenant && Array.isArray(own?.tickets);
269
+ // BOT-3228 AC-3: why the session's own read was not used, so a branch guess
270
+ // says so and the cause can be found.
271
+ const sessionRead = ownOk
272
+ ? "ok"
273
+ : own == null
274
+ ? "unavailable"
275
+ : own?.session_id !== state.session_id
276
+ ? "other_session"
277
+ : own?.tenant_id !== tenant
278
+ ? "other_tenant"
279
+ : "malformed";
268
280
  const sessionKeys = ownOk && !selected
269
281
  ? [...new Set(own.tickets.map((x) => String(x?.key || "").toUpperCase()).filter((k) => keyPattern.test(k)))].slice(0, 5)
270
282
  : [];
@@ -541,6 +553,7 @@ export async function readStatus({
541
553
  // BOT-3136: where the tickets came from — the registered session, an explicit
542
554
  // pick, or (only when the session registered none) a guess from the branch.
543
555
  binding: bindingKind,
556
+ session_read: sessionRead,
544
557
  blockers: useLinear && key
545
558
  ? [...new Map(blockers.map((b) => [b.key, b])).values()].sort((a, b) =>
546
559
  a.key.localeCompare(b.key),
@@ -743,6 +756,10 @@ export async function main(args, {
743
756
  (args.length === 4 && args[2] !== "--ticket-id")
744
757
  )
745
758
  refuse("invalid_arguments");
759
+ // BOT-3228 AC-2: Claude's working directory can be any folder of the
760
+ // worktree (a `cd` in the session moves it); the binding and the session
761
+ // cache live at the worktree's root, so read from there.
762
+ cwd = await findAgentStateRoot(await realpath(cwd).catch(() => cwd));
746
763
  const request = { cwd, harnessSessionId: args[1], ticketId: args[3], linearKey: env.LINEAR_BB_API_KEY, skipEpic };
747
764
  if (UUID.test(args[1])) await keepSessionAlive({ cwd, harnessSessionId: args[1], now, heartbeat, renew });
748
765
  let snapshot;