@minimax-ai/code 0.4.7 → 0.4.8

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/CHANGELOG.zh-CN.md +20 -0
  3. package/README.zh-CN.md +7 -0
  4. package/assets/agents/_v2/explore.md.hbs +8 -0
  5. package/assets/agents/explore/agent.md +1 -0
  6. package/assets/agents/explore/system-prompt.md.hbs +9 -0
  7. package/assets/agents/mavis/features/delegation.md.hbs +4 -2
  8. package/chunks/{anthropic-LCJD7NOY.js → anthropic-MQQCIUHP.js} +1 -1
  9. package/chunks/{application-OZ6YEJNG.js → application-6MCV7ILB.js} +1 -1
  10. package/chunks/{auth-command-TP25VHV4.js → auth-command-T5DRRUNT.js} +1 -1
  11. package/chunks/{chunk-BNU46XHR.js → chunk-2CEKQTMO.js} +1 -1
  12. package/chunks/{chunk-RPO5CDCP.js → chunk-3V6OPTHM.js} +9 -9
  13. package/chunks/{chunk-C2OVBAOI.js → chunk-DIMUZAUA.js} +1 -1
  14. package/chunks/{chunk-2SW3R5AB.js → chunk-DV5WIEGS.js} +1 -1
  15. package/chunks/{chunk-YBZTB54I.js → chunk-E6MMSL54.js} +649 -646
  16. package/chunks/{chunk-SYLCIHHV.js → chunk-HMP2XYHW.js} +1 -1
  17. package/chunks/{chunk-OVLV6FQA.js → chunk-LOASZMQB.js} +531 -531
  18. package/chunks/{chunk-W7JHDTPW.js → chunk-VCJI7AJO.js} +1 -1
  19. package/chunks/{chunk-QJWOGW27.js → chunk-VPHVKGPT.js} +1 -1
  20. package/chunks/{chunk-22LVIQ2T.js → chunk-WAVNKSSE.js} +1 -1
  21. package/chunks/{chunk-NELAOQAA.js → chunk-X5PAB4UH.js} +2 -2
  22. package/chunks/chunk-Z44TXDGK.js +50 -0
  23. package/chunks/{chunk-KVMK6REW.js → chunk-ZCP4JGO4.js} +1 -1
  24. package/chunks/{chunk-AJSGEEWR.js → chunk-ZRZKBTCU.js} +1 -1
  25. package/chunks/{data-dir-KTXCGPJZ.js → data-dir-YVQZ5MXP.js} +1 -1
  26. package/chunks/{dist-MM7GHB2J.js → dist-N5YYFCWT.js} +1 -1
  27. package/chunks/{dist-XS6VO2LU.js → dist-Z3PYNW6P.js} +1 -1
  28. package/chunks/{install-source-3CE52ZIN.js → install-source-GWYHWTTG.js} +1 -1
  29. package/chunks/{launcher-BNIFOBXD.js → launcher-NIEXEZF5.js} +134 -134
  30. package/chunks/{lifecycle-EKT5LQIE.js → lifecycle-EEX754QU.js} +1 -1
  31. package/chunks/{main-FAPYW7S4.js → main-ANDH2IE5.js} +3 -3
  32. package/chunks/{plugin-command-TD3DWK7U.js → plugin-command-STBEQNGX.js} +1 -1
  33. package/chunks/{provider-command-AQPDCWDR.js → provider-command-MKVRALX5.js} +1 -1
  34. package/chunks/{run-acp-command-OPS4CBHL.js → run-acp-command-2AEYGDBH.js} +2 -2
  35. package/chunks/{run-exec-command-QR3TWWDO.js → run-exec-command-LVG3YSVK.js} +1 -1
  36. package/chunks/{update-KWS4AOND.js → update-CG3K6TMW.js} +1 -1
  37. package/cli.js +2 -2
  38. package/image-preview-worker.js +1 -1
  39. package/package.json +1 -1
  40. package/chunks/chunk-B2NJMA4I.js +0 -50
