pi-herdsman 0.21.0 → 0.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// extension/index.ts
|
|
2
2
|
import { contentText as contentText5 } from "@earendil-works/pi-ai";
|
|
3
3
|
import {
|
|
4
|
-
buildSessionProjection as
|
|
4
|
+
buildSessionProjection as buildSessionProjection3,
|
|
5
5
|
DynamicBorder,
|
|
6
6
|
getAgentDir as getAgentDir4,
|
|
7
7
|
getSelectListTheme as getSelectListTheme2,
|
|
@@ -15,7 +15,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
15
15
|
// package.json
|
|
16
16
|
var package_default = {
|
|
17
17
|
name: "pi-herdsman",
|
|
18
|
-
version: "0.21.
|
|
18
|
+
version: "0.21.2",
|
|
19
19
|
type: "module",
|
|
20
20
|
description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
|
|
21
21
|
license: "Apache-2.0",
|
|
@@ -64,7 +64,7 @@ var package_default = {
|
|
|
64
64
|
},
|
|
65
65
|
piHerdsman: {
|
|
66
66
|
runtime: {
|
|
67
|
-
pi: "1.0.
|
|
67
|
+
pi: "1.0.4",
|
|
68
68
|
herdr: {
|
|
69
69
|
version: "0.9.3",
|
|
70
70
|
sha256: {
|
|
@@ -93,9 +93,9 @@ var package_default = {
|
|
|
93
93
|
typebox: "*"
|
|
94
94
|
},
|
|
95
95
|
devDependencies: {
|
|
96
|
-
"@earendil-works/pi-ai": "1.0.
|
|
97
|
-
"@earendil-works/pi-coding-agent": "1.0.
|
|
98
|
-
"@earendil-works/pi-tui": "1.0.
|
|
96
|
+
"@earendil-works/pi-ai": "1.0.4",
|
|
97
|
+
"@earendil-works/pi-coding-agent": "1.0.4",
|
|
98
|
+
"@earendil-works/pi-tui": "1.0.4",
|
|
99
99
|
esbuild: "^0.28.2",
|
|
100
100
|
typebox: "^1.3.7"
|
|
101
101
|
},
|
|
@@ -1579,6 +1579,11 @@ function overrideBodyMode(definition) {
|
|
|
1579
1579
|
function normalizedToolNames(tools) {
|
|
1580
1580
|
return (tools ?? []).flatMap((tool) => tool.split(",")).map((tool) => tool.trim()).filter(Boolean);
|
|
1581
1581
|
}
|
|
1582
|
+
function matchesToolPattern(pattern, name) {
|
|
1583
|
+
if (!pattern.includes("*")) return pattern === name;
|
|
1584
|
+
const source = pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/gu, "\\$&")).join(".*");
|
|
1585
|
+
return new RegExp(`^${source}$`, "u").test(name);
|
|
1586
|
+
}
|
|
1582
1587
|
function readOptionalAgentDefinitions(root2) {
|
|
1583
1588
|
const stats = statSync3(root2, { throwIfNoEntry: false });
|
|
1584
1589
|
if (!stats) return [];
|
|
@@ -1954,33 +1959,41 @@ function agentLaunchArgs(agent, options) {
|
|
|
1954
1959
|
}
|
|
1955
1960
|
}
|
|
1956
1961
|
if (sharedPromptPath) args.push("--append-system-prompt", sharedPromptPath);
|
|
1957
|
-
if (managedAgent)
|
|
1958
|
-
args.push("--append-system-prompt", `<active_agent name="${agent.name}"/>`);
|
|
1959
1962
|
const explicitTools = frontmatter.tools !== void 0;
|
|
1960
|
-
const
|
|
1963
|
+
const configuredTools = normalizedToolNames(frontmatter.tools);
|
|
1964
|
+
const noTools = frontmatter.noTools === true || explicitTools && configuredTools.length === 0;
|
|
1961
1965
|
if (noTools) args.push("--no-tools");
|
|
1962
1966
|
if (frontmatter.noBuiltinTools) args.push("--no-builtin-tools");
|
|
1963
1967
|
const requiredTools = [
|
|
1964
1968
|
...managedAgent ? agentDefinitionDelegationEnabled(agent) ? [...AGENT_COORDINATION_TOOLS, "ask_owner"] : ["ask_owner"] : [],
|
|
1965
1969
|
...options.requiredTools ?? []
|
|
1966
1970
|
].filter((tool, index, all) => all.indexOf(tool) === index);
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
+
const requiredToolSet = new Set(requiredTools);
|
|
1972
|
+
const excluded = normalizedToolNames(frontmatter.excludeTools).filter((pattern) => !requiredToolSet.has(pattern)).filter((pattern, index, all) => all.indexOf(pattern) === index);
|
|
1973
|
+
for (const pattern of excluded) {
|
|
1974
|
+
if (!pattern.includes("*")) continue;
|
|
1975
|
+
const required = requiredTools.find(
|
|
1976
|
+
(tool) => matchesToolPattern(pattern, tool)
|
|
1977
|
+
);
|
|
1978
|
+
if (required)
|
|
1979
|
+
throw new Error(
|
|
1980
|
+
`agent ${agent.name} excludeTools pattern ${JSON.stringify(pattern)} matches required tool ${JSON.stringify(required)}; required tools cannot be excluded by patterns`
|
|
1971
1981
|
);
|
|
1972
|
-
|
|
1973
|
-
|
|
1982
|
+
}
|
|
1983
|
+
if (noTools || explicitTools) {
|
|
1984
|
+
const configured = configuredTools.filter(
|
|
1985
|
+
(tool) => (!managedAgent || tool !== "agent") && !requiredToolSet.has(tool)
|
|
1986
|
+
);
|
|
1987
|
+
const selected = [.../* @__PURE__ */ new Set([...configured, ...requiredTools])];
|
|
1988
|
+
if (selected.length) {
|
|
1989
|
+
if (!selected.some((tool) => tool.startsWith("mcp__"))) {
|
|
1990
|
+
selected.push("mcp__");
|
|
1991
|
+
if (!excluded.includes("mcp__")) excluded.push("mcp__");
|
|
1992
|
+
}
|
|
1993
|
+
args.push("--tools", selected.join(","));
|
|
1974
1994
|
}
|
|
1975
|
-
const requiredToolSet = new Set(requiredTools);
|
|
1976
|
-
const excluded = normalizedToolNames(frontmatter.excludeTools).filter((tool) => !requiredToolSet.has(tool)).filter((tool, index, all) => all.indexOf(tool) === index);
|
|
1977
|
-
if (excluded.length) args.push("--exclude-tools", excluded.join(","));
|
|
1978
|
-
} else {
|
|
1979
|
-
if (frontmatter.tools?.length)
|
|
1980
|
-
args.push("--tools", frontmatter.tools.join(","));
|
|
1981
|
-
if (frontmatter.excludeTools?.length)
|
|
1982
|
-
args.push("--exclude-tools", frontmatter.excludeTools.join(","));
|
|
1983
1995
|
}
|
|
1996
|
+
if (excluded.length) args.push("--exclude-tools", excluded.join(","));
|
|
1984
1997
|
const noSkills = frontmatter.noSkills ?? frontmatter.inheritSkills !== true;
|
|
1985
1998
|
if (noSkills) args.push("--no-skills");
|
|
1986
1999
|
for (const skill of frontmatter.skills ?? []) args.push("--skill", skill);
|
|
@@ -1989,6 +2002,8 @@ function agentLaunchArgs(agent, options) {
|
|
|
1989
2002
|
args.push("--no-extensions");
|
|
1990
2003
|
for (const extension of frontmatter.extensions ?? [])
|
|
1991
2004
|
args.push("--extension", extension);
|
|
2005
|
+
if (managedAgent)
|
|
2006
|
+
args.push("--append-system-prompt", `<active_agent name="${agent.name}"/>`);
|
|
1992
2007
|
return args;
|
|
1993
2008
|
}
|
|
1994
2009
|
|
|
@@ -3800,6 +3815,7 @@ async function rollbackHerdrStart(pi, ctx, started, signal) {
|
|
|
3800
3815
|
// extension/managed-agent-runtime.ts
|
|
3801
3816
|
import { isAbsolute as isAbsolute4, resolve as resolve5 } from "node:path";
|
|
3802
3817
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
3818
|
+
import { buildSessionProjection as buildSessionProjection2 } from "@earendil-works/pi-coding-agent";
|
|
3803
3819
|
import { contentText as contentText3 } from "@earendil-works/pi-ai";
|
|
3804
3820
|
|
|
3805
3821
|
// extension/agent-controller.ts
|
|
@@ -11889,10 +11905,21 @@ function createAgentController(pi, options) {
|
|
|
11889
11905
|
} finally {
|
|
11890
11906
|
resetRelease();
|
|
11891
11907
|
}
|
|
11908
|
+
let ownerDisplay = "lead";
|
|
11909
|
+
if (scope.kind === "managed-agent") {
|
|
11910
|
+
const definition2 = process.env.PI_HERDSMAN_AGENT_DEFINITION;
|
|
11911
|
+
const parentLabel = process.env.PI_HERDSMAN_LABEL;
|
|
11912
|
+
if (!definition2 || !parentLabel)
|
|
11913
|
+
throw new Error(
|
|
11914
|
+
"Managed-Agent launch is missing its definition or label"
|
|
11915
|
+
);
|
|
11916
|
+
ownerDisplay = displayIdentity(definition2, parentLabel);
|
|
11917
|
+
}
|
|
11892
11918
|
const env = [
|
|
11893
11919
|
`PI_HERDSMAN_MAILBOX=${mailbox}`,
|
|
11894
11920
|
`PI_HERDSMAN_RUN_ID=${runId}`,
|
|
11895
11921
|
`PI_HERDSMAN_OWNER_SESSION_ID=${owner}`,
|
|
11922
|
+
`PI_HERDSMAN_OWNER_DISPLAY=${ownerDisplay}`,
|
|
11896
11923
|
`PI_SUBAGENT_PARENT_SESSION=${forwardingSession}`,
|
|
11897
11924
|
`PI_HERDSMAN_LABEL=${label}`,
|
|
11898
11925
|
`PI_HERDSMAN_WORKSPACE_ID=${workspaceId}`,
|
|
@@ -13527,6 +13554,9 @@ function collectSessionUsage(ctx, ownedChildren, openOwnedSession, leadRoots = [
|
|
|
13527
13554
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
13528
13555
|
import { Type as Type2 } from "typebox";
|
|
13529
13556
|
import { isDeepStrictEqual } from "node:util";
|
|
13557
|
+
var DELEGATING_AGENT_ROLE_CHARTER = `## Delegating agent role
|
|
13558
|
+
${DELEGATING_AGENT_SCOPE_DESCRIPTION}
|
|
13559
|
+
${FILE_HANDOFF_GUIDANCE}`;
|
|
13530
13560
|
function currentTurnIsSoleToolCall(message, name) {
|
|
13531
13561
|
const turn = message;
|
|
13532
13562
|
if (turn?.role !== "assistant" || !Array.isArray(turn.content)) return false;
|
|
@@ -13670,6 +13700,7 @@ var AGENT_LABEL_PATTERN2 = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
|
13670
13700
|
var RESERVED_PREFIX = "__PI_HERDSMAN_AGENT_V5__:";
|
|
13671
13701
|
var AGENT_CONTEXT_RETIRED_ENTRY = "pi-herdsman-agent-context-retired";
|
|
13672
13702
|
var 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.";
|
|
13703
|
+
var CONTEXT_RETIREMENT_REMINDER = "This session is retired. Do not start new work or agents. Finish the current assignment and return a self-contained handoff.";
|
|
13673
13704
|
function createManagedAgentExecutionState() {
|
|
13674
13705
|
return {
|
|
13675
13706
|
assignment: void 0,
|
|
@@ -14699,7 +14730,9 @@ function registerManagedAgentRuntime(pi, options) {
|
|
|
14699
14730
|
const view = await controller.agentSnapshotView(
|
|
14700
14731
|
ctx,
|
|
14701
14732
|
scope,
|
|
14702
|
-
controller.sessionSignal()
|
|
14733
|
+
controller.sessionSignal(),
|
|
14734
|
+
true,
|
|
14735
|
+
false
|
|
14703
14736
|
);
|
|
14704
14737
|
return buildAgentStatusSnapshot(view, ctx, {
|
|
14705
14738
|
scope,
|
|
@@ -14717,29 +14750,23 @@ function registerManagedAgentRuntime(pi, options) {
|
|
|
14717
14750
|
});
|
|
14718
14751
|
}
|
|
14719
14752
|
controller?.registerTools(/* @__PURE__ */ new Map());
|
|
14720
|
-
|
|
14721
|
-
|
|
14722
|
-
|
|
14723
|
-
|
|
14724
|
-
|
|
14725
|
-
|
|
14726
|
-
|
|
14753
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
14754
|
+
const definition = process.env.PI_HERDSMAN_AGENT_DEFINITION;
|
|
14755
|
+
const label = process.env.PI_HERDSMAN_LABEL;
|
|
14756
|
+
event.systemPromptOptions.sections.pi_herdsman_agent = [
|
|
14757
|
+
`identity: ${displayIdentity(definition, label)}`,
|
|
14758
|
+
`direct_owner: ${process.env.PI_HERDSMAN_OWNER_DISPLAY}`
|
|
14759
|
+
].join("\n");
|
|
14760
|
+
if (delegationEnabled) {
|
|
14727
14761
|
const roster = startupDefinitionRoster;
|
|
14728
14762
|
const availableRoster = roster?.sessionId === ctx.sessionManager.getSessionId() ? roster : void 0;
|
|
14729
|
-
|
|
14730
|
-
|
|
14731
|
-
|
|
14732
|
-
${projection.roleCharter}
|
|
14763
|
+
event.systemPromptOptions.sections.delegating_agent_role = DELEGATING_AGENT_ROLE_CHARTER;
|
|
14764
|
+
if (availableRoster)
|
|
14765
|
+
event.systemPromptOptions.sections.agent_definitions = `${JSON.stringify(availableRoster.definitions, null, 2)}
|
|
14733
14766
|
|
|
14734
|
-
|
|
14735
|
-
|
|
14736
|
-
|
|
14737
|
-
${JSON.stringify(availableRoster.definitions, null, 2)}
|
|
14738
|
-
</agent_definitions>
|
|
14739
|
-
|
|
14740
|
-
This is the session-start definition snapshot. Use agent_list for live Agent state or to refresh Agent definitions after configuration changes.` : "")
|
|
14741
|
-
};
|
|
14742
|
-
});
|
|
14767
|
+
This is the session-start definition snapshot. Use agent_list for live Agent state or to refresh Agent definitions after configuration changes.`;
|
|
14768
|
+
}
|
|
14769
|
+
});
|
|
14743
14770
|
const execution = createManagedAgentExecutionState();
|
|
14744
14771
|
const metadataPublisher = createManagedAgentMetadataPublisher(pi);
|
|
14745
14772
|
const leafStatus = createManagedAgentLeafStatus({
|
|
@@ -14876,10 +14903,6 @@ This is the session-start definition snapshot. Use agent_list for live Agent sta
|
|
|
14876
14903
|
}
|
|
14877
14904
|
})
|
|
14878
14905
|
);
|
|
14879
|
-
registerManagedAgentContextHandlers(pi, {
|
|
14880
|
-
contextRetirementEnabled: () => readConfig().contextRetirement,
|
|
14881
|
-
hasActiveAssignment: () => !!execution.assignment?.activeRequestId
|
|
14882
|
-
});
|
|
14883
14906
|
const prepareDelegatingRoster = async (ctx) => {
|
|
14884
14907
|
startupDefinitionRoster = void 0;
|
|
14885
14908
|
if (!delegationEnabled) return;
|
|
@@ -15006,6 +15029,10 @@ This is the session-start definition snapshot. Use agent_list for live Agent sta
|
|
|
15006
15029
|
controller.shutdown();
|
|
15007
15030
|
}
|
|
15008
15031
|
});
|
|
15032
|
+
registerManagedAgentContextHandlers(pi, {
|
|
15033
|
+
contextRetirementEnabled: () => readConfig().contextRetirement,
|
|
15034
|
+
hasActiveAssignment: () => !!execution.assignment?.activeRequestId
|
|
15035
|
+
});
|
|
15009
15036
|
}
|
|
15010
15037
|
function createManagedAgentRequestState(pi, options) {
|
|
15011
15038
|
let requestPumpErrorReported = false;
|
|
@@ -15149,6 +15176,8 @@ function managedAgentEnvironmentError() {
|
|
|
15149
15176
|
if (!validId(e.PI_HERDSMAN_RUN_ID)) return "PI_HERDSMAN_RUN_ID invalid";
|
|
15150
15177
|
if (!validId(e.PI_HERDSMAN_OWNER_SESSION_ID))
|
|
15151
15178
|
return "PI_HERDSMAN_OWNER_SESSION_ID invalid";
|
|
15179
|
+
if (!e.PI_HERDSMAN_OWNER_DISPLAY?.trim())
|
|
15180
|
+
return "PI_HERDSMAN_OWNER_DISPLAY missing";
|
|
15152
15181
|
if (!e.PI_HERDSMAN_LABEL || !AGENT_LABEL_PATTERN2.test(e.PI_HERDSMAN_LABEL))
|
|
15153
15182
|
return "PI_HERDSMAN_LABEL invalid";
|
|
15154
15183
|
if (!e.PI_HERDSMAN_WORKSPACE_ID?.trim())
|
|
@@ -15170,7 +15199,13 @@ function sessionContextRetired(entries, sessionId) {
|
|
|
15170
15199
|
(entry) => entry?.type === "custom" && entry.customType === AGENT_CONTEXT_RETIRED_ENTRY && entry.data?.sessionId === sessionId
|
|
15171
15200
|
);
|
|
15172
15201
|
}
|
|
15202
|
+
function sessionRetirementGuidanceVisible(ctx, sessionId) {
|
|
15203
|
+
return buildSessionProjection2(ctx.sessionManager.getBranch()).entries.some(
|
|
15204
|
+
({ sourceEntry, messages }) => sourceEntry.type === "custom_message" && sourceEntry.customType === AGENT_CONTEXT_RETIRED_ENTRY && sourceEntry.details?.sessionId === sessionId && messages.length > 0
|
|
15205
|
+
);
|
|
15206
|
+
}
|
|
15173
15207
|
function registerManagedAgentContextHandlers(pi, options) {
|
|
15208
|
+
let overflowRetryGuidance;
|
|
15174
15209
|
pi.on(
|
|
15175
15210
|
"session_before_compact",
|
|
15176
15211
|
(event, ctx) => {
|
|
@@ -15179,24 +15214,46 @@ function registerManagedAgentContextHandlers(pi, options) {
|
|
|
15179
15214
|
if (event.reason === "manual") return;
|
|
15180
15215
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
15181
15216
|
const entries = ctx.sessionManager.getEntries();
|
|
15182
|
-
|
|
15183
|
-
|
|
15217
|
+
const retired = sessionContextRetired(entries, sessionId);
|
|
15218
|
+
const guided = sessionRetirementGuidanceVisible(ctx, sessionId);
|
|
15219
|
+
let guidance;
|
|
15220
|
+
if (!retired) pi.appendEntry(AGENT_CONTEXT_RETIRED_ENTRY, { sessionId });
|
|
15221
|
+
if (!guided) guidance = CONTEXT_RETIREMENT_INSTRUCTION;
|
|
15222
|
+
else if (event.reason === "overflow")
|
|
15223
|
+
guidance = CONTEXT_RETIREMENT_REMINDER;
|
|
15224
|
+
if (guidance) {
|
|
15225
|
+
pi.sendMessage(
|
|
15226
|
+
{
|
|
15227
|
+
customType: AGENT_CONTEXT_RETIRED_ENTRY,
|
|
15228
|
+
content: guidance,
|
|
15229
|
+
display: false,
|
|
15230
|
+
details: { sessionId }
|
|
15231
|
+
},
|
|
15232
|
+
{ triggerTurn: false }
|
|
15233
|
+
);
|
|
15234
|
+
if (event.reason === "overflow" && event.willRetry)
|
|
15235
|
+
overflowRetryGuidance = guidance;
|
|
15236
|
+
}
|
|
15184
15237
|
if (event.reason === "threshold") return { cancel: true };
|
|
15185
15238
|
}
|
|
15186
15239
|
);
|
|
15187
|
-
pi.on("
|
|
15188
|
-
if (
|
|
15189
|
-
|
|
15190
|
-
|
|
15191
|
-
|
|
15192
|
-
|
|
15240
|
+
pi.on("session_compact_failed", (event) => {
|
|
15241
|
+
if (event.reason === "overflow") overflowRetryGuidance = void 0;
|
|
15242
|
+
});
|
|
15243
|
+
pi.on("agent_settled", () => {
|
|
15244
|
+
overflowRetryGuidance = void 0;
|
|
15245
|
+
});
|
|
15246
|
+
pi.on("context", (event) => {
|
|
15247
|
+
if (!overflowRetryGuidance) return;
|
|
15248
|
+
const content = overflowRetryGuidance;
|
|
15249
|
+
overflowRetryGuidance = void 0;
|
|
15193
15250
|
return {
|
|
15194
15251
|
messages: [
|
|
15195
15252
|
...event.messages,
|
|
15196
15253
|
{
|
|
15197
15254
|
role: "custom",
|
|
15198
15255
|
customType: AGENT_CONTEXT_RETIRED_ENTRY,
|
|
15199
|
-
content
|
|
15256
|
+
content,
|
|
15200
15257
|
display: false,
|
|
15201
15258
|
timestamp: Date.now()
|
|
15202
15259
|
}
|
|
@@ -18660,7 +18717,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
18660
18717
|
listPeerLeadRecords: listPeerLeadRecords2,
|
|
18661
18718
|
publishProjectMessage,
|
|
18662
18719
|
resolveMessageFiles: resolveMessageFiles2,
|
|
18663
|
-
buildSessionProjection:
|
|
18720
|
+
buildSessionProjection: buildSessionProjection4,
|
|
18664
18721
|
contentText: contentText6,
|
|
18665
18722
|
supervisorStateType,
|
|
18666
18723
|
workspacePresentationProvenance: workspacePresentationProvenance2,
|
|
@@ -19054,7 +19111,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
19054
19111
|
};
|
|
19055
19112
|
const latestCustomMessageText = (ctx, customType) => {
|
|
19056
19113
|
const entry = [
|
|
19057
|
-
...
|
|
19114
|
+
...buildSessionProjection4(ctx.sessionManager.getBranch()).entries
|
|
19058
19115
|
].reverse().find(
|
|
19059
19116
|
(candidate) => candidate.sourceEntry.type === "custom_message" && candidate.sourceEntry.customType === customType && candidate.messages.length > 0
|
|
19060
19117
|
);
|
|
@@ -21017,9 +21074,6 @@ var LEAD_ROLE_CHARTER = `## Lead role
|
|
|
21017
21074
|
${LEAD_SCOPE_DESCRIPTION}
|
|
21018
21075
|
${LEAD_SUPERVISOR_PEER_GUIDANCE}
|
|
21019
21076
|
${FILE_HANDOFF_GUIDANCE}`;
|
|
21020
|
-
var DELEGATING_AGENT_ROLE_CHARTER = `## Delegating agent role
|
|
21021
|
-
${DELEGATING_AGENT_SCOPE_DESCRIPTION}
|
|
21022
|
-
${FILE_HANDOFF_GUIDANCE}`;
|
|
21023
21077
|
var MANAGER_ROLE_CHARTER = `## Manager role
|
|
21024
21078
|
Manage project work by branch. Use staff_delegate with a task and optional branch
|
|
21025
21079
|
to start new project work. Use staff_resume with its branch to resume existing
|
|
@@ -21614,125 +21668,6 @@ ${globalInstructions}
|
|
|
21614
21668
|
const currentChief = (failOnVerificationError = false) => roleTransitions.currentChief(failOnVerificationError);
|
|
21615
21669
|
const managerForScope = (scope) => roleTransitions.managerForScope(scope);
|
|
21616
21670
|
const currentWorktreeScope = (ctx) => roleTransitions.currentWorktreeScope(ctx);
|
|
21617
|
-
const managedSupervisorWorktreeScope = async (ctx) => {
|
|
21618
|
-
const workspaceId = process.env.HERDR_WORKSPACE_ID;
|
|
21619
|
-
if (!workspaceId) return void 0;
|
|
21620
|
-
try {
|
|
21621
|
-
return await worktreeGroupScope(pi, ctx, workspaceId, ctx.signal);
|
|
21622
|
-
} catch (error2) {
|
|
21623
|
-
if (error2 instanceof OperationError && error2.detail.details?.herdrCode === "not_git_worktree")
|
|
21624
|
-
return void 0;
|
|
21625
|
-
throw error2;
|
|
21626
|
-
}
|
|
21627
|
-
};
|
|
21628
|
-
const managedSupervisorAgent = (ctx, descriptor) => verifiedHerdrAgent(descriptor, {
|
|
21629
|
-
listAgents: async () => (await listAllHerdrAgents(pi, ctx, ctx.signal)).agents,
|
|
21630
|
-
getAgent: async (paneId) => (await runHerdr(pi, ctx, ["agent", "get", paneId], {
|
|
21631
|
-
signal: ctx.signal
|
|
21632
|
-
}))?.agent,
|
|
21633
|
-
expectedSession: expectedSession2,
|
|
21634
|
-
isPiAgent,
|
|
21635
|
-
matchesExpectedSession
|
|
21636
|
-
});
|
|
21637
|
-
const managedCurrentManager = async (ctx, scope) => {
|
|
21638
|
-
const currentScope = scope === null || scope === void 0 ? await managedSupervisorWorktreeScope(ctx) : scope;
|
|
21639
|
-
if (!currentScope) return void 0;
|
|
21640
|
-
const status = readManagerDescriptorStatus(
|
|
21641
|
-
supervisionRuntime(),
|
|
21642
|
-
currentScope.primaryWorkspaceId
|
|
21643
|
-
);
|
|
21644
|
-
if (!status || !status.live) return void 0;
|
|
21645
|
-
if (status.descriptor.repoKey !== currentScope.repoKey)
|
|
21646
|
-
throw new Error("Manager authority does not match project");
|
|
21647
|
-
verifyManagerCoordinationAuthority(
|
|
21648
|
-
status.descriptor,
|
|
21649
|
-
readLeadCoordinationState(
|
|
21650
|
-
supervisionRuntime(),
|
|
21651
|
-
status.descriptor.piSessionId
|
|
21652
|
-
),
|
|
21653
|
-
HERDSMAN_BUILD,
|
|
21654
|
-
requireCompatibleBuild
|
|
21655
|
-
);
|
|
21656
|
-
if (!await managedSupervisorAgent(ctx, status.descriptor))
|
|
21657
|
-
throw new Error(
|
|
21658
|
-
"Manager authority exists but live discovery is inconclusive"
|
|
21659
|
-
);
|
|
21660
|
-
return status.descriptor;
|
|
21661
|
-
};
|
|
21662
|
-
const managedCurrentChief = async (ctx, failOnVerificationError = false) => {
|
|
21663
|
-
const runtime = supervisionRuntime();
|
|
21664
|
-
const leaseMayExist = () => {
|
|
21665
|
-
try {
|
|
21666
|
-
statSync7(runtime.lock);
|
|
21667
|
-
return true;
|
|
21668
|
-
} catch (error2) {
|
|
21669
|
-
if (error2.code === "ENOENT") return false;
|
|
21670
|
-
throw error2;
|
|
21671
|
-
}
|
|
21672
|
-
};
|
|
21673
|
-
let descriptor;
|
|
21674
|
-
try {
|
|
21675
|
-
descriptor = readChiefDescriptor(runtime.descriptor);
|
|
21676
|
-
} catch (error2) {
|
|
21677
|
-
if (failOnVerificationError && leaseMayExist()) throw error2;
|
|
21678
|
-
return void 0;
|
|
21679
|
-
}
|
|
21680
|
-
requireCompatibleBuild(
|
|
21681
|
-
HERDSMAN_BUILD,
|
|
21682
|
-
descriptor.build,
|
|
21683
|
-
"supervision",
|
|
21684
|
-
`Chief ${descriptor.piSessionId}`
|
|
21685
|
-
);
|
|
21686
|
-
if (!chiefLeaseIsHeld(runtime)) {
|
|
21687
|
-
if (failOnVerificationError && leaseMayExist())
|
|
21688
|
-
throw new Error("Unable to verify Chief supervision lease");
|
|
21689
|
-
return void 0;
|
|
21690
|
-
}
|
|
21691
|
-
try {
|
|
21692
|
-
const verified = await verifyRemoteChiefAuthority(descriptor, {
|
|
21693
|
-
remoteIdentity: () => managedSupervisorAgent(ctx, descriptor),
|
|
21694
|
-
requireCompatibleBuild,
|
|
21695
|
-
build: HERDSMAN_BUILD
|
|
21696
|
-
});
|
|
21697
|
-
if (!verified) return void 0;
|
|
21698
|
-
return descriptor;
|
|
21699
|
-
} catch (error2) {
|
|
21700
|
-
if (error2 instanceof OperationError && error2.detail.category === "incompatible_build")
|
|
21701
|
-
throw error2;
|
|
21702
|
-
if (failOnVerificationError) throw error2;
|
|
21703
|
-
return void 0;
|
|
21704
|
-
}
|
|
21705
|
-
};
|
|
21706
|
-
const prepareManagedSupervisorState = async (ctx) => {
|
|
21707
|
-
const content = await leadSupervisorState(ctx, {
|
|
21708
|
-
currentWorktreeScope: managedSupervisorWorktreeScope,
|
|
21709
|
-
projectAssignmentForScope: (scope, sessionId) => {
|
|
21710
|
-
const assignments = findProjectAssignmentBySession(
|
|
21711
|
-
supervisionRuntime(),
|
|
21712
|
-
scope.repoKey,
|
|
21713
|
-
sessionId
|
|
21714
|
-
);
|
|
21715
|
-
if (assignments.length > 1)
|
|
21716
|
-
throw new Error(
|
|
21717
|
-
"Multiple project assignments match the Lead session"
|
|
21718
|
-
);
|
|
21719
|
-
return assignments[0];
|
|
21720
|
-
},
|
|
21721
|
-
currentManager: managedCurrentManager,
|
|
21722
|
-
currentChiefAuthority: managedCurrentChief
|
|
21723
|
-
});
|
|
21724
|
-
const latest = [
|
|
21725
|
-
...buildSessionProjection2(ctx.sessionManager.getBranch()).entries
|
|
21726
|
-
].reverse().find(
|
|
21727
|
-
(candidate) => candidate.sourceEntry.type === "custom_message" && candidate.sourceEntry.customType === SUPERVISOR_STATE_TYPE && candidate.messages.length > 0
|
|
21728
|
-
);
|
|
21729
|
-
const latestMessage = latest?.messages[0];
|
|
21730
|
-
return supervisorStateMessage(
|
|
21731
|
-
SUPERVISOR_STATE_TYPE,
|
|
21732
|
-
content,
|
|
21733
|
-
latestMessage ? contentText5(latestMessage.content, "") : void 0
|
|
21734
|
-
);
|
|
21735
|
-
};
|
|
21736
21671
|
const currentManager = (ctx, scope = null) => roleTransitions.currentManager(ctx, scope);
|
|
21737
21672
|
const currentSupervisor = (ctx) => roleTransitions.currentSupervisor(ctx);
|
|
21738
21673
|
const liveAgent = (...args) => leadRuntimes.liveAgent(...args);
|
|
@@ -22416,7 +22351,7 @@ ${summary}`,
|
|
|
22416
22351
|
messageLimits: messageLimits2,
|
|
22417
22352
|
chiefMessageBytes,
|
|
22418
22353
|
coordinationMessageMaxBytes: COORDINATION_MESSAGE_MAX_BYTES,
|
|
22419
|
-
buildSessionProjection:
|
|
22354
|
+
buildSessionProjection: buildSessionProjection3,
|
|
22420
22355
|
contentText: contentText5,
|
|
22421
22356
|
supervisorStateType: SUPERVISOR_STATE_TYPE,
|
|
22422
22357
|
sameManagerDescriptor,
|
|
@@ -22546,10 +22481,6 @@ ${summary}`,
|
|
|
22546
22481
|
resolveMessageFiles,
|
|
22547
22482
|
currentTurnMessage,
|
|
22548
22483
|
getAgentDefinitions: async (ctx) => (await contextAgentDefinitions(ctx)).definitions,
|
|
22549
|
-
prepareDelegatingStart: async (ctx) => ({
|
|
22550
|
-
roleCharter: DELEGATING_AGENT_ROLE_CHARTER,
|
|
22551
|
-
supervisorStateMessage: await prepareManagedSupervisorState(ctx)
|
|
22552
|
-
}),
|
|
22553
22484
|
appendError: (ctx, kind, error2) => appendDurableError(pi, ctx, kind, error2)
|
|
22554
22485
|
});
|
|
22555
22486
|
}
|