@cydm/pie 2.1.0 → 2.1.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.
Files changed (37) hide show
  1. package/README.md +6 -3
  2. package/dist/builtin/extensions/ask-user/index.js +1 -1
  3. package/dist/builtin/extensions/computer-use/index.js +3993 -107
  4. package/dist/builtin/extensions/plan-mode/index.js +1 -1
  5. package/dist/builtin/extensions/subagent/index.js +2 -2
  6. package/dist/builtin/extensions/todo/index.js +1 -1
  7. package/dist/builtin/skills/chrome-devtools-axi/LICENSE +21 -0
  8. package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +20 -1
  9. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +20034 -0
  10. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +8 -2
  11. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +26 -0
  12. package/dist/builtin/skills/chrome-devtools-axi/chunk-42SGITKJ.js +11 -0
  13. package/dist/builtin/skills/chrome-devtools-axi/chunk-OJ6N23UZ.js +47 -0
  14. package/dist/builtin/skills/chrome-devtools-axi/chunk-UPATXALW.js +215 -0
  15. package/dist/builtin/skills/chrome-devtools-axi/cli-F2VCSVL4.js +4424 -0
  16. package/dist/builtin/skills/skill-creator/SKILL.md +5 -2
  17. package/dist/builtin/skills/skill-creator/eval-viewer/generate_review.mjs +7 -20
  18. package/dist/builtin/skills/skill-creator/eval-viewer/viewer.html +15 -15
  19. package/dist/builtin/skills/skill-creator/scripts/aggregate_benchmark.mjs +20 -19
  20. package/dist/builtin/skills/skill-creator/scripts/generate_report.mjs +3 -3
  21. package/dist/builtin/skills/skill-creator/scripts/improve_description.mjs +12 -8
  22. package/dist/builtin/skills/skill-creator/scripts/package_skill.mjs +1 -0
  23. package/dist/builtin/skills/skill-creator/scripts/pie_runner.mjs +77 -31
  24. package/dist/builtin/skills/skill-creator/scripts/run_eval.mjs +38 -11
  25. package/dist/builtin/skills/skill-creator/scripts/run_loop.mjs +12 -6
  26. package/dist/builtin/skills/skill-creator/scripts/skill_metadata.mjs +12 -1
  27. package/dist/builtin/skills/tui-use/LICENSE +21 -0
  28. package/dist/builtin/skills/tui-use/README.md +13 -3
  29. package/dist/builtin/skills/tui-use/SKILL.md +87 -39
  30. package/dist/builtin/skills/tui-use/tui-use-cli.cjs +10608 -0
  31. package/dist/builtin/skills/tui-use/tui-use-cli.js +39 -0
  32. package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +7916 -0
  33. package/dist/chunks/{chunk-PMPD56N2.js → chunk-LU7RKALH.js} +82 -24
  34. package/dist/chunks/{chunk-G2POWIA5.js → chunk-TJ2F4FL5.js} +64 -16
  35. package/dist/cli.js +7503 -87
  36. package/package.json +26 -18
  37. package/scripts/repair-node-pty.mjs +45 -0
@@ -6000,6 +6000,47 @@ function setExtensionEnabledInSettings(settingsObject, identity, enabled) {
6000
6000
  return setEnablementInMap(settingsObject, "extensions", identity, enabled);
6001
6001
  }
6002
6002
 
6003
+ // ../../packages/agent-framework/src/extensions/resources.ts
6004
+ var ExtensionResourceScope = class {
6005
+ handlers = /* @__PURE__ */ new Set();
6006
+ disposal;
6007
+ closed = false;
6008
+ register(handler) {
6009
+ if (this.closed) throw new Error("Extension resources are already closing.");
6010
+ this.handlers.add(handler);
6011
+ return () => {
6012
+ this.handlers.delete(handler);
6013
+ };
6014
+ }
6015
+ dispose(reason = "shutdown", timeoutMs = 7500) {
6016
+ if (this.disposal) return this.disposal;
6017
+ this.closed = true;
6018
+ const handlers = [...this.handlers].reverse();
6019
+ this.handlers.clear();
6020
+ const controller = new AbortController();
6021
+ this.disposal = (async () => {
6022
+ let timer;
6023
+ try {
6024
+ const results = await Promise.race([
6025
+ Promise.allSettled(handlers.map((handler) => Promise.resolve().then(() => handler(reason, controller.signal)))),
6026
+ new Promise((_, reject) => {
6027
+ timer = setTimeout(() => {
6028
+ controller.abort();
6029
+ reject(new Error(`Extension cleanup exceeded ${timeoutMs}ms.`));
6030
+ }, timeoutMs);
6031
+ })
6032
+ ]);
6033
+ const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
6034
+ if (errors.length) throw new AggregateError(errors, "Extension resource cleanup failed.");
6035
+ } finally {
6036
+ clearTimeout(timer);
6037
+ controller.abort();
6038
+ }
6039
+ })();
6040
+ return this.disposal;
6041
+ }
6042
+ };
6043
+
6003
6044
  // ../../packages/agent-framework/src/interaction.ts
