@moxxy/cli 0.14.1 → 0.14.2

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
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from 'node:module';
3
- import { z as z$1, createMutex, defineTunnelProvider, definePlugin, defineProvider, defineTool, MoxxyError, asTurnId, defineMode, asPluginId, defineCommand, defineChannel, defineWorkflowExecutor, toFriendlyError, estimateTextTokens, classifyHttpStatus, createStuckLoopDetector, runCompactionIfNeeded, runElisionIfNeeded, collectProviderStream, usageEventFields, isContextOverflowError, emitRequestsAndDetectStuck, executeToolUses, buildSystemPromptWithSkills, projectMessages, defineCompactor, defineCacheStrategy, denyByDefaultResolver, createAllowListResolver, zodToJsonSchema, fileDiffSummary, runSingleShotTurn, defineSurface, runManualCompaction, isFileDiffDisplay, renderFrontmatter, defineEmbedder, migrateModeName, skillFrontmatterSchema, asSkillId, getInstallHint, parseFrontmatterFile, createDeferredPermissionResolver, encodeLoginPrompt, defineTranscriber, summarizeTokensByModel, countNodes, moxxyPackageSchema, classifyNetworkError, addModelTotals, createJsonFileStore, ISOLATION_RANK, MOXXY_PCM16_24KHZ_MIME, fileDiffVerb, parseFrontmatter, createCallbackResolver, autoAllowResolver, asSessionId, asToolCallId, defineViewRenderer, DEFAULT_VIEW_TAGS, isSafeViewUrl, evaluateToolRule, summarizeSessionTokensFromEvents, toDiffRows, diffGutterNo, computeElisionState, toolResultStubbed, toolResultStub, toolResultBytes, conversationalStubbed, conversationalStub, asEventId } from '@moxxy/sdk';
3
+ import { z as z$1, createMutex, defineTunnelProvider, definePlugin, defineProvider, defineTool, MoxxyError, asTurnId, defineMode, asPluginId, defineCommand, defineChannel, defineWorkflowExecutor, toFriendlyError, estimateTextTokens, classifyHttpStatus, createStuckLoopDetector, runCompactionIfNeeded, runElisionIfNeeded, collectProviderStream, usageEventFields, isContextOverflowError, emitRequestsAndDetectStuck, executeToolUses, buildSystemPromptWithSkills, projectMessages, defineCompactor, defineCacheStrategy, denyByDefaultResolver, createAllowListResolver, zodToJsonSchema, fileDiffSummary, runSingleShotTurn, defineSurface, runManualCompaction, isFileDiffDisplay, renderFrontmatter, defineEmbedder, migrateModeName, skillFrontmatterSchema, asSkillId, startChannelWith, parseFrontmatterFile, createDeferredPermissionResolver, getInstallHint, defineTranscriber, summarizeTokensByModel, countNodes, moxxyPackageSchema, encodeLoginPrompt, classifyNetworkError, addModelTotals, createJsonFileStore, ISOLATION_RANK, MOXXY_PCM16_24KHZ_MIME, fileDiffVerb, parseFrontmatter, createCallbackResolver, autoAllowResolver, asSessionId, asToolCallId, defineViewRenderer, DEFAULT_VIEW_TAGS, isSafeViewUrl, evaluateToolRule, summarizeSessionTokensFromEvents, toDiffRows, diffGutterNo, computeElisionState, toolResultStubbed, toolResultStub, toolResultBytes, conversationalStubbed, conversationalStub, asEventId } from '@moxxy/sdk';
4
4
  import * as fs32 from 'fs';
5
5
  import fs32__default, { existsSync, promises, ReadStream, mkdirSync, statSync, readdirSync, writeFileSync, readFileSync, unlinkSync, chmodSync, watch, createReadStream } from 'fs';
6
6
  import * as path3 from 'path';
@@ -145831,6 +145831,12 @@ function buildBrowserSurface(deps) {
145831
145831
  } else if (msg.type === "move" && typeof msg.fx === "number" && typeof msg.fy === "number") {
145832
145832
  await browserSidecarCall("mousemove", { x: msg.fx * vw, y: msg.fy * vh }, deps).catch(() => void 0);
145833
145833
  void tick();
145834
+ } else if (msg.type === "pick" && typeof msg.fx === "number" && typeof msg.fy === "number") {
145835
+ const element = await browserSidecarCall("pick", { x: msg.fx * vw, y: msg.fy * vh }, deps).catch(() => null);
145836
+ emit2({ type: "picked", element });
145837
+ } else if (msg.type === "zoom" && typeof msg.factor === "number") {
145838
+ await browserSidecarCall("zoom", { factor: msg.factor }, deps).catch(() => void 0);
145839
+ bump();
145834
145840
  } else if (msg.type === "key" && typeof msg.key === "string") {
145835
145841
  await browserSidecarCall("key", { key: msg.key }, deps).catch(() => void 0);
145836
145842
  bump();
@@ -151228,6 +151234,15 @@ async function probeSession(opts, read, boot = setupSessionWithConfig) {
151228
151234
  }
151229
151235
  }
