pi-herdsman 0.21.1 → 0.21.3

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.3",
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",
@@ -280,6 +280,7 @@ import {
280
280
  fuzzyFilter,
281
281
  Input,
282
282
  Key,
283
+ MouseRegion,
283
284
  matchesKey,
284
285
  SelectList,
285
286
  Spacer as Spacer2,
@@ -3815,6 +3816,7 @@ async function rollbackHerdrStart(pi, ctx, started, signal) {
3815
3816
  // extension/managed-agent-runtime.ts
3816
3817
  import { isAbsolute as isAbsolute4, resolve as resolve5 } from "node:path";
3817
3818
  import { realpathSync as realpathSync4 } from "node:fs";
3819
+ import { buildSessionProjection as buildSessionProjection2 } from "@earendil-works/pi-coding-agent";
3818
3820
  import { contentText as contentText3 } from "@earendil-works/pi-ai";
3819
3821
 
3820
3822
  // extension/agent-controller.ts
@@ -13699,6 +13701,7 @@ var AGENT_LABEL_PATTERN2 = /^[a-z][a-z0-9_-]{0,31}$/;
13699
13701
  var RESERVED_PREFIX = "__PI_HERDSMAN_AGENT_V5__:";
13700
13702
  var AGENT_CONTEXT_RETIRED_ENTRY = "pi-herdsman-agent-context-retired";
13701
13703
  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.";
13704
+ 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
13705
  function createManagedAgentExecutionState() {
13703
13706
  return {
13704
13707
  assignment: void 0,
@@ -14901,10 +14904,6 @@ This is the session-start definition snapshot. Use agent_list for live Agent sta
14901
14904
  }
14902
14905
  })
14903
14906
  );
14904
- registerManagedAgentContextHandlers(pi, {
14905
- contextRetirementEnabled: () => readConfig().contextRetirement,
14906
- hasActiveAssignment: () => !!execution.assignment?.activeRequestId
14907
- });
14908
14907
  const prepareDelegatingRoster = async (ctx) => {
14909
14908
  startupDefinitionRoster = void 0;
14910
14909
  if (!delegationEnabled) return;
@@ -15031,6 +15030,10 @@ This is the session-start definition snapshot. Use agent_list for live Agent sta
15031
15030
  controller.shutdown();
15032
15031
  }
15033
15032
  });
15033
+ registerManagedAgentContextHandlers(pi, {
15034
+ contextRetirementEnabled: () => readConfig().contextRetirement,
15035
+ hasActiveAssignment: () => !!execution.assignment?.activeRequestId
15036
+ });
15034
15037
  }
15035
15038
  function createManagedAgentRequestState(pi, options) {
15036
15039
  let requestPumpErrorReported = false;
@@ -15197,7 +15200,13 @@ function sessionContextRetired(entries, sessionId) {
15197
15200
  (entry) => entry?.type === "custom" && entry.customType === AGENT_CONTEXT_RETIRED_ENTRY && entry.data?.sessionId === sessionId
15198
15201
  );
15199
15202
  }