package/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ This changelog covers important changes that directly affect MCode TUI users. It
7
7
 
8
8
  Internal refactors, test-only changes, and changes limited to other product surfaces are excluded.
9
9
 
10
+ ## 0.4.8 · 2026-09-16
11
+
12
+ ### Added
13
+
14
+ - Explore subagents can run foreground Bash commands to inspect code and Git state, with a
15
+ read-only filesystem policy when sandboxing is available.
16
+
17
+ ### Improved
18
+
19
+ - Improved content review handling with guided response regeneration and fixed replies when
20
+ applicable, while retracting blocked drafts.
21
+ - Improved responsiveness when previewing very long thinking output, while keeping the full text
22
+ available in expanded details.
23
+ - Unified elapsed time in the running status, turn summary, and Goal display using `s`, `min`, and
24
+ `h`, retaining seconds for runs longer than an hour.
25
+
26
+ ### Fixed
27
+
28
+ - Restored the thinking toggle for capable custom provider models without changing their existing
29
+ effective thinking defaults.
30
+ - Fixed startup failures when custom agents conflict with built-in agent names, preserving custom
31
+ configuration during migration.
32
+ - Improved cancellation of streaming responses from compatible providers so interrupted reads can finish
33
+ promptly.
34
+ - Restored editable image labels when editing a previous message with double Esc or `/edit`.
35
+ Images can be removed, restored with undo, previewed when a local file is available, and resent.
36
+ - Fixed attachment validation errors when sending images or files during an active run, and
37
+ prevented accepted attachments from being lost when temporary draft files are cleaned up.
38
+
10
39
  ## 0.4.7 · 2026-09-15
11
40
 
12
41
  ### Added
@@ -8,6 +8,26 @@ TUI 正式版中用户能直接感知的重要变化。收录范围以 TUI 用
8
8
 
9
9
  仅内部重构、测试调整,或只影响其他产品界面且不改变 TUI 行为的变化不记录。
10
10
 
11
+ ## 0.4.8 · 2026-09-16
12
+
13
+ ### 新增
14
+
15
+ - Explore 子代理支持使用前台 Bash 检查代码与 Git 状态;沙箱可用时使用只读文件系统策略。
16
+
17
+ ### 改进
18
+
19
+ - 改善内容审核后的响应处理,支持按审核引导重新生成或返回适用的固定回复,并撤回被拦截的草稿。
20
+ - 改善超长思考内容预览时的响应速度,展开详情仍可查看完整内容。
21
+ - 运行状态、单轮结束摘要和 Goal 统一使用 `s`、`min`、`h` 显示耗时,超过一小时仍保留秒数。
22
+
23
+ ### 修复
24
+
25
+ - 恢复支持思考的自定义 Provider 模型的思考开关,保留已有的实际默认行为。
26
+ - 修复自定义 Agent 与内置 Agent 同名时的启动失败,并在迁移时保留自定义配置。
27
+ - 改善 兼容接口的流式响应取消,避免中断后仍等待数据读取。
28
+ - 双击 Esc 或使用 `/edit` 编辑上一条消息时,恢复可操作的图片标签,支持删除、撤销和重新发送;有可读本地文件时可再次预览。
29
+ - 修复运行中追加图片或文件时的附件校验失败,并避免已接收的附件随草稿临时文件清理而丢失。
30
+
11
31
  ## 0.4.7 · 2026-09-15
12
32
 
13
33
  ### 新增
package/README.zh-CN.md CHANGED
@@ -29,6 +29,9 @@ mcode
29
29
 
30
30
  MiniMax Code 会检查代码库、完成修改、运行能够执行的验证,并汇总已经确认的结果。
31
31
 
