pi-fabric 0.66.0 → 0.67.0
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/dist/chunks/{fabric-runtime-state-FDTVRRCU.js → fabric-runtime-state-LG265P3R.js} +1 -1
- package/dist/index.js +141 -1
- package/dist/index.js.map +3 -3
- package/dist/runtime/core-tool-properties.d.ts +6 -0
- package/dist/runtime/core-tool-properties.d.ts.map +1 -0
- package/dist/type-error-guidance.d.ts.map +1 -1
- package/package.json +1 -1
- /package/dist/chunks/{fabric-runtime-state-FDTVRRCU.js.map → fabric-runtime-state-LG265P3R.js.map} +0 -0
|
@@ -11707,4 +11707,4 @@ var deepAssign = (target, source) => {
|
|
|
11707
11707
|
export {
|
|
11708
11708
|
FabricRuntimeState
|
|
11709
11709
|
};
|
|
11710
|
-
//# sourceMappingURL=fabric-runtime-state-
|
|
11710
|
+
//# sourceMappingURL=fabric-runtime-state-LG265P3R.js.map
|
package/dist/index.js
CHANGED
|
@@ -76,6 +76,10 @@ import {
|
|
|
76
76
|
import {
|
|
77
77
|
resolveAgentDir
|
|
78
78
|
} from "./chunks/chunk-SOBEXOWK.js";
|
|
79
|
+
import {
|
|
80
|
+
GUEST_TYPE_DECLARATIONS,
|
|
81
|
+
PI_CORE_COMPATIBILITY_ARGUMENT_TYPE_NAMES
|
|
82
|
+
} from "./chunks/chunk-HGVFNZEQ.js";
|
|
79
83
|
import {
|
|
80
84
|
awaitPeerSettle,
|
|
81
85
|
buildPeerCards
|
|
@@ -2396,10 +2400,146 @@ var prepareFabricExecArguments = (input) => {
|
|
|
2396
2400
|
return prepared;
|
|
2397
2401
|
};
|
|
2398
2402
|
|
|
2403
|
+
// src/runtime/core-tool-properties.ts
|
|
2404
|
+
var CORE_TOOL_NAMES = Object.keys(
|
|
2405
|
+
PI_CORE_COMPATIBILITY_ARGUMENT_TYPE_NAMES
|
|
2406
|
+
);
|
|
2407
|
+
var extractTypeDeclarations = (declarations) => {
|
|
2408
|
+
const parsed = /* @__PURE__ */ new Map();
|
|
2409
|
+
for (const match of declarations.matchAll(/\btype\s+(\w+)\s*=/g)) {
|
|
2410
|
+
const name = match[1];
|
|
2411
|
+
if (name === void 0) continue;
|
|
2412
|
+
const rhsStart = match.index + match[0].length;
|
|
2413
|
+
let depth = 0;
|
|
2414
|
+
let end = rhsStart;
|
|
2415
|
+
while (end < declarations.length) {
|
|
2416
|
+
const character = declarations[end];
|
|
2417
|
+
if (character === "(" || character === "{" || character === "[") depth += 1;
|
|
2418
|
+
else if (character === ")" || character === "}" || character === "]") depth -= 1;
|
|
2419
|
+
else if (character === ";" && depth === 0) break;
|
|
2420
|
+
end += 1;
|
|
2421
|
+
}
|
|
2422
|
+
parsed.set(name, declarations.slice(rhsStart, end));
|
|
2423
|
+
}
|
|
2424
|
+
return parsed;
|
|
2425
|
+
};
|
|
2426
|
+
var matchCaptures = (text, pattern) => [...text.matchAll(pattern)].flatMap(
|
|
2427
|
+
(match) => match[1] === void 0 ? [] : [match[1]]
|
|
2428
|
+
);
|
|
2429
|
+
var objectLiteralKeys = (rhs) => {
|
|
2430
|
+
const withoutMappedKeys = rhs.replace(/\[\s*\w+\s+in\s+keyof\s+\w+\s*\]\s*:/g, " ");
|
|
2431
|
+
return matchCaptures(withoutMappedKeys, /([A-Za-z_]\w*)\s*\??:/g);
|
|
2432
|
+
};
|
|
2433
|
+
var referencedTypeNames = (rhs) => matchCaptures(rhs, /\b(Pi[A-Z]\w*)/g);
|
|
2434
|
+
var capitalise = (tool) => tool.charAt(0).toUpperCase() + tool.slice(1);
|
|
2435
|
+
var collectCoreToolProperties = (declarations) => {
|
|
2436
|
+
const typeDeclarations = extractTypeDeclarations(declarations);
|
|
2437
|
+
const owners = /* @__PURE__ */ new Map();
|
|
2438
|
+
for (const tool of CORE_TOOL_NAMES) {
|
|
2439
|
+
const roots = [
|
|
2440
|
+
`Pi${capitalise(tool)}Argument`,
|
|
2441
|
+
PI_CORE_COMPATIBILITY_ARGUMENT_TYPE_NAMES[tool],
|
|
2442
|
+
`Pi${capitalise(tool)}Options`
|
|
2443
|
+
];
|
|
2444
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2445
|
+
const walk = (name) => {
|
|
2446
|
+
if (visited.has(name)) return;
|
|
2447
|
+
visited.add(name);
|
|
2448
|
+
const rhs = typeDeclarations.get(name);
|
|
2449
|
+
if (rhs === void 0) return;
|
|
2450
|
+
for (const property of objectLiteralKeys(rhs)) {
|
|
2451
|
+
const toolSet = owners.get(property) ?? /* @__PURE__ */ new Set();
|
|
2452
|
+
toolSet.add(tool);
|
|
2453
|
+
owners.set(property, toolSet);
|
|
2454
|
+
}
|
|
2455
|
+
for (const reference of referencedTypeNames(rhs)) walk(reference);
|
|
2456
|
+
};
|
|
2457
|
+
for (const root of roots) walk(root);
|
|
2458
|
+
}
|
|
2459
|
+
return new Map([...owners].map(([property, toolSet]) => [property, [...toolSet]]));
|
|
2460
|
+
};
|
|
2461
|
+
var CORE_TOOL_PROPERTIES = collectCoreToolProperties(GUEST_TYPE_DECLARATIONS);
|
|
2462
|
+
|
|
2399
2463
|
// src/type-error-guidance.ts
|
|
2400
2464
|
var SYNTAX_ERROR_PATTERN = /expected|unterminated|unexpected|invalid character/i;
|
|
2401
2465
|
var PAYLOAD_CALL_PATTERN = /\bpi\.(?:edit|write)\s*\(/;
|
|
2466
|
+
var PROMISE_ALL_PATTERN = /\bPromise\.all\s*\(/;
|
|
2467
|
+
var TUPLE_ARITY_PATTERN = /Tuple type .* of length '[0-9]+' has no element at index '[0-9]+'/;
|
|
2468
|
+
var MISSING_NAME_PATTERN = /^Cannot find name '([^']+)'/;
|
|
2469
|
+
var UNKNOWN_PROPERTY_PATTERN = /'([^']+)' does not exist in type '([^']+)'/;
|
|
2470
|
+
var PI_CALL_PATTERN = /\bpi\.(\w+)\s*\(/g;
|
|
2471
|
+
var FABRIC_EXEC_ARGUMENT_NOTES = {
|
|
2472
|
+
strings: "named `strings` belong in the outer `fabric_exec` arguments, then become available inside `code` as `\u03C0.key`.",
|
|
2473
|
+
tokenBudget: "budget arguments (`tokenBudget`, `agentBudget`) belong to the outer `fabric_exec` call, not inside `code`.",
|
|
2474
|
+
agentBudget: "budget arguments (`tokenBudget`, `agentBudget`) belong to the outer `fabric_exec` call, not inside `code`.",
|
|
2475
|
+
display: "the `display` objective belongs to the outer `fabric_exec` call, not inside `code`.",
|
|
2476
|
+
resultFormat: "`resultFormat` belongs to the outer `fabric_exec` call, not inside `code`."
|
|
2477
|
+
};
|
|
2478
|
+
var PROPERTY_NOTES = {
|
|
2479
|
+
settle: "`settle:true` settles nonzero `pi.bash` exits into an `ok:false` envelope instead of rejecting; other `pi.*` calls reject failures normally.",
|
|
2480
|
+
timeout: "`timeout` is measured in seconds; `timeoutMs` is converted from milliseconds."
|
|
2481
|
+
};
|
|
2482
|
+
var isCoreToolName = (name) => CORE_TOOL_NAMES.includes(name);
|
|
2483
|
+
var toolFromTypeText = (typeText) => {
|
|
2484
|
+
for (const match of typeText.matchAll(/\bPi([A-Z]\w*)/g)) {
|
|
2485
|
+
const captured = match[1];
|
|
2486
|
+
if (captured === void 0) continue;
|
|
2487
|
+
const candidate = captured.replace(/(?:Compatibility)?(?:Argument|Options)$/, "").toLowerCase();
|
|
2488
|
+
if (isCoreToolName(candidate)) return candidate;
|
|
2489
|
+
}
|
|
2490
|
+
return void 0;
|
|
2491
|
+
};
|
|
2492
|
+
var enclosingCoreTool = (code, error) => {
|
|
2493
|
+
const lines = code.split("\n");
|
|
2494
|
+
for (const lineIndex of [error.line - 2, error.line - 1]) {
|
|
2495
|
+
if (lineIndex < 0 || lineIndex >= lines.length) continue;
|
|
2496
|
+
const offset = lines.slice(0, lineIndex).join("\n").length + (lineIndex > 0 ? 1 : 0) + Math.max(0, error.column - 1);
|
|
2497
|
+
PI_CALL_PATTERN.lastIndex = 0;
|
|
2498
|
+
let match;
|
|
2499
|
+
let tool;
|
|
2500
|
+
while ((match = PI_CALL_PATTERN.exec(code)) !== null && match.index < offset) {
|
|
2501
|
+
const called = match[1];
|
|
2502
|
+
if (called !== void 0 && isCoreToolName(called)) tool = called;
|
|
2503
|
+
}
|
|
2504
|
+
if (tool !== void 0) return tool;
|
|
2505
|
+
}
|
|
2506
|
+
return void 0;
|
|
2507
|
+
};
|
|
2508
|
+
var unknownPropertyHint = (property, tool) => {
|
|
2509
|
+
if (tool === void 0) return void 0;
|
|
2510
|
+
const envelopeNote = FABRIC_EXEC_ARGUMENT_NOTES[property];
|
|
2511
|
+
if (envelopeNote !== void 0) {
|
|
2512
|
+
return `Recovery hint: \`${property}\` is a \`fabric_exec\` argument, not a \`pi.${tool}\` property. ${envelopeNote}`;
|
|
2513
|
+
}
|
|
2514
|
+
const ownerTools = CORE_TOOL_PROPERTIES.get(property);
|
|
2515
|
+
if (ownerTools === void 0 || ownerTools.includes(tool)) return void 0;
|
|
2516
|
+
const owners = ownerTools.map((owner) => `\`pi.${owner}\``).join(", ");
|
|
2517
|
+
const note = PROPERTY_NOTES[property];
|
|
2518
|
+
return `Recovery hint: \`${property}\` is not a \`pi.${tool}\` property \u2014 it belongs to ${owners}.${note ? ` ${note}` : ""}`;
|
|
2519
|
+
};
|
|
2520
|
+
var hasLiteralPayloadInterpolation = (code, errors) => {
|
|
2521
|
+
if (!PAYLOAD_CALL_PATTERN.test(code)) return false;
|
|
2522
|
+
return errors.some((error) => {
|
|
2523
|
+
const name = MISSING_NAME_PATTERN.exec(error.message)?.[1];
|
|
2524
|
+
return name !== void 0 && code.includes(`\${${name}}`);
|
|
2525
|
+
});
|
|
2526
|
+
};
|
|
2402
2527
|
var typeErrorRecoveryHint = (code, errors) => {
|
|
2528
|
+
for (const error of errors) {
|
|
2529
|
+
const property = UNKNOWN_PROPERTY_PATTERN.exec(error.message)?.[1];
|
|
2530
|
+
const typeText = UNKNOWN_PROPERTY_PATTERN.exec(error.message)?.[2];
|
|
2531
|
+
if (property !== void 0 && typeText !== void 0) {
|
|
2532
|
+
const tool = toolFromTypeText(typeText) ?? enclosingCoreTool(code, error);
|
|
2533
|
+
const hint = unknownPropertyHint(property, tool);
|
|
2534
|
+
if (hint) return hint;
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
if (PROMISE_ALL_PATTERN.test(code) && errors.some((error) => TUPLE_ARITY_PATTERN.test(error.message))) {
|
|
2538
|
+
return "Recovery hint: match `Promise.all` destructuring one binding per promise; remove the extra binding or add the missing call.";
|
|
2539
|
+
}
|
|
2540
|
+
if (hasLiteralPayloadInterpolation(code, errors)) {
|
|
2541
|
+
return "Recovery hint: a `${...}` expression in an edit/write payload is being evaluated by the Fabric TypeScript program. Declare it if intentional; for literal file content, move the payload to top-level `strings` and reference `\u03C0.key`.";
|
|
2542
|
+
}
|
|
2403
2543
|
if (!PAYLOAD_CALL_PATTERN.test(code)) return void 0;
|
|
2404
2544
|
if (!errors.some((error) => SYNTAX_ERROR_PATTERN.test(error.message))) {
|
|
2405
2545
|
return void 0;
|
|
@@ -3551,7 +3691,7 @@ var FabricState = class {
|
|
|
3551
3691
|
return activation;
|
|
3552
3692
|
}
|
|
3553
3693
|
async #createRuntime() {
|
|
3554
|
-
const module = await (this.#options.runtimeLoader?.() ?? import("./chunks/fabric-runtime-state-
|
|
3694
|
+
const module = await (this.#options.runtimeLoader?.() ?? import("./chunks/fabric-runtime-state-LG265P3R.js"));
|
|
3555
3695
|
return new module.FabricRuntimeState(
|
|
3556
3696
|
this.pi,
|
|
3557
3697
|
this.capturedTools,
|