pi-herdsman 0.49.0 → 0.50.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/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");
@@ -20309,7 +20320,9 @@ This batch was not embedded. Use read_evidence to retrieve the items relevant to
20309
20320
  delegationEnabled ? effectiveDefinition.frontmatter.agents : []
20310
20321
  )}`,
20311
20322
  ...process.env.PI_CODING_AGENT_DIR ? [`PI_CODING_AGENT_DIR=${process.env.PI_CODING_AGENT_DIR}`] : [],
20312
- "PI_OFFLINE=1"
20323
+ ...effectiveDefinition.frontmatter.extensions?.some(
20324
+ (source) => source.startsWith("npm:")
20325
+ ) ? [] : ["PI_OFFLINE=1"]
20313
20326
  ];
20314
20327
  const registeredProviderIds = new Set(
20315
20328
  (ctx.modelRegistry?.getRegisteredProviderIds?.() ?? []).map(
@@ -22440,7 +22453,7 @@ function collectSessionUsage(ctx, ownedChildren, openOwnedSession, leadRoots = [
22440
22453
  breakdown
22441
22454
  };
22442
22455
  }
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;
22456
+ 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
22457
  var init_agent_controller = __esm({
22445
22458
  "extension/agent-controller.ts"() {
22446
22459
  "use strict";
@@ -22498,7 +22511,16 @@ var init_agent_controller = __esm({
22498
22511
  }
22499
22512
  }
22500
22513
  };
22501
- SHARED_AGENT_INSTRUCTIONS = `Work only on the assigned objective and preserve its stated scope, constraints,
22514
+ AUTHORITY_GUIDANCE = `The human user has the final say on decisions within their authority.
22515
+
22516
+ 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.
22517
+
22518
+ 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.
22519
+
22520
+ When unable to follow an instruction, identify the specific applicable constraint. Never invent restrictions or elevate conventions, recommendations, or personal judgment into binding requirements.`;
22521
+ SHARED_AGENT_INSTRUCTIONS = `${AUTHORITY_GUIDANCE}
22522
+
22523
+ Work only on the assigned objective and preserve its stated scope, constraints,
22502
22524
  authority, and acceptance criteria.
22503
22525
 
22504
22526
  Treat supplied files as message evidence. Explicit Agent attachments must contain
@@ -25871,7 +25893,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
25871
25893
  // package.json
25872
25894
  var package_default = {
25873
25895
  name: "pi-herdsman",
25874
- version: "0.49.0",
25896
+ version: "0.50.1",
25875
25897
  type: "module",
25876
25898
  description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
25877
25899
  license: "Apache-2.0",
@@ -27367,58 +27389,127 @@ Type forget ${branch} to confirm.`,
27367
27389
  )
27368
27390
  );
27369
27391
  };