151230
151236
 
151237
+ // src/setup/close-session.ts
151238
+ async function closeSession(session, persistence) {
151239
+ if (persistence) {
151240
+ await persistence.flush().catch(() => void 0);
151241
+ await persistence.settleWrites().catch(() => void 0);
151242
+ }
151243
+ await session.close("cli-exit").catch(() => void 0);
151244
+ }
151245
+
151231
151246
  // src/argv-helpers.ts
151232
151247
  function argvToSetupOptions(argv, overrides = {}) {
151233
151248
  return {
@@ -151310,7 +151325,7 @@ ${stdinBuf}` : prompt;
151310
151325
  }
151311
151326
  const model = stringFlag(argv, "model");
151312
151327
  const resolver2 = allowAll ? denyByDefaultResolver : allowTools.length > 0 ? createAllowListResolver(allowTools) : denyByDefaultResolver;
151313
- const session = await setupSession({
151328
+ const { session, persistence } = await setupSessionWithConfig({
151314
151329
  ...argvToSetupOptions(argv),
151315
151330
  resolver: resolver2
151316
151331
  });
@@ -151345,7 +151360,9 @@ ${stdinBuf}` : prompt;
151345
151360
  }
151346
151361
  } catch (err) {
151347
151362
  printError(`fatal: ${err instanceof Error ? err.message : String(err)}`);
151348
- return 1;
151363
+ exitCode = 1;
151364
+ } finally {
151365
+ await closeSession(session, persistence);
151349
151366
  }
151350
151367
  return exitCode;
151351
151368
  }
