@skydiveai/pi-extensions 0.1.259-beta.1 → 0.1.259-beta.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.
Files changed (2) hide show
  1. package/dist/index.mjs +19 -4
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1735,6 +1735,7 @@ var McpExtension = class {
1735
1735
  loggedLegacyToolNames = /* @__PURE__ */ new Set();
1736
1736
  lastConfigMtimeMs = 0;
1737
1737
  pendingMcpUpdate = null;
1738
+ toolBudgetWarning = "";
1738
1739
  /** Non-consuming peek used by `shouldStopAfterTurn`. */
1739
1740
  hasPendingUpdate() {
1740
1741
  return this.pendingMcpUpdate !== null;
@@ -2167,13 +2168,17 @@ var McpExtension = class {
2167
2168
  };
2168
2169
  }
2169
2170
  async reconcileAndRecordMtime({ pi, configPath, reason, contextWindow }) {
2171
+ const previousToolNames = new Set(this.registeredMcpToolNames);
2170
2172
  const summary = await this.reconcile({
2171
2173
  pi,
2172
2174
  configPath,
2173
2175
  contextWindow
2174
2176
  });
2175
2177
  this.lastConfigMtimeMs = await readConfigMtimeMs(configPath);
2176
- if (reason !== "session_start" && summaryHasChanges(summary)) this.pendingMcpUpdate = summary;
2178
+ this.toolBudgetWarning = summary.droppedTools > 0 ? TOOL_BUDGET_GUIDANCE : "";
2179
+ const toolsChanged = previousToolNames.size !== this.registeredMcpToolNames.size || [...previousToolNames].some((name) => !this.registeredMcpToolNames.has(name));
2180
+ const queueContinuation = reason !== "session_start" && (toolsChanged || summaryHasChanges(summary));
2181
+ if (queueContinuation) this.pendingMcpUpdate = summary;
2177
2182
  log$21.info({
2178
2183
  event: "mcp_reconcile",
2179
2184
  reason,
@@ -2185,7 +2190,7 @@ var McpExtension = class {
2185
2190
  removed: summary.removed,
2186
2191
  refreshed: summary.refreshed,
2187
2192
  errors: summary.errors,
2188
- queued_continuation: reason !== "session_start" && summaryHasChanges(summary)
2193
+ queued_continuation: queueContinuation
2189
2194
  }, "MCP reconcile complete");
2190
2195
  return summary;
2191
2196
  }
@@ -2223,6 +2228,10 @@ var McpExtension = class {
2223
2228
  }
2224
2229
  return { messages };
2225
2230
  });
2231
+ pi.on("before_agent_start", (event) => {
2232
+ if (!this.toolBudgetWarning) return;
2233
+ return { systemPrompt: `${event.systemPrompt}\n\n${this.toolBudgetWarning}` };
2234
+ });
2226
2235
  pi.on("tool_result", async (_event, ctx) => {
2227
2236
  const configPath = join(ctx.cwd, MCP_CONFIG_FILENAME);
2228
2237
  let mtime;
@@ -2340,6 +2349,11 @@ function appendStderrBlock(lines, stderr) {
2340
2349
  for (const line of stderr.trimEnd().split("\n")) lines.push(` ${line}`);
2341
2350
  lines.push(" ---");
2342
2351
  }
2352
+ const TOOL_BUDGET_GUIDANCE = [
2353
+ "Apply this guidance only when the current task needs actions from an integration whose tools were truncated. For unrelated tasks, do not mention truncation, ask about that integration, or change its tool selection. For a relevant task, briefly tell the user that only a subset of the integration actions is loaded. If their workflow is already clear, select the tools needed and continue without redundant questions. Otherwise ask what they want to do before choosing tools; a connection/status check alone does not specify a workflow. They can name actions or describe goals. Do not ask the user for tool names or MCP configuration, and do not perform write actions merely to test a connection.",
2354
+ "To expose missing tools, edit the affected server entry in mcp.config.json: set \"tools\" to an allowlist of needed tools or \"excludeTools\" to omit unneeded ones. Use original server tool names, without the mcp__<server>__ prefix. Selection happens before the tool budgets; caps still apply.",
2355
+ "Config edits are detected automatically; the harness starts a follow-up turn with the updated tool set. Continue the task there without asking the user to send another message."
2356
+ ].join("\n");
2343
2357
  /**
2344
2358
  * Human-readable lines describing any budget-driven truncation, shared by
2345
2359
  * `summaryText` (the reload_mcp tool output) and `formatMcpUpdateMessage` (the
@@ -2351,7 +2365,8 @@ function truncationLines(summary) {
2351
2365
  const { maxTotalTools, maxToolsPerServer } = summary.limits;
2352
2366
  const totalCapHint = Number.isFinite(maxTotalTools) ? `${maxTotalTools}` : "unlimited";
2353
2367
  lines.push(` WARNING: ${summary.droppedTools} MCP tool(s) were NOT registered because a tool budget was hit (token budget: ~${summary.tokenBudget} tokens, used ~${summary.tokensUsed}; total-tool cap: ${totalCapHint}, per-server cap: ${Number.isFinite(maxToolsPerServer) ? maxToolsPerServer : "unlimited"}).`);
2354
- lines.push(" Tool definitions are sent to the model on every prompt; too many (or too-large) tool schemas push the request over the limit, so they are budgeted against the model context window. Prune servers from mcp.config.json to bring the tool surface down.");
2368
+ lines.push(" Tool definitions are sent to the model on every prompt; too many (or too-large) tool schemas push the request over the limit, so they are budgeted against the model context window.");
2369
+ lines.push(TOOL_BUDGET_GUIDANCE);
2355
2370
  for (const [id, count] of Object.entries(summary.toolCounts)) {
2356
2371
  if (count.droppedReason === null) continue;
2357
2372
  const why = count.droppedReason === "tokens" ? "token budget exhausted" : count.droppedReason === "total" ? "total-tool cap reached" : "per-server cap";
@@ -2419,7 +2434,7 @@ function summaryText(summary) {
2419
2434
  return lines.join("\n");
2420
2435
  }
2421
2436
  function summaryHasChanges(summary) {
2422
- return summary.added.length > 0 || summary.removed.length > 0 || summary.refreshed.length > 0 || summary.errors.length > 0 || summary.droppedTools > 0;
2437
+ return summary.added.length > 0 || summary.removed.length > 0 || summary.refreshed.length > 0 || summary.errors.length > 0;
2423
2438
  }
2424
2439
  /**
2425
2440
  * Format a queued tool-update as a synthetic system-style message for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skydiveai/pi-extensions",
3
- "version": "0.1.259-beta.1",
3
+ "version": "0.1.259-beta.3",
4
4
  "homepage": "https://skydive.com",
5
5
  "license": "MIT",
6
6
  "author": "Create, Inc.",