27370
- const setRemovalPreauthorization = async (enabled, ctx) => {
27371
- const manager = await host.currentManager(ctx);
27372
- if (host.activeRole() !== "manager" || !manager || !ctx.hasUI)
27392
+ 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;
27393
+ const repositorySettingsIdentity = async (ctx) => {
27394
+ const workspaceId = process.env.HERDR_WORKSPACE_ID;
27395
+ const paneId = process.env.HERDR_PANE_ID;
27396
+ const tabId = process.env.HERDR_TAB_ID;
27397
+ const sessionId = ctx.sessionManager.getSessionId();
27398
+ const sessionFile = ctx.sessionManager.getSessionFile();
27399
+ const cwd = ctx.cwd;
27400
+ if (!workspaceId || !paneId || !tabId || !sessionId)
27373
27401
  throw new Error(
27374
- "Only an interactive active Manager can change this setting"
27402
+ "Verified workspace, pane, tab and session identity are required"
27375
27403
  );
27376
- const group = await host.worktreeGroupScope(
27377
- host.pi,
27378
- ctx,
27379
- manager.workspaceId,
27380
- ctx.signal
27404
+ const agent = await verifiedHerdrAgent(
27405
+ {
27406
+ piSessionId: sessionId,
27407
+ piSessionFile: sessionFile,
27408
+ workspaceId,
27409
+ paneId,
27410
+ tabId
27411
+ },
27412
+ {
27413
+ listAgents: async () => (await host.listAgents(ctx)).agents,
27414
+ getAgent: async (id) => (await host.runHerdr(host.pi, ctx, ["agent", "get", id], {
27415
+ signal: ctx.signal
27416
+ }))?.agent,
27417
+ expectedSession: host.expectedSession,
27418
+ isPiAgent: host.isPiAgent,
27419
+ matchesExpectedSession
27420
+ }
27381
27421
  );
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 }
27422
+ if (!agent)
27423
+ throw new Error(
27424
+ "Herdr session-to-workspace identity is unavailable or conflicting"
27393
27425
  );
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(
27426
+ const scope = await (host.localRepositoryScope ?? localRepositoryScope)(
27407
27427
  host.pi,
27408
27428
  ctx,
27409
- manager.workspaceId,
27429
+ workspaceId,
27410
27430
  ctx.signal
27411
27431
  );
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");
27432
+ 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)
27433
+ throw new Error("Session context changed while verifying repository");
27434
+ return {
27435
+ ...scope,
27436
+ workspaceId,
27437
+ paneId,
27438
+ tabId,
27439
+ sessionId,
27440
+ sessionFile,
27441
+ cwd
27442
+ };
27443
+ };
27444
+ const revalidateRepositorySettings = async (ctx, expected) => {
27445
+ const current = await repositorySettingsIdentity(ctx);
27446
+ ctx.signal?.throwIfAborted();
27447
+ if (!ctx.hasUI)
27448
+ throw new Error("Interactive session is no longer available");
27449
+ if (!sameRepositorySettingsIdentity(current, expected))
27450
+ throw new Error("Repository or session changed; reopen the selector");
27451
+ };
27452
+ const getRemovalPreauthorization = async (ctx) => {
27453
+ const identity = await repositorySettingsIdentity(ctx);
27417
27454
  return {
27418
- repoKey: manager.repoKey,
27419
- enabled: isWorktreeRemovalPreapproved(manager.repoKey)
27455
+ identity,
27456
+ repoKey: identity.repoKey,
27457
+ enabled: isWorktreeRemovalPreapproved(identity.repoKey)
27420
27458
  };
27421
27459
  };
27460
+ const setRemovalPreauthorization = async (enabled, ctx, expectedIdentity) => {
27461
+ if (!ctx.hasUI)
27462
+ throw new Error(
27463
+ "An interactive user is required to change repository settings"
27464
+ );
27465
+ const identity = await repositorySettingsIdentity(ctx);
27466
+ if (expectedIdentity && !sameRepositorySettingsIdentity(identity, expectedIdentity))
27467
+ throw new Error("Repository or session changed; reopen the selector");
27468
+ const previous = isWorktreeRemovalPreapproved(identity.repoKey);
27469
+ if (enabled && !previous) {
27470
+ const confirmed = await ctx.ui.confirm(
27471
+ "Allow worktree removal without individual approval?",
27472
+ [
27473
+ `Repository: ${identity.repoKey}`,
27474
+ "",
27475
+ "The Manager may execute explicitly requested, eligible",
27476
+ "worktree removals without asking again.",
27477
+ "Existing safety checks remain active."
27478
+ ].join("\n"),
27479
+ { signal: ctx.signal }
27480
+ );
27481
+ if (!confirmed) return false;
27482
+ }
27483
+ await revalidateRepositorySettings(ctx, identity);
27484
+ if (isWorktreeRemovalPreapproved(identity.repoKey) !== previous)
27485
+ throw new Error("Removal policy changed before saving the setting");
27486
+ if (previous !== enabled)
27487
+ setWorktreeRemovalPreapproved(identity.repoKey, enabled, previous);
27488
+ return true;
27489
+ };
27490
+ const setRepositoryMergeOverride = async (enabled, ctx, expectedIdentity, expected) => {
27491
+ if (!ctx.hasUI)
27492
+ throw new Error(
27493
+ "An interactive user is required to change repository settings"
27494
+ );
27495
+ const identity = await repositorySettingsIdentity(ctx);
27496
+ if (!sameRepositorySettingsIdentity(identity, expectedIdentity))
27497
+ throw new Error("Repository or session changed; reopen the selector");
27498
+ const level = (value2) => value2 === false ? 0 : value2 === true ? 1 : 2;
27499
+ const previous = expected.override ?? expected.global;
27500
+ const next = enabled ?? expected.global;
27501
+ if (next !== false && (level(next) > level(previous) || enabled !== void 0 && expected.override === void 0)) {
27502
+ const confirmed = await ctx.ui.confirm(
27503
+ `Allow Manager integration for ${identity.repoKey}?`,
27504
+ 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?",
27505
+ { signal: ctx.signal }
27506
+ );
27507
+ if (!confirmed) return false;
27508
+ }
27509
+ await revalidateRepositorySettings(ctx, identity);
27510
+ setManagerMergeOverride(identity.repoKey, enabled, expected);
27511
+ return true;
27512
+ };
27422
27513
  const {
27423
27514
  pi,
27424
27515
  leadRuntime,
@@ -30333,6 +30424,7 @@ ${(updated.requiredEvidence ?? []).map((entry) => `- ${entry.id}: ${entry.name}`
30333
30424
  cancelPendingRemoval,
30334
30425
  setRemovalPreauthorization,
30335
30426
  getRemovalPreauthorization,
30427
+ setRepositoryMergeOverride,
30336
30428
  forgetLegacyProjectAssignment,
30337
30429
  executeStaff,
30338
30430
  updateAssignmentEvidence,
@@ -30452,6 +30544,17 @@ import {
30452
30544
  getSupportedThinkingLevels
30453
30545
  } from "@earendil-works/pi-ai";
30454
30546
  function createLeadCommandRuntime(host) {
30547
+ const confirmMergeGrant = (ctx, setting, scope) => ctx.ui.confirm(
30548
+ `Allow Manager integration for ${scope}?`,
30549
+ 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?",
30550
+ { signal: ctx.signal }
30551
+ );
30552
+ const markCurrent = (items, current) => items.map(
30553
+ (item) => item.value === current ? {
30554
+ ...item,
30555
+ description: item.description ? `${item.description} \xB7 current` : "current"
30556
+ } : item
30557
+ );
30455
30558
  const modelToken2 = (model) => `${model.provider}/${model.id}`;
30456
30559
  return {
30457
30560
  async openPlacementMenu(ctx) {
@@ -30481,7 +30584,7 @@ function createLeadCommandRuntime(host) {
30481
30584
  ],
30482
30585
  current.effective
30483
30586
  );
30484
- if (!selected) return;
30587
+ if (!selected || selected === current.effective) return;
30485
30588
  host.updateSpawnPlacement(selected);
30486
30589
  const verified = await host.placementSettings(ctx);
30487
30590
  if (verified.effective !== selected)
@@ -30519,22 +30622,35 @@ function createLeadCommandRuntime(host) {
30519
30622
  );
30520
30623
  if (!setting) return;
30521
30624
  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
- ]);
30625
+ const currentBytes = setting === "inlineAttachmentLimitBytes" ? limits.inline.bytes : limits.mailbox.bytes;
30626
+ const currentChoice = presets.some(
30627
+ ({ bytes }) => bytes === currentBytes
30628
+ ) ? String(currentBytes) : "custom";
30629
+ const choice = await host.selectMenu(
30630
+ ctx,
30631
+ "Limit",
30632
+ markCurrent(
30633
+ [
30634
+ ...presets.map(({ label, bytes }) => ({
30635
+ value: String(bytes),
30636
+ label
30637
+ })),
30638
+ {
30639
+ value: "custom",
30640
+ label: "Custom\u2026",
30641
+ description: currentChoice === "custom" ? host.formatMessageLimit(currentBytes) : void 0,
30642
+ help: "Enter a custom limit in KiB, from 1 through 1024."
30643
+ },
30644
+ {
30645
+ value: "reset",
30646
+ label: "Reset",
30647
+ help: "Remove the configured override and use the default."
30648
+ }
30649
+ ],
30650
+ currentChoice
30651
+ ),
30652
+ currentChoice
30653
+ );
30538
30654
  if (!choice) continue;
30539
30655
  let value2;
30540
30656
  if (choice === "reset") value2 = void 0;
@@ -30548,6 +30664,7 @@ function createLeadCommandRuntime(host) {
30548
30664
  }
30549
30665
  value2 = kib * 1024;
30550
30666
  } else value2 = Number(choice);
30667
+ if (value2 !== void 0 && value2 === currentBytes) continue;
30551
30668
  host.updateMessageLimit(selectedLimit, value2);
30552
30669
  ctx.ui.notify(
30553
30670
  `${selectedLimit}: ${value2 === void 0 ? "reset" : host.formatMessageLimit(value2)}`
@@ -30571,7 +30688,7 @@ function createLeadCommandRuntime(host) {
30571
30688
  );
30572
30689
  return compactMatches.length === 1 ? compactMatches[0] : void 0;
30573
30690
  },
30574
- async openDefinitionsMenu(ctx) {
30691
+ async openDefinitionsMenu(ctx, initialSection) {
30575
30692
  let selectedSection = "agents";
30576
30693
  const selectedDefinitions = {};
30577
30694
  const loadDefinitions = async (section, includeProject = true, onWarning) => section === "agents" ? (await host.contextAgentDefinitions(ctx, onWarning)).definitions : discoverRoleDefinitions({
@@ -30588,18 +30705,18 @@ function createLeadCommandRuntime(host) {
30588
30705
  return loaded.find((candidate) => candidate.name === name);
30589
30706
  };
30590
30707
  while (true) {
30591
- const section = await host.selectMenu(
30708
+ const section = initialSection ?? await host.selectMenu(
30592
30709
  ctx,
30593
30710
  "Agents & Coordinators",
30594
30711
  [
30595
30712
  {
30596
30713
  value: "agents",
30597
- label: "Agents",
30714
+ label: "Agent definitions",
30598
30715
  help: "Definitions available for Agent delegation."
30599
30716
  },
30600
30717
  {
30601
30718
  value: "roles",
30602
- label: "Coordinators",
30719
+ label: "Coordinator profiles",
30603
30720
  help: "Profiles for existing Lead, Manager, and Chief roles; these do not grant authority."
30604
30721
  }
30605
30722
  ],
@@ -31135,6 +31252,7 @@ function createLeadCommandRuntime(host) {
31135
31252
  definition = verified;
31136
31253
  }
31137
31254
  }
31255
+ if (initialSection) return;
31138
31256
  }
31139
31257
  },
31140
31258
  async openRunningAgentsMenu(ctx) {
@@ -31286,7 +31404,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31286
31404
  }
31287
31405
  const mode = await host.selectMenu(
31288
31406
  ctx,
31289
- "Execution",
31407
+ "Lead mode",
31290
31408
  [
31291
31409
  {
31292
31410
  value: "flexible",
@@ -31310,7 +31428,25 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31310
31428
  }
31311
31429
  },
31312
31430
  async openSettingsMenu(ctx) {
31313
- let selectedSetting = "auto-activate-manager";
31431
+ let selectedCategory = "sessions";
31432
+ while (true) {
31433
+ const category = await host.selectMenu(
31434
+ ctx,
31435
+ "Settings",
31436
+ [
31437
+ { value: "sessions", label: "Sessions & agents" },
31438
+ { value: "manager", label: "Manager & repositories" },
31439
+ { value: "interface", label: "Interface" }
31440
+ ],
31441
+ selectedCategory
31442
+ );
31443
+ if (!category) return;
31444
+ selectedCategory = category;
31445
+ await this.openSettingsCategory(ctx, category);
31446
+ }
31447
+ },
31448
+ async openSettingsCategory(ctx, category) {
31449
+ let selectedSetting = category === "sessions" ? "default-lead-execution" : category === "manager" ? "auto-activate-manager" : "agent-layout";
31314
31450
  const loadProjectState = () => {
31315
31451
  if (!ctx.isProjectTrusted())
31316
31452
  return { trusted: false, overrides: {} };
@@ -31330,14 +31466,36 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31330
31466
  while (true) {
31331
31467
  const config = host.readConfig();
31332
31468
  const project = loadProjectState();
31469
+ let repository;
31470
+ if (category === "manager") {
31471
+ try {
31472
+ repository = await host.getRemovalPreauthorization(ctx);
31473
+ } catch {
31474
+ }
31475
+ }
31476
+ const merge = repository ? effectiveMergePolicy(config, repository.repoKey) : void 0;
31477
+ let messageSummary;
31478
+ if (category === "sessions") {
31479
+ try {
31480
+ const limits = await host.messageLimits(ctx);
31481
+ messageSummary = `Inline ${host.formatMessageLimit(limits.inline.bytes)} \xB7 mailbox ${host.formatMessageLimit(limits.mailbox.bytes)}`;
31482
+ } catch {
31483
+ messageSummary = "Unavailable";
31484
+ }
31485
+ }
31333
31486
  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
31487
  const selected = await host.selectMenu(
31335
31488
  ctx,
31336
- "Settings",
31489
+ category === "sessions" ? "Sessions & agents" : category === "manager" ? "Manager & repositories" : "Interface",
31337
31490
  [
31491
+ {
31492
+ value: "agent-layout",
31493
+ label: "Agent pane layout",
31494
+ description: category === "interface" ? (await host.placementSettings(ctx)).effective : void 0
31495
+ },
31338
31496
  {
31339
31497
  value: "default-lead-execution",
31340
- label: "Default Lead execution",
31498
+ label: "Default Lead mode",
31341
31499
  description: config.defaultLeadExecution,
31342
31500
  help: "Used when a future ordinary Lead session has no persisted execution choice."
31343
31501
  },
@@ -31349,8 +31507,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31349
31507
  },
31350
31508
  {
31351
31509
  value: "manager-git-bootstrap-confirmation",
31352
- label: "Skip Manager Git setup confirmation",
31353
- description: `Global ${config.managerGitBootstrapWithoutConfirmation ? "on" : "off"}`,
31510
+ label: "Git initialization prompt",
31511
+ description: config.managerGitBootstrapWithoutConfirmation ? "Skipped" : "Required",
31354
31512
  help: "Automatically initialize a non-Git workspace when Manager is started explicitly. Off by default."
31355
31513
  },
31356
31514
  {
@@ -31361,8 +31519,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31361
31519
  },
31362
31520
  {
31363
31521
  value: "manager-merge",
31364
- label: "Manager local merge",
31365
- description: `Global ${config.managerMergeEnabled === "divergent" ? "conflict-free merges" : config.managerMergeEnabled ? "fast-forward only" : "off"}`,
31522
+ label: "Local branch integration",
31523
+ description: merge ? `${!merge.enabled ? "Off" : merge.allowDivergence ? "Conflict-free merges" : "Fast-forward"} (${merge.source})` : "Repository unavailable",
31366
31524
  help: "Choose whether Managers may integrate accepted local branches only by fast-forward or also by clean divergent merge, with guarded cleanup."
31367
31525
  },
31368
31526
  {
@@ -31373,41 +31531,96 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31373
31531
  },
31374
31532
  {
31375
31533
  value: "max-agent-depth",
31376
- label: "Max Agent depth",
31534
+ label: "Maximum delegation depth",
31377
31535
  description: String(config.maxAgentDepth),
31378
31536
  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
31537
  },
31380
31538
  {
31381
31539
  value: "message-limits",
31382
- label: "Message limits",
31540
+ label: "Message size limits",
31541
+ description: messageSummary,
31383
31542
  help: "Configure inline attachment and managed mailbox payload byte limits."
31384
31543
  },
31385
31544
  {
31386
- value: "project-overrides",
31387
- label: "Project overrides\u2026",
31388
- help: "Choose project-specific values for Manager auto-start and context retirement."
31545
+ value: "removal-confirmation",
31546
+ label: "Worktree removal approval",
31547
+ description: repository ? `${repository.enabled ? "Skipped" : "Required"} (repository)` : "Repository unavailable"
31389
31548
  }
31390
- ],
31549
+ ].filter(
31550
+ (item) => (category === "sessions" ? [
31551
+ "default-lead-execution",
31552
+ "context-retirement",
31553
+ "max-agent-depth",
31554
+ "message-limits"
31555
+ ] : category === "manager" ? [
31556
+ "auto-activate-manager",
31557
+ "manager-git-bootstrap-confirmation",
31558
+ "manager-merge",
31559
+ "removal-confirmation"
31560
+ ] : ["agent-layout", "status-widget-rows"]).includes(item.value)
31561
+ ),
31391
31562
  selectedSetting
31392
31563
  );
31393
31564
  if (!selected) return;
31394
31565
  selectedSetting = selected;
31395
- if (selected === "project-overrides") {
31396
- await this.openProjectOverridesMenu(ctx);
31566
+ if (selected === "agent-layout") {
31567
+ await this.openPlacementMenu(ctx);
31568
+ } else if (selected === "manager-git-bootstrap-confirmation") {
31569
+ const choice = await host.selectMenu(
31570
+ ctx,
31571
+ "Manager Git setup prompt",
31572
+ markCurrent(
31573
+ [
31574
+ { value: "required", label: "Require confirmation" },
31575
+ {
31576
+ value: "skip",
31577
+ label: "Skip confirmation on explicit Manager start"
31578
+ }
31579
+ ],
31580
+ config.managerGitBootstrapWithoutConfirmation ? "skip" : "required"
31581
+ ),
31582
+ config.managerGitBootstrapWithoutConfirmation ? "skip" : "required"
31583
+ );
31584
+ if (choice && choice === "skip" !== config.managerGitBootstrapWithoutConfirmation) {
31585
+ if (choice === "skip" && !await ctx.ui.confirm(
31586
+ "Skip Manager Git setup confirmation?",
31587
+ "Explicit Manager activation may initialize a non-Git workspace without asking again.",
31588
+ { signal: ctx.signal }
31589
+ ))
31590
+ continue;
31591
+ if (ctx.signal?.aborted) continue;
31592
+ host.updateConfig(
31593
+ "managerGitBootstrapWithoutConfirmation",
31594
+ choice === "skip"
31595
+ );
31596
+ }
31397
31597
  } else if (selected === "status-widget-rows") {
31398
31598
  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
- ]);
31599
+ const currentChoice = config.statusWidgetMaxRows === DEFAULT_STATUS_WIDGET_MAX_ROWS ? "default" : [3, 5, 8, 12, 20].includes(config.statusWidgetMaxRows) ? String(config.statusWidgetMaxRows) : "custom";
31600
+ const choice = await host.selectMenu(
31601
+ ctx,
31602
+ "Status widget rows",
31603
+ markCurrent(
31604
+ [
31605
+ {
31606
+ value: "default",
31607
+ label: `Default (${DEFAULT_STATUS_WIDGET_MAX_ROWS})`
31608
+ },
31609
+ ...[3, 5, 8, 12, 20].map((rows) => ({
31610
+ value: String(rows),
31611
+ label: String(rows)
31612
+ })),
31613
+ {
31614
+ value: "custom",
31615
+ label: "Custom\u2026",
31616
+ description: currentChoice === "custom" ? String(config.statusWidgetMaxRows) : void 0
31617
+ },
31618
+ { value: "reset", label: "Reset" }
31619
+ ],
31620
+ currentChoice
31621
+ ),
31622
+ currentChoice
31623
+ );
31411
31624
  if (!choice) break;
31412
31625
  let value2;
31413
31626
  if (choice === "reset") value2 = void 0;
@@ -31424,6 +31637,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31424
31637
  }
31425
31638
  } else
31426
31639
  value2 = choice === "default" ? DEFAULT_STATUS_WIDGET_MAX_ROWS : Number(choice);
31640
+ if (value2 !== void 0 && value2 === config.statusWidgetMaxRows)
31641
+ break;
31427
31642
  try {
31428
31643
  host.updateConfig("statusWidgetMaxRows", value2);
31429
31644
  ctx.ui.notify(
@@ -31439,18 +31654,31 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31439
31654
  }
31440
31655
  } else if (selected === "max-agent-depth") {
31441
31656
  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
- ]);
31657
+ const currentChoice = config.maxAgentDepth === DEFAULT_MAX_AGENT_DEPTH ? "default" : [1, 2, 3, 4, 5].includes(config.maxAgentDepth) ? String(config.maxAgentDepth) : "custom";
31658
+ const choice = await host.selectMenu(
31659
+ ctx,
31660
+ "Max Agent depth",
31661
+ markCurrent(
31662
+ [
31663
+ {
31664
+ value: "default",
31665
+ label: `Default (${DEFAULT_MAX_AGENT_DEPTH})`
31666
+ },
31667
+ ...[1, 2, 3, 4, 5].map((depth) => ({
31668
+ value: String(depth),
31669
+ label: String(depth)
31670
+ })),
31671
+ {
31672
+ value: "custom",
31673
+ label: "Custom\u2026",
31674
+ description: currentChoice === "custom" ? String(config.maxAgentDepth) : void 0
31675
+ },
31676
+ { value: "reset", label: "Reset" }
31677
+ ],
31678
+ currentChoice
31679
+ ),
31680
+ currentChoice
31681
+ );
31454
31682
  if (!choice) break;
31455
31683
  let value2;
31456
31684
  if (choice === "reset") value2 = void 0;
@@ -31467,6 +31695,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31467
31695
  }
31468
31696
  } else
31469
31697
  value2 = choice === "default" ? DEFAULT_MAX_AGENT_DEPTH : Number(choice);
31698
+ if (value2 !== void 0 && value2 === config.maxAgentDepth) break;
31470
31699
  try {
31471
31700
  host.updateConfig("maxAgentDepth", value2);
31472
31701
  ctx.ui.notify(
@@ -31486,251 +31715,283 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31486
31715
  const mode = await host.selectMenu(
31487
31716
  ctx,
31488
31717
  "Default Lead execution",
31489
- [
31490
- { value: "flexible", label: "flexible" },
31491
- { value: "orchestrate", label: "orchestrate" }
31492
- ],
31718
+ markCurrent(
31719
+ [
31720
+ { value: "flexible", label: "flexible" },
31721
+ { value: "orchestrate", label: "orchestrate" }
31722
+ ],
31723
+ config.defaultLeadExecution
31724
+ ),
31493
31725
  config.defaultLeadExecution
31494
31726
  );
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;
31727
+ if (mode && mode !== config.defaultLeadExecution) {
31728
+ host.updateConfig("defaultLeadExecution", mode);
31729
+ ctx.ui.notify(`Default Lead mode: ${mode}`);
31523
31730
  }
31524
- host.updateConfig("managerMergeEnabled", setting);
31525
- ctx.ui.notify(
31526
- `Global Manager local merge: ${setting === "divergent" ? "conflict-free merges" : setting ? "fast-forward only" : "off"}`
31731
+ } else if (selected === "context-retirement" || selected === "auto-activate-manager") {
31732
+ await this.openProjectSetting(
31733
+ ctx,
31734
+ selected === "context-retirement" ? "contextRetirement" : "autoActivateManager"
31527
31735
  );
31736
+ } else if (selected === "manager-merge") {
31737
+ await this.openMergeSetting(ctx);
31738
+ } else if (selected === "removal-confirmation") {
31739
+ await this.openRemovalSetting(ctx);
31528
31740
  }
31529
31741
  }
31530
31742
  },
31531
- async openProjectOverridesMenu(ctx) {
31743
+ async openProjectSetting(ctx, key) {
31744
+ const title = key === "autoActivateManager" ? "Manager auto-start" : "Context retirement";
31745
+ let selectedScope = "global";
31532
31746
  while (true) {
31747
+ const global2 = host.readConfig()[key];
31533
31748
  let overrides;
31534
- let overrideError;
31535
- if (ctx.isProjectTrusted()) {
31749
+ let unavailable;
31750
+ if (!ctx.isProjectTrusted()) unavailable = "Project is not trusted";
31751
+ else
31536
31752
  try {
31537
31753
  overrides = host.readProjectOverrides(ctx);
31538
31754
  } catch (error2) {
31539
- overrideError = error2;
31755
+ unavailable = `Project settings unavailable: ${String(error2).replace(/^Error: /, "")}`;
31540
31756
  }
31757
+ const projectValue = overrides && Object.hasOwn(overrides, key) ? overrides[key] : void 0;
31758
+ const scope = await host.selectMenu(
31759
+ ctx,
31760
+ title,
31761
+ [
31762
+ {
31763
+ value: "global",
31764
+ label: "Global default",
31765
+ description: global2 ? "On" : "Off"
31766
+ },
31767
+ {
31768
+ value: "project",
31769
+ label: "Current project",
31770
+ description: unavailable ?? (projectValue === void 0 ? `Inherit global (${global2 ? "on" : "off"})` : projectValue ? "On" : "Off")
31771
+ }
31772
+ ],
31773
+ selectedScope
31774
+ );
31775
+ if (!scope) return;
31776
+ selectedScope = scope;
31777
+ if (scope === "project" && unavailable) {
31778
+ ctx.ui.notify(unavailable, "warning");
31779
+ continue;
31541
31780
  }
31542
- let removalPolicy;
31543
- try {
31544
- removalPolicy = await host.getRemovalPreauthorization(ctx);
31545
- } catch {
31546
- }
31547
- let mergePolicy;
31781
+ const currentChoice = scope === "global" ? global2 ? "on" : "off" : projectValue === void 0 ? "inherit" : projectValue ? "on" : "off";
31782
+ const choice = await host.selectMenu(
31783
+ ctx,
31784
+ scope === "global" ? `Global ${title}` : `Project ${title}`,
31785
+ markCurrent(
31786
+ [
31787
+ ...scope === "project" ? [
31788
+ {
31789
+ value: "inherit",
31790
+ label: `Inherit global (${global2 ? "on" : "off"})`
31791
+ }
31792
+ ] : [],
31793
+ { value: "on", label: "On" },
31794
+ { value: "off", label: "Off" }
31795
+ ],
31796
+ currentChoice
31797
+ ),
31798
+ currentChoice
31799
+ );
31800
+ if (!choice) continue;
31801
+ const value2 = choice === "inherit" ? void 0 : choice === "on";
31548
31802
  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) {
31803
+ if (scope === "global") {
31804
+ if (value2 === global2 || value2 === void 0) continue;
31805
+ host.updateConfig(key, value2);
31806
+ } else {
31807
+ if (value2 === projectValue) continue;
31808
+ host.updateProjectOverride(ctx, key, value2);
31809
+ }
31558
31810
  ctx.ui.notify(
31559
- "Project overrides are unavailable because this project is not trusted.",
31560
- "warning"
31811
+ `${title}: ${value2 === void 0 ? "inherited" : value2 ? "on" : "off"} (${scope}).`
31561
31812
  );
31562
- return;
31813
+ } catch (error2) {
31814
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31563
31815
  }
31564
- if (overrideError && !removalPolicy) {
31565
- ctx.ui.notify(String(overrideError).replace(/^Error: /, ""), "error");
31566
- return;
31816
+ }
31817
+ },
31818
+ async openMergeSetting(ctx) {
31819
+ let selectedScope = "global";
31820
+ while (true) {
31821
+ const config = host.readConfig();
31822
+ const global2 = config.managerMergeEnabled;
31823
+ let policy;
31824
+ let unavailable = "";
31825
+ try {
31826
+ policy = await host.getRemovalPreauthorization(ctx);
31827
+ } catch (error2) {
31828
+ unavailable = String(error2).replace(/^Error: /, "");
31567
31829
  }
31568
- const fields = [
31569
- ...ctx.isProjectTrusted() ? [
31830
+ const repositoryPolicy = policy ? effectiveMergePolicy(config, policy.repoKey) : void 0;
31831
+ const label = (value2) => value2 === false ? "Off" : value2 === true ? "Fast-forward" : "Conflict-free merges";
31832
+ const scope = await host.selectMenu(
31833
+ ctx,
31834
+ "Local branch integration",
31835
+ [
31570
31836
  {
31571
- value: "autoActivateManager",
31572
- label: "Manager auto-start",
31573
- help: "Attempt Manager mode automatically on eligible future session starts."
31837
+ value: "global",
31838
+ label: "Global default",
31839
+ description: label(global2)
31574
31840
  },
31575
31841
  {
31576
- value: "contextRetirement",
31577
- label: "Context retirement",
31578
- help: "Retire managed-Agent sessions at automatic context pressure."
31842
+ value: "repository",
31843
+ label: "Current repository",
31844
+ description: repositoryPolicy ? `${!repositoryPolicy.enabled ? "Off" : repositoryPolicy.allowDivergence ? "Conflict-free merges" : "Fast-forward"} (${repositoryPolicy.source})` : "Unavailable"
31579
31845
  }
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);
31846
+ ],
31847
+ selectedScope
31848
+ );
31849
+ if (!scope) return;
31850
+ selectedScope = scope;
31851
+ if (scope === "repository") {
31852
+ if (!policy || !repositoryPolicy) {
31853
+ ctx.ui.notify(`Repository unavailable: ${unavailable}`, "warning");
31854
+ continue;
31855
+ }
31856
+ const override = config.managerMergeOverrides[policy.repoKey];
31857
+ const currentChoice2 = override === void 0 ? "inherit" : override === false ? "off" : override === true ? "fast-forward" : "divergent";
31602
31858
  const choice2 = await host.selectMenu(
31603
31859
  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"
31860
+ `Local branch integration \xB7 ${policy.repoKey}`,
31861
+ markCurrent(
31862
+ [
31863
+ {
31864
+ value: "inherit",
31865
+ label: `Inherit global (${label(global2)})`
31866
+ },
31867
+ { value: "off", label: "Off" },
31868
+ { value: "fast-forward", label: "Fast-forward only" },
31869
+ { value: "divergent", label: "Conflict-free merges" }
31870
+ ],
31871
+ currentChoice2
31872
+ ),
31873
+ currentChoice2
31613
31874
  );
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"
31875
+ if (!choice2) continue;
31876
+ const value2 = choice2 === "inherit" ? void 0 : choice2 === "off" ? false : choice2 === "fast-forward" ? true : "divergent";
31877
+ if (value2 === override) continue;
31878
+ try {
31879
+ const stored = await host.setRepositoryMergeOverride(
31880
+ value2,
31881
+ ctx,
31882
+ policy.identity,
31883
+ { global: global2, override }
31622
31884
  );
31885
+ if (stored)
31886
+ ctx.ui.notify(
31887
+ `Local branch integration updated for ${policy.repoKey}.`
31888
+ );
31889
+ } catch (error2) {
31890
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31623
31891
  }
31624
31892
  continue;
31625
31893
  }
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}`,
31894
+ const current = host.readConfig().managerMergeEnabled;
31895
+ const currentChoice = current === false ? "off" : current === true ? "fast-forward" : "divergent";
31896
+ const choice = await host.selectMenu(
31897
+ ctx,
31898
+ "Global Manager local merge",
31899
+ markCurrent(
31635
31900
  [
31636
- {
31637
- value: "inherit",
31638
- label: `Inherit global (${global3 === "divergent" ? "conflict-free merges" : global3 ? "fast-forward only" : "off"})`
31639
- },
31640
31901
  { value: "off", label: "Off" },
31641
31902
  { value: "fast-forward", label: "Fast-forward only" },
31642
31903
  { value: "divergent", label: "Conflict-free merges" }
31643
31904
  ],
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);
31905
+ currentChoice
31906
+ ),
31907
+ currentChoice
31908
+ );
31909
+ if (!choice) continue;
31910
+ const setting = choice === "off" ? false : choice === "fast-forward" ? true : "divergent";
31911
+ if (setting === current) continue;
31912
+ if (setting !== false && (current === false || setting === "divergent" && current !== "divergent")) {
31913
+ if (!await confirmMergeGrant(ctx, setting, "global settings") || ctx.signal?.aborted)
31914
+ continue;
31915
+ }
31916
+ if (ctx.signal?.aborted) continue;
31917
+ if (host.readConfig().managerMergeEnabled !== current) {
31661
31918
  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}.`
31919
+ "Global Manager integration policy changed; reopen the selector.",
31920
+ "warning"
31663
31921
  );
31664
31922
  continue;
31665
31923
  }
31666
- if (!ctx.isProjectTrusted() || overrideError || !overrides) continue;
31667
- const key = field;
31668
- const global2 = host.readConfig()[key];
31924
+ try {
31925
+ host.updateConfig("managerMergeEnabled", setting, current);
31926
+ } catch (error2) {
31927
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31928
+ continue;
31929
+ }
31930
+ ctx.ui.notify(
31931
+ `Global Manager local merge: ${setting === "divergent" ? "conflict-free merges" : setting ? "fast-forward only" : "off"}`
31932
+ );
31933
+ }
31934
+ },
31935
+ async openRemovalSetting(ctx) {
31936
+ try {
31937
+ const policy = await host.getRemovalPreauthorization(ctx);
31669
31938
  const choice = await host.selectMenu(
31670
31939
  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"
31940
+ `Worktree removal approval \xB7 ${policy.repoKey}`,
31941
+ markCurrent(
31942
+ [
31943
+ { value: "required", label: "Require approval for each removal" },
31944
+ {
31945
+ value: "skip",
31946
+ label: "Allow explicit removals without individual approval"
31947
+ }
31948
+ ],
31949
+ policy.enabled ? "skip" : "required"
31950
+ ),
31951
+ policy.enabled ? "skip" : "required"
31690
31952
  );
31691
- if (!choice) continue;
31692
- try {
31693
- host.updateProjectOverride(
31694
- ctx,
31695
- key,
31696
- choice === "inherit" ? void 0 : choice === "on"
31697
- );
31953
+ if (!choice || choice === "skip" === policy.enabled) return;
31954
+ const stored = await host.setRemovalPreauthorization(
31955
+ choice === "skip",
31956
+ ctx,
31957
+ policy.identity
31958
+ );
31959
+ if (stored)
31698
31960
  ctx.ui.notify(
31699
- `${key === "autoActivateManager" ? "Manager auto-start" : "Context retirement"} ${choice === "inherit" ? "inherited" : `set ${choice} for this project`}.`
31961
+ `Worktree removal approval ${choice === "skip" ? "skipped" : "required"} for ${policy.repoKey}.`
31700
31962
  );
31701
- } catch (error2) {
31702
- ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31703
- }
31963
+ } catch (error2) {
31964
+ ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
31704
31965
  }
31705
31966
  },
31706
31967
  async openAgentsMenu(ctx) {
31707
31968
  let selectedSection = "running";
31708
31969
  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);
31970
+ let running = "Unavailable";
31971
+ try {
31972
+ const snapshot = await host.loadStatusSnapshot(
31973
+ ctx,
31974
+ host.controller.sessionSignal()
31975
+ );
31976
+ running = host.formatStatusCounts(snapshot.agents) || "0";
31977
+ } catch {
31978
+ if (ctx.signal?.aborted) return;
31979
+ }
31715
31980
  const selected = await host.selectMenu(
31716
31981
  ctx,
31717
- "Agents",
31982
+ "Agents & definitions",
31718
31983
  [
31719
31984
  {
31720
31985
  value: "running",
31721
- label: "Running",
31986
+ label: "Running agents",
31722
31987
  description: running,
31723
31988
  help: "Focus a live managed Agent."
31724
31989
  },
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
- },
31990
+ { value: "agent-definitions", label: "Agent definitions" },
31991
+ { value: "coordinator-profiles", label: "Coordinator profiles" },
31731
31992
  {
31732
31993
  value: "stop-all",
31733
- label: "Stop all\u2026",
31994
+ label: "Stop all agents\u2026",
31734
31995
  help: "Emergency stop for the owned Agent tree. Active work or pending results may be discarded."
31735
31996
  }
31736
31997
  ],
@@ -31739,7 +32000,10 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31739
32000
  if (!selected) return;
31740
32001
  selectedSection = selected;
31741
32002
  if (selected === "running") await this.openRunningAgentsMenu(ctx);
31742
- else if (selected === "layout") await this.openPlacementMenu(ctx);
32003
+ else if (selected === "agent-definitions")
32004
+ await this.openDefinitionsMenu(ctx, "agents");
32005
+ else if (selected === "coordinator-profiles")
32006
+ await this.openDefinitionsMenu(ctx, "roles");
31743
32007
  else if (selected === "stop-all") await this.confirmAndStopAll(ctx);
31744
32008
  }
31745
32009
  },
@@ -31747,36 +32011,37 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31747
32011
  let selectedSection = "execution";
31748
32012
  while (true) {
31749
32013
  const execution = host.leadExecutionPresentation();
32014
+ const showLeadMode = host.isLead() && !execution.managed;
32015
+ if (!showLeadMode && selectedSection === "execution")
32016
+ selectedSection = "agents";
31750
32017
  const selected = await host.selectMenu(
31751
32018
  ctx,
31752
32019
  `Pi Herdsman \xB7 v${host.version}`,
31753
32020
  [
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
- },
32021
+ ...showLeadMode ? [
32022
+ {
32023
+ value: "execution",
32024
+ label: "Lead mode",
32025
+ description: execution.mode,
32026
+ help: "Choose whether this Lead works directly or primarily delegates tasks."
32027
+ }
32028
+ ] : [],
31760
32029
  {
31761
32030
  value: "agents",
31762
- label: "Agents",
31763
- help: "View and manage background Agents."
32031
+ label: "Agents & definitions",
32032
+ help: "Manage running Agents and inspect definitions."
31764
32033
  },
31765
32034
  {
31766
32035
  value: "manager",
31767
- label: "Project manager",
31768
- description: host.roleActive("manager") ? "active" : void 0,
32036
+ label: "Project management",
32037
+ description: host.roleActive("manager") ? "Active" : "Inactive",
31769
32038
  help: "Coordinate independent project work across Git branches."
31770
32039
  },
31771
32040
  {
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."
32041
+ value: "chief",
32042
+ label: "Chief coordination",
32043
+ description: host.roleActive("chief") ? "Active" : "Inactive",
32044
+ help: "Supervise Managers and unassigned Leads across Herdsman."
31780
32045
  },
31781
32046
  {
31782
32047
  value: "settings",
@@ -31784,10 +32049,9 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31784
32049
  help: "Change Herdsman preferences."
31785
32050
  },
31786
32051
  {
31787
- value: "advanced",
31788
- label: "Advanced\u2026",
31789
- description: host.roleActive("chief") ? "Chief active" : void 0,
31790
- help: "Open advanced Herdsman coordination controls."
32052
+ value: "stats",
32053
+ label: "Usage & costs",
32054
+ help: "View token usage and model costs for this session and its managed work."
31791
32055
  }
31792
32056
  ],
31793
32057
  selectedSection
@@ -31799,46 +32063,50 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
31799
32063
  else if (selected === "manager")
31800
32064
  await this.openRoleMenu("manager", ctx);
31801
32065
  else if (selected === "stats") await this.showSessionStats(ctx);
31802
- else if (selected === "definitions")
31803
- await this.openDefinitionsMenu(ctx);
31804
32066
  else if (selected === "settings") await this.openSettingsMenu(ctx);
31805
- else if (selected === "advanced") await this.openAdvancedMenu(ctx);
32067
+ else if (selected === "chief") await this.openRoleMenu("chief", ctx);
31806
32068
  }
31807
32069
  },
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
32070
  async openRoleMenu(role2, ctx) {
31820
- const active = host.roleActive(role2);
31821
32071
  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);
32072
+ const title = role2 === "manager" ? "Project management" : "Chief mode";
32073
+ let selectedAction;
32074
+ while (true) {
32075
+ const active = host.roleActive(role2);
32076
+ const selected = await host.selectMenu(
32077
+ ctx,
32078
+ title,
32079
+ active ? [
32080
+ {
32081
+ value: "overview",
32082
+ label: role2 === "manager" ? "Project overview" : "Overview"
32083
+ },
32084
+ ...role2 === "manager" ? [
32085
+ {
32086
+ value: "pending-removals",
32087
+ label: "Pending removal requests"
32088
+ }
32089
+ ] : [],
32090
+ {
32091
+ value: "refresh",
32092
+ label: role2 === "manager" ? "Refresh Manager profile" : "Refresh profile",
32093
+ help: "Apply definition changes after the current turn becomes idle."
32094
+ },
32095
+ { value: "leave", label: `Leave ${name} mode` }
32096
+ ] : [{ value: "start", label: `Start ${name} mode` }],
32097
+ selectedAction
32098
+ );
32099
+ if (!selected) return;
32100
+ selectedAction = selected;
32101
+ if (selected === "overview" || selected === "start")
32102
+ await this.runRoleCommand(role2, "", ctx);
32103
+ else if (selected === "pending-removals")
32104
+ await host.reviewPendingRemoval(ctx);
32105
+ else if (selected === "refresh")
32106
+ await this.runRoleCommand(role2, "refresh", ctx);
32107
+ else if (selected === "leave")
32108
+ await this.runRoleCommand(role2, "leave", ctx);
32109
+ }
31842
32110
  },