@@ -151370,8 +151387,6 @@ async function readStdinIfPiped() {
151370
151387
  await init_dist9();
151371
151388
  await init_build2();
151372
151389
  var import_react70 = __toESM(require_react());
151373
-
151374
- // src/commands/web-surface.ts
151375
151390
  var REMOTE_CHANNELS = /* @__PURE__ */ new Set(["telegram"]);
151376
151391
  async function coAttachWebSurface(opts) {
151377
151392
  const { primary, session, vault, config } = opts;
@@ -151385,7 +151400,7 @@ async function coAttachWebSurface(opts) {
151385
151400
  await resolveTunnel(primary, session, webCfg, write);
151386
151401
  try {
151387
151402
  const web = def.create({ cwd: process.cwd(), vault, logger: session.logger, options: webCfg });
151388
- const handle2 = await web.start({ session });
151403
+ const handle2 = await startChannelWith(web, { session });
151389
151404
  const url2 = web.shareUrl;
151390
151405
  if (url2) write(` web surface ${url2}
151391
151406
  `);
@@ -151824,14 +151839,21 @@ function renderLogo(width = process.stdout.columns ?? 80, opts = {}) {
151824
151839
  }
151825
151840
  async function runInitCommand(argv) {
151826
151841
  const interactive = Boolean(process.stdin.isTTY);
151827
- const { session, vault } = await bootSessionWithConfig(argv, {
151842
+ const { session, vault, persistence } = await bootSessionWithConfig(argv, {
151828
151843
  skipKeyPrompt: true,
151829
151844
  skipProviderActivation: true,
151830
151845
  ...interactive ? { passphrasePrompt: promptVaultPassphrase } : {}
151831
151846
  });
151832
- if (!interactive) {
151833
- return await runHeadlessInit(session, vault);
151847
+ try {
151848
+ if (!interactive) {
151849
+ return await runHeadlessInit(session, vault);
151850
+ }
151851
+ return await runInteractiveInit(session, vault);
151852
+ } finally {
151853
+ await closeSession(session, persistence);
151834
151854
  }
151855
+ }
151856
+ async function runInteractiveInit(session, vault) {
151835
151857
  process.stdout.write(renderLogo());
151836
151858
  await vault.open();
151837
151859
  const providerDefs = session.providers.list();
@@ -152798,8 +152820,6 @@ function stringFlag2(argv, name) {
152798
152820
  function errorMessage(err) {
152799
152821
  return err instanceof Error ? err.message : String(err);
152800
152822
  }
152801
-
152802
- // src/commands/start-registered-channel.ts
152803
152823
  async function startRegisteredChannel(name, argv) {
152804
152824
  const standalone = hasBoolFlag(argv, "standalone");
152805
152825
  const mode = chooseClientMode({ standalone, runnerUp: standalone ? false : await isRunnerUp() });
@@ -152835,7 +152855,7 @@ async function runAttachedChannel(name, argv) {
152835
152855
  options: { ...configOpts, ...argv.flags }
152836
152856
  });
152837
152857
  remote.setPermissionResolver(channel.permissionResolver);
152838
- const handle2 = await channel.start({
152858
+ const handle2 = await startChannelWith(channel, {
152839
152859
  session: remote,
152840
152860
  model: stringFlag(argv, "model"),
152841
152861
  ...collectExtraFlags(argv)
@@ -152881,7 +152901,7 @@ async function runSelfHostedChannel(name, argv, standalone) {
152881
152901
  runnerServer = null;
152882
152902
  }
152883
152903
  }
152884
- const handle2 = await channel.start({
152904
+ const handle2 = await startChannelWith(channel, {
152885
152905
  session,
152886
152906
  model: stringFlag(argv, "model"),
152887
152907
  ...collectExtraFlags(argv)
@@ -154222,7 +154242,7 @@ async function runScheduleNow(argv) {
154222
154242
  process.stderr.write(colors.red("missing id") + "\n usage: moxxy schedule run <id>\n");
154223
154243
  return 2;
154224
154244
  }
154225
- const { session, scheduler: full } = await setupSessionWithConfig({
154245
+ const { session, scheduler: full, persistence } = await setupSessionWithConfig({
154226
154246
  cwd: process.cwd(),
154227
154247
  skipInitHooks: true
154228
154248
  });
@@ -154253,7 +154273,7 @@ async function runScheduleNow(argv) {
154253
154273
  );
154254
154274
  return outcome.ok ? 0 : 1;
154255
154275
  } finally {
154256
- await session.close("schedule-run").catch(() => void 0);
154276
+ await closeSession(session, persistence);
154257
154277
  }
154258
154278
  }
154259
154279
 
@@ -154334,7 +154354,25 @@ async function runDoctorCommand(argv) {
154334
154354
  });
154335
154355
  return emit(checks, asJson);
154336
154356
  }
154337
- const { session, config, configSources, vault, memory, pluginRegistration } = setupResult.value;
154357
+ const { session, config, configSources, vault, memory, pluginRegistration, persistence } = setupResult.value;
154358
+ try {
154359
+ return await runDoctorChecks({
154360
+ session,
154361
+ config,
154362
+ configSources,
154363
+ vault,
154364
+ memory,
154365
+ pluginRegistration,
154366
+ checks,
154367
+ checkKeys,
154368
+ asJson
154369
+ });
154370
+ } finally {
154371
+ await closeSession(session, persistence);
154372
+ }
154373
+ }
154374
+ async function runDoctorChecks(deps) {
154375
+ const { session, config, configSources, vault, memory, pluginRegistration, checks, checkKeys, asJson } = deps;
154338
154376
  if (configSources.length > 0) {
154339
154377
  const summary = configSources.map((s2) => `${s2.scope}:${s2.path}`).join(", ");
154340
154378
  checks.push({ id: "config", status: "ok", message: `loaded from ${summary}` });
@@ -154407,8 +154445,8 @@ async function runDoctorCommand(argv) {
154407
154445
  checks.push({ id: `provider:${name}`, status: "ok", message: "key resolved" });
154408
154446
  }
154409
154447
  }
154410
- const deps = { cwd: process.cwd(), vault, logger: session.logger, options: {} };
154411
- const channelEntries = await session.channels.listWithAvailability(deps);
154448
+ const channelDeps = { cwd: process.cwd(), vault, logger: session.logger, options: {} };
154449
+ const channelEntries = await session.channels.listWithAvailability(channelDeps);
154412
154450
  for (const { def, availability } of channelEntries) {
154413
154451
  if (availability.ok) {
154414
154452
  checks.push({ id: `channel:${def.name}`, status: "ok", message: "available" });
@@ -154620,12 +154658,18 @@ async function runLoginCommand(argv) {
154620
154658
  if (!sub || sub === "help" || sub === "--help" || sub === "-h") {
154621
154659
  let session = null;
154622
154660
  try {
154623
- const { session: s2 } = await bootSessionWithConfig(argv, {
154661
+ const { session: s2, persistence } = await bootSessionWithConfig(argv, {
154624
154662
  skipKeyPrompt: true,
154625
154663
  skipProviderActivation: true,
154626
154664
  tolerateNoProvider: true
154627
154665
  });
154628
154666
  session = s2;
154667
+ try {
154668
+ process.stdout.write(buildHelp(session));
154669
+ } finally {
154670
+ await closeSession(s2, persistence);
154671
+ }
154672
+ return sub ? 0 : 2;
154629
154673
  } catch {
154630
154674
  }
154631
154675
  process.stdout.write(buildHelp(session));
@@ -154636,11 +154680,18 @@ async function runLoginCommand(argv) {
154636
154680
  return await loginProvider(argv, sub);
154637
154681
  }
154638
154682
  async function loginProvider(argv, providerName2) {
154639
- const { session, vault } = await bootSessionWithConfig(argv, {
154683
+ const { session, vault, persistence } = await bootSessionWithConfig(argv, {
154640
154684
  skipKeyPrompt: true,
154641
154685
  skipProviderActivation: true,
154642
154686
  tolerateNoProvider: true
154643
154687
  });
154688
+ try {
154689
+ return await runLoginProvider(argv, providerName2, session, vault);
154690
+ } finally {
154691
+ await closeSession(session, persistence);
154692
+ }
154693
+ }
154694
+ async function runLoginProvider(argv, providerName2, session, vault) {
154644
154695
  const def = session.providers.list().find((d2) => d2.name === providerName2);
154645
154696
  if (!def) {
154646
154697
  process.stderr.write(
@@ -154691,11 +154742,18 @@ Run \`moxxy init\` to store its key in the vault.
154691
154742
  }
154692
154743
  }
154693
154744
  async function loginStatus(argv) {
154694
- const { session, vault } = await bootSessionWithConfig(argv, {
154745
+ const { session, vault, persistence } = await bootSessionWithConfig(argv, {
154695
154746
  skipKeyPrompt: true,
154696
154747
  skipProviderActivation: true,
154697
154748
  tolerateNoProvider: true
154698
154749
  });
154750
+ try {
154751
+ return await runLoginStatus(argv, session, vault);
154752
+ } finally {
154753
+ await closeSession(session, persistence);
154754
+ }
154755
+ }
154756
+ async function runLoginStatus(argv, session, vault) {
154699
154757
  await vault.open();
154700
154758
  const ctx = buildProviderAuthContext(vault, { headless: true });
154701
154759
  const filter = argv.positional[1];
@@ -154762,11 +154820,18 @@ async function loginLogout(argv) {
154762
154820
  );
154763
154821
  return 2;
154764
154822
  }
154765
- const { session, vault } = await bootSessionWithConfig(argv, {
154823
+ const { session, vault, persistence } = await bootSessionWithConfig(argv, {
154766
154824
  skipKeyPrompt: true,
154767
154825
  skipProviderActivation: true,
154768
154826
  tolerateNoProvider: true
154769
154827
  });
154828
+ try {
154829
+ return await runLoginLogout(providerName2, session, vault);
154830
+ } finally {
154831
+ await closeSession(session, persistence);
154832
+ }
154833
+ }
154834
+ async function runLoginLogout(providerName2, session, vault) {
154770
154835
  await vault.open();
154771
154836
  const def = session.providers.list().find((d2) => d2.name === providerName2);
154772
154837
  if (!def || def.auth?.kind !== "oauth") {
@@ -155202,8 +155267,6 @@ async function runPath(spec) {
155202
155267
  process.stdout.write(s2.unitPath + "\n");
155203
155268
  return 0;
155204
155269
  }
155205
-
155206
- // src/commands/serve.ts
155207
155270
  var BACKGROUND_UNITS = [
155208
155271
  {
155209
155272
  id: "scheduler",
@@ -155452,7 +155515,7 @@ async function startChannel(def, setup, installResolver) {
155452
155515
  if (installResolver) {
155453
155516
  session.setPermissionResolver(channel.permissionResolver);
155454
155517
  }
155455
- return channel.start({ session, ...channelOpts });
155518
+ return startChannelWith(channel, { session, ...channelOpts });
155456
155519
  }
155457
155520
  function failureHint(_name, error2) {
155458
155521
  const e3 = error2.toLowerCase();