pi-fabric 0.132.1 → 0.132.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 (34) hide show
  1. package/dist/chunks/{chunk-DQUSFEJL.js → chunk-5INZBPCM.js} +56 -22
  2. package/dist/chunks/chunk-5INZBPCM.js.map +7 -0
  3. package/dist/core/execution-guidelines.d.ts +6 -0
  4. package/dist/core/execution-guidelines.d.ts.map +1 -0
  5. package/dist/core/guidance-delivery.d.ts +19 -0
  6. package/dist/core/guidance-delivery.d.ts.map +1 -0
  7. package/dist/core/prompt-guidance.d.ts +1 -0
  8. package/dist/core/prompt-guidance.d.ts.map +1 -1
  9. package/dist/core/prompt-guidance.js +50 -1
  10. package/dist/core/prompt-guidance.js.map +3 -3
  11. package/dist/durable-extension.js +1 -1
  12. package/dist/durable-extension.js.map +1 -1
  13. package/dist/extension-bootstrap.d.ts.map +1 -1
  14. package/dist/extension-bootstrap.js +1 -1
  15. package/dist/extension.d.ts.map +1 -1
  16. package/dist/fabric-exec-tool.d.ts.map +1 -1
  17. package/dist/fabric-runtime-state.js +16 -4
  18. package/dist/fabric-runtime-state.js.map +2 -2
  19. package/dist/index.js +1 -1
  20. package/dist/topology/peer-presence.d.ts.map +1 -1
  21. package/dist/ui/widget.d.ts +1 -1
  22. package/dist/ui/widget.d.ts.map +1 -1
  23. package/dist/verified/generated/manifest.json +12 -3
  24. package/dist/verified/generated/prompt-guidance.d.ts +4 -0
  25. package/dist/verified/generated/prompt-guidance.js +17 -0
  26. package/docs/agents.md +1 -0
  27. package/docs/interface.md +1 -1
  28. package/docs/jev.md +1 -1
  29. package/docs/verified-kernels.md +23 -0
  30. package/package.json +1 -1
  31. package/proofs/index.ts +2 -0
  32. package/proofs/prompt-guidance.ts +38 -0
  33. package/scripts/verified-kernels.ts +1 -1
  34. package/dist/chunks/chunk-DQUSFEJL.js.map +0 -7
@@ -1781,6 +1781,25 @@ var FabricDirectToolApproval = class {
1781
1781
  }
1782
1782
  };
1783
1783
 
1784
+ // src/core/execution-guidelines.ts
1785
+ var fabricExecutionGuidelines = (kernel = "typescript", pythonRuntime = "monty", managedHost = false) => managedHost ? [
1786
+ "Batch independent operations with bounded concurrency, keep dependent calls ordered, inspect results, and return compact evidence."
1787
+ ] : [
1788
+ kernel === "python" ? "Batch independent operations in one `fabric_exec` Python program with `asyncio.gather`; await dependent/conditional steps sequentially. Coalesce independent replacements into one `await pi.edit(path=..., edits=[...])`. Return only the compact final JSON-compatible value." : "Batch independent operations in one `fabric_exec` program (`Promise.all` for parallel, sequential `await` for ordered), not one call per tool; keep dependent/conditional steps sequential. Coalesce non-dependent replacements from one file snapshot into one `pi.edit({path, edits:[...]})`; use `all:true` only for intentional repeated exact anchors. Return only the compact final value; intermediate results stay in the sandbox.",
1789
+ kernel === "python" ? "Search before reading with `await pi.grep(pattern=..., path=...)` or `await pi.find(pattern=..., path=...)`, then `await pi.read(path=..., offset=..., limit=...)`. Use Python dict syntax, `True`/`False`/`None`, and bounded searches; unbounded reads cap at 2000 lines or 50KB. Read continuation notices when needed." : "Search before reading: use `pi.grep`/`pi.find` to locate relevant lines, then `pi.read({path, offset, limit})` that range. Escape regex metacharacters, or use `literal:true` for exact punctuated text. Keep fan-out search limits small and widen only on misses. An unbounded `pi.read` returns at most 2000 lines or 50KB and, when truncated, ends with a `Use offset=\u2026` continuation notice; reserve whole-file reads for small files you will use in full.",
1790
+ "Keep the acceptance ledger in reasoning or concise progress notes (no tool call): define concrete checks, trace execution before editing, implement end to end, then run targeted tests and direct behavioral probes. Confirm requested public symbols, registrations, and configuration entries. Use the smallest checks that cover the ledger; escalate only for failures or cross-cutting risk. Inspect failures and iterate instead of rerunning unchanged passing checks. A build alone is not completion.",
1791
+ kernel === "python" ? "For test/probe nonzero exits, use `await pi.bash(command=..., settle=True)` and inspect the returned dict: `r['ok']`, `r['output']`, and `r.get('exitCode')`. Set shell `timeout` in seconds once for long suites. Return decisions and evidence rather than raw logs." : "Amortize round trips without inflating context: batch only independent, bounded work. Keep search\u2192read and edit\u2192verify sequential when an output determines the next action. Use `settle:true` for tests or probes whose nonzero result is evidence rather than an exceptional stop; for a known long suite, set `pi.bash` `timeout` in seconds once instead of retrying a timed-out call. Filter or summarize noisy command output inside the program and return decisions, failures, and evidence\u2014not raw logs or unused intermediate results.",
1792
+ "For edits/writes, pass named payloads through top-level `payloads`; each `\u03C0.key` must exactly match a key there; prefer `pi.edit`/`pi.write`. `pi.bash`: no stdin.",
1793
+ "Use `display.name` and objective `display.description`; Fabric pairs them with verified outcomes in deterministic compaction.",
1794
+ ...kernel === "python" && pythonRuntime === "monty" ? ["Monty requires acyclic JSON host arguments. For underscore-prefixed provider/tool names, use `await tools.call(ref=..., args={...})`, not direct attributes. Use `payloads['key']` for private/non-identifier payload keys."] : []
1795
+ ];
1796
+ var fabricOwnedExecutionGuidelines = () => [.../* @__PURE__ */ new Set([
1797
+ ...fabricExecutionGuidelines(),
1798
+ ...fabricExecutionGuidelines("python", "monty"),
1799
+ ...fabricExecutionGuidelines("python", "cpython"),
1800
+ ...fabricExecutionGuidelines("typescript", "monty", true)
1801
+ ])];
1802
+
1784
1803
  // src/fabric-exec-tool.ts
