@cydm/pie 4.6.1 → 4.8.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.
@@ -128,6 +128,7 @@ node <baseDir>/computer-use-axi-cli.js act --state S1 --actions '[
128
128
  ]' --expect '{"text":"hello"}'
129
129
  ```
130
130
 
131
+ - **Windows / PowerShell 5.1**: avoid passing nested JSON inline on the command line (PS 5.1 mangles quotes when invoking native executables). Write actions to a UTF-8 file or pipe via stdin using `--actions-file <path|->` and `--expect-file <path|->` (BOM is stripped automatically).
131
132
  - Batch steps only when the second does not need to inspect the first's
132
133
  result; steps run sequentially in one transaction.
133
134
  - Attach `--expect` (JSON condition: `text`/`role`/`value`/`ref`/`scope-ref`/
@@ -4343,6 +4343,7 @@ var init_permissions2 = __esm({
4343
4343
 
4344
4344
  // vendor/computer-use-axi/src/broker-server.ts
4345
4345
  init_test_backend_guard();
4346
+ import { execFile as execFile2 } from "node:child_process";
4346
4347
  import { createHash as createHash4, randomUUID as randomUUID8 } from "node:crypto";
4347
4348
  import { chmodSync as chmodSync2, lstatSync as lstatSync4, readFileSync as readFileSync5, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "node:fs";
4348
4349
  import net3 from "node:net";
@@ -4700,7 +4701,7 @@ function normalizeComputerUseOwner(value) {
4700
4701
 
4701
4702
  // vendor/computer-use-axi/src/broker-protocol.ts
4702
4703
  var BROKER_PROTOCOL_VERSION = 3;
4703
- var BROKER_ENGINE_VERSION = 4;
4704
+ var BROKER_ENGINE_VERSION = 5;
4704
4705
  var BROKER_PACKAGE_VERSION = "0.5.1-pie.1";
4705
4706
  var BROKER_RESULT_CACHE_MAX_ENTRIES = 256;
4706
4707
  var BROKER_REPLAY_LEDGER_MAX_IDS = 65536;
@@ -4770,6 +4771,10 @@ function boundedString(value, label2, maxBytes) {
4770
4771
  if (Buffer.byteLength(value, "utf8") > maxBytes) throw new BrokerProtocolError("invalid_params", `${label2} is too large.`);
4771
4772
  return value;
4772
4773
  }
4774
+ function optionalBoundedString(value, label2, maxBytes) {
4775
+ if (value === void 0) return void 0;
4776
+ return boundedString(value, label2, maxBytes);
4777
+ }
4773
4778
  function boundedNumber(value, label2, min, max) {
4774
4779
  if (typeof value !== "number" || !Number.isFinite(value)) throw new BrokerProtocolError("invalid_params", `${label2} must be a finite number.`);
4775
4780
  if (value < min || value > max) throw new BrokerProtocolError("invalid_params", `${label2} is out of range.`);
@@ -5061,11 +5066,20 @@ function validateHello(value) {
5061
5066
  throw new BrokerProtocolError("protocol_mismatch", `Protocol mismatch: broker ${BROKER_PROTOCOL_VERSION}, client ${String(value.protocolVersion)}.`);
5062
5067
  }
5063
5068
  if (value.buildIdentity !== BROKER_BUILD.identity) throw new BrokerProtocolError("build_mismatch", "Broker engine build identity differs.");
5069
+ let supervisor;
5070
+ if (value.supervisor !== void 0) {
5071
+ assertPlainRecord(value.supervisor, "hello.supervisor");
5072
+ assertKeys(value.supervisor, "hello.supervisor", ["pid", "startTime"]);
5073
+ const pid = Math.trunc(boundedNumber(value.supervisor.pid, "hello.supervisor.pid", 1, Number.MAX_SAFE_INTEGER));
5074
+ const startTime = optionalBoundedString(value.supervisor.startTime, "hello.supervisor.startTime", 256);
5075
+ supervisor = startTime ? { pid, startTime } : { pid };
5076
+ }
5064
5077
  return {
5065
5078
  type: "hello",
5066
5079
  buildIdentity: value.buildIdentity,
5067
5080
  protocolVersion: value.protocolVersion,
5068
- clientVersion: value.clientVersion === void 0 ? void 0 : boundedString(value.clientVersion, "clientVersion", 128)
5081
+ clientVersion: value.clientVersion === void 0 ? void 0 : boundedString(value.clientVersion, "clientVersion", 128),
5082
+ ...supervisor ? { supervisor } : {}
5069
5083
  };
5070
5084
  }
5071
5085
  function encodeFrame(value, maxBytes = BROKER_MAX_FRAME_BYTES) {
@@ -5431,7 +5445,10 @@ function focusedTarget(env) {
5431
5445
  return { focus: { x: Math.floor(env.image.width / 2), y: Math.floor(env.image.height / 2) } };
5432
5446
  }
5433
5447
  function containsEditable(node) {
5434
- if (node.canSetValue || node.role.toLowerCase().includes("text")) return true;
5448
+ const role = node.role.toLowerCase();
5449
+ if (node.isTextInput || node.canSetValue || role === "edit" || role === "textbox" || role.includes("textfield") || role.includes("textarea")) {
5450
+ return true;
5451
+ }
5435
5452
  return node.children.some(containsEditable);
5436
5453
  }
5437
5454
  function wireableInputDescendants(node) {
@@ -5810,10 +5827,14 @@ function damerauLevenshtein(a, b) {
5810
5827
  }
5811
5828
  return matrix[a.length][b.length];
5812
5829
  }
5830
+ var ZERO_WIDTH_RE = /[\u200B-\u200D\u2060\uFEFF]/g;
5831
+ function stripZeroWidth(text) {
5832
+ return text.replace(ZERO_WIDTH_RE, "");
5833
+ }
5813
5834
  function rankedTextMatch(values, text) {
5814
- const query = text.toLowerCase().replace(/\s+/g, " ").trim().slice(0, 256);
5835
+ const query = stripZeroWidth(text).toLowerCase().replace(/\s+/g, " ").trim().slice(0, 256);
5815
5836
  if (!query) return void 0;
5816
- const candidates = values.map((value) => value.toLowerCase().replace(/\s+/g, " ").trim().slice(0, 512)).filter(Boolean);
5837
+ const candidates = values.map((value) => stripZeroWidth(value).toLowerCase().replace(/\s+/g, " ").trim().slice(0, 512)).filter(Boolean);
5817
5838
  if (candidates.some((value) => value === query)) return { reason: "exact", score: 1 };
5818
5839
  if (candidates.some((value) => value.startsWith(query) || value.split(/\W+/).some((token) => token.startsWith(query)))) return { reason: "prefix", score: 0.95 };
5819
5840
  if (candidates.some((value) => value.includes(query))) return { reason: "substring", score: 0.9 };
@@ -5848,13 +5869,13 @@ function searchOutlineRanked(outline, text, role, capability, limit = 12) {
5848
5869
  return { matches: sorted.slice(0, limit).map(({ order: _order, ...match }) => match), totalMatches: strong.length + (useFuzzy ? fuzzy.length : 0) };
5849
5870
  }
5850
5871
  function searchOutline(outline, text, role, action, limit = 50) {
5851
- const query = text?.trim().toLowerCase();
5872
+ const query = text ? stripZeroWidth(text).replace(/\s+/g, " ").trim().toLowerCase() : void 0;
5852
5873
  const roleQuery = role?.trim();
5853
5874
  const actionQuery = action?.trim();
5854
5875
  const matches = [];
5855
5876
  for (const node of outline.nodes) {
5856
5877
  const label2 = outlineNodeLabel(node);
5857
- const haystack = [label2, node.role, node.subrole, node.identifier, node.title, node.description, node.value, ...node.text.map((item) => item.string)].join(" ").toLowerCase();
5878
+ const haystack = stripZeroWidth([label2, node.role, node.subrole, node.identifier, node.title, node.description, node.value, ...node.text.map((item) => item.string)].join(" ")).replace(/\s+/g, " ").toLowerCase();
5858
5879
  if (query && !haystack.includes(query)) continue;
5859
5880
  if (roleQuery && node.role !== roleQuery) continue;
5860
5881
  if (actionQuery && !actionMatches(node, actionQuery)) continue;
@@ -6128,11 +6149,45 @@ var CdpTab = class _CdpTab {
6128
6149
  async typeIntoBackendNode(backendNodeId, text, replace) {
6129
6150
  await this.withBackendNode(backendNodeId, "function(text, replace){ this.scrollIntoView({block:'center', inline:'center'}); this.focus(); if (replace) { if ('value' in this) this.value = ''; else this.textContent = ''; } if ('value' in this) this.value += text; else this.textContent = (this.textContent || '') + text; this.dispatchEvent(new InputEvent('input', {bubbles:true, inputType:'insertText', data:text})); this.dispatchEvent(new Event('change', {bubbles:true})); }", [text, replace]);
6130
6151
  }
6152
+ async wheelAt(x, y, deltaX, deltaY) {
6153
+ await this.send("Input.dispatchMouseEvent", {
6154
+ type: "mouseWheel",
6155
+ x,
6156
+ y,
6157
+ deltaX,
6158
+ deltaY
6159
+ });
6160
+ }
6131
6161
  async scrollBy(deltaX, deltaY, backendNodeId) {
6132
6162
  if (backendNodeId) {
6163
+ try {
6164
+ const resolved = await this.send("DOM.resolveNode", { backendNodeId });
6165
+ const objectId = resolved?.object?.objectId;
6166
+ if (typeof objectId === "string") {
6167
+ const rectRes = await this.send("Runtime.callFunctionOn", {
6168
+ objectId,
6169
+ functionDeclaration: "function(){ this.scrollIntoView({block:'center', inline:'center'}); const r = this.getBoundingClientRect(); const vw = window.innerWidth || 0; const vh = window.innerHeight || 0; const left = Math.max(0, r.left); const top = Math.max(0, r.top); const right = Math.min(vw, r.right); const bottom = Math.min(vh, r.bottom); const w = right - left; const h = bottom - top; return w > 0 && h > 0 ? { x: left + w / 2, y: top + h / 2, w, h } : null; }",
6170
+ returnByValue: true
6171
+ });
6172
+ const pt = !rectRes?.exceptionDetails ? rectRes?.result?.value : void 0;
6173
+ if (pt && typeof pt.x === "number" && typeof pt.y === "number" && Number.isFinite(pt.x) && Number.isFinite(pt.y) && (pt.w ?? 0) > 0 && (pt.h ?? 0) > 0) {
6174
+ await this.wheelAt(pt.x, pt.y, deltaX, deltaY);
6175
+ return;
6176
+ }
6177
+ }
6178
+ } catch {
6179
+ }
6133
6180
  await this.withBackendNode(backendNodeId, "function(dx, dy){ this.scrollIntoView({block:'center', inline:'center'}); this.scrollBy(dx, dy); }", [deltaX, deltaY]);
6134
6181
  return;
6135
6182
  }
6183
+ try {
6184
+ const center = await this.evaluate("({ x: Math.round((window.innerWidth || 800) / 2), y: Math.round((window.innerHeight || 600) / 2) })");
6185
+ if (center && typeof center.x === "number" && typeof center.y === "number" && Number.isFinite(center.x) && Number.isFinite(center.y)) {
6186
+ await this.wheelAt(center.x, center.y, deltaX, deltaY);
6187
+ return;
6188
+ }
6189
+ } catch {
6190
+ }
6136
6191
  await this.send("Runtime.evaluate", { expression: `window.scrollBy(${JSON.stringify(deltaX)}, ${JSON.stringify(deltaY)})` });
6137
6192
  }
6138
6193
  async typeIntoFocused(text) {
@@ -8865,7 +8920,7 @@ function trimOrUndefined(value) {
8865
8920
  return trimmed.length > 0 ? trimmed : void 0;
8866
8921
  }
8867
8922
  function normalizeText2(value) {
8868
- return (value ?? "").trim().toLowerCase();
8923
+ return (value ?? "").replace(/[\u200B-\u200D\u2060\uFEFF]/g, "").trim().toLowerCase();
8869
8924
  }
8870
8925
  function outlineNodeCenter(node) {
8871
8926
  if (!node.rect) {
@@ -10616,10 +10671,38 @@ function isAlive(pid) {
10616
10671
  try {
10617
10672
  process.kill(pid, 0);
10618
10673
  return true;
10619
- } catch {
10620
- return false;
10674
+ } catch (error) {
10675
+ return error?.code !== "ESRCH";
10621
10676
  }
10622
10677
  }
10678
+ function readProcessStartTimeAsync(pid) {
10679
+ if (!Number.isInteger(pid) || pid <= 0) return Promise.resolve(void 0);
10680
+ return new Promise((resolve2) => {
10681
+ const cmd = process.platform === "win32" ? "powershell" : "ps";
10682
+ const args = process.platform === "win32" ? [
10683
+ "-NoProfile",
10684
+ "-NonInteractive",
10685
+ "-Command",
10686
+ `$p = Get-CimInstance Win32_Process -Filter "ProcessId=${pid}"; if ($p) { $p.CreationDate.ToString('o') }`
10687
+ ] : ["-p", String(pid), "-o", "lstart="];
10688
+ const opts = process.platform === "win32" ? { timeout: 3e3, encoding: "utf8", windowsHide: true } : { timeout: 3e3, encoding: "utf8", env: { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC0" } };
10689
+ execFile2(cmd, args, opts, (error, stdout) => {
10690
+ if (error) {
10691
+ resolve2(void 0);
10692
+ return;
10693
+ }
10694
+ const trimmed = (stdout ?? "").trim();
10695
+ resolve2(trimmed || void 0);
10696
+ });
10697
+ });
10698
+ }
10699
+ async function isSupervisorGoneAsync(supervisor) {
10700
+ if (!isAlive(supervisor.pid)) return true;
10701
+ if (!supervisor.startTime) return false;
10702
+ const observed = await readProcessStartTimeAsync(supervisor.pid);
10703
+ if (!observed) return false;
10704
+ return observed !== supervisor.startTime;
10705
+ }
10623
10706
  function acquireBootstrapLock(directory) {
10624
10707
  ensurePrivateDirectory(directory);
10625
10708
  const lockPath = path14.join(directory, "broker.lock");
@@ -10745,6 +10828,32 @@ async function startBroker(options = {}) {
10745
10828
  const replayLedgerLimit = options.replayLedgerLimit ?? BROKER_REPLAY_LEDGER_MAX_IDS;
10746
10829
  const owners = /* @__PURE__ */ new Set();
10747
10830
  const knownStateIds = /* @__PURE__ */ new Set();
10831
+ const supervisors = /* @__PURE__ */ new Map();
10832
+ let hasUnsupervisedCaller = false;
10833
+ const registerSupervisor = (anchor) => {
10834
+ if (!anchor) return;
10835
+ const coarseKey = `${anchor.pid}:`;
10836
+ if (anchor.startTime) {
10837
+ supervisors.delete(coarseKey);
10838
+ supervisors.set(`${anchor.pid}:${anchor.startTime}`, anchor);
10839
+ return;
10840
+ }
10841
+ for (const existing of supervisors.values()) {
10842
+ if (existing.pid === anchor.pid && existing.startTime) return;
10843
+ }
10844
+ supervisors.set(coarseKey, anchor);
10845
+ };
10846
+ {
10847
+ const rawPid = process.env.PIE_SUPERVISOR_PID?.trim();
10848
+ if (rawPid && /^\d+$/.test(rawPid)) {
10849
+ const pid = Number(rawPid);
10850
+ if (Number.isSafeInteger(pid) && pid > 0) {
10851
+ const startTime = process.env.PIE_SUPERVISOR_START_TIME?.trim();
10852
+ registerSupervisor(startTime ? { pid, startTime } : { pid });
10853
+ }
10854
+ }
10855
+ }
10856
+ const unknownGraceMs = options.unknownGraceMs ?? BROKER_DRAIN_MAX_MS;
10748
10857
  let active = 0;
10749
10858
  let queued = 0;
10750
10859
  let lastActivity = Date.now();
@@ -10825,6 +10934,7 @@ async function startBroker(options = {}) {
10825
10934
  if (entry.finished) {
10826
10935
  if (state === "done") {
10827
10936
  entry.state = "done";
10937
+ entry.unknownSince = void 0;
10828
10938
  entry.result = result;
10829
10939
  entry.error = void 0;
10830
10940
  if (result !== void 0) collectStateIds(result, knownStateIds);
@@ -10838,6 +10948,7 @@ async function startBroker(options = {}) {
10838
10948
  }
10839
10949
  entry.finished = true;
10840
10950
  entry.state = state;
10951
+ entry.unknownSince = state === "unknown" ? Date.now() : void 0;
10841
10952
  entry.result = result;
10842
10953
  entry.error = error;
10843
10954
  if (result !== void 0) collectStateIds(result, knownStateIds);
@@ -10871,6 +10982,8 @@ async function startBroker(options = {}) {
10871
10982
  if (currentState === "unknown" || currentState === "error") return;
10872
10983
  const message = error instanceof Error ? error.message : String(error);
10873
10984
  finish(entry, "error", void 0, { code: "engine_error", message, dispatched: entry.dispatched });
10985
+ } finally {
10986
+ entry.settled = true;
10874
10987
  }
10875
10988
  };
10876
10989
  const handleEngineRequest = async (request, socket) => {
@@ -10920,6 +11033,7 @@ async function startBroker(options = {}) {
10920
11033
  state: "queued",
10921
11034
  dispatched: false,
10922
11035
  finished: false,
11036
+ settled: false,
10923
11037
  slotHeld: false,
10924
11038
  controller: new AbortController(),
10925
11039
  fingerprint,
@@ -11018,6 +11132,7 @@ async function startBroker(options = {}) {
11018
11132
  const decoder = new FrameDecoder();
11019
11133
  let helloOk = false;
11020
11134
  let helloRejected = false;
11135
+ let socketSupervisor;
11021
11136
  const drainingConnection = stopping || drainRequested;
11022
11137
  if (drainingConnection) {
11023
11138
  send(socket, {
@@ -11083,8 +11198,9 @@ async function startBroker(options = {}) {
11083
11198
  continue;
11084
11199
  }
11085
11200
  try {
11086
- validateHello(frame);
11201
+ const hello = validateHello(frame);
11087
11202
  helloOk = true;
11203
+ socketSupervisor = hello.supervisor;
11088
11204
  send(socket, {
11089
11205
  type: "hello",
11090
11206
  ok: true,
@@ -11128,7 +11244,12 @@ async function startBroker(options = {}) {
11128
11244
  });
11129
11245
  continue;
11130
11246
  }
11131
- void (request.command === "status" || request.command === "stop" || request.command === "permissions" || request.command === "debug_restart_helper" ? handleControl(request, socket) : handleEngineRequest(request, socket));
11247
+ const isControl = request.command === "status" || request.command === "stop" || request.command === "permissions" || request.command === "debug_restart_helper";
11248
+ if (!isControl) {
11249
+ if (socketSupervisor) registerSupervisor(socketSupervisor);
11250
+ else hasUnsupervisedCaller = true;
11251
+ }
11252
+ void (isControl ? handleControl(request, socket) : handleEngineRequest(request, socket));
11132
11253
  }
11133
11254
  });
11134
11255
  socket.on("close", () => {
@@ -11225,7 +11346,9 @@ async function startBroker(options = {}) {
11225
11346
  }
11226
11347
  }
11227
11348
  const deadline = Date.now() + BROKER_DRAIN_MAX_MS;
11228
- while ((permissionSetupInFlight || [...entries.values()].some((entry) => entry.state === "running" || entry.state === "unknown")) && Date.now() < deadline) {
11349
+ while ((permissionSetupInFlight || [...entries.values()].some(
11350
+ (entry) => entry.state === "running" || entry.state === "unknown" && !entry.settled
11351
+ )) && Date.now() < deadline) {
11229
11352
  await sleep3(50);
11230
11353
  }
11231
11354
  persistManifest();
@@ -11292,13 +11415,43 @@ async function startBroker(options = {}) {
11292
11415
  await shutdown("close");
11293
11416
  }
11294
11417
  };
11418
+ const checkIntervalMs = Math.min(
11419
+ options.supervisorCheckMs ?? 15e3,
11420
+ Math.min(6e4, Math.max(1e3, Math.floor(idleExitMs / 4)))
11421
+ );
11422
+ let lifecycleCheckInFlight = false;
11295
11423
  idleTimer = setInterval(() => {
11296
- if (stopping) return;
11297
- const uncertain = [...entries.values()].some((entry) => entry.state === "running" || entry.state === "unknown" || entry.state === "queued");
11298
- if (uncertain || permissionSetupInFlight) return;
11299
- if (Date.now() - lastActivity < idleExitMs) return;
11300
- void shutdown("idle");
11301
- }, Math.min(6e4, Math.max(1e3, Math.floor(idleExitMs / 4))));
11424
+ if (stopping || lifecycleCheckInFlight) return;
11425
+ lifecycleCheckInFlight = true;
11426
+ void (async () => {
11427
+ try {
11428
+ if (stopping) return;
11429
+ const now = Date.now();
11430
+ const busy = [...entries.values()].some(
11431
+ (entry) => entry.state === "running" || entry.state === "queued" || entry.state === "unknown" && !entry.settled && now - (entry.unknownSince ?? entry.startedAt) < unknownGraceMs
11432
+ );
11433
+ if (busy || permissionSetupInFlight) return;
11434
+ if (!hasUnsupervisedCaller && supervisors.size > 0) {
11435
+ const snapshot = [...supervisors.entries()];
11436
+ for (const [key, anchor] of snapshot) {
11437
+ if (stopping) return;
11438
+ if (await isSupervisorGoneAsync(anchor)) {
11439
+ if (supervisors.get(key) === anchor) supervisors.delete(key);
11440
+ }
11441
+ }
11442
+ if (stopping) return;
11443
+ if (!hasUnsupervisedCaller && supervisors.size === 0) {
11444
+ void shutdown("supervisors_gone");
11445
+ return;
11446
+ }
11447
+ }
11448
+ if (Date.now() - lastActivity < idleExitMs) return;
11449
+ void shutdown("idle");
11450
+ } finally {
11451
+ lifecycleCheckInFlight = false;
11452
+ }
11453
+ })();
11454
+ }, Math.max(50, checkIntervalMs));
11302
11455
  idleTimer.unref?.();
11303
11456
  return statusHandle;
11304
11457
  }
@@ -3,6 +3,7 @@ import { createRequire as __createRequire } from "node:module"; const require =
3
3
 
4
4
  // vendor/computer-use-axi/src/cli.ts
5
5
  import { randomUUID as randomUUID2 } from "node:crypto";
6
+ import { readFileSync as readFileSync2 } from "node:fs";
6
7
  import { pathToFileURL } from "node:url";
7
8
 
8
9
  // vendor/computer-use-axi/src/test-backend-guard.ts
@@ -156,7 +157,7 @@ function computerUseOwnerFromEnv(env = process.env) {
156
157
 
157
158
  // vendor/computer-use-axi/src/broker-protocol.ts
158
159
  var BROKER_PROTOCOL_VERSION = 3;
159
- var BROKER_ENGINE_VERSION = 4;
160
+ var BROKER_ENGINE_VERSION = 5;
160
161
  var BROKER_PACKAGE_VERSION = "0.5.1-pie.1";
161
162
  var BROKER_MAX_FRAME_BYTES = 4 * 1024 * 1024;
162
163
  var BROKER_MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
@@ -237,6 +238,14 @@ function resolveBrokerEndpoint(env = process.env) {
237
238
  }
238
239
 
239
240
  // vendor/computer-use-axi/src/broker-client.ts
241
+ function readSupervisorAnchorFromEnv(env = process.env) {
242
+ const rawPid = env.PIE_SUPERVISOR_PID?.trim();
243
+ if (!rawPid || !/^\d+$/.test(rawPid)) return void 0;
244
+ const pid = Number(rawPid);
245
+ if (!Number.isSafeInteger(pid) || pid <= 0) return void 0;
246
+ const startTime = env.PIE_SUPERVISOR_START_TIME?.trim();
247
+ return startTime ? { pid, startTime } : { pid };
248
+ }
240
249
  var BrokerCallError = class extends Error {
241
250
  constructor(code, message, options = {}) {
242
251
  super(message);
@@ -393,7 +402,14 @@ async function callBroker(options) {
393
402
  const socket = await connectOrSpawn(endpoint, options.spawnIfMissing !== false, spawnState);
394
403
  const frames = new SocketFrames(socket);
395
404
  try {
396
- socket.write(encodeFrame({ type: "hello", protocolVersion: BROKER_PROTOCOL_VERSION, clientVersion: "cli", buildIdentity: BROKER_BUILD.identity }));
405
+ const supervisor = readSupervisorAnchorFromEnv();
406
+ socket.write(encodeFrame({
407
+ type: "hello",
408
+ protocolVersion: BROKER_PROTOCOL_VERSION,
409
+ clientVersion: "cli",
410
+ buildIdentity: BROKER_BUILD.identity,
411
+ ...supervisor ? { supervisor } : {}
412
+ }));
397
413
  const helloFrame = await frames.next(BROKER_HANDSHAKE_TIMEOUT_MS);
398
414
  if (!helloFrame || typeof helloFrame !== "object" || helloFrame.type !== "hello") {
399
415
  throw new BrokerCallError("broker_no_handshake", "The computer-use broker did not answer the protocol handshake.", { exitCode: 1 });
@@ -496,7 +512,8 @@ Commands:
496
512
  read --ref @oN|--eN [--offset BYTES] [--state S]
497
513
  wait --state S (--text T | --role R | --ref @eN) [--until present|absent]
498
514
  [--scope-ref @eN] [--value V] [--timeout-ms MS]
499
- act --state S --actions '<JSON array>' [--expect '<JSON object>']
515
+ act --state S (--actions '<JSON array>' | --actions-file <path|->)
516
+ [--expect '<JSON object>' | --expect-file <path|->]
500
517
  browser launch [--url U]
501
518
  browser navigate --state S --url U
502
519
  browser eval --state S --expr '<JavaScript>'
@@ -562,7 +579,7 @@ function parseArgs(argv) {
562
579
  }
563
580
  if (!booleanFlags.has(key) && value === void 0) {
564
581
  const next = argv[i + 1];
565
- if (next !== void 0 && !next.startsWith("-")) {
582
+ if (next !== void 0 && (next === "-" || !next.startsWith("-"))) {
566
583
  value = next;
567
584
  i += 1;
568
585
  }
@@ -587,13 +604,42 @@ function numericFlag(args, name) {
587
604
  if (!Number.isFinite(parsed)) usageError(`${name} must be a number (got '${value}')`);
588
605
  return parsed;
589
606
  }
590
- function jsonFlag(args, name) {
591
- const value = requiredFlag(args, name);
592
- try {
593
- return JSON.parse(value);
594
- } catch (error) {
595
- usageError(`${name} must be valid JSON (${error.message})`);
607
+ function readJsonOption(args, inlineName, fileName, required, io) {
608
+ const hasInline = args.flags.has(inlineName);
609
+ const hasFile = args.flags.has(fileName);
610
+ if (hasInline && hasFile) {
611
+ usageError(`specify either ${inlineName} or ${fileName}, not both`);
612
+ }
613
+ if (hasInline) {
614
+ const inline = args.flags.get(inlineName) ?? "";
615
+ if (!inline) usageError(`${inlineName} requires a JSON value`);
616
+ try {
617
+ return { value: JSON.parse(inline), usedStdin: false };
618
+ } catch (error) {
619
+ usageError(`${inlineName} must be valid JSON (${error.message})`);
620
+ }
621
+ }
622
+ if (hasFile) {
623
+ const file = args.flags.get(fileName) ?? "";
624
+ if (!file) usageError(`${fileName} requires a file path or '-'`);
625
+ let raw;
626
+ const usedStdin = file === "-";
627
+ try {
628
+ raw = usedStdin ? io.readStdin ? io.readStdin() : readFileSync2(0, "utf8") : io.readFile ? io.readFile(file) : readFileSync2(file, "utf8");
629
+ } catch (error) {
630
+ usageError(`cannot read ${fileName} '${file}' (${error.message})`);
631
+ }
632
+ const cleaned = raw.replace(/^\uFEFF/, "");
633
+ try {
634
+ return { value: JSON.parse(cleaned), usedStdin };
635
+ } catch (error) {
636
+ usageError(`${fileName} '${file}' must contain valid JSON (${error.message})`);
637
+ }
638
+ }
639
+ if (required) {
640
+ usageError(`missing required option ${inlineName} (or ${fileName})`);
596
641
  }
642
+ return { value: void 0, usedStdin: false };
597
643
  }
598
644
  function usageError(message) {
599
645
  process.stderr.write(`computer-use-axi: ${message}
