소스 검색

fix: align default user data directory with shared runtime (#188)

DanielWalnut 2 달 전
부모
커밋
7c5b742c50

+ 1 - 1
README.md

@@ -78,7 +78,7 @@ mcode login --region global
 
 Complete sign-in in your browser, then open `mcode` and use `/status` to check your account and `/provider` to choose a model. Run `mcode logout` to sign out.
 
-Token Plan requires an account with available credits. The published npm CLI `@minimax-ai/code@0.4.12` defaults to `~/.minimax` for user data; builds from this repository default to `~/.minimax-code`. `MINIMAX_DATA_DIR` or `MAVIS_DATA_DIR` can override the data directory. The installer's `~/.minimax-code` installation directory is separate from this choice. See [Accounts and data](docs/installation.md#accounts-and-data) before locating or removing configuration and sessions.
+Token Plan requires an account with available credits. Builds from this repository and the published npm CLI `@minimax-ai/code@0.4.12` default to `~/.minimax` for user data (or `~/.minimax-<profile>` when a profile is selected). `MINIMAX_DATA_DIR` or `MAVIS_DATA_DIR` can override the data directory. The installer's `~/.minimax-code` installation directory is separate from this choice. See [Accounts and data](docs/installation.md#accounts-and-data) before locating or removing configuration and sessions.
 
 <details>
 <summary>Use your own API key (BYOK)</summary>

+ 1 - 1
README_ZH.md

@@ -78,7 +78,7 @@ mcode login --region global
 
 在浏览器中完成登录,再启动 `mcode`,通过 `/status` 检查账号、通过 `/provider` 选择模型。退出登录使用 `mcode logout`。
 
-Token Plan 需要账号与可用额度。已发布的 npm CLI `@minimax-ai/code@0.4.12` 默认将用户数据保存在 `~/.minimax`;从本仓库构建的版本默认为 `~/.minimax-code`。`MINIMAX_DATA_DIR` 或 `MAVIS_DATA_DIR` 可以覆盖数据目录。安装脚本使用的 `~/.minimax-code` 安装目录与数据目录的选择是两回事。查找或删除配置和会话前,请参阅[账号与数据](docs/installation.md#accounts-and-data)。
+Token Plan 需要账号与可用额度。从本仓库构建的版本与已发布的 npm CLI `@minimax-ai/code@0.4.12` 均默认将用户数据保存在 `~/.minimax`(选择 profile 时为 `~/.minimax-<profile>`)。`MINIMAX_DATA_DIR` 或 `MAVIS_DATA_DIR` 可以覆盖数据目录。安装脚本使用的 `~/.minimax-code` 安装目录与数据目录的选择是两回事。查找或删除配置和会话前,请参阅[账号与数据](docs/installation.md#accounts-and-data)。
 
 <details>
 <summary>使用自己的 API Key(BYOK)</summary>

+ 1 - 1
SECURITY.md

@@ -10,7 +10,7 @@ Include the affected version, operating system and Node.js version, a minimal re
 
 ## Data and service boundaries
 
-- The active data directory stores login state, provider configuration (including API keys in `config.yaml`), and sessions. The published npm CLI `@minimax-ai/code@0.4.12` defaults to `~/.minimax`; builds from this repository default to `~/.minimax-code`. Environment overrides can select another directory. Follow [Accounts and data](docs/installation.md#accounts-and-data) to identify it; the installer location alone does not identify stored credentials. Restrict local access to every data directory you have used and keep them out of Git, including old profiles. They are not shareable project configuration.
+- The active data directory stores login state, provider configuration (including API keys in `config.yaml`), and sessions. Builds from this repository and the published npm CLI `@minimax-ai/code@0.4.12` default to `~/.minimax` (or `~/.minimax-<profile>` when a profile is selected). Environment overrides can select another directory. Follow [Accounts and data](docs/installation.md#accounts-and-data) to identify it; the installer location alone does not identify stored credentials. Restrict local access to every data directory you have used and keep them out of Git, including old profiles. They are not shareable project configuration.
 - Models, official plugins, connectors, search, media, feedback, and telemetry may contact external services. Those services continue to control authorization and credits; source access does not grant access to accounts or third-party resources.
 - mcode-tools obtains short-lived access tokens through the host's lease broker. Never pass refresh tokens to tool processes.
 - Permissions and sandboxing do not replace review of untrusted plugins, MCP servers, and shell commands. If automatic permission classification is unavailable, retain user confirmation rather than allowing operations by default.

+ 5 - 3
docs/installation.md

@@ -39,17 +39,19 @@ On Windows, also use `node` with the appropriate local absolute path. Do not ove
 
 Run `/login` in the TUI or `pnpm mcode login`, choosing the region for your account. Token Plan requires an account and available credits. See the root README for BYOK configuration and testing.
 
-Data-directory defaults depend on the artifact you run:
+Source builds and the published npm CLI use the same default user data directory:
 
 | CLI artifact | Default user data directory |
 | --- | --- |
 | Published npm `@minimax-ai/code@0.4.12` | `~/.minimax` |
-| Build from this repository | `~/.minimax-code` |
+| Build from this repository | `~/.minimax` |
 
-The npm 0.4.12 default was checked against the [public registry artifact](https://registry.npmjs.org/@minimax-ai/code/0.4.12) on 2026-09-19, with its SHA-512 integrity verified. This applies to that published version, including local npm dependencies; do not infer the default of another release from its version label alone. The source default is defined in [`data-dir.ts`](../packages/tui/src/runtime/data-dir.ts). Login state, provider configuration such as `config.yaml`, caches, and sessions belong to the selected data directory.
+The npm 0.4.12 default was checked against the [public registry artifact](https://registry.npmjs.org/@minimax-ai/code/0.4.12) on 2026-09-19, with its SHA-512 integrity verified. This applies to that published version, including local npm dependencies; do not infer the default of another release from its version label alone. A selected profile uses `~/.minimax-<profile>`. The source default is defined in [`data-dir.ts`](../packages/tui/src/runtime/data-dir.ts). Login state, provider configuration such as `config.yaml`, caches, and sessions belong to the selected data directory.
 
 Both accept a non-empty `MINIMAX_DATA_DIR`, falling back to a non-empty `MAVIS_DATA_DIR`, before the default. The [macOS / Linux / WSL installer](https://filecdn.minimax.chat/public/install.sh) installs the npm package under `~/.minimax-code` by default (`MCODE_INSTALL_DIR` changes the installation location). It does not set either data-directory override. Installation files and user data are separate concerns, even when their directories have the same name.
 
+Earlier source builds used `~/.minimax-code` for user data. The new default does not move or merge that data. To keep using an existing source-build data directory, explicitly set `MINIMAX_DATA_DIR` to its path.
+
 To locate data safely:
 
 1. Identify the launcher you actually use with `command -v mcode` (POSIX) or `Get-Command mcode -All` (PowerShell), and run that launcher's `--version`. For a local npm dependency, use `node_modules/.bin/mcode --version`; a global npm listing does not identify it. A source build may report the same version as the npm release.

+ 1 - 1
docs/telemetry.md

@@ -4,7 +4,7 @@ All automatic telemetry uploads are disabled by default and each requires its ow
 
 ## Turn it on or off
 
-Add this to the active profile's `config.yaml`, then restart MCode. Builds from this repository default to `~/.minimax-code/config.yaml`; the published npm CLI `@minimax-ai/code@0.4.12` defaults to `~/.minimax/config.yaml`. Overrides can change this path; see [Accounts and data](installation.md#accounts-and-data) to locate it. The telemetry controls below describe this repository's source build and are not a guarantee of feature parity with that npm release.
+Add this to the active profile's `config.yaml`, then restart MCode. Builds from this repository and the published npm CLI `@minimax-ai/code@0.4.12` default to `~/.minimax/config.yaml` (or `~/.minimax-<profile>/config.yaml` when a profile is selected). Overrides can change this path; see [Accounts and data](installation.md#accounts-and-data) to locate it. The telemetry controls below describe this repository's source build and are not a guarantee of feature parity with that npm release.
 
 ```yaml
 telemetry:

+ 3 - 3
packages/tui/docs/status-line-config.md

@@ -15,7 +15,7 @@ Open `/statusline` to configure ordinary items:
 - Both regular and fullscreen modes adapt the panel to available height. Small windows prioritize search, the selected option, and save / cancel hints.
 - The panel is unavailable during pending permission / question interactions and in side sessions. It may open during ordinary execution without sending a model request.
 
-The panel manages ordinary items only. For automation, edit the current profile's `config.yaml` (default in this distribution: `~/.minimax-code/config.yaml`):
+The panel manages ordinary items only. For automation, edit the current profile's `config.yaml` (default in this distribution: `~/.minimax/config.yaml`):
 
 ```yaml
 tui:
@@ -27,7 +27,7 @@ Restart mcode after saving to enable the `[V]` line. `build-mode` is not in the
 
 ## Configuration location
 
-- File: `config.yaml` in the runtime data directory, normally `~/.minimax-code/config.yaml`.
+- File: `config.yaml` in the runtime data directory, normally `~/.minimax/config.yaml`.
 - Key: `tui.statusLine`, a **string array** of item IDs.
 - List order is display order, left to right. Items not listed are hidden.
 
@@ -243,7 +243,7 @@ A command may ignore stdin. stdout is accepted only after exit code `0` without
 - A deterministic selection changes every 30-second time bucket, using existing redraws rather than a dedicated timer. An idle terminal does not redraw merely to rotate tips; the next normal redraw selects the current bucket.
 - Left-side composer mode and action hints remain stable. Prefer a full tip, then a short version, then hide it if space is insufficient.
 - Welcome, active execution, follow-ups, goals, permission / question interactions, attachments, nonempty drafts, and temporary hints take precedence and suppress tips.
-- Tips are enabled by default. Disable them in `~/.minimax-code/config.yaml`:
+- Tips are enabled by default. Disable them in `~/.minimax/config.yaml`:
 
 ```yaml
 tui:

+ 7 - 4
packages/tui/src/runtime/data-dir.ts

@@ -1,5 +1,4 @@
-import { homedir } from 'node:os';
-import { join } from 'node:path';
+import { getPrimaryDataDirPath, getProfile } from '@mavis/config';
 import { resolveMcodeDataEnvironment, type McodeDataEnvironment } from '../auth/environment.js';
 import { configureTuiRuntimeEnvironment } from '../cli/environment.js';
 
@@ -17,8 +16,12 @@ export interface PrepareTuiDataDirOptions {
   configureRuntimeEnvironment?: typeof configureTuiRuntimeEnvironment;
 }
 
-export function resolveDefaultTuiDataDir(_buildEnv: McodeDataEnvironment): string {
-  return join(homedir(), '.minimax-code');
+export function resolveDefaultTuiDataDir(
+  _buildEnv: McodeDataEnvironment,
+  getPrimaryDataDir: typeof getPrimaryDataDirPath = getPrimaryDataDirPath,
+  getCurrentProfile: typeof getProfile = getProfile,
+): string {
+  return getPrimaryDataDir(undefined, getCurrentProfile());
 }
 
 function getDefaultTuiDataDir(): string {

+ 44 - 0
packages/tui/test/unit/runtime-data-dir.test.ts

@@ -0,0 +1,44 @@
+import { homedir } from 'node:os';
+import { join } from 'node:path';
+import { describe, expect, it, vi } from 'vitest';
+import {
+  getTuiDataDirPath,
+  prepareTuiDataDir,
+  resolveDefaultTuiDataDir,
+} from '../../src/runtime/data-dir.js';
+
+describe('TUI data directory', () => {
+  it.each(['dev', 'test', 'staging', 'prod'] as const)(
+    'uses the shared user directory for %s builds',
+    (buildEnv) => {
+      expect(resolveDefaultTuiDataDir(buildEnv, undefined, () => null)).toBe(
+        join(homedir(), '.minimax'),
+      );
+    },
+  );
+
+  it('keeps the shared profile suffix', () => {
+    expect(resolveDefaultTuiDataDir('prod', undefined, () => 'smoke')).toBe(
+      join(homedir(), '.minimax-smoke'),
+    );
+  });
+
+  it.each([
+    [{}, '/default'],
+    [{ MINIMAX_DATA_DIR: '  ', MAVIS_DATA_DIR: ' ' }, '/default'],
+    [{ MINIMAX_DATA_DIR: ' /public ', MAVIS_DATA_DIR: '/legacy' }, '/public'],
+    [{ MINIMAX_DATA_DIR: ' ', MAVIS_DATA_DIR: ' /legacy ' }, '/legacy'],
+  ])('preserves override precedence for %j', (environment, expected) => {
+    expect(getTuiDataDirPath(environment, () => '/default')).toBe(expected);
+  });
+
+  it('passes the selected directory to runtime initialization', async () => {
+    const configureRuntimeEnvironment = vi.fn();
+    await expect(prepareTuiDataDir({
+      environment: { MINIMAX_DATA_DIR: ' /selected ' },
+      getBuildEnv: () => 'prod',
+      configureRuntimeEnvironment,
+    })).resolves.toBe('/selected');
+    expect(configureRuntimeEnvironment).toHaveBeenCalledWith({ dataDir: '/selected' });
+  });
+});

+ 1 - 0
release/public-source.json

@@ -3217,6 +3217,7 @@
     "packages/tui/test/unit/provider-application.test.ts",
     "packages/tui/test/unit/run-coordinator-usage.test.ts",
     "packages/tui/test/unit/run-coordinator.test.ts",
+    "packages/tui/test/unit/runtime-data-dir.test.ts",
     "packages/tui/test/unit/runtime-event-normalizer.test.ts",
     "packages/tui/test/unit/runtime-feedback-diagnostic-upload.test.ts",
     "packages/tui/test/unit/runtime-feedback-service.test.ts",

+ 31 - 1
test/smoke.test.mjs

@@ -1,7 +1,7 @@
 import test from "node:test";
 import assert from "node:assert/strict";
 import { spawn, spawnSync } from "node:child_process";
-import { mkdtempSync, rmSync, readFileSync, existsSync, writeFileSync, chmodSync, statSync } from "node:fs";
+import { mkdirSync, mkdtempSync, rmSync, readFileSync, existsSync, writeFileSync, chmodSync, statSync } from "node:fs";
 import { tmpdir } from "node:os";
 import path from "node:path";
 import { fileURLToPath } from "node:url";
@@ -66,6 +66,36 @@ test("CLI version and command help work outside the source directory", (t) => {
     assert.ok(result.stdout.includes(expected), result.stdout);
   }
 });
+test("CLI defaults to the shared user config without migrating the old source directory", (t) => {
+  const options = fixture(t);
+  const home = options.cwd;
+  const config = path.join(home, ".minimax", "config.yaml");
+  const oldConfig = path.join(home, ".minimax-code", "config.yaml");
+  for (const file of [config, oldConfig]) mkdirSync(path.dirname(file));
+  writeFileSync(config, "telemetry:\n  enabled: true\n", { mode: 0o600 });
+  const oldContents = "telemetry:\n  enabled: false\n";
+  writeFileSync(oldConfig, oldContents, { mode: 0o600 });
+  for (const name of Object.keys(options.env)) {
+    if (name.startsWith("__MAVIS_RUNTIME")) delete options.env[name];
+  }
+  delete options.env.MINIMAX_DATA_DIR;
+  delete options.env.MAVIS_DATA_DIR;
+  Object.assign(options.env, {
+    HOME: home,
+    USERPROFILE: home,
+    MCODE_DISABLE_TELEMETRY: "1",
+  });
+  const result = spawnSync(process.execPath, [cli, "telemetry", "status"], {
+    ...options,
+    encoding: "utf8",
+    timeout: runtimeTimeoutMs,
+  });
+  assertSuccessfulChild(result);
+  const status = JSON.parse(result.stdout);
+  assert.equal(status.configFile, config);
+  assert.equal(status.configured, true);
+  assert.equal(readFileSync(oldConfig, "utf8"), oldContents);
+});
 test("provider configuration loads from an isolated data directory", (t) => {
   const result = spawnSync(process.execPath, [cli, "provider", "list"], {
     ...fixture(t),

+ 1 - 0
test/vitest-suites.json

@@ -63,6 +63,7 @@
       "packages/local-runtime/test/unit/local-background-task-task-output-polling-reminder.test.ts",
       "packages/mcode-tools-host/test/unit/resource-manifest.test.ts",
       "packages/tui/test/unit/headless-config.test.ts",
+      "packages/tui/test/unit/runtime-data-dir.test.ts",
       "packages/tui/test/unit/headless-contract.test.ts",
       "packages/tui/test/unit/headless-invocation.test.ts",
       "packages/tui/test/unit/headless-model-selection.test.ts",