@firstpick/pi-package-webui 0.7.4 → 0.7.6

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.
@@ -2,6 +2,11 @@ import { closeSync, fstatSync, openSync, readFileSync, readSync } from "node:fs"
2
2
  import path from "node:path";
3
3
  import { AgentSession, formatSkillsForPrompt } from "@earendil-works/pi-coding-agent";
4
4
  import { readWebuiSettings } from "./lib/git-workflow-preferences.mjs";
5
+ import {
6
+ formatSubagentLaunchSlotGuidance,
7
+ resolveSubagentLaunchSlotProjectKey,
8
+ subagentLaunchSlotScopeEntry,
9
+ } from "./lib/subagent-launch-slots.mjs";
5
10
  import { SUBAGENT_GATE_UPDATE_EVENT } from "./lib/subagent-gate.mjs";
6
11
 
7
12
  const HELPER_COMMAND = "webui-helper";
@@ -234,7 +239,9 @@ function subagentAgentName(value) {
234
239
  }
235
240
 
236
241
  function subagentAgentFromDisplay(value) {
237
- const display = subagentText(value, 240).replace(/^\[[^\]]+\]\s*/, "");
242
+ const display = subagentText(value, 240)
243
+ .replace(/^\[[^\]]+\]\s*/, "")
244
+ .replace(/\s+\[(?:fork|fresh|mixed)\]$/i, "");
238
245
  const labeled = display.match(/\(([^()]*)\)$/);
239
246
  return subagentAgentName(labeled?.[1] || display);
240
247
  }
@@ -485,7 +492,7 @@ function parseSubagentStatusText(text, previousRuns = new Map()) {
485
492
  if (runMatch) {
486
493
  const id = subagentText(runMatch[1], 160);
487
494
  const segments = rawLine.split(" | ").map((part) => part.trim());
488
- const mode = segments.find((part) => ["single", "parallel", "chain"].includes(part));
495
+ const mode = segments.map((part) => part.match(/^(single|parallel|chain)\b/)?.[1]).find(Boolean);
489
496
  const previous = previousRuns.get(id);
490
497
  current = {
491
498
  id,
@@ -540,6 +547,7 @@ export default function webuiRpcHelper(pi) {
540
547
  let enabledTools = new Set();
541
548
  let disabledSkills = new Set();
542
549
  let inheritedEnabledSkills = null;
550
+ let subagentLaunchSlotGuidance = "";
543
551
  let subagentContext = null;
544
552
  let subagentBridgeAvailable = false;
545
553
  let subagentPollTimer = null;
@@ -889,6 +897,18 @@ export default function webuiRpcHelper(pi) {
889
897
  }
890
898
  }
891
899
 
900
+ async function loadSubagentLaunchSlotGuidance(ctx) {
901
+ try {
902
+ const settings = await readWebuiSettings();
903
+ const projectKey = await resolveSubagentLaunchSlotProjectKey(ctx?.cwd);
904
+ const effective = subagentLaunchSlotScopeEntry(settings.subagentLaunchSlots, "project", projectKey);
905
+ subagentLaunchSlotGuidance = formatSubagentLaunchSlotGuidance(effective.entry.roles);
906
+ } catch (error) {
907
+ subagentLaunchSlotGuidance = "";
908
+ console.warn(`Web UI subagent launch slots could not be read: ${error instanceof Error ? error.message : String(error)}`);
909
+ }
910
+ }
911
+
892
912
  function persistToolsState() {
893
913
  pi.appendEntry(TOOLS_CONFIG_TYPE, { enabledTools: [...enabledTools] });
894
914
  }
@@ -1053,6 +1073,7 @@ export default function webuiRpcHelper(pi) {
1053
1073
  const globalDefaults = await readGlobalResourceDefaults();
1054
1074
  restoreToolsFromBranch(ctx, globalDefaults);
1055
1075
  restoreSkillsFromBranch(ctx, globalDefaults);
1076
+ await loadSubagentLaunchSlotGuidance(ctx);
1056
1077
  subagentContext = ctx;
1057
1078
  subagentPollGeneration += 1;
1058
1079
  foregroundSubagentRuns.clear();
@@ -1128,6 +1149,7 @@ export default function webuiRpcHelper(pi) {
1128
1149
 
1129
1150
  pi.on("session_shutdown", () => {
1130
1151
  subagentContext = null;
1152
+ subagentLaunchSlotGuidance = "";
1131
1153
  subagentPollGeneration += 1;
1132
1154
  clearTimeout(subagentPollTimer);
1133
1155
  subagentPollTimer = null;
@@ -1147,14 +1169,22 @@ export default function webuiRpcHelper(pi) {
1147
1169
  });
1148
1170
 
1149
1171
  pi.on("before_agent_start", async (event) => {
1150
- if (disabledSkills.size === 0 && inheritedEnabledSkills === null) return;
1151
- const allSkills = Array.isArray(event.systemPromptOptions?.skills) ? event.systemPromptOptions.skills : [];
1152
- if (allSkills.length === 0) return;
1153
- const disabledNames = allSkills.filter((skill) => !isSkillEnabled(skill.name)).map((skill) => skill.name);
1154
- if (disabledNames.length === 0) return;
1155
- const filteredSkills = allSkills.filter((skill) => isSkillEnabled(skill.name));
1156
- let nextPrompt = replaceAvailableSkillsSection(event.systemPrompt, filteredSkills);
1157
- for (const name of disabledNames) nextPrompt = nextPrompt.replace(skillBlockPattern(name), "");
1158
- return { systemPrompt: nextPrompt };
1172
+ let nextPrompt = event.systemPrompt;
1173
+ let changed = false;
1174
+ if (disabledSkills.size !== 0 || inheritedEnabledSkills !== null) {
1175
+ const allSkills = Array.isArray(event.systemPromptOptions?.skills) ? event.systemPromptOptions.skills : [];
1176
+ const disabledNames = allSkills.filter((skill) => !isSkillEnabled(skill.name)).map((skill) => skill.name);
1177
+ if (disabledNames.length) {
1178
+ const filteredSkills = allSkills.filter((skill) => isSkillEnabled(skill.name));
1179
+ nextPrompt = replaceAvailableSkillsSection(nextPrompt, filteredSkills);
1180
+ for (const name of disabledNames) nextPrompt = nextPrompt.replace(skillBlockPattern(name), "");
1181
+ changed = true;
1182
+ }
1183
+ }
1184
+ if (subagentLaunchSlotGuidance) {
1185
+ nextPrompt = `${String(nextPrompt || "").trimEnd()}\n\n${subagentLaunchSlotGuidance}\n`;
1186
+ changed = true;
1187
+ }
1188
+ return changed ? { systemPrompt: nextPrompt } : undefined;
1159
1189
  });
1160
1190
  }