31843
32111
  async runRoleCommand(role2, rawArgs, ctx) {
31844
32112
  const args = rawArgs.trim().split(/\s+/u).filter(Boolean);
@@ -36527,6 +36795,7 @@ function registerLeadRuntime(pi, options) {
36527
36795
  removeProjectMessagesForAssignment: options.roleTransitionHost.removeProjectMessagesForAssignment,
36528
36796
  appendDurableError: options.herdRunServices.appendDurableError,
36529
36797
  writeProjectAssignment: writeProjectAssignment2,
36798
+ listAgents: options.identityHost.listAgents,
36530
36799
  liveAgent,
36531
36800
  liveLead,
36532
36801
  currentManager: (...args) => roleTransitions.currentManager(...args),
@@ -36600,7 +36869,8 @@ function registerLeadRuntime(pi, options) {
36600
36869
  pi,
36601
36870
  persistStopClosures: (ctx, closures) => projectRuntime.persistStopClosures(ctx, closures),
36602
36871
  getRemovalPreauthorization: (ctx) => projectRuntime.getRemovalPreauthorization(ctx),
36603
- setRemovalPreauthorization: (enabled, ctx) => projectRuntime.setRemovalPreauthorization(enabled, ctx),
36872
+ setRemovalPreauthorization: (...args) => projectRuntime.setRemovalPreauthorization(...args),
36873
+ setRepositoryMergeOverride: (...args) => projectRuntime.setRepositoryMergeOverride(...args),
36604
36874
  collectOwnedSessionUsage: (ctx) => {
36605
36875
  const managerActive = activeLeadRole(leadRuntime) === "manager" && !leadRuntime.roleSuspended;
36606
36876
  if (!managerActive)
@@ -37105,12 +37375,21 @@ function registerLeadRuntime(pi, options) {
37105
37375
  }
37106
37376
  const restoredExecution = currentExecution();
37107
37377
  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));
37378
+ const projection = inheritedProjectionFor(
37379
+ mode,
37380
+ restoredExecution.definition,
37381
+ baseline,
37382
+ leadToolState.projectLeadTools(baseline, restoredExecution.definition)
37383
+ );
37384
+ if (projection) {
37385
+ const excluded = (name) => projection.excluded.some(
37386
+ (pattern) => matchesToolPattern(pattern, name)
37387
+ );
37111
37388
  leadToolState.setLeadTools(
37112
37389
  leadToolState.normalizeBaseTools([
37113
- ...restoredTools.filter((name) => !excluded(name)),
37390
+ ...restoredTools.filter(
37391
+ (name) => !excluded(name) && !projection.injected.includes(name)
37392
+ ),
37114
37393
  ...baseline.filter(excluded)
37115
37394
  ])
37116
37395
  );
@@ -42473,7 +42752,8 @@ var LEAD_COORDINATION_TOOLS = [
42473
42752
  var CHIEF_TOOLS = STAFF_TOOLS;
42474
42753
  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
42754
  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}
42755
+ var COMMON_LEAD_GUIDANCE = `${AUTHORITY_GUIDANCE}
42756
+ ${LEAD_SCOPE_DESCRIPTION}
42477
42757
  ${INTERNAL_MESSAGE_PROVENANCE_GUIDANCE}
42478
42758
  ${LEAD_SUPERVISOR_PEER_GUIDANCE}`;
42479
42759
  var ORDINARY_LEAD_CHARTER = `## Lead role
@@ -42501,6 +42781,7 @@ ${MANAGED_LEAD_GUIDANCE}`;
42501
42781
  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
42782
  var MANAGER_ROLE_CONTRACT = `## Manager role
42503
42783
  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.
42784
+ ${AUTHORITY_GUIDANCE}
42504
42785
  ${INTERNAL_MESSAGE_PROVENANCE_GUIDANCE}
42505
42786
  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
42787
  Subject to existing writer and authority safeguards, overlapping assignments
@@ -42528,6 +42809,7 @@ function formatMessageLimit(bytes) {
42528
42809
  }
42529
42810
  var CHIEF_ROLE_CONTRACT = `## Chief role
42530
42811
  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.
42812
+ ${AUTHORITY_GUIDANCE}
42531
42813
  ${INTERNAL_MESSAGE_PROVENANCE_GUIDANCE}
42532
42814
  ${AGENT_EXECUTION_OWNERSHIP_GUIDANCE}
42533
42815
  ${AGENT_UNRESOLVED_GUIDANCE}
@@ -43578,12 +43860,56 @@ ${summary}`,
43578
43860
  { triggerTurn: false }
43579
43861
  );
43580
43862
  };
43863
+ const reviewPendingRemoval = async (ctx) => {
43864
+ const pending = projectRuntime.listPendingRemovals(ctx);
43865
+ if (!pending.length) {
43866
+ ctx.ui.notify("There are no pending worktree removals.", "info");
43867
+ return;
43868
+ }
43869
+ const selected = await selectMenu(
43870
+ ctx,
43871
+ "Review pending worktree removal",
43872
+ pending.map(({ branch, checkoutPath }) => ({
43873
+ value: branch,
43874
+ label: `${branch} \xB7 ${checkoutPath}`
43875
+ }))
43876
+ );
43877
+ if (!selected) return;
43878
+ const request = pending.find((item) => item.branch === selected);
43879
+ if (!request) throw new Error("Pending removal is unavailable");
43880
+ const action = await selectMenu(ctx, `Pending removal \xB7 ${selected}`, [
43881
+ { value: "approve", label: "Approve removal\u2026" },
43882
+ { value: "dismiss", label: "Dismiss request" }
43883
+ ]);
43884
+ if (!action) return;
43885
+ if (action === "dismiss") {
43886
+ if (!projectRuntime.cancelPendingRemoval(request, ctx))
43887
+ throw new Error("Pending removal changed; review the new request");
43888
+ ctx.ui.notify(
43889
+ `Pending removal of ${request.branch} dismissed.`,
43890
+ "info"
43891
+ );
43892
+ return;
43893
+ }
43894
+ const result = await projectRuntime.approvePendingRemoval(request, ctx);
43895
+ ctx.ui.notify(
43896
+ result.content[0]?.text ?? "Removal finished.",
43897
+ result.details.ok || "cancelled" in result.details && result.details.cancelled ? "info" : "warning"
43898
+ );
43899
+ return;
43900
+ };
43581
43901
  let leadCommandRuntime;
43582
43902
  const leadCommandHost = {
43583
43903
  pi,
43904
+ reviewPendingRemoval,
43584
43905
  persistStopClosures: (ctx, closures) => projectRuntime.persistStopClosures(ctx, closures),
43585
43906
  getRemovalPreauthorization: (ctx) => projectRuntime.getRemovalPreauthorization(ctx),
43586
- setRemovalPreauthorization: (enabled, ctx) => projectRuntime.setRemovalPreauthorization(enabled, ctx),
43907
+ setRemovalPreauthorization: (enabled, ctx, expectedManager) => projectRuntime.setRemovalPreauthorization(
43908
+ enabled,
43909
+ ctx,
43910
+ expectedManager
43911
+ ),
43912
+ setRepositoryMergeOverride: (...args) => projectRuntime.setRepositoryMergeOverride(...args),
43587
43913
  runHerdr,
43588
43914
  presentStopSummary,
43589
43915
  version: HERDSMAN_VERSION,
@@ -43626,8 +43952,8 @@ ${summary}`,
43626
43952
  input: (ctx, label) => ctx.ui.input(label),
43627
43953
  updateSpawnPlacement: (placement) => updateConfig("spawnPlacement", placement),
43628
43954
  updateMessageLimit: (key, value2) => updateConfig(key, value2),
43629
- updateConfig: (key, value2) => {
43630
- updateConfig(key, value2);
43955
+ updateConfig: (key, value2, expectedManagerMergeEnabled) => {
43956
+ updateConfig(key, value2, expectedManagerMergeEnabled);
43631
43957
  if (key === "statusWidgetMaxRows") {
43632
43958
  const rows = value2 === void 0 ? DEFAULT_STATUS_WIDGET_MAX_ROWS : value2;
43633
43959
  leadRuntimes.statusRuntime?.setStatusWidgetMaxRows(rows);
@@ -43654,7 +43980,7 @@ ${summary}`,
43654
43980
  "leave",
43655
43981
  "remove",
43656
43982
  "forget",
43657
- "remove-preapproval"
43983
+ "removal-confirmation"
43658
43984
  ];
43659
43985
  const input = prefix.trimStart();
43660
43986
  const [command, branchPrefix] = input.split(/\s+/u);
@@ -43663,9 +43989,9 @@ ${summary}`,
43663
43989
  value: value2,
43664
43990
  label: value2
43665
43991
  }));
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}`,
43992
+ if (command === "removal-confirmation")
43993
+ return input.includes(" ") && input.trim().split(/\s+/u).length <= 2 ? ["required", "skip"].filter((value2) => value2.startsWith(branchPrefix ?? "")).map((value2) => ({
43994
+ value: `removal-confirmation ${value2}`,
43669
43995
  label: value2
43670
43996
  })) : null;
43671
43997
  if (command !== "remove" && command !== "forget")
@@ -43688,84 +44014,36 @@ ${summary}`,
43688
44014
  },
43689
44015
  handler: async (rawArgs, ctx) => {
43690
44016
  const args = rawArgs.trim().split(/\s+/u).filter(Boolean);
43691
- if (args[0] === "remove-preapproval") {
44017
+ if (args[0] === "removal-confirmation") {
43692
44018
  if (args.length === 1) {
43693
44019
  const policy = await projectRuntime.getRemovalPreauthorization(ctx);
43694
44020
  ctx.ui.notify(
43695
- `Worktree removal confirmation: ${policy.enabled ? "skipped" : "required"} for ${policy.repoKey}.`,
44021
+ `Worktree removal approval: ${policy.enabled ? "Skipped" : "Required"} for ${policy.repoKey}.`,
43696
44022
  "info"
43697
44023
  );
43698
44024
  return;
43699
44025
  }
43700
- if (args.length !== 2 || !["on", "off"].includes(args[1])) {
44026
+ if (args.length !== 2 || !["required", "skip"].includes(args[1])) {
43701
44027
  ctx.ui.notify(
43702
- "Usage: /manager remove-preapproval <on|off>",
44028
+ "Usage: /manager removal-confirmation [required|skip]",
43703
44029
  "error"
43704
44030
  );
43705
44031
  return;
43706
44032
  }
43707
- const enabled = args[1] === "on";
44033
+ const enabled = args[1] === "skip";
43708
44034
  const stored = await projectRuntime.setRemovalPreauthorization(
43709
44035
  enabled,
43710
44036
  ctx
43711
44037
  );
43712
44038
  ctx.ui.notify(
43713
- `Skip worktree removal confirmation for ${enabled ? "this repository is On" : "this repository is Off"}${stored ? "." : "; setting unchanged."}`,
44039
+ stored ? `Worktree removal approval: ${enabled ? "Skipped" : "Required"}.` : "Worktree removal approval setting unchanged.",
43714
44040
  stored ? "info" : "warning"
43715
44041
  );
43716
44042
  return;
43717
44043
  }
43718
44044
  if (args[0] === "remove") {
43719
44045
  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
- );
44046
+ await reviewPendingRemoval(ctx);
43769
44047
  return;
43770
44048
  }
43771
44049
  if (args.length !== 2) {