dsh-cliworker-now 0.0.0-stage → 0.7.6

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 (285) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +344 -0
  3. package/README.md +346 -2
  4. package/cordis.patch.yml +3 -0
  5. package/lib/account-models.mjs +259 -0
  6. package/lib/client.js +21542 -0
  7. package/lib/client.js.map +1 -0
  8. package/lib/grok-catalog.mjs +145 -0
  9. package/lib/hermes-native-entry.py +61 -0
  10. package/lib/index.js +12409 -0
  11. package/lib/index.js.map +1 -0
  12. package/lib/native-launch.mjs +179 -0
  13. package/lib/own-account-lease.mjs +105 -0
  14. package/lib/pi-installation.mjs +63 -0
  15. package/lib/pi-login.mjs +80 -0
  16. package/lib/pi-native-catalog.mjs +417 -0
  17. package/lib/pi-omp-bridge.mjs +602 -0
  18. package/lib/pi-omp-environment.mjs +15 -0
  19. package/lib/pi-omp-refresh.mjs +324 -0
  20. package/lib/private-launch.mjs +19 -0
  21. package/lib/terminal-bridge.mjs +18 -0
  22. package/lib/typert.host.d.ts +3 -0
  23. package/lib/typert.host.js +1358 -0
  24. package/lib/typert.remote-client.d.ts +70 -0
  25. package/lib/typert.remote-client.d.ts.map +1 -0
  26. package/lib/typert.remote-client.js +1190 -0
  27. package/lib/types/client/account-terminal-css.d.ts +1 -0
  28. package/lib/types/client/account-terminal-css.js +3 -0
  29. package/lib/types/client/account-terminal-css.js.map +1 -0
  30. package/lib/types/client/account-terminal.d.ts +13 -0
  31. package/lib/types/client/account-terminal.js +296 -0
  32. package/lib/types/client/account-terminal.js.map +1 -0
  33. package/lib/types/client/assets/antigravity.png +0 -0
  34. package/lib/types/client/assets/claude-code.png +0 -0
  35. package/lib/types/client/assets/cliworker-now-logo.png +0 -0
  36. package/lib/types/client/assets/codex.png +0 -0
  37. package/lib/types/client/assets/grok.png +0 -0
  38. package/lib/types/client/assets/hermes.png +0 -0
  39. package/lib/types/client/assets/kimi-dark.png +0 -0
  40. package/lib/types/client/assets/kimi-light.png +0 -0
  41. package/lib/types/client/assets/mimo-code.png +0 -0
  42. package/lib/types/client/assets/omp.png +0 -0
  43. package/lib/types/client/assets/opencode.png +0 -0
  44. package/lib/types/client/assets/pi.png +0 -0
  45. package/lib/types/client/assets/zcode.png +0 -0
  46. package/lib/types/client/composer-keymap.d.ts +18 -0
  47. package/lib/types/client/composer-keymap.js +49 -0
  48. package/lib/types/client/composer-keymap.js.map +1 -0
  49. package/lib/types/client/conversation-timeline.d.ts +6 -0
  50. package/lib/types/client/conversation-timeline.js +65 -0
  51. package/lib/types/client/conversation-timeline.js.map +1 -0
  52. package/lib/types/client/copy-text.d.ts +5 -0
  53. package/lib/types/client/copy-text.js +45 -0
  54. package/lib/types/client/copy-text.js.map +1 -0
  55. package/lib/types/client/icons.d.ts +21 -0
  56. package/lib/types/client/icons.js +68 -0
  57. package/lib/types/client/icons.js.map +1 -0
  58. package/lib/types/client/index.d.ts +3 -0
  59. package/lib/types/client/index.js +124 -0
  60. package/lib/types/client/index.js.map +1 -0
  61. package/lib/types/client/management-styles.d.ts +1 -0
  62. package/lib/types/client/management-styles.js +17 -0
  63. package/lib/types/client/management-styles.js.map +1 -0
  64. package/lib/types/client/name-copy.d.ts +5 -0
  65. package/lib/types/client/name-copy.js +107 -0
  66. package/lib/types/client/name-copy.js.map +1 -0
  67. package/lib/types/client/native-job-overlay.d.ts +11 -0
  68. package/lib/types/client/native-job-overlay.js +129 -0
  69. package/lib/types/client/native-job-overlay.js.map +1 -0
  70. package/lib/types/client/operation-error.d.ts +2 -0
  71. package/lib/types/client/operation-error.js +12 -0
  72. package/lib/types/client/operation-error.js.map +1 -0
  73. package/lib/types/client/panel.d.ts +8 -0
  74. package/lib/types/client/panel.js +310 -0
  75. package/lib/types/client/panel.js.map +1 -0
  76. package/lib/types/client/rename-copy-styles.d.ts +1 -0
  77. package/lib/types/client/rename-copy-styles.js +21 -0
  78. package/lib/types/client/rename-copy-styles.js.map +1 -0
  79. package/lib/types/client/rename-worker.d.ts +9 -0
  80. package/lib/types/client/rename-worker.js +53 -0
  81. package/lib/types/client/rename-worker.js.map +1 -0
  82. package/lib/types/client/role-presets.d.ts +6 -0
  83. package/lib/types/client/role-presets.js +111 -0
  84. package/lib/types/client/role-presets.js.map +1 -0
  85. package/lib/types/client/settings-dialog.d.ts +13 -0
  86. package/lib/types/client/settings-dialog.js +415 -0
  87. package/lib/types/client/settings-dialog.js.map +1 -0
  88. package/lib/types/client/stat-popover.d.ts +10 -0
  89. package/lib/types/client/stat-popover.js +32 -0
  90. package/lib/types/client/stat-popover.js.map +1 -0
  91. package/lib/types/client/styles.d.ts +9 -0
  92. package/lib/types/client/styles.js +221 -0
  93. package/lib/types/client/styles.js.map +1 -0
  94. package/lib/types/client/telemetry.d.ts +11 -0
  95. package/lib/types/client/telemetry.js +24 -0
  96. package/lib/types/client/telemetry.js.map +1 -0
  97. package/lib/types/client/worker-card.d.ts +10 -0
  98. package/lib/types/client/worker-card.js +75 -0
  99. package/lib/types/client/worker-card.js.map +1 -0
  100. package/lib/types/client/worker-model-menu.d.ts +9 -0
  101. package/lib/types/client/worker-model-menu.js +136 -0
  102. package/lib/types/client/worker-model-menu.js.map +1 -0
  103. package/lib/types/client/workers.d.ts +21 -0
  104. package/lib/types/client/workers.js +59 -0
  105. package/lib/types/client/workers.js.map +1 -0
  106. package/lib/types/host/account-identity.d.ts +16 -0
  107. package/lib/types/host/account-identity.js +126 -0
  108. package/lib/types/host/account-identity.js.map +1 -0
  109. package/lib/types/host/account-login.d.ts +10 -0
  110. package/lib/types/host/account-login.js +126 -0
  111. package/lib/types/host/account-login.js.map +1 -0
  112. package/lib/types/host/account-models.d.mts +19 -0
  113. package/lib/types/host/account-models.mjs +259 -0
  114. package/lib/types/host/accounts.d.ts +41 -0
  115. package/lib/types/host/accounts.js +838 -0
  116. package/lib/types/host/accounts.js.map +1 -0
  117. package/lib/types/host/adapters.d.ts +24 -0
  118. package/lib/types/host/adapters.js +331 -0
  119. package/lib/types/host/adapters.js.map +1 -0
  120. package/lib/types/host/agy-context.d.ts +8 -0
  121. package/lib/types/host/agy-context.js +122 -0
  122. package/lib/types/host/agy-context.js.map +1 -0
  123. package/lib/types/host/agy-models.d.ts +4 -0
  124. package/lib/types/host/agy-models.js +37 -0
  125. package/lib/types/host/agy-models.js.map +1 -0
  126. package/lib/types/host/authorized-catalog.d.ts +14 -0
  127. package/lib/types/host/authorized-catalog.js +26 -0
  128. package/lib/types/host/authorized-catalog.js.map +1 -0
  129. package/lib/types/host/bridge-protocol.d.ts +15 -0
  130. package/lib/types/host/bridge-protocol.js +80 -0
  131. package/lib/types/host/bridge-protocol.js.map +1 -0
  132. package/lib/types/host/cli-account-binding.d.ts +32 -0
  133. package/lib/types/host/cli-account-binding.js +502 -0
  134. package/lib/types/host/cli-account-binding.js.map +1 -0
  135. package/lib/types/host/cli-protocol.d.ts +27 -0
  136. package/lib/types/host/cli-protocol.js +212 -0
  137. package/lib/types/host/cli-protocol.js.map +1 -0
  138. package/lib/types/host/codex-account.d.ts +8 -0
  139. package/lib/types/host/codex-account.js +143 -0
  140. package/lib/types/host/codex-account.js.map +1 -0
  141. package/lib/types/host/codex-models.d.ts +6 -0
  142. package/lib/types/host/codex-models.js +165 -0
  143. package/lib/types/host/codex-models.js.map +1 -0
  144. package/lib/types/host/extended-adapters.d.ts +43 -0
  145. package/lib/types/host/extended-adapters.js +205 -0
  146. package/lib/types/host/extended-adapters.js.map +1 -0
  147. package/lib/types/host/first-party-account-context.d.ts +26 -0
  148. package/lib/types/host/first-party-account-context.js +55 -0
  149. package/lib/types/host/first-party-account-context.js.map +1 -0
  150. package/lib/types/host/first-party-models.d.ts +28 -0
  151. package/lib/types/host/first-party-models.js +370 -0
  152. package/lib/types/host/first-party-models.js.map +1 -0
  153. package/lib/types/host/grok-adapter.d.ts +44 -0
  154. package/lib/types/host/grok-adapter.js +293 -0
  155. package/lib/types/host/grok-adapter.js.map +1 -0
  156. package/lib/types/host/grok-models.d.ts +47 -0
  157. package/lib/types/host/grok-models.js +320 -0
  158. package/lib/types/host/grok-models.js.map +1 -0
  159. package/lib/types/host/harness-opencode-accounts.d.ts +17 -0
  160. package/lib/types/host/harness-opencode-accounts.js +80 -0
  161. package/lib/types/host/harness-opencode-accounts.js.map +1 -0
  162. package/lib/types/host/hermes-account-context.d.ts +8 -0
  163. package/lib/types/host/hermes-account-context.js +99 -0
  164. package/lib/types/host/hermes-account-context.js.map +1 -0
  165. package/lib/types/host/hermes-accounts.d.ts +19 -0
  166. package/lib/types/host/hermes-accounts.js +342 -0
  167. package/lib/types/host/hermes-accounts.js.map +1 -0
  168. package/lib/types/host/hermes-adapter.d.ts +90 -0
  169. package/lib/types/host/hermes-adapter.js +446 -0
  170. package/lib/types/host/hermes-adapter.js.map +1 -0
  171. package/lib/types/host/hermes-env.d.ts +4 -0
  172. package/lib/types/host/hermes-env.js +22 -0
  173. package/lib/types/host/hermes-env.js.map +1 -0
  174. package/lib/types/host/hermes-installation.d.ts +10 -0
  175. package/lib/types/host/hermes-installation.js +162 -0
  176. package/lib/types/host/hermes-installation.js.map +1 -0
  177. package/lib/types/host/hermes-models.d.ts +26 -0
  178. package/lib/types/host/hermes-models.js +328 -0
  179. package/lib/types/host/hermes-models.js.map +1 -0
  180. package/lib/types/host/hermes-native-entry.py +61 -0
  181. package/lib/types/host/hermes-nous.d.ts +49 -0
  182. package/lib/types/host/hermes-nous.js +343 -0
  183. package/lib/types/host/hermes-nous.js.map +1 -0
  184. package/lib/types/host/hermes-suppression.d.ts +7 -0
  185. package/lib/types/host/hermes-suppression.js +69 -0
  186. package/lib/types/host/hermes-suppression.js.map +1 -0
  187. package/lib/types/host/index.d.ts +138 -0
  188. package/lib/types/host/index.js +932 -0
  189. package/lib/types/host/index.js.map +1 -0
  190. package/lib/types/host/kimi-accounts.d.ts +15 -0
  191. package/lib/types/host/kimi-accounts.js +218 -0
  192. package/lib/types/host/kimi-accounts.js.map +1 -0
  193. package/lib/types/host/managed-agent.d.ts +4 -0
  194. package/lib/types/host/managed-agent.js +127 -0
  195. package/lib/types/host/managed-agent.js.map +1 -0
  196. package/lib/types/host/mimo-configuration.d.ts +22 -0
  197. package/lib/types/host/mimo-configuration.js +258 -0
  198. package/lib/types/host/mimo-configuration.js.map +1 -0
  199. package/lib/types/host/native-launch.d.mts +2 -0
  200. package/lib/types/host/native-launch.mjs +179 -0
  201. package/lib/types/host/native-process.d.ts +3 -0
  202. package/lib/types/host/native-process.js +26 -0
  203. package/lib/types/host/native-process.js.map +1 -0
  204. package/lib/types/host/opencode-adapter.d.ts +94 -0
  205. package/lib/types/host/opencode-adapter.js +507 -0
  206. package/lib/types/host/opencode-adapter.js.map +1 -0
  207. package/lib/types/host/opencode-native.d.ts +27 -0
  208. package/lib/types/host/opencode-native.js +403 -0
  209. package/lib/types/host/opencode-native.js.map +1 -0
  210. package/lib/types/host/own-account-lease.d.mts +5 -0
  211. package/lib/types/host/own-account-lease.mjs +105 -0
  212. package/lib/types/host/pi-installation.d.mts +7 -0
  213. package/lib/types/host/pi-installation.mjs +63 -0
  214. package/lib/types/host/pi-omp-accounts.d.ts +28 -0
  215. package/lib/types/host/pi-omp-accounts.js +175 -0
  216. package/lib/types/host/pi-omp-accounts.js.map +1 -0
  217. package/lib/types/host/pi-omp-adapter.d.ts +32 -0
  218. package/lib/types/host/pi-omp-adapter.js +176 -0
  219. package/lib/types/host/pi-omp-adapter.js.map +1 -0
  220. package/lib/types/host/pi-omp-environment.d.mts +1 -0
  221. package/lib/types/host/pi-omp-environment.mjs +15 -0
  222. package/lib/types/host/pi-omp-identity.d.ts +2 -0
  223. package/lib/types/host/pi-omp-identity.js +142 -0
  224. package/lib/types/host/pi-omp-identity.js.map +1 -0
  225. package/lib/types/host/pi-omp-logout.d.ts +3 -0
  226. package/lib/types/host/pi-omp-logout.js +152 -0
  227. package/lib/types/host/pi-omp-logout.js.map +1 -0
  228. package/lib/types/host/pi-omp-native.d.ts +71 -0
  229. package/lib/types/host/pi-omp-native.js +753 -0
  230. package/lib/types/host/pi-omp-native.js.map +1 -0
  231. package/lib/types/host/pi-omp-refresh.d.mts +7 -0
  232. package/lib/types/host/pi-omp-refresh.mjs +324 -0
  233. package/lib/types/host/process.d.ts +43 -0
  234. package/lib/types/host/process.js +134 -0
  235. package/lib/types/host/process.js.map +1 -0
  236. package/lib/types/host/protocol.d.ts +23 -0
  237. package/lib/types/host/protocol.js +112 -0
  238. package/lib/types/host/protocol.js.map +1 -0
  239. package/lib/types/host/roles.d.ts +34 -0
  240. package/lib/types/host/roles.js +80 -0
  241. package/lib/types/host/roles.js.map +1 -0
  242. package/lib/types/host/routing.d.ts +31 -0
  243. package/lib/types/host/routing.js +225 -0
  244. package/lib/types/host/routing.js.map +1 -0
  245. package/lib/types/host/runtime.d.ts +60 -0
  246. package/lib/types/host/runtime.js +586 -0
  247. package/lib/types/host/runtime.js.map +1 -0
  248. package/lib/types/host/storage.d.ts +48 -0
  249. package/lib/types/host/storage.js +449 -0
  250. package/lib/types/host/storage.js.map +1 -0
  251. package/lib/types/host/telemetry.d.ts +17 -0
  252. package/lib/types/host/telemetry.js +158 -0
  253. package/lib/types/host/telemetry.js.map +1 -0
  254. package/lib/types/host/zcode-account-models.d.ts +16 -0
  255. package/lib/types/host/zcode-account-models.js +114 -0
  256. package/lib/types/host/zcode-account-models.js.map +1 -0
  257. package/lib/types/host/zcode-adapter.d.ts +93 -0
  258. package/lib/types/host/zcode-adapter.js +804 -0
  259. package/lib/types/host/zcode-adapter.js.map +1 -0
  260. package/lib/types/host/zcode-grok-accounts.d.ts +28 -0
  261. package/lib/types/host/zcode-grok-accounts.js +359 -0
  262. package/lib/types/host/zcode-grok-accounts.js.map +1 -0
  263. package/lib/types/shared/accounts.d.ts +43 -0
  264. package/lib/types/shared/accounts.js +2 -0
  265. package/lib/types/shared/accounts.js.map +1 -0
  266. package/lib/types/shared/builtin-presets.d.ts +2 -0
  267. package/lib/types/shared/builtin-presets.js +231 -0
  268. package/lib/types/shared/builtin-presets.js.map +1 -0
  269. package/lib/types/shared/cli-settings.d.ts +5 -0
  270. package/lib/types/shared/cli-settings.js +2 -0
  271. package/lib/types/shared/cli-settings.js.map +1 -0
  272. package/lib/types/shared/model-presentation.d.ts +10 -0
  273. package/lib/types/shared/model-presentation.js +95 -0
  274. package/lib/types/shared/model-presentation.js.map +1 -0
  275. package/lib/types/shared/models.d.ts +7 -0
  276. package/lib/types/shared/models.js +35 -0
  277. package/lib/types/shared/models.js.map +1 -0
  278. package/lib/types/shared/telemetry.d.ts +18 -0
  279. package/lib/types/shared/telemetry.js +16 -0
  280. package/lib/types/shared/telemetry.js.map +1 -0
  281. package/lib/types/shared/types.d.ts +127 -0
  282. package/lib/types/shared/types.js +147 -0
  283. package/lib/types/shared/types.js.map +1 -0
  284. package/lib/zcode-resume.mjs +423 -0
  285. package/package.json +109 -4
