pi-herdsman 0.49.0 → 0.50.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.
package/dist/index.js CHANGED
@@ -13776,7 +13776,7 @@ function effectiveMergePolicy(config, repoKey) {
13776
13776
  source: Object.hasOwn(config.managerMergeOverrides, repoKey) ? "repository" : "global"
13777
13777
  };
13778
13778
  }
13779
- function setManagerMergeOverride(repoKey, enabled) {
13779
+ function setManagerMergeOverride(repoKey, enabled, expected) {
13780
13780
  if (!validRepoIdentity(repoKey) || enabled !== void 0 && !validManagerMergeSetting(enabled))
13781
13781
  throw new Error(
13782
13782
  "A verified repository identity and optional merge policy are required"
@@ -13787,6 +13787,10 @@ function setManagerMergeOverride(repoKey, enabled) {
13787
13787
  });
13788
13788
  try {
13789
13789
  const current = readRawConfig();
13790
+ if (expected && ((current.managerMergeEnabled ?? DEFAULT_CONFIG.managerMergeEnabled) !== expected.global || current.managerMergeOverrides?.[repoKey] !== expected.override))
13791
+ throw new Error(
13792
+ "Manager integration policy changed; reopen the selector."
13793
+ );
13790
13794
  const overrides = { ...current.managerMergeOverrides };
13791
13795
  if (enabled === void 0) delete overrides[repoKey];
13792
13796
  else overrides[repoKey] = enabled;
@@ -13807,7 +13811,7 @@ function setManagerMergeOverride(repoKey, enabled) {
13807
13811
  release();
13808
13812
  }
13809
13813
  }
13810
- function setWorktreeRemovalPreapproved(repoKey, enabled) {
13814
+ function setWorktreeRemovalPreapproved(repoKey, enabled, expected) {
13811
13815
  if (!repoKey || typeof enabled !== "boolean")
13812
13816
  throw new Error(
13813
13817
  "A verified repository identity and boolean policy are required"
@@ -13819,6 +13823,8 @@ function setWorktreeRemovalPreapproved(repoKey, enabled) {
13819
13823
  try {
13820
13824
  const current = readRawConfig();
13821
13825
  const repos = new Set(current.worktreeRemovalPreapprovedRepos ?? []);
13826
+ if (expected !== void 0 && repos.has(repoKey) !== expected)
13827
+ throw new Error("Removal policy changed before saving the setting");
13822
13828
  if (enabled) repos.add(repoKey);
13823
13829
  else repos.delete(repoKey);
13824
13830
  if (repos.size) current.worktreeRemovalPreapprovedRepos = [...repos];
@@ -14006,13 +14012,18 @@ function writeConfigAtomically(path, content, mode = 384) {
14006
14012
  }
14007
14013
  if (cleanupFailed) throw cleanupError;
14008
14014
  }
14009
- function updateConfig(key, value2) {
14015
+ function updateConfig(key, value2, expectedManagerMergeEnabled) {
14010
14016
  const path = herdsmanConfigPath();
14011
14017
  const release = claimProcessLock(`${path}.lock`, {
14012
14018
  name: "Pi Herdsman config update"
14013
14019
  });
14014
14020
  try {
14015
14021
  const current = readRawConfig();
14022
+ if (expectedManagerMergeEnabled !== void 0 && (key !== "managerMergeEnabled" || (current.managerMergeEnabled ?? DEFAULT_CONFIG.managerMergeEnabled) !== expectedManagerMergeEnabled))
14023
+ throw new Error(
14024
+ "Global Manager integration policy changed; reopen the selector."
14025
+ );
14026
+ if (value2 === void 0 && !Object.hasOwn(current, key)) return;
14016
14027
  if (value2 !== void 0) {
14017
14028
  if (key === "statusWidgetMaxRows" && !validStatusWidgetMaxRows(value2))
14018
14029
  throw new Error("Invalid Pi Herdsman config field statusWidgetMaxRows");
@@ -22440,7 +22451,7 @@ function collectSessionUsage(ctx, ownedChildren, openOwnedSession, leadRoots = [
22440
22451
  breakdown
22441
22452
  };
22442
22453
  }
22443
- var delegationLockPath, claimDelegationLock, waitForDelegationLock, SHARED_AGENT_INSTRUCTIONS, INTEGRATION_SESSION_RETRY_MS, INTEGRATION_SESSION_RETRIES, HEALTH_STALE_AFTER_MS, HEALTH_STALE_SCAN_MS, HEALTH_STALE_DIAGNOSTIC_TIMEOUT_MS, HEALTH_STALE_DIAGNOSTIC_LINES, HEALTH_ATTENTION_REPEAT_MIN_MS, HEALTH_ATTENTION_FIRST_REPEAT_MS, AGENT_LABEL_PATTERN, validAgentLabel, modelToken, messageLimits, AGENT_DEFINITION_ENTRY, AGENT_EXECUTION_OWNERSHIP_GUIDANCE, AGENT_UNRESOLVED_NAVIGATION_GUIDANCE, AGENT_UNRESOLVED_GUIDANCE, AGENT_DELEGATION_GUIDANCE, AGENT_HANDOFF_GUIDANCE, LEAD_SCOPE_DESCRIPTION, DELEGATING_AGENT_SCOPE_DESCRIPTION, STOP_CLOSURE_ENTRY, ACCEPTED_ASSIGNMENT_ENTRY, RESULT_REF_ENTRY, TRANSCRIPT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_OMISSION;
22454
+ var delegationLockPath, claimDelegationLock, waitForDelegationLock, AUTHORITY_GUIDANCE, SHARED_AGENT_INSTRUCTIONS, INTEGRATION_SESSION_RETRY_MS, INTEGRATION_SESSION_RETRIES, HEALTH_STALE_AFTER_MS, HEALTH_STALE_SCAN_MS, HEALTH_STALE_DIAGNOSTIC_TIMEOUT_MS, HEALTH_STALE_DIAGNOSTIC_LINES, HEALTH_ATTENTION_REPEAT_MIN_MS, HEALTH_ATTENTION_FIRST_REPEAT_MS, AGENT_LABEL_PATTERN, validAgentLabel, modelToken, messageLimits, AGENT_DEFINITION_ENTRY, AGENT_EXECUTION_OWNERSHIP_GUIDANCE, AGENT_UNRESOLVED_NAVIGATION_GUIDANCE, AGENT_UNRESOLVED_GUIDANCE, AGENT_DELEGATION_GUIDANCE, AGENT_HANDOFF_GUIDANCE, LEAD_SCOPE_DESCRIPTION, DELEGATING_AGENT_SCOPE_DESCRIPTION, STOP_CLOSURE_ENTRY, ACCEPTED_ASSIGNMENT_ENTRY, RESULT_REF_ENTRY, TRANSCRIPT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_OMISSION;
22444
22455
  var init_agent_controller = __esm({
22445
22456
  "extension/agent-controller.ts"() {
22446
22457
  "use strict";
@@ -22498,7 +22509,16 @@ var init_agent_controller = __esm({
22498
22509
  }
22499
22510
  }
22500
22511
  };
22501
- SHARED_AGENT_INSTRUCTIONS = `Work only on the assigned objective and preserve its stated scope, constraints,
22512
+ AUTHORITY_GUIDANCE = `The human user has the final say on decisions within their authority.
22513
+
22514
+ Respect the authority hierarchy within verified supervision and ownership boundaries: Human > Chief > Manager > Lead > Agent. Higher-level decisions take precedence over subordinate judgment, preferences, and defaults. Agents may advise but must follow applicable decisions.
22515
+
22516
+ Authority flows through the responsible direct supervisor or owner. Higher rank does not grant additional capabilities, ownership, or permission to cross role or assignment boundaries.
22517
+
22518
+ When unable to follow an instruction, identify the specific applicable constraint. Never invent restrictions or elevate conventions, recommendations, or personal judgment into binding requirements.`;
22519
+ SHARED_AGENT_INSTRUCTIONS = `${AUTHORITY_GUIDANCE}
22520
+
22521
+ Work only on the assigned objective and preserve its stated scope, constraints,
22502
22522
  authority, and acceptance criteria.
22503
22523
 
22504
22524
  Treat supplied files as message evidence. Explicit Agent attachments must contain
@@ -25871,7 +25891,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
25871
25891
  // package.json
25872
25892
  var package_default = {
25873
25893
  name: "pi-herdsman",
25874
- version: "0.49.0",
25894
+ version: "0.50.0",
25875
25895
  type: "module",
25876
25896
  description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
25877
25897
  license: "Apache-2.0",
@@ -27367,58 +27387,127 @@ Type forget ${branch} to confirm.`,
27367
27387
  )
27368
27388
  );
27369
27389
  };
27370
- const setRemovalPreauthorization = async (enabled, ctx) => {
27371
- const manager = await host.currentManager(ctx);
27372
- if (host.activeRole() !== "manager" || !manager || !ctx.hasUI)
27390
+ const sameRepositorySettingsIdentity = (a, b) => a.repoKey === b.repoKey && a.checkoutPath === b.checkoutPath && a.isPrimary === b.isPrimary && a.workspaceId === b.workspaceId && a.paneId === b.paneId && a.tabId === b.tabId && a.cwd === b.cwd && a.sessionId === b.sessionId && a.sessionFile === b.sessionFile;
27391
+ const repositorySettingsIdentity = async (ctx) => {
27392
+ const workspaceId = process.env.HERDR_WORKSPACE_ID;
27393
+ const paneId = process.env.HERDR_PANE_ID;
27394
+ const tabId = process.env.HERDR_TAB_ID;
27395
+ const sessionId = ctx.sessionManager.getSessionId();
27396
+ const sessionFile = ctx.sessionManager.getSessionFile();
27397
+ const cwd = ctx.cwd;
27398
+ if (!workspaceId || !paneId || !tabId || !sessionId)
27373
27399
  throw new Error(
27374
- "Only an interactive active Manager can change this setting"
27400
+ "Verified workspace, pane, tab and session identity are required"
27375
27401
  );
27376
- const group = await host.worktreeGroupScope(
27377
- host.pi,
27378
- ctx,
27379
- manager.workspaceId,
27380
- ctx.signal
27402
+ const agent = await verifiedHerdrAgent(
27403
+ {
27404
+ piSessionId: sessionId,
27405
+ piSessionFile: sessionFile,
27406
+ workspaceId,
27407
+ paneId,
27408
+ tabId
27409
+ },
27410
+ {
27411
+ listAgents: async () => (await host.listAgents(ctx)).agents,
27412
+ getAgent: async (id) => (await host.runHerdr(host.pi, ctx, ["agent", "get", id], {
27413
+ signal: ctx.signal
27414
+ }))?.agent,
27415
+ expectedSession: host.expectedSession,
27416
+ isPiAgent: host.isPiAgent,
27417
+ matchesExpectedSession
27418
+ }
27381
27419
  );
27382
- if (group.repoKey !== manager.repoKey)
27383
- throw new Error("Manager worktree group is not authoritative");
27384
- if (enabled) {
27385
- const answer = await ctx.ui.input(
27386
- `Skip worktree removal confirmation for this verified repository?
27387
-
27388
- ${manager.repoKey}
27389
-
27390
- Subsequent explicitly requested removals here can proceed without a per-removal prompt. All safety checks remain active. Type enable to confirm.`,
27391
- void 0,
27392
- { signal: ctx.signal }
27420
+ if (!agent)
27421
+ throw new Error(
27422
+ "Herdr session-to-workspace identity is unavailable or conflicting"
27393
27423
  );
27394
- if (answer !== "enable") return false;
27395
- }
27396
- const current = await host.currentManager(ctx);
27397
- if (!current || !host.sameManagerDescriptor(current, manager))
27398
- throw new Error("Manager authority changed before saving the setting");
27399
- setWorktreeRemovalPreapproved(manager.repoKey, enabled);
27400
- return isWorktreeRemovalPreapproved(manager.repoKey) === enabled;
27401
- };
27402
- const getRemovalPreauthorization = async (ctx) => {
27403
- const manager = await host.currentManager(ctx);
27404
- if (host.activeRole() !== "manager" || !manager)
27405
- throw new Error("Only the active Manager can inspect this setting");
27406
- const group = await host.worktreeGroupScope(
27424
+ const scope = await (host.localRepositoryScope ?? localRepositoryScope)(
27407
27425
  host.pi,
27408
27426
  ctx,
27409
- manager.workspaceId,
27427
+ workspaceId,
27410
27428
  ctx.signal
27411
27429
  );
27412
- if (group.repoKey !== manager.repoKey)
27413
- throw new Error("Manager worktree group is not authoritative");
27414
- const current = await host.currentManager(ctx);
27415
- if (!current || !host.sameManagerDescriptor(current, manager))
27416
- throw new Error("Manager authority changed while reading this setting");
27430
+ if (workspaceId !== process.env.HERDR_WORKSPACE_ID || paneId !== process.env.HERDR_PANE_ID || tabId !== process.env.HERDR_TAB_ID || sessionId !== ctx.sessionManager.getSessionId() || sessionFile !== ctx.sessionManager.getSessionFile() || cwd !== ctx.cwd)
27431
+ throw new Error("Session context changed while verifying repository");
27432
+ return {
27433
+ ...scope,
27434
+ workspaceId,
27435
+ paneId,
27436
+ tabId,
27437
+ sessionId,
27438
+ sessionFile,
27439
+ cwd
27440
+ };
27441
+ };
27442
+ const revalidateRepositorySettings = async (ctx, expected) => {
27443
+ const current = await repositorySettingsIdentity(ctx);
27444
+ ctx.signal?.throwIfAborted();
27445
+ if (!ctx.hasUI)
27446
+ throw new Error("Interactive session is no longer available");
27447
+ if (!sameRepositorySettingsIdentity(current, expected))
27448
+ throw new Error("Repository or session changed; reopen the selector");
27449
+ };
27450
+ const getRemovalPreauthorization = async (ctx) => {
27451
+ const identity = await repositorySettingsIdentity(ctx);
27417
27452
  return {
27418
- repoKey: manager.repoKey,
27419
- enabled: isWorktreeRemovalPreapproved(manager.repoKey)
27453
+ identity,
27454
+ repoKey: identity.repoKey,
27455
+ enabled: isWorktreeRemovalPreapproved(identity.repoKey)
27420
27456
  };
27421
27457
  };
27458
+ const setRemovalPreauthorization = async (enabled, ctx, expectedIdentity) => {
27459
+ if (!ctx.hasUI)
27460
+ throw new Error(
27461
+ "An interactive user is required to change repository settings"
27462
+ );
27463
+ const identity = await repositorySettingsIdentity(ctx);
27464
+ if (expectedIdentity && !sameRepositorySettingsIdentity(identity, expectedIdentity))
27465
+ throw new Error("Repository or session changed; reopen the selector");
27466
+ const previous = isWorktreeRemovalPreapproved(identity.repoKey);
27467
+ if (enabled && !previous) {
27468
+ const confirmed = await ctx.ui.confirm(
27469
+ "Allow worktree removal without individual approval?",
27470
+ [
27471
+ `Repository: ${identity.repoKey}`,
27472
+ "",
27473
+ "The Manager may execute explicitly requested, eligible",
27474
+ "worktree removals without asking again.",
27475
+ "Existing safety checks remain active."
27476
+ ].join("\n"),
27477
+ { signal: ctx.signal }
27478
+ );
27479
+ if (!confirmed) return false;
27480
+ }
27481
+ await revalidateRepositorySettings(ctx, identity);
27482
+ if (isWorktreeRemovalPreapproved(identity.repoKey) !== previous)
27483
+ throw new Error("Removal policy changed before saving the setting");
27484
+ if (previous !== enabled)
27485
+ setWorktreeRemovalPreapproved(identity.repoKey, enabled, previous);
27486
+ return true;
27487
+ };
27488
+ const setRepositoryMergeOverride = async (enabled, ctx, expectedIdentity, expected) => {
27489
+ if (!ctx.hasUI)
27490
+ throw new Error(
27491
+ "An interactive user is required to change repository settings"
27492
+ );
27493
+ const identity = await repositorySettingsIdentity(ctx);
27494
+ if (!sameRepositorySettingsIdentity(identity, expectedIdentity))
27495
+ throw new Error("Repository or session changed; reopen the selector");
27496
+ const level = (value2) => value2 === false ? 0 : value2 === true ? 1 : 2;
27497
+ const previous = expected.override ?? expected.global;
27498
+ const next = enabled ?? expected.global;
27499
+ if (next !== false && (level(next) > level(previous) || enabled !== void 0 && expected.override === void 0)) {
27500
+ const confirmed = await ctx.ui.confirm(
27501
+ `Allow Manager integration for ${identity.repoKey}?`,
27502
+ next === "divergent" ? "Allow conflict-free divergent merges? Git may create a merge commit and verified integration may automatically remove the exact source worktree." : "Allow fast-forward integration and automatic cleanup of successfully integrated source worktrees?",
27503
+ { signal: ctx.signal }
27504
+ );
27505
+ if (!confirmed) return false;
27506
+ }
27507
+ await revalidateRepositorySettings(ctx, identity);
27508
+ setManagerMergeOverride(identity.repoKey, enabled, expected);
27509
+ return true;
27510
+ };
27422
27511
  const {
27423
27512
  pi,
27424
27513
  leadRuntime,
@@ -30333,6 +30422,7 @@ ${(updated.requiredEvidence ?? []).map((entry) => `- ${entry.id}: ${entry.name}`
30333
30422
  cancelPendingRemoval,
30334
30423
  setRemovalPreauthorization,
30335
30424
  getRemovalPreauthorization,
30425
+ setRepositoryMergeOverride,
30336
30426
  forgetLegacyProjectAssignment,
30337
30427
  executeStaff,
30338
30428
  updateAssignmentEvidence,
@@ -30452,6 +30542,17 @@ import {
30452
30542
  getSupportedThinkingLevels
30453
30543
  } from "@earendil-works/pi-ai";
30454
30544
  function createLeadCommandRuntime(host) {
30545
+ const confirmMergeGrant = (ctx, setting, scope) => ctx.ui.confirm(
30546
+ `Allow Manager integration for ${scope}?`,
30547
+ setting === "divergent" ? "Allow conflict-free divergent merges? Git may create a merge commit and verified integration may automatically remove the exact source worktree." : "Allow fast-forward integration and automatic cleanup of successfully integrated source worktrees?",
30548
+ { signal: ctx.signal }
30549
+ );
30550
+ const markCurrent = (items, current) => items.map(
30551
+ (item) => item.value === current ? {
30552
+ ...item,
30553
+ description: item.description ? `${item.description} \xB7 current` : "current"
30554
+ } : item
30555
+ );
30455
30556
  const modelToken2 = (model) => `${model.provider}/${model.id}`;
30456
30557
  return {
30457
30558
  async openPlacementMenu(ctx) {
@@ -30481,7 +30582,7 @@ function createLeadCommandRuntime(host) {
30481
30582
  ],
30482
30583
  current.effective
30483
30584
  );
30484
- if (!selected) return;
30585
+ if (!selected || selected === current.effective) return;
30485
30586
  host.updateSpawnPlacement(selected);
30486
30587
  const verified = await host.placementSettings(ctx);
30487
30588
  if (verified.effective !== selected)
@@ -30519,22 +30620,35 @@ function createLeadCommandRuntime(host) {
30519
30620
  );
30520
30621
  if (!setting) return;
30521
30622
  selectedLimit = setting;
30522
- const choice = await host.selectMenu(ctx, "Limit", [
30523
- ...presets.map(({ label, bytes }) => ({
30524
- value: String(bytes),
30525
- label
30526
- })),
30527
- {
30528
- value: "custom",
30529
- label: "Custom\u2026",
30530
- help: "Enter a custom limit in KiB, from 1 through 1024."
30531
- },
30532
- {
30533
- value: "reset",
30534
- label: "Reset",
30535
- help: "Remove the configured override and use the default."
30536
- }
30537
- ]);
30623
+ const currentBytes = setting === "inlineAttachmentLimitBytes" ? limits.inline.bytes : limits.mailbox.bytes;
30624
+ const currentChoice = presets.some(
30625
+ ({ bytes }) => bytes === currentBytes
30626
+ ) ? String(currentBytes) : "custom";
30627
+ const choice = await host.selectMenu(
30628
+ ctx,
30629
+ "Limit",
30630
+ markCurrent(
30631
+ [
30632
+ ...presets.map(({ label, bytes }) => ({
30633
+ value: String(bytes),
30634
+ label
30635
+ })),
30636
+ {
30637
+ value: "custom",
30638
+ label: "Custom\u2026",
30639
+ description: currentChoice === "custom" ? host.formatMessageLimit(currentBytes) : void 0,
30640
+ help: "Enter a custom limit in KiB, from 1 through 1024."
30641
+ },
30642
+ {
30643
+ value: "reset",
30644
+ label: "Reset",
30645
+ help: "Remove the configured override and use the default."
30646
+ }
30647
+ ],
30648
+ currentChoice
30649
+ ),
30650
+ currentChoice
30651
+ );
30538
30652
  if (!choice) continue;
30539
30653
  let value2;
30540
30654
  if (choice === "reset") value2 = void 0;
@@ -30548,6 +30662,7 @@ function createLeadCommandRuntime(host) {
30548
30662
  }
30549
30663
  value2 = kib * 1024;
30550
30664
  } else value2 = Number(choice);
30665
+ if (value2 !== void 0 && value2 === currentBytes) continue;
30551
30666
  host.updateMessageLimit(selectedLimit, value2);
30552
30667
  ctx.ui.notify(
30553
30668
  `${selectedLimit}: ${value2 === void 0 ? "reset" : host.formatMessageLimit(value2)}`
@@ -30571,7 +30686,7 @@ function createLeadCommandRuntime(host) {
30571
30686
  );
30572
30687
  return compactMatches.length === 1 ? compactMatches[0] : void 0;
30573
30688
  },
30574
- async openDefinitionsMenu(ctx) {
30689
+ async openDefinitionsMenu(ctx, initialSection) {
30575
30690
  let selectedSection = "agents";
30576
30691
  const selectedDefinitions = {};
30577
30692
  const loadDefinitions = async (section, includeProject = true, onWarning) => section === "agents" ? (await host.contextAgentDefinitions(ctx, onWarning)).definitions : discoverRoleDefinitions({
@@ -30588,18 +30703,18 @@ function createLeadCommandRuntime(host) {
30588
30703
  return loaded.find((candidate) => candidate.name === name);
30589
30704
  };
30590
30705
  while (true) {
30591
- const section = await host.selectMenu(
30706
+ const section = initialSection ?? await host.selectMenu(
30592
30707
  ctx,
30593
30708
  "Agents & Coordinators",
30594
30709
  [
30595
30710
  {
30596
30711
  value: "agents",
30597
- label: "Agents",
30712
+ label: "Agent definitions",
30598
30713
  help: "Definitions available for Agent delegation."
30599
30714
  },
30600
30715
  {
30601
30716
  value: "roles",
30602
- label: "Coordinators",
30717
+ label: "Coordinator profiles",
30603
30718
  help: "Profiles for existing Lead, Manager, and Chief roles; these do not grant authority."
30604
30719
  }
30605
30720
  ],
@@ -31135,6 +31250,7 @@ function createLeadCommandRuntime(host) {
31135
31250
  definition = verified;
31136
31251
  }
31137
31252
  }
31253
+ if (initialSection) return;
31138
31254
  }
31139
31255
  },
31140
31256
  async openRunningAgentsMenu(ctx) {
@@ -31286,7 +31402,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31286
31402
  }
31287
31403
  const mode = await host.selectMenu(
31288
31404
  ctx,
31289
- "Execution",
31405
+ "Lead mode",
31290
31406
  [
31291
31407
  {
31292
31408
  value: "flexible",
@@ -31310,7 +31426,25 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31310
31426
  }
31311
31427
  },
31312
31428
  async openSettingsMenu(ctx) {
31313
- let selectedSetting = "auto-activate-manager";
31429
+ let selectedCategory = "sessions";
31430
+ while (true) {
31431
+ const category = await host.selectMenu(
31432
+ ctx,
31433
+ "Settings",
31434
+ [
31435
+ { value: "sessions", label: "Sessions & agents" },
31436
+ { value: "manager", label: "Manager & repositories" },
31437
+ { value: "interface", label: "Interface" }
31438
+ ],
31439
+ selectedCategory
31440
+ );
31441
+ if (!category) return;
31442
+ selectedCategory = category;
31443
+ await this.openSettingsCategory(ctx, category);
31444
+ }
31445
+ },
31446
+ async openSettingsCategory(ctx, category) {
31447
+ let selectedSetting = category === "sessions" ? "default-lead-execution" : category === "manager" ? "auto-activate-manager" : "agent-layout";
31314
31448
  const loadProjectState = () => {
31315
31449
  if (!ctx.isProjectTrusted())
31316
31450
  return { trusted: false, overrides: {} };
@@ -31330,14 +31464,36 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31330
31464
  while (true) {
31331
31465
  const config = host.readConfig();
31332
31466
  const project = loadProjectState();
31467
+ let repository;
31468
+ if (category === "manager") {
31469
+ try {
31470
+ repository = await host.getRemovalPreauthorization(ctx);
31471
+ } catch {
31472
+ }
31473
+ }
31474
+ const merge = repository ? effectiveMergePolicy(config, repository.repoKey) : void 0;
31475
+ let messageSummary;
31476
+ if (category === "sessions") {
31477
+ try {
31478
+ const limits = await host.messageLimits(ctx);
31479
+ messageSummary = `Inline ${host.formatMessageLimit(limits.inline.bytes)} \xB7 mailbox ${host.formatMessageLimit(limits.mailbox.bytes)}`;
31480
+ } catch {
31481
+ messageSummary = "Unavailable";
31482
+ }
31483
+ }
31333
31484
  const projectDescription = (key) => !project.trusted ? `Effective ${config[key] ? "on" : "off"} (global; untrusted project)` : "error" in project ? "Project value unavailable" : `Effective ${(Object.hasOwn(project.overrides, key) ? project.overrides[key] : config[key]) ? "on" : "off"}${Object.hasOwn(project.overrides, key) ? " (project)" : " (global)"}`;
31334
31485
  const selected = await host.selectMenu(
31335
31486
  ctx,
31336
- "Settings",
31487
+ category === "sessions" ? "Sessions & agents" : category === "manager" ? "Manager & repositories" : "Interface",
31337
31488
  [
31489
+ {
31490
+ value: "agent-layout",
31491
+ label: "Agent pane layout",
31492
+ description: category === "interface" ? (await host.placementSettings(ctx)).effective : void 0
31493
+ },
31338
31494
  {
31339
31495
  value: "default-lead-execution",
31340
- label: "Default Lead execution",
31496
+ label: "Default Lead mode",
31341
31497
  description: config.defaultLeadExecution,
31342
31498
  help: "Used when a future ordinary Lead session has no persisted execution choice."
31343
31499
  },
@@ -31349,8 +31505,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31349
31505
  },
31350
31506
  {
31351
31507
  value: "manager-git-bootstrap-confirmation",
31352
- label: "Skip Manager Git setup confirmation",
31353
- description: `Global ${config.managerGitBootstrapWithoutConfirmation ? "on" : "off"}`,
31508
+ label: "Git initialization prompt",
31509
+ description: config.managerGitBootstrapWithoutConfirmation ? "Skipped" : "Required",
31354
31510
  help: "Automatically initialize a non-Git workspace when Manager is started explicitly. Off by default."
31355
31511
  },
31356
31512
  {
@@ -31361,8 +31517,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31361
31517
  },
31362
31518
  {
31363
31519
  value: "manager-merge",
31364
- label: "Manager local merge",
31365
- description: `Global ${config.managerMergeEnabled === "divergent" ? "conflict-free merges" : config.managerMergeEnabled ? "fast-forward only" : "off"}`,
31520
+ label: "Local branch integration",
31521
+ description: merge ? `${!merge.enabled ? "Off" : merge.allowDivergence ? "Conflict-free merges" : "Fast-forward"} (${merge.source})` : "Repository unavailable",
31366
31522
  help: "Choose whether Managers may integrate accepted local branches only by fast-forward or also by clean divergent merge, with guarded cleanup."
31367
31523
  },
31368
31524
  {
@@ -31373,41 +31529,96 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31373
31529
  },
31374
31530
  {
31375
31531
  value: "max-agent-depth",
31376
- label: "Max Agent depth",
31532
+ label: "Maximum delegation depth",
31377
31533
  description: String(config.maxAgentDepth),
31378
31534
  help: "Longest chain of nested Agents below the Lead, Manager or Chief (1 = Agents never delegate). Global only; checked at each launch. Existing Agents stay manageable when it is lowered."
31379
31535
  },
31380
31536
  {
31381
31537
  value: "message-limits",
31382
- label: "Message limits",
31538
+ label: "Message size limits",
31539
+ description: messageSummary,
31383
31540
  help: "Configure inline attachment and managed mailbox payload byte limits."
31384
31541
  },
31385
31542
  {
31386
- value: "project-overrides",
31387
- label: "Project overrides\u2026",
31388
- help: "Choose project-specific values for Manager auto-start and context retirement."
31543
+ value: "removal-confirmation",
31544
+ label: "Worktree removal approval",
31545
+ description: repository ? `${repository.enabled ? "Skipped" : "Required"} (repository)` : "Repository unavailable"
31389
31546
  }
31390
- ],
31547
+ ].filter(
31548
+ (item) => (category === "sessions" ? [
31549
+ "default-lead-execution",
31550
+ "context-retirement",
31551
+ "max-agent-depth",
31552
+ "message-limits"
31553
+ ] : category === "manager" ? [
31554
+ "auto-activate-manager",
31555
+ "manager-git-bootstrap-confirmation",
31556
+ "manager-merge",
31557
+ "removal-confirmation"
31558
+ ] : ["agent-layout", "status-widget-rows"]).includes(item.value)
31559
+ ),
31391
31560
  selectedSetting
31392
31561
  );
31393
31562
  if (!selected) return;
31394
31563
  selectedSetting = selected;
31395
- if (selected === "project-overrides") {
31396
- await this.openProjectOverridesMenu(ctx);
31564
+ if (selected === "agent-layout") {
31565
+ await this.openPlacementMenu(ctx);
31566
+ } else if (selected === "manager-git-bootstrap-confirmation") {
31567
+ const choice = await host.selectMenu(
31568
+ ctx,
31569
+ "Manager Git setup prompt",
31570
+ markCurrent(
31571
+ [
31572
+ { value: "required", label: "Require confirmation" },
31573
+ {
31574
+ value: "skip",
31575
+ label: "Skip confirmation on explicit Manager start"
31576
+ }
31577
+ ],
31578
+ config.managerGitBootstrapWithoutConfirmation ? "skip" : "required"
31579
+ ),
31580
+ config.managerGitBootstrapWithoutConfirmation ? "skip" : "required"
31581
+ );
31582
+ if (choice && choice === "skip" !== config.managerGitBootstrapWithoutConfirmation) {
31583
+ if (choice === "skip" && !await ctx.ui.confirm(
31584
+ "Skip Manager Git setup confirmation?",
31585
+ "Explicit Manager activation may initialize a non-Git workspace without asking again.",
31586
+ { signal: ctx.signal }
31587
+ ))
31588
+ continue;
31589
+ if (ctx.signal?.aborted) continue;
31590
+ host.updateConfig(
31591
+ "managerGitBootstrapWithoutConfirmation",
31592
+ choice === "skip"
31593
+ );
31594
+ }
31397
31595
  } else if (selected === "status-widget-rows") {
31398
31596
  while (true) {
31399
- const choice = await host.selectMenu(ctx, "Status widget rows", [
31400
- {
31401
- value: "default",
31402
- label: `Default (${DEFAULT_STATUS_WIDGET_MAX_ROWS})`
31403
- },
31404
- ...[3, 5, 8, 12, 20].map((rows) => ({
31405
- value: String(rows),
31406
- label: String(rows)
31407
- })),
31408
- { value: "custom", label: "Custom\u2026" },
31409
- { value: "reset", label: "Reset" }
31410
- ]);
31597
+ const currentChoice = config.statusWidgetMaxRows === DEFAULT_STATUS_WIDGET_MAX_ROWS ? "default" : [3, 5, 8, 12, 20].includes(config.statusWidgetMaxRows) ? String(config.statusWidgetMaxRows) : "custom";
31598
+ const choice = await host.selectMenu(
31599
+ ctx,
31600
+ "Status widget rows",
31601
+ markCurrent(
31602
+ [
31603
+ {
31604
+ value: "default",
31605
+ label: `Default (${DEFAULT_STATUS_WIDGET_MAX_ROWS})`
31606
+ },
31607
+ ...[3, 5, 8, 12, 20].map((rows) => ({
31608
+ value: String(rows),
31609
+ label: String(rows)
31610
+ })),
31611
+ {
31612
+ value: "custom",
31613
+ label: "Custom\u2026",
31614
+ description: currentChoice === "custom" ? String(config.statusWidgetMaxRows) : void 0
31615
+ },
31616
+ { value: "reset", label: "Reset" }
31617
+ ],
31618
+ currentChoice
31619
+ ),
31620
+ currentChoice
31621
+ );
31411
31622
  if (!choice) break;
31412
31623
  let value2;
31413
31624
  if (choice === "reset") value2 = void 0;
@@ -31424,6 +31635,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31424
31635
  }
31425
31636
  } else
31426
31637
  value2 = choice === "default" ? DEFAULT_STATUS_WIDGET_MAX_ROWS : Number(choice);
31638
+ if (value2 !== void 0 && value2 === config.statusWidgetMaxRows)
31639
+ break;
31427
31640
  try {
31428
31641
  host.updateConfig("statusWidgetMaxRows", value2);
31429
31642
  ctx.ui.notify(
@@ -31439,18 +31652,31 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31439
31652
  }
31440
31653
  } else if (selected === "max-agent-depth") {
31441
31654
  while (true) {
31442
- const choice = await host.selectMenu(ctx, "Max Agent depth", [
31443
- {
31444
- value: "default",
31445
- label: `Default (${DEFAULT_MAX_AGENT_DEPTH})`
31446
- },
31447
- ...[1, 2, 3, 4, 5].map((depth) => ({
31448
- value: String(depth),
31449
- label: String(depth)
31450
- })),
31451
- { value: "custom", label: "Custom\u2026" },
31452
- { value: "reset", label: "Reset" }
31453
- ]);
31655
+ const currentChoice = config.maxAgentDepth === DEFAULT_MAX_AGENT_DEPTH ? "default" : [1, 2, 3, 4, 5].includes(config.maxAgentDepth) ? String(config.maxAgentDepth) : "custom";
31656
+ const choice = await host.selectMenu(
31657
+ ctx,
31658
+ "Max Agent depth",
31659
+ markCurrent(
31660
+ [
31661
+ {
31662
+ value: "default",
31663
+ label: `Default (${DEFAULT_MAX_AGENT_DEPTH})`
31664
+ },
31665
+ ...[1, 2, 3, 4, 5].map((depth) => ({
31666
+ value: String(depth),
31667
+ label: String(depth)
31668
+ })),
31669
+ {
31670
+ value: "custom",
31671
+ label: "Custom\u2026",
31672
+ description: currentChoice === "custom" ? String(config.maxAgentDepth) : void 0
31673
+ },
31674
+ { value: "reset", label: "Reset" }
31675
+ ],
31676
+ currentChoice
31677
+ ),
31678
+ currentChoice
31679
+ );
31454
31680
  if (!choice) break;
31455
31681
  let value2;
31456
31682
  if (choice === "reset") value2 = void 0;
@@ -31467,6 +31693,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31467
31693
  }
31468
31694
  } else
31469
31695
  value2 = choice === "default" ? DEFAULT_MAX_AGENT_DEPTH : Number(choice);
31696
+ if (value2 !== void 0 && value2 === config.maxAgentDepth) break;
31470
31697
  try {
31471
31698
  host.updateConfig("maxAgentDepth", value2);
31472
31699
  ctx.ui.notify(
@@ -31486,251 +31713,283 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31486
31713
  const mode = await host.selectMenu(
31487
31714
  ctx,
31488
31715
  "Default Lead execution",
31489
- [
31490
- { value: "flexible", label: "flexible" },
31491
- { value: "orchestrate", label: "orchestrate" }
31492
- ],
31716
+ markCurrent(
31717
+ [
31718
+ { value: "flexible", label: "flexible" },
31719
+ { value: "orchestrate", label: "orchestrate" }
31720
+ ],
31721
+ config.defaultLeadExecution
31722
+ ),
31493
31723
  config.defaultLeadExecution
31494
31724
  );
31495
- if (mode) host.updateConfig("defaultLeadExecution", mode);
31496
- } else if (selected === "context-retirement" || selected === "auto-activate-manager" || selected === "manager-git-bootstrap-confirmation") {
31497
- const key = selected === "context-retirement" ? "contextRetirement" : selected === "auto-activate-manager" ? "autoActivateManager" : "managerGitBootstrapWithoutConfirmation";
31498
- const enabled = !host.readConfig()[key];
31499
- host.updateConfig(key, enabled);
31500
- ctx.ui.notify(
31501
- `Global ${key === "contextRetirement" ? "context retirement" : key === "autoActivateManager" ? "Manager auto-start" : "Manager Git setup confirmation skip"}: ${enabled ? "on" : "off"}`
31502
- );
31503
- } else if (selected === "manager-merge") {
31504
- const current = host.readConfig().managerMergeEnabled;
31505
- const choice = await host.selectMenu(
31506
- ctx,
31507
- "Global Manager local merge",
31508
- [
31509
- { value: "off", label: "Off" },
31510
- { value: "fast-forward", label: "Fast-forward only" },
31511
- { value: "divergent", label: "Conflict-free merges" }
31512
- ],
31513
- current === false ? "off" : current === true ? "fast-forward" : "divergent"
31514
- );
31515
- if (!choice) continue;
31516
- const setting = choice === "off" ? false : choice === "fast-forward" ? true : "divergent";
31517
- if (setting !== false && (current === false || setting === "divergent" && current !== "divergent")) {
31518
- const confirm = await ctx.ui.input(
31519
- setting === "divergent" ? "Enable conflict-free divergent Manager merges? Git may create a new merge commit, and successful integration can automatically remove the exact source worktree. Type enable to confirm." : "Enable fast-forward Manager integration and automatic cleanup of successfully integrated source worktrees. Type enable to confirm.",
31520
- void 0
31521
- );
31522
- if (confirm !== "enable") continue;
31725
+ if (mode && mode !== config.defaultLeadExecution) {
31726
+ host.updateConfig("defaultLeadExecution", mode);
31727
+ ctx.ui.notify(`Default Lead mode: ${mode}`);
31523
31728
  }
31524
- host.updateConfig("managerMergeEnabled", setting);
31525
- ctx.ui.notify(
31526
- `Global Manager local merge: ${setting === "divergent" ? "conflict-free merges" : setting ? "fast-forward only" : "off"}`
31729
+ } else if (selected === "context-retirement" || selected === "auto-activate-manager") {
31730
+ await this.openProjectSetting(
31731
+ ctx,
31732
+ selected === "context-retirement" ? "contextRetirement" : "autoActivateManager"
31527
31733
  );
31734
+ } else if (selected === "manager-merge") {
31735
+ await this.openMergeSetting(ctx);
31736
+ } else if (selected === "removal-confirmation") {
31737
+ await this.openRemovalSetting(ctx);
31528
31738
  }
31529
31739
  }
31530
31740
  },
31531
- async openProjectOverridesMenu(ctx) {
31741
+ async openProjectSetting(ctx, key) {
31742
+ const title = key === "autoActivateManager" ? "Manager auto-start" : "Context retirement";
31743
+ let selectedScope = "global";
31532
31744
  while (true) {
31745
+ const global2 = host.readConfig()[key];
31533
31746
  let overrides;
31534
- let overrideError;
31535
- if (ctx.isProjectTrusted()) {
31747
+ let unavailable;
31748
+ if (!ctx.isProjectTrusted()) unavailable = "Project is not trusted";
31749
+ else
31536
31750
  try {
31537
31751
  overrides = host.readProjectOverrides(ctx);
31538
31752
  } catch (error2) {
31539
- overrideError = error2;
31753
+ unavailable = `Project settings unavailable: ${String(error2).replace(/^Error: /, "")}`;
31540
31754
  }
31755
+ const projectValue = overrides && Object.hasOwn(overrides, key) ? overrides[key] : void 0;
31756
+ const scope = await host.selectMenu(
31757
+ ctx,
31758
+ title,
31759
+ [
31760
+ {
31761
+ value: "global",
31762
+ label: "Global default",
31763
+ description: global2 ? "On" : "Off"
31764
+ },
31765
+ {
31766
+ value: "project",
31767
+ label: "Current project",
31768
+ description: unavailable ?? (projectValue === void 0 ? `Inherit global (${global2 ? "on" : "off"})` : projectValue ? "On" : "Off")
31769
+ }
31770
+ ],
31771
+ selectedScope
31772
+ );
31773
+ if (!scope) return;
31774
+ selectedScope = scope;
31775
+ if (scope === "project" && unavailable) {
31776
+ ctx.ui.notify(unavailable, "warning");
31777
+ continue;
31541
31778
  }
31542
- let removalPolicy;
31543
- try {
31544
- removalPolicy = await host.getRemovalPreauthorization(ctx);
31545
- } catch {
31546
- }
31547
- let mergePolicy;
31779
+ const currentChoice = scope === "global" ? global2 ? "on" : "off" : projectValue === void 0 ? "inherit" : projectValue ? "on" : "off";
31780
+ const choice = await host.selectMenu(
31781
+ ctx,
31782
+ scope === "global" ? `Global ${title}` : `Project ${title}`,
31783
+ markCurrent(
31784
+ [
31785
+ ...scope === "project" ? [
31786
+ {
31787
+ value: "inherit",
31788
+ label: `Inherit global (${global2 ? "on" : "off"})`
31789
+ }
31790
+ ] : [],
31791
+ { value: "on", label: "On" },
31792
+ { value: "off", label: "Off" }
31793
+ ],
31794
+ currentChoice
31795
+ ),
31796
+ currentChoice
31797
+ );
31798
+ if (!choice) continue;
31799
+ const value2 = choice === "inherit" ? void 0 : choice === "on";
31548
31800
  try {
31549
- const manager = await host.getRemovalPreauthorization(ctx);
31550
- const policy = effectiveMergePolicy(
31551
- host.readConfig(),
31552
- manager.repoKey
31553
- );
31554
- mergePolicy = { repoKey: manager.repoKey, ...policy };
31555
- } catch {
31556
- }
31557
- if (!ctx.isProjectTrusted() && !removalPolicy) {
31801
+ if (scope === "global") {
31802
+ if (value2 === global2 || value2 === void 0) continue;
31803
+ host.updateConfig(key, value2);
31804
+ } else {
31805
+ if (value2 === projectValue) continue;
31806
+ host.updateProjectOverride(ctx, key, value2);
31807
+ }
31558
31808
  ctx.ui.notify(
31559
- "Project overrides are unavailable because this project is not trusted.",
31560
- "warning"
31809
+ `${title}: ${value2 === void 0 ? "inherited" : value2 ? "on" : "off"} (${scope}).`
31561
31810
  );
31562
- return;
31811
+ } catch (error2) {
31812
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31563
31813
  }
31564
- if (overrideError && !removalPolicy) {
31565
- ctx.ui.notify(String(overrideError).replace(/^Error: /, ""), "error");
31566
- return;
31814
+ }
31815
+ },
31816
+ async openMergeSetting(ctx) {
31817
+ let selectedScope = "global";
31818
+ while (true) {
31819
+ const config = host.readConfig();
31820
+ const global2 = config.managerMergeEnabled;
31821
+ let policy;
31822
+ let unavailable = "";
31823
+ try {
31824
+ policy = await host.getRemovalPreauthorization(ctx);
31825
+ } catch (error2) {
31826
+ unavailable = String(error2).replace(/^Error: /, "");
31567
31827
  }
31568
- const fields = [
31569
- ...ctx.isProjectTrusted() ? [
31828
+ const repositoryPolicy = policy ? effectiveMergePolicy(config, policy.repoKey) : void 0;
31829
+ const label = (value2) => value2 === false ? "Off" : value2 === true ? "Fast-forward" : "Conflict-free merges";
31830
+ const scope = await host.selectMenu(
31831
+ ctx,
31832
+ "Local branch integration",
31833
+ [
31570
31834
  {
31571
- value: "autoActivateManager",
31572
- label: "Manager auto-start",
31573
- help: "Attempt Manager mode automatically on eligible future session starts."
31835
+ value: "global",
31836
+ label: "Global default",
31837
+ description: label(global2)
31574
31838
  },
31575
31839
  {
31576
- value: "contextRetirement",
31577
- label: "Context retirement",
31578
- help: "Retire managed-Agent sessions at automatic context pressure."
31840
+ value: "repository",
31841
+ label: "Current repository",
31842
+ description: repositoryPolicy ? `${!repositoryPolicy.enabled ? "Off" : repositoryPolicy.allowDivergence ? "Conflict-free merges" : "Fast-forward"} (${repositoryPolicy.source})` : "Unavailable"
31579
31843
  }
31580
- ] : [],
31581
- ...removalPolicy ? [
31582
- {
31583
- value: "removal-confirmation",
31584
- label: `Worktree removal confirmation \xB7 ${removalPolicy.enabled ? "skip" : "required"}`,
31585
- help: `Controls confirmation for verified repository ${removalPolicy.repoKey}. Stored in user-level Herdsman authorization, not .pi/settings.json.`
31586
- }
31587
- ] : [],
31588
- ...mergePolicy ? [
31589
- {
31590
- value: "merge-permission",
31591
- label: `Manager local merge \xB7 ${!mergePolicy.enabled ? "off" : mergePolicy.allowDivergence ? "conflict-free merges" : "fast-forward only"} (${mergePolicy.source})`,
31592
- help: `Controls local integration and guarded cleanup for verified repository ${mergePolicy.repoKey}.`
31593
- }
31594
- ] : []
31595
- ];
31596
- const field = await host.selectMenu(ctx, "Project overrides", [
31597
- ...fields
31598
- ]);
31599
- if (!field) return;
31600
- if (field === "removal-confirmation") {
31601
- const policy = await host.getRemovalPreauthorization(ctx);
31844
+ ],
31845
+ selectedScope
31846
+ );
31847
+ if (!scope) return;
31848
+ selectedScope = scope;
31849
+ if (scope === "repository") {
31850
+ if (!policy || !repositoryPolicy) {
31851
+ ctx.ui.notify(`Repository unavailable: ${unavailable}`, "warning");
31852
+ continue;
31853
+ }
31854
+ const override = config.managerMergeOverrides[policy.repoKey];
31855
+ const currentChoice2 = override === void 0 ? "inherit" : override === false ? "off" : override === true ? "fast-forward" : "divergent";
31602
31856
  const choice2 = await host.selectMenu(
31603
31857
  ctx,
31604
- `Worktree removal \xB7 ${policy.repoKey}`,
31605
- [
31606
- { value: "required", label: "Require confirmation" },
31607
- {
31608
- value: "skip",
31609
- label: "Skip confirmation for this repository"
31610
- }
31611
- ],
31612
- policy.enabled ? "skip" : "required"
31858
+ `Local branch integration \xB7 ${policy.repoKey}`,
31859
+ markCurrent(
31860
+ [
31861
+ {
31862
+ value: "inherit",
31863
+ label: `Inherit global (${label(global2)})`
31864
+ },
31865
+ { value: "off", label: "Off" },
31866
+ { value: "fast-forward", label: "Fast-forward only" },
31867
+ { value: "divergent", label: "Conflict-free merges" }
31868
+ ],
31869
+ currentChoice2
31870
+ ),
31871
+ currentChoice2
31613
31872
  );
31614
- if (choice2 && choice2 === "skip" !== policy.enabled) {
31615
- const stored = await host.setRemovalPreauthorization(
31616
- choice2 === "skip",
31617
- ctx
31618
- );
31619
- ctx.ui.notify(
31620
- stored ? `Worktree removal confirmation ${choice2 === "skip" ? "skipped" : "required"} for ${policy.repoKey}.` : "Worktree removal policy unchanged.",
31621
- stored ? "info" : "warning"
31873
+ if (!choice2) continue;
31874
+ const value2 = choice2 === "inherit" ? void 0 : choice2 === "off" ? false : choice2 === "fast-forward" ? true : "divergent";
31875
+ if (value2 === override) continue;
31876
+ try {
31877
+ const stored = await host.setRepositoryMergeOverride(
31878
+ value2,
31879
+ ctx,
31880
+ policy.identity,
31881
+ { global: global2, override }
31622
31882
  );
31883
+ if (stored)
31884
+ ctx.ui.notify(
31885
+ `Local branch integration updated for ${policy.repoKey}.`
31886
+ );
31887
+ } catch (error2) {
31888
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31623
31889
  }
31624
31890
  continue;
31625
31891
  }
31626
- if (field === "merge-permission" && mergePolicy) {
31627
- const global3 = host.readConfig().managerMergeEnabled;
31628
- const current = effectiveMergePolicy(
31629
- host.readConfig(),
31630
- mergePolicy.repoKey
31631
- );
31632
- const choice2 = await host.selectMenu(
31633
- ctx,
31634
- `Manager local merge \xB7 ${mergePolicy.repoKey}`,
31892
+ const current = host.readConfig().managerMergeEnabled;
31893
+ const currentChoice = current === false ? "off" : current === true ? "fast-forward" : "divergent";
31894
+ const choice = await host.selectMenu(
31895
+ ctx,
31896
+ "Global Manager local merge",
31897
+ markCurrent(
31635
31898
  [
31636
- {
31637
- value: "inherit",
31638
- label: `Inherit global (${global3 === "divergent" ? "conflict-free merges" : global3 ? "fast-forward only" : "off"})`
31639
- },
31640
31899
  { value: "off", label: "Off" },
31641
31900
  { value: "fast-forward", label: "Fast-forward only" },
31642
31901
  { value: "divergent", label: "Conflict-free merges" }
31643
31902
  ],
31644
- current.source === "global" ? "inherit" : !current.enabled ? "off" : current.allowDivergence ? "divergent" : "fast-forward"
31645
- );
31646
- if (!choice2) continue;
31647
- const enabled = choice2 === "inherit" ? void 0 : choice2 === "off" ? false : choice2 === "fast-forward" ? true : "divergent";
31648
- if (enabled !== void 0 && enabled !== false && (current.source !== "repository" || !current.enabled || enabled === "divergent" && !current.allowDivergence)) {
31649
- const confirm = await ctx.ui.input(
31650
- enabled === "divergent" ? "Enable conflict-free divergent Manager merges? Git may create a new merge commit, and successful integration can automatically remove the exact source worktree. Type enable to confirm." : "Enable fast-forward Manager integration and automatic cleanup of successfully integrated source worktrees. Type enable to confirm.",
31651
- void 0
31652
- );
31653
- if (confirm !== "enable") continue;
31654
- }
31655
- const exactManager = await host.getRemovalPreauthorization(ctx);
31656
- if (exactManager.repoKey !== mergePolicy.repoKey)
31657
- throw new Error(
31658
- "Manager repository changed; policy was not updated"
31659
- );
31660
- setManagerMergeOverride(mergePolicy.repoKey, enabled);
31903
+ currentChoice
31904
+ ),
31905
+ currentChoice
31906
+ );
31907
+ if (!choice) continue;
31908
+ const setting = choice === "off" ? false : choice === "fast-forward" ? true : "divergent";
31909
+ if (setting === current) continue;
31910
+ if (setting !== false && (current === false || setting === "divergent" && current !== "divergent")) {
31911
+ if (!await confirmMergeGrant(ctx, setting, "global settings") || ctx.signal?.aborted)
31912
+ continue;
31913
+ }
31914
+ if (ctx.signal?.aborted) continue;
31915
+ if (host.readConfig().managerMergeEnabled !== current) {
31661
31916
  ctx.ui.notify(
31662
- `Manager local merge ${enabled === void 0 ? "inherits global" : enabled === "divergent" ? "allows conflict-free merges" : enabled ? "allows fast-forward only" : "disabled"} for ${mergePolicy.repoKey}.`
31917
+ "Global Manager integration policy changed; reopen the selector.",
31918
+ "warning"
31663
31919
  );
31664
31920
  continue;
31665
31921
  }
31666
- if (!ctx.isProjectTrusted() || overrideError || !overrides) continue;
31667
- const key = field;
31668
- const global2 = host.readConfig()[key];
31922
+ try {
31923
+ host.updateConfig("managerMergeEnabled", setting, current);
31924
+ } catch (error2) {
31925
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31926
+ continue;
31927
+ }
31928
+ ctx.ui.notify(
31929
+ `Global Manager local merge: ${setting === "divergent" ? "conflict-free merges" : setting ? "fast-forward only" : "off"}`
31930
+ );
31931
+ }
31932
+ },
31933
+ async openRemovalSetting(ctx) {
31934
+ try {
31935
+ const policy = await host.getRemovalPreauthorization(ctx);
31669
31936
  const choice = await host.selectMenu(
31670
31937
  ctx,
31671
- key === "autoActivateManager" ? "Manager auto-start" : "Context retirement",
31672
- [
31673
- {
31674
- value: "inherit",
31675
- label: `Inherit global (${global2 ? "on" : "off"})`,
31676
- help: "Remove this project's explicit value and use the current global default."
31677
- },
31678
- {
31679
- value: "on",
31680
- label: "On for this project",
31681
- help: "Enable this preference in this trusted project."
31682
- },
31683
- {
31684
- value: "off",
31685
- label: "Off for this project",
31686
- help: "Disable this preference in this trusted project."
31687
- }
31688
- ],
31689
- Object.hasOwn(overrides, key) ? overrides[key] ? "on" : "off" : "inherit"
31938
+ `Worktree removal approval \xB7 ${policy.repoKey}`,
31939
+ markCurrent(
31940
+ [
31941
+ { value: "required", label: "Require approval for each removal" },
31942
+ {
31943
+ value: "skip",
31944
+ label: "Allow explicit removals without individual approval"
31945
+ }
31946
+ ],
31947
+ policy.enabled ? "skip" : "required"
31948
+ ),
31949
+ policy.enabled ? "skip" : "required"
31690
31950
  );
31691
- if (!choice) continue;
31692
- try {
31693
- host.updateProjectOverride(
31694
- ctx,
31695
- key,
31696
- choice === "inherit" ? void 0 : choice === "on"
31697
- );
31951
+ if (!choice || choice === "skip" === policy.enabled) return;
31952
+ const stored = await host.setRemovalPreauthorization(
31953
+ choice === "skip",
31954
+ ctx,
31955
+ policy.identity
31956
+ );
31957
+ if (stored)
31698
31958
  ctx.ui.notify(
31699
- `${key === "autoActivateManager" ? "Manager auto-start" : "Context retirement"} ${choice === "inherit" ? "inherited" : `set ${choice} for this project`}.`
31959
+ `Worktree removal approval ${choice === "skip" ? "skipped" : "required"} for ${policy.repoKey}.`
31700
31960
  );
31701
- } catch (error2) {
31702
- ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31703
- }
31961
+ } catch (error2) {
31962
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31704
31963
  }
31705
31964
  },
31706
31965
  async openAgentsMenu(ctx) {
31707
31966
  let selectedSection = "running";
31708
31967
  while (true) {
31709
- const snapshot = await host.loadStatusSnapshot(
31710
- ctx,
31711
- host.controller.sessionSignal()
31712
- );
31713
- const running = host.formatStatusCounts(snapshot.agents) || "0";
31714
- const placement = await host.placementSettings(ctx);
31968
+ let running = "Unavailable";
31969
+ try {
31970
+ const snapshot = await host.loadStatusSnapshot(
31971
+ ctx,
31972
+ host.controller.sessionSignal()
31973
+ );
31974
+ running = host.formatStatusCounts(snapshot.agents) || "0";
31975
+ } catch {
31976
+ if (ctx.signal?.aborted) return;
31977
+ }
31715
31978
  const selected = await host.selectMenu(
31716
31979
  ctx,
31717
- "Agents",
31980
+ "Agents & definitions",
31718
31981
  [
31719
31982
  {
31720
31983
  value: "running",
31721
- label: "Running",
31984
+ label: "Running agents",
31722
31985
  description: running,
31723
31986
  help: "Focus a live managed Agent."
31724
31987
  },
31725
- {
31726
- value: "layout",
31727
- label: "Layout",
31728
- description: placement.effective,
31729
- help: "Choose where newly delegated Lead-direct Agents are placed in Herdr."
31730
- },
31988
+ { value: "agent-definitions", label: "Agent definitions" },
31989
+ { value: "coordinator-profiles", label: "Coordinator profiles" },
31731
31990
  {
31732
31991
  value: "stop-all",
31733
- label: "Stop all\u2026",
31992
+ label: "Stop all agents\u2026",
31734
31993
  help: "Emergency stop for the owned Agent tree. Active work or pending results may be discarded."
31735
31994
  }
31736
31995
  ],
@@ -31739,7 +31998,10 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31739
31998
  if (!selected) return;
31740
31999
  selectedSection = selected;
31741
32000
  if (selected === "running") await this.openRunningAgentsMenu(ctx);
31742
- else if (selected === "layout") await this.openPlacementMenu(ctx);
32001
+ else if (selected === "agent-definitions")
32002
+ await this.openDefinitionsMenu(ctx, "agents");
32003
+ else if (selected === "coordinator-profiles")
32004
+ await this.openDefinitionsMenu(ctx, "roles");
31743
32005
  else if (selected === "stop-all") await this.confirmAndStopAll(ctx);
31744
32006
  }
31745
32007
  },
@@ -31747,36 +32009,37 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31747
32009
  let selectedSection = "execution";
31748
32010
  while (true) {
31749
32011
  const execution = host.leadExecutionPresentation();
32012
+ const showLeadMode = host.isLead() && !execution.managed;
32013
+ if (!showLeadMode && selectedSection === "execution")
32014
+ selectedSection = "agents";
31750
32015
  const selected = await host.selectMenu(
31751
32016
  ctx,
31752
32017
  `Pi Herdsman \xB7 v${host.version}`,
31753
32018
  [
31754
- {
31755
- value: "execution",
31756
- label: "Execution",
31757
- description: execution.managed ? managedExecutionLabel(execution.lifecycle) : execution.mode,
31758
- help: execution.managed ? "This assigned session uses managed-lead. Use Pi /fork or /clone to continue independently (same Git checkout)." : "Choose whether this session works directly or primarily delegates tasks."
31759
- },
32019
+ ...showLeadMode ? [
32020
+ {
32021
+ value: "execution",
32022
+ label: "Lead mode",
32023
+ description: execution.mode,
32024
+ help: "Choose whether this Lead works directly or primarily delegates tasks."
32025
+ }
32026
+ ] : [],
31760
32027
  {
31761
32028
  value: "agents",
31762
- label: "Agents",
31763
- help: "View and manage background Agents."
32029
+ label: "Agents & definitions",
32030
+ help: "Manage running Agents and inspect definitions."
31764
32031
  },
31765
32032
  {
31766
32033
  value: "manager",
31767
- label: "Project manager",
31768
- description: host.roleActive("manager") ? "active" : void 0,
32034
+ label: "Project management",
32035
+ description: host.roleActive("manager") ? "Active" : "Inactive",
31769
32036
  help: "Coordinate independent project work across Git branches."
31770
32037
  },
31771
32038
  {
31772
- value: "stats",
31773
- label: "Session stats",
31774
- help: "View token usage and model costs for this session and its managed work."
31775
- },
31776
- {
31777
- value: "definitions",
31778
- label: "Definitions",
31779
- help: "Inspect available Agents and their configuration."
32039
+ value: "chief",
32040
+ label: "Chief coordination",
32041
+ description: host.roleActive("chief") ? "Active" : "Inactive",
32042
+ help: "Supervise Managers and unassigned Leads across Herdsman."
31780
32043
  },
31781
32044
  {
31782
32045
  value: "settings",
@@ -31784,10 +32047,9 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31784
32047
  help: "Change Herdsman preferences."
31785
32048
  },
31786
32049
  {
31787
- value: "advanced",
31788
- label: "Advanced\u2026",
31789
- description: host.roleActive("chief") ? "Chief active" : void 0,
31790
- help: "Open advanced Herdsman coordination controls."
32050
+ value: "stats",
32051
+ label: "Usage & costs",
32052
+ help: "View token usage and model costs for this session and its managed work."
31791
32053
  }
31792
32054
  ],
31793
32055
  selectedSection
@@ -31799,46 +32061,50 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31799
32061
  else if (selected === "manager")
31800
32062
  await this.openRoleMenu("manager", ctx);
31801
32063
  else if (selected === "stats") await this.showSessionStats(ctx);
31802
- else if (selected === "definitions")
31803
- await this.openDefinitionsMenu(ctx);
31804
32064
  else if (selected === "settings") await this.openSettingsMenu(ctx);
31805
- else if (selected === "advanced") await this.openAdvancedMenu(ctx);
32065
+ else if (selected === "chief") await this.openRoleMenu("chief", ctx);
31806
32066
  }
31807
32067
  },
31808
- async openAdvancedMenu(ctx) {
31809
- const selected = await host.selectMenu(ctx, "Advanced", [
31810
- {
31811
- value: "chief",
31812
- label: "Chief mode",
31813
- description: host.roleActive("chief") ? "active" : void 0,
31814
- help: "Supervise Managers and unassigned Leads across Herdsman."
31815
- }
31816
- ]);
31817
- if (selected === "chief") await this.openRoleMenu("chief", ctx);
31818
- },
31819
32068
  async openRoleMenu(role2, ctx) {
31820
- const active = host.roleActive(role2);
31821
32069
  const name = role2 === "manager" ? "Manager" : "Chief";
31822
- const title = role2 === "manager" ? "Project manager" : "Chief mode";
31823
- const selected = await host.selectMenu(
31824
- ctx,
31825
- title,
31826
- active ? [
31827
- { value: "overview", label: "Overview" },
31828
- {
31829
- value: "refresh",
31830
- label: "Refresh profile",
31831
- help: "Apply definition changes after the current turn becomes idle."
31832
- },
31833
- { value: "leave", label: `Leave ${name} mode` }
31834
- ] : [{ value: "start", label: `Start ${name} mode` }]
31835
- );
31836
- if (selected === "overview" || selected === "start")
31837
- await this.runRoleCommand(role2, "", ctx);
31838
- else if (selected === "refresh")
31839
- await this.runRoleCommand(role2, "refresh", ctx);
31840
- else if (selected === "leave")
31841
- await this.runRoleCommand(role2, "leave", ctx);
32070
+ const title = role2 === "manager" ? "Project management" : "Chief mode";
32071
+ let selectedAction;
32072
+ while (true) {
32073
+ const active = host.roleActive(role2);
32074
+ const selected = await host.selectMenu(
32075
+ ctx,
32076
+ title,
32077
+ active ? [
32078
+ {
32079
+ value: "overview",
32080
+ label: role2 === "manager" ? "Project overview" : "Overview"
32081
+ },
32082
+ ...role2 === "manager" ? [
32083
+ {
32084
+ value: "pending-removals",
32085
+ label: "Pending removal requests"
32086
+ }
32087
+ ] : [],
32088
+ {
32089
+ value: "refresh",
32090
+ label: role2 === "manager" ? "Refresh Manager profile" : "Refresh profile",
32091
+ help: "Apply definition changes after the current turn becomes idle."
32092
+ },
32093
+ { value: "leave", label: `Leave ${name} mode` }
32094
+ ] : [{ value: "start", label: `Start ${name} mode` }],
32095
+ selectedAction
32096
+ );
32097
+ if (!selected) return;
32098
+ selectedAction = selected;
32099
+ if (selected === "overview" || selected === "start")
32100
+ await this.runRoleCommand(role2, "", ctx);
32101
+ else if (selected === "pending-removals")
32102
+ await host.reviewPendingRemoval(ctx);
32103
+ else if (selected === "refresh")
32104
+ await this.runRoleCommand(role2, "refresh", ctx);
32105
+ else if (selected === "leave")
32106
+ await this.runRoleCommand(role2, "leave", ctx);
32107
+ }
31842
32108
  },
31843
32109
  async runRoleCommand(role2, rawArgs, ctx) {
31844
32110
  const args = rawArgs.trim().split(/\s+/u).filter(Boolean);
@@ -36527,6 +36793,7 @@ function registerLeadRuntime(pi, options) {
36527
36793
  removeProjectMessagesForAssignment: options.roleTransitionHost.removeProjectMessagesForAssignment,
36528
36794
  appendDurableError: options.herdRunServices.appendDurableError,
36529
36795
  writeProjectAssignment: writeProjectAssignment2,
36796
+ listAgents: options.identityHost.listAgents,
36530
36797
  liveAgent,
36531
36798
  liveLead,
36532
36799
  currentManager: (...args) => roleTransitions.currentManager(...args),
@@ -36600,7 +36867,8 @@ function registerLeadRuntime(pi, options) {
36600
36867
  pi,
36601
36868
  persistStopClosures: (ctx, closures) => projectRuntime.persistStopClosures(ctx, closures),
36602
36869
  getRemovalPreauthorization: (ctx) => projectRuntime.getRemovalPreauthorization(ctx),
36603
- setRemovalPreauthorization: (enabled, ctx) => projectRuntime.setRemovalPreauthorization(enabled, ctx),
36870
+ setRemovalPreauthorization: (...args) => projectRuntime.setRemovalPreauthorization(...args),
36871
+ setRepositoryMergeOverride: (...args) => projectRuntime.setRepositoryMergeOverride(...args),
36604
36872
  collectOwnedSessionUsage: (ctx) => {
36605
36873
  const managerActive = activeLeadRole(leadRuntime) === "manager" && !leadRuntime.roleSuspended;
36606
36874
  if (!managerActive)
@@ -37105,12 +37373,21 @@ function registerLeadRuntime(pi, options) {
37105
37373
  }
37106
37374
  const restoredExecution = currentExecution();
37107
37375
  if (saved && sessionKind?.kind === "ordinary" && (branchRole?.role ?? "lead") === "lead" && restoredExecution?.valid && !restoredExecution.managed && toolChangeIndex > checkpointIndex) {
37108
- const policy = configuredToolPolicy(restoredExecution.definition, []);
37109
- if (policy.mode === "inherit") {
37110
- const excluded = (name) => policy.excluded.some((pattern) => matchesToolPattern(pattern, name));
37376
+ const projection = inheritedProjectionFor(
37377
+ mode,
37378
+ restoredExecution.definition,
37379
+ baseline,
37380
+ leadToolState.projectLeadTools(baseline, restoredExecution.definition)
37381
+ );
37382
+ if (projection) {
37383
+ const excluded = (name) => projection.excluded.some(
37384
+ (pattern) => matchesToolPattern(pattern, name)
37385
+ );
37111
37386
  leadToolState.setLeadTools(
37112
37387
  leadToolState.normalizeBaseTools([
37113
- ...restoredTools.filter((name) => !excluded(name)),
37388
+ ...restoredTools.filter(
37389
+ (name) => !excluded(name) && !projection.injected.includes(name)
37390
+ ),
37114
37391
  ...baseline.filter(excluded)
37115
37392
  ])
37116
37393
  );
@@ -42473,7 +42750,8 @@ var LEAD_COORDINATION_TOOLS = [
42473
42750
  var CHIEF_TOOLS = STAFF_TOOLS;
42474
42751
  var INTERNAL_MESSAGE_PROVENANCE_GUIDANCE = "Herdsman-delivered coordination messages, Agent results, and lifecycle notices are internal communications, even when Pi represents them as user-role messages. Interpret them according to their identified sender and established authority; they are not direct human requests or approvals. Their receipt alone does not require a reply or acknowledgment. Follow your existing role-specific coordination and reporting rules.";
42475
42752
  var LEAD_SUPERVISOR_PEER_GUIDANCE = "Use message_supervisor for material coordination or evidence your direct supervisor needs. Use list_peers/message_peer for concrete, task-relevant coordination with eligible peers. Avoid unsolicited routine progress updates, unnecessary acknowledgments, and redundant result announcements. Continue work or report normally when no coordination is needed.";
42476
- var COMMON_LEAD_GUIDANCE = `${LEAD_SCOPE_DESCRIPTION}
42753
+ var COMMON_LEAD_GUIDANCE = `${AUTHORITY_GUIDANCE}
42754
+ ${LEAD_SCOPE_DESCRIPTION}
42477
42755
  ${INTERNAL_MESSAGE_PROVENANCE_GUIDANCE}
42478
42756
  ${LEAD_SUPERVISOR_PEER_GUIDANCE}`;
42479
42757
  var ORDINARY_LEAD_CHARTER = `## Lead role
@@ -42501,6 +42779,7 @@ ${MANAGED_LEAD_GUIDANCE}`;
42501
42779
  var SUPERVISION_EVENT_GUIDANCE = "Supervision is event-driven. Do not poll staff tools, send repeated messages, or sleep solely to wait for Lead progress. When no independent work remains, end the turn; incoming Lead updates resume coordination.";
42502
42780
  var MANAGER_ROLE_CONTRACT = `## Manager role
42503
42781
  You are the verified Manager for this Pi session. Supervise eligible Leads in your verified project worktree group. Manage project execution only through exact current project assignments; supervision alone grants no Agent ownership or project lifecycle authority. Configuration changes operating guidance and ordinary tool availability, never authority.
42782
+ ${AUTHORITY_GUIDANCE}
42504
42783
  ${INTERNAL_MESSAGE_PROVENANCE_GUIDANCE}
42505
42784
  Project execution belongs to assigned Leads and their Agent trees. Recovery of a Lead's directly owned Agents belongs to that Lead. Coordinate the existing project assignment through the Lead. Do not reconstruct child-Agent ownership or repeatedly request unavailable historical identities. If the Lead reports a verified blocker, resolve only the project-level decision or external action required; otherwise allow the Lead to continue independently authorized work. Coordination messages and reports are nonterminal and do not establish completion. Use remove_worktree only for an explicitly requested checkout-removal action; never infer removal from completion, review, or inactivity. Unless this repository has been explicitly preauthorized by a human, the tool registers a pending approval and returns promptly. Direct the user to /manager remove to review it, then continue unrelated coordination. Do not repeat or poll a pending request; its result is not evidence of removal.
42506
42785
  Subject to existing writer and authority safeguards, overlapping assignments
@@ -42528,6 +42807,7 @@ function formatMessageLimit(bytes) {
42528
42807
  }
42529
42808
  var CHIEF_ROLE_CONTRACT = `## Chief role
42530
42809
  You are the verified workspace-neutral Chief for this Pi session. Supervise only verified direct-report Managers and eligible unassigned top-level Leads; never bypass a Manager to control assigned Leads or their Agents. Role configuration does not establish authority. Supervision snapshots are non-authoritative coordination data. Do not perform local implementation work or assume this Pi process's working directory is the supervised scope.
42810
+ ${AUTHORITY_GUIDANCE}
42531
42811
  ${INTERNAL_MESSAGE_PROVENANCE_GUIDANCE}
42532
42812
  ${AGENT_EXECUTION_OWNERSHIP_GUIDANCE}
42533
42813
  ${AGENT_UNRESOLVED_GUIDANCE}
@@ -43578,12 +43858,56 @@ ${summary}`,
43578
43858
  { triggerTurn: false }
43579
43859
  );
43580
43860
  };
43861
+ const reviewPendingRemoval = async (ctx) => {
43862
+ const pending = projectRuntime.listPendingRemovals(ctx);
43863
+ if (!pending.length) {
43864
+ ctx.ui.notify("There are no pending worktree removals.", "info");
43865
+ return;
43866
+ }
43867
+ const selected = await selectMenu(
43868
+ ctx,
43869
+ "Review pending worktree removal",
43870
+ pending.map(({ branch, checkoutPath }) => ({
43871
+ value: branch,
43872
+ label: `${branch} \xB7 ${checkoutPath}`
43873
+ }))
43874
+ );
43875
+ if (!selected) return;
43876
+ const request = pending.find((item) => item.branch === selected);
43877
+ if (!request) throw new Error("Pending removal is unavailable");
43878
+ const action = await selectMenu(ctx, `Pending removal \xB7 ${selected}`, [
43879
+ { value: "approve", label: "Approve removal\u2026" },
43880
+ { value: "dismiss", label: "Dismiss request" }
43881
+ ]);
43882
+ if (!action) return;
43883
+ if (action === "dismiss") {
43884
+ if (!projectRuntime.cancelPendingRemoval(request, ctx))
43885
+ throw new Error("Pending removal changed; review the new request");
43886
+ ctx.ui.notify(
43887
+ `Pending removal of ${request.branch} dismissed.`,
43888
+ "info"
43889
+ );
43890
+ return;
43891
+ }
43892
+ const result = await projectRuntime.approvePendingRemoval(request, ctx);
43893
+ ctx.ui.notify(
43894
+ result.content[0]?.text ?? "Removal finished.",
43895
+ result.details.ok || "cancelled" in result.details && result.details.cancelled ? "info" : "warning"
43896
+ );
43897
+ return;
43898
+ };
43581
43899
  let leadCommandRuntime;
43582
43900
  const leadCommandHost = {
43583
43901
  pi,
43902
+ reviewPendingRemoval,
43584
43903
  persistStopClosures: (ctx, closures) => projectRuntime.persistStopClosures(ctx, closures),
43585
43904
  getRemovalPreauthorization: (ctx) => projectRuntime.getRemovalPreauthorization(ctx),
43586
- setRemovalPreauthorization: (enabled, ctx) => projectRuntime.setRemovalPreauthorization(enabled, ctx),
43905
+ setRemovalPreauthorization: (enabled, ctx, expectedManager) => projectRuntime.setRemovalPreauthorization(
43906
+ enabled,
43907
+ ctx,
43908
+ expectedManager
43909
+ ),
43910
+ setRepositoryMergeOverride: (...args) => projectRuntime.setRepositoryMergeOverride(...args),
43587
43911
  runHerdr,
43588
43912
  presentStopSummary,
43589
43913
  version: HERDSMAN_VERSION,
@@ -43626,8 +43950,8 @@ ${summary}`,
43626
43950
  input: (ctx, label) => ctx.ui.input(label),
43627
43951
  updateSpawnPlacement: (placement) => updateConfig("spawnPlacement", placement),
43628
43952
  updateMessageLimit: (key, value2) => updateConfig(key, value2),
43629
- updateConfig: (key, value2) => {
43630
- updateConfig(key, value2);
43953
+ updateConfig: (key, value2, expectedManagerMergeEnabled) => {
43954
+ updateConfig(key, value2, expectedManagerMergeEnabled);
43631
43955
  if (key === "statusWidgetMaxRows") {
43632
43956
  const rows = value2 === void 0 ? DEFAULT_STATUS_WIDGET_MAX_ROWS : value2;
43633
43957
  leadRuntimes.statusRuntime?.setStatusWidgetMaxRows(rows);
@@ -43654,7 +43978,7 @@ ${summary}`,
43654
43978
  "leave",
43655
43979
  "remove",
43656
43980
  "forget",
43657
- "remove-preapproval"
43981
+ "removal-confirmation"
43658
43982
  ];
43659
43983
  const input = prefix.trimStart();
43660
43984
  const [command, branchPrefix] = input.split(/\s+/u);
@@ -43663,9 +43987,9 @@ ${summary}`,
43663
43987
  value: value2,
43664
43988
  label: value2
43665
43989
  }));
43666
- if (command === "remove-preapproval")
43667
- return input.trim().split(/\s+/u).length === 2 ? ["on", "off"].filter((value2) => value2.startsWith(branchPrefix ?? "")).map((value2) => ({
43668
- value: `remove-preapproval ${value2}`,
43990
+ if (command === "removal-confirmation")
43991
+ return input.includes(" ") && input.trim().split(/\s+/u).length <= 2 ? ["required", "skip"].filter((value2) => value2.startsWith(branchPrefix ?? "")).map((value2) => ({
43992
+ value: `removal-confirmation ${value2}`,
43669
43993
  label: value2
43670
43994
  })) : null;
43671
43995
  if (command !== "remove" && command !== "forget")
@@ -43688,84 +44012,36 @@ ${summary}`,
43688
44012
  },
43689
44013
  handler: async (rawArgs, ctx) => {
43690
44014
  const args = rawArgs.trim().split(/\s+/u).filter(Boolean);
43691
- if (args[0] === "remove-preapproval") {
44015
+ if (args[0] === "removal-confirmation") {
43692
44016
  if (args.length === 1) {
43693
44017
  const policy = await projectRuntime.getRemovalPreauthorization(ctx);
43694
44018
  ctx.ui.notify(
43695
- `Worktree removal confirmation: ${policy.enabled ? "skipped" : "required"} for ${policy.repoKey}.`,
44019
+ `Worktree removal approval: ${policy.enabled ? "Skipped" : "Required"} for ${policy.repoKey}.`,
43696
44020
  "info"
43697
44021
  );
43698
44022
  return;
43699
44023
  }
43700
- if (args.length !== 2 || !["on", "off"].includes(args[1])) {
44024
+ if (args.length !== 2 || !["required", "skip"].includes(args[1])) {
43701
44025
  ctx.ui.notify(
43702
- "Usage: /manager remove-preapproval <on|off>",
44026
+ "Usage: /manager removal-confirmation [required|skip]",
43703
44027
  "error"
43704
44028
  );
43705
44029
  return;
43706
44030
  }
43707
- const enabled = args[1] === "on";
44031
+ const enabled = args[1] === "skip";
43708
44032
  const stored = await projectRuntime.setRemovalPreauthorization(
43709
44033
  enabled,
43710
44034
  ctx
43711
44035
  );
43712
44036
  ctx.ui.notify(
43713
- `Skip worktree removal confirmation for ${enabled ? "this repository is On" : "this repository is Off"}${stored ? "." : "; setting unchanged."}`,
44037
+ stored ? `Worktree removal approval: ${enabled ? "Skipped" : "Required"}.` : "Worktree removal approval setting unchanged.",
43714
44038
  stored ? "info" : "warning"
43715
44039
  );
43716
44040
  return;
43717
44041
  }
43718
44042
  if (args[0] === "remove") {
43719
44043
  if (args.length === 1) {
43720
- const pending = projectRuntime.listPendingRemovals(ctx);
43721
- if (!pending.length) {
43722
- ctx.ui.notify(
43723
- "There are no pending worktree removals.",
43724
- "info"
43725
- );
43726
- return;
43727
- }
43728
- const selected = await selectMenu(
43729
- ctx,
43730
- "Review pending worktree removal",
43731
- pending.map(({ branch, checkoutPath }) => ({
43732
- value: branch,
43733
- label: `${branch} \xB7 ${checkoutPath}`
43734
- }))
43735
- );
43736
- if (!selected) return;
43737
- const request = pending.find(
43738
- (item) => item.branch === selected
43739
- );
43740
- if (!request) throw new Error("Pending removal is unavailable");
43741
- const action = await selectMenu(
43742
- ctx,
43743
- `Pending removal \xB7 ${selected}`,
43744
- [
43745
- { value: "approve", label: "Approve removal\u2026" },
43746
- { value: "dismiss", label: "Dismiss request" }
43747
- ]
43748
- );
43749
- if (!action) return;
43750
- if (action === "dismiss") {
43751
- if (!projectRuntime.cancelPendingRemoval(request, ctx))
43752
- throw new Error(
43753
- "Pending removal changed; review the new request"
43754
- );
43755
- ctx.ui.notify(
43756
- `Pending removal of ${request.branch} dismissed.`,
43757
- "info"
43758
- );
43759
- return;
43760
- }
43761
- const result2 = await projectRuntime.approvePendingRemoval(
43762
- request,
43763
- ctx
43764
- );
43765
- ctx.ui.notify(
43766
- result2.content[0]?.text ?? "Removal finished.",
43767
- result2.details.ok || "cancelled" in result2.details && result2.details.cancelled ? "info" : "warning"
43768
- );
44044
+ await reviewPendingRemoval(ctx);
43769
44045
  return;
43770
44046
  }
43771
44047
  if (args.length !== 2) {