@tempoxyz/mercator 0.0.417 → 0.0.422

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/index.js CHANGED
@@ -2,8 +2,9 @@ import { Cli, z } from 'incur';
2
2
  import packageMetadata from '../package.json' with { type: 'json' };
3
3
  import { installCodexAgents, removeCodexAgents } from './agents.js';
4
4
  import { ClaimProvider, claimMach, WalletClaimError } from './claim.js';
5
+ import { clientEndpoint } from './client-endpoint.js';
5
6
  import { selectSetupClients } from './client-selection.js';
6
- import { CLIENT_IDS, Client, clientIntegrationLabel, clientLabel, configurationState, installedClients, mergeConfigFile, protectGrokConfig, removalPlan, removeConfigFile, setupPlan, } from './clients.js';
7
+ import { CLIENT_IDS, Client, configurationState, installedClients, mergeConfigFile, protectGrokConfig, removalPlan, removeConfigFile, setupPlan, } from './clients.js';
7
8
  import { installClaudeMarketplacePlugin, installCodexMarketplacePlugin, installGrokMarketplacePlugin, removeCodexMarketplacePlugin, } from './codex-marketplace.js';
8
9
  import { inspectCodexPlugin, installCodexPlugin, removeCodexPlugin, } from './codex-plugin.js';
9
10
  import { runInteractiveCommand } from './command.js';
@@ -12,22 +13,18 @@ import { fundMach, WalletFundingError } from './fund.js';
12
13
  import { getJob } from './job.js';
13
14
  import { authorizeMcpClient } from './mcp-authorization.js';
14
15
  import { setupNativePayments } from './native-payments.js';
16
+ import { recordSetupResult, setup, } from './setup.js';
15
17
  import { confirmSetup } from './setup-confirmation.js';
16
18
  import { startTerminalSetupProgress } from './setup-progress.js';
19
+ import { formatSetupResult } from './setup-render.js';
17
20
  import { createSetupTelemetry, SetupTelemetryEvent, setupFailureCategory, } from './setup-telemetry.js';
18
21
  import { RemoteSubmissionError, SubmitError, submitPaidJob } from './submit.js';
19
- import { styleText, supportsColor } from './terminal-style.js';
22
+ import { supportsColor } from './terminal-style.js';
20
23
  import { standaloneUpdate } from './update.js';
21
24
  import { inspectWallet, inspectWalletProvider, openBrowserUrl, openFundingPage, setupWallet, useWallet, WalletProvider, WalletRequiredError, } from './wallet.js';
22
25
  const DEFAULT_ENDPOINT = 'https://mercator.tempo.xyz/mcp/auth';
23
26
  /** Tempo-authenticated management page for remote MCP grants and spending limits. */
24
27
  const ACCOUNT_URL = 'https://mercator.tempo.xyz/account?login=1';
25
- /** Copyable prompts that turn a completed installation into a first successful use. */
26
- const SETUP_EXAMPLE_PROMPTS = [
27
- 'Find an API for live flight status and show me the cheapest option.',
28
- 'Quote the cheapest plan for current ETH and BTC prices.',
29
- 'Run that plan with a maximum budget of $1.',
30
- ];
31
28
  /** Concise human help for the remote-first installer and recovery surface. */
