pi-better-subagents 0.27.0 → 0.27.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.
@@ -28,19 +28,40 @@ export function effectiveSubagentSettings(
28
28
  }
29
29
 
30
30
  export function formatSubagentSettings(settings: EffectiveSubagentSettings): string {
31
+ const manual = settings.delegationMode === "manual";
32
+ const capacity = manual
33
+ ? "The limit is a ceiling, not a target. In manual mode it bounds only work the user or an active workflow explicitly delegates; no slot count is an invitation to launch work."
34
+ : "The limit is a ceiling, not a target. Launch ready, independent, useful work when a suitable subagent is available.";
35
+ // No occupancy counters here. This text is injected into the conversation and
36
+ // may only ever be appended to, so anything volatile would force either a
37
+ // rewrite of already-sent content (which invalidates the provider's cached
38
+ // prefix) or one more copy per change. Admission rechecks capacity at the
39
+ // spawn anyway; live counts stay available through the subagent_settings tool.
31
40
  return [
32
41
  `Subagent settings: revision ${settings.revision}`,
33
42
  `Delegation: ${settings.delegationMode} (${settings.sources.delegationMode})`,
34
43
  `Concurrency limit: ${settings.maxConcurrent} (${settings.sources.maxConcurrent})`,
35
- `Running: ${settings.runningCount}; reserved: ${settings.pendingCount}`,
36
- `Occupied slots: ${settings.occupiedSlots}`,
37
- `Available slots: ${settings.availableSlots}`,
38
- "The limit is a ceiling, not a target. Launch ready, independent, useful work within available capacity. " +
39
- "This is a point-in-time snapshot; spawn admission rechecks capacity. Lowering the limit does not stop existing runs.",
44
+ // Mode first: the policy governs the settings that follow it.
40
45
  delegationPrompt(settings.delegationMode),
46
+ capacity + " Spawn admission rechecks capacity; lower the limit without stopping existing runs.",
41
47
  ].join("\n");
42
48
  }
43
49
 
50
+ /**
51
+ * Append the delegation policy to the end of the system prompt.
52
+ *
53
+ * The system prompt is not part of the compaction window, so the policy survives
54
+ * a summary that rewrites the conversation. It is also part of the cached
55
+ * prefix, so it costs nothing per request while it stays unchanged.
56
+ *
57
+ * Nothing volatile goes in here: live occupancy would rewrite the cached prefix
58
+ * on every run, and admission rechecks capacity at spawn anyway.
59
+ */
60
+ export function appendSubagentSettings(systemPrompt: string, settings: EffectiveSubagentSettings): string {
61
+ const policy = formatSubagentSettings(settings);
62
+ return systemPrompt.includes(policy) ? systemPrompt : `${systemPrompt}\n\n${policy}`;
63
+ }
64
+
44
65
  export function subagentSettingsTool(Type: any, read: () => EffectiveSubagentSettings) {
45
66
  return {
46
67
  name: "subagent_settings",
package/index.ts CHANGED
@@ -38,7 +38,7 @@ import { selectSessionByName } from "./session-selection.ts";
38
38
  import { isWithinWorkspace } from "./workspace-scope.ts";
39
39
  import { loadConfig, writeDelegationMode, writeSubagentSettings, isConcurrencyCap, normalizeConcurrencyCap, normalizeTools, resolveExtensionPath, configPath, selfDir, SAFE_DEFAULT_TOOLS, SAFE_CLEAN_TOOLS } from "./config.ts";
40
40
  import { createSubagentSettingsPage } from "./settings-page.ts";
41
- import { effectiveSubagentSettings, formatSubagentSettings, subagentSettingsTool, SUBAGENT_SETTINGS_CONTEXT } from "./effective-settings.ts";
41
+ import { appendSubagentSettings, effectiveSubagentSettings, formatSubagentSettings, subagentSettingsTool, SUBAGENT_SETTINGS_CONTEXT } from "./effective-settings.ts";
42
42
  import { STEER_FILE_ENV, readSteerReceipt } from "./child-steer.ts";
43
43
  import {
44
44
  decideTiming,
@@ -3603,18 +3603,12 @@ export default function (pi: ExtensionAPI) {
3603
3603
  pi.registerTool(discoveryTool as Parameters<ExtensionAPI["registerTool"]>[0]);
3604
3604
 
3605
3605
  pi.on("before_agent_start", (event) => ({
3606
- systemPrompt: `${appendExecutionPolicy(event.systemPrompt)}\n\nUse the latest Subagent settings context block as the authoritative delegation mode and capacity snapshot. Its delegation guidance replaces earlier mode-specific guidance, including guidance in a plan. Inspect subagent_settings when needed; never treat the concurrency limit as a target number of agents.`,
3606
+ systemPrompt: appendSubagentSettings(
3607
+ `${appendExecutionPolicy(event.systemPrompt)}\n\nTreat the Subagent settings block at the end of this prompt as the authoritative delegation mode and cap. Its delegation guidance replaces earlier mode-specific guidance, including guidance in a plan. Live occupancy is not pushed into context: inspect subagent_settings when it matters, and never treat the concurrency limit as a target number of agents.`,
3608
+ effectiveSettings(),
3609
+ ),
3607
3610
  }));
3608
3611
 
3609
- pi.on("context", (event) => {
3610
- const settings = effectiveSettings();
3611
- return { messages: [
3612
- ...event.messages.filter(message => message.role !== "custom" || message.customType !== SUBAGENT_SETTINGS_CONTEXT),
3613
- { role: "custom" as const, customType: SUBAGENT_SETTINGS_CONTEXT,
3614
- content: formatSubagentSettings(settings), display: false, details: settings, timestamp: Date.now() },
3615
- ] };
3616
- });
3617
-
3618
3612
  // ---- live-status lifecycle -----------------------------------------
3619
3613
  pi.on("agent_start", async (_event, ctx) => {
3620
3614
  setCallbackBatchContext(pi, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-subagents",
3
- "version": "0.27.0",
3
+ "version": "0.27.1",
4
4
  "description": "Pi extension for detached, sandboxed subagent runs that keep the foreground session free.",
5
5
  "license": "MIT",
6
6
  "type": "module",