@moxxy/cli 0.12.6 → 0.12.7

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/bin.js CHANGED
@@ -23,13 +23,13 @@ import tty, { ReadStream as ReadStream$1 } from 'tty';
23
23
  import { EventEmitter } from 'events';
24
24
  import { Buffer as Buffer$1 } from 'buffer';
25
25
  import { isFileDiffDisplay as isFileDiffDisplay$1 } from '@moxxy/sdk/tool-display';
26
- import { readFile, mkdir, open, rm, stat, rename as rename$1, unlink, writeFile } from 'fs/promises';
26
+ import { readFile, mkdir, open, rm, stat, rename as rename$1, unlink, writeFile, access, constants as constants$1 } from 'fs/promises';
27
27
  import { spawn, spawnSync } from 'child_process';
28
28
  import { deprecate, inspect, styleText } from 'util';
29
29
  import { ReadableStream as ReadableStream$1 } from 'stream/web';
30
30
  import * as b2 from 'readline';
31
31
  import b2__default, { createInterface } from 'readline';
32
- import net, { isIP } from 'net';
32
+ import net2, { isIP } from 'net';
33
33
  import { AsyncLocalStorage } from 'async_hooks';
34
34
  import { lookup } from 'dns/promises';
35
35
  import { Worker } from 'worker_threads';
@@ -331,20 +331,6 @@ var init_log = __esm({
331
331
  }
332
332
  }
333
333
  }
