@muggleai/works 5.26.0-staging.218 → 5.26.0-staging.220

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.
@@ -9,7 +9,7 @@
9
9
  "name": "muggleai",
10
10
  "source": "./plugin",
11
11
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
12
- "version": "5.26.0-staging.218"
12
+ "version": "5.26.0-staging.220"
13
13
  }
14
14
  ]
15
15
  }
package/README.md CHANGED
@@ -345,6 +345,7 @@ muggle serve --local # Local tools only (muggle-local-*)
345
345
 
346
346
  # Setup and diagnostics
347
347
  muggle init # Guided setup; saves preferences, offers the CI check
348
+ muggle llm-source [--show] # Who supplies the model for local runs: Muggle AI credit, your Anthropic key, or a local model
348
349
  muggle setup [--force] # Download or update the browser runner
349
350
  muggle upgrade [--check] # Install the latest runner version
350
351
  muggle versions # List installed runner versions
@@ -1,4 +1,4 @@
1
- import { __export, getLogger, getConfig, createChildLogger, buildElectronAppReleaseAssetUrl, getActiveRuntimeTarget, getAuthService, hasApiKey, getElectronAppVersion, getElectronAppDir, getPlatformKey, reconcileProjectPreferences, getDataDir2, PREFERENCES_FILE_NAME, isFirstRun, writePreferences, DEFAULT_PREFERENCES, isElectronAppInstalled, getElectronAppChecksums, getChecksumForPlatform, getElectronAppSignedFromVersion, getReleaseSignerIdentityUri, verifyFileChecksum, resolveElectronAppExecutablePath, calculateFileChecksum, initTelemetry, Surface, ServiceName, track, EventName, getQaTools, getLocalQaTools, performLogout, assertDeviceCodeClientProvisioned, performLogin, getActiveElectronAppReleaseStream, buildToolInputJsonSchema, toolRequiresAuth, getCallerCredentials, parseElectronAppDirName, getElectronAppReleaseTagPrefix, hasShownDisclosure, markDisclosureShown, getBundledElectronAppVersion, getElectronAppVersionSource, getCredentialsFilePath, ElectronAppReleaseStream, buildElectronAppChecksumsUrl, __require, getDisclosureCopy, buildOnboardingPlan, applyOnboardingAnswers, needsOnboarding, readRunView, RunViewError, renderRunViewText, writeRunViewHtml, openBrowserUrl, evaluateCheckoutFreshness, runGitCommand, BLOCKING_FRESHNESS_VERDICTS, claimServiceStack, BUSY_EXIT_CODE, checkServiceStack, releaseServiceStack, readServiceStackStatus, resolvePreferences, OnboardingBlanketChoice, PreferenceKey, getDataDir } from './chunk-EC47OWYJ.js';
1
+ import { __export, getLogger, getConfig, createChildLogger, buildElectronAppReleaseAssetUrl, getActiveRuntimeTarget, getAuthService, hasApiKey, getElectronAppVersion, getElectronAppDir, getPlatformKey, reconcileProjectPreferences, getDataDir2, PREFERENCES_FILE_NAME, isFirstRun, writePreferences, DEFAULT_PREFERENCES, isElectronAppInstalled, getElectronAppChecksums, getChecksumForPlatform, getElectronAppSignedFromVersion, getReleaseSignerIdentityUri, verifyFileChecksum, resolveElectronAppExecutablePath, calculateFileChecksum, initTelemetry, Surface, ServiceName, track, EventName, getQaTools, getLocalQaTools, performLogout, assertDeviceCodeClientProvisioned, performLogin, getActiveElectronAppReleaseStream, buildToolInputJsonSchema, toolRequiresAuth, getCallerCredentials, parseElectronAppDirName, getElectronAppReleaseTagPrefix, hasShownDisclosure, markDisclosureShown, getBundledElectronAppVersion, getElectronAppVersionSource, getCredentialsFilePath, ElectronAppReleaseStream, buildElectronAppChecksumsUrl, __require, getDisclosureCopy, buildOnboardingPlan, applyOnboardingAnswers, needsOnboarding, buildLlmSourcePlan, describeLlmSourceStatus, resolveLlmSourceStatus, readRunView, RunViewError, renderRunViewText, writeRunViewHtml, openBrowserUrl, evaluateCheckoutFreshness, runGitCommand, BLOCKING_FRESHNESS_VERDICTS, claimServiceStack, BUSY_EXIT_CODE, checkServiceStack, releaseServiceStack, readServiceStackStatus, resolvePreferences, OnboardingBlanketChoice, PreferenceKey, applyLlmSourceSelection, LlmSource, getDataDir, DEFAULT_LOCAL_LLM_BASE_URL, isValidLocalBaseUrl } from './chunk-NFS44KNQ.js';
2
2
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema } from '@modelcontextprotocol/sdk/types.js';
4
4
  import { v4 } from 'uuid';
