# Files changed · PR \#23891 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/23891/diffs)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

[fix\(acp-registry\): offer Global MiniMax Code sign-in](https://git.cafe/pingdotgg/t3code/pull/23891.md)

Version: 10

Head commit: dd61206ecae7e4b19c2e2f98a1bfcff4b9c04cca

Base commit: 200dad3b39aa9c2562b4bae54106ab8acdcc4163

Comparison base: 52bb5c8c4e0908e4ef10428c12258be55b964f39

Showing up to 20 entries from this revision. If the pull request changes, reopen the first page before continuing.

## knip.jsonc

Status: modified; +2; −0

```diff
@@ -24,6 +24,8 @@
       "entry": [
         // These fixture scripts are injected into a browser page by path.
         "fixtures/issue-16534/*.js",
+        // Run by hand to seed MiniMax auth into an isolated T3 home.
+        "fixtures/minimax-auth.mjs",
         "knip-schemas.ts",
         "mobile-native-client.ts",
         "setup-worktree.ts",
```

## packages/provider-acp-registry/src/server/auth.test.ts

Status: modified; +28; −0

```diff
@@ -345,3 +345,31 @@
     assert.isTrue(h.killed());
   }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
 );
+
+it.effect("offers MiniMax Code's Global region alongside its Mainland China default login", () =>
+  Effect.gen(function* () {
+    // mcode advertises one terminal method whose `login` defaults to mainland
+    // China; its CLI selects a Global account with `--region global`.
+    const h = yield* makeHarness(
+      {
+        id: "minimax-code-login",
+        name: "Sign in to MiniMax Code",
+        type: "terminal",
+        args: ["login"],
+      },
+      false,
+      decodeSettings({ agentId: "minimax-code" }),
+    );
+    const { methods = [] } = yield* h.state((value) => (value.methods?.length ?? 0) > 0);
+    const global = methods.find((method) => /global/i.test(method.name));
+    assert.isDefined(global, `no Global sign-in among ${JSON.stringify(methods)}`);
+    // The advertised ID stays the Mainland China login so saved authMethodId values keep working.
+    assert.deepEqual(
+      methods.map((method) => method.id),
+      [global!.id, "minimax-code-login"],
+    );
+    yield* h.controller.start("owner", Effect.void, global!.id);
+    yield* h.phase("waiting");
+    assert.deepEqual(h.terminalSpawn()?.args, ["--acp", "login", "--region", "global"]);
+  }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
+);
```

## packages/provider-acp-registry/src/server/auth.ts

Status: modified; +7; −2

```diff
@@ -19,6 +19,7 @@
 import * as ProviderAuthFlow from "@t3tools/provider-core/server/providerAuthFlow";
 import { normalizeAcpRegistryAuthMethods, normalizeAcpRegistryWebUrl } from "./probe.ts";
 import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
+import { withMinimaxCodeRegions } from "./minimaxCodeAcp.ts";
 import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts";
 import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
 
@@ -116,7 +117,9 @@
             failure("methods", "Could not discover this agent's sign-in methods.", cause),
           ),
         );
+      const advertised = normalizeAcpRegistryAuthMethods(
+        withMinimaxCodeRegions(initialized.authMethods),
-      const advertised = normalizeAcpRegistryAuthMethods(initialized.authMethods)
+      )
         .filter(
           (method) => method.id.length <= 128 && (method.type !== "terminal" || Option.isSome(pty)),
         )
@@ -274,7 +277,9 @@
               failure("start", "Could not initialize the selected ACP agent.", cause),
             ),
           );
-        const method = initialized.authMethods?.find((method) => method.id === methodId);
+        const method = withMinimaxCodeRegions(initialized.authMethods)?.find(
+          (method) => method.id === methodId,
+        );
         if (!method)
           return yield* failure("start", "The agent no longer advertises this sign-in method.");
         if (method.type === "terminal") {
```

## packages/provider-acp-registry/src/server/minimaxCodeAcp.ts

Status: added; +37; −0

```diff
@@ -1,0 +1,37 @@
+import type * as AcpSchema from "effect-acp/compat";
+
+const MINIMAX_CODE_LOGIN = "minimax-code-login";
+
+// mcode advertises one terminal login. Without `--region` it reuses the saved
+// account's region or falls back to Mainland China, so Global accounts could
+// not sign in. Offer both regions, keeping the advertised ID for Mainland China
+// so a configured authMethodId still selects the same login.
+export function withMinimaxCodeRegions(
+  methods: ReadonlyArray<AcpSchema.AuthMethod> | undefined,
+): ReadonlyArray<AcpSchema.AuthMethod> | undefined {
+  const login = methods?.find((method) => method.id === MINIMAX_CODE_LOGIN);
+  if (
+    methods === undefined ||
+    login?.type !== "terminal" ||
+    methods.some((method) => method.type === "terminal" && method.args?.includes("--region"))
+  )
+    return methods;
+  const args = login.args ?? [];
+  return methods.flatMap((method) =>
+    method === login
+      ? [
+          {
+            ...login,
+            id: `${MINIMAX_CODE_LOGIN}:global`,
+            name: `${login.name} (Global)`,
+            args: [...args, "--region", "global"],
+          },
+          {
+            ...login,
+            name: `${login.name} (Mainland China)`,
+            args: [...args, "--region", "cn"],
+          },
+        ]
+      : [method],
+  );
+}
```

## scripts/fixtures/minimax-auth.mjs

Status: added; +59; −0

```diff
@@ -1,0 +1,59 @@
+import * as NodeFSP from "node:fs/promises";
+import * as NodeOS from "node:os";
+import * as NodePath from "node:path";
+
+const base = process.argv[2];
+if (!base) throw new Error("Usage: node scripts/fixtures/minimax-auth.mjs <isolated-t3-home>");
+// Resolve symlinks through the deepest existing ancestor so neither a linked
+// live home nor a not-yet-created path can alias ~/.t3 before anything is written.
+const canonical = async (path) => {
+  const absolute = NodePath.resolve(path);
+  try {
+    return await NodeFSP.realpath(absolute);
+  } catch (error) {
+    const parent = NodePath.dirname(absolute);
+    if (error.code !== "ENOENT" || parent === absolute) throw error;
+    return NodePath.join(await canonical(parent), NodePath.basename(absolute));
+  }
+};
+const resolved = await canonical(base);
+const live = NodePath.join(NodeOS.homedir(), ".t3");
+if (resolved === (await canonical(live))) throw new Error("Refusing the live T3 home");
+const userdata = NodePath.join(resolved, "userdata");
+const file = NodePath.join(userdata, "settings.json");
+// A linked userdata directory or settings file can still alias the live settings.
+if ((await canonical(file)) === (await canonical(NodePath.join(live, "userdata", "settings.json"))))
+  throw new Error("Refusing the live T3 settings");
+await NodeFSP.mkdir(resolved, { recursive: true });
+const readJson = async (file) => {
+  try {
+    return JSON.parse(await NodeFSP.readFile(file, "utf8"));
+  } catch (error) {
+    if (error.code === "ENOENT") return {};
+    throw error;
+  }
+};
+const runtime = await readJson(NodePath.join(userdata, "server-runtime.json"));
+if (runtime.pid) {
+  let running = true;
+  try {
+    process.kill(runtime.pid, 0);
+  } catch (error) {
+    if (error.code === "ESRCH") running = false;
+    else throw error;
+  }
+  if (running) throw new Error("Stop the isolated server before seeding settings");
+}
+const settings = await readJson(file);
+settings.providerInstances ??= {};
+settings.providerInstances.acpRegistry_minimax_code = {
+  driver: "acpRegistry",
+  displayName: "MiniMax Code",
+  enabled: true,
+  config: { agentId: "minimax-code", distribution: "auto" },
+};
+await NodeFSP.mkdir(userdata, { recursive: true });
+await NodeFSP.writeFile(file, `${JSON.stringify(settings, null, 2)}\n`);
+console.log(
+  "Seeded unauthenticated MiniMax configuration; install mcode 0.2.7 in this isolated home before capture. No credentials are seeded.",
+);
```