1785
1804
  import { Container as Container2, Text as Text2 } from "@earendil-works/pi-tui";
1786
1805
  import { Type } from "typebox";
@@ -2100,17 +2119,7 @@ var createFabricExecTool = (state, codePreviewSettings, pendingHandoffs, decorat
2100
2119
  label: "Fabric",
2101
2120
  description: managedHost ? "Execute type-checked TypeScript in the managed QuickJS runtime. See the managed execution guidance for authorized tool contracts." : python ? monty ? "Execute Python through Fabric's configured Monty sandbox. Monty runs a Python subset with VM resource limits, no native filesystem/network/environment access, and only host-mediated tools. Each invocation starts fresh. This is the exclusive model tool path in full code mode and Schema enforce mode." : "Execute Python through Fabric\u2019s configured CPython kernel for Pi core tools, MCP, providers, discovery, and extensions. Each call uses a fresh process. Native execution is trusted code; Schema enforce requires OS isolation. This is the exclusive model tool path in full code mode and Schema enforce mode." : "Execute code through Fabric's TypeScript kernel: type-checked TypeScript by default, unmodified JavaScript with executor.codemodeProfile native. Both support nativeTools; native mode places Pi-compatible calls on tools and Fabric discovery on fabric.tools. Compose Pi core tools, MCP, Fabric providers, discovery, and extensions. QuickJS is isolated by default; the optional Node/Bun process is an unsafe trusted-code escape hatch. In full code mode, and always in Schema enforce mode, this is the exclusive model tool path.",
2102
2121
  promptSnippet: managedHost ? `Authorized host tools (${managedHost.providers.join(", ") || "none"}) and deterministic computation` : "Pi core tools, MCP, Fabric providers, discovery, and extensions",
2103
- promptGuidelines: managedHost ? [
2104
- "Batch independent operations with bounded concurrency, keep dependent calls ordered, inspect results, and return compact evidence."
2105
- ] : [
2106
- python ? "Batch independent operations in one `fabric_exec` Python program with `asyncio.gather`; await dependent/conditional steps sequentially. Coalesce independent replacements into one `await pi.edit(path=..., edits=[...])`. Return only the compact final JSON-compatible value." : "Batch independent operations in one `fabric_exec` program (`Promise.all` for parallel, sequential `await` for ordered), not one call per tool; keep dependent/conditional steps sequential. Coalesce non-dependent replacements from one file snapshot into one `pi.edit({path, edits:[...]})`; use `all:true` only for intentional repeated exact anchors. Return only the compact final value; intermediate results stay in the sandbox.",
2107
- python ? "Search before reading with `await pi.grep(pattern=..., path=...)` or `await pi.find(pattern=..., path=...)`, then `await pi.read(path=..., offset=..., limit=...)`. Use Python dict syntax, `True`/`False`/`None`, and bounded searches; unbounded reads cap at 2000 lines or 50KB. Read continuation notices when needed." : "Search before reading: use `pi.grep`/`pi.find` to locate relevant lines, then `pi.read({path, offset, limit})` that range. Escape regex metacharacters, or use `literal:true` for exact punctuated text. Keep fan-out search limits small and widen only on misses. An unbounded `pi.read` returns at most 2000 lines or 50KB and, when truncated, ends with a `Use offset=\u2026` continuation notice; reserve whole-file reads for small files you will use in full.",
2108
- "Keep the acceptance ledger in reasoning or concise progress notes (no tool call): define concrete checks, trace execution before editing, implement end to end, then run targeted tests and direct behavioral probes. Confirm requested public symbols, registrations, and configuration entries. Use the smallest checks that cover the ledger; escalate only for failures or cross-cutting risk. Inspect failures and iterate instead of rerunning unchanged passing checks. A build alone is not completion.",
2109
- python ? "For test/probe nonzero exits, use `await pi.bash(command=..., settle=True)` and inspect the returned dict: `r['ok']`, `r['output']`, and `r.get('exitCode')`. Set shell `timeout` in seconds once for long suites. Return decisions and evidence rather than raw logs." : "Amortize round trips without inflating context: batch only independent, bounded work. Keep search\u2192read and edit\u2192verify sequential when an output determines the next action. Use `settle:true` for tests or probes whose nonzero result is evidence rather than an exceptional stop; for a known long suite, set `pi.bash` `timeout` in seconds once instead of retrying a timed-out call. Filter or summarize noisy command output inside the program and return decisions, failures, and evidence\u2014not raw logs or unused intermediate results.",
2110
- "For edits/writes, pass named payloads through top-level `payloads`; each `\u03C0.key` must exactly match a key there; prefer `pi.edit`/`pi.write`. `pi.bash`: no stdin.",
2111
- "Use `display.name` and objective `display.description`; Fabric pairs them with verified outcomes in deterministic compaction.",
2112
- ...monty ? ["Monty requires acyclic JSON host arguments. For underscore-prefixed provider/tool names, use `await tools.call(ref=..., args={...})`, not direct attributes. Use `payloads['key']` for private/non-identifier payload keys."] : []
2113
- ],
2122
+ promptGuidelines: fabricExecutionGuidelines(toolKernel(state), python ? state.config.executor.pythonRuntime : void 0, Boolean(managedHost)),
2114
2123
  // The model-facing schema is intentionally flat: one large `code` string
2115
2124
  // plus scalar/optional params. Do not add nested arrays-of-objects with
2116
2125
  // escaped content here. SOTA models are post-trained on one dominant
@@ -4321,10 +4330,11 @@ var widgetRowLimit = (maxRows, terminalRows) => {
4321
4330
  var widgetFocusedRowLimit = (maxRows, terminalRows) => widgetRowLimit(maxRows, terminalRows);
4322
4331
  var widgetViewport = (contentRows, budget, offset) => {
4323
4332
  const available = Math.max(0, Math.floor(budget));
4324
- const hasCue = contentRows > available && available > 1;
4333
+ const maxOffset = available > 0 ? Math.max(0, contentRows - available) : 0;
4334
+ const clampedOffset = Math.max(0, Math.min(maxOffset, Math.floor(offset)));
4335
+ const hasCue = clampedOffset < maxOffset && available > 1;
4325
4336
  const windowRows = Math.max(0, available - Number(hasCue));
4326
- const maxOffset = windowRows > 0 ? Math.max(0, contentRows - windowRows) : 0;
4327
- return { windowRows, hasCue, maxOffset, offset: Math.max(0, Math.min(maxOffset, Math.floor(offset))) };
4337
+ return { windowRows, hasCue, maxOffset, offset: clampedOffset };
4328
4338
  };
4329
4339
  var HEADER_ROW = "\0main";
4330
4340
  var FabricWidget = class {
@@ -4520,7 +4530,7 @@ var FabricWidget = class {
4520
4530
  const header = headerWidth === width ? lines[0] ?? "" : this.#content(snapshot, width, headerWidth).lines[0] ?? "";
4521
4531
  const boundedHeader = label ? this.#withRightLabel(header, label, width) : truncateToWidth3(header, width);
4522
4532
  const visibleLines = [boundedHeader, ...lines.slice(start, start + capacity).map((line) => truncateToWidth3(line, width))];
4523
- if (viewport.hasCue) visibleLines.push(below > 0 ? truncateToWidth3(this.theme.fg("dim", `\u2193 ${below} more`), width) : "");
4533
+ if (viewport.hasCue) visibleLines.push(truncateToWidth3(this.theme.fg("dim", `\u2193 ${below} more`), width));
4524
4534
  this.#rows = rows.filter((row) => row.line === 0 || row.line >= start && row.line < start + capacity).map((row) => ({ ...row, line: row.line === 0 ? 0 : row.line - start + 1 }));
4525
4535
  if (rows.length === 0 && this.interaction?.collapseIdle?.()) return [];
4526
4536
  this.#spacerRows = spacer;
@@ -6807,6 +6817,9 @@ function createFabricExtension(entryUrl) {
6807
6817
  defaultFabricExecutionGuidance,
6808
6818
  extensionToolRosterGuidance,
6809
6819
  fabricExecutionKernelGuidance,
6820
+ fabricGuidanceDelivery,
6821
+ relocateFabricGuidelines,
6822
+ stripFabricRuleBullets,
6810
6823
  managedHostExecutionGuidance,
6811
6824
  managedHostKernelGuidance,
6812
6825
  fabricSchemaGuidance
@@ -6815,8 +6828,25 @@ function createFabricExtension(entryUrl) {
6815
6828
  const captureSnapshot = state.bootstrapped ? capturePolicy() : void 0;
6816
6829
  const managedHost = state.managedHostOptions;
6817
6830
  const skillReader = managedHost ? managedHost.skillReader ?? null : void 0;
6818
- const sections = event.systemPromptOptions.forceSystemPrompt === void 0 ? event.systemPromptOptions.sections : void 0;
6819
- const systemPrompt = sections ? "" : restoreSkillsForFullCodePrompt(event.systemPrompt, skills, effectiveFullCodeMode, skillReader);
6831
+ const delivery = fabricGuidanceDelivery(
6832
+ true,
6833
+ event.systemPromptOptions.sections !== void 0,
6834
+ event.systemPromptOptions.forceSystemPrompt !== void 0
6835
+ );
6836
+ const sections = delivery.section ? event.systemPromptOptions.sections : void 0;
6837
+ const ownedExecutionRules = fabricOwnedExecutionGuidelines();
6838
+ const executionRules = relocateFabricGuidelines(
6839
+ event.systemPromptOptions.toolGuidelines,
6840
+ fabricExecutionGuidelines(config.executor.kernel, config.executor.pythonRuntime, Boolean(managedHost)),
6841
+ delivery,
6842
+ ownedExecutionRules
6843
+ );
6844
+ const systemPrompt = sections ? "" : restoreSkillsForFullCodePrompt(
6845
+ stripFabricRuleBullets(event.systemPrompt, ownedExecutionRules),
6846
+ skills,
6847
+ effectiveFullCodeMode,
6848
+ skillReader
6849
+ );
6820
6850
  const prompt = userPromptText(event);
6821
6851
  const skillReferenceGuidance = effectiveFullCodeMode && prompt !== void 0 ? buildSkillReferenceGuidance(prompt, skills, skillReader) : void 0;
6822
6852
  const currentModel = context.model ? `${context.model.provider}/${context.model.id}` : void 0;
@@ -6836,20 +6866,24 @@ function createFabricExtension(entryUrl) {
6836
6866
  const guidance = [
6837
6867
  managedHost ? managedHostKernelGuidance(managedHost) : fabricExecutionKernelGuidance(effectiveFullCodeMode, config.executor.kernel, config.executor.pythonRuntime, config.executor.codemodeProfile),
6838
6868
  resolvedGuidance.slotText,
6869
+ executionRules.text,
6839
6870
  fabricSchemaGuidance(schemaMode),
6840
6871
  overrideGuidance,
6841
6872
  extensionRoster,
6842
6873
  resolvedGuidance.appendText,
6843
6874
  managedHost?.guidance
6844
6875
  ].filter((section) => Boolean(section)).join("\n\n");
6876
+ const catalog = sections ? restoreSkillsForFullCodePrompt(sections.skills ?? "", skills, effectiveFullCodeMode, skillReader).trim() : void 0;
6877
+ const forced = delivery.append ? { systemPrompt: `${systemPrompt}
6878
+
6879
+ ${guidance}` } : {};
6845
6880
  if (sections) {
6846
- const catalog = restoreSkillsForFullCodePrompt("", skills, effectiveFullCodeMode, skillReader).trim();
6847
6881
  if (catalog) sections.skills = catalog;
6848
6882
  sections.fabric = guidance;
6849
6883
  }
6850
- const forced = sections ? {} : { systemPrompt: `${systemPrompt}
6851
-
6852
- ${guidance}` };
6884
+ if (executionRules.remaining !== void 0 && event.systemPromptOptions.toolGuidelines) {
6885
+ event.systemPromptOptions.toolGuidelines.fabric_exec = executionRules.remaining;
6886
+ }
6853
6887
  if (!skillReferenceGuidance) return sections ? void 0 : forced;
6854
6888
  return {
6855
6889
  ...forced,
@@ -7003,4 +7037,4 @@ export {
7003
7037
  FABRIC_MANAGED_HOST_VERSION,
7004
7038
  createFabricExtension
7005
7039
  };
7006
- //# sourceMappingURL=chunk-DQUSFEJL.js.map
7040
+ //# sourceMappingURL=chunk-5INZBPCM.js.map