@@ -602,7 +648,7 @@ ${USAGE}
602
648
  `);
603
649
  process.exit(2);
604
650
  }
605
- function buildCommand(args) {
651
+ function buildCommand(args, io = {}) {
606
652
  if (args.command === "browser") {
607
653
  const sub = args.rest[0] ?? usageError("browser requires a subcommand: launch | navigate | eval");
608
654
  if (sub === "launch") return { command: "launch_browser", params: { url: optionalFlag(args, "--url") } };
@@ -674,16 +720,23 @@ function buildCommand(args) {
674
720
  return { command: "wait_for", params };
675
721
  }
676
722
  case "act": {
677
- const actions = jsonFlag(args, "--actions");
723
+ const stateId = requiredFlag(args, "--state");
724
+ if (args.flags.has("--actions") && args.flags.has("--actions-file")) {
725
+ usageError("specify either --actions or --actions-file, not both");
726
+ }
727
+ if (args.flags.has("--expect") && args.flags.has("--expect-file")) {
728
+ usageError("specify either --expect or --expect-file, not both");
729
+ }
730
+ if (args.flags.get("--actions-file") === "-" && args.flags.get("--expect-file") === "-") {
731
+ usageError("cannot read both --actions-file and --expect-file from stdin ('-')");
732
+ }
733
+ const actionsRead = readJsonOption(args, "--actions", "--actions-file", true, io);
734
+ const actions = actionsRead.value;
678
735
  if (!Array.isArray(actions) || actions.length === 0) usageError("--actions must be a non-empty JSON array");
679
- const params = { stateId: requiredFlag(args, "--state"), actions };
680
- const expect = optionalFlag(args, "--expect");
681
- if (expect !== void 0) {
682
- try {
683
- params.expect = JSON.parse(expect);
684
- } catch (error) {
685
- usageError(`--expect must be valid JSON (${error.message})`);
686
- }
736
+ const params = { stateId, actions };
737
+ const expectRead = readJsonOption(args, "--expect", "--expect-file", false, io);
738
+ if (expectRead.value !== void 0) {
739
+ params.expect = expectRead.value;
687
740
  }
688
741
  return { command: "act_ui", params };
689
742
  }
@@ -44,7 +44,7 @@ function inputHeaderLine(userInput) {
44
44
  }
45
45
  function composeForwardBody(sessionId, sessionName, userInput, text, mode = "topic-root") {
46
46
  const lines = [];
47
- if (mode !== "topic-reply") lines.push(`**[Pie] \xB7 ${sessionLabel(sessionId, sessionName)}**`);
47
+ lines.push(`**[Pie] \xB7 ${sessionLabel(sessionId, sessionName)}**`);
48
48
  const input = inputHeaderLine(userInput);
49
49
  if (input) lines.push(input);
50
50
  if (lines.length > 0) lines.push("");
@@ -446,10 +446,10 @@ function resolveConfig(cwd, dir) {
446
446
  for (const file of configPaths(cwd, dir)) {
447
447
  const layer = readLayer(file);
448
448
  if (Object.keys(layer).length) present = true;
449
- const legacy = ["chatId", "receiveId", "openId", "larkCli", "allowUsers", "groupAccess"].some((key) => key in layer);
449
+ const legacy = ["chatId", "receiveId", "openId", "larkCli", "allowUsers", "groupAccess"].some((key2) => key2 in layer);
450
450
  if (legacy && !layer.provider) {
451
451
  const previous = providers.feishu ?? {};
452
- providers.feishu = { ...previous, ...Object.fromEntries(["chatId", "openId", "larkCli", "allowUsers", "groupAccess"].filter((key) => key in layer).map((key) => [key, layer[key]])), ...layer.receiveId && !layer.chatId ? { chatId: layer.receiveId } : {} };
452
+ providers.feishu = { ...previous, ...Object.fromEntries(["chatId", "openId", "larkCli", "allowUsers", "groupAccess"].filter((key2) => key2 in layer).map((key2) => [key2, layer[key2]])), ...layer.receiveId && !layer.chatId ? { chatId: layer.receiveId } : {} };
453
453
  merged.provider = "feishu";
454
454
  }
455
455
  if (isRecord(layer.providers)) {
@@ -558,6 +558,22 @@ function resolveImForwardConfig(cwd, dir) {
558
558
  return { config: { enabled: cfg.enabled, chatId, allowUsers: allowUsers?.length ? allowUsers : void 0, larkCli: typeof raw.larkCli === "string" && raw.larkCli.trim() ? raw.larkCli.trim() : void 0, retryBackoffMs: cfg.retryBackoffMs }, problems: chatId.startsWith("oc_") ? [] : ["im-forward: chatId does not look like a chat id (oc_...)"] };
559
559
  }
560
560
 
561
+ // builtin/extensions/pie-ipc/runtime-registry.ts
562
+ var runtimes = /* @__PURE__ */ new Map();
563
+ function key(root) {
564
+ return root.replace(/[\\/]+$/, "");
565
+ }
566
+ function registerIpcRuntime(root, runtime) {
567
+ const k = key(root);
568
+ runtimes.set(k, runtime);
569
+ return () => {
570
+ if (runtimes.get(k) === runtime) runtimes.delete(k);
571
+ };
572
+ }
573
+ function currentIpcRuntime(root) {
574
+ return runtimes.get(key(root));
575
+ }
576
+
561
577
  // builtin/extensions/pie-ipc/pure.ts
562
578
  import { randomBytes } from "node:crypto";
563
579
  var IPC_PROTOCOL_VERSION = 2;
@@ -714,9 +730,9 @@ var BoundedIdSet = class {
714
730
  if (this.seen.size > this.max) {
715
731
  const drop = Math.max(1, Math.floor(this.max / 4));
716
732
  let dropped = 0;
717
- for (const key of this.seen.keys()) {
733
+ for (const key2 of this.seen.keys()) {
718
734
  if (dropped >= drop) break;
719
- this.seen.delete(key);
735
+ this.seen.delete(key2);
720
736
  dropped += 1;
721
737
  }
722
738
  }
@@ -776,6 +792,8 @@ function parseStatusFile(raw) {
776
792
  };
777
793
  if (typeof record.unattended === "boolean") file.unattended = record.unattended;
778
794
  if (typeof record.isManager === "boolean") file.isManager = record.isManager;
795
+ if (typeof record.sessionControls === "boolean") file.sessionControls = record.sessionControls;
796
+ if (typeof record.workerPeek === "boolean") file.workerPeek = record.workerPeek;
779
797
  if (typeof record.version === "string" && record.version.length <= 64 && !hasControlChars(record.version)) file.version = record.version;
780
798
  if (typeof record.imBinding === "string" && record.imBinding.length <= 512 && !hasControlChars(record.imBinding)) file.imBinding = record.imBinding;
781
799
  if (Array.isArray(record.allowPeers) && record.allowPeers.length <= 1e3 && record.allowPeers.every((id) => typeof id === "string" && (id === "*" || isValidInstanceId(id)))) file.allowPeers = record.allowPeers;
@@ -1392,6 +1410,8 @@ export {
1392
1410
  resolveImForwardConfig,
1393
1411
  addressBookRoot,
1394
1412
  resolveAddress,
1413
+ registerIpcRuntime,
1414
+ currentIpcRuntime,
1395
1415
  IPC_PROTOCOL_VERSION,
1396
1416
  MAX_STATUS_FILE_BYTES,
1397
1417
  MAX_BODY_CHARS,
@@ -1410,7 +1430,6 @@ export {
1410
1430
  foldLifecycleEvent,
1411
1431
  resolveIpcConfig,
1412
1432
  assistantBodyText,
1413
- signEnvelope,
1414
1433
  IpcTransport,
1415
1434
  DISPATCH_PREFIX,
1416
1435
  onImBindingChanged,
@@ -1,10 +1,10 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import {
3
- readProcessCommandLine
4
- } from "./chunk-7RJXKN7N.js";
5
2
  import {
6
3
  getConfigDir
7
4
  } from "./chunk-CBDQJMUI.js";
5
+ import {
6
+ readProcessCommandLine
7
+ } from "./chunk-7RJXKN7N.js";
8
8
  import "./chunk-LZQXQOPJ.js";
9
9
 
10
10
  // src/commands/manager-cli.ts
@@ -123,6 +123,18 @@ ${CRON_SECTION_MARKER}
123
123
  - \u4F60\u6240\u5728\u7684\u65E0\u503C\u5B88\u5BBF\u4E3B\u53EF\u4EE5\u81EA\u5DF1\u7528 cron_manage\uFF08\u65E0\u4EBA\u503C\u5B88\u4E0A\u81EA\u52A8\u6388\u6743\u5E76\u7559\u75D5\uFF0C\u4E0D\u5FC5\u7B49\u4EBA\u786E\u8BA4\uFF09\u3002\u9002\u5408\u201C\u6BCF\u5929 9 \u70B9\u7ED9\u6211\u7B80\u62A5\u201D\u8FD9\u7C7B\u56FA\u5B9A\u8282\u594F\u7684\u4E8B\uFF1B\u4E0D\u9002\u5408\u62FF\u6765\u4EE3\u66FF worker \u5E72\u6D3B\u3002
124
124
  - \u5BBF\u4E3B\u91CD\u542F\u540E\uFF08\u5C24\u5176\u5D29\u6E83/\u65AD\u7535/OOM \u4E4B\u540E\uFF09\u7684\u7B2C\u4E00\u6B21\u5BF9\u8BDD\uFF0C\u5148\u7528 cron_manage list \u770B\u4E00\u773C\uFF1A\u82E5\u6709 blocked \u7684\u4EFB\u52A1\uFF0C\u8BF4\u660E\u4E0A\u6B21\u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8981\u539F\u6837\u544A\u8BC9\u7528\u6237\u5E76\u7B49\u4ED6\u51B3\u5B9A\u662F\u5426 resume\uFF1B**\u4E0D\u8981\u81EA\u4F5C\u4E3B\u5F20 resume\uFF0C\u4E5F\u4E0D\u8981\u5220\u4E86\u91CD\u5EFA**\uFF08\u91CD\u5EFA\u4F1A\u4E22\u6389\u4E0D\u786E\u5B9A\u6267\u884C\u7684\u8BB0\u5F55\uFF09\u3002
125
125
  `;