32
29
  const ROOT_HELP = `mercator@${packageMetadata.version} — Connect your agent to Mercator
33
30
 
@@ -449,619 +446,6 @@ export async function run(argv, overrides = {}) {
449
446
  }
450
447
  return exitCode;
451
448
  }
452
- async function setup(options, dependencies, progress, telemetry) {
453
- progress?.report(options.dryRun ? 'Preparing setup preview...' : 'Preparing setup...');
454
- const warnings = [];
455
- if (options.removeAgents && !options.agents) {
456
- throw new Error('--remove-agents and --no-agents cannot be used together');
457
- }
458
- if (options.force && options.removeAgents) {
459
- throw new Error('--force and --remove-agents cannot be used together');
460
- }
461
- if (options.removeAgents) {
462
- progress?.report('Removing managed Codex guidance...');
463
- const result = await dependencies.removeCodexAgents({ dryRun: options.dryRun });
464
- return {
465
- agents: result,
466
- clients: [],
467
- dryRun: options.dryRun,
468
- ready: true,
469
- warnings,
470
- };
471
- }
472
- let clients;
473
- let plugin;
474
- const marketplacePlugins = [];
475
- const clientResults = [];
476
- const detectedStates = new Map();
477
- if (options.client.length > 0) {
478
- clients = [...new Set(options.client)];
479
- progress?.report(`Selected: ${clients.map(clientIntegrationLabel).join(', ')}.`);
480
- }
481
- else {
482
- progress?.report('Detecting installed clients...');
483
- try {
484
- clients = await dependencies.installedClients();
485
- telemetry?.record(...clients.map((client) => ({
486
- client,
487
- event: SetupTelemetryEvent.ClientDetected,
488
- outcome: 'detected',
489
- })));
490
- }
491
- catch (error) {
492
- clients = [];
493
- warnings.push(`Client detection skipped: ${errorMessage(error)}. Select one later with mercator setup --client <client>.`);
494
- }
495
- if (clients.length === 0) {
496
- progress?.report('No supported client detected.');
497
- }
498
- else {
499
- progress?.report(`Detected: ${clients.map(clientIntegrationLabel).join(', ')}.`);
500
- }
501
- }
502
- if (options.client.length === 0 && !options.yes && clients.length > 0) {
503
- await progress?.preparePrompt?.();
504
- try {
505
- const selection = await dependencies.selectSetupClients(clients);
506
- if (!selection) {
507
- return {
508
- cancelled: true,
509
- clients: [],
510
- dryRun: options.dryRun,
511
- ready: true,
512
- warnings,
513
- };
514
- }
515
- clients = [...selection];
516
- if (clients.length === 0 && !options.plugin) {
517
- return {
518
- cancelled: true,
519
- clients: [],
520
- dryRun: options.dryRun,
521
- ready: true,
522
- warnings,
523
- };
524
- }
525
- }
526
- finally {
527
- progress?.resumeAfterPrompt?.();
528
- }
529
- }
530
- if (clients.length === 0 && !options.plugin) {
531
- warnings.push('No integration target is available. Install a supported client and rerun, or rerun without --no-plugin for the Codex/ChatGPT desktop plugin.');
532
- }
533
- const inspectionErrors = new Map();
534
- let diagnosticAuthorization;
535
- const uncheckedClients = clients.filter((client) => !detectedStates.has(client));
536
- if (uncheckedClients.length > 0) {
537
- progress?.report('Checking existing MCP registrations...');
538
- await Promise.all(uncheckedClients.map(async (client) => {
539
- try {
540
- detectedStates.set(client, await dependencies.configurationState(setupPlan(client, clientEndpoint(client, options.url))));
541
- }
542
- catch (error) {
543
- detectedStates.set(client, 'unknown');
544
- inspectionErrors.set(client, errorMessage(error));
545
- }
546
- }));
547
- }
548
- if (!options.dryRun) {
549
- const skippedClients = new Set();
550
- for (const client of clients) {
551
- const inspectionError = inspectionErrors.get(client);
552
- if (inspectionError) {
553
- clientResults.push({
554
- action: `Could not inspect the existing configuration: ${inspectionError}. Retry with mercator setup --client ${client}.`,
555
- client,
556
- status: 'skipped',
557
- });
558
- skippedClients.add(client);
559
- continue;
560
- }
561
- if (detectedStates.get(client) === 'unavailable') {
562
- const guidance = unavailableClientGuidance(client);
563
- progress?.report(`${guidance} Continuing with other integrations.`);
564
- clientResults.push({ action: guidance, client, status: 'skipped' });
565
- skippedClients.add(client);
566
- }
567
- }
568
- clients = clients.filter((client) => !skippedClients.has(client));
569
- }
570
- if (!options.dryRun && !options.yes) {
571
- const configurableClients = options.force
572
- ? clients
573
- : clients.filter((client) => detectedStates.get(client) !== 'different');
574
- const changedClients = options.force
575
- ? configurableClients
576
- : configurableClients.filter((client) => detectedStates.get(client) !== 'current');
577
- const confirmationActions = setupConfirmationActions(changedClients, options);
578
- if (confirmationActions.length > 0) {
579
- const confirmed = await dependencies.confirmSetup(confirmationActions, progress
580
- ? {
581
- ...(progress.color === undefined ? {} : { color: progress.color }),
582
- globe: progress.globe,
583
- }
584
- : { color: options.color });
585
- if (!confirmed) {
586
- return {
587
- cancelled: true,
588
- clients: [],
589
- dryRun: false,
590
- ready: true,
591
- warnings,
592
- };
593
- }
594
- }
595
- }
596
- if (options.plugin) {
597
- progress?.report('Bootstrapping the local desktop plugin...');
598
- try {
599
- plugin = await dependencies.installCodexPlugin({
600
- dryRun: options.dryRun,
601
- packageVersion: packageMetadata.version,
602
- skill: options.skill,
603
- });
604
- }
605
- catch (error) {
606
- warnings.push(`Codex/ChatGPT plugin skipped: ${errorMessage(error)}. Other integrations continued; rerun mercator setup --plugin to retry.`);
607
- }
608
- if (plugin && clients.includes(Client.Codex)) {
609
- try {
610
- await dependencies.removeCodexMarketplacePlugin({ dryRun: options.dryRun });
611
- }
612
- catch (error) {
613
- warnings.push(`Duplicate Codex marketplace plugin cleanup skipped: ${errorMessage(error)}. Remove it with codex plugin remove mercator@tempo.`);
614
- }
615
- }
616
- if (options.skill) {
617
- const marketplaceInstallers = [
618
- { client: Client.Claude, install: dependencies.installClaudeMarketplacePlugin },
619
- { client: Client.Grok, install: dependencies.installGrokMarketplacePlugin },
620
- ];
621
- for (const { client, install } of marketplaceInstallers) {
622
- if (!clients.includes(client))
623
- continue;
624
- progress?.report(`Trying the ${clientLabel(client)} plugin marketplace...`);
625
- try {
626
- const marketplacePlugin = await install({ dryRun: options.dryRun });
627
- marketplacePlugins.push({ ...marketplacePlugin, client });
628
- }
629
- catch (error) {
630
- const marketplace = 'tempo';
631
- marketplacePlugins.push({
632
- client,
633
- error: errorMessage(error),
634
- marketplace,
635
- plugin: 'mercator',
636
- status: 'skipped',
637
- });
638
- }
639
- }
640
- }
641
- }
642
- for (const client of clients) {
643
- const endpoint = clientEndpoint(client, options.url);
644
- let plan = setupPlan(client, endpoint);
645
- const state = detectedStates.get(client);
646
- if (state === undefined)
647
- throw new Error(`${client}: MCP state was not inspected.`);
648
- if (state === 'current' && !options.force) {
649
- clientResults.push({ client, status: 'already_configured' });
650
- continue;
651
- }
652
- if (state === 'different' && !options.force) {
653
- clientResults.push({
654
- action: `${plan.undo}, then run setup again, or use --force`,
655
- client,
656
- status: 'conflict',
657
- });
658
- continue;
659
- }
660
- if (options.dryRun) {
661
- progress?.report(`Planning ${client} MCP configuration...`);
662
- clientResults.push({
663
- action: options.force || state === 'legacy'
664
- ? `Recreate the Mercator MCP registration, then run: ${describeSetupPlan(plan)}`
665
- : describeSetupPlan(plan),
666
- client,
667
- status: 'planned',
668
- });
669
- continue;
670
- }
671
- try {
672
- const replaceExisting = options.force || state === 'legacy';
673
- if (client === Client.Grok && isProtectedMcpEndpoint(endpoint)) {
674
- progress?.report('Authorize Grok in Tempo Wallet...');
675
- const authorization = await dependencies.authorizeMcpClient(endpoint);
676
- diagnosticAuthorization = authorization.authorization;
677
- plan = setupPlan(client, endpoint, {
678
- authorization: authorization.authorization,
679
- });
680
- }
681
- if (replaceExisting && state !== 'missing') {
682
- progress?.report(`Removing existing ${client} MCP registration...`);
683
- await removeClientConfiguration(client, dependencies);
684
- }
685
- progress?.report(`Configuring ${client} MCP...`);
686
- if (plan.kind === 'file')
687
- await dependencies.mergeConfigFile(plan);
688
- else {
689
- await dependencies.runCommand(plan.command, plan.args);
690
- if (client === Client.Grok && diagnosticAuthorization) {
691
- await dependencies.protectGrokConfig();
692
- }
693
- }
694
- clientResults.push({
695
- client,
696
- status: replaceExisting && state !== 'missing' ? 'reconfigured' : 'configured',
697
- });
698
- }
699
- catch (error) {
700
- clientResults.push({
701
- action: `${errorMessage(error)}. Retry with mercator setup --client ${client}.`,
702
- client,
703
- status: 'skipped',
704
- });
705
- }
706
- }
707
- let agents;
708
- if (options.agents && (plugin !== undefined || clients.includes(Client.Codex))) {
709
- progress?.report('Refreshing managed Codex guidance...');
710
- try {
711
- agents = await dependencies.installCodexAgents({ dryRun: options.dryRun });
712
- }
713
- catch (error) {
714
- warnings.push(`Codex guidance skipped: ${errorMessage(error)}. MCP access is unaffected; rerun mercator setup --agents to retry.`);
715
- }
716
- }
717
- let nativePayments = [];
718
- const nativePaymentClients = clients.filter((client) => client === Client.OpenClaw || client === Client.Hermes);
719
- if (nativePaymentClients.length > 0) {
720
- progress?.report('Checking client-managed MCP payments...');
721
- try {
722
- nativePayments = await dependencies.setupNativePayments(clients, {
723
- dryRun: options.dryRun || options.force,
724
- endpoint: options.url,
725
- });
726
- }
727
- catch (error) {
728
- warnings.push(`Client-managed payment setup skipped: ${errorMessage(error)}. Retry with mercator setup.`);
729
- }
730
- }
731
- if (options.dryRun) {
732
- return {
733
- ...(agents ? { agents } : {}),
734
- clients: clientResults,
735
- dryRun: true,
736
- nativePayments,
737
- ...(plugin ? { plugin } : {}),
738
- ...(marketplacePlugins.length > 0 ? { marketplacePlugins } : {}),
739
- ready: true,
740
- warnings,
741
- };
742
- }
743
- progress?.report('Running Mercator readiness checks...');
744
- let diagnosis;
745
- try {
746
- const diagnosticEndpoints = new Set(clients.map((client) => clientEndpoint(client, options.url)));
747
- const diagnosticEndpoint = diagnosticEndpoints.size === 1 ? [...diagnosticEndpoints][0] : options.url;
748
- const hostedClients = clients.filter((client) => isProtectedMcpEndpoint(clientEndpoint(client, options.url)));
749
- const grokIsOnlyHostedClient = hostedClients.length > 0 && hostedClients.every((client) => client === Client.Grok);
750
- diagnosis = await diagnoseWithoutWallet(diagnosticEndpoint ?? options.url, dependencies, progress, grokIsOnlyHostedClient ? diagnosticAuthorization : undefined);
751
- }
752
- catch (error) {
753
- const message = errorMessage(error);
754
- warnings.push(`Readiness check skipped: ${message}. Your completed setup was preserved; run mercator doctor to retry.`);
755
- diagnosis = {
756
- ready: false,
757
- report: {
758
- discovery: 'failed',
759
- endpoint: options.url,
760
- error: message,
761
- paidExecution: 'not_verified',
762
- tools: [],
763
- transport: 'failed',
764
- },
765
- };
766
- }
767
- const integrationReady = plugin !== undefined ||
768
- clientResults.some((client) => ['already_configured', 'configured', 'reconfigured'].includes(client.status));
769
- return {
770
- ...(agents
771
- ? {
772
- agents: {
773
- ...agents,
774
- reloadRequired: agents.state !== 'current',
775
- },
776
- }
777
- : {}),
778
- clients: clientResults,
779
- diagnosis: diagnosis.report,
780
- dryRun: false,
781
- nativePayments,
782
- ...(plugin ? { plugin } : {}),
783
- ...(marketplacePlugins.length > 0 ? { marketplacePlugins } : {}),
784
- ready: diagnosis.ready &&
785
- nativePaymentClients.length === 0 &&
786
- (integrationReady ||
787
- marketplacePlugins.some(({ status }) => status === 'configured')),
788
- warnings,
789
- };
790
- }
791
- function recordSetupResult(telemetry, result) {
792
- if ('cancelled' in result && result.cancelled) {
793
- telemetry.record({ event: SetupTelemetryEvent.ReadinessChecked, outcome: 'skipped' }, { event: SetupTelemetryEvent.SetupFinished, outcome: 'cancelled' });
794
- return;
795
- }
796
- const incomplete = result.warnings.length > 0 ||
797
- result.clients.some(({ status }) => ['conflict', 'skipped'].includes(status)) ||
798
- ('marketplacePlugins' in result &&
799
- Boolean(result.marketplacePlugins?.some(({ status }) => status === 'skipped')));
800
- telemetry.record(...result.clients.map(({ client, status: outcome }) => ({
801
- client,
802
- event: SetupTelemetryEvent.ClientConfigured,
803
- outcome,
804
- })), {
805
- event: SetupTelemetryEvent.ReadinessChecked,
806
- outcome: result.dryRun ? 'skipped' : result.ready ? 'ready' : 'failed',
807
- }, {
808
- event: SetupTelemetryEvent.SetupFinished,
809
- outcome: result.dryRun
810
- ? 'planned'
811
- : result.ready && !incomplete
812
- ? 'succeeded'
813
- : 'partial',
814
- });
815
- }
816
- function unavailableClientGuidance(client) {
817
- if (client === Client.Codex) {
818
- return 'Codex CLI is not available on PATH. Install it, then rerun mercator setup --client codex; the desktop plugin can still be installed without it.';
819
- }
820
- return `${clientLabel(client)} is not available on PATH. Install its CLI and rerun, or omit --client ${client} to auto-detect available clients.`;
821
- }
822
- function errorMessage(error) {
823
- return error instanceof Error ? error.message : String(error);
824
- }
825
- /** Identifies the hosted-wallet route without treating arbitrary subpaths as protected. */
826
- export function isProtectedMcpEndpoint(endpoint) {
827
- return new URL(endpoint).pathname.replace(/\/$/, '') === '/mcp/auth';
828
- }
829
- /** Preserves runtime-native MPP clients that do not implement hosted-wallet OAuth. */
830
- export function clientEndpoint(client, endpoint) {
831
- if (isProtectedMcpEndpoint(endpoint) &&
832
- (client === Client.OpenClaw || client === Client.Hermes)) {
833
- const legacy = new URL(endpoint);
834
- legacy.pathname = '/mcp';
835
- return legacy.href;
836
- }
837
- return endpoint;
838
- }
839
- function setupConfirmationActions(clients, options) {
840
- const actions = [];
841
- if (options.plugin)
842
- actions.push('Install the Codex/ChatGPT desktop plugin');
843
- if (options.plugin && options.skill)
844
- actions.push('Install the Mercator skill');
845
- if (clients.length > 0) {
846
- const labels = clients.map(clientLabel);
847
- const formatted = labels.length === 1
848
- ? labels[0]
849
- : `${labels.slice(0, -1).join(', ')} and ${labels.at(-1)}`;
850
- actions.push(`Configure the Mercator MCP server for ${formatted}`);
851
- }
852
- if (options.agents && (options.plugin || clients.includes(Client.Codex))) {
853
- actions.push('Install Mercator guidance');
854
- }
855
- if (clients.some((client) => client === Client.OpenClaw || client === Client.Hermes)) {
856
- actions.push('Configure client-managed MCP payments');
857
- }
858
- return actions;
859
- }
860
- async function removeClientConfiguration(client, dependencies) {
861
- const removal = removalPlan(client);
862
- if (removal.kind === 'manual') {
863
- throw new Error(`${client}: Cannot force setup automatically. ${removal.instructions}`);
864
- }
865
- if (removal.kind === 'file') {
866
- await dependencies.removeConfigFile(removal);
867
- return;
868
- }
869
- await dependencies.runCommand(removal.command, removal.args);
870
- }
871
- function formatSetupResult(result, color = false) {
872
- if ('cancelled' in result && result.cancelled) {
873
- return 'Mercator setup cancelled.\n\nNo changes made.';
874
- }
875
- if ('agents' in result && result.agents && 'paths' in result.agents) {
876
- const { paths, state } = result.agents;
877
- const title = state === 'removed'
878
- ? 'Mercator guidance removed.'
879
- : state === 'planned'
880
- ? 'Mercator guidance removal preview — no changes made.'
881
- : 'Mercator guidance was not installed.';
882
- return [
883
- styleText(title, 'bold', color),
884
- '',
885
- ...paths.map((path) => `✓ ${path}`),
886
- ].join('\n');
887
- }
888
- const hasWarnings = result.warnings.length > 0 ||
889
- result.clients.some((client) => client.status === 'conflict' || client.status === 'skipped') ||
890
- ('marketplacePlugins' in result &&
891
- Boolean(result.marketplacePlugins?.some((plugin) => plugin.status === 'skipped')));
892
- const title = result.dryRun
893
- ? 'Mercator setup preview — no changes made.'
894
- : result.ready && !hasWarnings
895
- ? 'Mercator setup complete.'
896
- : result.ready
897
- ? 'Mercator setup complete with warnings.'
898
- : 'Mercator setup needs attention.';
899
- const lines = [styleText(title, 'bold', color)];
900
- const integrations = [];
901
- for (const client of result.clients) {
902
- const glyph = client.status === 'planned' || client.status === 'skipped'
903
- ? '→'
904
- : client.status === 'conflict'
905
- ? '!'
906
- : '✓';
907
- const status = client.status === 'planned'
908
- ? 'would be configured'
909
- : client.status === 'conflict'
910
- ? 'configured differently'
911
- : client.status === 'already_configured'
912
- ? 'already configured — nothing changed'
913
- : client.status === 'reconfigured'
914
- ? 'updated'
915
- : humanizeStatus(client.status);
916
- integrations.push(formatSetupRow(glyph, `${clientLabel(client.client)} MCP`, status, color));
917
- if (client.action)
918
- integrations.push(` ${client.action}`);
919
- }
920
- if ('plugin' in result && result.plugin) {
921
- const glyph = result.plugin.status === 'planned' ? '→' : '✓';
922
- const status = result.plugin.status === 'planned'
923
- ? 'would be installed'
924
- : result.plugin.status === 'already_configured'
925
- ? 'already installed — nothing changed'
926
- : humanizeStatus(result.plugin.status);
927
- integrations.push(formatSetupRow(glyph, 'Codex/ChatGPT plugin', status, color));
928
- integrations.push(result.plugin.status === 'planned'
929
- ? formatSetupRow('→', 'Mercator skill', result.plugin.skillInstalled ? 'would be installed' : 'would be omitted', color)
930
- : result.plugin.skillInstalled
931
- ? formatSetupRow('✓', 'Mercator skill', 'installed', color)
932
- : formatSetupRow('○', 'Mercator skill', 'not installed', color));
933
- }
934
- if ('marketplacePlugins' in result && result.marketplacePlugins) {
935
- for (const marketplacePlugin of result.marketplacePlugins) {
936
- const glyph = marketplacePlugin.status === 'planned'
937
- ? '→'
938
- : marketplacePlugin.status === 'skipped'
939
- ? '○'
940
- : '✓';
941
- const status = marketplacePlugin.status === 'planned'
942
- ? 'would be installed'
943
- : humanizeStatus(marketplacePlugin.status);
944
- integrations.push(formatSetupRow(glyph, `${clientLabel(marketplacePlugin.client)} plugin`, status, color));
945
- if (marketplacePlugin.error)
946
- integrations.push(` ${marketplacePlugin.error}`);
947
- }
948
- }
949
- if ('agents' in result && result.agents) {
950
- const glyph = result.agents.state === 'planned' ? '→' : '✓';
951
- const status = result.agents.state === 'planned'
952
- ? 'would be updated'
953
- : humanizeStatus(result.agents.state);
954
- integrations.push(formatSetupRow(glyph, 'Codex guidance', status, color));
955
- if (result.agents.shadowed) {
956
- integrations.push(formatSetupRow('!', 'Codex guidance', 'shadowed by AGENTS.override.md', color));
957
- }
958
- }
959
- if (integrations.length > 0) {
960
- lines.push('', styleText('Integrations', 'bold', color), ...integrations);
961
- }
962
- const readiness = [];
963
- if ('nativePayments' in result) {
964
- for (const payment of result.nativePayments) {
965
- const glyph = payment.status === 'ready' ? '✓' : payment.status === 'planned' ? '→' : '!';
966
- const status = payment.status === 'planned'
967
- ? 'would be configured'
968
- : humanizeStatus(payment.status);
969
- readiness.push(formatSetupRow(glyph, `${clientLabel(payment.client)} payments`, status, color));
970
- if (payment.status === 'action_required' || payment.status === 'planned') {
971
- readiness.push(...payment.guidance.map((guidance) => ` ${guidance}`));
972
- }
973
- }
974
- }
975
- if ('diagnosis' in result) {
976
- readiness.push(formatSetupRow(result.diagnosis.transport === 'ready' ? '✓' : '✗', 'MCP transport', humanizeStatus(result.diagnosis.transport), color), formatSetupRow(result.diagnosis.discovery === 'ready'
977
- ? '✓'
978
- : result.diagnosis.transport === 'ready'
979
- ? '✗'
980
- : '○', 'Service discovery', result.diagnosis.transport === 'ready'
981
- ? humanizeStatus(result.diagnosis.discovery)
982
- : 'not checked', color), formatSetupRow(result.diagnosis.paidExecution === 'ready'
983
- ? '✓'
984
- : result.diagnosis.paidExecution === 'failed'
985
- ? '✗'
986
- : '○', 'Paid execution', humanizeStatus(result.diagnosis.paidExecution), color));
987
- if (result.diagnosis.error)
988
- readiness.push(` ${result.diagnosis.error}`);
989
- }
990
- if (readiness.length > 0) {
991
- lines.push('', styleText('Readiness', 'bold', color), ...readiness);
992
- }
993
- if (result.warnings.length > 0) {
994
- lines.push('', styleText('Warnings', 'bold', color), ...result.warnings.map((warning) => formatSetupRow('!', warning, undefined, color)));
995
- }
996
- const preservedClientCount = result.clients.filter(({ status }) => ['already_configured', 'configured', 'reconfigured'].includes(status)).length;
997
- const hasClientFailure = result.clients.some(({ status }) => ['conflict', 'skipped'].includes(status));
998
- if (!result.dryRun && hasClientFailure && preservedClientCount > 0) {
999
- const preservedSummary = preservedClientCount === 1
1000
- ? '1 successful client integration was preserved.'
1001
- : `${preservedClientCount} successful client integrations were preserved.`;
1002
- lines.push('', preservedSummary);
1003
- }
1004
- if (result.dryRun) {
1005
- lines.push('', result.clients.some((client) => client.status === 'conflict')
1006
- ? 'Resolve the items marked ! before applying this setup.'
1007
- : 'Run without --dry-run to apply these changes.');
1008
- return lines.join('\n');
1009
- }
1010
- if (!result.ready) {
1011
- lines.push('', 'Your completed setup was preserved.', '', 'Retry readiness checks:', ' mercator doctor');
1012
- return lines.join('\n');
1013
- }
1014
- const nativePaymentsReady = 'nativePayments' in result &&
1015
- result.nativePayments.every((payment) => payment.status === 'ready');
1016
- const pluginReload = 'plugin' in result && result.plugin ? result.plugin.reloadRequired : false;
1017
- const agentsReload = 'agents' in result && result.agents && 'reloadRequired' in result.agents
1018
- ? result.agents.reloadRequired
1019
- : false;
1020
- if (pluginReload || agentsReload) {
1021
- lines.push('');
1022
- if (pluginReload && agentsReload) {
1023
- lines.push('Restart Codex and ChatGPT desktop to load the new integrations.');
1024
- }
1025
- else if (pluginReload) {
1026
- lines.push('Restart ChatGPT desktop to load the new integration.');
1027
- }
1028
- else {
1029
- lines.push('Restart Codex to load the updated guidance.');
1030
- }
1031
- }
1032
- const everythingCurrent = result.clients.every((client) => client.status === 'already_configured') &&
1033
- (!('plugin' in result) || result.plugin?.status === 'already_configured') &&
1034
- (!('agents' in result) || result.agents?.state === 'current') &&
1035
- nativePaymentsReady &&
1036
- !pluginReload &&
1037
- !agentsReload;
1038
- if (everythingCurrent) {
1039
- lines.push('', 'Everything is up to date.');
1040
- }
1041
- lines.push('', styleText('Try Mercator', 'bold', color), ...SETUP_EXAMPLE_PROMPTS.map((prompt) => ` “${prompt}”`));
1042
- return lines.join('\n');
1043
- }
1044
- function formatSetupRow(glyph, label, status, color) {
1045
- const style = glyph === '✓'
1046
- ? 'green'
1047
- : glyph === '!'
1048
- ? 'yellow'
1049
- : glyph === '✗'
1050
- ? 'red'
1051
- : glyph === '→'
1052
- ? 'cyan'
1053
- : 'dim';
1054
- const detail = status ? ` — ${styleText(status, style, color)}` : '';
1055
- return ` ${styleText(glyph, style, color)} ${label}${detail}`;
1056
- }
1057
- function humanizeStatus(status) {
1058
- return status.replaceAll('_', ' ');
1059
- }
1060
- function describeSetupPlan(plan) {
1061
- return plan.kind === 'command'
1062
- ? [plan.command, ...plan.args].join(' ')
1063
- : `Update ${plan.path}`;
1064
- }
1065
449
  async function uninstall(options, dependencies) {
1066
450
  let plugin;
1067
451
  if (options.client.length === 0 || options.client.includes(Client.Codex)) {
@@ -1106,6 +490,9 @@ async function uninstall(options, dependencies) {
1106
490
  preserved: ['wallets', 'keys', 'balances', 'payment_sessions', 'mpp_plugins'],
1107
491
  };
1108
492
  }
493
+ function errorMessage(error) {
494
+ return error instanceof Error ? error.message : String(error);
495
+ }
1109
496
  async function clientStatus(endpoint, dependencies) {
1110
497
  const installed = await dependencies.installedClients();
1111
498
  const clients = await Promise.all(installed.map(async (client) => {
@@ -1141,21 +528,6 @@ async function doctor(options, dependencies, progress) {
1141
528
  report: combined,
1142
529
  };
1143
530
  }
1144
- async function diagnoseWithoutWallet(endpoint, dependencies, progress, authorization) {
1145
- const authenticatedFetch = authorization
1146
- ? (input, init) => {
1147
- const headers = new Headers(init?.headers);
1148
- headers.set('authorization', authorization);
1149
- return fetch(input, { ...init, headers });
1150
- }
1151
- : undefined;
1152
- const diagnosed = await dependencies.diagnose(endpoint, authenticatedFetch, progress?.report);
1153
- return {
1154
- ready: diagnosed.transport === 'ready' &&
1155
- diagnosed.discovery === 'ready' &&
1156
- diagnosed.paidExecution === 'ready',
1157
- report: diagnosed,
1158
- };
1159
- }
531
+ export { clientEndpoint, isProtectedMcpEndpoint } from './client-endpoint.js';
1160
532
  export { diagnose, inspectCodexPlugin, inspectWallet, inspectWalletProvider, installClaudeMarketplacePlugin, installCodexMarketplacePlugin, installCodexPlugin, installGrokMarketplacePlugin, openFundingPage, removeCodexMarketplacePlugin, removeCodexPlugin, setupPlan, setupWallet, useWallet, };
1161
533
  //# sourceMappingURL=index.js.map