334
- /**
335
- * Drop every event from the log. Used by `/new` to start a fresh
336
- * session without rebuilding the entire Session object — the
337
- * registries, resolvers, and active provider stay; only the
338
- * conversation context vanishes. Per-event listeners are NOT
339
- * notified (there's no "event removed" event in the schema), but
340
- * {@link onClear} subscribers fire — that's how the persistence
341
- * sidecar truncates its JSONL (so `--resume` can't resurrect wiped
342
- * history) and how the runner broadcasts a reset to attached
343
- * mirrors, in lockstep with the wipe.
344
- *
345
- * Safe to call only when no turn is in flight — callers should abort
346
- * their AbortController and await any pending runTurn() first.
347
- */
348
334
  /**
349
335
  * Start this (empty) log at `seq` instead of 0. A mirror primed by a
350
336
  * PARTIAL attach replay (`replay: 'none'` / `{ tail }`) calls this with the
@@ -363,6 +349,20 @@ var init_log = __esm({
363
349
  this.byType = null;
364
350
  this.byTurnId = null;
365
351
  }
352
+ /**
353
+ * Drop every event from the log. Used by `/new` to start a fresh
354
+ * session without rebuilding the entire Session object — the
355
+ * registries, resolvers, and active provider stay; only the
356
+ * conversation context vanishes. Per-event listeners are NOT
357
+ * notified (there's no "event removed" event in the schema), but
358
+ * {@link onClear} subscribers fire — that's how the persistence
359
+ * sidecar truncates its JSONL (so `--resume` can't resurrect wiped
360
+ * history) and how the runner broadcasts a reset to attached
361
+ * mirrors, in lockstep with the wipe.
362
+ *
363
+ * Safe to call only when no turn is in flight — callers should abort
364
+ * their AbortController and await any pending runTurn() first.
365
+ */
366
366
  clear() {
367
367
  this.events.length = 0;
368
368
  this.byType = null;
@@ -929,6 +929,14 @@ var init_lifecycle = __esm({
929
929
  setPlugins(plugins) {
930
930
  this.entries = plugins.map((plugin4) => ({ plugin: plugin4, hooks: plugin4.hooks ?? {} }));
931
931
  }
932
+ /**
933
+ * Whether any registered plugin declares an `onEvent` hook. Lets the
934
+ * per-event fan-out skip building an AppContext (which clones the whole
935
+ * `process.env`) when no plugin would consume it — the common case.
936
+ */
937
+ hasEventHooks() {
938
+ return this.entries.some((e3) => typeof e3.hooks.onEvent === "function");
939
+ }
932
940
  async dispatchInit(ctx) {
933
941
  for (const e3 of this.entries)
934
942
  await this.safe(e3, "onInit", () => e3.hooks.onInit?.(ctx));
@@ -1018,11 +1026,14 @@ async function discoverPlugins(opts) {
1018
1026
  opts.logger.debug("discovery: failed to list packages in root", { root, err: String(err) });
1019
1027
  continue;
1020
1028
  }
1021
- for (const pkgPath of pkgsDirs) {
1029
+ const uniquePaths = pkgsDirs.filter((pkgPath) => {
1022
1030
  if (seen.has(pkgPath))
1023
- continue;
1031
+ return false;
1024
1032
  seen.add(pkgPath);
1025
- const manifest = await readPluginManifest(pkgPath, opts.logger);
1033
+ return true;
1034
+ });
1035
+ const manifests = await Promise.all(uniquePaths.map((pkgPath) => readPluginManifest(pkgPath, opts.logger)));
1036
+ for (const manifest of manifests) {
1026
1037
  if (manifest)
1027
1038
  out.push(manifest);
1028
1039
  }
@@ -1043,22 +1054,19 @@ async function candidateRoots(cwd2) {
1043
1054
  }
1044
1055
  async function listPackageDirs(root) {
1045
1056
  const entries = await promises.readdir(root, { withFileTypes: true }).catch(() => []);
1046
- const out = [];
1047
- for (const entry of entries) {
1057
+ const perEntry = await Promise.all(entries.map(async (entry) => {
1048
1058
  if (!entry.isDirectory() && !entry.isSymbolicLink())
1049
- continue;
1059
+ return [];
1050
1060
  const full = path3.join(root, entry.name);
1051
1061
  if (entry.name.startsWith("@")) {
1052
1062
  const sub = await promises.readdir(full, { withFileTypes: true }).catch(() => []);
1053
- for (const s2 of sub) {
1054
- if (s2.isDirectory() || s2.isSymbolicLink())
1055
- out.push(path3.join(full, s2.name));
1056
- }
1057
- } else if (entry.name !== ".bin" && entry.name !== ".pnpm") {
1058
- out.push(full);
1063
+ return sub.filter((s2) => s2.isDirectory() || s2.isSymbolicLink()).map((s2) => path3.join(full, s2.name));
1059
1064
  }
1060
- }
1061
- return out;
1065
+ if (entry.name !== ".bin" && entry.name !== ".pnpm")
1066
+ return [full];
1067
+ return [];
1068
+ }));
1069
+ return perEntry.flat();
1062
1070
  }
1063
1071
  async function readPluginManifest(packagePath, logger) {
1064
1072
  const pkgJsonPath = path3.join(packagePath, "package.json");
@@ -2513,6 +2521,12 @@ var init_skills = __esm({
2513
2521
  };
2514
2522
  }
2515
2523
  });
2524
+ function formatZodIssues(error2) {
2525
+ return error2.issues.map((iss) => {
2526
+ const path59 = iss.path.length ? iss.path.join(".") : "(root)";
2527
+ return `${path59}: ${iss.message}`;
2528
+ }).join("; ");
2529
+ }
2516
2530
  function emptyLog() {
2517
2531
  return {
2518
2532
  length: 0,
@@ -2566,11 +2580,7 @@ var init_tools2 = __esm({
2566
2580
  throw new Error(`Unknown tool: ${name}`);
2567
2581
  const parseResult = tool.inputSchema.safeParse(input);
2568
2582
  if (!parseResult.success) {
2569
- const issues = parseResult.error.issues.map((iss) => {
2570
- const path59 = iss.path.length ? iss.path.join(".") : "(root)";
2571
- return `${path59}: ${iss.message}`;
2572
- }).join("; ");
2573
- throw new Error(`Invalid input for ${name}: ${issues}`);
2583
+ throw new Error(`Invalid input for ${name}: ${formatZodIssues(parseResult.error)}`);
2574
2584
  }
2575
2585
  const parsed = parseResult.data;
2576
2586
  const ctx = {
@@ -2585,8 +2595,13 @@ var init_tools2 = __esm({
2585
2595
  ...this.secretResolver ? { getSecret: this.secretResolver } : {}
2586
2596
  };
2587
2597
  const result = await tool.handler(parsed, ctx);
2588
- if (tool.outputSchema)
2589
- return tool.outputSchema.parse(result);
2598
+ if (tool.outputSchema) {
2599
+ const outResult = tool.outputSchema.safeParse(result);
2600
+ if (!outResult.success) {
2601
+ throw new Error(`Tool ${name} produced invalid output: ${formatZodIssues(outResult.error)}`);
2602
+ }
2603
+ return outResult.data;
2604
+ }
2590
2605
  return result;
2591
2606
  }
2592
2607
  };
@@ -2618,6 +2633,9 @@ var init_commands = __esm({
2618
2633
  if (this.commands.has(cmd.name)) {
2619
2634
  throw new Error(`Command already registered: /${cmd.name}`);
2620
2635
  }
2636
+ if (this.aliases.has(cmd.name)) {
2637
+ throw new Error(`Command name already in use as an alias: /${cmd.name}`);
2638
+ }
2621
2639
  this.commands.set(cmd.name, cmd);
2622
2640
  for (const alias of cmd.aliases ?? []) {
2623
2641
  if (this.aliases.has(alias) || this.commands.has(alias)) {
@@ -3401,7 +3419,11 @@ var init_session = __esm({
3401
3419
  ...opts.pluginDiscoveryPaths ? { userPaths: opts.pluginDiscoveryPaths } : {},
3402
3420
  ...opts.isPluginDisabled ? { isDisabled: opts.isPluginDisabled } : {}
3403
3421
  });
3404
- this.log.subscribe((event) => this.dispatcher.dispatchEvent(event, this.appContext()));
3422
+ this.log.subscribe((event) => {
3423
+ if (!this.dispatcher.hasEventHooks())
3424
+ return;
3425
+ return this.dispatcher.dispatchEvent(event, this.appContext());
3426
+ });
3405
3427
  }
3406
3428
  get signal() {
3407
3429
  return this.controller.signal;
@@ -3599,11 +3621,11 @@ async function writeAtomic(file, filePath) {
3599
3621
  await writeFileAtomic(filePath, JSON.stringify(file, null, 2) + "\n");
3600
3622
  }
3601
3623
  async function mergeUsageStats(delta, filePath = usageStatsPath()) {
3624
+ const keys = Object.keys(delta);
3625
+ if (keys.length === 0)
3626
+ return loadUsageStats(filePath);
3602
3627
  return mergeMutex.run(async () => {
3603
- const keys = Object.keys(delta);
3604
3628
  const current = await loadUsageStats(filePath);
3605
- if (keys.length === 0)
3606
- return current;
3607
3629
  const now = (/* @__PURE__ */ new Date()).toISOString();
3608
3630
  const models = { ...current.models };
3609
3631
  for (const key of keys) {
@@ -39146,11 +39168,11 @@ var require_codegen = __commonJS({
39146
39168
  const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
39147
39169
  return `${varKind} ${this.name}${rhs};` + _n;
39148
39170
  }
39149
- optimizeNames(names, constants2) {
39171
+ optimizeNames(names, constants3) {
39150
39172
  if (!names[this.name.str])
39151
39173
  return;
39152
39174
  if (this.rhs)
39153
- this.rhs = optimizeExpr(this.rhs, names, constants2);
39175
+ this.rhs = optimizeExpr(this.rhs, names, constants3);
39154
39176
  return this;
39155
39177
  }
39156
39178
  get names() {
@@ -39167,10 +39189,10 @@ var require_codegen = __commonJS({
39167
39189
  render({ _n }) {
39168
39190
  return `${this.lhs} = ${this.rhs};` + _n;
39169
39191
  }
39170
- optimizeNames(names, constants2) {
39192
+ optimizeNames(names, constants3) {
39171
39193
  if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
39172
39194
  return;
39173
- this.rhs = optimizeExpr(this.rhs, names, constants2);
39195
+ this.rhs = optimizeExpr(this.rhs, names, constants3);
39174
39196
  return this;
39175
39197
  }
39176
39198
  get names() {
@@ -39231,8 +39253,8 @@ var require_codegen = __commonJS({
39231
39253
  optimizeNodes() {
39232
39254
  return `${this.code}` ? this : void 0;
39233
39255
  }
39234
- optimizeNames(names, constants2) {
39235
- this.code = optimizeExpr(this.code, names, constants2);
39256
+ optimizeNames(names, constants3) {
39257
+ this.code = optimizeExpr(this.code, names, constants3);
39236
39258
  return this;
39237
39259
  }
39238
39260
  get names() {
@@ -39261,12 +39283,12 @@ var require_codegen = __commonJS({
39261
39283
  }
39262
39284
  return nodes.length > 0 ? this : void 0;
39263
39285
  }
39264
- optimizeNames(names, constants2) {
39286
+ optimizeNames(names, constants3) {
39265
39287
  const { nodes } = this;
39266
39288
  let i2 = nodes.length;
39267
39289
  while (i2--) {
39268
39290
  const n2 = nodes[i2];
39269
- if (n2.optimizeNames(names, constants2))
39291
+ if (n2.optimizeNames(names, constants3))
39270
39292
  continue;
39271
39293
  subtractNames(names, n2.names);
39272
39294
  nodes.splice(i2, 1);
@@ -39319,12 +39341,12 @@ var require_codegen = __commonJS({
39319
39341
  return void 0;
39320
39342
  return this;
39321
39343
  }
39322
- optimizeNames(names, constants2) {
39344
+ optimizeNames(names, constants3) {
39323
39345
  var _a3;
39324
- this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants2);
39325
- if (!(super.optimizeNames(names, constants2) || this.else))
39346
+ this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants3);
39347
+ if (!(super.optimizeNames(names, constants3) || this.else))
39326
39348
  return;
39327
- this.condition = optimizeExpr(this.condition, names, constants2);
39349
+ this.condition = optimizeExpr(this.condition, names, constants3);
39328
39350
  return this;
39329
39351
  }
39330
39352
  get names() {
@@ -39347,10 +39369,10 @@ var require_codegen = __commonJS({
39347
39369
  render(opts) {
39348
39370
  return `for(${this.iteration})` + super.render(opts);
39349
39371
  }
39350
- optimizeNames(names, constants2) {
39351
- if (!super.optimizeNames(names, constants2))
39372
+ optimizeNames(names, constants3) {
39373
+ if (!super.optimizeNames(names, constants3))
39352
39374
  return;
39353
- this.iteration = optimizeExpr(this.iteration, names, constants2);
39375
+ this.iteration = optimizeExpr(this.iteration, names, constants3);
39354
39376
  return this;
39355
39377
  }
39356
39378
  get names() {
@@ -39386,10 +39408,10 @@ var require_codegen = __commonJS({
39386
39408
  render(opts) {
39387
39409
  return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
39388
39410
  }
39389
- optimizeNames(names, constants2) {
39390
- if (!super.optimizeNames(names, constants2))
39411
+ optimizeNames(names, constants3) {
39412
+ if (!super.optimizeNames(names, constants3))
39391
39413
  return;
39392
- this.iterable = optimizeExpr(this.iterable, names, constants2);
39414
+ this.iterable = optimizeExpr(this.iterable, names, constants3);
39393
39415
  return this;
39394
39416
  }
39395
39417
  get names() {
@@ -39431,11 +39453,11 @@ var require_codegen = __commonJS({
39431
39453
  (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
39432
39454
  return this;
39433
39455
  }
39434
- optimizeNames(names, constants2) {
39456
+ optimizeNames(names, constants3) {
39435
39457
  var _a3, _b;
39436
- super.optimizeNames(names, constants2);
39437
- (_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants2);
39438
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants2);
39458
+ super.optimizeNames(names, constants3);
39459
+ (_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names, constants3);
39460
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants3);
39439
39461
  return this;
39440
39462
  }
39441
39463
  get names() {
@@ -39736,7 +39758,7 @@ var require_codegen = __commonJS({
39736
39758
  function addExprNames(names, from) {
39737
39759
  return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
39738
39760
  }
39739
- function optimizeExpr(expr, names, constants2) {
39761
+ function optimizeExpr(expr, names, constants3) {
39740
39762
  if (expr instanceof code_1.Name)
39741
39763
  return replaceName(expr);
39742
39764
  if (!canOptimize(expr))
@@ -39751,14 +39773,14 @@ var require_codegen = __commonJS({
39751
39773
  return items;
39752
39774
  }, []));
39753
39775
  function replaceName(n2) {
39754
- const c2 = constants2[n2.str];
39776
+ const c2 = constants3[n2.str];
39755
39777
  if (c2 === void 0 || names[n2.str] !== 1)
39756
39778
  return n2;
39757
39779
  delete names[n2.str];
39758
39780
  return c2;
39759
39781
  }
39760
39782
  function canOptimize(e3) {
39761
- return e3 instanceof code_1._Code && e3._items.some((c2) => c2 instanceof code_1.Name && names[c2.str] === 1 && constants2[c2.str] !== void 0);
39783
+ return e3 instanceof code_1._Code && e3._items.some((c2) => c2 instanceof code_1.Name && names[c2.str] === 1 && constants3[c2.str] !== void 0);
39762
39784
  }
39763
39785
  }
39764
39786
  function subtractNames(names, from) {
@@ -49138,13 +49160,14 @@ async function runMcpCallWithFallback(callPromise, signal, toolName) {
49138
49160
  async function wrapMcpServerTools(opts) {
49139
49161
  const prefix = opts.toolNamePrefix ?? defaultToolNamePrefix;
49140
49162
  const list = await opts.client.listTools();
49141
- return list.tools.map((descriptor) => wrapOneTool(descriptor, opts.server.name, opts.client, prefix));
49163
+ const resolveClient = () => Promise.resolve(opts.client);
49164
+ return list.tools.map((descriptor) => wrapOneMcpTool(descriptor, opts.server.name, resolveClient, prefix));
49142
49165
  }
49143
49166
  function wrapMcpServerToolsLazy(opts) {
49144
49167
  const prefix = opts.toolNamePrefix ?? defaultToolNamePrefix;
49145
- return opts.descriptors.map((descriptor) => wrapOneLazyTool(descriptor, opts.server.name, opts.getClient, prefix));
49168
+ return opts.descriptors.map((descriptor) => wrapOneMcpTool(descriptor, opts.server.name, opts.getClient, prefix));
49146
49169
  }
49147
- function wrapOneLazyTool(descriptor, serverName, getClient, prefix) {
49170
+ function wrapOneMcpTool(descriptor, serverName, resolveClient, prefix) {
49148
49171
  const wrappedName = prefix(serverName, descriptor.name);
49149
49172
  return defineTool({
49150
49173
  name: wrappedName,
@@ -49155,23 +49178,7 @@ function wrapOneLazyTool(descriptor, serverName, getClient, prefix) {
49155
49178
  handler: async (input, ctx) => {
49156
49179
  if (ctx.signal.aborted)
49157
49180
  throw new Error("aborted");
49158
- const client = await getClient();
49159
- if (ctx.signal.aborted)
49160
- throw new Error("aborted");
49161
- const result = await runMcpCallWithFallback(client.callTool({ name: descriptor.name, arguments: input }), ctx.signal, wrappedName);
49162
- return renderResult(result.content, result.isError);
49163
- }
49164
- });
49165
- }
49166
- function wrapOneTool(descriptor, serverName, client, prefix) {
49167
- const wrappedName = prefix(serverName, descriptor.name);
49168
- return defineTool({
49169
- name: wrappedName,
49170
- description: descriptor.description ?? `MCP tool ${descriptor.name} on server ${serverName}`,
49171
- inputSchema: z.record(z.string(), z.unknown()),
49172
- inputJsonSchema: descriptor.inputSchema ?? { type: "object" },
49173
- permission: { action: "prompt" },
49174
- handler: async (input, ctx) => {
49181
+ const client = await resolveClient();
49175
49182
  if (ctx.signal.aborted)
49176
49183
  throw new Error("aborted");
49177
49184
  const result = await runMcpCallWithFallback(client.callTool({ name: descriptor.name, arguments: input }), ctx.signal, wrappedName);
@@ -49237,27 +49244,23 @@ async function mutateMcpConfig(fn) {
49237
49244
  });
49238
49245
  }
49239
49246
  async function setServerDisabled(name, disabled) {
49240
- return configMutex.run(async () => {
49241
- const cfg = await readMcpConfig();
49247
+ return mutateMcpConfig((cfg) => {
49242
49248
  const idx = cfg.servers.findIndex((s2) => s2.name === name);
49243
49249
  if (idx < 0)
49244
- return null;
49250
+ return { next: cfg, result: null };
49245
49251
  const updated = { ...cfg.servers[idx], disabled };
49246
49252
  const nextServers = [...cfg.servers];
49247
49253
  nextServers[idx] = updated;
49248
- await writeMcpConfig({ servers: nextServers });
49249
- return updated;
49254
+ return { next: { servers: nextServers }, result: updated };
49250
49255
  });
49251
49256
  }
49252
49257
  async function removeServerFromConfig(name) {
49253
- return configMutex.run(async () => {
49254
- const cfg = await readMcpConfig();
49258
+ return mutateMcpConfig((cfg) => {
49255
49259
  const before = cfg.servers.length;
49256
49260
  const next = cfg.servers.filter((s2) => s2.name !== name);
49257
49261
  if (next.length === before)
49258
- return false;
49259
- await writeMcpConfig({ servers: next });
49260
- return true;
49262
+ return { next: cfg, result: false };
49263
+ return { next: { servers: next }, result: true };
49261
49264
  });
49262
49265
  }
49263
49266
  var configMutex;
@@ -51252,7 +51255,7 @@ var require_react_development = __commonJS({
51252
51255
  var dispatcher = resolveDispatcher();
51253
51256
  return dispatcher.useCallback(callback, deps);
51254
51257
  }
51255
- function useMemo9(create2, deps) {
51258
+ function useMemo8(create2, deps) {
51256
51259
  var dispatcher = resolveDispatcher();
51257
51260
  return dispatcher.useMemo(create2, deps);
51258
51261
  }
@@ -52024,7 +52027,7 @@ var require_react_development = __commonJS({
52024
52027
  exports.useImperativeHandle = useImperativeHandle;
52025
52028
  exports.useInsertionEffect = useInsertionEffect;
52026
52029
  exports.useLayoutEffect = useLayoutEffect2;
52027
- exports.useMemo = useMemo9;
52030
+ exports.useMemo = useMemo8;
52028
52031
  exports.useReducer = useReducer2;
52029
52032
  exports.useRef = useRef9;
52030
52033
  exports.useState = useState17;
@@ -88230,18 +88233,18 @@ var init_ToolsPanel = __esm({
88230
88233
  return (0, import_jsx_runtime26.jsx)(Modal, { title: "Tools", subtitle: "none registered", ...onClose ? { onClose } : {}, children: (0, import_jsx_runtime26.jsx)(Text, { dimColor: true, children: "(no tools registered)" }) });
88231
88234
  }
88232
88235
  const slice = filtered.slice(scroll.visible.start, scroll.visible.end);
88236
+ const termWidth = process.stdout.columns ?? 80;
88237
+ const descWidth = Math.max(20, termWidth - NAME_COL2 - BADGE_COL - 12);
88233
88238
  const subtitle = filtered.length === 0 ? `0 of ${sorted.length} \xB7 no tools in this filter` : `${scroll.cursor + 1} of ${filtered.length} \xB7 ${filtered.length} shown`;
88234
88239
  const hints = "\u2191\u2193 navigate \xB7 PgUp/PgDn fast \xB7 g/G top/bottom";
88235
88240
  return (0, import_jsx_runtime26.jsxs)(Modal, { title: "Tools", subtitle, hints, tabs, activeTabId: activeTab, onTabChange: (id) => setActiveTab(id), ...onClose ? { onClose } : {}, children: [filtered.length === 0 ? (0, import_jsx_runtime26.jsx)(Text, { dimColor: true, children: "(no tools match this filter)" }) : null, scroll.canScrollUp ? (0, import_jsx_runtime26.jsx)(Text, { dimColor: true, children: ` \u2191 ${scroll.offset} more above` }) : null, slice.map((t2, i2) => {
88236
88241
  const absoluteIndex = scroll.visible.start + i2;
88237
88242
  const focused = absoluteIndex === scroll.cursor;
88238
- return (0, import_jsx_runtime26.jsx)(ToolRow, { tool: t2, focused }, t2.name);
88243
+ return (0, import_jsx_runtime26.jsx)(ToolRow, { tool: t2, focused, descWidth }, t2.name);
88239
88244
  }), scroll.canScrollDown ? (0, import_jsx_runtime26.jsx)(Text, { dimColor: true, children: ` \u2193 ${filtered.length - scroll.visible.end} more below` }) : null] });
88240
88245
  };
88241
- ToolRow = ({ tool, focused }) => {
88246
+ ToolRow = ({ tool, focused, descWidth }) => {
88242
88247
  const perm = tool.permission?.action ?? "allow";
88243
- const termWidth = process.stdout.columns ?? 80;
88244
- const descWidth = Math.max(20, termWidth - NAME_COL2 - BADGE_COL - 12);
88245
88248
  const desc = oneLine(tool.description ?? "");
88246
88249
  return (0, import_jsx_runtime26.jsxs)(Box_default, { children: [(0, import_jsx_runtime26.jsx)(Text, { ...focused ? {} : { dimColor: true }, children: focused ? "\u203A " : " " }), (0, import_jsx_runtime26.jsx)(Box_default, { width: NAME_COL2, children: (0, import_jsx_runtime26.jsx)(Text, { bold: true, children: truncate3(tool.name, NAME_COL2 - 2) }) }), (0, import_jsx_runtime26.jsx)(Box_default, { width: BADGE_COL, children: (0, import_jsx_runtime26.jsx)(PermissionBadge, { action: perm }) }), (0, import_jsx_runtime26.jsx)(Box_default, { width: descWidth, children: (0, import_jsx_runtime26.jsx)(Text, { dimColor: true, wrap: "truncate", children: desc }) })] });
88247
88250
  };
@@ -89667,8 +89670,7 @@ var init_PermissionEditor = __esm({
89667
89670
  exit();
89668
89671
  }
89669
89672
  });
89670
- const visible = (0, import_react67.useMemo)(() => rows, [rows]);
89671
- return (0, import_jsx_runtime38.jsxs)(Box_default, { flexDirection: "column", padding: 1, children: [(0, import_jsx_runtime38.jsxs)(Box_default, { marginBottom: 1, children: [(0, import_jsx_runtime38.jsx)(Text, { bold: true, color: "magenta", children: "moxxy perms editor" }), (0, import_jsx_runtime38.jsxs)(Text, { dimColor: true, children: [" (", policyPath2, ")"] })] }), visible.length === 0 ? (0, import_jsx_runtime38.jsx)(Text, { dimColor: true, children: "(no rules \u2014 press `a` to add an allow rule, `D` for deny)" }) : visible.map((row, i2) => {
89673
+ return (0, import_jsx_runtime38.jsxs)(Box_default, { flexDirection: "column", padding: 1, children: [(0, import_jsx_runtime38.jsxs)(Box_default, { marginBottom: 1, children: [(0, import_jsx_runtime38.jsx)(Text, { bold: true, color: "magenta", children: "moxxy perms editor" }), (0, import_jsx_runtime38.jsxs)(Text, { dimColor: true, children: [" (", policyPath2, ")"] })] }), rows.length === 0 ? (0, import_jsx_runtime38.jsx)(Text, { dimColor: true, children: "(no rules \u2014 press `a` to add an allow rule, `D` for deny)" }) : rows.map((row, i2) => {
89672
89674
  const focused = i2 === cursor;
89673
89675
  return (0, import_jsx_runtime38.jsxs)(Box_default, { children: [(0, import_jsx_runtime38.jsx)(Text, { color: focused ? "cyan" : void 0, children: focused ? "\u203A " : " " }), (0, import_jsx_runtime38.jsx)(Text, { color: row.kind === "allow" ? "green" : "red", children: row.kind.padEnd(5) }), (0, import_jsx_runtime38.jsxs)(Text, { children: [" ", row.name] }), row.reason ? (0, import_jsx_runtime38.jsxs)(Text, { dimColor: true, children: [" \u2014 ", row.reason] }) : null] }, `${row.kind}:${row.name}:${i2}`);
89674
89676
  }), (0, import_jsx_runtime38.jsx)(Box_default, { marginTop: 1, children: mode.kind === "add" ? (0, import_jsx_runtime38.jsxs)(Text, { children: ["new ", mode.bucket, " rule: ", (0, import_jsx_runtime38.jsx)(Text, { color: "cyan", children: mode.buffer }), (0, import_jsx_runtime38.jsx)(Text, { dimColor: true, children: " (enter to confirm, esc to cancel)" })] }) : mode.kind === "confirm-delete" ? (0, import_jsx_runtime38.jsxs)(Text, { color: "yellow", children: ["delete `", mode.row.name, "` (", mode.row.kind, ")? [y/N]"] }) : mode.kind === "message" ? (0, import_jsx_runtime38.jsxs)(Text, { color: "green", children: [mode.text, " (press any key)"] }) : (0, import_jsx_runtime38.jsxs)(Text, { dimColor: true, children: ["\u2191/\u2193 move \xB7 space/enter flip \xB7 a add allow \xB7 D add deny \xB7 d delete \xB7 q quit", dirty ? (0, import_jsx_runtime38.jsxs)(Text, { color: "green", children: [" \xB7 ", status] }) : null] }) })] });
@@ -92096,7 +92098,7 @@ var require_crc = __commonJS({
92096
92098
  // ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js
92097
92099
  var require_parser2 = __commonJS({
92098
92100
  "../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/parser.js"(exports, module) {
92099
- var constants2 = require_constants5();
92101
+ var constants3 = require_constants5();
92100
92102
  var CrcCalculator = require_crc();
92101
92103
  var Parser = module.exports = function(options, dependencies) {
92102
92104
  this._options = options;
@@ -92107,12 +92109,12 @@ var require_parser2 = __commonJS({
92107
92109
  this._palette = [];
92108
92110
  this._colorType = 0;
92109
92111
  this._chunks = {};
92110
- this._chunks[constants2.TYPE_IHDR] = this._handleIHDR.bind(this);
92111
- this._chunks[constants2.TYPE_IEND] = this._handleIEND.bind(this);
92112
- this._chunks[constants2.TYPE_IDAT] = this._handleIDAT.bind(this);
92113
- this._chunks[constants2.TYPE_PLTE] = this._handlePLTE.bind(this);
92114
- this._chunks[constants2.TYPE_tRNS] = this._handleTRNS.bind(this);
92115
- this._chunks[constants2.TYPE_gAMA] = this._handleGAMA.bind(this);
92112
+ this._chunks[constants3.TYPE_IHDR] = this._handleIHDR.bind(this);
92113
+ this._chunks[constants3.TYPE_IEND] = this._handleIEND.bind(this);
92114
+ this._chunks[constants3.TYPE_IDAT] = this._handleIDAT.bind(this);
92115
+ this._chunks[constants3.TYPE_PLTE] = this._handlePLTE.bind(this);
92116
+ this._chunks[constants3.TYPE_tRNS] = this._handleTRNS.bind(this);
92117
+ this._chunks[constants3.TYPE_gAMA] = this._handleGAMA.bind(this);
92116
92118
  this.read = dependencies.read;
92117
92119
  this.error = dependencies.error;
92118
92120
  this.metadata = dependencies.metadata;
@@ -92127,10 +92129,10 @@ var require_parser2 = __commonJS({
92127
92129
  };
92128
92130
  };
92129
92131
  Parser.prototype.start = function() {
92130
- this.read(constants2.PNG_SIGNATURE.length, this._parseSignature.bind(this));
92132
+ this.read(constants3.PNG_SIGNATURE.length, this._parseSignature.bind(this));
92131
92133
  };
92132
92134
  Parser.prototype._parseSignature = function(data) {
92133
- let signature = constants2.PNG_SIGNATURE;
92135
+ let signature = constants3.PNG_SIGNATURE;
92134
92136
  for (let i2 = 0; i2 < signature.length; i2++) {
92135
92137
  if (data[i2] !== signature[i2]) {
92136
92138
  this.error(new Error("Invalid file signature"));
@@ -92147,7 +92149,7 @@ var require_parser2 = __commonJS({
92147
92149
  name += String.fromCharCode(data[i2]);
92148
92150
  }
92149
92151
  let ancillary = Boolean(data[4] & 32);
92150
- if (!this._hasIHDR && type !== constants2.TYPE_IHDR) {
92152
+ if (!this._hasIHDR && type !== constants3.TYPE_IHDR) {
92151
92153
  this.error(new Error("Expected IHDR on beggining"));
92152
92154
  return;
92153
92155
  }
@@ -92195,7 +92197,7 @@ var require_parser2 = __commonJS({
92195
92197
  this.error(new Error("Unsupported bit depth " + depth));
92196
92198
  return;
92197
92199
  }
92198
- if (!(colorType in constants2.COLORTYPE_TO_BPP_MAP)) {
92200
+ if (!(colorType in constants3.COLORTYPE_TO_BPP_MAP)) {
92199
92201
  this.error(new Error("Unsupported color type"));
92200
92202
  return;
92201
92203
  }
@@ -92212,16 +92214,16 @@ var require_parser2 = __commonJS({
92212
92214
  return;
92213
92215
  }
92214
92216
  this._colorType = colorType;
92215
- let bpp = constants2.COLORTYPE_TO_BPP_MAP[this._colorType];
92217
+ let bpp = constants3.COLORTYPE_TO_BPP_MAP[this._colorType];
92216
92218
  this._hasIHDR = true;
92217
92219
  this.metadata({
92218
92220
  width,
92219
92221
  height,
92220
92222
  depth,
92221
92223
  interlace: Boolean(interlace),
92222
- palette: Boolean(colorType & constants2.COLORTYPE_PALETTE),
92223
- color: Boolean(colorType & constants2.COLORTYPE_COLOR),
92224
- alpha: Boolean(colorType & constants2.COLORTYPE_ALPHA),
92224
+ palette: Boolean(colorType & constants3.COLORTYPE_PALETTE),
92225
+ color: Boolean(colorType & constants3.COLORTYPE_COLOR),
92226
+ alpha: Boolean(colorType & constants3.COLORTYPE_ALPHA),
92225
92227
  bpp,
92226
92228
  colorType
92227
92229
  });
@@ -92245,7 +92247,7 @@ var require_parser2 = __commonJS({
92245
92247
  };
92246
92248
  Parser.prototype._parseTRNS = function(data) {
92247
92249
  this._crc.write(data);
92248
- if (this._colorType === constants2.COLORTYPE_PALETTE_COLOR) {
92250
+ if (this._colorType === constants3.COLORTYPE_PALETTE_COLOR) {
92249
92251
  if (this._palette.length === 0) {
92250
92252
  this.error(new Error("Transparency chunk must be after palette"));
92251
92253
  return;
@@ -92259,10 +92261,10 @@ var require_parser2 = __commonJS({
92259
92261
  }
92260
92262
  this.palette(this._palette);
92261
92263
  }
92262
- if (this._colorType === constants2.COLORTYPE_GRAYSCALE) {
92264
+ if (this._colorType === constants3.COLORTYPE_GRAYSCALE) {
92263
92265
  this.transColor([data.readUInt16BE(0)]);
92264
92266
  }
92265
- if (this._colorType === constants2.COLORTYPE_COLOR) {
92267
+ if (this._colorType === constants3.COLORTYPE_COLOR) {
92266
92268
  this.transColor([
92267
92269
  data.readUInt16BE(0),
92268
92270
  data.readUInt16BE(2),
@@ -92276,7 +92278,7 @@ var require_parser2 = __commonJS({
92276
92278
  };
92277
92279
  Parser.prototype._parseGAMA = function(data) {
92278
92280
  this._crc.write(data);
92279
- this.gamma(data.readUInt32BE(0) / constants2.GAMMA_DIVISION);
92281
+ this.gamma(data.readUInt32BE(0) / constants3.GAMMA_DIVISION);
92280
92282
  this._handleChunkEnd();
92281
92283
  };
92282
92284
  Parser.prototype._handleIDAT = function(length) {
@@ -92288,7 +92290,7 @@ var require_parser2 = __commonJS({
92288
92290
  };
92289
92291
  Parser.prototype._parseIDAT = function(length, data) {
92290
92292
  this._crc.write(data);
92291
- if (this._colorType === constants2.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
92293
+ if (this._colorType === constants3.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
92292
92294
  throw new Error("Expected palette not found");
92293
92295
  }
92294
92296
  this.inflateData(data);
@@ -92768,9 +92770,9 @@ var require_parser_async = __commonJS({
92768
92770
  // ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js
92769
92771
  var require_bitpacker = __commonJS({
92770
92772
  "../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/bitpacker.js"(exports, module) {
92771
- var constants2 = require_constants5();
92773
+ var constants3 = require_constants5();
92772
92774
  module.exports = function(dataIn, width, height, options) {
92773
- let outHasAlpha = [constants2.COLORTYPE_COLOR_ALPHA, constants2.COLORTYPE_ALPHA].indexOf(
92775
+ let outHasAlpha = [constants3.COLORTYPE_COLOR_ALPHA, constants3.COLORTYPE_ALPHA].indexOf(
92774
92776
  options.colorType
92775
92777
  ) !== -1;
92776
92778
  if (options.colorType === options.inputColorType) {
@@ -92790,11 +92792,11 @@ var require_bitpacker = __commonJS({
92790
92792
  }
92791
92793
  let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
92792
92794
  let maxValue = 255;
92793
- let inBpp = constants2.COLORTYPE_TO_BPP_MAP[options.inputColorType];
92795
+ let inBpp = constants3.COLORTYPE_TO_BPP_MAP[options.inputColorType];
92794
92796
  if (inBpp === 4 && !options.inputHasAlpha) {
92795
92797
  inBpp = 3;
92796
92798
  }
92797
- let outBpp = constants2.COLORTYPE_TO_BPP_MAP[options.colorType];
92799
+ let outBpp = constants3.COLORTYPE_TO_BPP_MAP[options.colorType];
92798
92800
  if (options.bitDepth === 16) {
92799
92801
  maxValue = 65535;
92800
92802
  outBpp *= 2;
@@ -92818,24 +92820,24 @@ var require_bitpacker = __commonJS({
92818
92820
  let blue;
92819
92821
  let alpha = maxValue;
92820
92822
  switch (options.inputColorType) {
92821
- case constants2.COLORTYPE_COLOR_ALPHA:
92823
+ case constants3.COLORTYPE_COLOR_ALPHA:
92822
92824
  alpha = data[inIndex + 3];
92823
92825
  red = data[inIndex];
92824
92826
  green = data[inIndex + 1];
92825
92827
  blue = data[inIndex + 2];
92826
92828
  break;
92827
- case constants2.COLORTYPE_COLOR:
92829
+ case constants3.COLORTYPE_COLOR:
92828
92830
  red = data[inIndex];
92829
92831
  green = data[inIndex + 1];
92830
92832
  blue = data[inIndex + 2];
92831
92833
  break;
92832
- case constants2.COLORTYPE_ALPHA:
92834
+ case constants3.COLORTYPE_ALPHA:
92833
92835
  alpha = data[inIndex + 1];
92834
92836
  red = data[inIndex];
92835
92837
  green = red;
92836
92838
  blue = red;
92837
92839
  break;
92838
- case constants2.COLORTYPE_GRAYSCALE:
92840
+ case constants3.COLORTYPE_GRAYSCALE:
92839
92841
  red = data[inIndex];
92840
92842
  green = red;
92841
92843
  blue = red;
@@ -92868,8 +92870,8 @@ var require_bitpacker = __commonJS({
92868
92870
  for (let x4 = 0; x4 < width; x4++) {
92869
92871
  let rgba = getRGBA();
92870
92872
  switch (options.colorType) {
92871
- case constants2.COLORTYPE_COLOR_ALPHA:
92872
- case constants2.COLORTYPE_COLOR:
92873
+ case constants3.COLORTYPE_COLOR_ALPHA:
92874
+ case constants3.COLORTYPE_COLOR:
92873
92875
  if (options.bitDepth === 8) {
92874
92876
  outData[outIndex] = rgba.red;
92875
92877
  outData[outIndex + 1] = rgba.green;
@@ -92886,8 +92888,8 @@ var require_bitpacker = __commonJS({
92886
92888
  }
92887
92889
  }
92888
92890
  break;
92889
- case constants2.COLORTYPE_ALPHA:
92890
- case constants2.COLORTYPE_GRAYSCALE: {
92891
+ case constants3.COLORTYPE_ALPHA:
92892
+ case constants3.COLORTYPE_GRAYSCALE: {
92891
92893
  let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
92892
92894
  if (options.bitDepth === 8) {
92893
92895
  outData[outIndex] = grayscale;
@@ -93058,7 +93060,7 @@ var require_filter_pack = __commonJS({
93058
93060
  // ../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js
93059
93061
  var require_packer = __commonJS({
93060
93062
  "../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer.js"(exports, module) {
93061
- var constants2 = require_constants5();
93063
+ var constants3 = require_constants5();
93062
93064
  var CrcStream = require_crc();
93063
93065
  var bitPacker = require_bitpacker();
93064
93066
  var filter = require_filter_pack();
@@ -93071,23 +93073,23 @@ var require_packer = __commonJS({
93071
93073
  options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
93072
93074
  options.deflateFactory = options.deflateFactory || zlib2.createDeflate;
93073
93075
  options.bitDepth = options.bitDepth || 8;
93074
- options.colorType = typeof options.colorType === "number" ? options.colorType : constants2.COLORTYPE_COLOR_ALPHA;
93075
- options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants2.COLORTYPE_COLOR_ALPHA;
93076
+ options.colorType = typeof options.colorType === "number" ? options.colorType : constants3.COLORTYPE_COLOR_ALPHA;
93077
+ options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants3.COLORTYPE_COLOR_ALPHA;
93076
93078
  if ([
93077
- constants2.COLORTYPE_GRAYSCALE,
93078
- constants2.COLORTYPE_COLOR,
93079
- constants2.COLORTYPE_COLOR_ALPHA,
93080
- constants2.COLORTYPE_ALPHA
93079
+ constants3.COLORTYPE_GRAYSCALE,
93080
+ constants3.COLORTYPE_COLOR,
93081
+ constants3.COLORTYPE_COLOR_ALPHA,
93082
+ constants3.COLORTYPE_ALPHA
93081
93083
  ].indexOf(options.colorType) === -1) {
93082
93084
  throw new Error(
93083
93085
  "option color type:" + options.colorType + " is not supported at present"
93084
93086
  );
93085
93087
  }
93086
93088
  if ([
93087
- constants2.COLORTYPE_GRAYSCALE,
93088
- constants2.COLORTYPE_COLOR,
93089
- constants2.COLORTYPE_COLOR_ALPHA,
93090
- constants2.COLORTYPE_ALPHA
93089
+ constants3.COLORTYPE_GRAYSCALE,
93090
+ constants3.COLORTYPE_COLOR,
93091
+ constants3.COLORTYPE_COLOR_ALPHA,
93092
+ constants3.COLORTYPE_ALPHA
93091
93093
  ].indexOf(options.inputColorType) === -1) {
93092
93094
  throw new Error(
93093
93095
  "option input color type:" + options.inputColorType + " is not supported at present"
@@ -93111,7 +93113,7 @@ var require_packer = __commonJS({
93111
93113
  };
93112
93114
  Packer.prototype.filterData = function(data, width, height) {
93113
93115
  let packedData = bitPacker(data, width, height, this._options);
93114
- let bpp = constants2.COLORTYPE_TO_BPP_MAP[this._options.colorType];
93116
+ let bpp = constants3.COLORTYPE_TO_BPP_MAP[this._options.colorType];
93115
93117
  let filteredData = filter(packedData, width, height, this._options, bpp);
93116
93118
  return filteredData;
93117
93119
  };
@@ -93131,8 +93133,8 @@ var require_packer = __commonJS({
93131
93133
  };
93132
93134
  Packer.prototype.packGAMA = function(gamma) {
93133
93135
  let buf = Buffer.alloc(4);
93134
- buf.writeUInt32BE(Math.floor(gamma * constants2.GAMMA_DIVISION), 0);
93135
- return this._packChunk(constants2.TYPE_gAMA, buf);
93136
+ buf.writeUInt32BE(Math.floor(gamma * constants3.GAMMA_DIVISION), 0);
93137
+ return this._packChunk(constants3.TYPE_gAMA, buf);
93136
93138
  };
93137
93139
  Packer.prototype.packIHDR = function(width, height) {
93138
93140
  let buf = Buffer.alloc(13);
@@ -93143,13 +93145,13 @@ var require_packer = __commonJS({
93143
93145
  buf[10] = 0;
93144
93146
  buf[11] = 0;
93145
93147
  buf[12] = 0;
93146
- return this._packChunk(constants2.TYPE_IHDR, buf);
93148
+ return this._packChunk(constants3.TYPE_IHDR, buf);
93147
93149
  };
93148
93150
  Packer.prototype.packIDAT = function(data) {
93149
- return this._packChunk(constants2.TYPE_IDAT, data);
93151
+ return this._packChunk(constants3.TYPE_IDAT, data);
93150
93152
  };
93151
93153
  Packer.prototype.packIEND = function() {
93152
- return this._packChunk(constants2.TYPE_IEND, null);
93154
+ return this._packChunk(constants3.TYPE_IEND, null);
93153
93155
  };
93154
93156
  }
93155
93157
  });
@@ -93159,7 +93161,7 @@ var require_packer_async = __commonJS({
93159
93161
  "../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/packer-async.js"(exports, module) {
93160
93162
  var util = __require("util");
93161
93163
  var Stream5 = __require("stream");
93162
- var constants2 = require_constants5();
93164
+ var constants3 = require_constants5();
93163
93165
  var Packer = require_packer();
93164
93166
  var PackerAsync = module.exports = function(opt) {
93165
93167
  Stream5.call(this);
@@ -93170,7 +93172,7 @@ var require_packer_async = __commonJS({
93170
93172
  };
93171
93173
  util.inherits(PackerAsync, Stream5);
93172
93174
  PackerAsync.prototype.pack = function(data, width, height, gamma) {
93173
- this.emit("data", Buffer.from(constants2.PNG_SIGNATURE));
93175
+ this.emit("data", Buffer.from(constants3.PNG_SIGNATURE));
93174
93176
  this.emit("data", this._packer.packIHDR(width, height));
93175
93177
  if (gamma) {
93176
93178
  this.emit("data", this._packer.packGAMA(gamma));
@@ -93486,7 +93488,7 @@ var require_packer_sync = __commonJS({
93486
93488
  if (!zlib2.deflateSync) {
93487
93489
  hasSyncZlib = false;
93488
93490
  }
93489
- var constants2 = require_constants5();
93491
+ var constants3 = require_constants5();
93490
93492
  var Packer = require_packer();
93491
93493
  module.exports = function(metaData, opt) {
93492
93494
  if (!hasSyncZlib) {
@@ -93497,7 +93499,7 @@ var require_packer_sync = __commonJS({
93497
93499
  let options = opt || {};
93498
93500
  let packer = new Packer(options);
93499
93501
  let chunks = [];
93500
- chunks.push(Buffer.from(constants2.PNG_SIGNATURE));
93502
+ chunks.push(Buffer.from(constants3.PNG_SIGNATURE));
93501
93503
  chunks.push(packer.packIHDR(metaData.width, metaData.height));
93502
93504
  if (metaData.gamma) {
93503
93505
  chunks.push(packer.packGAMA(metaData.gamma));
@@ -99716,7 +99718,7 @@ var require_client_h1 = __commonJS({
99716
99718
  kResume,
99717
99719
  kHTTPContext
99718
99720
  } = require_symbols();
99719
- var constants2 = require_constants7();
99721
+ var constants3 = require_constants7();
99720
99722
  var EMPTY_BUF = Buffer.alloc(0);
99721
99723
  var FastBuffer = Buffer[Symbol.species];
99722
99724
  var addListener = util.addListener;
@@ -99788,7 +99790,7 @@ var require_client_h1 = __commonJS({
99788
99790
  constructor(client, socket, { exports: exports2 }) {
99789
99791
  assert(Number.isFinite(client[kMaxHeadersSize]) && client[kMaxHeadersSize] > 0);
99790
99792
  this.llhttp = exports2;
99791
- this.ptr = this.llhttp.llhttp_alloc(constants2.TYPE.RESPONSE);
99793
+ this.ptr = this.llhttp.llhttp_alloc(constants3.TYPE.RESPONSE);
99792
99794
  this.client = client;
99793
99795
  this.socket = socket;
99794
99796
  this.timeout = null;
@@ -99883,11 +99885,11 @@ var require_client_h1 = __commonJS({
99883
99885
  currentBufferRef = null;
99884
99886
  }
99885
99887
  const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr;
99886
- if (ret !== constants2.ERROR.OK) {
99888
+ if (ret !== constants3.ERROR.OK) {
99887
99889
  const body = data.subarray(offset);
99888
- if (ret === constants2.ERROR.PAUSED_UPGRADE) {
99890
+ if (ret === constants3.ERROR.PAUSED_UPGRADE) {
99889
99891
  this.onUpgrade(body);
99890
- } else if (ret === constants2.ERROR.PAUSED) {
99892
+ } else if (ret === constants3.ERROR.PAUSED) {
99891
99893
  this.paused = true;
99892
99894
  socket.unshift(body);
99893
99895
  } else {
@@ -99910,10 +99912,10 @@ var require_client_h1 = __commonJS({
99910
99912
  } finally {
99911
99913
  currentParser = null;
99912
99914
  }
99913
- if (ret === constants2.ERROR.OK) {
99915
+ if (ret === constants3.ERROR.OK) {
99914
99916
  return null;
99915
99917
  }
99916
- if (ret === constants2.ERROR.PAUSED || ret === constants2.ERROR.PAUSED_UPGRADE) {
99918
+ if (ret === constants3.ERROR.PAUSED || ret === constants3.ERROR.PAUSED_UPGRADE) {
99917
99919
  this.paused = true;
99918
99920
  return null;
99919
99921
  }
@@ -99930,7 +99932,7 @@ var require_client_h1 = __commonJS({
99930
99932
  const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0);
99931
99933
  message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")";
99932
99934
  }
99933
- return new HTTPParserError(message, constants2.ERROR[ret], data);
99935
+ return new HTTPParserError(message, constants3.ERROR[ret], data);
99934
99936
  }
99935
99937
  destroy() {
99936
99938
  assert(this.ptr != null);
@@ -100101,7 +100103,7 @@ var require_client_h1 = __commonJS({
100101
100103
  socket[kBlocking] = false;
100102
100104
  client[kResume]();
100103
100105
  }
100104
- return pause ? constants2.ERROR.PAUSED : 0;
100106
+ return pause ? constants3.ERROR.PAUSED : 0;
100105
100107
  }
100106
100108
  onBody(buf) {
100107
100109
  const { client, socket, statusCode, maxResponseSize } = this;
@@ -100123,7 +100125,7 @@ var require_client_h1 = __commonJS({
100123
100125
  }
100124
100126
  this.bytesRead += buf.length;
100125
100127
  if (request.onData(buf) === false) {
100126
- return constants2.ERROR.PAUSED;
100128
+ return constants3.ERROR.PAUSED;
100127
100129
  }
100128
100130
  }
100129
100131
  onMessageComplete() {
@@ -100158,13 +100160,13 @@ var require_client_h1 = __commonJS({
100158
100160
  if (socket[kWriting]) {
100159
100161
  assert(client[kRunning] === 0);
100160
100162
  util.destroy(socket, new InformationalError("reset"));
100161
- return constants2.ERROR.PAUSED;
100163
+ return constants3.ERROR.PAUSED;
100162
100164
  } else if (!shouldKeepAlive) {
100163
100165
  util.destroy(socket, new InformationalError("reset"));
100164
- return constants2.ERROR.PAUSED;
100166
+ return constants3.ERROR.PAUSED;
100165
100167
  } else if (socket[kReset] && client[kRunning] === 0) {
100166
100168
  util.destroy(socket, new InformationalError("reset"));
100167
- return constants2.ERROR.PAUSED;
100169
+ return constants3.ERROR.PAUSED;
100168
100170
  } else if (client[kPipelining] == null || client[kPipelining] === 1) {
100169
100171
  setImmediate(() => client[kResume]());
100170
100172
  } else {
@@ -114632,11 +114634,8 @@ async function resolveValue(value, vault) {
114632
114634
  return Promise.all(value.map((v3) => resolveValue(v3, vault)));
114633
114635
  }
114634
114636
  if (value && typeof value === "object") {
114635
- const out = {};
114636
- for (const [k3, v3] of Object.entries(value)) {
114637
- out[k3] = await resolveValue(v3, vault);
114638
- }
114639
- return out;
114637
+ const pairs = await Promise.all(Object.entries(value).map(async ([k3, v3]) => [k3, await resolveValue(v3, vault)]));
114638
+ return Object.fromEntries(pairs);
114640
114639
  }
114641
114640
  return value;
114642
114641
  }
@@ -115200,6 +115199,15 @@ function rankCosine(entries, vectors, query, limit2) {
115200
115199
  ranked.sort((a2, b3) => b3.score - a2.score);
115201
115200
  return ranked.slice(0, limit2);
115202
115201
  }
115202
+ function countOccurrences(haystack, needle) {
115203
+ let n2 = 0;
115204
+ let i2 = haystack.indexOf(needle);
115205
+ while (i2 !== -1) {
115206
+ n2 += 1;
115207
+ i2 = haystack.indexOf(needle, i2 + needle.length);
115208
+ }
115209
+ return n2;
115210
+ }
115203
115211
  function entryForEmbedding(entry) {
115204
115212
  return [
115205
115213
  entry.frontmatter.name,
@@ -115216,7 +115224,7 @@ function scoreEntry(entry, tokens) {
115216
115224
  for (const t2 of tokens) {
115217
115225
  if (!t2)
115218
115226
  continue;
115219
- const matches = haystack.split(t2).length - 1;
115227
+ const matches = countOccurrences(haystack, t2);
115220
115228
  if (matches > 0) {
115221
115229
  score += matches;
115222
115230
  if (entry.frontmatter.name.toLowerCase().includes(t2))
@@ -126446,6 +126454,10 @@ var OpenAIProvider = class {
126446
126454
  req.signal ? { signal: req.signal } : void 0
126447
126455
  );
126448
126456
  } catch (err) {
126457
+ if (req.signal?.aborted) {
126458
+ yield { type: "error", message: "aborted", retryable: false };
126459
+ return;
126460
+ }
126449
126461
  yield { type: "error", ...toFriendlyError(err, { provider: this.name }) };
126450
126462
  return;
126451
126463
  }
@@ -126510,6 +126522,10 @@ var OpenAIProvider = class {
126510
126522
  }
126511
126523
  }
126512
126524
  } catch (err) {
126525
+ if (req.signal?.aborted) {
126526
+ yield { type: "error", message: "aborted", retryable: false };
126527
+ return;
126528
+ }
126513
126529
  yield { type: "error", ...toFriendlyError(err, { provider: this.name }) };
126514
126530
  return;
126515
126531
  }
@@ -126804,8 +126820,8 @@ async function refreshAccessToken(input, fetchImpl2 = fetch) {
126804
126820
  return parseTokenResponse(json);
126805
126821
  }
126806
126822
  function parseTokenResponse(json) {
126807
- const access = typeof json.access_token === "string" ? json.access_token : null;
126808
- if (!access) {
126823
+ const access2 = typeof json.access_token === "string" ? json.access_token : null;
126824
+ if (!access2) {
126809
126825
  throw new MoxxyError({
126810
126826
  code: "PROVIDER_UNKNOWN_RESPONSE",
126811
126827
  message: `token response missing access_token: ${JSON.stringify(json).slice(0, 200)}`
@@ -126817,7 +126833,7 @@ function parseTokenResponse(json) {
126817
126833
  const tokenType = typeof json.token_type === "string" ? json.token_type : "Bearer";
126818
126834
  const idToken = typeof json.id_token === "string" ? json.id_token : void 0;
126819
126835
  return {
126820
- accessToken: access,
126836
+ accessToken: access2,
126821
126837
  ...refresh !== void 0 ? { refreshToken: refresh } : {},
126822
126838
  ...expiresIn != null ? { expiresAt: Date.now() + expiresIn * 1e3 } : {},
126823
126839
  ...scope !== void 0 ? { scope } : {},
@@ -127078,24 +127094,27 @@ async function storeTokenSet(vault, provider, tokens, meta) {
127078
127094
  async function readStoredCreds(vault, provider) {
127079
127095
  validateProvider(provider);
127080
127096
  const base2 = `oauth/${provider}`;
127081
- const access = await vault.get(`${base2}/access_token`);
127082
- if (!access)
127097
+ const access2 = await vault.get(`${base2}/access_token`);
127098
+ if (!access2)
127083
127099
  return null;
127084
- const refresh = await vault.get(`${base2}/refresh_token`);
127085
- const expiresStr = await vault.get(`${base2}/expires_at`);
127086
- const scope = await vault.get(`${base2}/scope`);
127087
- const tokenType = await vault.get(`${base2}/token_type`) ?? "Bearer";
127088
- const idToken = await vault.get(`${base2}/id_token`);
127089
- const clientId = await vault.get(`${base2}/client_id`);
127090
- const clientSecret = await vault.get(`${base2}/client_secret`);
127091
- const tokenUrl = await vault.get(`${base2}/token_url`);
127092
- const extrasRaw = await vault.get(`${base2}/extras`);
127100
+ const [refresh, expiresStr, scope, tokenTypeRaw, idToken, clientId, clientSecret, tokenUrl, extrasRaw] = await Promise.all([
127101
+ vault.get(`${base2}/refresh_token`),
127102
+ vault.get(`${base2}/expires_at`),
127103
+ vault.get(`${base2}/scope`),
127104
+ vault.get(`${base2}/token_type`),
127105
+ vault.get(`${base2}/id_token`),
127106
+ vault.get(`${base2}/client_id`),
127107
+ vault.get(`${base2}/client_secret`),
127108
+ vault.get(`${base2}/token_url`),
127109
+ vault.get(`${base2}/extras`)
127110
+ ]);
127111
+ const tokenType = tokenTypeRaw ?? "Bearer";
127093
127112
  if (!clientId || !tokenUrl) {
127094
127113
  return null;
127095
127114
  }
127096
127115
  return {
127097
127116
  tokenSet: {
127098
- accessToken: access,
127117
+ accessToken: access2,
127099
127118
  ...refresh !== null ? { refreshToken: refresh } : {},
127100
127119
  ...expiresStr !== null ? { expiresAt: Number.parseInt(expiresStr, 10) } : {},
127101
127120
  ...scope !== null ? { scope } : {},
@@ -127886,6 +127905,17 @@ function buildCodexHeaders(tokens, sessionId) {
127886
127905
  return headers;
127887
127906
  }
127888
127907
 
127908
+ // ../plugin-provider-openai-codex/dist/codex/stream-types.js
127909
+ function parseToolArgs(args) {
127910
+ if (!args)
127911
+ return {};
127912
+ try {
127913
+ return JSON.parse(args);
127914
+ } catch {
127915
+ return { _rawPartial: args };
127916
+ }
127917
+ }
127918
+
127889
127919
  // ../plugin-provider-openai-codex/dist/codex/sse-event-handler.js
127890
127920
  function handleSseEvent(ev, pending2, emitReasoning = false) {
127891
127921
  const type = ev.type ?? "";
@@ -127942,14 +127972,7 @@ function handleSseEvent(ev, pending2, emitReasoning = false) {
127942
127972
  pending2.delete(id);
127943
127973
  if (typeof ev.arguments === "string" && ev.arguments)
127944
127974
  entry.args = ev.arguments;
127945
- let input = {};
127946
- if (entry.args) {
127947
- try {
127948
- input = JSON.parse(entry.args);
127949
- } catch {
127950
- input = { _rawPartial: entry.args };
127951
- }
127952
- }
127975
+ const input = parseToolArgs(entry.args);
127953
127976
  const outId = entry.callId || entry.id;
127954
127977
  const events = [];
127955
127978
  if (!entry.emittedStart && entry.name) {
@@ -128014,12 +128037,13 @@ async function* consumeResponsesSse(body, signal, emitReasoning = false) {
128014
128037
  if (done)
128015
128038
  break;
128016
128039
  buffer += decoder.decode(value, { stream: true });
128017
- buffer = buffer.replace(/\r\n/g, "\n");
128018
- let sep3;
128019
- while ((sep3 = buffer.indexOf("\n\n")) !== -1) {
128020
- const frame = buffer.slice(0, sep3);
128021
- buffer = buffer.slice(sep3 + 2);
128022
- for (const line of frame.split("\n")) {
128040
+ let m3;
128041
+ const sepRe = /\r?\n\r?\n/g;
128042
+ while ((m3 = sepRe.exec(buffer)) !== null) {
128043
+ const frame = buffer.slice(0, m3.index);
128044
+ buffer = buffer.slice(m3.index + m3[0].length);
128045
+ sepRe.lastIndex = 0;
128046
+ for (const line of frame.split(/\r?\n/)) {
128023
128047
  if (!line.startsWith("data:"))
128024
128048
  continue;
128025
128049
  const payload = line.slice(5).trimStart();
@@ -128061,16 +128085,8 @@ async function* consumeResponsesSse(body, signal, emitReasoning = false) {
128061
128085
  return;
128062
128086
  for (const entry of pending2.values()) {
128063
128087
  if (entry.emittedStart) {
128064
- let input = {};
128065
- if (entry.args) {
128066
- try {
128067
- input = JSON.parse(entry.args);
128068
- } catch {
128069
- input = { _rawPartial: entry.args };
128070
- }
128071
- }
128072
128088
  sawToolCall = true;
128073
- yield { type: "tool_use_end", id: entry.callId || entry.id, input };
128089
+ yield { type: "tool_use_end", id: entry.callId || entry.id, input: parseToolArgs(entry.args) };
128074
128090
  }
128075
128091
  }
128076
128092
  if (stopReason === "end_turn" && sawToolCall) {
@@ -129736,11 +129752,11 @@ var SUMMARY_CHARS = 1500;
129736
129752
  var recallTool = defineTool({
129737
129753
  name: "recall",
129738
129754
  description: 'Retrieve earlier content that was elided from context to save tokens. Pass the `callId` shown in an "[output elided \u2014 recall(...)]" stub to get a tool result back, or a `seq` / `turnId` to recall an earlier message or whole turn. Set `summarize: true` for a truncated preview instead of the full text. Only call this when you actually need the detail \u2014 the recent context is always present verbatim.',
129739
- inputSchema: z.object({
129740
- callId: z.string().optional().describe("The callId from an elided tool-result stub."),
129741
- seq: z.number().int().nonnegative().optional().describe("Event sequence number to recall."),
129742
- turnId: z.string().optional().describe("Recall every message from this turn."),
129743
- summarize: z.boolean().optional().describe("Return a truncated preview instead of the full content.")
129755
+ inputSchema: z$1.object({
129756
+ callId: z$1.string().optional().describe("The callId from an elided tool-result stub."),
129757
+ seq: z$1.number().int().nonnegative().optional().describe("Event sequence number to recall."),
129758
+ turnId: z$1.string().optional().describe("Recall every message from this turn."),
129759
+ summarize: z$1.boolean().optional().describe("Return a truncated preview instead of the full content.")
129744
129760
  }),
129745
129761
  permission: { action: "allow" },
129746
129762
  isolation: {
@@ -130432,7 +130448,8 @@ async function* runGoalMode(ctx) {
130432
130448
  const exited = yield* executeToolUses(goalCtx, toolUses, iteration);
130433
130449
  if (exited)
130434
130450
  return;
130435
- const terminal = detectGoalTerminal(ctx.log.slice(), toolUses);
130451
+ const hasGoalTool = toolUses.some((t2) => t2.name === GOAL_COMPLETE_TOOL || t2.name === GOAL_ABANDON_TOOL);
130452
+ const terminal = hasGoalTool ? detectGoalTerminal(ctx.log.slice(), toolUses) : null;
130436
130453
  if (terminal?.kind === "complete") {
130437
130454
  yield await ctx.emit({
130438
130455
  type: "plugin_event",
@@ -132768,7 +132785,10 @@ async function handleVoiceMessage(ctx, state, deps, cb) {
132768
132785
  const fetcher = cb.fetchAudio ?? ((u2) => fetch(u2));
132769
132786
  const response = await fetcher(url2);
132770
132787
  if (!response.ok) {
132771
- deps.logger?.warn("telegram voice download failed", { status: "ok=false" });
132788
+ deps.logger?.warn("telegram voice download failed", {
132789
+ ...response.status !== void 0 ? { status: response.status } : {},
132790
+ ...response.statusText ? { statusText: response.statusText } : {}
132791
+ });
132772
132792
  await ctx.reply("Failed to download the voice note from Telegram.");
132773
132793
  return;
132774
132794
  }
@@ -134377,7 +134397,7 @@ async function driveTurn(session, prompt, runOptions, res) {
134377
134397
  } finally {
134378
134398
  res.off("close", onClose);
134379
134399
  }
134380
- const finalAssistant = events.findLast?.((e3) => e3.type === "assistant_message");
134400
+ const finalAssistant = events.findLast((e3) => e3.type === "assistant_message");
134381
134401
  const assistant = finalAssistant && finalAssistant.type === "assistant_message" ? finalAssistant.content : "";
134382
134402
  return { events, assistant };
134383
134403
  }
@@ -135547,6 +135567,31 @@ var JsonRpcPeer = class {
135547
135567
  this.closeHandlers.length = 0;
135548
135568
  }
135549
135569
  };
135570
+ function platformSocket(name, posixPath, platform2 = process.platform) {
135571
+ if (platform2 === "win32") {
135572
+ return `\\\\.\\pipe\\moxxy-${name.replace(/[^A-Za-z0-9_-]/g, "_")}`;
135573
+ }
135574
+ return posixPath;
135575
+ }
135576
+ function runnerSocketPath() {
135577
+ const override = process.env.MOXXY_RUNNER_SOCKET;
135578
+ if (override)
135579
+ return override;
135580
+ return platformSocket("serve", path3__default.join(os5__default.homedir(), ".moxxy", "serve.sock"));
135581
+ }
135582
+ function isRunnerUp(socketPath = runnerSocketPath()) {
135583
+ return new Promise((resolve12) => {
135584
+ const socket = net2.connect(socketPath);
135585
+ const finish = (up) => {
135586
+ socket.destroy();
135587
+ resolve12(up);
135588
+ };
135589
+ socket.once("connect", () => finish(true));
135590
+ socket.once("error", () => finish(false));
135591
+ });
135592
+ }
135593
+
135594
+ // ../runner/dist/unix-socket.js
135550
135595
  var stderrLogger = {
135551
135596
  warn: (msg, meta) => process.stderr.write(`[moxxy-runner] WARN ${msg} ${meta ? JSON.stringify(meta) : ""}
135552
135597
  `),
@@ -135568,10 +135613,11 @@ var NdjsonTransport = class {
135568
135613
  }
135569
135614
  onData(chunk) {
135570
135615
  this.buffer += chunk;
135571
- let newline = this.buffer.indexOf("\n");
135616
+ let start = 0;
135617
+ let newline = this.buffer.indexOf("\n", start);
135572
135618
  while (newline >= 0) {
135573
- const line = this.buffer.slice(0, newline);
135574
- this.buffer = this.buffer.slice(newline + 1);
135619
+ const line = this.buffer.slice(start, newline);
135620
+ start = newline + 1;
135575
135621
  if (line.trim().length > 0) {
135576
135622
  let parsed;
135577
135623
  try {
@@ -135582,8 +135628,9 @@ var NdjsonTransport = class {
135582
135628
  if (parsed !== void 0)
135583
135629
  this.frameHandler?.(parsed);
135584
135630
  }
135585
- newline = this.buffer.indexOf("\n");
135631
+ newline = this.buffer.indexOf("\n", start);
135586
135632
  }
135633
+ this.buffer = start > 0 ? this.buffer.slice(start) : this.buffer;
135587
135634
  }
135588
135635
  emitClose(err) {
135589
135636
  if (this.closedEmitted)
@@ -135615,7 +135662,7 @@ async function createUnixSocketServer(socketPath, logger = stderrLogger) {
135615
135662
  warnWindowsPipeAclOnce(logger, socketPath);
135616
135663
  }
135617
135664
  const connectionHandlers = [];
135618
- const server = net.createServer((socket) => {
135665
+ const server = net2.createServer((socket) => {
135619
135666
  const transport = new NdjsonTransport(socket);
135620
135667
  for (const handler of connectionHandlers)
135621
135668
  handler(transport);
@@ -135661,7 +135708,7 @@ var DEFAULT_CONNECT_TIMEOUT_MS = 1e4;
135661
135708
  function connectUnixSocket(socketPath, opts = {}) {
135662
135709
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
135663
135710
  return new Promise((resolve12, reject) => {
135664
- const socket = net.connect(socketPath);
135711
+ const socket = net2.connect(socketPath);
135665
135712
  let settled = false;
135666
135713
  const timer = setTimeout(() => {
135667
135714
  if (settled)
@@ -135717,15 +135764,7 @@ function warnWindowsPipeAclOnce(logger, pipePath) {
135717
135764
  async function reclaimStaleSocket(socketPath) {
135718
135765
  if (!fs28__default.existsSync(socketPath))
135719
135766
  return;
135720
- const alive = await new Promise((resolve12) => {
135721
- const probe = net.connect(socketPath);
135722
- const finish = (up) => {
135723
- probe.destroy();
135724
- resolve12(up);
135725
- };
135726
- probe.once("connect", () => finish(true));
135727
- probe.once("error", () => finish(false));
135728
- });
135767
+ const alive = await isRunnerUp(socketPath);
135729
135768
  if (!alive) {
135730
135769
  try {
135731
135770
  fs28__default.unlinkSync(socketPath);
@@ -135733,29 +135772,6 @@ async function reclaimStaleSocket(socketPath) {
135733
135772
  }
135734
135773
  }
135735
135774
  }
135736
- function platformSocket(name, posixPath, platform2 = process.platform) {
135737
- if (platform2 === "win32") {
135738
- return `\\\\.\\pipe\\moxxy-${name.replace(/[^A-Za-z0-9_-]/g, "_")}`;
135739
- }
135740
- return posixPath;
135741
- }
135742
- function runnerSocketPath() {
135743
- const override = process.env.MOXXY_RUNNER_SOCKET;
135744
- if (override)
135745
- return override;
135746
- return platformSocket("serve", path3__default.join(os5__default.homedir(), ".moxxy", "serve.sock"));
135747
- }
135748
- function isRunnerUp(socketPath = runnerSocketPath()) {
135749
- return new Promise((resolve12) => {
135750
- const socket = net.connect(socketPath);
135751
- const finish = (up) => {
135752
- socket.destroy();
135753
- resolve12(up);
135754
- };
135755
- socket.once("connect", () => finish(true));
135756
- socket.once("error", () => finish(false));
135757
- });
135758
- }
135759
135775
 
135760
135776
  // ../runner/dist/server.js
135761
135777
  init_dist();
@@ -139028,8 +139044,12 @@ function buildTerminalSurface() {
139028
139044
  const proc = await getSharedTerminal(ctx.cwd);
139029
139045
  const dataSubs = /* @__PURE__ */ new Set();
139030
139046
  const emit2 = (payload) => {
139031
- for (const cb of dataSubs)
139032
- cb(payload);
139047
+ for (const cb of dataSubs) {
139048
+ try {
139049
+ cb(payload);
139050
+ } catch {
139051
+ }
139052
+ }
139033
139053
  };
139034
139054
  const unsubData = proc.onData((data) => emit2({ type: "data", data }));
139035
139055
  const unsubExit = proc.onExit((code) => emit2({ type: "exit", code }));
@@ -140356,21 +140376,7 @@ var keyTool = defineTool({
140356
140376
  async handler({ key, modifiers }, ctx) {
140357
140377
  ensureDarwin("computer_key");
140358
140378
  const mods = modifiers ?? [];
140359
- const usingClause = mods.length > 0 ? ` using {${mods.map(modifierClause).join(", ")}}` : "";
140360
- let script;
140361
- const lower2 = key.toLowerCase();
140362
- if (lower2 in KEY_CODES) {
140363
- script = `tell application "System Events" to key code ${KEY_CODES[lower2]}${usingClause}`;
140364
- } else if (key.length === 1) {
140365
- const literal3 = `"${key.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
140366
- script = `tell application "System Events" to keystroke ${literal3}${usingClause}`;
140367
- } else {
140368
- throw new MoxxyError({
140369
- code: "TOOL_ERROR",
140370
- message: `unknown key "${key}". Use a single character or one of: ${Object.keys(KEY_CODES).join(", ")}.`,
140371
- context: { tool: "computer_key", key }
140372
- });
140373
- }
140379
+ const script = buildKeyScript(key, mods);
140374
140380
  const proc = await runProcess("osascript", ["-e", script], {
140375
140381
  ...ctx.signal ? { signal: ctx.signal } : {},
140376
140382
  timeoutMs: 1e4
@@ -140385,6 +140391,22 @@ var keyTool = defineTool({
140385
140391
  return { ok: true, key, modifiers: mods };
140386
140392
  }
140387
140393
  });
140394
+ function buildKeyScript(key, modifiers) {
140395
+ const usingClause = modifiers.length > 0 ? ` using {${modifiers.map(modifierClause).join(", ")}}` : "";
140396
+ const lower2 = key.toLowerCase();
140397
+ if (lower2 in KEY_CODES) {
140398
+ return `tell application "System Events" to key code ${KEY_CODES[lower2]}${usingClause}`;
140399
+ }
140400
+ if (key.length === 1) {
140401
+ const literal3 = `"${key.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
140402
+ return `tell application "System Events" to keystroke ${literal3}${usingClause}`;
140403
+ }
140404
+ throw new MoxxyError({
140405
+ code: "TOOL_ERROR",
140406
+ message: `unknown key "${key}". Use a single character or one of: ${Object.keys(KEY_CODES).join(", ")}.`,
140407
+ context: { tool: "computer_key", key }
140408
+ });
140409
+ }
140388
140410
  function modifierClause(m3) {
140389
140411
  switch (m3) {
140390
140412
  case "cmd":
@@ -140687,6 +140709,24 @@ function nextFireTime(expr, after, timeZone) {
140687
140709
  }
140688
140710
  return null;
140689
140711
  }
140712
+ var formatterCache = /* @__PURE__ */ new Map();
140713
+ function formatterFor(timeZone) {
140714
+ let fmt2 = formatterCache.get(timeZone);
140715
+ if (!fmt2) {
140716
+ fmt2 = new Intl.DateTimeFormat("en-US", {
140717
+ timeZone,
140718
+ year: "numeric",
140719
+ month: "2-digit",
140720
+ day: "2-digit",
140721
+ weekday: "short",
140722
+ hour: "2-digit",
140723
+ minute: "2-digit",
140724
+ hour12: false
140725
+ });
140726
+ formatterCache.set(timeZone, fmt2);
140727
+ }
140728
+ return fmt2;
140729
+ }
140690
140730
  function decomposeInZone(d2, timeZone) {
140691
140731
  if (!timeZone || timeZone === "local") {
140692
140732
  return {
@@ -140698,16 +140738,7 @@ function decomposeInZone(d2, timeZone) {
140698
140738
  minute: d2.getMinutes()
140699
140739
  };
140700
140740
  }
140701
- const fmt2 = new Intl.DateTimeFormat("en-US", {
140702
- timeZone,
140703
- year: "numeric",
140704
- month: "2-digit",
140705
- day: "2-digit",
140706
- weekday: "short",
140707
- hour: "2-digit",
140708
- minute: "2-digit",
140709
- hour12: false
140710
- });
140741
+ const fmt2 = formatterFor(timeZone);
140711
140742
  const parts = {};
140712
140743
  for (const part of fmt2.formatToParts(d2))
140713
140744
  parts[part.type] = part.value;
@@ -143821,11 +143852,9 @@ async function runTask() {
143821
143852
  }
143822
143853
  }
143823
143854
  `;
143824
- var DEFAULT_ENV = ["PATH", "HOME", "USER", "SHELL", "LANG", "LC_ALL", "TERM"];
143825
143855
  var KILL_GRACE_MS = 2e3;
143826
143856
  function createSubprocessIsolator(opts = {}) {
143827
143857
  const defaultTimeMs = opts.defaultTimeMs ?? 6e4;
143828
- const envAllowlist = opts.defaultEnvAllowlist ?? DEFAULT_ENV;
143829
143858
  const nodePath = opts.nodePath ?? process.execPath;
143830
143859
  return {
143831
143860
  name: "subprocess",
@@ -143839,13 +143868,7 @@ function createSubprocessIsolator(opts = {}) {
143839
143868
  throw new Error(`[security:subprocess] ${verdict.reason}`);
143840
143869
  }
143841
143870
  const timeMs = caps.timeMs ?? defaultTimeMs;
143842
- const allowedEnv = caps.env ?? envAllowlist;
143843
- const env3 = {};
143844
- for (const key of allowedEnv) {
143845
- const v3 = process.env[key];
143846
- if (v3 !== void 0)
143847
- env3[key] = v3;
143848
- }
143871
+ const env3 = buildBrokerEnv({ env: caps.env ?? opts.defaultEnvAllowlist }, void 0);
143849
143872
  const child = spawn(nodePath, ["--input-type=module", "-e", SHIM_SOURCE2], {
143850
143873
  cwd: call.cwd,
143851
143874
  env: env3,
@@ -144861,6 +144884,29 @@ async function loadDir2(dir, scope, logger) {
144861
144884
  }
144862
144885
  return out;
144863
144886
  }
144887
+
144888
+ // ../plugin-workflows/dist/format.js
144889
+ function slugify2(name) {
144890
+ return name.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
144891
+ }
144892
+ function triggerSummary(on) {
144893
+ if (!on)
144894
+ return "on-demand";
144895
+ const parts = [];
144896
+ if (on.schedule?.cron)
144897
+ parts.push(`cron(${on.schedule.cron})`);
144898
+ if (on.schedule?.runAt)
144899
+ parts.push("runAt");
144900
+ if (on.afterWorkflow)
144901
+ parts.push(`after(${[on.afterWorkflow].flat().join(",")})`);
144902
+ if (on.fileChanged)
144903
+ parts.push("fileChanged");
144904
+ if (on.webhook)
144905
+ parts.push(`webhook(${on.webhook})`);
144906
+ return parts.length > 0 ? parts.join(" + ") : "on-demand";
144907
+ }
144908
+
144909
+ // ../plugin-workflows/dist/store.js
144864
144910
  var WorkflowStore = class {
144865
144911
  byName = /* @__PURE__ */ new Map();
144866
144912
  opts;
@@ -144982,9 +145028,6 @@ async function uniqueFilename2(dir, base2) {
144982
145028
  }
144983
145029
  return candidate;
144984
145030
  }
144985
- function slugify2(name) {
144986
- return name.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
144987
- }
144988
145031
  async function exists3(p3) {
144989
145032
  try {
144990
145033
  await promises.access(p3);
@@ -146282,22 +146325,6 @@ function validateTool(deps) {
146282
146325
  }
146283
146326
  });
146284
146327
  }
146285
- function triggerSummary(on) {
146286
- if (!on)
146287
- return "on-demand";
146288
- const parts = [];
146289
- if (on.schedule?.cron)
146290
- parts.push(`cron(${on.schedule.cron})`);
146291
- if (on.schedule?.runAt)
146292
- parts.push("runAt");
146293
- if (on.afterWorkflow)
146294
- parts.push(`after(${[on.afterWorkflow].flat().join(",")})`);
146295
- if (on.fileChanged)
146296
- parts.push("fileChanged");
146297
- if (on.webhook)
146298
- parts.push(`webhook(${on.webhook})`);
146299
- return parts.length > 0 ? parts.join(" + ") : "on-demand";
146300
- }
146301
146328
  var HELP = [
146302
146329
  "Usage: /workflows <subcommand>",
146303
146330
  " list show all workflows (\u25CF enabled / \u25CB disabled)",
@@ -146367,7 +146394,7 @@ async function listCmd(deps) {
146367
146394
  }
146368
146395
  const rows = [...all].sort((a2, b3) => a2.workflow.name.localeCompare(b3.workflow.name)).map((w4) => {
146369
146396
  const mark = w4.workflow.enabled ? "\u25CF" : "\u25CB";
146370
- const trig = triggerSummary2(w4.workflow.on);
146397
+ const trig = triggerSummary(w4.workflow.on);
146371
146398
  return ` ${mark} ${w4.workflow.name} [${w4.scope}] ${w4.workflow.steps.length} steps ${trig}
146372
146399
  ${w4.workflow.description}`;
146373
146400
  });
@@ -146441,7 +146468,7 @@ async function validateCmd(deps, name) {
146441
146468
  async function newCmd2(deps, name) {
146442
146469
  if (!name)
146443
146470
  return { kind: "error", message: "usage: /workflows new <name>" };
146444
- const slug = slugify3(name);
146471
+ const slug = slugify2(name);
146445
146472
  if (!/^[a-z0-9][a-z0-9-]*$/i.test(slug))
146446
146473
  return { kind: "error", message: `"${name}" is not a valid workflow name.` };
146447
146474
  const dir = deps.userDir ?? defaultUserWorkflowsDir();
@@ -146484,22 +146511,6 @@ async function rmCmd(deps, name) {
146484
146511
  function statusMark(status) {
146485
146512
  return status === "completed" ? "\u2713" : status === "skipped" ? "\u2013" : status === "failed" ? "\u2717" : "\xB7";
146486
146513
  }
146487
- function triggerSummary2(on) {
146488
- if (!on)
146489
- return "on-demand";
146490
- const parts = [];
146491
- if (on.schedule?.cron)
146492
- parts.push(`cron(${on.schedule.cron})`);
146493
- if (on.schedule?.runAt)
146494
- parts.push("runAt");
146495
- if (on.afterWorkflow)
146496
- parts.push(`after(${[on.afterWorkflow].flat().join(",")})`);
146497
- if (on.fileChanged)
146498
- parts.push("fileChanged");
146499
- if (on.webhook)
146500
- parts.push(`webhook(${on.webhook})`);
146501
- return parts.length > 0 ? parts.join("+") : "on-demand";
146502
- }
146503
146514
  async function readLastRun(dir, name) {
146504
146515
  if (!dir)
146505
146516
  return null;
@@ -146513,7 +146524,7 @@ async function readLastRun(dir, name) {
146513
146524
  for (const file of candidates) {
146514
146525
  try {
146515
146526
  const raw = await promises.readFile(path3.join(dir, file), "utf8");
146516
- const lines = raw.trim().split("\n").map((l2) => JSON.parse(l2));
146527
+ const lines = raw.trim().split("\n").filter((l2) => !l2.startsWith('{"kind":"output"')).map((l2) => JSON.parse(l2));
146517
146528
  const run2 = lines.find((l2) => l2.kind === "run");
146518
146529
  if (run2?.workflow !== name)
146519
146530
  continue;
@@ -146532,9 +146543,6 @@ function truncate7(s2, max) {
146532
146543
  return s2.length > max ? `${s2.slice(0, max)}
146533
146544
  \u2026 (truncated)` : s2;
146534
146545
  }
146535
- function slugify3(name) {
146536
- return name.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
146537
- }
146538
146546
  function starterTemplate(slug) {
146539
146547
  return `# Workflow: ${slug}
146540
146548
  # A DAG of steps. Each step has exactly one action: skill | prompt | tool | workflow.
@@ -146735,7 +146743,7 @@ function buildWorkflowsIntegration(args) {
146735
146743
  enabled: w4.workflow.enabled,
146736
146744
  scope: w4.scope,
146737
146745
  steps: w4.workflow.steps.length,
146738
- triggers: triggerSummary3(w4.workflow.on)
146746
+ triggers: triggerSummary2(w4.workflow.on)
146739
146747
  })),
146740
146748
  setEnabled: async (name, enabled) => {
146741
146749
  await store.setEnabled(name, enabled);
@@ -147023,7 +147031,7 @@ function safeActiveProvider(session) {
147023
147031
  return null;
147024
147032
  }
147025
147033
  }
147026
- function triggerSummary3(on) {
147034
+ function triggerSummary2(on) {
147027
147035
  if (!on) return "on-demand";
147028
147036
  const parts = [];
147029
147037
  if (on.schedule?.cron) parts.push(`cron(${on.schedule.cron})`);
@@ -150433,7 +150441,7 @@ function cliBin() {
150433
150441
  }
150434
150442
  async function fileExists(p3) {
150435
150443
  try {
150436
- await readFile(p3);
150444
+ await access(p3, constants$1.F_OK);
150437
150445
  return true;
150438
150446
  } catch {
150439
150447
  return false;