126
+ var PANEL_ACTIONS_SECTION_MARKER = "## \u9762\u677F\u52A8\u4F5C\uFF08\u811A\u672C\u6309\u94AE\uFF09";
127
+ var PANEL_ACTIONS_SECTION = `
128
+ ${PANEL_ACTIONS_SECTION_MARKER}
129
+
130
+ - \u7FA4\u53CB\u5728 IM \u91CC\u63D0\u7684**\u53EF\u91CD\u590D\u9700\u6C42**\uFF08\u201C\u4EE5\u540E\u6211\u90FD\u60F3\u4E00\u952E XX\u201D\uFF09\uFF0C\u505A\u6210 /panel \u5361\u7247\u4E0A\u7684\u811A\u672C\u6309\u94AE\uFF1A\u6D3E worker \u5F00\u53D1\u811A\u672C\u5230 ~/.pie/panel-actions/ \u5E76\u81EA\u6D4B\u901A\u8FC7\uFF0C\u7136\u540E\u7528 panel_action add \u6CE8\u518C\u6309\u94AE\uFF0C\u6700\u540E\u544A\u8BC9\u7FA4\u53CB\u6309\u94AE\u4F4D\u7F6E\u3002
131
+ - \u6309\u94AE\u70B9\u51FB = \u76F4\u63A5\u8DD1\u811A\u672C\uFF08\u96F6 LLM\u3001\u786E\u5B9A\u6027\u3001\u79D2\u7EA7\uFF09\u3002LLM \u53EA\u53C2\u4E0E\u4E00\u6B21\u6027\u5F00\u53D1\uFF0C\u4E4B\u540E\u6BCF\u6B21\u4F7F\u7528\u90FD\u662F\u7EAF\u6267\u884C\u3002
132
+ - \u811A\u672C\u5951\u7EA6\uFF1A\u6309\u6269\u5C55\u540D\u9009\u89E3\u91CA\u5668\uFF08.mjs/.js\u2192node\uFF0C.sh\u2192bash\uFF0C.py\u2192python3\uFF09\uFF1B\u4E0A\u4E0B\u6587\u8D70\u73AF\u5883\u53D8\u91CF\uFF08PIE_ACTION_TRIGGER_NAME/OPEN_ID\u3001PIE_ACTION_CHAT_ID\u3001PIE_ACTION_PAYLOAD\uFF1Bworker \u8303\u56F4\u7684\u6309\u94AE\u8FD8\u6709 PIE_ACTION_WORKER \u548C PIE_ACTION_WORKER_DIR\uFF09\uFF1B**stdout \u5C31\u662F\u7ED3\u679C**\uFF08markdown\uFF0C\u81EA\u52A8\u53D1\u56DE IM\uFF09\uFF1Bexit 0 \u6210\u529F\uFF0C\u975E\u96F6\u5931\u8D25\u3002
133
+ - scope \u4E09\u6001\uFF1Amanager\uFF08\u4E3B\u5361\uFF0C\u5168\u5C40\u52A8\u4F5C\uFF09\uFF1Bworker\uFF08\u6BCF\u4E2A worker \u5361\u4E0A\u90FD\u6709\uFF0C\u70B9\u5728\u8C01\u7684\u5361\u5C31\u5E26\u8C01\u7684\u4E0A\u4E0B\u6587\u8DD1\u2014\u2014\u201C\u6784\u5EFA\u672C\u9879\u76EE\u201D\u8FD9\u7C7B\u901A\u7528\u6309\u94AE\uFF09\uFF1Bworker:<\u540D\u5B57>\uFF08\u9489\u6B7B\u67D0\u4E2A worker\uFF09\u3002\u62FF\u4E0D\u51C6 scope \u5C31\u5728\u590D\u8FF0\u786E\u8BA4\u65F6\u5FF5\u51FA\u6765\u8BA9\u7FA4\u53CB\u62CD\u677F\u3002
134
+ - \u6CE8\u518C\u524D\u5FC5\u987B\u5411\u63D0\u9700\u6C42\u7684\u7FA4\u53CB**\u590D\u8FF0\u786E\u8BA4**\uFF08\u6309\u94AE\u540D/\u811A\u672C\u5E72\u4EC0\u4E48/scope\uFF09\uFF0C\u786E\u8BA4\u672C\u8EAB\u7559\u75D5\uFF1B\u6CE8\u518C\u65F6\u586B creatorName/creatorOpenId \u8BB0\u4F4F\u662F\u8C01\u63D0\u7684\u3002
135
+ - \u6CBB\u7406\u9760\u8FFD\u8D23\u4E0D\u9760\u95E8\u7981\uFF1A\u6BCF\u6B21\u89E6\u53D1\u7ED3\u679C\u5361\u81EA\u52A8\u7F72\u540D\u201C\u7531\u8C01\u89E6\u53D1\u201D\uFF0C\u5BA1\u8BA1\u5199\u5728 ~/.pie/panel-actions/audit.jsonl\u3002\u6309\u94AE\u88AB\u6EE5\u7528\u65F6 panel_action remove \u5220\u6389\uFF08\u811A\u672C\u6587\u4EF6\u4FDD\u7559\uFF09\u3002
136
+ - \u6309\u94AE\u4E0D\u662F\u4E07\u80FD\u7684\uFF1A\u9700\u8981\u65B0\u80FD\u529B\u7684\u9700\u6C42\u5148\u6D3E worker \u5F00\u53D1\uFF1B\u4E00\u6B21\u6027\u7684\u6D3B\u76F4\u63A5\u6D3E\u6D3B\uFF0C\u4E0D\u8981\u505A\u6309\u94AE\u3002
137
+ `;
126
138
  var SEED_AGENTS_MD = `# Pie Manager (manager)
127
139
 
128
140
  \u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B manager pie\uFF1A\u7ED1\u5B9A IM\uFF08\u5E73\u53F0\u65E0\u5173\uFF09\uFF0C\u65E0\u4EBA\u503C\u5B88\uFF0C\u901A\u8FC7 IM \u4E0E\u7528\u6237\u5BF9\u8BDD\u3002
@@ -148,7 +160,7 @@ var SEED_AGENTS_MD = `# Pie Manager (manager)
148
160
  - \u4FE1\u4EFB\u9012\u8FDB\uFF1A\u540C\u7C7B\u52A8\u4F5C\u88AB\u7528\u6237\u9A8C\u6536\u591A\u6B21\u540E\u53EF\u4EE5\u51CF\u5C11\u8BF7\u793A\uFF0C\u76F4\u63A5\u505A\u6389\u5E76\u6C47\u62A5\uFF1B\u7528\u6237\u7EA0\u6B63\u8FC7\u7684\u4E8B\u4E0D\u8981\u91CD\u72AF\u3002