@@ -15,6 +15,7 @@ import { createHash } from 'crypto';
15
15
  import { platform, homedir, arch, hostname } from 'os';
16
16
  import { createInterface } from 'readline/promises';
17
17
  import { execFile, execFileSync, spawnSync } from 'child_process';
18
+ import { Writable } from 'stream';
18
19
  import { pipeline } from 'stream/promises';
19
20
  import { readFile } from 'fs/promises';
20
21
  import { verify } from 'sigstore';
@@ -1053,7 +1054,7 @@ async function resolveGsScreenshotUrls(report, opts) {
1053
1054
  if (gsUrls.length === 0) {
1054
1055
  return report;
1055
1056
  }
1056
- const mcps = await import('./src-VMHCXZNO.js');
1057
+ const mcps = await import('./src-HALLVP7O.js');
1057
1058
  const credentials = await mcps.getCallerCredentialsAsync();
1058
1059
  if (!credentials.bearerToken && !credentials.apiKey) {
1059
1060
  stderrWrite(
@@ -2133,6 +2134,7 @@ function getHelpGuidance() {
2133
2134
  "",
2134
2135
  ` ${colorize("Setup & Diagnostics:", COLORS.bold)}`,
2135
2136
  ` ${cmd("muggle init")} Explain Muggle Test and save your preferences`,
2137
+ ` ${cmd("muggle llm-source")} Choose who supplies the model for local runs`,
2136
2138
  ` ${cmd("muggle setup")} Download/update Electron app`,
2137
2139
  ` ${cmd("muggle setup --force")} Force re-download`,
2138
2140
  ` ${cmd("muggle doctor")} Diagnose installation issues`,
@@ -2687,6 +2689,114 @@ async function applyCiWorkflowPreference(preference, cwd, ask) {
2687
2689
  installCiWorkflow({ cwd, force: false });
2688
2690
  return "installed" /* Installed */;
2689
2691
  }
2692
+ function createTerminalPrompter() {
2693
+ let isEchoMuted = false;
2694
+ const echoControlledOutput = new Writable({
2695
+ write(chunk, encoding, callback) {
2696
+ if (!isEchoMuted) {
2697
+ process.stdout.write(chunk, encoding);
2698
+ }
2699
+ callback();
2700
+ }
2701
+ });
2702
+ const rl = createInterface({ input: process.stdin, output: echoControlledOutput, terminal: true });
2703
+ return {
2704
+ ask: (question) => rl.question(question),
2705
+ askHidden: async (question) => {
2706
+ process.stdout.write(question);
2707
+ isEchoMuted = true;
2708
+ try {
2709
+ return await rl.question("");
2710
+ } finally {
2711
+ isEchoMuted = false;
2712
+ process.stdout.write("\n");
2713
+ }
2714
+ },
2715
+ close: () => rl.close()
2716
+ };
2717
+ }
2718
+ async function askAnthropicApiKeySelection(prompter) {
2719
+ const apiKey = (await prompter.askHidden("Anthropic API key (input hidden; Enter to cancel): ")).trim();
2720
+ if (!apiKey) {
2721
+ return void 0;
2722
+ }
2723
+ return { source: "anthropic-api-key" /* AnthropicApiKey */, apiKey };
2724
+ }
2725
+ async function askLocalModelSelection(prompter, current, print) {
2726
+ const defaultBaseUrl = current.localBaseUrl ?? DEFAULT_LOCAL_LLM_BASE_URL;
2727
+ let localBaseUrl = "";
2728
+ while (!isValidLocalBaseUrl(localBaseUrl)) {
2729
+ localBaseUrl = (await prompter.ask(`Endpoint URL [${defaultBaseUrl}]: `)).trim() || defaultBaseUrl;
2730
+ if (!isValidLocalBaseUrl(localBaseUrl)) {
2731
+ print(`Enter an http(s) URL, e.g. ${DEFAULT_LOCAL_LLM_BASE_URL}`);
2732
+ }
2733
+ }
2734
+ const modelHint = current.localModel ? ` [${current.localModel}]` : "";
2735
+ let localModel = "";
2736
+ while (!localModel) {
2737
+ localModel = (await prompter.ask(`Vision-capable model name${modelHint}: `)).trim() || (current.localModel ?? "");
2738
+ if (!localModel) {
2739
+ print("Enter the model name the endpoint serves, e.g. qwen2.5vl.");
2740
+ }
2741
+ }
2742
+ const apiKey = (await prompter.askHidden("Endpoint API key, if it needs one (input hidden; Enter for none): ")).trim();
2743
+ return {
2744
+ source: "local-model" /* LocalModel */,
2745
+ localBaseUrl,
2746
+ localModel,
2747
+ apiKey: apiKey || void 0
2748
+ };
2749
+ }
2750
+ async function askSourceIndex(prompter, optionCount, print) {
2751
+ for (; ; ) {
2752
+ const answer = (await prompter.ask(`Choose 1-${optionCount} (press Enter to keep the current source): `)).trim();
2753
+ if (answer.length === 0) {
2754
+ return void 0;
2755
+ }
2756
+ const picked = Number.parseInt(answer, 10);
2757
+ if (Number.isInteger(picked) && picked >= 1 && picked <= optionCount) {
2758
+ return picked - 1;
2759
+ }
2760
+ print(`Enter a number between 1 and ${optionCount}.`);
2761
+ }
2762
+ }
2763
+ async function askLlmSourceSelection(prompter, plan, print = (line) => console.log(line)) {
2764
+ print("");
2765
+ print(`- ${plan.header} -`);
2766
+ print(plan.prompt);
2767
+ print(plan.scopeNote);
2768
+ plan.options.forEach((option, index) => {
2769
+ const mark = option.source === plan.current.source ? "*" : " ";
2770
+ print(` ${mark} ${index + 1}. ${option.label}`);
2771
+ print(` ${option.description}`);
2772
+ });
2773
+ print(`Current \u2014 ${describeLlmSourceStatus(plan.current)}`);
2774
+ const pickedIndex = await askSourceIndex(prompter, plan.options.length, print);
2775
+ if (pickedIndex === void 0) {
2776
+ return void 0;
2777
+ }
2778
+ const source = plan.options[pickedIndex].source;
2779
+ if (source === "muggle-credit" /* MuggleCredit */) {
2780
+ return { source };
2781
+ }
2782
+ if (source === "anthropic-api-key" /* AnthropicApiKey */) {
2783
+ return askAnthropicApiKeySelection(prompter);
2784
+ }
2785
+ return askLocalModelSelection(prompter, plan.current, print);
2786
+ }
2787
+ async function runLlmSourceStep() {
2788
+ const prompter = createTerminalPrompter();
2789
+ try {
2790
+ const selection = await askLlmSourceSelection(prompter, buildLlmSourcePlan());
2791
+ if (!selection) {
2792
+ console.log(`Kept. ${describeLlmSourceStatus(resolveLlmSourceStatus())}`);
2793
+ return;
2794
+ }
2795
+ console.log(`Saved. ${describeLlmSourceStatus(applyLlmSourceSelection(selection))}`);
2796
+ } finally {
2797
+ prompter.close();
2798
+ }
2799
+ }
2690
2800
  var ACCEPT_HINT = "press Enter to accept";
2691
2801
  function printPrimer() {
2692
2802
  const plan = buildOnboardingPlan();
@@ -2890,11 +3000,85 @@ async function initCommand(options) {
2890
3000
  if (!needsOnboarding()) {
2891
3001
  console.log("Muggle is already set up. Re-running the walkthrough \u2014 your current values are pre-selected.");
2892
3002
  }
2893
- reportOutcome(applyOnboardingAnswers(await runTerminalWalkthrough()));
3003
+ const onboardingOutcome = applyOnboardingAnswers(await runTerminalWalkthrough());
3004
+ reportOutcome(onboardingOutcome);
3005
+ if (!onboardingOutcome.skip) {
3006
+ await runLlmSourceStep();
3007
+ }
2894
3008
  await runInteractiveCiOffer();
2895
3009
  runWatchServiceOffer();
2896
3010
  }
2897
3011
 
3012
+ // src/cli/llm-source/llm-source-command.ts
3013
+ function parseLlmSource(rawSource) {
3014
+ return Object.values(LlmSource).find((source) => source === rawSource);
3015
+ }
3016
+ async function applyAnthropicKeyFromTerminal() {
3017
+ if (!process.stdin.isTTY) {
3018
+ console.error(
3019
+ "An API key is only accepted at a hidden terminal prompt \u2014 never as an argument. Run `muggle llm-source` in a terminal."
3020
+ );
3021
+ process.exitCode = 1;
3022
+ return;
3023
+ }
3024
+ const prompter = createTerminalPrompter();
3025
+ try {
3026
+ const selection = await askAnthropicApiKeySelection(prompter);
3027
+ if (!selection) {
3028
+ console.log(`Cancelled. ${describeLlmSourceStatus(resolveLlmSourceStatus())}`);
3029
+ return;
3030
+ }
3031
+ console.log(`Saved. ${describeLlmSourceStatus(applyLlmSourceSelection(selection))}`);
3032
+ } finally {
3033
+ prompter.close();
3034
+ }
3035
+ }
3036
+ async function applySourceFromFlags(options) {
3037
+ const source = parseLlmSource(options.use ?? "");
3038
+ if (!source) {
3039
+ console.error(`--use must be one of: ${Object.values(LlmSource).join(", ")}`);
3040
+ process.exitCode = 1;
3041
+ return;
3042
+ }
3043
+ if (source === "anthropic-api-key" /* AnthropicApiKey */) {
3044
+ await applyAnthropicKeyFromTerminal();
3045
+ return;
3046
+ }
3047
+ try {
3048
+ const status = applyLlmSourceSelection({
3049
+ source,
3050
+ localBaseUrl: options.baseUrl,
3051
+ localModel: options.model
3052
+ });
3053
+ console.log(`Saved. ${describeLlmSourceStatus(status)}`);
3054
+ } catch (error) {
3055
+ console.error(error instanceof Error ? error.message : String(error));
3056
+ process.exitCode = 1;
3057
+ }
3058
+ }
3059
+ async function llmSourceCommand(options) {
3060
+ if (options.json) {
3061
+ console.log(JSON.stringify(buildLlmSourcePlan(), null, 2));
3062
+ return;
3063
+ }
3064
+ if (options.show) {
3065
+ console.log(describeLlmSourceStatus(resolveLlmSourceStatus()));
3066
+ return;
3067
+ }
3068
+ if (options.use) {
3069
+ await applySourceFromFlags(options);
3070
+ return;
3071
+ }
3072
+ if (!process.stdin.isTTY) {
3073
+ console.error(
3074
+ "`muggle llm-source` needs an interactive terminal. Use `--show` to see the current source, or `--use muggle-credit` / `--use local-model --base-url <url> --model <name>` to set one."
3075
+ );
3076
+ process.exitCode = 1;
3077
+ return;
3078
+ }
3079
+ await runLlmSourceStep();
3080
+ }
3081
+
2898
3082
  // src/cli/login.ts
2899
3083
  var logger4 = getLogger();
2900
3084
  async function loginCommand(options) {
@@ -5718,6 +5902,7 @@ function createProgram() {
5718
5902
  program.name("muggle").description("Unified MCP server for Muggle AI \u2014 cloud E2E and local E2E testing").version(packageVersion);
5719
5903
  program.command("serve").description("Start the MCP server").option("--e2e", "Only enable cloud E2E tools (remote URLs; muggle-remote-* prefix)").option("--local", "Only enable local E2E tools (localhost; muggle-local-* prefix)").option("--stdio", "Use stdio transport (default)").action(serveCommand);
5720
5904
  program.command("init").description("Set up Muggle Test \u2014 explains how it works and saves your preferences").option("--json", "Emit the walkthrough as JSON instead of prompting").option("--apply <file>", "Apply answers from a JSON file").action(initCommand);
5905
+ program.command("llm-source").description("Choose who supplies the model for local runs: Muggle AI credit, your Anthropic key, or a local model").option("--show", "Print the source in effect").option("--json", "Emit the question as JSON instead of prompting").option("--use <source>", "Set a source without prompting: muggle-credit, anthropic-api-key, local-model").option("--base-url <url>", "Endpoint URL, with --use local-model").option("--model <name>", "Model served at the endpoint, with --use local-model").action(llmSourceCommand);
5721
5906
  program.command("setup").description("Download/update the Electron app for local testing").option("--force", "Force re-download even if already installed").action(setupCommand);
5722
5907
  program.command("upgrade").description("Check for and install the latest electron-app version").option("--force", "Force re-download even if already on latest").option("--check", "Check for updates only, don't download").option("--version <version>", "Download a specific version (e.g., 1.0.2)").action(upgradeCommand);
5723
5908
  program.command("versions").description("List installed electron-app versions").action(versionsCommand);