@@ -0,0 +1,258 @@
1
+ import { constants } from 'node:fs';
2
+ import { lstat, open, readdir, realpath } from 'node:fs/promises';
3
+ import { homedir, userInfo } from 'node:os';
4
+ import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
5
+ import { safePiOmpAncestors } from "./pi-omp-native.js";
6
+ export class MimoConfigurationError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = 'MimoConfigurationError';
10
+ }
11
+ }
12
+ const unavailable = () => new MimoConfigurationError('MiMo 配置来源无法确认,请检查配置');
13
+ const interpolation = () => new MimoConfigurationError('MiMo 配置含外部引用,请改为本 CLI 配置');
14
+ const remote = () => new MimoConfigurationError('MiMo 远程配置无法核验,请使用本地配置');
15
+ /** Mirrors native Global.Path; arbitrary config/content/DB selectors are cleared in the child. */
16
+ export function mimoConfigurationPaths(options = {}) {
17
+ const env = options.env ?? process.env;
18
+ const osHome = options.osHome ?? homedir();
19
+ const paths = options.paths ?? { join, isAbsolute };
20
+ const home = env.HOME || env.USERPROFILE || osHome;
21
+ const root = env.MIMOCODE_HOME;
22
+ const config = root
23
+ ? paths.join(root, 'config')
24
+ : paths.join(env.XDG_CONFIG_HOME || paths.join(osHome, '.config'), 'mimocode');
25
+ const data = root
26
+ ? paths.join(root, 'data')
27
+ : paths.join(env.XDG_DATA_HOME || paths.join(osHome, '.local/share'), 'mimocode');
28
+ if (![home, config, data, ...(root ? [root] : [])].every(paths.isAbsolute))
29
+ throw unavailable();
30
+ return { home, config, data };
31
+ }
32
+ export async function mimoConfigurationFiles(project) {
33
+ if (!isAbsolute(project))
34
+ throw unavailable();
35
+ const { home, config } = mimoConfigurationPaths();
36
+ const files = new Set([join(config, 'config.json')]);
37
+ const add = (directory) => {
38
+ files.add(join(directory, 'mimocode.json'));
39
+ files.add(join(directory, 'mimocode.jsonc'));
40
+ };
41
+ add(config);
42
+ add(join(home, '.mimocode'));
43
+ // Native stops at the worktree; checking every ancestor also covers unversioned projects.
44
+ let physical;
45
+ try {
46
+ physical = await realpath(project);
47
+ }
48
+ catch {
49
+ throw unavailable();
50
+ }
51
+ for (const start of new Set([resolve(project), physical])) {
52
+ for (let directory = start;; directory = dirname(directory)) {
53
+ add(directory);
54
+ add(join(directory, '.mimocode'));
55
+ if (dirname(directory) === directory)
56
+ break;
57
+ }
58
+ }
59
+ return [...files];
60
+ }
61
+ async function exists(path) {
62
+ try {
63
+ await lstat(path);
64
+ return true;
65
+ }
66
+ catch (error) {
67
+ if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
68
+ return false;
69
+ throw unavailable();
70
+ }
71
+ }
72
+ async function ownDirectory(path) {
73
+ try {
74
+ const stat = await lstat(path);
75
+ if (!stat.isDirectory() || stat.isSymbolicLink())
76
+ throw unavailable();
77
+ }
78
+ catch (error) {
79
+ if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR')
80
+ throw unavailable();
81
+ }
82
+ }
83
+ async function readConfiguration(path, signal) {
84
+ signal.throwIfAborted();
85
+ let file, bytes;
86
+ try {
87
+ // A selected project may be an alias; check its physical ancestor chain and
88
+ // keep the named file identity stable instead of rejecting the project itself.
89
+ await safePiOmpAncestors(await realpath(dirname(path)));
90
+ const entry = await lstat(path);
91
+ if (entry.isSymbolicLink() || !entry.isFile() || entry.nlink !== 1)
92
+ throw unavailable();
93
+ file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
94
+ const before = await file.stat();
95
+ if (!before.isFile() ||
96
+ before.nlink !== 1 ||
97
+ before.dev !== entry.dev ||
98
+ before.ino !== entry.ino ||
99
+ before.size > 1_048_576)
100
+ throw unavailable();
101
+ bytes = Buffer.alloc(before.size + 1);
102
+ let offset = 0;
103
+ while (offset < bytes.length) {
104
+ signal.throwIfAborted();
105
+ const { bytesRead } = await file.read(bytes, offset, bytes.length - offset, offset);
106
+ if (!bytesRead)
107
+ break;
108
+ offset += bytesRead;
109
+ }
110
+ const after = await file.stat();
111
+ const current = await lstat(path);
112
+ if (current.isSymbolicLink() ||
113
+ current.dev !== before.dev ||
114
+ current.ino !== before.ino ||
115
+ current.nlink !== 1 ||
116
+ offset !== before.size ||
117
+ after.size !== before.size ||
118
+ after.mtimeMs !== before.mtimeMs ||
119
+ current.size !== after.size ||
120
+ current.mtimeMs !== after.mtimeMs)
121
+ throw unavailable();
122
+ return bytes.subarray(0, before.size).toString('utf8');
123
+ }
124
+ catch (error) {
125
+ signal.throwIfAborted();
126
+ if (error.code === 'ENOENT' || error.code === 'ENOTDIR')
127
+ return undefined;
128
+ throw unavailable();
129
+ }
130
+ finally {
131
+ bytes?.fill(0);
132
+ await file?.close();
133
+ }
134
+ }
135
+ /** Auth.Service reads this file independently of model/project configuration. */
136
+ export async function readMimoOwnAuth(signal) {
137
+ const { data } = mimoConfigurationPaths();
138
+ await safePiOmpAncestors(data);
139
+ for (const directory of [process.env.MIMOCODE_HOME, data])
140
+ if (directory)
141
+ await ownDirectory(directory);
142
+ const text = await readConfiguration(join(data, 'auth.json'), signal);
143
+ if (!text)
144
+ return {};
145
+ try {
146
+ const auth = JSON.parse(text);
147
+ if (!auth || typeof auth !== 'object' || Array.isArray(auth))
148
+ throw unavailable();
149
+ return auth;
150
+ }
151
+ catch {
152
+ throw unavailable();
153
+ }
154
+ }
155
+ export async function readMimoAccount(signal) {
156
+ const auth = (await readMimoOwnAuth(signal)).xiaomi;
157
+ signal.throwIfAborted();
158
+ if (!auth)
159
+ return { state: 'unconfigured', summary: '尚未登录 MiMo', verification: 'local' };
160
+ // The built-in browser login persists ApiAuth, including optional uid/base_url metadata.
161
+ if (auth.type === 'api' && typeof auth.key === 'string' && auth.key.trim())
162
+ return { state: 'authenticated', summary: 'MiMo 登录', authMethod: 'api', verification: 'local' };
163
+ return { state: 'configured', summary: '已配置 MiMo 账号,请检查登录', verification: 'local' };
164
+ }
165
+ /** Only unavoidable external inputs remain relevant in an isolated account terminal. */
166
+ export async function assertMimoAccountConfiguration(signal) {
167
+ if (Object.values(await readMimoOwnAuth(signal)).some((value) => value?.type === 'wellknown'))
168
+ throw remote();
169
+ if (process.platform === 'darwin')
170
+ for (const path of [
171
+ join('/Library/Managed Preferences', userInfo().username, 'ai.opencode.managed.plist'),
172
+ '/Library/Managed Preferences/ai.opencode.managed.plist',
173
+ ])
174
+ if (await exists(path))
175
+ throw unavailable();
176
+ signal.throwIfAborted();
177
+ }
178
+ /** Native Config.Service expands references before returning metadata, so inspect before spawning it. */
179
+ export async function assertMimoConfiguration(project, signal) {
180
+ signal.throwIfAborted();
181
+ const { home, config, data } = mimoConfigurationPaths();
182
+ for (const directory of [process.env.MIMOCODE_HOME, config, data, join(home, '.mimocode')])
183
+ if (directory)
184
+ await ownDirectory(directory);
185
+ for (const path of await mimoConfigurationFiles(project)) {
186
+ if (basename(dirname(path)) === '.mimocode')
187
+ await ownDirectory(dirname(path));
188
+ const text = await readConfiguration(path, signal);
189
+ // Native substitution happens on raw JSON/JSONC before parsing, including non-auth fields.
190
+ if (text && /\{(?:file|env):/.test(text))
191
+ throw interpolation();
192
+ }
193
+ // Legacy TOML is imported by native code; managed OpenCode sources do not belong to this CLI.
194
+ const unsupported = [join(config, 'config')];
195
+ const managed = process.platform === 'darwin'
196
+ ? '/Library/Application Support/opencode'
197
+ : process.platform === 'win32'
198
+ ? join(process.env.ProgramData || 'C:\\ProgramData', 'opencode')
199
+ : '/etc/opencode';
200
+ unsupported.push(join(managed, 'mimocode.json'), join(managed, 'mimocode.jsonc'));
201
+ if (process.platform === 'darwin')
202
+ unsupported.push(join('/Library/Managed Preferences', userInfo().username, 'ai.opencode.managed.plist'), '/Library/Managed Preferences/ai.opencode.managed.plist');
203
+ for (const path of unsupported)
204
+ if (await exists(path))
205
+ throw unavailable();
206
+ const authText = await readConfiguration(join(data, 'auth.json'), signal);
207
+ if (authText) {
208
+ let auth;
209
+ try {
210
+ auth = JSON.parse(authText);
211
+ }
212
+ catch {
213
+ throw unavailable();
214
+ }
215
+ if (!auth || typeof auth !== 'object' || Array.isArray(auth))
216
+ throw unavailable();
217
+ if (Object.values(auth).some((value) => value?.type === 'wellknown'))
218
+ throw remote();
219
+ }
220
+ // An active console org supplies remote JSON that native then interpolates. Only inspect its
221
+ // presence; no tokens, account details, or remote config are read or requested here.
222
+ let names;
223
+ try {
224
+ names = await readdir(data);
225
+ }
226
+ catch (error) {
227
+ if (error.code !== 'ENOENT')
228
+ throw unavailable();
229
+ names = [];
230
+ }
231
+ for (const name of names.filter((name) => /^mimocode(?:-[A-Za-z0-9._-]+)?\.db$/.test(name))) {
232
+ signal.throwIfAborted();
233
+ const path = join(data, name);
234
+ const stat = await lstat(path);
235
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1)
236
+ throw unavailable();
237
+ const { DatabaseSync } = await import('node:sqlite');
238
+ signal.throwIfAborted();
239
+ let db;
240
+ let active = false;
241
+ try {
242
+ db = new DatabaseSync(path, { readOnly: true, allowExtension: false });
243
+ db.exec('PRAGMA query_only = ON; PRAGMA trusted_schema = OFF');
244
+ if (db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'account_state'").get())
245
+ active = !!db.prepare('SELECT 1 FROM account_state WHERE active_org_id IS NOT NULL LIMIT 1').get();
246
+ }
247
+ catch {
248
+ throw unavailable();
249
+ }
250
+ finally {
251
+ db?.close();
252
+ }
253
+ if (active)
254
+ throw remote();
255
+ }
256
+ signal.throwIfAborted();
257
+ }
258
+ //# sourceMappingURL=mimo-configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mimo-configuration.js","sourceRoot":"","sources":["../../../src/host/mimo-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF;AACD,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,sBAAsB,CAAC,qBAAqB,CAAC,CAAA;AAC3E,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,IAAI,sBAAsB,CAAC,0BAA0B,CAAC,CAAA;AAClF,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,sBAAsB,CAAC,uBAAuB,CAAC,CAAA;AAExE,kGAAkG;AAClG,MAAM,UAAU,sBAAsB,CACpC,UAII,EAAE;IAEN,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAA;IACtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,EAAE,CAA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QAC5F,MAAM,CAAC,cAAc,EAAE,CAAA;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC7B,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC;YAAE,MAAM,WAAW,EAAE,CAAA;QACpF,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAA;QACpD,MAAM,CAAC,cAAc,EAAE,CAAA;QACvB,IAAI,EAAiD,CAAA;QACrD,IAAI,MAAM,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC;YACH,EAAE,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAA;YACtE,EAAE,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;YAC9D,IAAI,EAAE,CAAC,OAAO,CAAC,6EAA6E,CAAC,CAAC,GAAG,EAAE;gBACjG,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,qEAAqE,CAAC,CAAC,GAAG,EAAE,CAAA;QACtG,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,WAAW,EAAE,CAAA;QACrB,CAAC;gBAAS,CAAC;YACT,EAAE,EAAE,KAAK,EAAE,CAAA;QACb,CAAC;QACD,IAAI,MAAM;YAAE,MAAM,MAAM,EAAE,CAAA;IAC5B,CAAC;IACD,MAAM,CAAC,cAAc,EAAE,CAAA;AACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export function resolveNativeEntry(executable: string, platform?: NodeJS.Platform): string
2
+ export function nativeLaunchArgv(argv: readonly string[], platform?: NodeJS.Platform): string[]
@@ -0,0 +1,179 @@
1
+ // Inspect fixed launcher data; never ask a shell to interpret CLI arguments.
2
+ import { openSync, readSync, fstatSync, closeSync, realpathSync, statSync, existsSync } from 'node:fs'
3
+ import { dirname, extname, isAbsolute, resolve, sep, delimiter, join } from 'node:path'
4
+ import { homedir, userInfo } from 'node:os'
5
+
6
+ const invalid = () => new Error('CLI 启动入口无法确认,请配置原生程序或固定 Node/Bun 入口')
7
+ const batch = (value) => /\.(?:cmd|bat)$/i.test(value)
8
+ function text(path, limit = 128 * 1024) {
9
+ const descriptor = openSync(path, 'r')
10
+ try {
11
+ const info = fstatSync(descriptor)
12
+ if (!info.isFile() || info.size > limit) throw invalid()
13
+ const bytes = Buffer.alloc(info.size + 1)
14
+ const read = readSync(descriptor, bytes, 0, bytes.length, 0)
15
+ const after = fstatSync(descriptor)
16
+ if (read !== info.size || info.size !== after.size || info.mtimeMs !== after.mtimeMs) throw invalid()
17
+ return bytes
18
+ .subarray(0, read)
19
+ .toString('utf8')
20
+ .replace(/^\uFEFF/, '')
21
+ } finally {
22
+ closeSync(descriptor)
23
+ }
24
+ }
25
+ function file(path) {
26
+ const canonical = realpathSync(path)
27
+ if (!statSync(canonical).isFile()) throw invalid()
28
+ return canonical
29
+ }
30
+ function scriptRuntime(path) {
31
+ const descriptor = openSync(path, 'r')
32
+ try {
33
+ const bytes = Buffer.alloc(256)
34
+ const length = readSync(descriptor, bytes, 0, bytes.length, 0)
35
+ const header = bytes.subarray(0, length).toString('utf8').split('\n')[0].trim()
36
+ if (header.startsWith('#!')) {
37
+ const match = /^#!\s*(?:\/usr\/bin\/env\s+(?:-S\s+)?)?(?:[^\s]*\/)?(node|bun)\s*$/.exec(header)
38
+ if (!match) throw invalid()
39
+ return match[1]
40
+ }
41
+ // A fixed npm bin entry can declare its runtime in the package manifest.
42
+ for (let directory = dirname(path), depth = 0; depth < 5; depth++, directory = dirname(directory)) {
43
+ const manifestPath = join(directory, 'package.json')
44
+ if (!existsSync(manifestPath)) continue
45
+ const manifest = JSON.parse(text(manifestPath))
46
+ const bins = typeof manifest.bin === 'string' ? [manifest.bin] : Object.values(manifest.bin ?? {})
47
+ if (bins.some((entry) => typeof entry === 'string' && resolve(directory, entry) === path)) {
48
+ if (manifest.engines?.bun && !manifest.engines?.node) return 'bun'
49
+ return 'node'
50
+ }
51
+ break
52
+ }
53
+ return /\.[cm]?js$/i.test(path) ? 'node' : undefined
54
+ } finally {
55
+ closeSync(descriptor)
56
+ }
57
+ }
58
+ function runtimeProgram(runtime, platform, launcherDirectory) {
59
+ if (runtime === 'node') return process.execPath
60
+ if (runtime !== 'bun') throw invalid()
61
+ const name = platform === 'win32' ? 'bun.exe' : 'bun'
62
+ const candidates = [
63
+ ...(launcherDirectory ? [join(launcherDirectory, name)] : []),
64
+ ...(process.env.PATH ?? '')
65
+ .split(delimiter)
66
+ .map((directory) => directory.replace(/^"|"$/g, ''))
67
+ .filter(isAbsolute)
68
+ .map((directory) => join(directory, name)),
69
+ ...(process.env.BUN_INSTALL ? [join(process.env.BUN_INSTALL, 'bin', name)] : []),
70
+ ...[homedir(), userInfo().homedir].map((home) => join(home, '.bun', 'bin', name)),
71
+ ]
72
+ const candidate = candidates.find((path) => existsSync(path) && statSync(path).isFile())
73
+ if (!candidate) throw new Error('未找到 Bun,请安装该 CLI 所需的 Bun 运行时')
74
+ return file(candidate)
75
+ }
76
+ function inspectBatch(executable, platform) {
77
+ const source = text(file(executable)).trim().replace(/\r\n/g, '\n')
78
+ // Nous' official fallback contains just a fixed interpreter and its encoded
79
+ // launcher. Preserve its own bootstrap; do not guess a virtualenv interpreter.
80
+ const hermes =
81
+ /^@echo off\n"([^"\n%]+)" -I -c "(import base64; exec\(base64\.b64decode\('([A-Za-z0-9+/]+={0,2})'\)\))" %\*$/i.exec(
82
+ source,
83
+ )
84
+ if (hermes) {
85
+ const decoded = Buffer.from(hermes[3], 'base64')
86
+ if (
87
+ !isAbsolute(hermes[1]) ||
88
+ decoded.toString('base64') !== hermes[3] ||
89
+ !decoded.toString('utf8').startsWith('import os, re, sys\n') ||
90
+ !decoded.toString('utf8').includes('import hermes_bootstrap') ||
91
+ !decoded.toString('utf8').includes('from hermes_cli.main import main')
92
+ )
93
+ throw invalid()
94
+ return { kind: 'python', argv: [file(hermes[1]), '-I', '-c', hermes[2]] }
95
+ }
96
+ const entries = new Set()
97
+ const runtimes = new Set()
98
+ for (const original of source.split('\n')) {
99
+ let line = original.trim()
100
+ if (!line || /^@?(?:echo off|rem\b.*)$/i.test(line)) continue
101
+ // npm cmd-shim's standard final control prefix is launcher boilerplate;
102
+ // it is discarded, and nothing from it is executed by this module.
103
+ line = line.replace(/^endLocal & goto #_undefined_# 2>NUL \|\| title [^&\n]+ & /i, '')
104
+ const command =
105
+ /^@?(?:(node|bun)|"%_prog%"|"%(?:~dp0|dp0%)[\\/](node|bun)\.exe")\s+"%(?:~dp0|dp0%)[\\/]([^"\n%]+)"\s+%\*$/i.exec(
106
+ line,
107
+ )
108
+ if (command) {
109
+ const path = file(resolve(dirname(executable), command[3].replace(/[\\/]/g, sep)))
110
+ if (!scriptRuntime(path)) throw invalid()
111
+ entries.add(path)
112
+ if (command[1] || command[2]) runtimes.add((command[1] || command[2]).toLowerCase())
113
+ continue
114
+ }
115
+ const program = /^@?set "?_prog=(?:%(?:~dp0|dp0%)[\\/])?(node|bun)(?:\.exe)?"?$/i.exec(line)
116
+ if (program) {
117
+ runtimes.add(program[1].toLowerCase())
118
+ continue
119
+ }
120
+ if (
121
+ /^@?(?:goto start|:find_dp0|:start|set dp0=%~dp0|exit \/b|setlocal|endlocal|call :find_dp0)$/i.test(
122
+ line,
123
+ ) ||
124
+ /^@?if (?:not )?exist "%(?:~dp0|dp0%)[\\/](?:node|bun)\.exe" \($/i.test(line) ||
125
+ /^\)(?: else \()?$/i.test(line) ||
126
+ /^@?set pathext=%pathext:;\.js;=;%$/i.test(line) ||
127
+ /^@?if (?:not )?defined node_path \($/i.test(line) ||
128
+ /^@?set "node_path=[^"\n&|<>]+"$/i.test(line)
129
+ )
130
+ continue
131
+ throw invalid()
132
+ }
133
+ if (entries.size !== 1 || runtimes.size !== 1) throw invalid()
134
+ const entry = [...entries][0],
135
+ runtime = [...runtimes][0]
136
+ if (scriptRuntime(entry) !== runtime) throw invalid()
137
+ return { kind: runtime, argv: [runtimeProgram(runtime, platform, dirname(executable)), entry] }
138
+ }
139
+
140
+ /** Canonical npm entry for installation identity checks; Python launchers keep their identity. */
141
+ export function resolveNativeEntry(executable, platform = process.platform) {
142
+ if (platform !== 'win32') return executable
143
+ if (isAbsolute(executable) && !extname(executable) && !existsSync(executable)) {
144
+ const extensions = (process.env.PATHEXT || '.EXE;.COM;.CMD;.BAT')
145
+ .split(';')
146
+ .map((extension) => extension.toLowerCase())
147
+ .filter((extension) => /^\.(?:exe|com|cmd|bat)$/.test(extension))
148
+ const candidate = [...new Set(extensions)]
149
+ .map((extension) => executable + extension)
150
+ .find((path) => existsSync(path) && statSync(path).isFile())
151
+ if (candidate) executable = candidate
152
+ }
153
+ if (!batch(executable)) return executable
154
+ const inspected = inspectBatch(executable, platform)
155
+ // Keep Bun's fixed shim identity: it may pin a bundled bun.exe beside the
156
+ // shim which cannot be recovered from only the package's JS path.
157
+ return inspected.kind === 'node' ? inspected.argv[1] : executable
158
+ }
159
+
160
+ /** Windows CreateProcess accepts real programs, not npm command files. */
161
+ export function nativeLaunchArgv(argv, platform = process.platform) {
162
+ if (
163
+ !Array.isArray(argv) ||
164
+ !argv.length ||
165
+ argv.some((value) => typeof value !== 'string' || value.includes('\0'))
166
+ )
167
+ throw invalid()
168
+ if (platform !== 'win32') {
169
+ if (!/\.[cm]?js$/i.test(argv[0])) return [...argv]
170
+ const entry = file(argv[0])
171
+ return [runtimeProgram(scriptRuntime(entry), platform), entry, ...argv.slice(1)]
172
+ }
173
+ const executable = resolveNativeEntry(argv[0], platform),
174
+ arguments_ = argv.slice(1)
175
+ if (batch(executable)) return [...inspectBatch(executable, platform).argv, ...arguments_]
176
+ if (/\.[cm]?js$/i.test(executable) || (extname(executable) === '' && scriptRuntime(executable)))
177
+ return [runtimeProgram(scriptRuntime(executable), platform), file(executable), ...arguments_]
178
+ return [executable, ...arguments_]
179
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProcessBackend } from './process.ts';
2
+ /** One normalization boundary for tasks, metadata and interactive account menus. */
3
+ export declare function nativeProcessBackend(backend: ProcessBackend, platform?: NodeJS.Platform): ProcessBackend;
@@ -0,0 +1,26 @@
1
+ import { nativeLaunchArgv, resolveNativeEntry } from './native-launch.mjs';
2
+ /** One normalization boundary for tasks, metadata and interactive account menus. */
3
+ export function nativeProcessBackend(backend, platform = process.platform) {
4
+ const normalize = (spec) => {
5
+ const argv = nativeLaunchArgv(spec.argv, platform);
6
+ return {
7
+ ...spec,
8
+ argv,
9
+ ...(argv[0] === process.execPath ? { env: { ...spec.env, ELECTRON_RUN_AS_NODE: '1' } } : {}),
10
+ };
11
+ };
12
+ return {
13
+ async resolveExecutable(name) {
14
+ return resolveNativeEntry(await backend.resolveExecutable(resolveNativeEntry(name, platform)), platform);
15
+ },
16
+ spawn(spec) {
17
+ return backend.spawn(normalize(spec));
18
+ },
19
+ ...(backend.spawnTerminal
20
+ ? {
21
+ spawnTerminal: (spec) => backend.spawnTerminal(normalize(spec)),
22
+ }
23
+ : {}),
24
+ };
25
+ }
26
+ //# sourceMappingURL=native-process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-process.js","sourceRoot":"","sources":["../../../src/host/native-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAG1E,oFAAoF;AACpF,MAAM,UAAU,oBAAoB,CAAC,OAAuB,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ;IACvF,MAAM,SAAS,GAAG,CAAiE,IAAO,EAAE,EAAE;QAC5F,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAClD,OAAO;YACL,GAAG,IAAI;YACP,IAAI;YACJ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7F,CAAA;IACH,CAAC,CAAA;IACD,OAAO;QACL,KAAK,CAAC,iBAAiB,CAAC,IAAI;YAC1B,OAAO,kBAAkB,CAAC,MAAM,OAAO,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;QAC1G,CAAC;QACD,KAAK,CAAC,IAAI;YACR,OAAO,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;QACvC,CAAC;QACD,GAAG,CAAC,OAAO,CAAC,aAAa;YACvB,CAAC,CAAC;gBACE,aAAa,EAAE,CAAC,IAAiE,EAAE,EAAE,CACnF,OAAO,CAAC,aAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aAC1C;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { type ModelChoice, type TaskMode } from '../shared/types.ts';
2
+ import type { EventInput, ProtocolResult } from './protocol.ts';
3
+ import { type OpenCodeNativeOptions } from './opencode-native.ts';
4
+ import { probeAccountModels } from './account-models.mjs';
5
+ export interface OpenCodeInput {
6
+ executable: string;
7
+ project: string;
8
+ preference: {
9
+ model: string;
10
+ effort: string;
11
+ };
12
+ mode: TaskMode;
13
+ prompt: string;
14
+ conversationId?: string;
15
+ stateDirectory: string;
16
+ /** Stable private XDG data root shared with account login, not worker databases. */
17
+ authDirectory?: string;
18
+ /** Deprecated compatibility option; ignored. */
19
+ managedCredentials?: boolean;
20
+ nativeHome?: string;
21
+ modelsPath?: string;
22
+ signal?: AbortSignal;
23
+ }
24
+ type Capture = (argv: string[], env?: Record<string, string>) => Promise<string>;
25
+ export interface OpenCodeCredentialConfig {
26
+ zaiCredentialRef?: string;
27
+ resolveCredential?: (ref: string) => Promise<string | undefined>;
28
+ }
29
+ /** Compatibility only: Host credentials are never resolved for OpenCode. */
30
+ export declare function openCodeCredentialEnvironment(_config: OpenCodeCredentialConfig): Promise<Record<string, string>>;
31
+ export declare function openCodeAuthDirectory(stateDirectory?: string): string;
32
+ /** Only the auth data root is shared; each process keeps its own DB/config/cache. */
33
+ export declare function openCodeEnvironment(stateDirectory: string, config: Record<string, unknown>, authDirectory?: string, _managedCredentials?: boolean, modelsPath?: string): Promise<{
34
+ OPENCODE_MODELS_PATH?: string | undefined;
35
+ XDG_CONFIG_HOME: string;
36
+ XDG_DATA_HOME: string;
37
+ XDG_CACHE_HOME: string;
38
+ XDG_STATE_HOME: string;
39
+ TMPDIR: string;
40
+ OPENCODE_DB: string;
41
+ OPENCODE_CONFIG: string;
42
+ OPENCODE_CONFIG_DIR: string;
43
+ OPENCODE_CONFIG_CONTENT: string;
44
+ OPENCODE_PERMISSION: string;
45
+ OPENCODE_AUTO_SHARE: string;
46
+ OPENCODE_DISABLE_AUTOUPDATE: string;
47
+ OPENCODE_DISABLE_PRUNE: string;
48
+ OPENCODE_DISABLE_SHARE: string;
49
+ OPENCODE_DISABLE_DEFAULT_PLUGINS: string;
50
+ OPENCODE_AUTH_CONTENT: string;
51
+ OPENCODE_DISABLE_PROJECT_CONFIG: string;
52
+ OPENCODE_DISABLE_CLAUDE_CODE: string;
53
+ OPENCODE_DISABLE_EXTERNAL_SKILLS: string;
54
+ OPENCODE_DISABLE_LSP_DOWNLOAD: string;
55
+ OPENCODE_DISABLE_MODELS_FETCH: string;
56
+ OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: string;
57
+ OPENCODE_PURE: string;
58
+ }>;
59
+ export declare function prepareOpenCode(input: OpenCodeInput): Promise<{
60
+ argv: string[];
61
+ env: Record<string, string>;
62
+ }>;
63
+ /** CLI default zero prices are not affirmative price evidence. */
64
+ export declare function parseOpenCodeModels(output: string): ModelChoice[];
65
+ export interface OpenCodeDiscoveryOptions extends OpenCodeNativeOptions {
66
+ credentialEnv?: Record<string, string>;
67
+ probeOptions?: Parameters<typeof probeAccountModels>[1];
68
+ }
69
+ export declare function discoverOpenCode(executable: string, capture: Capture, stateDirectory: string, authDirectory?: string, _managedCredentials?: boolean, options?: OpenCodeDiscoveryOptions): Promise<ModelChoice[]>;
70
+ /** Native OpenCode JSONL; success needs clean EOF after stop, identity and no failed tool. */
71
+ export declare class OpenCodeProtocol {
72
+ private emit;
73
+ private identify;
74
+ private maxLineBytes;
75
+ private decoder;
76
+ private pending;
77
+ private ended;
78
+ private stopped;
79
+ private sawStep;
80
+ private failure?;
81
+ private response;
82
+ private steps;
83
+ private textParts;
84
+ private openTools;
85
+ conversationId?: string;
86
+ result?: ProtocolResult;
87
+ constructor(emit: (event: EventInput) => void, identify: (id: string) => void, maxLineBytes: number);
88
+ feed(chunk: Buffer | string): void;
89
+ end(): void;
90
+ private step;
91
+ private id;
92
+ private line;
93
+ }
94
+ export {};