pi-herdsman 0.52.0 → 0.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.52.1](https://github.com/boadij/pi-herdsman/compare/v0.52.0...v0.52.1) (2026-11-21)
4
+
5
+
6
+ ### Fixes
7
+
8
+ * **manager:** inherit Pi agent directory in worktree Leads ([#1076](https://github.com/boadij/pi-herdsman/issues/1076)) ([5d789a1](https://github.com/boadij/pi-herdsman/commit/5d789a104a69e35e841b3502e4f1fabe55304252)), closes [#1072](https://github.com/boadij/pi-herdsman/issues/1072)
9
+ * **ui:** allow managed Leads to focus Managers across builds ([#1073](https://github.com/boadij/pi-herdsman/issues/1073)) ([c5b35de](https://github.com/boadij/pi-herdsman/commit/c5b35deaf831008b4aa8864d0d1ef43d984e0176))
10
+ * **ui:** close remaining Agent startup status gap ([#1071](https://github.com/boadij/pi-herdsman/issues/1071)) ([f25bce5](https://github.com/boadij/pi-herdsman/commit/f25bce5c24ab333104d963e7d3c15495819c2964))
11
+ * **ui:** eliminate verified Agent startup flicker ([#1078](https://github.com/boadij/pi-herdsman/issues/1078)) ([b0fefa5](https://github.com/boadij/pi-herdsman/commit/b0fefa5bfabe041200b38a23a0553f9ab030d889))
12
+ * **ui:** preserve verified Agent startup status ([#1068](https://github.com/boadij/pi-herdsman/issues/1068)) ([bf65910](https://github.com/boadij/pi-herdsman/commit/bf6591034052461de36656b5337e3b4820c82819))
13
+
14
+
15
+ ### Documentation
16
+
17
+ * **audit:** add workflow optimization lens ([#1069](https://github.com/boadij/pi-herdsman/issues/1069)) ([39b6b46](https://github.com/boadij/pi-herdsman/commit/39b6b464cab27420243ecbbb4f575a721482bea5))
18
+ * **contributors:** add recognition skill and refresh acknowledgments ([#1080](https://github.com/boadij/pi-herdsman/issues/1080)) ([dbee621](https://github.com/boadij/pi-herdsman/commit/dbee6210b4147eaa2bfd976928d1e09672df786f))
19
+
20
+
21
+ ### Other Changes
22
+
23
+ * **deps:** update ghcr.io/jdx/mise docker tag to v2026.11.11 ([#1067](https://github.com/boadij/pi-herdsman/issues/1067)) ([d75e6e7](https://github.com/boadij/pi-herdsman/commit/d75e6e7a0a0a9555c5c09bb50d3ed7feac873aaa))
24
+ * **deps:** update ghcr.io/jdx/mise docker tag to v2026.11.12 ([#1074](https://github.com/boadij/pi-herdsman/issues/1074)) ([f3e1ce8](https://github.com/boadij/pi-herdsman/commit/f3e1ce82c4ba597b15ef1156140bb9bb9b367668))
25
+ * **pi:** expose vendored GitHub CLI skill to project leads ([#1077](https://github.com/boadij/pi-herdsman/issues/1077)) ([2e92696](https://github.com/boadij/pi-herdsman/commit/2e926967801919a19925e3a6848cda48f9def992))
26
+ * **release:** streamline guarded release preparation ([#1070](https://github.com/boadij/pi-herdsman/issues/1070)) ([2c0abbe](https://github.com/boadij/pi-herdsman/commit/2c0abbe5da865fcb8b830600332d6b61229b2818))
27
+ * **runtime:** validate and adopt Pi 1.6.0 ([#1063](https://github.com/boadij/pi-herdsman/issues/1063)) ([37bae59](https://github.com/boadij/pi-herdsman/commit/37bae5982c95c9b653141193e445fee2cbaf5e6c))
28
+
3
29
  ## [0.52.0](https://github.com/boadij/pi-herdsman/compare/v0.51.0...v0.52.0) (2026-11-20)
4
30
 
5
31
 
package/dist/index.js CHANGED
@@ -4633,9 +4633,11 @@ async function startHerdrAgent(pi, ctx, options) {
4633
4633
  "--timeout",
4634
4634
  String(Math.min(remaining, childTimeout)),
4635
4635
  "--",
4636
- ...options.extensionPath ? ["--extension", options.extensionPath] : [],
4636
+ // Publish Pi session identity before Herdsman's startup handler
4637
+ // makes the managed mailbox state observable.
4637
4638
  "--extension",
4638
4639
  HERDR_AGENT_STATE_EXTENSION,
4640
+ ...options.extensionPath ? ["--extension", options.extensionPath] : [],
4639
4641
  ...options.agentArgs ?? []
4640
4642
  ],
4641
4643
  {
@@ -12604,25 +12606,34 @@ function rootStatusBreadcrumb(role2) {
12604
12606
  function buildAgentStatusSnapshot(view, ctx, host) {
12605
12607
  const ownerSessionId = ctx.sessionManager.getSessionId();
12606
12608
  const unresolvedMailboxState = host.scope.kind === "root" && view.stateIssues.length > 0;
12607
- const listed = view.visible.map(
12608
- (snapshot) => host.listedAgentRecord(
12609
+ const agents = view.visible.map((observed) => {
12610
+ const agent = host.listedAgentRecord(
12609
12611
  view,
12610
- snapshot,
12612
+ observed,
12611
12613
  ownerSessionId,
12612
12614
  host.scope,
12613
12615
  unresolvedMailboxState
12614
- )
12615
- );
12616
- const agents = listed.map((agent) => {
12616
+ );
12617
12617
  const runtime = host.runtimeForLabel(agent.agent);
12618
12618
  const tokens = agent.tokens && typeof agent.tokens === "object" ? agent.tokens : {};
12619
12619
  const role2 = Reflect.get(tokens, "role");
12620
12620
  const task = Reflect.get(tokens, "task");
12621
12621
  const presentation = parsePresentationTokens(tokens);
12622
12622
  const state = agent.state === "working" || agent.state === "blocked" || agent.state === "settling" || agent.state === "starting" || agent.state === "unknown" || agent.state === "lost" ? agent.state : "unknown";
12623
+ const { presence, state: durableState, lifecycleState } = observed;
12624
+ const verifiedLive = presence.kind === "live" && runtime !== void 0 && runtimeIdentityMatches(runtime, durableState, presence.agent);
12625
+ const beforeInteractiveReady = runtime === void 0 && presence.kind === "live" && presence.agent.agent_status === "unknown" && presence.agent.interactive_ready !== true;
12626
+ const startupTransition = state === "unknown" && (verifiedLive || runtime === void 0 && presence.kind === "live") && !durableState.completedRequestId && !durableState.resultError && !durableState.pendingAskId && ((lifecycleState === "working" || beforeInteractiveReady) && !durableState.activeRequestId || lifecycleState === "idle" && !!durableState.activeRequestId);
12623
12627
  return {
12624
12628
  label: agent.agent,
12625
12629
  state,
12630
+ ...verifiedLive && (state === "working" || state === "blocked") && durableState.activeRequestId !== void 0 ? { activeRequestId: durableState.activeRequestId } : {},
12631
+ ...startupTransition ? {
12632
+ startupTransition: {
12633
+ runId: durableState.runId,
12634
+ activeRequestId: durableState.activeRequestId
12635
+ }
12636
+ } : {},
12626
12637
  definition: collapseDisplayText(
12627
12638
  typeof agent.agent_definition === "string" && agent.agent_definition.trim() ? agent.agent_definition : typeof role2 === "string" ? role2 : void 0
12628
12639
  ) ?? "unknown",
@@ -12720,9 +12731,15 @@ function createAgentStatusRuntime() {
12720
12731
  const widgetSnapshot = (snapshot, standalone = false) => {
12721
12732
  const pendingStarts = options?.pendingStartEntries() ?? [];
12722
12733
  if (!pendingStarts.length) return snapshot;
12723
- const agents = snapshot.agents.map(
12724
- (agent) => options.hasPendingStart(agent.label) && agent.state === "settling" ? { ...agent, state: "starting" } : agent
12725
- );
12734
+ const agents = snapshot.agents.map((agent) => {
12735
+ if (agent.state === "settling" && options.hasPendingStart(agent.label))
12736
+ return { ...agent, state: "starting" };
12737
+ if (agent.state !== "unknown" || !agent.startupTransition || snapshot.stale || snapshot.unavailable)
12738
+ return agent;
12739
+ const pending = pendingStarts.find(({ label }) => label === agent.label);
12740
+ const { runId, activeRequestId } = agent.startupTransition;
12741
+ return pending?.runId === runId && (activeRequestId === void 0 || activeRequestId === pending.requestId) ? { ...agent, state: "starting" } : agent;
12742
+ });
12726
12743
  const pendingAgents = pendingStarts.filter(
12727
12744
  ({ label }) => !snapshot.agents.some((agent) => agent.label === label)
12728
12745
  ).map(({ label, definition, task, startedAt, parentLabel }) => ({
@@ -12745,7 +12762,7 @@ function createAgentStatusRuntime() {
12745
12762
  const { label } = pending;
12746
12763
  const agent = snapshot.agents.find((item) => item.label === label);
12747
12764
  const runtime = options.runtimeForLabel(label);
12748
- const resolved = pending.requestId !== void 0 && (agent?.state === "working" || agent?.state === "blocked" || runtime?.activeRequestId === pending.requestId && agent !== void 0 && agent.state !== "settling" || runtime?.completedRequestId === pending.requestId);
12765
+ const resolved = pending.requestId !== void 0 && (runtime?.completedRequestId === pending.requestId || runtime?.activeRequestId === pending.requestId && agent?.activeRequestId === pending.requestId && (agent.state === "working" || agent.state === "blocked"));
12749
12766
  if (resolved) options.clearPendingStart(label, pending);
12750
12767
  }
12751
12768
  };
@@ -16570,6 +16587,7 @@ function createAgentController(pi, options) {
16570
16587
  };
16571
16588
  const closeSnapshot = async (context, snapshot2, signal, report, assignmentLockHeld = false, preserveOwnerMessages = false) => {
16572
16589
  const state = snapshot2.state;
16590
+ const pending = pendingStarts.get(state.agentLabel);
16573
16591
  const mailbox = agentMailboxPath(state.workspaceId, state.agentLabel);
16574
16592
  const release = assignmentLockHeld ? void 0 : claimAssignmentLock3(mailbox, "close", {
16575
16593
  label: state.agentLabel,
@@ -16713,14 +16731,20 @@ function createAgentController(pi, options) {
16713
16731
  removeAgentMailbox(mailbox);
16714
16732
  } catch (error2) {
16715
16733
  const message = `Agent pane closed but mailbox cleanup failed: ${String(error2)}`;
16716
- const runtime = runtimes.get(state.agentLabel);
16717
- if (runtime?.workspaceId === state.workspaceId)
16718
- runtime.cleanupError = message;
16734
+ const runtime2 = runtimes.get(state.agentLabel);
16735
+ if (runtime2?.workspaceId === state.workspaceId)
16736
+ runtime2.cleanupError = message;
16719
16737
  if (!report?.onCleanupFailure) throw error2;
16720
16738
  options.appendError(context, "pi_herdsman_cleanup_error", error2);
16721
16739
  report.onCleanupFailure(state.agentLabel, message);
16722
16740
  return;
16723
16741
  }
16742
+ const runtime = runtimes.get(state.agentLabel);
16743
+ if (pending?.requestId !== void 0 && pendingStarts.get(state.agentLabel) === pending && runtime && sameIdentity(
16744
+ recordDependencies.runtimeIdentityState(runtime),
16745
+ current
16746
+ ) && (runtime.activeRequestId === pending.requestId || current.lastAck?.accepted && current.lastAck.requestId === pending.requestId))
16747
+ pendingStarts.delete(state.agentLabel);
16724
16748
  invalidateRuntime(state.agentLabel, state.workspaceId);
16725
16749
  report?.onClosed?.({
16726
16750
  state: current,
@@ -18725,6 +18749,7 @@ This batch was not embedded. Use read_evidence to retrieve the items relevant to
18725
18749
  }
18726
18750
  const pendingStart = {
18727
18751
  label,
18752
+ runId,
18728
18753
  definition: agentDefinition,
18729
18754
  requestId: assignment.requestId,
18730
18755
  ...p.task !== void 0 ? { task: p.task } : {},
@@ -24511,7 +24536,7 @@ ${DELEGATING_AGENT_SCOPE_DESCRIPTION}`;
24511
24536
  import { contentText as contentText5 } from "@earendil-works/pi-ai";
24512
24537
  import {
24513
24538
  buildSessionProjection as buildSessionProjection3,
24514
- getAgentDir as getAgentDir3,
24539
+ getAgentDir as getAgentDir4,
24515
24540
  getSelectListTheme as getSelectListTheme2,
24516
24541
  SessionManager as SessionManager3
24517
24542
  } from "@earendil-works/pi-coding-agent";
@@ -24545,7 +24570,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
24545
24570
  // package.json
24546
24571
  var package_default = {
24547
24572
  name: "pi-herdsman",
24548
- version: "0.52.0",
24573
+ version: "0.52.1",
24549
24574
  type: "module",
24550
24575
  description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
24551
24576
  license: "Apache-2.0",
@@ -24593,7 +24618,7 @@ var package_default = {
24593
24618
  },
24594
24619
  piHerdsman: {
24595
24620
  runtime: {
24596
- pi: "1.5.2",
24621
+ pi: "1.6.0",
24597
24622
  herdr: {
24598
24623
  version: "0.9.5",
24599
24624
  sha256: {
@@ -24628,9 +24653,9 @@ var package_default = {
24628
24653
  typebox: "*"
24629
24654
  },
24630
24655
  devDependencies: {
24631
- "@earendil-works/pi-ai": "1.5.2",
24632
- "@earendil-works/pi-coding-agent": "1.5.2",
24633
- "@earendil-works/pi-tui": "1.5.2",
24656
+ "@earendil-works/pi-ai": "1.6.0",
24657
+ "@earendil-works/pi-coding-agent": "1.6.0",
24658
+ "@earendil-works/pi-tui": "1.6.0",
24634
24659
  "@modelcontextprotocol/sdk": "1.32.2",
24635
24660
  "@types/node": "22.20.5",
24636
24661
  "@types/proper-lockfile": "4.1.4",
@@ -24817,6 +24842,7 @@ init_config();
24817
24842
  init_core();
24818
24843
  init_storage();
24819
24844
  init_agent_controller();
24845
+ import { getAgentDir as getAgentDir3 } from "@earendil-works/pi-coding-agent";
24820
24846
  init_agent_definitions();
24821
24847
  import { randomUUID as randomUUID12 } from "node:crypto";
24822
24848
  import { realpathSync as realpathSync6, statSync as statSync7, unlinkSync as unlinkSync9 } from "node:fs";
@@ -27531,6 +27557,7 @@ Type forget ${branch} to confirm.`,
27531
27557
  throw new Error(
27532
27558
  `Branch ${branch} already has live Lead session ${herdrSessionId2(leads[0])}. Coordinate with that Lead or close it before starting managed work on this branch.`
27533
27559
  );
27560
+ return inventory;
27534
27561
  };
27535
27562
  if (branchWorktrees[0]?.open_workspace_id)
27536
27563
  await assertUnoccupied(branchWorktrees[0].open_workspace_id);
@@ -27615,8 +27642,8 @@ Type forget ${branch} to confirm.`,
27615
27642
  if (!currentScope.isPrimary || currentScope.repoKey !== manager.repoKey || currentScope.checkoutPath !== localScope.checkoutPath || !current || !sameManagerDescriptor2(current, manager))
27616
27643
  throw new Error("Manager identity changed before project activation");
27617
27644
  let workspaceId;
27618
- let paneId;
27619
- let tabId;
27645
+ let initialPaneId;
27646
+ let initialTabId;
27620
27647
  let cwd;
27621
27648
  const assignedPlacement = operation.action === "resume" ? resolveAssignmentCheckout(
27622
27649
  assignment,
@@ -27652,8 +27679,8 @@ Type forget ${branch} to confirm.`,
27652
27679
  { signal }
27653
27680
  );
27654
27681
  workspaceId = opened?.workspace?.workspace_id;
27655
- paneId = opened?.root_pane?.pane_id;
27656
- tabId = opened?.tab?.tab_id ?? opened?.root_pane?.tab_id;
27682
+ initialPaneId = opened?.root_pane?.pane_id;
27683
+ initialTabId = opened?.tab?.tab_id ?? opened?.root_pane?.tab_id;
27657
27684
  cwd = opened?.worktree?.path;
27658
27685
  if (assignedPlacement?.status === "matched" && (!opened?.worktree?.path || !sameDirectory(opened.worktree.path, assignedPlacement.path)))
27659
27686
  throw new Error(
@@ -27678,25 +27705,25 @@ Type forget ${branch} to confirm.`,
27678
27705
  timeout: 18e4
27679
27706
  });
27680
27707
  workspaceId = created?.workspace?.workspace_id;
27681
- paneId = created?.root_pane?.pane_id;
27682
- tabId = created?.tab?.tab_id;
27708
+ initialPaneId = created?.root_pane?.pane_id;
27709
+ initialTabId = created?.tab?.tab_id;
27683
27710
  cwd = created?.worktree?.path;
27684
27711
  if (created?.worktree?.branch && created.worktree.branch !== assignment.branch)
27685
27712
  throw new Error(
27686
27713
  "Herdr created a worktree on a different branch than the persisted assignment"
27687
27714
  );
27688
27715
  }
27689
- if (typeof workspaceId !== "string" || !workspaceId || typeof paneId !== "string" || !paneId || typeof tabId !== "string" || !tabId || typeof cwd !== "string" || !cwd)
27716
+ if (typeof workspaceId !== "string" || !workspaceId || typeof initialPaneId !== "string" || !initialPaneId || typeof initialTabId !== "string" || !initialTabId || typeof cwd !== "string" || !cwd)
27690
27717
  throw new Error("Herdr did not return exact worktree identities");
27691
- if (operation.action === "delegate") {
27718
+ const assertAssignedGitCheckout = async (checkout) => {
27692
27719
  const [common, branchResult] = await Promise.all([
27693
27720
  pi.exec(
27694
27721
  "git",
27695
27722
  ["rev-parse", "--path-format=absolute", "--git-common-dir"],
27696
- { cwd, signal, timeout: 1e4 }
27723
+ { cwd: checkout, signal, timeout: 1e4 }
27697
27724
  ),
27698
27725
  pi.exec("git", ["symbolic-ref", "--quiet", "--short", "HEAD"], {
27699
- cwd,
27726
+ cwd: checkout,
27700
27727
  signal,
27701
27728
  timeout: 1e4
27702
27729
  })
@@ -27705,6 +27732,9 @@ Type forget ${branch} to confirm.`,
27705
27732
  throw new Error(
27706
27733
  "Herdr checkout does not match the assigned repository and branch"
27707
27734
  );
27735
+ };
27736
+ if (operation.action === "delegate") {
27737
+ await assertAssignedGitCheckout(cwd);
27708
27738
  if (!isAbsolute7(cwd) || workspaceId === primaryWorkspaceId || !sameDirectory(
27709
27739
  topology.source.source_checkout_path,
27710
27740
  localScope.checkoutPath
@@ -27776,6 +27806,17 @@ Type forget ${branch} to confirm.`,
27776
27806
  let previousLeadInstanceId;
27777
27807
  let leadStartupStartedAt;
27778
27808
  let freshRestorationAttestation = false;
27809
+ let requireResolvedSession = false;
27810
+ const label = `lead-${id.slice(0, 8)}`;
27811
+ const expectedName = herdrAgentAlias(workspaceId, label, id);
27812
+ let paneId = initialPaneId;
27813
+ let tabId = initialTabId;
27814
+ const isCurrentCandidate = (agent) => agent.workspace_id === workspaceId && (agent.name === expectedName || isPiAgent2(agent) && (herdrSessionId2(agent) === assignment.id || agent.pane_id === initialPaneId && agent.tab_id === initialTabId));
27815
+ const assertManagerCurrent = async () => {
27816
+ const fresh = await currentManager(ctx);
27817
+ if (!fresh || !sameManagerDescriptor2(fresh, manager))
27818
+ throw new Error("Manager changed during project activation");
27819
+ };
27779
27820
  const verifyLeadCandidate = (candidate) => {
27780
27821
  const reported = sessionIdentity2(candidate?.agent_session);
27781
27822
  if (!reported) return false;
@@ -27784,6 +27825,7 @@ Type forget ${branch} to confirm.`,
27784
27825
  throw new Error(
27785
27826
  "Herdr session identity does not match the Manager assignment"
27786
27827
  );
27828
+ if (requireResolvedSession && !resolvedSessionId) return false;
27787
27829
  const state = readLeadCoordinationState2(
27788
27830
  supervisionRuntime2(),
27789
27831
  assignment.id
@@ -27814,28 +27856,36 @@ Type forget ${branch} to confirm.`,
27814
27856
  return state?.role === "lead" && state.piSessionId === assignment.id;
27815
27857
  };
27816
27858
  const currentInventory = await herdrSessionSnapshot2(pi, ctx, signal);
27817
- const currentCandidates = currentInventory.agents.filter(
27818
- (agent) => isPiAgent2(agent) && agent.workspace_id === workspaceId && agent.pane_id === paneId && agent.tab_id === tabId
27819
- );
27859
+ const currentCandidates = currentInventory.agents.filter(isCurrentCandidate);
27820
27860
  if (currentCandidates.length > 1)
27821
27861
  throw new Error("Ambiguous Lead session in new worktree");
27822
27862
  if (currentCandidates.length === 1) {
27823
- if (verifyLeadCandidate(currentCandidates[0]))
27824
- lead = currentCandidates[0];
27863
+ const candidate = currentCandidates[0];
27864
+ if (typeof candidate.pane_id !== "string" || !candidate.pane_id || typeof candidate.tab_id !== "string" || !candidate.tab_id)
27865
+ throw new Error(
27866
+ "Herdr did not report exact existing Lead tab identities"
27867
+ );
27868
+ requireResolvedSession = candidate.pane_id !== initialPaneId || candidate.tab_id !== initialTabId;
27869
+ paneId = candidate.pane_id;
27870
+ tabId = candidate.tab_id;
27871
+ if (verifyLeadCandidate(candidate)) lead = candidate;
27825
27872
  }
27826
- let effectiveProjectTrusted;
27827
- if (!lead) {
27873
+ const originalPaneRunsPi = async () => {
27828
27874
  const processInfo = await runHerdr3(
27829
27875
  pi,
27830
27876
  ctx,
27831
- ["pane", "process-info", "--pane", paneId],
27877
+ ["pane", "process-info", "--pane", initialPaneId],
27832
27878
  { signal }
27833
27879
  );
27834
27880
  const foreground = processInfo?.process_info?.foreground_processes;
27835
- const piAlreadyRunning = currentCandidates.length === 1 || Array.isArray(foreground) && foreground.some((process2) => {
27881
+ return Array.isArray(foreground) && foreground.some((process2) => {
27836
27882
  const executable = `${process2?.argv0 ?? ""} ${process2?.cmdline ?? ""}`;
27837
27883
  return /(^|[\\/\s])pi(?:\s|$)/i.test(executable);
27838
27884
  });
27885
+ };
27886
+ let effectiveProjectTrusted;
27887
+ if (!lead) {
27888
+ const piAlreadyRunning = currentCandidates.length === 1 || await originalPaneRunsPi();
27839
27889
  if (!piAlreadyRunning) {
27840
27890
  await assertResumePlacement();
27841
27891
  await assertUnoccupied(workspaceId);
@@ -27905,6 +27955,43 @@ Type forget ${branch} to confirm.`,
27905
27955
  ...operation.action === "delegate" ? { inheritedThinking: pi.getThinkingLevel() } : {},
27906
27956
  modelDecision
27907
27957
  });
27958
+ const created = await runHerdr3(
27959
+ pi,
27960
+ ctx,
27961
+ [
27962
+ "tab",
27963
+ "create",
27964
+ "--workspace",
27965
+ workspaceId,
27966
+ "--cwd",
27967
+ cwd,
27968
+ "--label",
27969
+ label,
27970
+ "--env",
27971
+ `PI_CODING_AGENT_DIR=${getAgentDir3()}`,
27972
+ "--no-focus"
27973
+ ],
27974
+ { signal }
27975
+ );
27976
+ const tab = created?.tab;
27977
+ const pane = created?.root_pane;
27978
+ if (typeof tab?.tab_id !== "string" || !tab.tab_id || tab.workspace_id !== workspaceId || tab.tab_id === initialTabId || typeof pane?.pane_id !== "string" || !pane.pane_id || pane.pane_id === initialPaneId || typeof pane.terminal_id !== "string" || !pane.terminal_id || pane.workspace_id !== workspaceId || pane.tab_id !== tab.tab_id)
27979
+ throw new Error("Herdr did not return exact Lead tab identities");
27980
+ if (operation.action === "delegate")
27981
+ await assertAssignedGitCheckout(cwd);
27982
+ else await assertResumePlacement();
27983
+ const latestInventory = await assertUnoccupied(workspaceId);
27984
+ if (latestInventory.agents.some(isCurrentCandidate) || await originalPaneRunsPi())
27985
+ throw new Error(
27986
+ "A Lead appeared during tab creation; work was preserved"
27987
+ );
27988
+ await assertManagerCurrent();
27989
+ if (readProjectAssignment2(runtime, manager.repoKey, branch)?.id !== assignment.id)
27990
+ throw new Error(
27991
+ "Project assignment changed during Lead tab creation"
27992
+ );
27993
+ tabId = tab.tab_id;
27994
+ paneId = pane.pane_id;
27908
27995
  previousLeadInstanceId = readLeadCoordinationState2(
27909
27996
  supervisionRuntime2(),
27910
27997
  assignment.id
@@ -27916,7 +28003,7 @@ Type forget ${branch} to confirm.`,
27916
28003
  tabId,
27917
28004
  paneId,
27918
28005
  cwd,
27919
- label: `lead-${id.slice(0, 8)}`,
28006
+ label,
27920
28007
  runId: id,
27921
28008
  extensionPath: HERDSMAN_EXTENSION_PATH2,
27922
28009
  agentArgs: [...launchArgs, "--session-id", assignment.id],
@@ -28038,11 +28125,6 @@ Type forget ${branch} to confirm.`,
28038
28125
  await assertResumePlacement();
28039
28126
  await queueResumeHandoff(false);
28040
28127
  }
28041
- const assertManagerCurrent = async () => {
28042
- const fresh = await currentManager(ctx);
28043
- if (!fresh || !sameManagerDescriptor2(fresh, manager))
28044
- throw new Error("Manager changed during project activation");
28045
- };
28046
28128
  await assertManagerCurrent();
28047
28129
  const latestState = readLeadCoordinationState2(
28048
28130
  supervisionRuntime2(),
@@ -35549,8 +35631,15 @@ function registerLeadRuntime(pi, options) {
35549
35631
  scope,
35550
35632
  sessionId
35551
35633
  );
35552
- const manager = await roleTransitions.currentManager(ctx);
35553
- if (!current() || !assignment || !manager || manager.repoKey !== assignment.repoKey)
35634
+ if (!current() || !assignment)
35635
+ throw new Error("Managed project assignment changed.");
35636
+ const manager = roleTransitions.managerForScope(scope);
35637
+ const supervision = options.roleTransitionHost.supervisionRuntime();
35638
+ const coordination = manager ? options.roleTransitionHost.readLeadCoordinationState(
35639
+ supervision,
35640
+ manager.piSessionId
35641
+ ) : void 0;
35642
+ if (!current() || !manager || manager.repoKey !== assignment.repoKey || !manager.build || !coordination || coordination.role !== "manager" || coordination.piSessionId !== manager.piSessionId || !coordination.build || !sameRuntimeBuild(manager.build, coordination.build))
35554
35643
  throw new Error("Managed project Manager is unavailable.");
35555
35644
  const target2 = await verifiedHerdrAgent(manager, {
35556
35645
  listAgents: async () => (await options.identityHost.listAgents(ctx)).agents,
@@ -35559,10 +35648,16 @@ function registerLeadRuntime(pi, options) {
35559
35648
  isPiAgent: options.identityHost.isPiAgent,
35560
35649
  matchesExpectedSession: options.identityHost.matchesExpectedSession
35561
35650
  });
35562
- const currentManager = await roleTransitions.currentManager(ctx);
35563
35651
  const currentScope = await roleTransitions.currentWorktreeScope(ctx);
35564
35652
  const currentAssignment = currentScope ? roleTransitions.projectAssignmentForScope(currentScope, sessionId) : void 0;
35565
- if (!current() || !target2 || !currentAssignment || currentAssignment.id !== assignment.id || currentAssignment.repoKey !== assignment.repoKey || currentAssignment.branch !== assignment.branch || !currentManager || currentManager.repoKey !== assignment.repoKey || !options.projectHost.sameManagerDescriptor(currentManager, manager))
35653
+ const currentManager = roleTransitions.managerForScope(
35654
+ currentScope ?? void 0
35655
+ );
35656
+ const currentCoordination = currentManager ? options.roleTransitionHost.readLeadCoordinationState(
35657
+ supervision,
35658
+ currentManager.piSessionId
35659
+ ) : void 0;
35660
+ if (!current() || !target2 || !currentAssignment || currentAssignment.id !== assignment.id || currentAssignment.repoKey !== assignment.repoKey || currentAssignment.branch !== assignment.branch || !currentManager || currentManager.repoKey !== assignment.repoKey || !options.projectHost.sameManagerDescriptor(currentManager, manager) || !currentManager.build || !currentCoordination || currentCoordination.role !== "manager" || currentCoordination.piSessionId !== currentManager.piSessionId || currentCoordination.instanceId !== coordination.instanceId || !currentCoordination.build || !sameRuntimeBuild(currentManager.build, currentCoordination.build))
35566
35661
  throw new Error("Managed project Manager changed.");
35567
35662
  await options.commandHost.runHerdr(
35568
35663
  pi,
@@ -42471,8 +42566,8 @@ This is a nonblocking notification, not a pending await_owner request. Do not us
42471
42566
  const normalizeLeadTools = (tools) => leadToolState.normalizeLeadTools(tools);
42472
42567
  let roleTransitions;
42473
42568
  const isCurrentChief = (ctx) => leadRuntime.chiefMode === "active" && !!leadRuntime.chiefLease && leadRuntime.chiefLease.descriptor.piSessionId === ctx.sessionManager.getSessionId();
42474
- const chiefGlobalInstructions2 = (options) => chiefGlobalInstructions(options, getAgentDir3());
42475
- const chiefSystemPrompt2 = (options, body) => chiefSystemPrompt(options, body, CHIEF_ROLE_CONTRACT, getAgentDir3());
42569
+ const chiefGlobalInstructions2 = (options) => chiefGlobalInstructions(options, getAgentDir4());
42570
+ const chiefSystemPrompt2 = (options, body) => chiefSystemPrompt(options, body, CHIEF_ROLE_CONTRACT, getAgentDir4());
42476
42571
  const roleCharter = (ctx) => {
42477
42572
  const role2 = activeRole();
42478
42573
  if (leadRuntime.roleSuspended || role2 === "chief" && !isCurrentChief(ctx) || role2 === "manager" && !leadRuntime.managerLease)