6004
6045
  var InteractionUnavailableError = class extends Error {
6005
6046
  request;
@@ -8832,6 +8873,8 @@ var commaPattern = /\\,/g;
8832
8873
  var periodPattern = /\\\./g;
8833
8874
  var EXPANSION_MAX = 1e5;
8834
8875
  var EXPANSION_MAX_LENGTH = 4e6;
8876
+ var EXPANSION_MAX_DEPTH = 1e3;
8877
+ var EXPANSION_MAX_REWRITES = 1e3;
8835
8878
  function numeric(str) {
8836
8879
  return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
8837
8880
  }
@@ -8841,36 +8884,44 @@ function escapeBraces(str) {
8841
8884
  function unescapeBraces(str) {
8842
8885
  return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
8843
8886
  }
8844
- function parseCommaParts(str) {
8845
- if (!str) {
8846
- return [""];
8887
+ function pushAll(target, items) {
8888
+ for (let i = 0; i < items.length; i++) {
8889
+ target.push(items[i]);
8847
8890
  }
8891
+ }
8892
+ function parseCommaParts(str) {
8848
8893
  const parts = [];
8849
- const m = balanced("{", "}", str);
8850
- if (!m) {
8851
- return str.split(",");
8852
- }
8853
- const { pre, body, post } = m;
8854
- const p = pre.split(",");
8855
- p[p.length - 1] += "{" + body + "}";
8856
- const postParts = parseCommaParts(post);
8857
- if (post.length) {
8858
- ;
8859
- p[p.length - 1] += postParts.shift();
8860
- p.push.apply(p, postParts);
8861
- }
8862
- parts.push.apply(parts, p);
8863
- return parts;
8894
+ let carry = "";
8895
+ for (; ; ) {
8896
+ const m = balanced("{", "}", str);
8897
+ if (!m) {
8898
+ const tail = str.split(",");
8899
+ tail[0] = carry + tail[0];
8900
+ pushAll(parts, tail);
8901
+ return parts;
8902
+ }
8903
+ const { pre, body, post } = m;
8904
+ const p = pre.split(",");
8905
+ p[0] = carry + p[0];
8906
+ p[p.length - 1] += "{" + body + "}";
8907
+ if (!post.length) {
8908
+ pushAll(parts, p);
8909
+ return parts;
8910
+ }
8911
+ carry = p.pop();
8912
+ pushAll(parts, p);
8913
+ str = post;
8914
+ }
8864
8915
  }
8865
8916
  function expand(str, options = {}) {
8866
8917
  if (!str) {
8867
8918
  return [];
8868
8919
  }
8869
- const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options;
8920
+ const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH, maxDepth = EXPANSION_MAX_DEPTH, maxRewrites = EXPANSION_MAX_REWRITES } = options;
8870
8921
  if (str.slice(0, 2) === "{}") {
8871
8922
  str = "\\{\\}" + str.slice(2);
8872
8923
  }
8873
- return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces);
8924
+ return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces);
8874
8925
  }
8875
8926
  function embrace(str) {
8876
8927
  return "{" + str + "}";
@@ -8948,8 +8999,12 @@ function expandSequence(body, isAlphaSequence, max, maxLength) {
8948
8999
  }
8949
9000
  return N;
8950
9001
  }
8951
- function expand_(str, max, maxLength, isTop) {
9002
+ function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
9003
+ if (depth > maxDepth) {
9004
+ return [str];
9005
+ }
8952
9006
  let acc = [""];
9007
+ let rewrites = 0;
8953
9008
  let dropEmpties = false;
8954
9009
  let firstGroup = true;
8955
9010
  for (; ; ) {
@@ -8971,7 +9026,8 @@ function expand_(str, max, maxLength, isTop) {
8971
9026
  const isSequence = isNumericSequence || isAlphaSequence;
8972
9027
  const isOptions = m.body.indexOf(",") >= 0;
8973
9028
  if (!isSequence && !isOptions) {
8974
- if (m.post.match(/,(?!,).*\}/)) {
9029
+ if (rewrites < maxRewrites && m.post.match(/,(?!,).*\}/)) {
9030
+ rewrites++;
8975
9031
  str = m.pre + "{" + m.body + escClose + m.post;
8976
9032
  isTop = true;
8977
9033
  continue;
@@ -8988,7 +9044,7 @@ function expand_(str, max, maxLength, isTop) {
8988
9044
  } else {
8989
9045
  let n = parseCommaParts(m.body);
8990
9046
  if (n.length === 1 && n[0] !== void 0) {
8991
- n = expand_(n[0], max, maxLength, false).map(embrace);
9047
+ n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace);
8992
9048
  if (n.length === 1) {
8993
9049
  acc = combine(acc, pre + n[0], [""], max, maxLength, dropEmpties && !m.post.length);
8994
9050
  if (!m.post.length)
@@ -9006,7 +9062,7 @@ function expand_(str, max, maxLength, isTop) {
9006
9062
  values = [];
9007
9063
  let valuesLength = 0;
9008
9064
  outer: for (let j = 0; j < n.length; j++) {
9009
- const expanded = expand_(n[j], max, maxLength, false);
9065
+ const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false);
9010
9066
  for (let k = 0; k < expanded.length; k++) {
9011
9067
  const v = expanded[k];
9012
9068
  if (dropsEmpties && !v)
@@ -15287,6 +15343,7 @@ export {
15287
15343
  calculateTotalTokens,
15288
15344
  estimateContextTokens,
15289
15345
  getAutoCompactTokenLimit,
15346
+ isCompactSummaryMessage,
15290
15347
  findFirstKeptEntryId,
15291
15348
  createCompactionSummary,
15292
15349
  generateEntryId,
@@ -15300,6 +15357,7 @@ export {
15300
15357
  extractExtensionSettings,
15301
15358
  setEnablementInMap,
15302
15359
  setExtensionEnabledInSettings,
15360
+ ExtensionResourceScope,
15303
15361
  registerInteractionHandler,
15304
15362
  hasInteractionHandler,
15305
15363
  requestInteraction,
@@ -1,5 +1,6 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
+ getBuiltinDir,
3
4
  getConfigDir
4
5
  } from "./chunk-5353DEEC.js";
5
6
  import {
@@ -11,7 +12,7 @@ import {
11
12
  createSharedWebSearchTool,
12
13
  interpretShellExit,
13
14
  requestInteraction
14
- } from "./chunk-PMPD56N2.js";
15
+ } from "./chunk-LU7RKALH.js";
15
16
  import {
16
17
  Type
17
18
  } from "./chunk-XXGYUYXI.js";
@@ -163,6 +164,7 @@ var bashSchema = Type.Object({
163
164
  });
164
165
  var DEFAULT_TIMEOUT_SECONDS = 120;
165
166
  var MAX_GENERIC_TIMEOUT_SECONDS = 120;
167
+ var OUTPUT_DRAIN_TIMEOUT_MS = 1e3;
166
168
  function resolveTimeoutPolicy(requestedTimeout, commandClass) {
167
169
  const requestedSeconds = requestedTimeout ?? DEFAULT_TIMEOUT_SECONDS;
168
170
  if (requestedSeconds > MAX_GENERIC_TIMEOUT_SECONDS && commandClass !== "package_manager" && commandClass !== "test_or_build") {
@@ -192,12 +194,15 @@ function validateBashCommand(command) {
192
194
  throw new Error("Invalid bash command. The command argument must be only a real shell command, not tool-call markup.");
193
195
  }
194
196
  }
195
- function buildEffectiveCommand(command, options) {
197
+ function buildEffectiveCommand(command, options, shell) {
196
198
  const prefix = options?.commandPrefix?.trim();
197
199
  if (!prefix) {
198
200
  return command;
199
201
  }
200
202
  validateBashCommand(prefix);
203
+ if (shell === "powershell") {
204
+ return `& { ${prefix} }; if (-not $?) { exit 1 }; ${command}`;
205
+ }
201
206
  return `${prefix} && ${command}`;
202
207
  }
203
208
  function resolveShell(shell) {
@@ -208,7 +213,8 @@ function resolveShell(shell) {
208
213
  }
209
214
  function buildSpawnCommand(shell, command) {
210
215
  if (shell === "powershell") {
211
- return { file: process.platform === "win32" ? "powershell.exe" : "pwsh", args: ["-NoProfile", "-NonInteractive", "-Command", command], shell: false };
216
+ const utf8Command = `[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding; $OutputEncoding = [Console]::OutputEncoding; ${command}`;
217
+ return { file: process.platform === "win32" ? "powershell.exe" : "pwsh", args: ["-NoProfile", "-NonInteractive", "-Command", utf8Command], shell: false };
212
218
  }
213
219
  if (shell === "cmd") {
214
220
  return { file: "cmd.exe", args: ["/d", "/s", "/c", command], shell: false };
@@ -314,7 +320,11 @@ function finishTempFileStream(stream) {
314
320
  if (!stream || stream.closed) return Promise.resolve();
315
321
  return new Promise((resolve2, reject) => {
316
322
  let done = false;
323
+ const timer = setTimeout(() => {
324
+ stream.destroy(new Error("Timed out flushing shell output."));
325
+ }, OUTPUT_DRAIN_TIMEOUT_MS);
317
326
  const cleanup = () => {
327
+ clearTimeout(timer);
318
328
  stream.off("close", onClose);
319
329
  stream.off("error", onError);
320
330
  };
@@ -347,7 +357,7 @@ function buildBashRecoveryHint(command, output) {
347
357
  if (/\bnpm ERR!|\bnpm error\b/i.test(output) && /\b(?:ECONNRESET|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|fetch failed|socket hang up|registry|proxy)\b/i.test(output)) {
348
358
  return "npm could not reach the registry. Treat this as an environment/network/proxy issue, not a source-code failure; retry npm install/npm ci when network is available or check npm proxy/registry settings.";
349
359
  }
350
- if (/\bnpm\s+run\b/.test(command) && (/(?:^|\n)\s*(?:sh|bash|zsh):\s+[\w@./-]+:\s+command not found\b/i.test(output) || /(?:^|\r?\n)\s*'[^']+'\s+is not recognized as an internal or external command\b/i.test(output))) {
360
+ if (/\bnpm\s+run\b/.test(command) && (/(?:^|\n)\s*(?:sh|bash|zsh):\s+[\w@./-]+:\s+command not found\b/i.test(output) || /(?:^|\r?\n)\s*'[^']+'\s+is not recognized as an internal or external command\b/i.test(output) || /\u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4/.test(output))) {
351
361
  return "This npm script could not find a local executable. Check whether dependencies were installed successfully in cwd, whether node_modules exists, and whether a prior npm install/npm ci failed before treating this as a code failure.";
352
362
  }
353
363
  return void 0;
@@ -396,8 +406,9 @@ function killProcessTree(pid) {
396
406
  try {
397
407
  spawn("taskkill", ["/F", "/T", "/PID", String(pid)], {
398
408
  stdio: "ignore",
399
- detached: true
400
- });
409
+ windowsHide: true
410
+ }).on("error", () => {
411
+ }).unref();
401
412
  } catch {
402
413
  }
403
414
  } else {
@@ -432,7 +443,7 @@ function createBashTool(defaultCwd, options) {
432
443
  execute: async (_toolCallId, { command, timeout, cwd, shell }, signal, onUpdate) => {
433
444
  validateBashCommand(command);
434
445
  const resolvedShell = resolveShell(shell);
435
- const effectiveCommand = buildEffectiveCommand(command, options);
446
+ const effectiveCommand = buildEffectiveCommand(command, options, resolvedShell);
436
447
  const workingDir = normalizeWorkingDirectory(cwd, defaultCwd);
437
448
  validateWorkingDirectory(workingDir);
438
449
  const risk = classifyShellCommand(effectiveCommand, resolvedShell, {
@@ -495,25 +506,42 @@ function createBashTool(defaultCwd, options) {
495
506
  headBytes += prefix.length;
496
507
  };
497
508
  let timedOut = false;
509
+ let processExited = false;
510
+ let exitCode = null;
511
+ let exitSignal = null;
512
+ let drainTimer;
498
513
  const spawnCommand = buildSpawnCommand(resolvedShell, effectiveCommand);
499
514
  const child = (options?.spawnProcess ?? spawn)(spawnCommand.file, spawnCommand.args, {
500
515
  shell: spawnCommand.shell,
501
516
  cwd: workingDir,
502
517
  env: process.env,
503
- detached: process.platform !== "win32"
518
+ detached: process.platform !== "win32",
519
+ windowsHide: true
504
520
  });
521
+ const closePipes = () => {
522
+ child.stdin?.destroy();
523
+ child.stdout?.destroy();
524
+ child.stderr?.destroy();
525
+ };
505
526
  const timeoutId = setTimeout(() => {
527
+ if (settled) return;
506
528
  timedOut = true;
507
- if (child.pid) {
529
+ if (child.pid && !processExited) {
508
530
  killProcessTree(child.pid);
509
531
  }
532
+ closePipes();
533
+ child.unref?.();
534
+ void finishExecution(exitCode, exitSignal, true);
510
535
  }, timeoutMs);
511
536
  const failExecution = (error) => {
512
537
  if (settled) return;
513
538
  settled = true;
514
539
  clearTimeout(timeoutId);
540
+ if (drainTimer) clearTimeout(drainTimer);
515
541
  signal?.removeEventListener("abort", onAbort);
516
- if (child.pid) killProcessTree(child.pid);
542
+ if (child.pid && !processExited) killProcessTree(child.pid);
543
+ closePipes();
544
+ child.unref?.();
517
545
  discardOutputArtifact(tempFilePath, tempFileStream);
518
546
  reject(error);
519
547
  };
@@ -605,11 +633,13 @@ function createBashTool(defaultCwd, options) {
605
633
  chunksBytes -= removed.length;
606
634
  }
607
635
  });
608
- child.on("close", async (code, sig) => {
636
+ const finishExecution = async (code, sig, stdioIncomplete = false) => {
637
+ if (settled) return;
638
+ settled = true;
609
639
  try {
610
640
  clearTimeout(timeoutId);
641
+ if (drainTimer) clearTimeout(drainTimer);
611
642
  signal?.removeEventListener("abort", onAbort);
612
- if (settled) return;
613
643
  const fullBuffer = Buffer.concat(chunks);
614
644
  let fullOutput = fullBuffer.toString("utf-8");
615
645
  if (totalBytes > fullBuffer.length) {
@@ -641,6 +671,7 @@ ${fullOutput}`;
641
671
  exitCode: code,
642
672
  signal: sig?.toString() ?? null,
643
673
  timedOut,
674
+ ...stdioIncomplete ? { stdioIncomplete: true } : {},
644
675
  shell: resolvedShell,
645
676
  commandClass: risk.commandClass,
646
677
  riskWarnings: risk.riskWarnings,
@@ -696,6 +727,9 @@ ${commandNonzeroHint}`;
696
727
  [Command timed out after ${timeoutPolicy.effectiveSeconds} seconds]`;
697
728
  outputText += "\n[Timeout hint: split custom searches or service polls into smaller bounded steps with progress output, inspect partial results/logs, then make a decision. Avoid repeating long waits. Reserve long timeouts for installs, builds, and tests.]";
698
729
  }
730
+ if (stdioIncomplete && !timedOut) {
731
+ outputText += "\n\n[Output capture ended after the command exited because a descendant kept stdio open. Captured output may be incomplete.]";
732
+ }
699
733
  if (timeoutPolicy.capped) {
700
734
  outputText += `
701
735
 
@@ -716,13 +750,26 @@ ${commandNonzeroHint}`;
716
750
  outputText += "\n\n[Repeat hint: this exact command already returned the same result in this session. If it proves the task, stop; otherwise change the command or inspect a different file/range.]";
717
751
  }
718
752
  const content = [{ type: "text", text: outputText }];
719
- settled = true;
720
753
  resolve2({ content, details, isError: outcome.toolFailure });
721
754
  } catch (error) {
722
755
  discardOutputArtifact(tempFilePath, tempFileStream);
723
- settled = true;
724
756
  reject(error);
725
757
  }
758
+ };
759
+ child.on("exit", (code, sig) => {
760
+ processExited = true;
761
+ exitCode = code;
762
+ exitSignal = sig;
763
+ if (settled) return;
764
+ drainTimer = setTimeout(() => {
765
+ closePipes();
766
+ child.unref?.();
767
+ void finishExecution(code, sig, true);
768
+ }, OUTPUT_DRAIN_TIMEOUT_MS);
769
+ });
770
+ child.on("close", (code, sig) => {
771
+ processExited = true;
772
+ void finishExecution(code, sig);
726
773
  });
727
774
  child.on("error", (err) => {
728
775
  failExecution(new Error(`Failed to start bash command in ${workingDir}: ${err.message}. Check that the command is executable and cwd exists.`));
@@ -912,8 +959,9 @@ import * as os from "node:os";
912
959
  import * as path2 from "node:path";
913
960
  var require2 = createRequire(import.meta.url);
914
961
  function resolveAxiCli() {
915
- const packageJson = require2.resolve("chrome-devtools-axi/package.json");
916
- return path2.join(path2.dirname(packageJson), "dist", "bin", "chrome-devtools-axi.js");
962
+ const runtime = path2.join(getBuiltinDir(), "skills", "chrome-devtools-axi", "chrome-devtools-axi-runtime.js");
963
+ if (!fs2.existsSync(runtime)) throw new Error("Pie's packaged browser runtime is missing. Rebuild or reinstall Pie.");
964
+ return runtime;
917
965
  }
918
966
  function resolveMcpScript() {
919
967
  const packageJson = require2.resolve("chrome-devtools-mcp/package.json");