pi-herdsman 0.34.0 → 0.34.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 +692 -205
- package/dist/index.js.map +3 -3
- package/dist/peer-bridge.js.map +2 -2
- package/docs/guides/handoffs.md +9 -0
- package/docs/guides/recovery.md +8 -0
- package/docs/reference/agent-states.md +8 -0
- package/docs/reference/agent.md +20 -1
- package/docs/reference/status-widget.md +27 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1139,6 +1139,7 @@ function validate(value2, kind) {
|
|
|
1139
1139
|
"status",
|
|
1140
1140
|
"text",
|
|
1141
1141
|
"error",
|
|
1142
|
+
"resultBindings",
|
|
1142
1143
|
"contextUsage",
|
|
1143
1144
|
"completedAt"
|
|
1144
1145
|
];
|
|
@@ -1294,6 +1295,8 @@ function validate(value2, kind) {
|
|
|
1294
1295
|
if (v.status !== "completed" && v.status !== "failed")
|
|
1295
1296
|
throw new Error("Invalid result status");
|
|
1296
1297
|
finite("completedAt");
|
|
1298
|
+
if (v.resultBindings !== void 0 && (!Array.isArray(v.resultBindings) || !v.resultBindings.every(isResultBinding) || new Set(v.resultBindings.map((binding) => binding.ref)).size !== v.resultBindings.length))
|
|
1299
|
+
throw new Error("Invalid or conflicting result bindings");
|
|
1297
1300
|
if (v.status === "completed" && (typeof v.text !== "string" || !v.text.trim() || v.error !== void 0))
|
|
1298
1301
|
throw new Error("Invalid completed result");
|
|
1299
1302
|
if (v.status === "failed") {
|
|
@@ -1309,6 +1312,8 @@ function validate(value2, kind) {
|
|
|
1309
1312
|
throw new Error("Invalid failed result");
|
|
1310
1313
|
if (v.text !== void 0)
|
|
1311
1314
|
throw new Error("Failed result cannot contain text");
|
|
1315
|
+
if (v.resultBindings !== void 0)
|
|
1316
|
+
throw new Error("Failed result cannot contain result bindings");
|
|
1312
1317
|
}
|
|
1313
1318
|
if (v.contextUsage !== void 0) {
|
|
1314
1319
|
const usage = v.contextUsage;
|
|
@@ -2665,7 +2670,12 @@ function agentLaunchArgs(agent, options2) {
|
|
|
2665
2670
|
}
|
|
2666
2671
|
if (sharedPromptPath) args.push("--append-system-prompt", sharedPromptPath);
|
|
2667
2672
|
const requiredTools = [
|
|
2668
|
-
...managedAgent ? agentDefinitionDelegationEnabled(agent) ? [
|
|
2673
|
+
...managedAgent ? agentDefinitionDelegationEnabled(agent) ? [
|
|
2674
|
+
...AGENT_COORDINATION_TOOLS,
|
|
2675
|
+
"ask_owner",
|
|
2676
|
+
"read_evidence",
|
|
2677
|
+
"attach_handoff"
|
|
2678
|
+
] : ["ask_owner", "read_evidence", "attach_handoff"] : [],
|
|
2669
2679
|
...options2.requiredTools ?? []
|
|
2670
2680
|
].filter((tool, index, all) => all.indexOf(tool) === index);
|
|
2671
2681
|
const policy = configuredToolPolicy(agent, requiredTools);
|
|
@@ -2803,10 +2813,11 @@ import {
|
|
|
2803
2813
|
mkdirSync as mkdirSync5,
|
|
2804
2814
|
openSync as openSync5,
|
|
2805
2815
|
readSync as readSync2,
|
|
2806
|
-
realpathSync as realpathSync2
|
|
2816
|
+
realpathSync as realpathSync2,
|
|
2817
|
+
statSync as statSync4
|
|
2807
2818
|
} from "node:fs";
|
|
2808
2819
|
import { createConnection } from "node:net";
|
|
2809
|
-
import { join as join5, resolve as resolve3 } from "node:path";
|
|
2820
|
+
import { isAbsolute as isAbsolute2, join as join5, resolve as resolve3 } from "node:path";
|
|
2810
2821
|
import { StringDecoder } from "node:string_decoder";
|
|
2811
2822
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
2812
2823
|
function parseHerdrVersion(value2) {
|
|
@@ -3001,6 +3012,66 @@ async function runHerdr(pi, ctx, args, options2 = {}) {
|
|
|
3001
3012
|
);
|
|
3002
3013
|
return stdoutJson.result;
|
|
3003
3014
|
}
|
|
3015
|
+
function sameDirectory(left, right) {
|
|
3016
|
+
try {
|
|
3017
|
+
const leftPath = realpathSync2(left);
|
|
3018
|
+
const rightPath = realpathSync2(right);
|
|
3019
|
+
const leftStat = statSync4(leftPath, { bigint: true });
|
|
3020
|
+
const rightStat = statSync4(rightPath, { bigint: true });
|
|
3021
|
+
if (!leftStat.isDirectory() || !rightStat.isDirectory()) return false;
|
|
3022
|
+
if (leftStat.dev !== 0n && rightStat.dev !== 0n && leftStat.ino !== 0n && rightStat.ino !== 0n)
|
|
3023
|
+
return leftStat.dev === rightStat.dev && leftStat.ino === rightStat.ino;
|
|
3024
|
+
return leftPath === rightPath;
|
|
3025
|
+
} catch {
|
|
3026
|
+
return false;
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
async function localRepositoryScope(pi, ctx, workspaceId, signal) {
|
|
3030
|
+
const listed = await runHerdr(
|
|
3031
|
+
pi,
|
|
3032
|
+
ctx,
|
|
3033
|
+
["worktree", "list", "--cwd", ctx.cwd],
|
|
3034
|
+
{ signal }
|
|
3035
|
+
);
|
|
3036
|
+
const workspace2 = (await runHerdr(pi, ctx, ["workspace", "get", workspaceId], { signal }))?.workspace;
|
|
3037
|
+
const source = listed?.source;
|
|
3038
|
+
if (workspace2?.workspace_id !== workspaceId || typeof source?.repo_key !== "string" || !isAbsolute2(source.repo_key) || typeof source?.repo_name !== "string" || !source.repo_name || !Array.isArray(listed?.worktrees))
|
|
3039
|
+
throw new Error("Herdr local repository identity is unavailable");
|
|
3040
|
+
const gitPath = async (argument) => {
|
|
3041
|
+
const result = await pi.exec(
|
|
3042
|
+
"git",
|
|
3043
|
+
["rev-parse", "--path-format=absolute", argument],
|
|
3044
|
+
{
|
|
3045
|
+
cwd: ctx.cwd,
|
|
3046
|
+
signal,
|
|
3047
|
+
timeout: 1e4
|
|
3048
|
+
}
|
|
3049
|
+
);
|
|
3050
|
+
const path = String(result.stdout ?? "").trim();
|
|
3051
|
+
if (result.code !== 0 || result.killed || result.stderr?.trim() || !isAbsolute2(path))
|
|
3052
|
+
throw new Error("Git local repository identity is unavailable");
|
|
3053
|
+
return realpathSync2(path);
|
|
3054
|
+
};
|
|
3055
|
+
const [checkoutPath, gitDir, commonDir] = await Promise.all([
|
|
3056
|
+
gitPath("--show-toplevel"),
|
|
3057
|
+
gitPath("--git-dir"),
|
|
3058
|
+
gitPath("--git-common-dir")
|
|
3059
|
+
]);
|
|
3060
|
+
const isPrimary = sameDirectory(gitDir, commonDir);
|
|
3061
|
+
if (!sameDirectory(commonDir, source.repo_key))
|
|
3062
|
+
throw new Error("Herdr repository does not match the current checkout");
|
|
3063
|
+
const membership = workspace2.worktree;
|
|
3064
|
+
if (membership != null && (typeof membership.repo_key !== "string" || typeof membership.checkout_path !== "string" || typeof membership.is_linked_worktree !== "boolean" || !sameDirectory(membership.repo_key, commonDir) || !sameDirectory(membership.checkout_path, checkoutPath) || membership.is_linked_worktree !== !isPrimary))
|
|
3065
|
+
throw new Error(
|
|
3066
|
+
"Herdr workspace association does not match the current checkout"
|
|
3067
|
+
);
|
|
3068
|
+
return {
|
|
3069
|
+
repoKey: source.repo_key,
|
|
3070
|
+
repoName: source.repo_name,
|
|
3071
|
+
checkoutPath,
|
|
3072
|
+
isPrimary
|
|
3073
|
+
};
|
|
3074
|
+
}
|
|
3004
3075
|
async function worktreeGroupScope(pi, ctx, workspaceId, signal, timeout) {
|
|
3005
3076
|
const listed = await runHerdr(
|
|
3006
3077
|
pi,
|
|
@@ -4842,7 +4913,7 @@ import {
|
|
|
4842
4913
|
writeFileSync as writeFileSync3
|
|
4843
4914
|
} from "node:fs";
|
|
4844
4915
|
import { homedir as homedir3 } from "node:os";
|
|
4845
|
-
import { basename as basename5, dirname as dirname5, isAbsolute as
|
|
4916
|
+
import { basename as basename5, dirname as dirname5, isAbsolute as isAbsolute3, join as join6, relative, sep as sep2 } from "node:path";
|
|
4846
4917
|
function populateMenuFrame(container, theme, title, body, footer, help) {
|
|
4847
4918
|
container.clear();
|
|
4848
4919
|
container.addChild(new DynamicBorder((line) => theme.fg("border", line)));
|
|
@@ -5012,8 +5083,8 @@ function lifecycleMarker(state) {
|
|
|
5012
5083
|
function compactModelToken(model) {
|
|
5013
5084
|
return model?.split("/").at(-1) ?? "";
|
|
5014
5085
|
}
|
|
5015
|
-
function activityIndicator(state, frame) {
|
|
5016
|
-
return
|
|
5086
|
+
function activityIndicator(state, frame, animate = true) {
|
|
5087
|
+
return animate && animates(state) ? spinner[frame % spinner.length] : lifecycleMarker(state);
|
|
5017
5088
|
}
|
|
5018
5089
|
function managedExecutionLabel(lifecycle) {
|
|
5019
5090
|
return lifecycle === "retired" || lifecycle === "unavailable" ? `managed \xB7 ${lifecycle}` : "managed";
|
|
@@ -5029,11 +5100,15 @@ function buildStatusRows(agents, options2) {
|
|
|
5029
5100
|
...agent.paneId ? { paneId: agent.paneId } : {},
|
|
5030
5101
|
...agent.sessionId ? { sessionId: agent.sessionId } : {},
|
|
5031
5102
|
tree,
|
|
5032
|
-
indicator: activityIndicator(
|
|
5103
|
+
indicator: activityIndicator(
|
|
5104
|
+
agent.state,
|
|
5105
|
+
options2.frame ?? 0,
|
|
5106
|
+
options2.animate
|
|
5107
|
+
),
|
|
5033
5108
|
definition: agent.definition || "?",
|
|
5034
5109
|
agentLabel: agent.label,
|
|
5035
5110
|
state: lifecycleLabel(agent.state),
|
|
5036
|
-
elapsed: formatElapsed(agent.startedAt, options2.now) ?? "",
|
|
5111
|
+
elapsed: options2.now === void 0 ? "" : formatElapsed(agent.startedAt, options2.now) ?? "",
|
|
5037
5112
|
model: compactModelToken(agent.model),
|
|
5038
5113
|
thinking: agent.thinking ?? "",
|
|
5039
5114
|
context: Number.isInteger(agent.contextPercent) ? `${agent.contextPercent}%` : "",
|
|
@@ -5090,7 +5165,7 @@ function layoutWidth(columns, layout) {
|
|
|
5090
5165
|
function renderIdentity(row, definitionWidth, identityWidth, theme) {
|
|
5091
5166
|
const definition = padVisible(row.definition, definitionWidth);
|
|
5092
5167
|
const raw = `${row.tree}${row.indicator} ${definition} ${row.agentLabel}`;
|
|
5093
|
-
return themed(theme, "muted",
|
|
5168
|
+
return themed(theme, "muted", row.tree) + themed(theme, STATE_COLOR[row.state] ?? "muted", `${row.indicator} `) + (theme?.bold?.(definition) ?? definition) + themed(theme, "muted", ` ${row.agentLabel}`) + " ".repeat(Math.max(0, identityWidth - visibleWidth(raw)));
|
|
5094
5169
|
}
|
|
5095
5170
|
function renderStatusLine(row, columns, layout, width, theme) {
|
|
5096
5171
|
const { definitionWidth, widths } = columns;
|
|
@@ -5218,12 +5293,12 @@ function presentationReports(reports) {
|
|
|
5218
5293
|
);
|
|
5219
5294
|
}
|
|
5220
5295
|
function classifySupervisedLead(lead) {
|
|
5221
|
-
if (lead.runtimeState === "working"
|
|
5296
|
+
if (lead.runtimeState === "working" || lead.runtimeState === "starting" || lead.runtimeState === "settling")
|
|
5297
|
+
return "ACTIVE/TRANSITIONAL";
|
|
5222
5298
|
if (lead.runtimeState === "blocked") return "BLOCKED";
|
|
5223
|
-
if (lead.runtimeState === "unknown") return "UNKNOWN";
|
|
5224
5299
|
if (lead.runtimeState === "idle" || lead.runtimeState === "done")
|
|
5225
5300
|
return "IDLE/DONE";
|
|
5226
|
-
return "
|
|
5301
|
+
return "UNRESOLVED";
|
|
5227
5302
|
}
|
|
5228
5303
|
function buildSupervisedLeadDisplays(leads) {
|
|
5229
5304
|
const byDisplay = /* @__PURE__ */ new Map();
|
|
@@ -5304,14 +5379,6 @@ function groupSupervisedLeads(leads) {
|
|
|
5304
5379
|
groups.get(group).sort((a, b) => a.displayName.localeCompare(b.displayName));
|
|
5305
5380
|
return groups;
|
|
5306
5381
|
}
|
|
5307
|
-
function groupOrderedSupervisedLeads(leads) {
|
|
5308
|
-
const groups = new Map(
|
|
5309
|
-
SUPERVISION_GROUPS.map((group) => [group, []])
|
|
5310
|
-
);
|
|
5311
|
-
for (const lead of leads)
|
|
5312
|
-
groups.get(classifySupervisedLead(lead)).push(lead);
|
|
5313
|
-
return groups;
|
|
5314
|
-
}
|
|
5315
5382
|
function orderedSupervisionLeads(leads) {
|
|
5316
5383
|
const displays = buildSupervisedLeadDisplays(leads);
|
|
5317
5384
|
const groups = groupSupervisedLeads(displays);
|
|
@@ -5359,33 +5426,67 @@ function managerSupervisionItems(snapshot) {
|
|
|
5359
5426
|
}))
|
|
5360
5427
|
];
|
|
5361
5428
|
}
|
|
5429
|
+
function supervisionActivityMarker(state, activeAgents) {
|
|
5430
|
+
return (state === "idle" || state === "done") && activeAgents > 0 ? "\u25C9" : lifecycleMarker(state);
|
|
5431
|
+
}
|
|
5362
5432
|
function supervisionLeadMarker(lead) {
|
|
5363
|
-
return (
|
|
5433
|
+
return supervisionActivityMarker(
|
|
5434
|
+
lead.runtimeState,
|
|
5435
|
+
lead.agentCounts?.active ?? 0
|
|
5436
|
+
);
|
|
5364
5437
|
}
|
|
5365
5438
|
function lifecycleColor(state) {
|
|
5366
5439
|
return STATE_COLOR[lifecycleLabel(state)] ?? "muted";
|
|
5367
5440
|
}
|
|
5441
|
+
function supervisionLeadColor(lead) {
|
|
5442
|
+
return supervisionLeadMarker(lead) === "\u25C9" ? "accent" : lifecycleColor(lead.runtimeState);
|
|
5443
|
+
}
|
|
5368
5444
|
function identifyingLabelVisible(text, label, width, expectedStart) {
|
|
5369
5445
|
if (expectedStart !== void 0)
|
|
5370
5446
|
return label.length > 0 && expectedStart + visibleWidth(label) <= width;
|
|
5371
5447
|
const start = text.lastIndexOf(label);
|
|
5372
5448
|
return label.length > 0 && start >= 0 && visibleWidth(text.slice(0, start + label.length)) <= width;
|
|
5373
5449
|
}
|
|
5450
|
+
function renderSupervisionHeader(label, status, width, theme) {
|
|
5451
|
+
const marker = themed(theme, "success", "\u25CF");
|
|
5452
|
+
const markerWidth = visibleWidth("\u25CF");
|
|
5453
|
+
const identity = themed(theme, "muted", label);
|
|
5454
|
+
const freshnessText = status === "fresh" ? "" : `\xB7 ${status}`;
|
|
5455
|
+
const freshness = freshnessText ? themed(theme, "warning", freshnessText) : "";
|
|
5456
|
+
if (!freshness)
|
|
5457
|
+
return safeLine(
|
|
5458
|
+
`${marker} ${truncateToWidth(identity, Math.max(0, width - markerWidth - 1), "\u2026")}`,
|
|
5459
|
+
width
|
|
5460
|
+
);
|
|
5461
|
+
const freshnessWidth = visibleWidth(freshnessText);
|
|
5462
|
+
const identityWidth = width - markerWidth - freshnessWidth - 2;
|
|
5463
|
+
if (identityWidth > 0)
|
|
5464
|
+
return safeLine(
|
|
5465
|
+
`${marker} ${truncateToWidth(identity, identityWidth, "\u2026")} ${freshness}`,
|
|
5466
|
+
width
|
|
5467
|
+
);
|
|
5468
|
+
if (width >= markerWidth + visibleWidth(` ${status}`))
|
|
5469
|
+
return safeLine(`${marker} ${themed(theme, "warning", status)}`, width);
|
|
5470
|
+
return safeLine(
|
|
5471
|
+
`${truncateToWidth(marker, width, "")}${themed(
|
|
5472
|
+
theme,
|
|
5473
|
+
"warning",
|
|
5474
|
+
truncateToWidth(status, Math.max(0, width - markerWidth), "\u2026")
|
|
5475
|
+
)}`,
|
|
5476
|
+
width
|
|
5477
|
+
);
|
|
5478
|
+
}
|
|
5374
5479
|
function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
5375
5480
|
const status = options2.status ?? "fresh";
|
|
5376
5481
|
const role2 = options2.role ?? "chief";
|
|
5377
5482
|
if (status === "unavailable")
|
|
5378
5483
|
return [
|
|
5379
5484
|
{
|
|
5380
|
-
text:
|
|
5381
|
-
`${themed(options2.theme, "success", "\u25CF")} ${themed(options2.theme, "muted", `${role2} \xB7 unavailable`)}`,
|
|
5382
|
-
width
|
|
5383
|
-
)
|
|
5485
|
+
text: renderSupervisionHeader(role2, status, width, options2.theme)
|
|
5384
5486
|
}
|
|
5385
5487
|
];
|
|
5386
5488
|
const displays = orderedSupervisionLeads(presentationReports(reports));
|
|
5387
|
-
const
|
|
5388
|
-
const ordinary = SUPERVISION_GROUPS.flatMap((group) => groups.get(group));
|
|
5489
|
+
const ordinary = displays;
|
|
5389
5490
|
const cap = options2.ordinaryCap ?? 6;
|
|
5390
5491
|
const shown = ordinary.slice(0, Math.max(0, cap));
|
|
5391
5492
|
const hidden = ordinary.length - Math.min(ordinary.length, Math.max(0, cap));
|
|
@@ -5400,18 +5501,20 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5400
5501
|
).length;
|
|
5401
5502
|
const managerSnapshot = role2 === "manager" && !Array.isArray(reports) ? reports : void 0;
|
|
5402
5503
|
const project = managerSnapshot && "project" in managerSnapshot ? managerSnapshot.project : void 0;
|
|
5403
|
-
const
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5504
|
+
const headerText = role2 === "manager" ? `manager${project ? ` \xB7 ${project}` : ""}` : `chief \xB7 ${supervisionCountLabel(managers, leads)}${incompatible ? ` \xB7 ${incompatible} incompatible` : ""}`;
|
|
5505
|
+
const header = renderSupervisionHeader(
|
|
5506
|
+
headerText,
|
|
5507
|
+
status,
|
|
5508
|
+
width,
|
|
5509
|
+
options2.theme
|
|
5510
|
+
);
|
|
5408
5511
|
if (managerSnapshot && "leads" in managerSnapshot && !("managers" in managerSnapshot)) {
|
|
5409
5512
|
const items = managerSupervisionItems(managerSnapshot);
|
|
5410
5513
|
const visible = items.slice(0, Math.max(0, cap));
|
|
5411
5514
|
const remaining = items.length - visible.length;
|
|
5412
5515
|
const now = Date.now();
|
|
5413
5516
|
const metadata = visible.map((item) => ({
|
|
5414
|
-
elapsed: formatElapsed(
|
|
5517
|
+
elapsed: status === "stale" ? "" : formatElapsed(
|
|
5415
5518
|
item.kind === "work" ? item.lead?.herdRunStartedAt : void 0,
|
|
5416
5519
|
now
|
|
5417
5520
|
) ?? "",
|
|
@@ -5420,7 +5523,7 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5420
5523
|
) ? `${item.kind === "work" ? item.lead.contextPercent : ""}%` : ""
|
|
5421
5524
|
}));
|
|
5422
5525
|
const workMarkers = {
|
|
5423
|
-
active: "\
|
|
5526
|
+
active: "\xB7",
|
|
5424
5527
|
paused: "\u25CB",
|
|
5425
5528
|
conflict: "!"
|
|
5426
5529
|
};
|
|
@@ -5428,7 +5531,7 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5428
5531
|
(candidate) => visible.every((item, index) => {
|
|
5429
5532
|
if (item.kind !== "work") return true;
|
|
5430
5533
|
const branch = index === visible.length - 1 && !remaining ? "\u2514\u2500" : "\u251C\u2500";
|
|
5431
|
-
const marker = item.lead?.compatibility === "incompatible" ? "!" : item.work.status === "active" && item.lead ?
|
|
5534
|
+
const marker = item.lead?.compatibility === "incompatible" ? "!" : item.work.status === "active" && item.lead ? supervisionLeadMarker(item.lead) : workMarkers[item.work.status];
|
|
5432
5535
|
const prefixWidth = visibleWidth(`${branch} ${marker} `);
|
|
5433
5536
|
const suffixWidth = visibleWidth(
|
|
5434
5537
|
item.lead?.compatibility === "incompatible" ? " \xB7 build mismatch" : ` \xB7 ${item.work.status}`
|
|
@@ -5446,7 +5549,7 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5446
5549
|
if (item.kind === "lead")
|
|
5447
5550
|
return {
|
|
5448
5551
|
text: safeLine(
|
|
5449
|
-
`${themed(options2.theme, item.lead.compatibility === "incompatible" ? "warning" :
|
|
5552
|
+
`${themed(options2.theme, item.lead.compatibility === "incompatible" ? "warning" : supervisionLeadColor(item.lead), `${branch} ${navigation}${item.lead.compatibility === "incompatible" ? "!" : supervisionLeadMarker(item.lead)}`)} ${themed(options2.theme, "muted", `${item.lead.branch ?? item.lead.displayName} \xB7 Lead${item.lead.compatibility === "incompatible" ? " \xB7 build mismatch" : ""}`)}`,
|
|
5450
5553
|
width
|
|
5451
5554
|
),
|
|
5452
5555
|
...status === "fresh" && item.lead.compatibility !== "incompatible" ? {
|
|
@@ -5457,7 +5560,7 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5457
5560
|
}
|
|
5458
5561
|
} : {}
|
|
5459
5562
|
};
|
|
5460
|
-
const marker = lead?.compatibility === "incompatible" ? "!" : item.work.status === "active" && lead ?
|
|
5563
|
+
const marker = lead?.compatibility === "incompatible" ? "!" : item.work.status === "active" && lead ? supervisionLeadMarker(lead) : workMarkers[item.work.status];
|
|
5461
5564
|
const prefix = `${branch} ${navigation}${marker} `;
|
|
5462
5565
|
const suffix = lead?.compatibility === "incompatible" ? " \xB7 build mismatch" : ` \xB7 ${item.work.status}`;
|
|
5463
5566
|
const telemetry = [
|
|
@@ -5468,7 +5571,7 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5468
5571
|
(total, value2) => total + visibleWidth(value2) + 2,
|
|
5469
5572
|
0
|
|
5470
5573
|
);
|
|
5471
|
-
const markerColor = lead?.compatibility === "incompatible" ? "warning" : item.work.status === "active" && lead ?
|
|
5574
|
+
const markerColor = lead?.compatibility === "incompatible" ? "warning" : item.work.status === "active" && lead ? supervisionLeadColor(lead) : item.work.status === "active" ? "muted" : item.work.status === "conflict" ? "warning" : "muted";
|
|
5472
5575
|
const markerText = themed(options2.theme, markerColor, marker);
|
|
5473
5576
|
const branchWidth = width - visibleWidth(prefix) - visibleWidth(suffix) - telemetryWidth;
|
|
5474
5577
|
const displayedBranch = safeLine(item.work.branch, branchWidth);
|
|
@@ -5500,7 +5603,7 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5500
5603
|
const intent = status === "fresh" && !isIncompatible ? { kind: "session", sessionId: lead.lead } : void 0;
|
|
5501
5604
|
const row = {
|
|
5502
5605
|
text: safeLine(
|
|
5503
|
-
`${themed(options2.theme, isIncompatible ? "warning" :
|
|
5606
|
+
`${themed(options2.theme, isIncompatible ? "warning" : supervisionLeadColor(lead), `${branch} ${indicators}${marker}`)} ${themed(options2.theme, "muted", `${lead.displayName}${isIncompatible ? " \xB7 build mismatch" : `${counts?.total ? ` \xB7 ${counts.total} compatible lead${counts.total === 1 ? "" : "s"}` : ""}${incompatibleLeads ? ` \xB7 ${incompatibleLeads} incompatible` : ""}${lead.agentCounts?.total ? ` \xB7 ${lead.agentCounts.total} agent${lead.agentCounts.total === 1 ? "" : "s"}` : ""}`}`)}`,
|
|
5504
5607
|
width
|
|
5505
5608
|
),
|
|
5506
5609
|
...intent ? { intent } : {},
|
|
@@ -5512,9 +5615,13 @@ function renderSupervisionRows(reports, width, options2 = {}, selectedLead) {
|
|
|
5512
5615
|
row,
|
|
5513
5616
|
...children.map((child, childIndex) => {
|
|
5514
5617
|
const childBranch = childIndex === children.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
5618
|
+
const childMarker = supervisionActivityMarker(
|
|
5619
|
+
child.runtime_state,
|
|
5620
|
+
child.agent_counts?.active ?? 0
|
|
5621
|
+
);
|
|
5515
5622
|
return {
|
|
5516
5623
|
text: safeLine(
|
|
5517
|
-
child.compatibility === "incompatible" ? `${themed(options2.theme, "warning", `${childIndent}${childBranch} !`)} ${themed(options2.theme, "muted", `${child.branch ?? child.display_name} \xB7 build mismatch`)}` : `${themed(options2.theme, "muted", `${childIndent}${childBranch} ${child.branch ?? child.display_name} \xB7 `)}${themed(options2.theme, lifecycleColor(child.runtime_state), child.runtime_state)}${themed(options2.theme, "muted", `${child.agent_counts?.total ? ` \xB7 ${child.agent_counts.total} agent${child.agent_counts.total === 1 ? "" : "s"}` : ""}`)}`,
|
|
5624
|
+
child.compatibility === "incompatible" ? `${themed(options2.theme, "warning", `${childIndent}${childBranch} !`)} ${themed(options2.theme, "muted", `${child.branch ?? child.display_name} \xB7 build mismatch`)}` : `${themed(options2.theme, "muted", `${childIndent}${childBranch} ${child.branch ?? child.display_name} \xB7 `)}${themed(options2.theme, childMarker === "\u25C9" ? "accent" : lifecycleColor(child.runtime_state), childMarker)} ${themed(options2.theme, lifecycleColor(child.runtime_state), child.runtime_state)}${themed(options2.theme, "muted", `${child.agent_counts?.total ? ` \xB7 ${child.agent_counts.total} agent${child.agent_counts.total === 1 ? "" : "s"}` : ""}`)}`,
|
|
5518
5625
|
width
|
|
5519
5626
|
),
|
|
5520
5627
|
...status === "fresh" && child.compatibility !== "incompatible" ? {
|
|
@@ -5548,7 +5655,7 @@ function formatSupervisionNotification(reports, status = "fresh") {
|
|
|
5548
5655
|
const lines = [
|
|
5549
5656
|
`Pi Herdsman \xB7 ${supervisionCountLabel(managers, leads)}${incompatible ? ` \xB7 ${incompatible} incompatible` : ""}${status === "stale" ? " \xB7 stale" : ""}`,
|
|
5550
5657
|
...ordered.slice(0, 8).map(
|
|
5551
|
-
(lead) => `${lead.compatibility === "incompatible" ? `incompatible ${lead.role} \xB7 ` : `${lead.role === "lead" ? "direct lead \xB7 " : "manager \xB7 "}${
|
|
5658
|
+
(lead) => `${lead.compatibility === "incompatible" ? `incompatible ${lead.role} \xB7 ` : `${lead.role === "lead" ? "direct lead \xB7 " : "manager \xB7 "}${lead.runtimeState}: `}${lead.displayName}${lead.compatibility === "incompatible" ? " \xB7 build mismatch" : `${lead.leadCounts?.total ? ` \xB7 ${lead.leadCounts.total} compatible lead${lead.leadCounts.total === 1 ? "" : "s"}` : ""}${lead.incompatibleLeadCount ? ` \xB7 ${lead.incompatibleLeadCount} incompatible lead${lead.incompatibleLeadCount === 1 ? "" : "s"}` : ""}${lead.agentCounts?.total ? ` \xB7 ${leadAgentCounts(lead)}` : ""}`}`
|
|
5552
5659
|
)
|
|
5553
5660
|
];
|
|
5554
5661
|
if (ordered.length > 8) lines.push(`\u2026 ${ordered.length - 8} more \xB7 /chief`);
|
|
@@ -5912,7 +6019,7 @@ function formatAgentDefinitions(definitions) {
|
|
|
5912
6019
|
}
|
|
5913
6020
|
function displayHomePath(path) {
|
|
5914
6021
|
const home = homedir3();
|
|
5915
|
-
if (!
|
|
6022
|
+
if (!isAbsolute3(path)) return path;
|
|
5916
6023
|
const remainder = relative(home, path);
|
|
5917
6024
|
if (remainder === "") return "~";
|
|
5918
6025
|
if (remainder !== ".." && !remainder.startsWith(`..${sep2}`))
|
|
@@ -7390,7 +7497,7 @@ function renderAgentLostMessage(message, options2, theme) {
|
|
|
7390
7497
|
function createStatusWidget(invalidate, theme, onFocus) {
|
|
7391
7498
|
return new StatusWidget(invalidate, theme, onFocus);
|
|
7392
7499
|
}
|
|
7393
|
-
var LIFECYCLE, STATE_COLOR, MIN_TASK_WIDTH, STATUS_LAYOUTS, SUPERVISION_GROUPS, MANAGER_METADATA_LAYOUTS, SUPERVISION_CONTEXT_MAX_BYTES, WidthSafeText, spinner, StatusWidget;
|
|
7500
|
+
var LIFECYCLE, animates, STATE_COLOR, MIN_TASK_WIDTH, STATUS_LAYOUTS, SUPERVISION_GROUPS, MANAGER_METADATA_LAYOUTS, SUPERVISION_CONTEXT_MAX_BYTES, WidthSafeText, spinner, StatusWidget;
|
|
7394
7501
|
var init_presentation = __esm({
|
|
7395
7502
|
"extension/presentation.ts"() {
|
|
7396
7503
|
init_agent_definitions();
|
|
@@ -7406,6 +7513,7 @@ var init_presentation = __esm({
|
|
|
7406
7513
|
unknown: ["?", "unknown"],
|
|
7407
7514
|
lost: ["\xD7", "lost"]
|
|
7408
7515
|
};
|
|
7516
|
+
animates = (state) => state === "working" || state === "starting";
|
|
7409
7517
|
STATE_COLOR = {
|
|
7410
7518
|
[lifecycleLabel("working")]: "success",
|
|
7411
7519
|
[lifecycleLabel("blocked")]: "warning",
|
|
@@ -7422,10 +7530,10 @@ var init_presentation = __esm({
|
|
|
7422
7530
|
{ task: false, elapsed: false, context: false }
|
|
7423
7531
|
];
|
|
7424
7532
|
SUPERVISION_GROUPS = [
|
|
7425
|
-
"
|
|
7533
|
+
"ACTIVE/TRANSITIONAL",
|
|
7426
7534
|
"BLOCKED",
|
|
7427
7535
|
"IDLE/DONE",
|
|
7428
|
-
"
|
|
7536
|
+
"UNRESOLVED"
|
|
7429
7537
|
];
|
|
7430
7538
|
MANAGER_METADATA_LAYOUTS = [
|
|
7431
7539
|
{ elapsed: true, context: true },
|
|
@@ -7466,9 +7574,7 @@ var init_presentation = __esm({
|
|
|
7466
7574
|
this.snapshot = snapshot;
|
|
7467
7575
|
this.hits = [];
|
|
7468
7576
|
this.renderedWidth = -1;
|
|
7469
|
-
const animated = snapshot.agents.some(
|
|
7470
|
-
(agent) => agent.state === "working" || agent.state === "settling" || agent.state === "starting"
|
|
7471
|
-
);
|
|
7577
|
+
const animated = !snapshot.stale && !snapshot.unavailable && snapshot.agents.some((agent) => animates(agent.state));
|
|
7472
7578
|
if (animated && !this.timer)
|
|
7473
7579
|
this.timer = setInterval(() => {
|
|
7474
7580
|
this.frame++;
|
|
@@ -7487,16 +7593,25 @@ var init_presentation = __esm({
|
|
|
7487
7593
|
const s = this.snapshot;
|
|
7488
7594
|
this.renderedWidth = width;
|
|
7489
7595
|
this.hits = [];
|
|
7490
|
-
const suffix = s.unavailable ? "unavailable" : `${formatStatusCounts(s.agents)}${s.stale ? " \xB7 stale" : ""}`;
|
|
7491
7596
|
const availableWidth = Math.max(0, width);
|
|
7492
7597
|
const execution = s.execution ? ` \xB7 ${s.execution.kind === "managed" ? managedExecutionLabel(s.execution.lifecycle) : s.execution.mode}` : "";
|
|
7493
|
-
const
|
|
7598
|
+
const observedNow = s.stale ? s.refreshedAt : Date.now();
|
|
7599
|
+
const elapsed = observedNow === void 0 ? void 0 : formatElapsed(s.herdRunStartedAt, observedNow);
|
|
7494
7600
|
let run2 = !s.identityOnly && elapsed ? ` \xB7 ${elapsed}` : "";
|
|
7495
|
-
const
|
|
7601
|
+
const counts = s.identityOnly || s.unavailable ? "" : formatStatusCounts(s.agents);
|
|
7602
|
+
const freshness = s.unavailable ? "unavailable" : s.stale ? "stale" : "";
|
|
7603
|
+
const freshnessSuffix = freshness ? ` ${freshness}` : "";
|
|
7604
|
+
const fullSuffix = s.unavailable ? freshnessSuffix : counts ? ` ${counts}${s.stale ? " \xB7 stale" : ""}` : freshnessSuffix;
|
|
7605
|
+
const fullSuffixWidth = visibleWidth(fullSuffix);
|
|
7606
|
+
const freshnessSuffixWidth = visibleWidth(freshnessSuffix);
|
|
7496
7607
|
const breadcrumbSegments = s.breadcrumb ?? [{ text: "?" }];
|
|
7608
|
+
const fullIdentityWidth = visibleWidth(
|
|
7609
|
+
renderBreadcrumb(breadcrumbSegments, Number.MAX_SAFE_INTEGER).text
|
|
7610
|
+
);
|
|
7611
|
+
const reservedSuffixWidth = freshness && fullSuffixWidth + fullIdentityWidth <= availableWidth ? fullSuffixWidth : freshnessSuffixWidth || (fullSuffixWidth + fullIdentityWidth <= availableWidth ? fullSuffixWidth : 0);
|
|
7497
7612
|
const renderedBreadcrumb = renderBreadcrumb(
|
|
7498
7613
|
breadcrumbSegments,
|
|
7499
|
-
availableWidth
|
|
7614
|
+
Math.max(0, availableWidth - reservedSuffixWidth)
|
|
7500
7615
|
);
|
|
7501
7616
|
const breadcrumb = renderedBreadcrumb.text;
|
|
7502
7617
|
if (!s.stale && !s.unavailable) this.hits.push(...renderedBreadcrumb.hits);
|
|
@@ -7504,6 +7619,9 @@ var init_presentation = __esm({
|
|
|
7504
7619
|
0,
|
|
7505
7620
|
availableWidth - visibleWidth(breadcrumb)
|
|
7506
7621
|
);
|
|
7622
|
+
const includeCounts = !!counts && visibleWidth(fullSuffix) <= remainingWidth;
|
|
7623
|
+
const suffixBody = includeCounts ? `${counts}${s.stale ? " \xB7 stale" : ""}` : freshness;
|
|
7624
|
+
const suffixText = suffixBody ? `${breadcrumb ? " " : ""}${suffixBody}` : "";
|
|
7507
7625
|
const executionFits = !!execution && visibleWidth(execution) + visibleWidth(suffixText) <= remainingWidth;
|
|
7508
7626
|
const shownExecution = executionFits ? execution : "";
|
|
7509
7627
|
if (!s.stale && !s.unavailable && executionFits && s.execution?.kind === "managed" && (!s.execution.lifecycle || s.execution.lifecycle === "assigned")) {
|
|
@@ -7528,13 +7646,15 @@ var init_presentation = __esm({
|
|
|
7528
7646
|
const styledExecution = shownExecution ? this.theme.fg("muted", shownExecution) : "";
|
|
7529
7647
|
const styledTools = tools ? this.theme.fg("muted", tools) : "";
|
|
7530
7648
|
const styledRun = run2 ? this.theme.fg("accent", run2) : "";
|
|
7531
|
-
const styledSuffix = suffixText ? this.theme.fg("
|
|
7649
|
+
const styledSuffix = !suffixText ? "" : s.unavailable ? this.theme.fg("warning", suffixText) : s.stale ? `${includeCounts ? this.theme.fg("muted", `${breadcrumb ? " " : ""}${counts} \xB7 `) : breadcrumb ? " " : ""}${this.theme.fg("warning", "stale")}` : this.theme.fg("muted", suffixText);
|
|
7532
7650
|
const header = `${styledBreadcrumb}${styledExecution}${styledTools}${styledRun}${styledSuffix}`;
|
|
7533
|
-
const
|
|
7651
|
+
const compactStaleHeader = s.stale && !s.unavailable && !breadcrumb && visibleWidth("\u25CF stale") <= availableWidth ? `${this.theme.fg("success", "\u25CF")} ${this.theme.fg("warning", "stale")}` : header;
|
|
7652
|
+
const out = [truncateToWidth(compactStaleHeader, availableWidth, "\u2026")];
|
|
7534
7653
|
if (s.identityOnly) return out;
|
|
7535
7654
|
const rows = renderStatusRows(s.agents, {
|
|
7536
|
-
now:
|
|
7655
|
+
now: observedNow,
|
|
7537
7656
|
frame: this.frame,
|
|
7657
|
+
animate: !s.stale && !s.unavailable,
|
|
7538
7658
|
width: Math.max(0, width),
|
|
7539
7659
|
theme: this.theme
|
|
7540
7660
|
});
|
|
@@ -9590,13 +9710,13 @@ import {
|
|
|
9590
9710
|
openSync as openSync8,
|
|
9591
9711
|
readFileSync as readFileSync8,
|
|
9592
9712
|
readSync as readSync3,
|
|
9593
|
-
statSync as
|
|
9713
|
+
statSync as statSync5,
|
|
9594
9714
|
renameSync as renameSync7,
|
|
9595
9715
|
unlinkSync as unlinkSync7,
|
|
9596
9716
|
writeFileSync as writeFileSync5
|
|
9597
9717
|
} from "node:fs";
|
|
9598
9718
|
import { createHash as createHash8, randomUUID as randomUUID9 } from "node:crypto";
|
|
9599
|
-
import { basename as basename7, dirname as dirname7, isAbsolute as
|
|
9719
|
+
import { basename as basename7, dirname as dirname7, isAbsolute as isAbsolute4, join as join8, normalize } from "node:path";
|
|
9600
9720
|
import { isDeepStrictEqual } from "node:util";
|
|
9601
9721
|
function readSessionKind(entries, sessionId) {
|
|
9602
9722
|
let identity;
|
|
@@ -9953,7 +10073,7 @@ function removeMalformedChiefMessageUnlocked(runtime, toSessionId, id) {
|
|
|
9953
10073
|
} catch (error2) {
|
|
9954
10074
|
if (error2.code === "ENOENT") {
|
|
9955
10075
|
try {
|
|
9956
|
-
|
|
10076
|
+
statSync5(path);
|
|
9957
10077
|
errors.push(
|
|
9958
10078
|
new Error("Unable to confirm malformed Chief message removal")
|
|
9959
10079
|
);
|
|
@@ -10030,7 +10150,7 @@ function writeChiefMessageUnlocked(record, runtime, clearQuarantine) {
|
|
|
10030
10150
|
const path = chiefMessagePath(runtime, record.toSessionId, record.id);
|
|
10031
10151
|
if (record.kind !== "project_assignment") {
|
|
10032
10152
|
try {
|
|
10033
|
-
|
|
10153
|
+
statSync5(path);
|
|
10034
10154
|
const existing = readChiefMessage(path);
|
|
10035
10155
|
if (!isDeepStrictEqual(existing, record))
|
|
10036
10156
|
throw new Error(
|
|
@@ -10097,7 +10217,7 @@ function writeChiefMessageUnlocked(record, runtime, clearQuarantine) {
|
|
|
10097
10217
|
function conclusivelyMalformedChiefMessage(path) {
|
|
10098
10218
|
let content;
|
|
10099
10219
|
try {
|
|
10100
|
-
if (
|
|
10220
|
+
if (statSync5(path).size > COORDINATION_MESSAGE_MAX_BYTES) return true;
|
|
10101
10221
|
content = readFileSync8(path, "utf8");
|
|
10102
10222
|
} catch {
|
|
10103
10223
|
return false;
|
|
@@ -10115,7 +10235,7 @@ function assertChiefMessageNotQuarantined(runtime, toSessionId, id) {
|
|
|
10115
10235
|
function readStoredChiefMessage(path) {
|
|
10116
10236
|
let size;
|
|
10117
10237
|
try {
|
|
10118
|
-
size =
|
|
10238
|
+
size = statSync5(path).size;
|
|
10119
10239
|
} catch (error2) {
|
|
10120
10240
|
throw new Error("Unable to read Chief message", { cause: error2 });
|
|
10121
10241
|
}
|
|
@@ -10260,7 +10380,7 @@ function quarantineChiefMessageUnlocked(runtime, toSessionId, id) {
|
|
|
10260
10380
|
}
|
|
10261
10381
|
function chiefMessageQuarantined(runtime, toSessionId, id) {
|
|
10262
10382
|
try {
|
|
10263
|
-
|
|
10383
|
+
statSync5(`${chiefMessagePath(runtime, toSessionId, id)}.quarantine`);
|
|
10264
10384
|
return true;
|
|
10265
10385
|
} catch (error2) {
|
|
10266
10386
|
if (error2.code === "ENOENT") return false;
|
|
@@ -10700,7 +10820,7 @@ function listPeerLeadRecords(runtime = peerRuntime()) {
|
|
|
10700
10820
|
return entries.filter((entry) => /^[0-9a-f]{64}\.json$/.test(entry)).sort().flatMap((entry) => {
|
|
10701
10821
|
try {
|
|
10702
10822
|
const path = join8(runtime.peers, entry);
|
|
10703
|
-
if (
|
|
10823
|
+
if (statSync5(path).size > PEER_LEAD_RECORD_MAX_BYTES) return [];
|
|
10704
10824
|
const text = readFileSync8(path, "utf8");
|
|
10705
10825
|
const value2 = JSON.parse(text);
|
|
10706
10826
|
if (!validPeerLeadRecord(value2) || peerLeadRecordFilename(value2.piSessionId) !== entry)
|
|
@@ -10869,13 +10989,13 @@ function readManagerDescriptorStatus(runtime, workspaceId) {
|
|
|
10869
10989
|
const lockPath = `${path}.lock`;
|
|
10870
10990
|
let content;
|
|
10871
10991
|
try {
|
|
10872
|
-
if (
|
|
10992
|
+
if (statSync5(path).size > CHIEF_DESCRIPTOR_MAX_BYTES)
|
|
10873
10993
|
throw new Error("descriptor too large");
|
|
10874
10994
|
content = readFileSync8(path, "utf8");
|
|
10875
10995
|
} catch (error2) {
|
|
10876
10996
|
if (error2.code === "ENOENT") {
|
|
10877
10997
|
try {
|
|
10878
|
-
if (!
|
|
10998
|
+
if (!statSync5(lockPath, { throwIfNoEntry: false })) return void 0;
|
|
10879
10999
|
} catch (lockError) {
|
|
10880
11000
|
throw new Error("Unable to verify Manager descriptor", {
|
|
10881
11001
|
cause: lockError
|
|
@@ -10909,7 +11029,7 @@ function readManagerDescriptor(runtime, workspaceId) {
|
|
|
10909
11029
|
throw new Error("Unable to verify Manager supervision lease");
|
|
10910
11030
|
return status.descriptor;
|
|
10911
11031
|
}
|
|
10912
|
-
function listManagerDescriptors(runtime = supervisionRuntime()) {
|
|
11032
|
+
function listManagerDescriptors(runtime = supervisionRuntime(), strict = false) {
|
|
10913
11033
|
let entries;
|
|
10914
11034
|
try {
|
|
10915
11035
|
entries = readdirSync5(runtime.managers);
|
|
@@ -10920,13 +11040,18 @@ function listManagerDescriptors(runtime = supervisionRuntime()) {
|
|
|
10920
11040
|
return entries.filter((entry) => /^[0-9a-f]{64}\.json$/.test(entry)).sort().flatMap((entry) => {
|
|
10921
11041
|
try {
|
|
10922
11042
|
const path = join8(runtime.managers, entry);
|
|
10923
|
-
if (
|
|
11043
|
+
if (statSync5(path).size > CHIEF_DESCRIPTOR_MAX_BYTES)
|
|
11044
|
+
throw new Error("Manager descriptor too large");
|
|
10924
11045
|
const candidate = JSON.parse(readFileSync8(path, "utf8"));
|
|
10925
11046
|
if (!validManagerDescriptor(candidate) || basename7(managerDescriptorPath(runtime, candidate.workspaceId)) !== entry)
|
|
10926
|
-
|
|
10927
|
-
const
|
|
10928
|
-
|
|
10929
|
-
|
|
11047
|
+
throw new Error("Invalid Manager descriptor");
|
|
11048
|
+
const status = readManagerDescriptorStatus(
|
|
11049
|
+
runtime,
|
|
11050
|
+
candidate.workspaceId
|
|
11051
|
+
);
|
|
11052
|
+
return status?.live ? [status.descriptor] : [];
|
|
11053
|
+
} catch (error2) {
|
|
11054
|
+
if (strict) throw error2;
|
|
10930
11055
|
return [];
|
|
10931
11056
|
}
|
|
10932
11057
|
});
|
|
@@ -11006,7 +11131,7 @@ function validProjectAssignment(value2) {
|
|
|
11006
11131
|
];
|
|
11007
11132
|
return required.every((key) => Object.hasOwn(r, key)) && Object.keys(r).every(
|
|
11008
11133
|
(key) => required.includes(key) || optional.includes(key)
|
|
11009
|
-
) && Object.keys(r).length >= required.length && r.version === 2 && UUID3.test(String(r.id)) && validNativeIdentity(r.repoKey) && validNativeIdentity(r.branch) && typeof r.text === "string" && r.text.length > 0 && (r.checkoutPath === void 0 || typeof r.checkoutPath === "string" &&
|
|
11134
|
+
) && Object.keys(r).length >= required.length && r.version === 2 && UUID3.test(String(r.id)) && validNativeIdentity(r.repoKey) && validNativeIdentity(r.branch) && typeof r.text === "string" && r.text.length > 0 && (r.checkoutPath === void 0 || typeof r.checkoutPath === "string" && isAbsolute4(r.checkoutPath) && normalize(r.checkoutPath) === r.checkoutPath && !/[\u0000-\u001f]/.test(r.checkoutPath)) && (r.piSessionFile === void 0 || typeof r.piSessionFile === "string" && r.piSessionFile.length > 0) && (r.resultBindings === void 0 || Array.isArray(r.resultBindings) && r.resultBindings.every(isResultBinding)) && (r.requiredEvidence === void 0 || Array.isArray(r.requiredEvidence) && r.requiredEvidence.every(isRequiredEvidence) && r.requiredEvidence.every(
|
|
11010
11135
|
(evidence) => "result" in evidence || evidence.sourceAssignmentId === r.id
|
|
11011
11136
|
) && new Set(r.requiredEvidence.map((evidence) => evidence.id)).size === r.requiredEvidence.length) && (r.currentEvidenceIds === void 0 || Array.isArray(r.currentEvidenceIds) && new Set(r.currentEvidenceIds).size === r.currentEvidenceIds.length && r.currentEvidenceIds.every(
|
|
11012
11137
|
(id) => typeof id === "string" && r.requiredEvidence?.some(
|
|
@@ -11592,7 +11717,7 @@ function removeProjectMessage(runtime, repoKey, branch, id) {
|
|
|
11592
11717
|
if (!UUID3.test(id)) throw new Error("Invalid project message ID");
|
|
11593
11718
|
const directory2 = projectMessageDirectory(runtime, repoKey, branch);
|
|
11594
11719
|
try {
|
|
11595
|
-
if (!
|
|
11720
|
+
if (!statSync5(directory2).isDirectory())
|
|
11596
11721
|
throw new Error("Invalid project message directory");
|
|
11597
11722
|
} catch (error2) {
|
|
11598
11723
|
if (error2.code === "ENOENT") return;
|
|
@@ -11634,7 +11759,7 @@ function readProjectMessageFile(path) {
|
|
|
11634
11759
|
}
|
|
11635
11760
|
function readStoredProjectMessageFile(path) {
|
|
11636
11761
|
try {
|
|
11637
|
-
if (
|
|
11762
|
+
if (statSync5(path).size > COORDINATION_MESSAGE_MAX_BYTES)
|
|
11638
11763
|
throw new Error("large");
|
|
11639
11764
|
const stored = JSON.parse(readFileSync8(path, "utf8"));
|
|
11640
11765
|
if (!validProjectMessage(stored) || basename7(path) !== `${stored.id}.json`)
|
|
@@ -12088,7 +12213,7 @@ import {
|
|
|
12088
12213
|
truncateTail as truncateTail2
|
|
12089
12214
|
} from "@earendil-works/pi-coding-agent";
|
|
12090
12215
|
import { contentText as contentText2 } from "@earendil-works/pi-ai";
|
|
12091
|
-
import { realpathSync as realpathSync3, statSync as
|
|
12216
|
+
import { realpathSync as realpathSync3, statSync as statSync6 } from "node:fs";
|
|
12092
12217
|
import { unlinkSync as unlinkSync8 } from "node:fs";
|
|
12093
12218
|
import { createHash as createHash9, randomUUID as randomUUID10 } from "node:crypto";
|
|
12094
12219
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
@@ -13384,7 +13509,7 @@ function resolveAssignmentSession(ctx, raw, options2 = {}) {
|
|
|
13384
13509
|
"continue"
|
|
13385
13510
|
);
|
|
13386
13511
|
try {
|
|
13387
|
-
|
|
13512
|
+
statSync6(
|
|
13388
13513
|
agentMailboxPath(
|
|
13389
13514
|
historicalClose.workspace_id,
|
|
13390
13515
|
historicalClose.agent
|
|
@@ -13437,7 +13562,7 @@ function resolveAssignmentSession(ctx, raw, options2 = {}) {
|
|
|
13437
13562
|
);
|
|
13438
13563
|
if (!historicalClose) {
|
|
13439
13564
|
try {
|
|
13440
|
-
|
|
13565
|
+
statSync6(
|
|
13441
13566
|
agentMailboxPath(
|
|
13442
13567
|
historicalTerminal.workspaceId,
|
|
13443
13568
|
historicalTerminal.agentLabel
|
|
@@ -14142,7 +14267,7 @@ function createAgentController(pi, options2) {
|
|
|
14142
14267
|
const persistedTranscriptReady2 = (state) => {
|
|
14143
14268
|
if (!state.piSessionId || !state.piSessionFile) return false;
|
|
14144
14269
|
try {
|
|
14145
|
-
const file2 =
|
|
14270
|
+
const file2 = statSync6(state.piSessionFile, { throwIfNoEntry: false });
|
|
14146
14271
|
return !!file2?.isFile() && file2.size > 0;
|
|
14147
14272
|
} catch {
|
|
14148
14273
|
return false;
|
|
@@ -16182,9 +16307,15 @@ function createAgentController(pi, options2) {
|
|
|
16182
16307
|
const expected = resultIdentity(runtime, result.requestId);
|
|
16183
16308
|
const identityMismatch = runtimes.get(runtime.label) !== runtime || result.runId !== runtime.runId || result.ownerSessionId !== runtime.ownerSessionId || result.workspaceId !== runtime.workspaceId || result.agentLabel !== runtime.label || result.paneId !== runtime.paneId || result.requestId !== (runtime.activeRequestId ?? runtime.completedRequestId);
|
|
16184
16309
|
if (identityMismatch) return;
|
|
16185
|
-
|
|
16310
|
+
let entries = context.sessionManager.getEntries();
|
|
16186
16311
|
const evidenceKey = JSON.stringify(Object.values(expected));
|
|
16187
16312
|
if (!hasDeliveredResult(entries, expected) && !resultDeliveryEvidence.has(evidenceKey)) {
|
|
16313
|
+
const forwardedResultBindings = result.status === "completed" ? result.resultBindings ?? [] : [];
|
|
16314
|
+
if (forwardedResultBindings.length) {
|
|
16315
|
+
validateMessageFiles(forwardedResultBindings, runtime.cwd, "result");
|
|
16316
|
+
importResultBindings(pi, context, forwardedResultBindings, "result");
|
|
16317
|
+
entries = context.sessionManager.getEntries();
|
|
16318
|
+
}
|
|
16188
16319
|
const elapsedMs = result.status === "completed" && Number.isFinite(runtime.startedAt) && runtime.startedAt !== void 0 && runtime.startedAt >= 0 && Number.isFinite(result.completedAt) && result.completedAt >= 0 && result.completedAt >= runtime.startedAt ? result.completedAt - runtime.startedAt : void 0;
|
|
16189
16320
|
const completion = truncateModelText(
|
|
16190
16321
|
result.status === "completed" ? result.text : result.error?.message ?? "Agent failed",
|
|
@@ -16229,6 +16360,9 @@ function createAgentController(pi, options2) {
|
|
|
16229
16360
|
const content = [
|
|
16230
16361
|
header,
|
|
16231
16362
|
...semanticResult ? [`Result ref: ${semanticResult.ref}`] : [],
|
|
16363
|
+
...forwardedResultBindings.length ? [
|
|
16364
|
+
`Forwardable result evidence: ${forwardedResultBindings.map((binding) => binding.ref).join(", ")}`
|
|
16365
|
+
] : [],
|
|
16232
16366
|
...retirement ? [retirement] : [],
|
|
16233
16367
|
completion.content,
|
|
16234
16368
|
...status ? [status.content] : []
|
|
@@ -17649,7 +17783,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
17649
17783
|
options2.onChanged();
|
|
17650
17784
|
}
|
|
17651
17785
|
for (const promptPath of promptPaths)
|
|
17652
|
-
if (
|
|
17786
|
+
if (statSync6(promptPath, { throwIfNoEntry: false }))
|
|
17653
17787
|
unlinkSync8(promptPath);
|
|
17654
17788
|
if (releaseClaim) releaseClaim();
|
|
17655
17789
|
}
|
|
@@ -19052,6 +19186,11 @@ Do not overlap writers in a worktree or file-ownership boundary. For dependent
|
|
|
19052
19186
|
work, pass reusable direct-agent result refs through \`files\`. Preserve
|
|
19053
19187
|
canonical result:<request-id> refs already supplied as file evidence exactly
|
|
19054
19188
|
when forwarding them.
|
|
19189
|
+
Before completing, a managed Agent may call attach_handoff({files}) to select
|
|
19190
|
+
verified semantic result refs for its ordinary final handoff to its direct
|
|
19191
|
+
owner. This is non-blocking selection, not a separate evidence transfer; a ref
|
|
19192
|
+
mentioned only in completion text is not forwardable. Use exact refs only, and
|
|
19193
|
+
do not select evidence unless the owner needs it.
|
|
19055
19194
|
Do not silently broaden scope or make an unapproved scope, architecture,
|
|
19056
19195
|
security, protocol, repository-boundary, product, or operational decision.
|
|
19057
19196
|
|
|
@@ -19141,6 +19280,7 @@ __export(managed_agent_runtime_exports, {
|
|
|
19141
19280
|
readEvidencePage: () => readEvidencePage,
|
|
19142
19281
|
registerManagedAgentActivityHandlers: () => registerManagedAgentActivityHandlers,
|
|
19143
19282
|
registerManagedAgentAskOwnerTool: () => registerManagedAgentAskOwnerTool,
|
|
19283
|
+
registerManagedAgentAttachHandoffTool: () => registerManagedAgentAttachHandoffTool,
|
|
19144
19284
|
registerManagedAgentContextHandlers: () => registerManagedAgentContextHandlers,
|
|
19145
19285
|
registerManagedAgentInputHandlers: () => registerManagedAgentInputHandlers,
|
|
19146
19286
|
registerManagedAgentResultCapture: () => registerManagedAgentResultCapture,
|
|
@@ -19154,7 +19294,7 @@ __export(managed_agent_runtime_exports, {
|
|
|
19154
19294
|
sessionContextRetired: () => sessionContextRetired,
|
|
19155
19295
|
validateManagedAgentIdentity: () => validateManagedAgentIdentity
|
|
19156
19296
|
});
|
|
19157
|
-
import { isAbsolute as
|
|
19297
|
+
import { isAbsolute as isAbsolute6, resolve as resolve5 } from "node:path";
|
|
19158
19298
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
19159
19299
|
import { buildSessionProjection as buildSessionProjection2 } from "@earendil-works/pi-coding-agent";
|
|
19160
19300
|
import { contentText as contentText3 } from "@earendil-works/pi-ai";
|
|
@@ -19945,6 +20085,89 @@ function createManagedAgentAskOwnerHandler(options2) {
|
|
|
19945
20085
|
};
|
|
19946
20086
|
};
|
|
19947
20087
|
}
|
|
20088
|
+
function handoffSelectionDetails(state, resultBindings) {
|
|
20089
|
+
return {
|
|
20090
|
+
version: 1,
|
|
20091
|
+
assignmentRequestId: state.activeRequestId,
|
|
20092
|
+
runId: state.runId,
|
|
20093
|
+
ownerSessionId: state.ownerSessionId,
|
|
20094
|
+
workspaceId: state.workspaceId,
|
|
20095
|
+
agentLabel: state.agentLabel,
|
|
20096
|
+
paneId: state.paneId,
|
|
20097
|
+
piSessionId: state.piSessionId,
|
|
20098
|
+
resultBindings: [...resultBindings]
|
|
20099
|
+
};
|
|
20100
|
+
}
|
|
20101
|
+
function latestHandoffSelection(ctx, state) {
|
|
20102
|
+
let selected;
|
|
20103
|
+
const expectedKeys = [
|
|
20104
|
+
"version",
|
|
20105
|
+
"assignmentRequestId",
|
|
20106
|
+
"runId",
|
|
20107
|
+
"ownerSessionId",
|
|
20108
|
+
"workspaceId",
|
|
20109
|
+
"agentLabel",
|
|
20110
|
+
"paneId",
|
|
20111
|
+
"piSessionId",
|
|
20112
|
+
"resultBindings"
|
|
20113
|
+
];
|
|
20114
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
20115
|
+
const message = entry?.type === "message" ? entry.message : void 0;
|
|
20116
|
+
if (message?.role !== "toolResult" || message.toolName !== ATTACH_HANDOFF_TOOL || message.isError !== false)
|
|
20117
|
+
continue;
|
|
20118
|
+
const details = message.details;
|
|
20119
|
+
if (!details || typeof details !== "object" || details.assignmentRequestId !== state.activeRequestId)
|
|
20120
|
+
continue;
|
|
20121
|
+
if (Object.keys(details).length !== expectedKeys.length || Object.keys(details).some((key) => !expectedKeys.includes(key)) || details.version !== 1 || details.runId !== state.runId || details.ownerSessionId !== state.ownerSessionId || details.workspaceId !== state.workspaceId || details.agentLabel !== state.agentLabel || details.paneId !== state.paneId || details.piSessionId !== state.piSessionId || !Array.isArray(details.resultBindings) || !details.resultBindings.every(isResultBinding) || new Set(
|
|
20122
|
+
details.resultBindings.map((binding) => binding.ref)
|
|
20123
|
+
).size !== details.resultBindings.length)
|
|
20124
|
+
throw new Error("Invalid or conflicting handoff selection metadata");
|
|
20125
|
+
selected = [...details.resultBindings];
|
|
20126
|
+
}
|
|
20127
|
+
return selected;
|
|
20128
|
+
}
|
|
20129
|
+
function verifyHandoffSelection(ctx, selected) {
|
|
20130
|
+
const resolved = resolveMessageFiles(
|
|
20131
|
+
ctx,
|
|
20132
|
+
selected.map((binding) => binding.ref),
|
|
20133
|
+
ATTACH_HANDOFF_TOOL
|
|
20134
|
+
);
|
|
20135
|
+
if (resolved.length !== selected.length || resolved.some(
|
|
20136
|
+
(binding, index) => !isResultBinding(binding) || !isDeepStrictEqual3(binding, selected[index])
|
|
20137
|
+
))
|
|
20138
|
+
throw new Error("Selected result binding is unavailable on this branch");
|
|
20139
|
+
validateMessageFiles(
|
|
20140
|
+
resolved,
|
|
20141
|
+
ctx.cwd,
|
|
20142
|
+
ATTACH_HANDOFF_TOOL
|
|
20143
|
+
);
|
|
20144
|
+
return resolved;
|
|
20145
|
+
}
|
|
20146
|
+
function registerManagedAgentAttachHandoffTool(pi, execute) {
|
|
20147
|
+
pi.registerTool({
|
|
20148
|
+
name: ATTACH_HANDOFF_TOOL,
|
|
20149
|
+
label: "Attach handoff evidence",
|
|
20150
|
+
exposure: "model-only",
|
|
20151
|
+
promptSnippet: "Select reusable results for this assignment's final handoff",
|
|
20152
|
+
description: "Select verified semantic result references for your eventual completion to your direct owner. This is non-blocking and does not send evidence now. Use only exact result:<agent>#<index> references; text-only mentions do not grant access.",
|
|
20153
|
+
executionMode: "sequential",
|
|
20154
|
+
parameters: Type2.Object(
|
|
20155
|
+
{
|
|
20156
|
+
files: Type2.Array(
|
|
20157
|
+
Type2.String({
|
|
20158
|
+
minLength: 1,
|
|
20159
|
+
description: "Exact semantic result reference, such as result:scout#21."
|
|
20160
|
+
}),
|
|
20161
|
+
{
|
|
20162
|
+
description: "Semantic result references to select for the eventual completion; an empty list clears the selection."
|
|
20163
|
+
}
|
|
20164
|
+
)
|
|
20165
|
+
},
|
|
20166
|
+
{ additionalProperties: false }
|
|
20167
|
+
),
|
|
20168
|
+
execute
|
|
20169
|
+
});
|
|
20170
|
+
}
|
|
19948
20171
|
function registerManagedAgentAskOwnerTool(pi, execute) {
|
|
19949
20172
|
const files = Type2.Optional(
|
|
19950
20173
|
Type2.Array(
|
|
@@ -20547,7 +20770,19 @@ function registerManagedAgentSettlementHandlers(pi, execution, options2) {
|
|
|
20547
20770
|
const observation = execution.observation;
|
|
20548
20771
|
const outcome = observation?.requestId === state.activeRequestId ? observation.outcome : void 0;
|
|
20549
20772
|
const responseText = observation?.requestId === state.activeRequestId && observation.outcome === "completed" && observation.responseEntryId ? observation.responseText?.trim() ?? "" : "";
|
|
20550
|
-
|
|
20773
|
+
let completed = !aborted && outcome === "completed" && !!responseText;
|
|
20774
|
+
let resultBindings;
|
|
20775
|
+
let handoffSelectionError = false;
|
|
20776
|
+
if (completed) {
|
|
20777
|
+
try {
|
|
20778
|
+
const selected = latestHandoffSelection(ctx, state);
|
|
20779
|
+
if (selected?.length)
|
|
20780
|
+
resultBindings = verifyHandoffSelection(ctx, selected);
|
|
20781
|
+
} catch {
|
|
20782
|
+
completed = false;
|
|
20783
|
+
handoffSelectionError = true;
|
|
20784
|
+
}
|
|
20785
|
+
}
|
|
20551
20786
|
const result = {
|
|
20552
20787
|
version: 5,
|
|
20553
20788
|
runId: state.runId,
|
|
@@ -20557,10 +20792,13 @@ function registerManagedAgentSettlementHandlers(pi, execution, options2) {
|
|
|
20557
20792
|
agentLabel: state.agentLabel,
|
|
20558
20793
|
paneId: state.paneId,
|
|
20559
20794
|
status: completed ? "completed" : "failed",
|
|
20560
|
-
...completed ? {
|
|
20795
|
+
...completed ? {
|
|
20796
|
+
text: responseText,
|
|
20797
|
+
...resultBindings?.length ? { resultBindings } : {}
|
|
20798
|
+
} : {
|
|
20561
20799
|
error: {
|
|
20562
|
-
code: aborted ? "aborted" : outcome === "error" ? "execution_error" : "empty_result",
|
|
20563
|
-
message: aborted ? "Agent execution was cancelled" : outcome === "error" ? "Agent model execution failed" : "Agent produced no assistant text"
|
|
20800
|
+
code: aborted ? "aborted" : handoffSelectionError || outcome === "error" ? "execution_error" : "empty_result",
|
|
20801
|
+
message: aborted ? "Agent execution was cancelled" : handoffSelectionError ? "Selected handoff evidence could not be verified" : outcome === "error" ? "Agent model execution failed" : "Agent produced no assistant text"
|
|
20564
20802
|
}
|
|
20565
20803
|
},
|
|
20566
20804
|
contextUsage: ctx.getContextUsage(),
|
|
@@ -20598,9 +20836,10 @@ function registerManagedAgentSettlementHandlers(pi, execution, options2) {
|
|
|
20598
20836
|
...current,
|
|
20599
20837
|
status: "failed",
|
|
20600
20838
|
text: void 0,
|
|
20839
|
+
resultBindings: void 0,
|
|
20601
20840
|
error: {
|
|
20602
20841
|
code: "result_too_large",
|
|
20603
|
-
message: "Agent
|
|
20842
|
+
message: "Agent result exceeded the mailbox result limit"
|
|
20604
20843
|
}
|
|
20605
20844
|
};
|
|
20606
20845
|
execution.resultWriteAttempts = 0;
|
|
@@ -20977,6 +21216,60 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
20977
21216
|
controller.sessionTreeChanged(ctx, controller.sessionSignal());
|
|
20978
21217
|
});
|
|
20979
21218
|
}
|
|
21219
|
+
registerManagedAgentAttachHandoffTool(
|
|
21220
|
+
pi,
|
|
21221
|
+
async (_id, params, _signal, _update, ctx) => {
|
|
21222
|
+
const state = execution.assignment;
|
|
21223
|
+
if (!state?.activeRequestId || state.completedRequestId || execution.pendingResult)
|
|
21224
|
+
fail(
|
|
21225
|
+
"invalid_request",
|
|
21226
|
+
"There is no matching active assignment for handoff selection",
|
|
21227
|
+
ATTACH_HANDOFF_TOOL
|
|
21228
|
+
);
|
|
21229
|
+
const managed = managedAgentIdentity(ctx);
|
|
21230
|
+
const assignmentMatches = (current) => current.activeRequestId === state.activeRequestId && state.activeRequestId === managed.activeRequestId && sameManagedAgentIdentity(state, current);
|
|
21231
|
+
if (!assignmentMatches(managed))
|
|
21232
|
+
fail(
|
|
21233
|
+
"invalid_request",
|
|
21234
|
+
"There is no matching active assignment for handoff selection",
|
|
21235
|
+
ATTACH_HANDOFF_TOOL
|
|
21236
|
+
);
|
|
21237
|
+
if (!params.files.every((ref) => parseSemanticResultRef(ref)))
|
|
21238
|
+
fail(
|
|
21239
|
+
"invalid_request",
|
|
21240
|
+
"Handoff selection accepts semantic result references only",
|
|
21241
|
+
ATTACH_HANDOFF_TOOL
|
|
21242
|
+
);
|
|
21243
|
+
const resolved = resolveMessageFiles(
|
|
21244
|
+
ctx,
|
|
21245
|
+
params.files,
|
|
21246
|
+
ATTACH_HANDOFF_TOOL
|
|
21247
|
+
);
|
|
21248
|
+
if (resolved.some((binding) => !isResultBinding(binding)) || new Set(resolved.map((binding) => binding.ref)).size !== resolved.length)
|
|
21249
|
+
fail(
|
|
21250
|
+
"invalid_request",
|
|
21251
|
+
"Handoff selection contains invalid or duplicate result references",
|
|
21252
|
+
ATTACH_HANDOFF_TOOL
|
|
21253
|
+
);
|
|
21254
|
+
const bindings = verifyHandoffSelection(ctx, resolved);
|
|
21255
|
+
const latest = managedAgentIdentity(ctx);
|
|
21256
|
+
if (!assignmentMatches(latest) || latest.activeRequestId !== state.activeRequestId)
|
|
21257
|
+
fail(
|
|
21258
|
+
"invalid_request",
|
|
21259
|
+
"Managed-agent assignment changed during handoff selection",
|
|
21260
|
+
ATTACH_HANDOFF_TOOL
|
|
21261
|
+
);
|
|
21262
|
+
return {
|
|
21263
|
+
content: [
|
|
21264
|
+
{
|
|
21265
|
+
type: "text",
|
|
21266
|
+
text: bindings.length ? `Selected ${bindings.length} semantic result reference${bindings.length === 1 ? "" : "s"} for your eventual completion. This does not send evidence now.` : "Cleared the selected semantic result references for your eventual completion."
|
|
21267
|
+
}
|
|
21268
|
+
],
|
|
21269
|
+
details: handoffSelectionDetails(state, bindings)
|
|
21270
|
+
};
|
|
21271
|
+
}
|
|
21272
|
+
);
|
|
20980
21273
|
registerManagedAgentAskOwnerTool(
|
|
20981
21274
|
pi,
|
|
20982
21275
|
createManagedAgentAskOwnerHandler({
|
|
@@ -21303,7 +21596,7 @@ function allowedAgentDefinitionsFromEnv() {
|
|
|
21303
21596
|
function managedAgentEnvironmentError() {
|
|
21304
21597
|
const e = process.env;
|
|
21305
21598
|
if (!e.PI_HERDSMAN_MAILBOX) return "PI_HERDSMAN_MAILBOX missing";
|
|
21306
|
-
if (!
|
|
21599
|
+
if (!isAbsolute6(e.PI_HERDSMAN_MAILBOX))
|
|
21307
21600
|
return "PI_HERDSMAN_MAILBOX is not absolute";
|
|
21308
21601
|
if (!validId(e.PI_HERDSMAN_RUN_ID)) return "PI_HERDSMAN_RUN_ID invalid";
|
|
21309
21602
|
if (!validId(e.PI_HERDSMAN_OWNER_SESSION_ID))
|
|
@@ -21641,7 +21934,7 @@ function registerManagedAgentSessionStartHandler(pi, execution, options2) {
|
|
|
21641
21934
|
}
|
|
21642
21935
|
});
|
|
21643
21936
|
}
|
|
21644
|
-
var DELEGATING_AGENT_ROLE_CHARTER, AGENT_REQUIRED_EVIDENCE_ENTRY, READ_EVIDENCE_MAX_BYTES, READ_EVIDENCE_MAX_LINES, SESSION_REQUEST_ID, EVIDENCE_CONTINUATION_RESERVE, AGENT_LABEL_PATTERN2, RESERVED_PREFIX, AGENT_CONTEXT_RETIRED_ENTRY, CONTEXT_RETIREMENT_INSTRUCTION, CONTEXT_RETIREMENT_REMINDER;
|
|
21937
|
+
var DELEGATING_AGENT_ROLE_CHARTER, AGENT_REQUIRED_EVIDENCE_ENTRY, READ_EVIDENCE_MAX_BYTES, READ_EVIDENCE_MAX_LINES, SESSION_REQUEST_ID, EVIDENCE_CONTINUATION_RESERVE, AGENT_LABEL_PATTERN2, RESERVED_PREFIX, AGENT_CONTEXT_RETIRED_ENTRY, CONTEXT_RETIREMENT_INSTRUCTION, CONTEXT_RETIREMENT_REMINDER, ATTACH_HANDOFF_TOOL;
|
|
21645
21938
|
var init_managed_agent_runtime = __esm({
|
|
21646
21939
|
"extension/managed-agent-runtime.ts"() {
|
|
21647
21940
|
init_mailbox();
|
|
@@ -21670,6 +21963,7 @@ ${FILE_HANDOFF_GUIDANCE}`;
|
|
|
21670
21963
|
AGENT_CONTEXT_RETIRED_ENTRY = "pi-herdsman-agent-context-retired";
|
|
21671
21964
|
CONTEXT_RETIREMENT_INSTRUCTION = "Context pressure has retired this session. Do not start new work or new agents. Finish the current coherent operation at the next safe point. Avoid nonessential tool calls and validation; perform only what is needed for a reliable handoff. Resolve already-running dependent work, then complete this assignment with a self-contained handoff covering completed work, current state, relevant files, validation performed, unresolved issues, and exact next steps. This session will not be continued or forked.";
|
|
21672
21965
|
CONTEXT_RETIREMENT_REMINDER = "This session is retired. Do not start new work or agents. Finish the current assignment and return a self-contained handoff.";
|
|
21966
|
+
ATTACH_HANDOFF_TOOL = "attach_handoff";
|
|
21673
21967
|
}
|
|
21674
21968
|
});
|
|
21675
21969
|
|
|
@@ -21681,7 +21975,7 @@ import {
|
|
|
21681
21975
|
getSelectListTheme as getSelectListTheme2,
|
|
21682
21976
|
SessionManager as SessionManager2
|
|
21683
21977
|
} from "@earendil-works/pi-coding-agent";
|
|
21684
|
-
import { readFileSync as readFileSync13, statSync as
|
|
21978
|
+
import { readFileSync as readFileSync13, statSync as statSync8, unlinkSync as unlinkSync12 } from "node:fs";
|
|
21685
21979
|
import { basename as basename9, dirname as dirname9, resolve as resolve7 } from "node:path";
|
|
21686
21980
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
21687
21981
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
@@ -21689,7 +21983,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
21689
21983
|
// package.json
|
|
21690
21984
|
var package_default = {
|
|
21691
21985
|
name: "pi-herdsman",
|
|
21692
|
-
version: "0.34.
|
|
21986
|
+
version: "0.34.1",
|
|
21693
21987
|
type: "module",
|
|
21694
21988
|
description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
|
|
21695
21989
|
license: "Apache-2.0",
|
|
@@ -21852,8 +22146,8 @@ import { getSelectListTheme } from "@earendil-works/pi-coding-agent";
|
|
|
21852
22146
|
import { visibleWidth as visibleWidth2 } from "@earendil-works/pi-tui";
|
|
21853
22147
|
import { contentText as contentText4, getSupportedThinkingLevels } from "@earendil-works/pi-ai";
|
|
21854
22148
|
import { createHash as createHash12, randomUUID as randomUUID14 } from "node:crypto";
|
|
21855
|
-
import { lstatSync as lstatSync6, realpathSync as realpathSync5, statSync as
|
|
21856
|
-
import { dirname as dirname8, isAbsolute as
|
|
22149
|
+
import { lstatSync as lstatSync6, realpathSync as realpathSync5, statSync as statSync7, unlinkSync as unlinkSync11 } from "node:fs";
|
|
22150
|
+
import { dirname as dirname8, isAbsolute as isAbsolute7, join as join12, resolve as resolve6 } from "node:path";
|
|
21857
22151
|
|
|
21858
22152
|
// extension/peer-transport.ts
|
|
21859
22153
|
init_lock();
|
|
@@ -24132,7 +24426,7 @@ function registerLeadRuntime(pi, options2) {
|
|
|
24132
24426
|
options2.supervisionHost.contextType
|
|
24133
24427
|
),
|
|
24134
24428
|
persistedTranscriptReady: (target) => persistedTranscriptReady(target, (path) => {
|
|
24135
|
-
const file2 = (options2.supervisionHost.statSync ??
|
|
24429
|
+
const file2 = (options2.supervisionHost.statSync ?? statSync7)(path, {
|
|
24136
24430
|
throwIfNoEntry: false
|
|
24137
24431
|
});
|
|
24138
24432
|
return !!file2?.isFile() && file2.size > 0;
|
|
@@ -25483,7 +25777,7 @@ function createLeadSupervisionRuntime(host) {
|
|
|
25483
25777
|
manager.workspaceId,
|
|
25484
25778
|
ctx.signal
|
|
25485
25779
|
);
|
|
25486
|
-
if (group.repoKey !== manager.repoKey
|
|
25780
|
+
if (group.repoKey !== manager.repoKey)
|
|
25487
25781
|
throw new Error("Manager workspace is not the assigned project");
|
|
25488
25782
|
const incompatible = [];
|
|
25489
25783
|
const [leads, topology] = await Promise.all([
|
|
@@ -25501,7 +25795,7 @@ function createLeadSupervisionRuntime(host) {
|
|
|
25501
25795
|
await host.reconcileProjectAssignments?.(
|
|
25502
25796
|
ctx,
|
|
25503
25797
|
group.repoKey,
|
|
25504
|
-
|
|
25798
|
+
manager.workspaceId,
|
|
25505
25799
|
topology.source.source_checkout_path
|
|
25506
25800
|
);
|
|
25507
25801
|
const assignments = host.listProjectAssignments(
|
|
@@ -25645,7 +25939,41 @@ function createLeadSupervisionRuntime(host) {
|
|
|
25645
25939
|
const sessions = new Set(assignments.map((assignment) => assignment.id));
|
|
25646
25940
|
if (sessions.size !== assignments.length)
|
|
25647
25941
|
throw new Error("Multiple project assignments match a Lead session");
|
|
25648
|
-
|
|
25942
|
+
const repoManagers = host.listManagerDescriptors(host.supervisionRuntime()).filter((candidate) => candidate.repoKey === manager.repoKey);
|
|
25943
|
+
const ordinarySupervisionAvailable = repoManagers.length === 1 && host.sameManagerDescriptor(repoManagers[0], manager);
|
|
25944
|
+
const leads = await Promise.all(
|
|
25945
|
+
snapshot2.leads.map(async (lead) => {
|
|
25946
|
+
try {
|
|
25947
|
+
const descriptor = {
|
|
25948
|
+
piSessionId: lead.lead,
|
|
25949
|
+
piSessionFile: lead.piSessionFile,
|
|
25950
|
+
paneId: lead.paneId,
|
|
25951
|
+
tabId: lead.tabId,
|
|
25952
|
+
workspaceId: lead.workspaceId
|
|
25953
|
+
};
|
|
25954
|
+
const agent = await host.remoteChiefAgent(ctx, descriptor);
|
|
25955
|
+
if (typeof agent?.cwd !== "string" || !agent.cwd) return void 0;
|
|
25956
|
+
const repository = await localRepositoryScope(
|
|
25957
|
+
host.pi,
|
|
25958
|
+
{ ...ctx, cwd: agent.cwd },
|
|
25959
|
+
lead.workspaceId,
|
|
25960
|
+
ctx.signal
|
|
25961
|
+
);
|
|
25962
|
+
if (repository.repoKey !== manager.repoKey) return void 0;
|
|
25963
|
+
const current = await host.remoteChiefAgent(ctx, descriptor);
|
|
25964
|
+
if (!current || current.cwd !== agent.cwd) return void 0;
|
|
25965
|
+
return lead;
|
|
25966
|
+
} catch (error2) {
|
|
25967
|
+
if (ctx.signal?.aborted) throw ctx.signal.reason;
|
|
25968
|
+
if (error2 instanceof Error && error2.name === "AbortError")
|
|
25969
|
+
throw error2;
|
|
25970
|
+
return void 0;
|
|
25971
|
+
}
|
|
25972
|
+
})
|
|
25973
|
+
);
|
|
25974
|
+
return leads.filter((lead) => lead !== void 0).filter(
|
|
25975
|
+
(lead) => sessions.has(lead.lead) || ordinarySupervisionAvailable
|
|
25976
|
+
).map((lead) => ({
|
|
25649
25977
|
...lead,
|
|
25650
25978
|
relationship: sessions.has(lead.lead) ? "assigned" : "supervised"
|
|
25651
25979
|
}));
|
|
@@ -27341,15 +27669,23 @@ function createLeadProjectRuntime(host) {
|
|
|
27341
27669
|
manager.workspaceId,
|
|
27342
27670
|
signal
|
|
27343
27671
|
);
|
|
27344
|
-
if (group.repoKey !== manager.repoKey
|
|
27672
|
+
if (group.repoKey !== manager.repoKey)
|
|
27345
27673
|
throw new Error("Manager worktree group is not authoritative");
|
|
27674
|
+
const localScope = await localRepositoryScope(
|
|
27675
|
+
host.pi,
|
|
27676
|
+
ctx,
|
|
27677
|
+
manager.workspaceId,
|
|
27678
|
+
signal
|
|
27679
|
+
);
|
|
27680
|
+
if (!localScope.isPrimary || localScope.repoKey !== manager.repoKey)
|
|
27681
|
+
throw new Error("Manager checkout is not the verified primary checkout");
|
|
27346
27682
|
const topology = await host.runHerdr(
|
|
27347
27683
|
host.pi,
|
|
27348
27684
|
ctx,
|
|
27349
27685
|
["worktree", "list", "--workspace", manager.workspaceId],
|
|
27350
27686
|
{ signal }
|
|
27351
27687
|
);
|
|
27352
|
-
if (topology?.source?.
|
|
27688
|
+
if (topology?.source?.repo_key !== manager.repoKey || typeof topology?.source?.source_checkout_path !== "string" || realpathSync5(topology.source.source_checkout_path) !== localScope.checkoutPath || !Array.isArray(topology?.worktrees))
|
|
27353
27689
|
throw new Error("Herdr worktree topology is not authoritative");
|
|
27354
27690
|
const assignments = host.listProjectAssignments(host.supervisionRuntime(), manager.repoKey).filter((assignment2) => assignment2.branch === branch);
|
|
27355
27691
|
if (assignments.length !== 1)
|
|
@@ -27903,13 +28239,21 @@ function createLeadProjectRuntime(host) {
|
|
|
27903
28239
|
branch
|
|
27904
28240
|
);
|
|
27905
28241
|
if (!before) throw new Error("No project assignment exists on this branch");
|
|
28242
|
+
const localScope = await localRepositoryScope(
|
|
28243
|
+
host.pi,
|
|
28244
|
+
ctx,
|
|
28245
|
+
initialManager.workspaceId,
|
|
28246
|
+
operationSignal
|
|
28247
|
+
);
|
|
28248
|
+
if (!localScope.isPrimary || localScope.repoKey !== initialManager.repoKey)
|
|
28249
|
+
throw new Error("Manager checkout is not the verified primary checkout");
|
|
27906
28250
|
const initialTopology = await host.runHerdr(
|
|
27907
28251
|
host.pi,
|
|
27908
28252
|
ctx,
|
|
27909
28253
|
["worktree", "list", "--workspace", initialManager.workspaceId],
|
|
27910
28254
|
{ signal: operationSignal }
|
|
27911
28255
|
);
|
|
27912
|
-
if (initialTopology?.source?.repo_key !== initialManager.repoKey || initialTopology?.source?.
|
|
28256
|
+
if (initialTopology?.source?.repo_key !== initialManager.repoKey || typeof initialTopology?.source?.source_checkout_path !== "string" || realpathSync5(initialTopology.source.source_checkout_path) !== localScope.checkoutPath)
|
|
27913
28257
|
throw new Error("Herdr worktree topology is unavailable or inconsistent");
|
|
27914
28258
|
await host.reconcileProjectAssignments(
|
|
27915
28259
|
ctx,
|
|
@@ -27953,15 +28297,25 @@ function createLeadProjectRuntime(host) {
|
|
|
27953
28297
|
manager.workspaceId,
|
|
27954
28298
|
operationSignal
|
|
27955
28299
|
);
|
|
27956
|
-
if (group.repoKey !== manager.repoKey
|
|
28300
|
+
if (group.repoKey !== manager.repoKey)
|
|
27957
28301
|
throw new Error("Manager worktree group is not authoritative");
|
|
28302
|
+
const localScope2 = await localRepositoryScope(
|
|
28303
|
+
host.pi,
|
|
28304
|
+
ctx,
|
|
28305
|
+
manager.workspaceId,
|
|
28306
|
+
operationSignal
|
|
28307
|
+
);
|
|
28308
|
+
if (!localScope2.isPrimary || localScope2.repoKey !== manager.repoKey)
|
|
28309
|
+
throw new Error(
|
|
28310
|
+
"Manager checkout is not the verified primary checkout"
|
|
28311
|
+
);
|
|
27958
28312
|
const topology = await host.runHerdr(
|
|
27959
28313
|
host.pi,
|
|
27960
28314
|
ctx,
|
|
27961
28315
|
["worktree", "list", "--workspace", manager.workspaceId],
|
|
27962
28316
|
{ signal: operationSignal }
|
|
27963
28317
|
);
|
|
27964
|
-
if (topology?.source?.repo_key !== manager.repoKey || topology?.source?.
|
|
28318
|
+
if (topology?.source?.repo_key !== manager.repoKey || typeof topology?.source?.source_checkout_path !== "string" || realpathSync5(topology.source.source_checkout_path) !== localScope2.checkoutPath || !Array.isArray(topology.worktrees) || topology.worktrees.some(
|
|
27965
28319
|
(worktree) => typeof worktree?.path !== "string" || !worktree.path || worktree.branch !== void 0 && typeof worktree.branch !== "string"
|
|
27966
28320
|
))
|
|
27967
28321
|
throw new Error(
|
|
@@ -28123,7 +28477,7 @@ Type forget ${branch} to confirm.`,
|
|
|
28123
28477
|
manager.workspaceId,
|
|
28124
28478
|
ctx.signal
|
|
28125
28479
|
);
|
|
28126
|
-
if (group.repoKey !== manager.repoKey
|
|
28480
|
+
if (group.repoKey !== manager.repoKey)
|
|
28127
28481
|
throw new Error("Manager worktree group is not authoritative");
|
|
28128
28482
|
if (enabled) {
|
|
28129
28483
|
const answer = await ctx.ui.input(
|
|
@@ -28153,7 +28507,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
28153
28507
|
manager.workspaceId,
|
|
28154
28508
|
ctx.signal
|
|
28155
28509
|
);
|
|
28156
|
-
if (group.repoKey !== manager.repoKey
|
|
28510
|
+
if (group.repoKey !== manager.repoKey)
|
|
28157
28511
|
throw new Error("Manager worktree group is not authoritative");
|
|
28158
28512
|
const current = await host.currentManager(ctx);
|
|
28159
28513
|
if (!current || !host.sameManagerDescriptor(current, manager))
|
|
@@ -28281,13 +28635,23 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
28281
28635
|
manager
|
|
28282
28636
|
))
|
|
28283
28637
|
throw sourceError;
|
|
28638
|
+
const localScope = await localRepositoryScope(
|
|
28639
|
+
host.pi,
|
|
28640
|
+
ctx,
|
|
28641
|
+
manager.workspaceId,
|
|
28642
|
+
operationSignal
|
|
28643
|
+
);
|
|
28644
|
+
if (!localScope.isPrimary || localScope.repoKey !== manager.repoKey)
|
|
28645
|
+
throw new Error(
|
|
28646
|
+
"Manager checkout is not the verified primary checkout"
|
|
28647
|
+
);
|
|
28284
28648
|
const topology = await host.runHerdr(
|
|
28285
28649
|
host.pi,
|
|
28286
28650
|
ctx,
|
|
28287
28651
|
["worktree", "list", "--workspace", manager.workspaceId],
|
|
28288
28652
|
{ signal: operationSignal }
|
|
28289
28653
|
);
|
|
28290
|
-
if (topology?.source?.
|
|
28654
|
+
if (topology?.source?.repo_key !== manager.repoKey || typeof topology?.source?.source_checkout_path !== "string" || realpathSync5(topology.source.source_checkout_path) !== localScope.checkoutPath)
|
|
28291
28655
|
throw sourceError;
|
|
28292
28656
|
const targetPath2 = topology.source.source_checkout_path;
|
|
28293
28657
|
const sourceRef = await host.pi.exec(
|
|
@@ -28445,7 +28809,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
28445
28809
|
if (probe.code !== 0 || probe.killed || probe.stderr?.trim())
|
|
28446
28810
|
throw new Error("Git operation state is unverifiable");
|
|
28447
28811
|
try {
|
|
28448
|
-
|
|
28812
|
+
statSync7(resolve6(path, String(probe.stdout ?? "").trim()));
|
|
28449
28813
|
throw new Error(`Git operation ${state} is in progress`);
|
|
28450
28814
|
} catch (error2) {
|
|
28451
28815
|
if (error2.code !== "ENOENT" && !(error2 instanceof Error && error2.message.startsWith("Git operation ")))
|
|
@@ -28688,7 +29052,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
28688
29052
|
continue;
|
|
28689
29053
|
}
|
|
28690
29054
|
try {
|
|
28691
|
-
|
|
29055
|
+
statSync7(
|
|
28692
29056
|
resolve6(targetPath, String(path.stdout ?? "").trim())
|
|
28693
29057
|
);
|
|
28694
29058
|
operationStates.push(state);
|
|
@@ -28826,26 +29190,24 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
28826
29190
|
const manager = await currentManager(ctx);
|
|
28827
29191
|
if (!manager || !leadRuntime.managerLease || !sameManagerDescriptor2(manager, leadRuntime.managerLease.descriptor))
|
|
28828
29192
|
throw new Error("Manager lease is no longer active");
|
|
28829
|
-
const
|
|
29193
|
+
const localScope = await localRepositoryScope(
|
|
28830
29194
|
pi,
|
|
28831
29195
|
ctx,
|
|
28832
29196
|
manager.workspaceId,
|
|
28833
29197
|
signal
|
|
28834
29198
|
);
|
|
28835
|
-
if (
|
|
28836
|
-
throw new Error(
|
|
28837
|
-
|
|
28838
|
-
);
|
|
28839
|
-
const primaryWorkspaceId = group.primaryWorkspaceId;
|
|
29199
|
+
if (!localScope.isPrimary || localScope.repoKey !== manager.repoKey)
|
|
29200
|
+
throw new Error("Manager checkout is not the verified primary checkout");
|
|
29201
|
+
const primaryWorkspaceId = manager.workspaceId;
|
|
28840
29202
|
const runtime = supervisionRuntime3();
|
|
28841
29203
|
const branch = operation.branch;
|
|
28842
29204
|
const topology = await runHerdr2(
|
|
28843
29205
|
pi,
|
|
28844
29206
|
ctx,
|
|
28845
|
-
["worktree", "list", "--
|
|
29207
|
+
["worktree", "list", "--cwd", localScope.checkoutPath],
|
|
28846
29208
|
{ signal }
|
|
28847
29209
|
);
|
|
28848
|
-
if (topology?.source?.
|
|
29210
|
+
if (topology?.source?.repo_key !== manager.repoKey || !Array.isArray(topology?.worktrees))
|
|
28849
29211
|
throw new Error("Herdr worktree topology is not authoritative");
|
|
28850
29212
|
if (operation.action === "resume")
|
|
28851
29213
|
await host.reconcileProjectAssignments(
|
|
@@ -29028,6 +29390,15 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29028
29390
|
}
|
|
29029
29391
|
const promptPaths = [];
|
|
29030
29392
|
try {
|
|
29393
|
+
const currentScope = await localRepositoryScope(
|
|
29394
|
+
pi,
|
|
29395
|
+
ctx,
|
|
29396
|
+
manager.workspaceId,
|
|
29397
|
+
signal
|
|
29398
|
+
);
|
|
29399
|
+
const current = await currentManager(ctx);
|
|
29400
|
+
if (!currentScope.isPrimary || currentScope.repoKey !== manager.repoKey || currentScope.checkoutPath !== localScope.checkoutPath || !current || !sameManagerDescriptor2(current, manager))
|
|
29401
|
+
throw new Error("Manager identity changed before project activation");
|
|
29031
29402
|
let workspaceId;
|
|
29032
29403
|
let paneId;
|
|
29033
29404
|
let tabId;
|
|
@@ -29053,8 +29424,8 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29053
29424
|
[
|
|
29054
29425
|
"worktree",
|
|
29055
29426
|
"open",
|
|
29056
|
-
"--
|
|
29057
|
-
|
|
29427
|
+
"--cwd",
|
|
29428
|
+
localScope.checkoutPath,
|
|
29058
29429
|
"--branch",
|
|
29059
29430
|
assignment.branch,
|
|
29060
29431
|
"--no-focus"
|
|
@@ -29076,8 +29447,8 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29076
29447
|
const args = [
|
|
29077
29448
|
"worktree",
|
|
29078
29449
|
"create",
|
|
29079
|
-
"--
|
|
29080
|
-
|
|
29450
|
+
"--cwd",
|
|
29451
|
+
localScope.checkoutPath,
|
|
29081
29452
|
"--branch",
|
|
29082
29453
|
assignment.branch,
|
|
29083
29454
|
"--no-focus"
|
|
@@ -29113,11 +29484,11 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29113
29484
|
timeout: 1e4
|
|
29114
29485
|
})
|
|
29115
29486
|
]);
|
|
29116
|
-
if (common.code !== 0 || common.killed || common.stderr?.trim() || branchResult.code !== 0 || branchResult.killed || branchResult.stderr?.trim() || !
|
|
29487
|
+
if (common.code !== 0 || common.killed || common.stderr?.trim() || branchResult.code !== 0 || branchResult.killed || branchResult.stderr?.trim() || !isAbsolute7(String(common.stdout ?? "").trim()) || realpathSync5(String(common.stdout).trim()) !== realpathSync5(manager.repoKey) || String(branchResult.stdout ?? "").trim() !== assignment.branch)
|
|
29117
29488
|
throw new Error(
|
|
29118
29489
|
"Herdr checkout does not match the assigned repository and branch"
|
|
29119
29490
|
);
|
|
29120
|
-
if (!
|
|
29491
|
+
if (!isAbsolute7(cwd) || workspaceId === primaryWorkspaceId || realpathSync5(cwd) === realpathSync5(topology.source.source_checkout_path) || matchingWorktrees.length === 1 && realpathSync5(cwd) !== realpathSync5(matchingWorktrees[0].path))
|
|
29121
29492
|
throw new Error(
|
|
29122
29493
|
"Herdr checkout is not the verified linked project worktree"
|
|
29123
29494
|
);
|
|
@@ -29429,7 +29800,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29429
29800
|
throw error2;
|
|
29430
29801
|
} finally {
|
|
29431
29802
|
for (const promptPath of promptPaths)
|
|
29432
|
-
if (
|
|
29803
|
+
if (statSync7(promptPath, { throwIfNoEntry: false }))
|
|
29433
29804
|
unlinkSync11(promptPath);
|
|
29434
29805
|
}
|
|
29435
29806
|
};
|
|
@@ -29660,7 +30031,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29660
30031
|
const currentLead2 = (await directReports(ctx)).find(
|
|
29661
30032
|
(candidate) => reportSession(candidate) === params.session
|
|
29662
30033
|
);
|
|
29663
|
-
if (!currentAuthority || currentAuthority.leaseId !== authority.leaseId || !currentLead2 || !sameLeadIdentity(currentLead2, lead) || !currentLead2.availableActions.includes("inspect"))
|
|
30034
|
+
if (!currentAuthority || currentAuthority.leaseId !== authority.leaseId || !currentLead2 || !sameLeadIdentity(currentLead2, lead) || currentLead2.relationship !== lead.relationship || !currentLead2.availableActions.includes("inspect"))
|
|
29664
30035
|
throw new Error("Lead changed during inspection");
|
|
29665
30036
|
return result({
|
|
29666
30037
|
ok: true,
|
|
@@ -29852,7 +30223,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29852
30223
|
manager.workspaceId,
|
|
29853
30224
|
ctx.signal
|
|
29854
30225
|
);
|
|
29855
|
-
if (scope.repoKey !== manager.repoKey
|
|
30226
|
+
if (scope.repoKey !== manager.repoKey)
|
|
29856
30227
|
throw new Error("Manager workspace authority could not be verified");
|
|
29857
30228
|
const assignment = host.readProjectAssignment(
|
|
29858
30229
|
host.supervisionRuntime(),
|
|
@@ -29899,7 +30270,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
29899
30270
|
currentManager2.workspaceId,
|
|
29900
30271
|
ctx.signal
|
|
29901
30272
|
);
|
|
29902
|
-
if (currentScope.repoKey !== assignment.repoKey
|
|
30273
|
+
if (currentScope.repoKey !== assignment.repoKey)
|
|
29903
30274
|
throw new Error(
|
|
29904
30275
|
"Manager workspace authority changed before required evidence was updated"
|
|
29905
30276
|
);
|
|
@@ -31965,7 +32336,24 @@ function createLeadInboxRuntime(host) {
|
|
|
31965
32336
|
});
|
|
31966
32337
|
return authorized;
|
|
31967
32338
|
};
|
|
32339
|
+
const recordedManagerSender = (record) => {
|
|
32340
|
+
const senders = listManagerDescriptors2(supervisionRuntime3()).filter(
|
|
32341
|
+
(manager) => manager.piSessionId === record.fromSessionId
|
|
32342
|
+
);
|
|
32343
|
+
if (senders.length === 1) return senders[0];
|
|
32344
|
+
if (senders.length > 1) return void 0;
|
|
32345
|
+
try {
|
|
32346
|
+
listManagerDescriptors2(supervisionRuntime3(), true);
|
|
32347
|
+
} catch (error2) {
|
|
32348
|
+
throw new Error(
|
|
32349
|
+
"Manager descriptor verification is temporarily unavailable",
|
|
32350
|
+
{ cause: error2 }
|
|
32351
|
+
);
|
|
32352
|
+
}
|
|
32353
|
+
return void 0;
|
|
32354
|
+
};
|
|
31968
32355
|
const authorizeChiefRecord = async (record, ctx, verifyLiveChief = true) => {
|
|
32356
|
+
const sameLiveLead = (current, original) => current.workspace_id === original.workspace_id && current.pane_id === original.pane_id && current.tab_id === original.tab_id && current.cwd === original.cwd;
|
|
31969
32357
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
31970
32358
|
if (record.toSessionId !== sessionId) return false;
|
|
31971
32359
|
if (!record.build || !sameRuntimeBuild2(record.build, HERDSMAN_BUILD2))
|
|
@@ -31982,12 +32370,12 @@ function createLeadInboxRuntime(host) {
|
|
|
31982
32370
|
managerDiagnostic("project_assignment_scope_complete");
|
|
31983
32371
|
if (!scope.workspaceIds.includes(workspaceId2))
|
|
31984
32372
|
return projectAssignmentAuthorized(false, "workspace_scope_mismatch");
|
|
31985
|
-
const
|
|
32373
|
+
const assignment2 = record.branch ? readProjectAssignment2(
|
|
31986
32374
|
supervisionRuntime3(),
|
|
31987
32375
|
scope.repoKey,
|
|
31988
32376
|
record.branch
|
|
31989
32377
|
) : void 0;
|
|
31990
|
-
if (!
|
|
32378
|
+
if (!assignment2 || assignment2.id !== sessionId || record.id !== assignment2.id)
|
|
31991
32379
|
return projectAssignmentAuthorized(
|
|
31992
32380
|
false,
|
|
31993
32381
|
"assignment_evidence_mismatch"
|
|
@@ -32003,7 +32391,7 @@ function createLeadInboxRuntime(host) {
|
|
|
32003
32391
|
if (topology?.source?.source_workspace_id !== scope.primaryWorkspaceId || topology?.source?.repo_key !== scope.repoKey || !Array.isArray(topology?.worktrees))
|
|
32004
32392
|
return projectAssignmentAuthorized(false, "worktree_topology_mismatch");
|
|
32005
32393
|
const worktrees = topology.worktrees.filter(
|
|
32006
|
-
(worktree) => worktree.branch ===
|
|
32394
|
+
(worktree) => worktree.branch === assignment2.branch
|
|
32007
32395
|
);
|
|
32008
32396
|
if (worktrees.length !== 1)
|
|
32009
32397
|
return projectAssignmentAuthorized(false, "branch_placement_mismatch");
|
|
@@ -32025,7 +32413,7 @@ function createLeadInboxRuntime(host) {
|
|
|
32025
32413
|
}
|
|
32026
32414
|
if (leadRuntime.chiefMode === "active") {
|
|
32027
32415
|
const chief = await currentChiefAuthority(ctx, true);
|
|
32028
|
-
if (!chief || record.leaseId !== chief.leaseId || record.leadSessionId !== record.fromSessionId)
|
|
32416
|
+
if (!chief || record.kind !== "manager_message" && record.leaseId !== chief.leaseId || record.leadSessionId !== record.fromSessionId)
|
|
32029
32417
|
return false;
|
|
32030
32418
|
if (record.kind === "lead_message") {
|
|
32031
32419
|
const leads = await liveLead(ctx, record.fromSessionId);
|
|
@@ -32046,29 +32434,37 @@ function createLeadInboxRuntime(host) {
|
|
|
32046
32434
|
supervisionRuntime3(),
|
|
32047
32435
|
record.leadSessionId
|
|
32048
32436
|
);
|
|
32049
|
-
const
|
|
32437
|
+
const supervisor = await host.resolveEffectiveSupervisor(
|
|
32050
32438
|
ctx,
|
|
32051
32439
|
record.fromSessionId,
|
|
32052
32440
|
leads[0].workspace_id,
|
|
32053
32441
|
scope2
|
|
32054
32442
|
);
|
|
32055
|
-
return !!state2 && (state2.role ?? "lead") === "lead" &&
|
|
32443
|
+
return !!state2 && (state2.role ?? "lead") === "lead" && supervisor.kind === "chief" && supervisor.chief.piSessionId === chief.piSessionId && supervisor.chief.leaseId === chief.leaseId;
|
|
32056
32444
|
}
|
|
32057
32445
|
if (record.kind !== "manager_message") return false;
|
|
32058
|
-
const manager2 =
|
|
32059
|
-
|
|
32446
|
+
const manager2 = recordedManagerSender(record);
|
|
32447
|
+
if (!manager2) return false;
|
|
32448
|
+
if (record.leaseId !== manager2.leaseId) return false;
|
|
32449
|
+
const managerState2 = readLeadCoordinationState2(
|
|
32450
|
+
supervisionRuntime3(),
|
|
32451
|
+
manager2.piSessionId
|
|
32060
32452
|
);
|
|
32061
|
-
if (!
|
|
32062
|
-
|
|
32063
|
-
|
|
32453
|
+
if (!managerState2)
|
|
32454
|
+
throw new Error(
|
|
32455
|
+
"Manager coordination state is temporarily unavailable"
|
|
32456
|
+
);
|
|
32457
|
+
if (managerState2.role !== "manager" || managerState2.piSessionId !== manager2.piSessionId || !sameRuntimeBuild2(manager2.build, HERDSMAN_BUILD2) || !sameRuntimeBuild2(managerState2.build, HERDSMAN_BUILD2))
|
|
32064
32458
|
return false;
|
|
32459
|
+
if (!await remoteChiefAgent(ctx, manager2))
|
|
32460
|
+
throw new Error("Manager live identity is temporarily unavailable");
|
|
32065
32461
|
const scope = await worktreeGroupScope2(
|
|
32066
32462
|
pi,
|
|
32067
32463
|
ctx,
|
|
32068
32464
|
manager2.workspaceId,
|
|
32069
32465
|
ctx.signal
|
|
32070
32466
|
);
|
|
32071
|
-
return scope.
|
|
32467
|
+
return scope.repoKey === manager2.repoKey;
|
|
32072
32468
|
}
|
|
32073
32469
|
if (activeRole() === "manager" && !leadRuntime.roleSuspended) {
|
|
32074
32470
|
if (record.kind === "chief_message") {
|
|
@@ -32079,49 +32475,102 @@ function createLeadInboxRuntime(host) {
|
|
|
32079
32475
|
if (!manager2 || record.leaseId !== manager2.leaseId || record.kind !== "lead_message" || record.leadSessionId !== record.fromSessionId)
|
|
32080
32476
|
return false;
|
|
32081
32477
|
const leads = await liveLead(ctx, record.fromSessionId);
|
|
32082
|
-
if (leads.length !== 1) return false;
|
|
32083
|
-
const
|
|
32478
|
+
if (leads.length !== 1 || typeof leads[0].cwd !== "string") return false;
|
|
32479
|
+
const lead = leads[0];
|
|
32480
|
+
const scope = await localRepositoryScope(
|
|
32084
32481
|
pi,
|
|
32085
|
-
ctx,
|
|
32086
|
-
|
|
32482
|
+
{ ...ctx, cwd: lead.cwd },
|
|
32483
|
+
lead.workspace_id,
|
|
32087
32484
|
ctx.signal
|
|
32088
32485
|
);
|
|
32089
|
-
const
|
|
32090
|
-
supervisionRuntime3(),
|
|
32091
|
-
record.leadSessionId
|
|
32092
|
-
);
|
|
32093
|
-
const supervisor2 = await host.resolveEffectiveSupervisor(
|
|
32486
|
+
const supervisor = await host.resolveEffectiveSupervisor(
|
|
32094
32487
|
ctx,
|
|
32095
32488
|
record.fromSessionId,
|
|
32096
|
-
|
|
32489
|
+
lead.workspace_id,
|
|
32097
32490
|
scope
|
|
32098
32491
|
);
|
|
32099
|
-
|
|
32492
|
+
const [refreshedManager, currentLeads] = await Promise.all([
|
|
32493
|
+
host.currentManager(ctx),
|
|
32494
|
+
liveLead(ctx, record.fromSessionId)
|
|
32495
|
+
]);
|
|
32496
|
+
const state2 = readLeadCoordinationState2(
|
|
32497
|
+
supervisionRuntime3(),
|
|
32498
|
+
record.leadSessionId
|
|
32499
|
+
);
|
|
32500
|
+
return !!refreshedManager && refreshedManager.piSessionId === manager2.piSessionId && refreshedManager.leaseId === manager2.leaseId && refreshedManager.repoKey === manager2.repoKey && currentLeads.length === 1 && sameLiveLead(currentLeads[0], lead) && supervisor.kind === "manager" && supervisor.manager.piSessionId === manager2.piSessionId && supervisor.manager.leaseId === manager2.leaseId && scope.repoKey === manager2.repoKey && !!state2 && (state2.role ?? "lead") === "lead";
|
|
32100
32501
|
}
|
|
32101
32502
|
if (activeRole() !== "lead" || leadRuntime.roleSuspended) return false;
|
|
32102
32503
|
if (record.kind === "chief_message") {
|
|
32103
32504
|
const chief = await currentChiefAuthority(ctx);
|
|
32104
32505
|
const workspaceId2 = host.workspaceId();
|
|
32105
32506
|
if (!workspaceId2) return false;
|
|
32106
|
-
|
|
32507
|
+
let localScope2;
|
|
32508
|
+
try {
|
|
32509
|
+
localScope2 = await localRepositoryScope(
|
|
32510
|
+
pi,
|
|
32511
|
+
ctx,
|
|
32512
|
+
workspaceId2,
|
|
32513
|
+
ctx.signal
|
|
32514
|
+
);
|
|
32515
|
+
} catch (error2) {
|
|
32516
|
+
if (!(error2 instanceof OperationError && error2.detail.details?.herdrCode === "not_git_worktree"))
|
|
32517
|
+
throw error2;
|
|
32518
|
+
}
|
|
32519
|
+
const supervisor = await host.resolveEffectiveSupervisor(
|
|
32107
32520
|
ctx,
|
|
32108
32521
|
sessionId,
|
|
32109
|
-
workspaceId2
|
|
32522
|
+
workspaceId2,
|
|
32523
|
+
localScope2
|
|
32110
32524
|
);
|
|
32525
|
+
let currentLocalScope = localScope2;
|
|
32526
|
+
if (localScope2) {
|
|
32527
|
+
currentLocalScope = await localRepositoryScope(
|
|
32528
|
+
pi,
|
|
32529
|
+
ctx,
|
|
32530
|
+
workspaceId2,
|
|
32531
|
+
ctx.signal
|
|
32532
|
+
);
|
|
32533
|
+
if (currentLocalScope.repoKey !== localScope2.repoKey || currentLocalScope.checkoutPath !== localScope2.checkoutPath)
|
|
32534
|
+
return false;
|
|
32535
|
+
}
|
|
32536
|
+
const currentChief = await currentChiefAuthority(ctx);
|
|
32537
|
+
if (host.workspaceId() !== workspaceId2 || ctx.sessionManager.getSessionId() !== sessionId)
|
|
32538
|
+
return false;
|
|
32111
32539
|
const state2 = readLeadCoordinationState2(supervisionRuntime3(), sessionId);
|
|
32112
|
-
return !!chief &&
|
|
32540
|
+
return !!chief && !!currentChief && currentChief.piSessionId === chief.piSessionId && currentChief.leaseId === chief.leaseId && (!localScope2 || !!currentLocalScope) && supervisor.kind === "chief" && supervisor.chief.piSessionId === chief.piSessionId && supervisor.chief.leaseId === chief.leaseId && !!state2 && chief.piSessionId === record.fromSessionId && chief.leaseId === record.leaseId && record.leadSessionId === sessionId;
|
|
32113
32541
|
}
|
|
32114
32542
|
if (record.kind !== "manager_message") return false;
|
|
32543
|
+
const manager = recordedManagerSender(record);
|
|
32544
|
+
if (!manager) return false;
|
|
32545
|
+
if (record.leaseId !== manager.leaseId || record.leadSessionId !== sessionId)
|
|
32546
|
+
return false;
|
|
32547
|
+
const managerState = readLeadCoordinationState2(
|
|
32548
|
+
supervisionRuntime3(),
|
|
32549
|
+
manager.piSessionId
|
|
32550
|
+
);
|
|
32551
|
+
if (!managerState)
|
|
32552
|
+
throw new Error("Manager coordination state is temporarily unavailable");
|
|
32553
|
+
if (managerState.role !== "manager" || managerState.piSessionId !== manager.piSessionId || !sameRuntimeBuild2(manager.build, HERDSMAN_BUILD2) || !sameRuntimeBuild2(managerState.build, HERDSMAN_BUILD2))
|
|
32554
|
+
return false;
|
|
32555
|
+
if (!await remoteChiefAgent(ctx, manager))
|
|
32556
|
+
throw new Error("Manager live identity is temporarily unavailable");
|
|
32115
32557
|
const workspaceId = host.workspaceId();
|
|
32116
32558
|
if (!workspaceId) throw new Error("Project scope cannot be verified");
|
|
32117
|
-
const
|
|
32559
|
+
const localScope = await localRepositoryScope(
|
|
32560
|
+
pi,
|
|
32118
32561
|
ctx,
|
|
32119
|
-
|
|
32120
|
-
|
|
32562
|
+
workspaceId,
|
|
32563
|
+
ctx.signal
|
|
32121
32564
|
);
|
|
32122
|
-
|
|
32123
|
-
|
|
32124
|
-
|
|
32565
|
+
if (localScope.repoKey !== manager.repoKey) return false;
|
|
32566
|
+
const assignment = host.projectAssignmentForScope(localScope, sessionId);
|
|
32567
|
+
if (assignment) {
|
|
32568
|
+
if (assignment.branch !== record.branch) return false;
|
|
32569
|
+
} else {
|
|
32570
|
+
const supervisor = host.managerForScope(localScope);
|
|
32571
|
+
if (!supervisor || supervisor.piSessionId !== manager.piSessionId || supervisor.leaseId !== manager.leaseId || record.branch !== void 0)
|
|
32572
|
+
return false;
|
|
32573
|
+
}
|
|
32125
32574
|
let state;
|
|
32126
32575
|
try {
|
|
32127
32576
|
state = readLeadCoordinationState2(supervisionRuntime3(), sessionId);
|
|
@@ -32133,8 +32582,6 @@ function createLeadInboxRuntime(host) {
|
|
|
32133
32582
|
return false;
|
|
32134
32583
|
throw error2;
|
|
32135
32584
|
}
|
|
32136
|
-
if (!manager)
|
|
32137
|
-
throw new Error("Manager authority is temporarily unavailable");
|
|
32138
32585
|
if (!state)
|
|
32139
32586
|
throw new Error("Lead coordination state is temporarily unavailable");
|
|
32140
32587
|
return (state.role ?? "lead") === "lead" && record.leaseId === manager.leaseId && record.fromSessionId === manager.piSessionId && record.leadSessionId === sessionId && record.kind === "manager_message";
|
|
@@ -32228,7 +32675,7 @@ function createLeadInboxRuntime(host) {
|
|
|
32228
32675
|
if (record.kind === "peer_message")
|
|
32229
32676
|
return authorizePeerRecord(record, ctx);
|
|
32230
32677
|
try {
|
|
32231
|
-
if (verifyLease) {
|
|
32678
|
+
if (verifyLease && !(record.kind === "manager_message" && (activeRole() === "lead" || activeRole() === "chief"))) {
|
|
32232
32679
|
const chief = activeRole() === "chief" || activeRole() === "manager" && record.kind === "chief_message" ? await currentChiefAuthority(ctx) : await currentManager(ctx);
|
|
32233
32680
|
if (!chief)
|
|
32234
32681
|
throw new Error("Supervisor lease could not be verified");
|
|
@@ -32733,11 +33180,11 @@ async function resolveLeadControllerRole(state, ctx, requestedRole, deps, option
|
|
|
32733
33180
|
const { paneId, tabId, workspaceId } = deps.identity;
|
|
32734
33181
|
if (requestedRole !== "manager" && !optional || !paneId || !tabId || !workspaceId)
|
|
32735
33182
|
return;
|
|
32736
|
-
|
|
32737
|
-
|
|
33183
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
33184
|
+
deps.activationGuard(sessionId, "Manager");
|
|
32738
33185
|
let scope;
|
|
32739
33186
|
try {
|
|
32740
|
-
scope = await deps.
|
|
33187
|
+
scope = await deps.localRepositoryScope(workspaceId, ctx.signal);
|
|
32741
33188
|
} catch (error2) {
|
|
32742
33189
|
if (!deps.isCurrent()) return;
|
|
32743
33190
|
if (error2 instanceof OperationError && error2.detail.details?.herdrCode === "not_git_worktree") {
|
|
@@ -32747,25 +33194,35 @@ async function resolveLeadControllerRole(state, ctx, requestedRole, deps, option
|
|
|
32747
33194
|
if (!optional) state.roleSuspended = true;
|
|
32748
33195
|
throw error2;
|
|
32749
33196
|
}
|
|
32750
|
-
if (!deps.isCurrent())
|
|
32751
|
-
|
|
33197
|
+
if (!deps.isCurrent() || ctx.sessionManager.getSessionId() !== sessionId)
|
|
33198
|
+
return;
|
|
33199
|
+
if (!scope.isPrimary) {
|
|
32752
33200
|
if (!optional) deps.persistLeadRole();
|
|
32753
33201
|
return;
|
|
32754
33202
|
}
|
|
33203
|
+
if (!await deps.verifyCurrentIdentity() || !deps.isCurrent() || ctx.sessionManager.getSessionId() !== sessionId)
|
|
33204
|
+
return;
|
|
33205
|
+
deps.activationGuard(sessionId, "Manager");
|
|
32755
33206
|
try {
|
|
32756
33207
|
const lease = deps.claimManagerLease({
|
|
32757
33208
|
build: deps.build,
|
|
32758
|
-
piSessionId:
|
|
33209
|
+
piSessionId: sessionId,
|
|
32759
33210
|
piSessionFile: ctx.sessionManager.getSessionFile(),
|
|
32760
33211
|
paneId,
|
|
32761
33212
|
tabId,
|
|
32762
33213
|
workspaceId,
|
|
32763
33214
|
repoKey: scope.repoKey
|
|
32764
33215
|
});
|
|
32765
|
-
|
|
33216
|
+
{
|
|
32766
33217
|
let verified;
|
|
32767
33218
|
try {
|
|
32768
33219
|
verified = await deps.verifyManagerIdentity(lease.descriptor);
|
|
33220
|
+
const currentScope = await deps.localRepositoryScope(
|
|
33221
|
+
workspaceId,
|
|
33222
|
+
ctx.signal
|
|
33223
|
+
);
|
|
33224
|
+
if (!currentScope.isPrimary || currentScope.repoKey !== scope.repoKey || !await deps.verifyCurrentIdentity() || ctx.sessionManager.getSessionId() !== sessionId)
|
|
33225
|
+
throw new Error("Manager identity changed during restoration");
|
|
32769
33226
|
} catch (error2) {
|
|
32770
33227
|
if (!deps.isCurrent()) {
|
|
32771
33228
|
lease.release();
|
|
@@ -32834,7 +33291,7 @@ async function resolveLeadControllerRole(state, ctx, requestedRole, deps, option
|
|
|
32834
33291
|
}
|
|
32835
33292
|
function gitPathStatus(path) {
|
|
32836
33293
|
try {
|
|
32837
|
-
return
|
|
33294
|
+
return statSync7(path).isDirectory() ? "present" : "unknown";
|
|
32838
33295
|
} catch (error2) {
|
|
32839
33296
|
const code = error2.code;
|
|
32840
33297
|
return code === "ENOENT" || code === "ENOTDIR" ? "absent" : "unknown";
|
|
@@ -32881,7 +33338,7 @@ function parseGitWorktreeInventory(output) {
|
|
|
32881
33338
|
else if (/^prunable(?: .*)?$/.test(value2)) prunable = true;
|
|
32882
33339
|
else if (!/^[^\s]+(?: .*)?$/.test(value2)) return void 0;
|
|
32883
33340
|
}
|
|
32884
|
-
if (!path || !
|
|
33341
|
+
if (!path || !isAbsolute7(path) || (bare ? !!branch || detached : !head || !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(head) || !branch && !detached) || branch !== void 0 && !branch)
|
|
32885
33342
|
return void 0;
|
|
32886
33343
|
worktrees.push({
|
|
32887
33344
|
path,
|
|
@@ -32921,6 +33378,17 @@ function createLeadRoleTransitions(state, host) {
|
|
|
32921
33378
|
throw error2;
|
|
32922
33379
|
}
|
|
32923
33380
|
};
|
|
33381
|
+
const currentLocalRepositoryScope = async (ctx) => {
|
|
33382
|
+
const workspaceId = host.workspaceId();
|
|
33383
|
+
if (!workspaceId) return void 0;
|
|
33384
|
+
try {
|
|
33385
|
+
return await localRepositoryScope(host.pi, ctx, workspaceId, ctx.signal);
|
|
33386
|
+
} catch (error2) {
|
|
33387
|
+
if (error2 instanceof OperationError && error2.detail.details?.herdrCode === "not_git_worktree")
|
|
33388
|
+
return void 0;
|
|
33389
|
+
throw error2;
|
|
33390
|
+
}
|
|
33391
|
+
};
|
|
32924
33392
|
const projectAssignmentForScope = (scope, sessionId) => {
|
|
32925
33393
|
const assignments = host.findProjectAssignmentBySession(
|
|
32926
33394
|
host.supervisionRuntime(),
|
|
@@ -33068,17 +33536,20 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33068
33536
|
};
|
|
33069
33537
|
const managerForScope = (scope) => {
|
|
33070
33538
|
if (!scope) return void 0;
|
|
33071
|
-
const
|
|
33072
|
-
|
|
33073
|
-
scope.primaryWorkspaceId
|
|
33539
|
+
const managers = listManagerDescriptors(host.supervisionRuntime()).filter(
|
|
33540
|
+
(manager) => manager.repoKey === scope.repoKey
|
|
33074
33541
|
);
|
|
33075
|
-
if (
|
|
33076
|
-
|
|
33077
|
-
|
|
33078
|
-
return status.descriptor;
|
|
33542
|
+
if (managers.length > 1)
|
|
33543
|
+
throw new Error("Manager supervisor is ambiguous for this repository");
|
|
33544
|
+
return managers[0];
|
|
33079
33545
|
};
|
|
33080
33546
|
const currentManager = async (ctx, scope) => {
|
|
33081
|
-
const
|
|
33547
|
+
const ownLease = activeLeadRole(state) === "manager" && !state.roleSuspended ? state.managerLease : void 0;
|
|
33548
|
+
const ownStatus = ownLease && host.readManagerDescriptorStatus(
|
|
33549
|
+
host.supervisionRuntime(),
|
|
33550
|
+
ownLease.descriptor.workspaceId
|
|
33551
|
+
);
|
|
33552
|
+
const descriptor = ownLease ? ownStatus?.live && host.sameManagerDescriptor(ownStatus.descriptor, ownLease.descriptor) ? ownStatus.descriptor : void 0 : managerForScope(
|
|
33082
33553
|
scope === null || scope === void 0 ? await currentWorktreeScope2(ctx) : scope
|
|
33083
33554
|
);
|
|
33084
33555
|
if (!descriptor) return void 0;
|
|
@@ -33204,12 +33675,12 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33204
33675
|
ctx.sessionManager.getSessionId()
|
|
33205
33676
|
);
|
|
33206
33677
|
if (identity?.kind === "managed") {
|
|
33207
|
-
const scope2 = await
|
|
33678
|
+
const scope2 = await currentLocalRepositoryScope(ctx);
|
|
33208
33679
|
if (!scope2 || scope2.repoKey !== identity.repoKey) return void 0;
|
|
33209
33680
|
const assignment = projectAssignmentForScope(scope2, identity.sessionId);
|
|
33210
33681
|
return assignment && assignment.branch === identity.branch ? currentManager(ctx, scope2) : void 0;
|
|
33211
33682
|
}
|
|
33212
|
-
const scope = await
|
|
33683
|
+
const scope = await currentLocalRepositoryScope(ctx);
|
|
33213
33684
|
if (!scope) return host.currentChiefAuthority(ctx);
|
|
33214
33685
|
const workspaceId = host.workspaceId();
|
|
33215
33686
|
if (!workspaceId) return host.currentChiefAuthority(ctx);
|
|
@@ -33235,15 +33706,14 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33235
33706
|
return true;
|
|
33236
33707
|
};
|
|
33237
33708
|
const gitWorktreeInventory = async (ctx, repoKey, primaryWorkspaceId, sourceCheckoutPath) => {
|
|
33238
|
-
if (!
|
|
33709
|
+
if (!isAbsolute7(sourceCheckoutPath)) return void 0;
|
|
33239
33710
|
try {
|
|
33240
33711
|
const scope = await host.worktreeGroupScope(
|
|
33241
33712
|
ctx,
|
|
33242
33713
|
primaryWorkspaceId,
|
|
33243
33714
|
ctx.signal
|
|
33244
33715
|
);
|
|
33245
|
-
if (scope.repoKey !== repoKey
|
|
33246
|
-
return void 0;
|
|
33716
|
+
if (scope.repoKey !== repoKey) return void 0;
|
|
33247
33717
|
const rootResult = await host.pi.exec(
|
|
33248
33718
|
"git",
|
|
33249
33719
|
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
@@ -33252,7 +33722,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33252
33722
|
if (rootResult.code !== 0 || rootResult.killed || rootResult.stderr?.trim())
|
|
33253
33723
|
return void 0;
|
|
33254
33724
|
const commonDir = String(rootResult.stdout ?? "").trim();
|
|
33255
|
-
if (!commonDir || !
|
|
33725
|
+
if (!commonDir || !isAbsolute7(commonDir)) return void 0;
|
|
33256
33726
|
const result = await host.pi.exec(
|
|
33257
33727
|
"git",
|
|
33258
33728
|
["worktree", "list", "--porcelain", "-z"],
|
|
@@ -33416,7 +33886,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33416
33886
|
["worktree", "list", "--workspace", manager.workspaceId],
|
|
33417
33887
|
{ signal: ctx.signal }
|
|
33418
33888
|
);
|
|
33419
|
-
if (topology?.source?.repo_key !== manager.repoKey ||
|
|
33889
|
+
if (topology?.source?.repo_key !== manager.repoKey || typeof topology?.source?.source_checkout_path !== "string")
|
|
33420
33890
|
throw new Error("Manager worktree topology is not authoritative");
|
|
33421
33891
|
await reconcileProjectAssignments(
|
|
33422
33892
|
ctx,
|
|
@@ -33753,7 +34223,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33753
34223
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
33754
34224
|
let scope;
|
|
33755
34225
|
try {
|
|
33756
|
-
scope = await host.
|
|
34226
|
+
scope = await localRepositoryScope(host.pi, ctx, workspaceId, ctx.signal);
|
|
33757
34227
|
} catch (error2) {
|
|
33758
34228
|
if (!(error2 instanceof OperationError) || error2.detail.details?.herdrCode !== "not_git_worktree")
|
|
33759
34229
|
throw error2;
|
|
@@ -33763,18 +34233,9 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33763
34233
|
"/manager requires interactive confirmation to initialize Git"
|
|
33764
34234
|
);
|
|
33765
34235
|
const target = realpathSync5(resolve6(ctx.cwd));
|
|
33766
|
-
const targetStat =
|
|
34236
|
+
const targetStat = statSync7(target, { bigint: true });
|
|
33767
34237
|
if (!targetStat.isDirectory() || targetStat.dev === 0n || targetStat.ino === 0n)
|
|
33768
34238
|
throw new Error("Manager Git target is not a directory");
|
|
33769
|
-
const sameDirectory = (leftPath, rightPath) => {
|
|
33770
|
-
try {
|
|
33771
|
-
const left = statSync6(leftPath, { bigint: true });
|
|
33772
|
-
const right = statSync6(rightPath, { bigint: true });
|
|
33773
|
-
return left.isDirectory() && right.isDirectory() && left.dev !== 0n && right.dev !== 0n && left.ino !== 0n && right.ino !== 0n && left.dev === right.dev && left.ino === right.ino;
|
|
33774
|
-
} catch {
|
|
33775
|
-
return false;
|
|
33776
|
-
}
|
|
33777
|
-
};
|
|
33778
34239
|
const verifyHerdrTarget = async () => {
|
|
33779
34240
|
const pane = (await host.runHerdr(host.pi, ctx, ["pane", "get", paneId], {
|
|
33780
34241
|
signal: ctx.signal
|
|
@@ -33783,7 +34244,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33783
34244
|
signal: ctx.signal
|
|
33784
34245
|
}))?.workspace;
|
|
33785
34246
|
const paneCwd = pane?.cwd;
|
|
33786
|
-
if (pane?.pane_id !== paneId || pane?.tab_id !== tabId || pane?.workspace_id !== workspaceId || workspace2?.workspace_id !== workspaceId || typeof paneCwd !== "string" || !
|
|
34247
|
+
if (pane?.pane_id !== paneId || pane?.tab_id !== tabId || pane?.workspace_id !== workspaceId || workspace2?.workspace_id !== workspaceId || typeof paneCwd !== "string" || !isAbsolute7(paneCwd) || !sameDirectory(paneCwd, target))
|
|
33787
34248
|
throw new Error(
|
|
33788
34249
|
"Manager activation cancelled because Herdr workspace identity does not match the approved directory"
|
|
33789
34250
|
);
|
|
@@ -33809,7 +34270,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33809
34270
|
throw new Error("Manager activation cancelled.");
|
|
33810
34271
|
await verifyHerdrTarget();
|
|
33811
34272
|
if (ctx.sessionManager.getSessionId() !== sessionId || host.identity.workspaceId !== workspaceId || host.identity.paneId !== paneId || host.identity.tabId !== tabId || !sameDirectory(resolve6(ctx.cwd), target) || (() => {
|
|
33812
|
-
const current =
|
|
34273
|
+
const current = statSync7(target, { bigint: true });
|
|
33813
34274
|
return current.dev !== targetStat.dev || current.ino !== targetStat.ino;
|
|
33814
34275
|
})())
|
|
33815
34276
|
throw new Error(
|
|
@@ -33956,8 +34417,13 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33956
34417
|
"--path-format=absolute",
|
|
33957
34418
|
"--git-common-dir"
|
|
33958
34419
|
]);
|
|
33959
|
-
scope = await
|
|
33960
|
-
|
|
34420
|
+
scope = await localRepositoryScope(
|
|
34421
|
+
host.pi,
|
|
34422
|
+
ctx,
|
|
34423
|
+
workspaceId,
|
|
34424
|
+
ctx.signal
|
|
34425
|
+
);
|
|
34426
|
+
if (!scope || !scope.isPrimary || !sameDirectory(scope.repoKey, gitCommonDir))
|
|
33961
34427
|
throw new Error(
|
|
33962
34428
|
"Manager activation could not verify the initialized repository in Herdr"
|
|
33963
34429
|
);
|
|
@@ -33967,8 +34433,16 @@ function createLeadRoleTransitions(state, host) {
|
|
|
33967
34433
|
}
|
|
33968
34434
|
if (!scope)
|
|
33969
34435
|
throw new Error("Manager workspace could not be verified in Herdr");
|
|
33970
|
-
if (scope.
|
|
34436
|
+
if (!scope.isPrimary)
|
|
33971
34437
|
throw new Error("/manager is available only in the primary workspace");
|
|
34438
|
+
if (!await host.remoteChiefAgent(ctx, {
|
|
34439
|
+
piSessionId: sessionId,
|
|
34440
|
+
piSessionFile: ctx.sessionManager.getSessionFile(),
|
|
34441
|
+
paneId,
|
|
34442
|
+
tabId,
|
|
34443
|
+
workspaceId
|
|
34444
|
+
}))
|
|
34445
|
+
throw new Error("Manager identity changed during activation");
|
|
33972
34446
|
if (ctx.sessionManager.getSessionId() !== sessionId)
|
|
33973
34447
|
throw new Error(
|
|
33974
34448
|
"Manager activation cancelled because the session changed"
|
|
@@ -34004,6 +34478,14 @@ function createLeadRoleTransitions(state, host) {
|
|
|
34004
34478
|
throw new Error("Manager coordination state could not be persisted");
|
|
34005
34479
|
if (!await host.remoteChiefAgent(ctx, lease.descriptor))
|
|
34006
34480
|
throw new Error("Manager could not be verified in Herdr");
|
|
34481
|
+
const currentScope = await localRepositoryScope(
|
|
34482
|
+
host.pi,
|
|
34483
|
+
ctx,
|
|
34484
|
+
workspaceId,
|
|
34485
|
+
ctx.signal
|
|
34486
|
+
);
|
|
34487
|
+
if (!currentScope.isPrimary || !sameDirectory(currentScope.repoKey, scope.repoKey) || !await host.remoteChiefAgent(ctx, lease.descriptor) || ctx.sessionManager.getSessionId() !== sessionId)
|
|
34488
|
+
throw new Error("Manager identity changed during activation");
|
|
34007
34489
|
host.reconcileRoleTools();
|
|
34008
34490
|
host.clearNormalUI();
|
|
34009
34491
|
host.startSupervisionUI(ctx);
|
|
@@ -34283,10 +34765,15 @@ function createLeadRoleTransitions(state, host) {
|
|
|
34283
34765
|
{
|
|
34284
34766
|
identity: host.identity,
|
|
34285
34767
|
build: host.build,
|
|
34286
|
-
|
|
34768
|
+
localRepositoryScope: (workspaceId, signal) => localRepositoryScope(host.pi, ctx, workspaceId, signal),
|
|
34287
34769
|
claimManagerLease: host.claimManagerLease,
|
|
34288
34770
|
coordinationHealthy: host.coordinationHealthy,
|
|
34289
34771
|
verifyManagerIdentity: (descriptor) => host.remoteChiefAgent(ctx, descriptor),
|
|
34772
|
+
verifyCurrentIdentity: () => host.remoteChiefAgent(ctx, {
|
|
34773
|
+
piSessionId: ctx.sessionManager.getSessionId(),
|
|
34774
|
+
piSessionFile: ctx.sessionManager.getSessionFile(),
|
|
34775
|
+
...host.identity
|
|
34776
|
+
}),
|
|
34290
34777
|
unresolvedManagerLease: () => {
|
|
34291
34778
|
host.markLeadCoordinationUnhealthy(ctx);
|
|
34292
34779
|
reconcileRoleTools();
|
|
@@ -34915,7 +35402,7 @@ If needed, install the Pi integration once:
|
|
|
34915
35402
|
};
|
|
34916
35403
|
},
|
|
34917
35404
|
persistedTranscriptReady: (state) => persistedTranscriptReady(state, (path) => {
|
|
34918
|
-
const file2 =
|
|
35405
|
+
const file2 = statSync8(path, { throwIfNoEntry: false });
|
|
34919
35406
|
return !!file2?.isFile() && file2.size > 0;
|
|
34920
35407
|
}),
|
|
34921
35408
|
agentDefinitions: async (ctx) => (await contextAgentDefinitions(ctx)).definitions,
|
|
@@ -34923,7 +35410,7 @@ If needed, install the Pi integration once:
|
|
|
34923
35410
|
state,
|
|
34924
35411
|
(path) => readFileSync13(path, "utf8"),
|
|
34925
35412
|
(path) => {
|
|
34926
|
-
const file2 =
|
|
35413
|
+
const file2 = statSync8(path, { throwIfNoEntry: false });
|
|
34927
35414
|
return !!file2?.isFile() && file2.size > 0;
|
|
34928
35415
|
}
|
|
34929
35416
|
),
|
|
@@ -35099,7 +35586,7 @@ Use reply_agent with agent="${ask.agentLabel}" to answer this question.`,
|
|
|
35099
35586
|
sessionId,
|
|
35100
35587
|
(cwd, id) => SessionManager2.findById(cwd, id)
|
|
35101
35588
|
),
|
|
35102
|
-
statSync:
|
|
35589
|
+
statSync: statSync8,
|
|
35103
35590
|
workspacePresentationProvenance,
|
|
35104
35591
|
normalizeHerdrLifecycleState,
|
|
35105
35592
|
appendDurableError,
|
|
@@ -35194,7 +35681,7 @@ ${globalInstructions}
|
|
|
35194
35681
|
tabId: process.env.HERDR_TAB_ID,
|
|
35195
35682
|
workspaceId: process.env.HERDR_WORKSPACE_ID
|
|
35196
35683
|
},
|
|
35197
|
-
statSync:
|
|
35684
|
+
statSync: statSync8,
|
|
35198
35685
|
readChiefDescriptor,
|
|
35199
35686
|
chiefLeaseIsHeld,
|
|
35200
35687
|
sameChiefDescriptor,
|
|
@@ -35313,7 +35800,7 @@ ${globalInstructions}
|
|
|
35313
35800
|
target,
|
|
35314
35801
|
(path) => readFileSync13(path, "utf8"),
|
|
35315
35802
|
(path) => {
|
|
35316
|
-
const file2 =
|
|
35803
|
+
const file2 = statSync8(path, { throwIfNoEntry: false });
|
|
35317
35804
|
return !!file2?.isFile() && file2.size > 0;
|
|
35318
35805
|
}
|
|
35319
35806
|
)
|