15203
+ function sessionRetirementGuidanceVisible(ctx, sessionId) {
15204
+ return buildSessionProjection2(ctx.sessionManager.getBranch()).entries.some(
15205
+ ({ sourceEntry, messages }) => sourceEntry.type === "custom_message" && sourceEntry.customType === AGENT_CONTEXT_RETIRED_ENTRY && sourceEntry.details?.sessionId === sessionId && messages.length > 0
15206
+ );
15207
+ }
15200
15208
  function registerManagedAgentContextHandlers(pi, options) {
15209
+ let overflowRetryGuidance;
15201
15210
  pi.on(
15202
15211
  "session_before_compact",
15203
15212
  (event, ctx) => {
@@ -15206,24 +15215,46 @@ function registerManagedAgentContextHandlers(pi, options) {
15206
15215
  if (event.reason === "manual") return;
15207
15216
  const sessionId = ctx.sessionManager.getSessionId();
15208
15217
  const entries = ctx.sessionManager.getEntries();
15209
- if (!sessionContextRetired(entries, sessionId))
15210
- pi.appendEntry(AGENT_CONTEXT_RETIRED_ENTRY, { sessionId });
15218
+ const retired = sessionContextRetired(entries, sessionId);
15219
+ const guided = sessionRetirementGuidanceVisible(ctx, sessionId);
15220
+ let guidance;
15221
+ if (!retired) pi.appendEntry(AGENT_CONTEXT_RETIRED_ENTRY, { sessionId });
15222
+ if (!guided) guidance = CONTEXT_RETIREMENT_INSTRUCTION;
15223
+ else if (event.reason === "overflow")
15224
+ guidance = CONTEXT_RETIREMENT_REMINDER;
15225
+ if (guidance) {
15226
+ pi.sendMessage(
15227
+ {
15228
+ customType: AGENT_CONTEXT_RETIRED_ENTRY,
15229
+ content: guidance,
15230
+ display: false,
15231
+ details: { sessionId }
15232
+ },
15233
+ { triggerTurn: false }
15234
+ );
15235
+ if (event.reason === "overflow" && event.willRetry)
15236
+ overflowRetryGuidance = guidance;
15237
+ }
15211
15238
  if (event.reason === "threshold") return { cancel: true };
15212
15239
  }
15213
15240
  );
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;
15241
+ pi.on("session_compact_failed", (event) => {
15242
+ if (event.reason === "overflow") overflowRetryGuidance = void 0;
15243
+ });
15244
+ pi.on("agent_settled", () => {
15245
+ overflowRetryGuidance = void 0;
15246
+ });
15247
+ pi.on("context", (event) => {
15248
+ if (!overflowRetryGuidance) return;
15249
+ const content = overflowRetryGuidance;
15250
+ overflowRetryGuidance = void 0;
15220
15251
  return {
15221
15252
  messages: [
15222
15253
  ...event.messages,
15223
15254
  {
15224
15255
  role: "custom",
15225
15256
  customType: AGENT_CONTEXT_RETIRED_ENTRY,
15226
- content: CONTEXT_RETIREMENT_INSTRUCTION,
15257
+ content,
15227
15258
  display: false,
15228
15259
  timestamp: Date.now()
15229
15260
  }
@@ -18687,7 +18718,7 @@ function createLeadCoordinationRuntime(host) {
18687
18718
  listPeerLeadRecords: listPeerLeadRecords2,
18688
18719
  publishProjectMessage,
18689
18720
  resolveMessageFiles: resolveMessageFiles2,
18690
- buildSessionProjection: buildSessionProjection3,
18721
+ buildSessionProjection: buildSessionProjection4,
18691
18722
  contentText: contentText6,
18692
18723
  supervisorStateType,
18693
18724
  workspacePresentationProvenance: workspacePresentationProvenance2,
@@ -19081,7 +19112,7 @@ function createLeadCoordinationRuntime(host) {
19081
19112
  };
19082
19113
  const latestCustomMessageText = (ctx, customType) => {
19083
19114
  const entry = [
19084
- ...buildSessionProjection3(ctx.sessionManager.getBranch()).entries
19115
+ ...buildSessionProjection4(ctx.sessionManager.getBranch()).entries
19085
19116
  ].reverse().find(
19086
19117
  (candidate) => candidate.sourceEntry.type === "custom_message" && candidate.sourceEntry.customType === customType && candidate.messages.length > 0
19087
19118
  );
@@ -21011,6 +21042,21 @@ function createLeadRoleTransitions(state, host) {
21011
21042
 
21012
21043
  // extension/index.ts
21013
21044
  var HERDSMAN_VERSION = package_default.version;
21045
+ function expandableMessage(initialExpanded, render) {
21046
+ let expanded = initialExpanded;
21047
+ const content = new Container2();
21048
+ const rebuild = () => {
21049
+ content.clear();
21050
+ content.addChild(render(expanded));
21051
+ };
21052
+ rebuild();
21053
+ return new MouseRegion(content, (event) => {
21054
+ if (event.type !== "click" || event.button !== "left") return void 0;
21055
+ expanded = !expanded;
21056
+ rebuild();
21057
+ return { handled: true };
21058
+ });
21059
+ }
21014
21060
  var HERDSMAN_EXTENSION_PATH = fileURLToPath2(import.meta.url);
21015
21061
  var HERDSMAN_BUILD = runtimeBuild(HERDSMAN_VERSION, HERDSMAN_EXTENSION_PATH);
21016
21062
  var PI_SESSION_ID_PATTERN = "^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$";
@@ -21314,12 +21360,28 @@ function index_default(pi) {
21314
21360
  for (const kind of COORDINATION_MESSAGE_KINDS) {
21315
21361
  pi.registerMessageRenderer(
21316
21362
  `pi-herdsman-${kind}`,
21317
- (message, options, theme) => renderCoordinationMessage(kind, message, options, theme)
21363
+ (message, options, theme) => expandableMessage(
21364
+ options.expanded,
21365
+ (expanded) => renderCoordinationMessage(
21366
+ kind,
21367
+ message,
21368
+ { ...options, expanded },
21369
+ theme
21370
+ )
21371
+ )
21318
21372
  );
21319
21373
  }
21320
21374
  pi.registerMessageRenderer(
21321
21375
  "pi-herdsman-project_message",
21322
- (message, options, theme) => renderCoordinationMessage("project_message", message, options, theme)
21376
+ (message, options, theme) => expandableMessage(
21377
+ options.expanded,
21378
+ (expanded) => renderCoordinationMessage(
21379
+ "project_message",
21380
+ message,
21381
+ { ...options, expanded },
21382
+ theme
21383
+ )
21384
+ )
21323
21385
  );
21324
21386
  pi.registerMessageRenderer(
21325
21387
  "pi-herdsman-stop-summary",
@@ -21327,23 +21389,38 @@ function index_default(pi) {
21327
21389
  );
21328
21390
  pi.registerMessageRenderer(
21329
21391
  "pi-herdsman-agent-result",
21330
- (message, options, theme) => renderCompletionMessage(message, options, theme)
21392
+ (message, options, theme) => expandableMessage(
21393
+ options.expanded,
21394
+ (expanded) => renderCompletionMessage(message, { ...options, expanded }, theme)
21395
+ )
21331
21396
  );
21332
21397
  pi.registerMessageRenderer(
21333
21398
  "pi-herdsman-agent-ask",
21334
- (message, options, theme) => renderAgentAskMessage(message, options, theme)
21399
+ (message, options, theme) => expandableMessage(
21400
+ options.expanded,
21401
+ (expanded) => renderAgentAskMessage(message, { ...options, expanded }, theme)
21402
+ )
21335
21403
  );
21336
21404
  pi.registerMessageRenderer(
21337
21405
  "pi-herdsman-agent-stale",
21338
- (message, options, theme) => renderAgentStaleMessage(message, options, theme)
21406
+ (message, options, theme) => expandableMessage(
21407
+ options.expanded,
21408
+ (expanded) => renderAgentStaleMessage(message, { ...options, expanded }, theme)
21409
+ )
21339
21410
  );
21340
21411
  pi.registerMessageRenderer(
21341
21412
  "pi-herdsman-agent-lost",
21342
- (message, options, theme) => renderAgentLostMessage(message, options, theme)
21413
+ (message, options, theme) => expandableMessage(
21414
+ options.expanded,
21415
+ (expanded) => renderAgentLostMessage(message, { ...options, expanded }, theme)
21416
+ )
21343
21417
  );
21344
21418
  pi.registerMessageRenderer(
21345
21419
  "pi-herdsman-agent-attention",
21346
- (message, options, theme) => renderAgentAttentionMessage(message, options, theme)
21420
+ (message, options, theme) => expandableMessage(
21421
+ options.expanded,
21422
+ (expanded) => renderAgentAttentionMessage(message, { ...options, expanded }, theme)
21423
+ )
21347
21424
  );
21348
21425
  const processRole = role();
21349
21426
  if (processRole === "unmanaged") {
@@ -22321,7 +22398,7 @@ ${summary}`,
22321
22398
  messageLimits: messageLimits2,
22322
22399
  chiefMessageBytes,
22323
22400
  coordinationMessageMaxBytes: COORDINATION_MESSAGE_MAX_BYTES,
22324
- buildSessionProjection: buildSessionProjection2,
22401
+ buildSessionProjection: buildSessionProjection3,
22325
22402
  contentText: contentText5,
22326
22403
  supervisorStateType: SUPERVISOR_STATE_TYPE,
22327
22404
  sameManagerDescriptor,