pi-subagents-lite 1.4.0 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-subagents-lite",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Lightweight sub-agents for pi — spawn specialized agents with isolated sessions, tools, and models.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -130,11 +130,11 @@ function parseFrontmatter(
130
130
  /* parseExtensions */
131
131
  /* ------------------------------------------------------------------ */
132
132
 
133
- /** Split comma-separated string, trim whitespace, and remove empty entries. */
133
+ /** Split comma-separated string, trim whitespace, strip brackets, and remove empty entries. */
134
134
  function splitCommaList(value: string): string[] {
135
135
  return value
136
136
  .split(",")
137
- .map((s) => s.trim())
137
+ .map((s) => s.trim().replace(/^\[|\]$/g, "").trim())
138
138
  .filter((s) => s.length > 0);
139
139
  }
140
140
 
@@ -528,23 +528,23 @@ export async function runAgent(
528
528
  const config = getConfig(type, store.agent.loadSkillsImplicitly, store.agent.loadExtensionsImplicitly);
529
529
  const agentConfig = getAgentConfig(type);
530
530
 
531
- // Warn on mutual exclusion violations
532
- const notify = (msg: string) => {
533
- if (ctx.ui?.notify) ctx.ui.notify(`[pi-subagents] ${msg}`, "warning");
534
- else console.warn(`[pi-subagents] ${msg}`);
535
- };
531
+ // Buffer warnings during setup to avoid inserting custom_message entries
532
+ // between tool_use and tool_result in the session tree (causes Anthropic 400).
533
+ // Flushed after runTurnLoop completes.
534
+ const warnings: string[] = [];
535
+ const bufferNotify = (msg: string) => { warnings.push(msg); };
536
536
  if (agentConfig?.excludeTools && Array.isArray(agentConfig.tools)) {
537
- notify(`agent "${type}": both tools and exclude_tools set — tools (whitelist) wins`);
537
+ bufferNotify(`agent "${type}": both tools and exclude_tools set — tools (whitelist) wins`);
538
538
  }
539
539
  if (agentConfig?.excludeExtensions && Array.isArray(agentConfig.extensions)) {
540
- notify(`agent "${type}": both extensions and exclude_extensions set — extensions (whitelist) wins`);
540
+ bufferNotify(`agent "${type}": both extensions and exclude_extensions set — extensions (whitelist) wins`);
541
541
  }
542
542
 
543
543
  const effectiveCwd = options.cwd ?? ctx.cwd;
544
544
  const env = await detectEnv(options.pi, effectiveCwd);
545
545
 
546
546
  // Resolve system prompt mode + source prompts + context files
547
- const { mode, extras: promptExtras } = resolveSystemPromptSources(ctx, effectiveCwd, notify);
547
+ const { mode, extras: promptExtras } = resolveSystemPromptSources(ctx, effectiveCwd, bufferNotify);
548
548
 
549
549
  const systemPrompt = buildPrompt(
550
550
  type, agentConfig, config, effectiveCwd, env,
@@ -553,7 +553,7 @@ export async function runAgent(
553
553
  const { loader, reloadAndMap } = createResourceLoader(config, agentConfig, effectiveCwd, systemPrompt);
554
554
  const { extResult } = await reloadAndMap();
555
555
  const session = await createAndConfigureSession(
556
- ctx, options, agentConfig, type, effectiveCwd, loader, extResult, notify,
556
+ ctx, options, agentConfig, type, effectiveCwd, loader, extResult, bufferNotify,
557
557
  );
558
558
  const { unsubscribe: unsubTurns, getAborted, getTurnLimited } = wireTurnTracking(session, {
559
559
  ...options,
@@ -561,5 +561,12 @@ export async function runAgent(
561
561
  });
562
562
 
563
563
  const responseText = await runTurnLoop(session, prompt, options, unsubTurns);
564
+
565
+ // Flush buffered warnings now that tool_result is in the session tree.
566
+ for (const msg of warnings) {
567
+ if (ctx.ui?.notify) ctx.ui.notify(`[pi-subagents-lite] ${msg}`, "warning");
568
+ else console.warn(`[pi-subagents-lite] ${msg}`);
569
+ }
570
+
564
571
  return { responseText, session, aborted: getAborted(), turnLimited: getTurnLimited() };
565
572
  }