32
+ 运行状态行、单轮结束后的耗时和 Goal 计时统一使用 `s` / `min` / `h`,例如
33
+ `30s`、`9min30s`、`2h9min30s`;超过一小时仍显示秒。运行耗时统计当前轮,Goal 统计累计 active 时间,两者数值可以不同。
34
+
32
35
  ## 内部包的 Codex 登录
33
36
 
34
37
  在 `/provider` 选择 OpenAI Codex,或在 `/model` 选择 Connect OpenAI Codex,再选择登录方式:
@@ -90,6 +93,10 @@ MiniMax Code 工作时,按 `Enter` 将输入内容 steer 给当前 Turn;按
90
93
  标出编号,并在输入框上方显示预览。继续输入或移开光标会收起预览;用左右方向键移回图片标签即可再次查看。`Esc`
91
94
  收起;`Enter` 仍按当前状态发送或 steer,不会打开图片。
92
95
 
96
+ 空输入框连续按两次 `Esc` 或使用 `/edit` 编辑上一条消息时,图片会恢复为可操作的
97
+ `[Image #1]` 标签,支持删除、撤销和重新发送。当前进程内最近一次带附件提交会保留原标签位置;
98
+ 没有本地编辑快照的历史消息会在正文末尾重建标签。只有资源 ID、没有可读本地文件的图片仍保留标签和元信息。
99
+
93
100
  支持 Kitty 图片协议的终端以及 regular 模式的 iTerm2 可以显示图片;其他终端显示格式、尺寸和大小。预览最多读取 20
94
101
  MB、处理 2500 万像素,超限、格式不支持或读取失败时保留文字信息和原附件。预览副本不影响原图发送,也不自动去重。
95
102
 
@@ -14,6 +14,14 @@ requires creating, editing, or saving any file, stop immediately and return
14
14
  the file-writing requirement and returning the research in `final_text`.
15
15
  Referencing existing files for read-only inspection is allowed.
16
16
 
17
+ # Read-only Bash
18
+ Use `bash` only to inspect existing code or Git state. Do not modify files, Git
19
+ state, or external systems, and do not run commands with other side effects. If
20
+ the investigation needs a side effect, return `ROLE_MISMATCH`.
21
+
22
+ Explore does not have `task_output`, so do not use `run_in_background` with
23
+ `bash`. Run each Bash command in the foreground and return its result.
24
+
17
25
  - Locate relevant files, symbols, configuration, tests, data flow, or
18
26
  authoritative sources.
19
27
  - Prefer targeted reads and searches. Stop when the bounded evidence needed for
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  tools:
3
+ - bash
3
4
  - read
4
5
  - grep
5
6
  - glob
@@ -10,6 +10,15 @@ requires creating, editing, or saving any file, stop immediately and return
10
10
  the file-writing requirement and returning the research in `final_text`.
11
11
  Referencing existing files for read-only inspection is allowed.
12
12
 
13
+ ## Read-only Bash
14
+
15
+ Use `bash` only to inspect existing code or Git state. Do not modify files, Git
16
+ state, or external systems, and do not run commands with other side effects. If
17
+ the investigation needs a side effect, return `ROLE_MISMATCH`.
18
+
19
+ Explore does not have `task_output`, so do not use `run_in_background` with
20
+ `bash`. Run each Bash command in the foreground and return its result.
21
+
13
22
  - Locate relevant files, symbols, configuration, tests, data flow, or
14
23
  authoritative sources.
15
24
  - Prefer targeted reads and searches. Stop when the bounded evidence needed for
@@ -24,8 +24,10 @@ Use `task` only for one concrete, bounded subtask:
24
24
  A user's authorization for the requested work also authorizes internal delegation inside that scope.
25
25
  It does not authorize broader edits, new external side effects, or overlapping writers.
26
26
 
27
- Use explore for bounded codebase mapping or evidence gathering, not to transfer
28
- interpretation or final decision-making.
27
+ Use Explore for bounded codebase mapping or evidence gathering. It can use
28
+ `bash` for read-only Git and code investigation. When continuing the same
29
+ investigation, reuse the existing task with `task_append` instead of opening a
30
+ new task.
29
31
 
