Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mmx config export-schema | jq .

### `mmx agent setup`

Configure MiniMax for Claude Code, Codex, Grok Build, OpenCode, Hermes, Pi, [Oh my Pi](https://github.com/can1357/oh-my-pi), or Zed while preserving unrelated settings. Run without options for the interactive wizard; supplying options makes the command non-interactive and suitable for scripts.
Configure MiniMax for Claude Code, Codex, Grok Build, OpenCode, Hermes, Pi, [Oh my Pi](https://github.com/can1357/oh-my-pi), Zed, or DeepSeek Harness while preserving unrelated settings. Run without options for the interactive wizard; supplying options makes the command non-interactive and suitable for scripts.

```bash
mmx agent setup
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mmx config export-schema | jq .

### `mmx agent setup`

一键为 Claude Code、Codex、Grok Build、OpenCode、Hermes、Pi、[Oh my Pi](https://github.com/can1357/oh-my-pi) 或 Zed 配置 MiniMax,并保留配置文件中的其他设置。不带选项时进入交互式向导;带选项时自动使用非交互模式,便于脚本调用。
一键为 Claude Code、Codex、Grok Build、OpenCode、Hermes、Pi、[Oh my Pi](https://github.com/can1357/oh-my-pi)、Zed 或 DeepSeek Harness 配置 MiniMax,并保留配置文件中的其他设置。不带选项时进入交互式向导;带选项时自动使用非交互模式,便于脚本调用。

```bash
mmx agent setup
Expand Down
1 change: 1 addition & 0 deletions src/agent/availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const AGENT_EXECUTABLES: Record<AgentId, readonly string[]> = {
pi: ['pi'],
'oh-my-pi': ['omp'],
zed: ['zed', 'zeditor'],
'deepseek-harness': ['dsh'],
};

const AGENT_RUNTIME_MARKERS: Partial<Record<AgentId, readonly [string, string]>> = {
Expand Down
188 changes: 187 additions & 1 deletion src/agent/configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
type ParseError,
} from 'jsonc-parser/lib/esm/main.js';
import { parse as parseToml } from 'smol-toml';
import { parseDocument } from 'yaml';
import { isMap, isSeq, parseDocument, type Document } from 'yaml';

import { CLIError } from '../errors/base';
import { ExitCode } from '../errors/codes';
Expand Down Expand Up @@ -156,6 +156,8 @@ function configPathsForAgent(
}
case 'oh-my-pi':
return ohMyPiConfigPaths(home, env);
case 'deepseek-harness':
return [...dshProfilePaths(options), join(dshHome(options), '.credentials.yaml')];
case 'zed': {
// Mirrors Zed's paths::config_dir().
if (process.platform === 'win32') {
Expand Down Expand Up @@ -1137,6 +1139,187 @@ function prepareZed(options: AgentSetupOptions, path: string): PreparedAgentFile
return [{ agent: 'zed', path, ...prepared, after: updateJsonc(prepared.before, label, updates) }];
}

const DSH_PROFILE_PATCH_TEMPLATE = `# Your patch layer for this dsh profile, applied after every bundle layer:
# a top-level YAML array of loader patch entries (id-targeted config
# overrides, disables, and insert lists; \`!!js\` expressions allowed).
[]
`;
const DSH_ALWAYS_PROFILES = ['web', 'desktop'];
const DSH_OPTIONAL_PROFILES = ['headless', 'acp'];
const DSH_REASONING_EFFORTS = {
low: 'low',
medium: 'medium',
high: 'high',
xhigh: 'xhigh',
max: 'max',
};

function dshHome(options: AgentSetupOptions): string {
const home = options.homeDir ?? homedir();
const env = options.env ?? process.env;
return pathFromOverride(env.DSH_HOME, join(home, '.dsh'), home);
}

function dshProfilePaths(options: AgentSetupOptions): string[] {
const root = join(dshHome(options), 'profiles');
const paths: string[] = [];
const seen = new Set<string>();
for (const name of [...DSH_ALWAYS_PROFILES, ...DSH_OPTIONAL_PROFILES]) {
const path = join(root, name, 'cordis.patch.yml');
if (DSH_OPTIONAL_PROFILES.includes(name) && !existsSync(path)) continue;
const target = writeTarget(path);
if (seen.has(target)) continue;
seen.add(target);
paths.push(path);
}
return paths;
}

function parseDshDocument(before: string | null, label: string, empty: string): Document {
const document = parseDocument(before ?? empty);
if (document.errors.length > 0) {
throw new CLIError(
`${label} is not valid YAML: ${document.errors[0]?.message ?? 'parse error'}`,
ExitCode.GENERAL,
INVALID_CONFIG_HINT,
);
}
return document;
}

function dshPatchIndexes(document: Document, id: string): number[] {
if (!isSeq(document.contents)) return [];
const found: number[] = [];
document.contents.items.forEach((item, index) => {
if (isMap(item) && item.get('id') === id) found.push(index);
});
return found;
}

function ensureDshPatchEntry(document: Document, id: string, label: string): number {
if (document.contents === null) {
document.contents = document.createNode([]);
}
if (!isSeq(document.contents)) {
throw new CLIError(`${label} must be a YAML sequence.`, ExitCode.GENERAL, INVALID_CONFIG_HINT);
}
if (document.contents.items.length === 0) document.contents.flow = false;
const found = dshPatchIndexes(document, id);
if (found.length > 1) {
throw new CLIError(`${label} has duplicate ${id} overrides.`, ExitCode.GENERAL, INVALID_CONFIG_HINT);
}
if (found.length === 1) return found[0]!;
document.add(document.createNode({ id, config: {} }));
return document.contents.items.length - 1;
}

function dshModels() {
return ['MiniMax-M4', 'MiniMax-M3.1-Flash'].map(id => ({
id,
name: id,
contextWindow: 1_000_000,
maxTokens: 131072,
input: ['text', 'image'],
reasoningEfforts: { ...DSH_REASONING_EFFORTS },
}));
}

function upsertDshModels(document: Document, path: Array<string | number>, models: ReturnType<typeof dshModels>, label: string): void {
const existing = document.getIn(path);
if (existing === undefined) {
document.setIn(path, document.createNode(models));
return;
}
if (!isSeq(existing)) {
throw new CLIError(`${label} models must be an array.`, ExitCode.GENERAL, INVALID_CONFIG_HINT);
}
for (const model of models) {
const index = existing.items.findIndex(item => isMap(item) && item.get('id') === model.id);
if (index < 0) {
existing.add(document.createNode(model));
continue;
}
for (const [key, value] of Object.entries(model)) {
document.setIn([...path, index, key], document.createNode(value));
}
}
}

function updateDshPatch(before: string | null, options: AgentSetupOptions, path: string): string {
const label = 'DeepSeek Harness cordis.patch.yml';
const document = parseDshDocument(before, label, DSH_PROFILE_PATCH_TEMPLATE);
const providerId = options.region === 'cn' ? 'minimax-cn' : 'minimax';
const apiKeyEnv = options.region === 'cn' ? 'MINIMAX_CN_API_KEY' : 'MINIMAX_API_KEY';
const index = ensureDshPatchEntry(document, 'llm-pi-ai', label);
const providers = document.getIn([index, 'config', 'providers']);
if (providers !== undefined && !isMap(providers)) {
throw new CLIError(`${label} providers must be a mapping.`, ExitCode.GENERAL, INVALID_CONFIG_HINT);
}
const providerPath = [index, 'config', 'providers', providerId];
const provider = document.getIn(providerPath);
if (provider !== undefined && !isMap(provider)) {
throw new CLIError(`${label} providers.${providerId} must be a mapping.`, ExitCode.GENERAL, INVALID_CONFIG_HINT);
}
document.setIn([...providerPath, 'displayName'], options.region === 'cn' ? 'MiniMax' : 'MiniMax en');
document.setIn([...providerPath, 'apiKeyEnv'], apiKeyEnv);
document.setIn([...providerPath, 'api'], 'openai-completions');
document.setIn([...providerPath, 'baseURL'], endpointsForRegion(options.region).openai);
upsertDshModels(document, [...providerPath, 'models'], dshModels(), label);

const defaultIndex = ensureDshPatchEntry(document, 'agent-default-model', label);
document.setIn([defaultIndex, 'config', 'provider'], providerId);
document.setIn([defaultIndex, 'config', 'model'], options.model);

if (basename(dirname(path)) === 'headless'
&& dshPatchIndexes(document, 'credentials').length === 0) {
document.add(document.createNode({ id: 'credentials', disabled: false }));
}
return document.toString();
}

function updateDshCredentials(before: string | null, options: AgentSetupOptions): string {
const label = 'DeepSeek Harness .credentials.yaml';
const document = parseDshDocument(before, label, 'version: 1\nrefs: {}\n');
if (document.contents === null) {
document.contents = document.createNode({ version: 1, refs: {} });
}
if (!isMap(document.contents) || document.get('version') !== 1) {
throw new CLIError(
`${label} is not a version 1 credential document.`,
ExitCode.GENERAL,
INVALID_CONFIG_HINT,
);
}
const refs = document.get('refs');
if (refs !== undefined && refs !== null && !isMap(refs)) {
throw new CLIError(`${label} refs must be a mapping.`, ExitCode.GENERAL, INVALID_CONFIG_HINT);
}
const apiKeyEnv = options.region === 'cn' ? 'MINIMAX_CN_API_KEY' : 'MINIMAX_API_KEY';
document.setIn(['refs', apiKeyEnv], options.apiKey);
return document.toString();
}

function prepareDeepseekHarness(options: AgentSetupOptions): PreparedAgentFile[] {
const prepared: PreparedAgentFile[] = dshProfilePaths(options).map((path) => {
const existing = readPrepared(path);
return {
agent: 'deepseek-harness',
path,
...existing,
after: updateDshPatch(existing.before, options, path),
};
});
const credentialsPath = join(dshHome(options), '.credentials.yaml');
const credentials = readPrepared(credentialsPath);
prepared.push({
agent: 'deepseek-harness',
path: credentialsPath,
...credentials,
after: updateDshCredentials(credentials.before, options),
});
return prepared;
}

export function prepareAgentConfigurations(options: AgentSetupOptions): PreparedAgentFile[] {
const prepared: PreparedAgentFile[] = [];
for (const agent of options.agents) {
Expand Down Expand Up @@ -1166,6 +1349,9 @@ export function prepareAgentConfigurations(options: AgentSetupOptions): Prepared
case 'zed':
prepared.push(...prepareZed(options, paths[0]!));
break;
case 'deepseek-harness':
prepared.push(...prepareDeepseekHarness(options));
break;
}
}
assertDistinctConfigurationTargets(prepared);
Expand Down
9 changes: 8 additions & 1 deletion src/agent/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExitCode } from '../errors/codes';
import type { AgentId } from './types';

type NpmAgentId = Extract<AgentId, 'codex' | 'opencode' | 'pi'>;
type ScriptAgentId = Exclude<AgentId, NpmAgentId | 'zed'>;
type ScriptAgentId = Exclude<AgentId, NpmAgentId | 'zed' | 'deepseek-harness'>;

const NPM_PACKAGES: Record<NpmAgentId, string> = {
codex: '@openai/codex',
Expand Down Expand Up @@ -127,6 +127,7 @@ export function getAgentInstallIssue(
?? ((executable: string) => defaultCommandExists(executable, platform));

if (agent === 'zed') return 'Install Zed from https://zed.dev/download.';
if (agent === 'deepseek-harness') return 'Install DeepSeek Harness with npm install -g @deepseek-ai/dsh.';
if (!SUPPORTED_PLATFORMS.has(platform)) {
return `Automated installation is not supported on ${platform}.`;
}
Expand Down Expand Up @@ -228,6 +229,9 @@ export function getAgentInstallCommand(
if (agent === 'zed') {
throw new CLIError('Install Zed from https://zed.dev/download.', ExitCode.USAGE);
}
if (agent === 'deepseek-harness') {
throw new CLIError('Install DeepSeek Harness with npm install -g @deepseek-ai/dsh.', ExitCode.USAGE);
}

const args = [
'install',
Expand Down Expand Up @@ -301,6 +305,9 @@ export function getAgentVerificationCommand(
if (agent === 'zed') {
return { executable: 'zed', args: ['--version'], display: 'zed --version' };
}
if (agent === 'deepseek-harness') {
return { executable: 'dsh', args: ['--version'], display: 'dsh --version' };
}
const display = `${AGENT_EXECUTABLES[agent]} --version`;
if (platform === 'win32') {
return {
Expand Down
1 change: 1 addition & 0 deletions src/agent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const AGENT_IDS = [
'pi',
'oh-my-pi',
'zed',
'deepseek-harness',
] as const;

export type AgentId = typeof AGENT_IDS[number];
Expand Down
5 changes: 4 additions & 1 deletion src/commands/agent/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const AGENT_ALIASES: Record<string, AgentId> = {
'oh-my-pi': 'oh-my-pi',
omp: 'oh-my-pi',
zed: 'zed',
'deepseek-harness': 'deepseek-harness',
dsh: 'deepseek-harness',
};

const AGENT_LABELS: Record<AgentId, string> = {
Expand All @@ -67,6 +69,7 @@ const AGENT_LABELS: Record<AgentId, string> = {
pi: 'Pi',
'oh-my-pi': 'Oh my Pi (omp)',
zed: 'Zed',
'deepseek-harness': 'DeepSeek Harness',
};
// Zed keeps provider keys in the OS keychain or the MINIMAX_API_KEY environment variable.
const ZED_API_KEY_HINT = 'Zed: paste your MiniMax API key in Agent Panel > Settings > minimax, '
Expand Down Expand Up @@ -482,7 +485,7 @@ export default defineCommand({
options: [
{
flag: '--agent <name>',
description: 'Agent: claude-code, codex, grok/grok-build, opencode, hermes, pi, oh-my-pi/omp, zed (repeatable)',
description: 'Agent: claude-code, codex, grok/grok-build, opencode, hermes, pi, oh-my-pi/omp, zed, deepseek-harness/dsh (repeatable)',
type: 'array',
},
{
Expand Down
Loading
Loading