@cydm/pie 2.2.0 → 2.4.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.
Files changed (27) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +3 -3
  2. package/dist/builtin/extensions/computer-use/index.js +49 -12
  3. package/dist/builtin/extensions/computer-use/package.json +3 -0
  4. package/dist/builtin/extensions/computer-use/prebuilt/macos/arm64/pie-computer-use +0 -0
  5. package/dist/builtin/extensions/computer-use/prebuilt/macos/universal/pie-computer-use.app/Contents/MacOS/pie-computer-use +0 -0
  6. package/dist/builtin/extensions/computer-use/prebuilt/macos/x64/pie-computer-use +0 -0
  7. package/dist/builtin/extensions/computer-use/scripts/build-native.mjs +2 -1
  8. package/dist/builtin/extensions/computer-use/scripts/setup-helper.mjs +2 -2
  9. package/dist/builtin/extensions/computer-use/scripts/test-native-retention.mjs +204 -0
  10. package/dist/builtin/extensions/herdr-agent-state/index.js +272 -0
  11. package/dist/builtin/extensions/herdr-agent-state/package.json +11 -0
  12. package/dist/builtin/extensions/mcp-adapter/index.js +188 -74
  13. package/dist/builtin/extensions/plan-mode/index.js +3 -3
  14. package/dist/builtin/extensions/subagent/index.js +5 -5
  15. package/dist/builtin/extensions/todo/index.js +3 -3
  16. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
  17. package/dist/builtin/skills/chrome-devtools-axi/{cli-F2VCSVL4.js → cli-P4VG6ZZG.js} +48 -8
  18. package/dist/builtin/skills/skill-creator/scripts/pie_runner.mjs +33 -12
  19. package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +5 -7
  20. package/dist/chunks/{chunk-HH2Q2SNX.js → chunk-FKUEIYFQ.js} +8213 -7367
  21. package/dist/chunks/{chunk-G3SE3I2L.js → chunk-XVUV3IM2.js} +112 -40
  22. package/dist/chunks/{chunk-IM43UYVV.js → chunk-YRXXRLMQ.js} +75 -14
  23. package/dist/chunks/{chunk-QJH6YN2W.js → chunk-ZKHMNEXL.js} +1 -1
  24. package/dist/chunks/{src-QSP2OPHU.js → src-SXUQ7OY6.js} +2 -2
  25. package/dist/chunks/{test-stream-CVGWFLSX.js → test-stream-OD3B57AS.js} +1 -1
  26. package/dist/cli.js +1321 -894
  27. package/package.json +2 -2
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import crypto from "node:crypto";
4
- import { spawn } from "node:child_process";
4
+ import { execFile, spawn } from "node:child_process";
5
5
  import fs from "node:fs";
6
- import os from "node:os";
7
6
  import path from "node:path";
8
7
  import { fileURLToPath } from "node:url";
8
+ import { promisify } from "node:util";
9
9
 
10
10
  const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
11
+ const execFileAsync = promisify(execFile);
11
12
 
12
13
  export function findProjectRoot(start = process.cwd()) {
13
14
  return path.resolve(start);
@@ -62,11 +63,30 @@ export function getPieCliPath() {
62
63
  );
63
64
  }
64
65
 
