pi-herdsman 0.21.1 → 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 buildSessionProjection2,
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.1",
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",
@@ -3815,6 +3815,7 @@ async function rollbackHerdrStart(pi, ctx, started, signal) {
3815
3815
  // extension/managed-agent-runtime.ts
3816
3816
  import { isAbsolute as isAbsolute4, resolve as resolve5 } from "node:path";
3817
3817
  import { realpathSync as realpathSync4 } from "node:fs";
3818
+ import { buildSessionProjection as buildSessionProjection2 } from "@earendil-works/pi-coding-agent";
3818
3819
  import { contentText as contentText3 } from "@earendil-works/pi-ai";
3819
3820
 
3820
3821
  // extension/agent-controller.ts
@@ -13699,6 +13700,7 @@ var AGENT_LABEL_PATTERN2 = /^[a-z][a-z0-9_-]{0,31}$/;
13699
13700
  var RESERVED_PREFIX = "__PI_HERDSMAN_AGENT_V5__:";
13700
13701
  var AGENT_CONTEXT_RETIRED_ENTRY = "pi-herdsman-agent-context-retired";
13701
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.";
13702
13704
  function createManagedAgentExecutionState() {
13703
13705
  return {
13704
13706
  assignment: void 0,
@@ -14901,10 +14903,6 @@ This is the session-start definition snapshot. Use agent_list for live Agent sta
14901
14903
  }
14902
14904
  })
14903
14905
  );
14904
- registerManagedAgentContextHandlers(pi, {
14905
- contextRetirementEnabled: () => readConfig().contextRetirement,
14906
- hasActiveAssignment: () => !!execution.assignment?.activeRequestId
14907
- });
14908
14906
  const prepareDelegatingRoster = async (ctx) => {
14909
14907
  startupDefinitionRoster = void 0;
14910
14908
  if (!delegationEnabled) return;
@@ -15031,6 +15029,10 @@ This is the session-start definition snapshot. Use agent_list for live Agent sta
15031
15029
  controller.shutdown();
15032
15030
  }
15033
15031
  });
15032
+ registerManagedAgentContextHandlers(pi, {
15033
+ contextRetirementEnabled: () => readConfig().contextRetirement,
15034
+ hasActiveAssignment: () => !!execution.assignment?.activeRequestId
15035
+ });
15034
15036
  }
15035
15037
  function createManagedAgentRequestState(pi, options) {
15036
15038
  let requestPumpErrorReported = false;
@@ -15197,7 +15199,13 @@ function sessionContextRetired(entries, sessionId) {
15197
15199
  (entry) => entry?.type === "custom" && entry.customType === AGENT_CONTEXT_RETIRED_ENTRY && entry.data?.sessionId === sessionId
15198
15200
  );
15199
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
+ }
15200
15207
  function registerManagedAgentContextHandlers(pi, options) {
15208
+ let overflowRetryGuidance;
15201
15209
  pi.on(
15202
15210
  "session_before_compact",
15203
15211
  (event, ctx) => {
@@ -15206,24 +15214,46 @@ function registerManagedAgentContextHandlers(pi, options) {
15206
15214
  if (event.reason === "manual") return;
15207
15215
  const sessionId = ctx.sessionManager.getSessionId();
15208
15216
  const entries = ctx.sessionManager.getEntries();
15209
- if (!sessionContextRetired(entries, sessionId))
15210
- pi.appendEntry(AGENT_CONTEXT_RETIRED_ENTRY, { sessionId });
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
+ }
15211
15237
  if (event.reason === "threshold") return { cancel: true };
15212
15238
  }
15213
15239
  );
15214
- pi.on("context", (event, ctx) => {
15215
- if (!options.contextRetirementEnabled()) return;
15216
- if (!options.hasActiveAssignment()) return;
15217
- const sessionId = ctx.sessionManager.getSessionId();
15218
- if (!sessionContextRetired(ctx.sessionManager.getEntries(), sessionId))
15219
- return;
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;
15220
15250
  return {
15221
15251
  messages: [
15222
15252
  ...event.messages,
15223
15253
  {
15224
15254
  role: "custom",
15225
15255
  customType: AGENT_CONTEXT_RETIRED_ENTRY,
15226
- content: CONTEXT_RETIREMENT_INSTRUCTION,
15256
+ content,
15227
15257
  display: false,
15228
15258
  timestamp: Date.now()
15229
15259
  }
@@ -18687,7 +18717,7 @@ function createLeadCoordinationRuntime(host) {
18687
18717
  listPeerLeadRecords: listPeerLeadRecords2,
18688
18718
  publishProjectMessage,
18689
18719
  resolveMessageFiles: resolveMessageFiles2,
18690
- buildSessionProjection: buildSessionProjection3,
18720
+ buildSessionProjection: buildSessionProjection4,
18691
18721
  contentText: contentText6,
18692
18722
  supervisorStateType,
18693
18723
  workspacePresentationProvenance: workspacePresentationProvenance2,
@@ -19081,7 +19111,7 @@ function createLeadCoordinationRuntime(host) {
19081
19111
  };
19082
19112
  const latestCustomMessageText = (ctx, customType) => {
19083
19113
  const entry = [
19084
- ...buildSessionProjection3(ctx.sessionManager.getBranch()).entries
19114
+ ...buildSessionProjection4(ctx.sessionManager.getBranch()).entries
19085
19115
  ].reverse().find(
19086
19116
  (candidate) => candidate.sourceEntry.type === "custom_message" && candidate.sourceEntry.customType === customType && candidate.messages.length > 0
19087
19117
  );
@@ -22321,7 +22351,7 @@ ${summary}`,
22321
22351
  messageLimits: messageLimits2,
22322
22352
  chiefMessageBytes,
22323
22353
  coordinationMessageMaxBytes: COORDINATION_MESSAGE_MAX_BYTES,
22324
- buildSessionProjection: buildSessionProjection2,
22354
+ buildSessionProjection: buildSessionProjection3,
22325
22355
  contentText: contentText5,
22326
22356
  supervisorStateType: SUPERVISOR_STATE_TYPE,
22327
22357
  sameManagerDescriptor,