149
161
  - \u5207\u6A21\u578B\uFF1A\u7528\u6237\u8BF4\u67D0\u4F1A\u8BDD\u989D\u5EA6\u8017\u5C3D/\u60F3\u6362\u6A21\u578B\u65F6\uFF0C\u7528 ipc_control_notify\uFF08to=\u4F1A\u8BDD\u540D\uFF0C control=model.set\uFF0C payload={model: "provider/modelId"}\uFF09\uFF1B\u56DE\u6267\u4F1A\u544A\u8BC9\u4F60\u6210\u529F\u6216\u7ED3\u6784\u5316\u7684\u62D2\u7EDD\u539F\u56E0\u3002\u8FD9\u662F\u9065\u63A7\uFF0C\u4E0D\u4F1A\u5728\u5BF9\u65B9\u4F1A\u8BDD\u91CC\u7559\u4E0B\u4EFB\u4F55\u6D88\u606F\u3002
150
162
  - \u6D88\u606F\u6CA1\u6536\u5230 reaction \u65F6\u4E0D\u8981\u8BA9\u5B83\u60AC\u7740\uFF1A\u540C\u4E00\u4EFD\u6B63\u6587\u518D\u53D1\u4E00\u6B21\u5373\u53EF\uFF08\u4E0D\u5E26\u5F15\u7528\uFF09\uFF0C\u6216\u52A0 \`\u4F1A\u8BDD\u540D:\` \u6307\u5B9A\u76EE\u6807\u3002
151
- ${CRON_SECTION}`;
163
+ ${CRON_SECTION}${PANEL_ACTIONS_SECTION}`;
152
164
  function workspaceDir() {
153
165
  const dir = path2.join(os.homedir(), ".pie", "manager");
154
166
  migrateLegacyWorkspace(dir);
@@ -311,6 +323,7 @@ function seedWorkspace(dir) {
311
323
  return;
312
324
  }
313
325
  if (!current.includes(CRON_SECTION_MARKER)) fs2.appendFileSync(agents, CRON_SECTION);
326
+ if (!current.includes(PANEL_ACTIONS_SECTION_MARKER)) fs2.appendFileSync(agents, PANEL_ACTIONS_SECTION);
314
327
  const v1Marker = "\u4F60\u662F\u7528\u6237\u5728 IM \u4E0A\u7684\u552F\u4E00\u8054\u7EDC\u70B9\u3002\u9ED8\u8BA4\u6D3E\u6D3B";
315
328
  const v2Marker = "\u4F60\u662F\u88AB\u52A8\u8D77\u6B65\u7684";
316
329
  if (current.includes(v1Marker) && !current.includes(v2Marker)) {
@@ -894,7 +907,7 @@ function withStartLock(dir, fn) {
894
907
  });
895
908
  }
896
909
  async function runUpgradeCommand(args) {
897
- const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-LSTOHBUV.js");
910
+ const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-CTU3ISCW.js");
898
911
  const targetIdx = args.indexOf("--target");
899
912
  if (targetIdx >= 0 && typeof args[targetIdx + 1] !== "string") {
900
913
  console.error('--target expects "latest" or an x.y.z version (no value given)');