66
+ async function readLastAssistant(sessionId, cwd, deadline) {
67
+ let before;
68
+ do {
69
+ // Skills ship as plain scripts; use the bundled CLI's storage API instead
70
+ // of importing workspace-only packages or depending on its disk layout.
71
+ const { stdout } = await execFileAsync(process.execPath, [
72
+ getPieCliPath(), "sessions", "read", sessionId, "--json", "--fields", "message", "--limit", "1",
73
+ ...(before ? ["--before", before] : []),
74
+ ], { cwd, windowsHide: true, timeout: Math.max(1, deadline - Date.now()), maxBuffer: 16 * 1024 * 1024 });
75
+ const page = JSON.parse(stdout);
76
+ if (!page.ok) throw new Error(page.error?.message || "Could not read session");
77
+ const message = page.data?.events?.at(-1)?.message;
78
+ if (message?.role === "assistant") return message;
79
+ before = page.meta?.hasMoreBefore ? page.meta.nextBefore : null;
80
+ } while (before);
81
+ return null;
82
+ }
83
+
65
84
  export async function runPieJsonPrompt(prompt, { cwd = process.cwd(), timeout = 300_000, sessionId = null, model = null } = {}) {
66
85
  if (model && (typeof model !== "string" || !/^[^/\s]+\/\S+$/.test(model))) {
67
86
  throw new Error("Model must use profile/modelId format.");
68
87
  }
69
88
  return new Promise((resolve, reject) => {
89
+ const deadline = Date.now() + timeout;
70
90
  const id = sessionId || `skill-run-${uuidFragment()}`;
71
91
  const turnId = `skill-turn-${uuidFragment()}`;
72
92
  const args = [getPieCliPath(), "--json-events", "--event-detail", "full", "--session-id", id];
@@ -141,27 +161,28 @@ export async function runPieJsonPrompt(prompt, { cwd = process.cwd(), timeout =
141
161
  child.on("error", (error) => {
142
162
  finish(() => reject(error));
143
163
  });
144
- child.on("close", (code) => {
164
+ child.on("close", async (code) => {
165
+ if (settled) return;
145
166
  if (buffer.trim()) consume(buffer.trim());
146
167
  if (code !== 0 || !turnSettled || !response) {
147
168
  finish(() => reject(new Error(`pie prompt exited ${code} without a settled response\nstderr: ${stderr}`)));
148
169
  return;
149
170
  }
150
- const configuredDir = process.env.PIE_CODING_AGENT_DIR || path.join(os.homedir(), ".pie");
151
- const configDir = configuredDir === "~" ? os.homedir()
152
- : configuredDir.startsWith("~/") ? path.join(os.homedir(), configuredDir.slice(2)) : configuredDir;
153
171
  let actualModel = null;
154
172
  try {
155
- const session = JSON.parse(fs.readFileSync(path.join(configDir, "sessions", `${id}.json`), "utf8"));
156
- const metadata = session.metadata || {};
157
- if (metadata.provider && metadata.modelId) actualModel = `${metadata.provider}/${metadata.modelId}`;
158
- const messages = session.messages || (session.entries || []).map((entry) => entry.message).filter(Boolean);
159
- const lastAssistant = messages.filter((message) => message.role === "assistant").at(-1);
173
+ const lastAssistant = await readLastAssistant(id, cwd, deadline);
174
+ if (lastAssistant?.provider && lastAssistant.model) actualModel = `${lastAssistant.provider}/${lastAssistant.model}`;
175
+ if (response.ok && !lastAssistant) throw new Error("No assistant reply in completed session");
160
176
  if (response.ok && lastAssistant) {
161
177
  response.text = typeof lastAssistant.content === "string" ? lastAssistant.content
162
178
  : (lastAssistant.content || []).filter((block) => block.type === "text").map((block) => block.text).join("");
163
179
  }
164
- } catch {}
180
+ } catch (error) {
181
+ if (response.ok) {
182
+ finish(() => reject(new Error(`Could not read completed Pie session: ${error.message}`)));
183
+ return;
184
+ }
185
+ }
165
186
  if (model && response.ok && actualModel !== model) {
166
187
  finish(() => reject(new Error(`Requested model ${model}, but session reported ${actualModel || "no model"}.`)));
167
188
  return;
@@ -7049,10 +7049,10 @@ async function matchLines(lines, pattern, regex = false, signal) {
7049
7049
  // vendor/tui-use/src/executable.ts
7050
7050
  var import_node_fs = __toESM(require("node:fs"));
7051
7051
  var import_node_path2 = __toESM(require("node:path"));
7052
- function resolveExecutable(file, cwd = process.cwd()) {
7052
+ function resolveExecutable(file, cwd = process.cwd(), env = process.env) {
7053
7053
  if (process.platform !== "win32") return file;
7054
7054
  if (/^node(?:\.exe)?$/i.test(file)) return process.execPath;
7055
- const dirs = file.includes("/") || file.includes("\\") || import_node_path2.default.isAbsolute(file) ? [cwd] : [cwd, ...(process.env.PATH ?? "").split(import_node_path2.default.delimiter)];
7055
+ const dirs = file.includes("/") || file.includes("\\") || import_node_path2.default.isAbsolute(file) ? [cwd] : [cwd, ...(env.PATH ?? "").split(import_node_path2.default.delimiter)];
7056
7056
  const extensions = import_node_path2.default.extname(file) ? [""] : ["", ".exe", ".com"];
7057
7057
  for (const dir of dirs) {
7058
7058
  for (const extension of extensions) {
@@ -7248,7 +7248,8 @@ var Session = class {
7248
7248
  this.startTime = Date.now();
7249
7249
  const cols = options.cols ?? 120;
7250
7250
  const rows = options.rows ?? 30;
7251
- const shell = options.argv ? { file: resolveExecutable(options.argv[0], options.cwd), args: options.argv.slice(1) } : commandShell(command);
7251
+ const env = options.env ?? process.env;
7252
+ const shell = options.argv ? { file: resolveExecutable(options.argv[0], options.cwd, env), args: options.argv.slice(1) } : commandShell(command, process.platform, env);
7252
7253
  this.terminal = new import_headless.Terminal({ cols, rows, allowProposedApi: true, scrollback: 1e4 });
7253
7254
  configureUnicode(this.terminal);
7254
7255
  this._isFullscreen = extractIsFullscreen(this.terminal.buffer);
@@ -7267,10 +7268,7 @@ var Session = class {
7267
7268
  rows,
7268
7269
  useConptyDll: process.platform === "win32",
7269
7270
  cwd: options.cwd ?? process.cwd(),
7270
- // The caller's env, not the daemon starter's: a persistent daemon
7271
- // outlives many projects, and each session must see the environment
7272
- // of the shell that started it (PATH setups, PIE_* overrides, ...).
7273
- env: options.env ?? process.env
7271
+ env
7274
7272
  });
7275
7273
  } catch (error) {
7276
7274
  this.terminal.dispose();