30
32
  ### Brief a fresh child
31
33
 
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
2
- import{a,b,c,d}from"./chunk-RPO5CDCP.js";import"./chunk-LOQ4VVEN.js";import"./chunk-2UWBSJDH.js";import"./chunk-GUFBGYOC.js";import"./chunk-CK62QLTS.js";import"./chunk-WFWSBUYD.js";import"./chunk-D76SO2ME.js";export{a as DEFAULT_THINKING_MODEL_IDS,b as isDefaultThinkingModelId,c as streamAnthropic,d as streamSimpleAnthropic};
2
+ import{a,b,c,d}from"./chunk-3V6OPTHM.js";import"./chunk-LOQ4VVEN.js";import"./chunk-2UWBSJDH.js";import"./chunk-GUFBGYOC.js";import"./chunk-CK62QLTS.js";import"./chunk-WFWSBUYD.js";import"./chunk-D76SO2ME.js";export{a as DEFAULT_THINKING_MODEL_IDS,b as isDefaultThinkingModelId,c as streamAnthropic,d as streamSimpleAnthropic};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
2
- import{c as a}from"./chunk-AJSGEEWR.js";import"./chunk-C3JRMX7L.js";import"./chunk-KVMK6REW.js";import"./chunk-W7JHDTPW.js";import"./chunk-O6RIRKRN.js";import"./chunk-HQ2U4QVQ.js";import"./chunk-B2NJMA4I.js";import"./chunk-CWWDVX6C.js";import"./chunk-D76SO2ME.js";export{a as McodeUpdateApplication};
2
+ import{c as a}from"./chunk-ZRZKBTCU.js";import"./chunk-C3JRMX7L.js";import"./chunk-ZCP4JGO4.js";import"./chunk-VCJI7AJO.js";import"./chunk-O6RIRKRN.js";import"./chunk-HQ2U4QVQ.js";import"./chunk-Z44TXDGK.js";import"./chunk-CWWDVX6C.js";import"./chunk-D76SO2ME.js";export{a as McodeUpdateApplication};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
2
- import{a as o,b as l,c as u}from"./chunk-BNU46XHR.js";import"./chunk-QJWOGW27.js";import{d as p}from"./chunk-SYLCIHHV.js";import"./chunk-22LVIQ2T.js";import"./chunk-2SW3R5AB.js";import"./chunk-ZITT4GJK.js";import"./chunk-2ZG44JU6.js";import"./chunk-B2NJMA4I.js";import"./chunk-CWWDVX6C.js";import"./chunk-D76SO2ME.js";async function A(r={}){let a=r.createApplication?r.createApplication(r.region):await c(r.region,r.prepareDataDir),t=r.writeError??(e=>process.stderr.write(e));return(await a.login(e=>{let n=l(e.verificationUriComplete??e.verificationUri);if(t(`Open: ${n}
2
+ import{a as o,b as l,c as u}from"./chunk-2CEKQTMO.js";import"./chunk-VPHVKGPT.js";import{d as p}from"./chunk-HMP2XYHW.js";import"./chunk-WAVNKSSE.js";import"./chunk-DV5WIEGS.js";import"./chunk-ZITT4GJK.js";import"./chunk-2ZG44JU6.js";import"./chunk-Z44TXDGK.js";import"./chunk-CWWDVX6C.js";import"./chunk-D76SO2ME.js";async function A(r={}){let a=r.createApplication?r.createApplication(r.region):await c(r.region,r.prepareDataDir),t=r.writeError??(e=>process.stderr.write(e));return(await a.login(e=>{let n=l(e.verificationUriComplete??e.verificationUri);if(t(`Open: ${n}
3
3
  Code: ${e.userCode}
4
4
  Waiting for authorization\u2026
5
5
  `),r.openBrowser===!1)return;(r.openExternalTarget??o(process.cwd()))(n).catch(()=>{t(`Couldn't open the default browser. Open the authorization URL above manually.
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
2
- import{a as p}from"./chunk-QJWOGW27.js";import{e as g,k as d,m as h}from"./chunk-22LVIQ2T.js";import{isAbsolute as f,resolve as A}from"node:path";import{spawn as E}from"node:child_process";import{fileURLToPath as y}from"node:url";function T(e){return t=>R(t,e)}function R(e,t){let i=S(e,t),[o,r]=process.platform==="darwin"?["open",[i]]:process.platform==="win32"?["rundll32",["url.dll,FileProtocolHandler",i]]:["xdg-open",[i]];return new Promise((s,u)=>{let n=E(o,r,{detached:!0,stdio:"ignore",windowsHide:!0});n.once("error",u),n.once("spawn",()=>{n.unref(),s()})})}function S(e,t){return/^https?:\/\//iu.test(e)?e:/^file:\/\//iu.test(e)?y(e):f(e)?e:A(t,e)}var x="mcode-internal";function k(e){try{let t=new URL(e);return t.searchParams.set("client_surface","tui"),t.searchParams.set("download_source",x),t.toString()}catch{return e}}var w={cn:{dev:"https://agent.minimaxi.com",test:"https://agent.minimaxi.com",staging:"https://agent.minimaxi.com",prod:"https://agent.minimax.cn"},en:{dev:"https://agent.minimax.io",test:"https://agent.minimax.io",staging:"https://agent.minimax.io",prod:"https://agent.minimax.io"}};function m(e){let t=w[e.region][e.buildEnv];return`${t}/auth/logout?logout_redirect_uri=${encodeURIComponent(t)}`}var c=class{constructor(t){this.options=t;let i=d({runtimeRegion:process.env.MAVIS_REGION==="en"?"en":"cn"});this.scope={region:t.region??i.region,buildEnv:t.buildEnv??i.buildEnv}}scope;async login(t,i=this.scope.region){this.track("login_click",{hailuo_user_id:this.hailuoUserId()});try{let o={...this.scope,region:i},r=!P(o,this.scope),s=this.options.sharedAuthCore;if(r){if(!this.options.resolveSharedAuthCore)throw new Error(C(this.scope,o));s=this.options.resolveSharedAuthCore(i)}let u=(await s.getStatus()).status==="authenticated",n=!1;await s.login({onDeviceAuthorization:M=>{n=!0,t?.({state:"device-authorization",...M})}}),this.persistRegionPreference(o);let l=u&&!n,v={state:l?"already-authenticated":"authenticated",message:l?r?`Already signed in with ${a(o.region)}.`:"Already signed in with MiniMax.":r?`Signed in with ${a(o.region)}.`:"Signed in with MiniMax.",...r?{restartRequired:!0}:{}};return this.trackLoginResult("1",""),v}catch(o){throw this.trackLoginResult("2",b(o)),o}}async logout(){this.track("logout_click",{hailuo_user_id:this.hailuoUserId()});let t=await this.options.sharedAuthCore.getStatus(),i=await this.options.sharedAuthCore.logout({revoke:!0}),o=m(this.scope);return t.status==="anonymous"&&i.status==="anonymous"?{state:"already-signed-out",message:"Already signed out of MiniMax.",logoutUrl:o}:{state:"signed-out",logoutUrl:o,message:i.status==="logout_pending"?`Signed out locally from ${a(this.scope.region)} across MCode. Server revocation is pending until the network recovers.`:`Signed out of ${a(this.scope.region)} on Desktop, CLI/TUI, and embedded mcode-tools.`}}trackLoginResult(t,i){this.track("login_result",{hailuo_user_id:this.hailuoUserId(),source:this.options.telemetrySource??"mcode_cli",result_type:t,fail_reason:i,login_type:"minimax_oauth"})}persistRegionPreference(t){try{this.options.writeRegionPreference?.(this.options.dataDir,t)}catch{}}hailuoUserId(){try{return this.options.hailuoUserId?.()?.trim()??""}catch{return""}}track(t,i){try{this.options.telemetry?.track(t,i)}catch{}}};function b(e){let t=e instanceof Error?e.message:String(e);return/cancel/iu.test(t)?"3":/network|offline|fetch|ECONN|ENOTFOUND|ETIMEDOUT/iu.test(t)?"2":/oauth|authorization|login failed|invalid login state/iu.test(t)?"5":/server|HTTP 5\d\d/iu.test(t)?"1":"4"}function P(e,t){return e.region===t.region&&e.buildEnv===t.buildEnv}function C(e,t){return e.region!==t.region?`Signed in to ${a(e.region)}. Run \`mcode logout\` before signing in to ${a(t.region)}.`:`Signed in to another MiniMax ${e.buildEnv} environment. Run \`mcode logout\` before signing in to ${t.buildEnv}.`}function a(e){return e==="cn"?"MiniMax China":"MiniMax Global"}function j(e){let t=d({runtimeRegion:e.region,runtimeBuildEnv:e.buildEnv}),i=e.region??t.region,o=e.buildEnv??t.buildEnv,r={dataDir:e.dataDir,region:i,buildEnv:o,...e.telemetry?{telemetry:e.telemetry}:{},...e.telemetrySource?{telemetrySource:e.telemetrySource}:{},...e.hailuoUserId?{hailuoUserId:e.hailuoUserId}:{},writeRegionPreference:e.writeRegionPreference??h},s=n=>(e.createSharedSession??p)({dataDir:e.dataDir,region:n,buildEnv:o,oauthEndpoints:g(e.oauthEndpointEnvironment??process.env,{buildEnv:o,region:n})}),u=e.sharedAuthCore??s(i);return new c({...r,sharedAuthCore:u,resolveSharedAuthCore:s})}export{T as a,k as b,j as c};
2
+ import{a as p}from"./chunk-VPHVKGPT.js";import{e as g,k as d,m as h}from"./chunk-WAVNKSSE.js";import{isAbsolute as f,resolve as A}from"node:path";import{spawn as E}from"node:child_process";import{fileURLToPath as y}from"node:url";function T(e){return t=>R(t,e)}function R(e,t){let i=S(e,t),[o,r]=process.platform==="darwin"?["open",[i]]:process.platform==="win32"?["rundll32",["url.dll,FileProtocolHandler",i]]:["xdg-open",[i]];return new Promise((s,u)=>{let n=E(o,r,{detached:!0,stdio:"ignore",windowsHide:!0});n.once("error",u),n.once("spawn",()=>{n.unref(),s()})})}function S(e,t){return/^https?:\/\//iu.test(e)?e:/^file:\/\//iu.test(e)?y(e):f(e)?e:A(t,e)}var x="mcode-internal";function k(e){try{let t=new URL(e);return t.searchParams.set("client_surface","tui"),t.searchParams.set("download_source",x),t.toString()}catch{return e}}var w={cn:{dev:"https://agent.minimaxi.com",test:"https://agent.minimaxi.com",staging:"https://agent.minimaxi.com",prod:"https://agent.minimax.cn"},en:{dev:"https://agent.minimax.io",test:"https://agent.minimax.io",staging:"https://agent.minimax.io",prod:"https://agent.minimax.io"}};function m(e){let t=w[e.region][e.buildEnv];return`${t}/auth/logout?logout_redirect_uri=${encodeURIComponent(t)}`}var c=class{constructor(t){this.options=t;let i=d({runtimeRegion:process.env.MAVIS_REGION==="en"?"en":"cn"});this.scope={region:t.region??i.region,buildEnv:t.buildEnv??i.buildEnv}}scope;async login(t,i=this.scope.region){this.track("login_click",{hailuo_user_id:this.hailuoUserId()});try{let o={...this.scope,region:i},r=!P(o,this.scope),s=this.options.sharedAuthCore;if(r){if(!this.options.resolveSharedAuthCore)throw new Error(C(this.scope,o));s=this.options.resolveSharedAuthCore(i)}let u=(await s.getStatus()).status==="authenticated",n=!1;await s.login({onDeviceAuthorization:M=>{n=!0,t?.({state:"device-authorization",...M})}}),this.persistRegionPreference(o);let l=u&&!n,v={state:l?"already-authenticated":"authenticated",message:l?r?`Already signed in with ${a(o.region)}.`:"Already signed in with MiniMax.":r?`Signed in with ${a(o.region)}.`:"Signed in with MiniMax.",...r?{restartRequired:!0}:{}};return this.trackLoginResult("1",""),v}catch(o){throw this.trackLoginResult("2",b(o)),o}}async logout(){this.track("logout_click",{hailuo_user_id:this.hailuoUserId()});let t=await this.options.sharedAuthCore.getStatus(),i=await this.options.sharedAuthCore.logout({revoke:!0}),o=m(this.scope);return t.status==="anonymous"&&i.status==="anonymous"?{state:"already-signed-out",message:"Already signed out of MiniMax.",logoutUrl:o}:{state:"signed-out",logoutUrl:o,message:i.status==="logout_pending"?`Signed out locally from ${a(this.scope.region)} across MCode. Server revocation is pending until the network recovers.`:`Signed out of ${a(this.scope.region)} on Desktop, CLI/TUI, and embedded mcode-tools.`}}trackLoginResult(t,i){this.track("login_result",{hailuo_user_id:this.hailuoUserId(),source:this.options.telemetrySource??"mcode_cli",result_type:t,fail_reason:i,login_type:"minimax_oauth"})}persistRegionPreference(t){try{this.options.writeRegionPreference?.(this.options.dataDir,t)}catch{}}hailuoUserId(){try{return this.options.hailuoUserId?.()?.trim()??""}catch{return""}}track(t,i){try{this.options.telemetry?.track(t,i)}catch{}}};function b(e){let t=e instanceof Error?e.message:String(e);return/cancel/iu.test(t)?"3":/network|offline|fetch|ECONN|ENOTFOUND|ETIMEDOUT/iu.test(t)?"2":/oauth|authorization|login failed|invalid login state/iu.test(t)?"5":/server|HTTP 5\d\d/iu.test(t)?"1":"4"}function P(e,t){return e.region===t.region&&e.buildEnv===t.buildEnv}function C(e,t){return e.region!==t.region?`Signed in to ${a(e.region)}. Run \`mcode logout\` before signing in to ${a(t.region)}.`:`Signed in to another MiniMax ${e.buildEnv} environment. Run \`mcode logout\` before signing in to ${t.buildEnv}.`}function a(e){return e==="cn"?"MiniMax China":"MiniMax Global"}function j(e){let t=d({runtimeRegion:e.region,runtimeBuildEnv:e.buildEnv}),i=e.region??t.region,o=e.buildEnv??t.buildEnv,r={dataDir:e.dataDir,region:i,buildEnv:o,...e.telemetry?{telemetry:e.telemetry}:{},...e.telemetrySource?{telemetrySource:e.telemetrySource}:{},...e.hailuoUserId?{hailuoUserId:e.hailuoUserId}:{},writeRegionPreference:e.writeRegionPreference??h},s=n=>(e.createSharedSession??p)({dataDir:e.dataDir,region:n,buildEnv:o,oauthEndpoints:g(e.oauthEndpointEnvironment??process.env,{buildEnv:o,region:n})}),u=e.sharedAuthCore??s(i);return new c({...r,sharedAuthCore:u,resolveSharedAuthCore:s})}export{T as a,k as b,j as c};