dimcode 0.0.63 → 0.0.64-beta.1

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 (42) hide show
  1. package/bin/dim.mjs +180 -0
  2. package/dist/ink.mjs +1295 -0
  3. package/package.json +12 -69
  4. package/README.md +0 -128
  5. package/cli.mjs +0 -99
  6. package/dist/aihubmix.json +0 -1
  7. package/dist/anthropic.json +0 -1
  8. package/dist/ark-code.json +0 -1
  9. package/dist/bailian-coding-plan.json +0 -1
  10. package/dist/cli.mjs +0 -1248
  11. package/dist/custom-provider.json +0 -1
  12. package/dist/deepseek.json +0 -1
  13. package/dist/google.json +0 -1
  14. package/dist/kimi-for-coding.json +0 -1
  15. package/dist/lm-studio.json +0 -1
  16. package/dist/minimax-cn-coding-plan.json +0 -1
  17. package/dist/minimax-cn.json +0 -1
  18. package/dist/minimax-coding-plan.json +0 -1
  19. package/dist/minimax.json +0 -1
  20. package/dist/models/aihubmix.json +0 -1
  21. package/dist/models/custom-provider.json +0 -1
  22. package/dist/models/openrouter.json +0 -1
  23. package/dist/models/siliconflow-com.json +0 -1
  24. package/dist/models/siliconflow.json +0 -1
  25. package/dist/models/zenmux.json +0 -1
  26. package/dist/moonshot-ai.json +0 -1
  27. package/dist/moonshot.json +0 -1
  28. package/dist/next-api-oauth.json +0 -1
  29. package/dist/ollama.json +0 -1
  30. package/dist/openai.json +0 -1
  31. package/dist/openrouter.json +0 -1
  32. package/dist/ppinfra.json +0 -1
  33. package/dist/siliconflow-com.json +0 -1
  34. package/dist/siliconflow.json +0 -1
  35. package/dist/xai.json +0 -1
  36. package/dist/xiaomi-token-plan-cn.json +0 -1
  37. package/dist/zai-coding-plan.json +0 -1
  38. package/dist/zai.json +0 -1
  39. package/dist/zenmux.json +0 -1
  40. package/dist/zhipuai-coding-plan.json +0 -1
  41. package/dist/zhipuai.json +0 -1
  42. package/icon.png +0 -0
package/bin/dim.mjs ADDED
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+ import childProcess from 'node:child_process'
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+ import process from 'node:process'
7
+ import { fileURLToPath, pathToFileURL } from 'node:url'
8
+
9
+ const __filename = fileURLToPath(import.meta.url)
10
+ const __dirname = path.dirname(__filename)
11
+ const isWindows = os.platform() === 'win32'
12
+
13
+ let wrapperVersion = ''
14
+ try {
15
+ const pkg = JSON.parse(
16
+ fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'),
17
+ )
18
+ wrapperVersion = pkg.version || ''
19
+ }
20
+ catch {}
21
+
22
+ const wrapperDir = path.join(__dirname, '..').replace(/\\/g, '/').toLowerCase()
23
+ const wrapperPm
24
+ = wrapperDir.includes('.bun/') || wrapperDir.includes('bun/install/')
25
+ ? 'bun'
26
+ : 'npm'
27
+
28
+ const args = process.argv.slice(2)
29
+ const routing = resolveRouting(args)
30
+
31
+ if (routing.target === 'opentui') {
32
+ runOpentui(routing.forwardArgs)
33
+ }
34
+ else {
35
+ await runInk()
36
+ }
37
+
38
+ function resolveRouting(argv) {
39
+ // Explicit `dim ink ...` forces the Ink TUI fallback.
40
+ if (argv[0] === 'ink')
41
+ return { target: 'ink', forwardArgs: argv.slice(1) }
42
+ // Explicit `dim opentui ...` also routes to the opentui binary
43
+ // (kept for symmetry; opentui is the default).
44
+ if (argv[0] === 'opentui')
45
+ return { target: 'opentui', forwardArgs: argv.slice(1) }
46
+
47
+ // Default: everything goes to the opentui binary.
48
+ return { target: 'opentui', forwardArgs: argv }
49
+ }
50
+
51
+ async function runInk() {
52
+ const inkEntry = path.join(__dirname, '..', 'dist', 'ink.mjs')
53
+ if (!fs.existsSync(inkEntry)) {
54
+ console.error('[dim] Ink bundle missing: ' + inkEntry)
55
+ console.error('[dim] Try reinstalling dimcode@beta.')
56
+ process.exit(1)
57
+ }
58
+ // Inner CLI's DEFAULT_PACKAGE_NAME is already 'dimcode', so no override
59
+ // needed. Pass wrapper version through for diagnostics.
60
+ process.env.DIMCODE_NPM_PACKAGE = 'dimcode'
61
+ process.env.DIMCODE_NPM_PACKAGE_MANAGER = wrapperPm
62
+ if (wrapperVersion)
63
+ process.env.DIMCODE_NPM_PACKAGE_VERSION = wrapperVersion
64
+ try {
65
+ await import(pathToFileURL(inkEntry).href)
66
+ }
67
+ catch (err) {
68
+ console.error('[dim] Failed to start Ink TUI:')
69
+ console.error(err)
70
+ process.exit(1)
71
+ }
72
+ }
73
+
74
+ function runOpentui(restArgs) {
75
+ const envPath = process.env.DIMCODE_BIN_PATH
76
+ if (envPath) {
77
+ if (!fs.existsSync(envPath)) {
78
+ console.error(
79
+ '[dim] DIMCODE_BIN_PATH is set but file not found: ' + envPath,
80
+ )
81
+ process.exit(1)
82
+ }
83
+ spawnBinary(envPath, restArgs)
84
+ return
85
+ }
86
+
87
+ const scriptPath = fs.realpathSync(__filename)
88
+ const scriptDir = path.dirname(scriptPath)
89
+
90
+ const platformMap = { darwin: 'darwin', linux: 'linux', win32: 'windows' }
91
+ const archMap = { x64: 'x64', arm64: 'arm64' }
92
+ const platform = platformMap[os.platform()] || os.platform()
93
+ const arch = archMap[os.arch()] || os.arch()
94
+ const base = 'dimcode-' + platform + '-' + arch
95
+ const binary = platform === 'windows' ? 'dimcode.exe' : 'dimcode'
96
+
97
+ if (process.env.DIMCODE_DEBUG) {
98
+ console.error('[dim] Wrapper version: ' + wrapperVersion)
99
+ console.error('[dim] Platform: ' + platform + ' Arch: ' + arch)
100
+ console.error('[dim] Looking for package: ' + base)
101
+ console.error('[dim] Script dir: ' + scriptDir)
102
+ }
103
+
104
+ const resolved = findBinary(scriptDir, base, binary)
105
+ if (!resolved) {
106
+ console.error(
107
+ '[dim] Could not find the opentui binary for your platform.\n'
108
+ + '\n'
109
+ + ' Platform: ' + os.platform() + ' (' + platform + ')\n'
110
+ + ' Arch: ' + os.arch() + ' (' + arch + ')\n'
111
+ + ' Expected: ' + base + '/bin/' + binary + '\n'
112
+ + ' Searched: ' + scriptDir + ' (and parent directories)\n'
113
+ + '\n'
114
+ + 'Try manually installing the platform package:\n'
115
+ + ' npm install ' + base + '\n',
116
+ )
117
+ process.exit(1)
118
+ }
119
+
120
+ if (process.env.DIMCODE_DEBUG)
121
+ console.error('[dim] Resolved binary: ' + resolved)
122
+
123
+ spawnBinary(resolved, restArgs)
124
+ }
125
+
126
+ function findBinary(startDir, base, binary) {
127
+ let current = startDir
128
+ for (;;) {
129
+ const modules = path.join(current, 'node_modules')
130
+ if (fs.existsSync(modules)) {
131
+ const candidate = path.join(modules, base, 'bin', binary)
132
+ if (fs.existsSync(candidate))
133
+ return candidate
134
+ }
135
+ const parent = path.dirname(current)
136
+ if (parent === current)
137
+ return
138
+ current = parent
139
+ }
140
+ }
141
+
142
+ function spawnBinary(target, forwardedArgs) {
143
+ const env = {
144
+ ...process.env,
145
+ DIMCODE_NPM_PACKAGE: 'dimcode',
146
+ DIMCODE_NPM_PACKAGE_MANAGER: wrapperPm,
147
+ DIMCODE_NPM_PACKAGE_ROOT: path.resolve(__dirname, '..'),
148
+ }
149
+ if (wrapperVersion)
150
+ env.DIMCODE_NPM_PACKAGE_VERSION = wrapperVersion
151
+
152
+ const result = childProcess.spawnSync(target, forwardedArgs, {
153
+ stdio: 'inherit',
154
+ cwd: process.cwd(),
155
+ env,
156
+ windowsHide: false,
157
+ })
158
+ if (result.error) {
159
+ console.error(
160
+ '[dim] Failed to start opentui binary: ' + result.error.message,
161
+ )
162
+ if (isWindows) {
163
+ console.error('[dim] Binary path: ' + target)
164
+ if (result.error.code === 'ENOENT') {
165
+ console.error(
166
+ '[dim] The binary file was not found. Try reinstalling:',
167
+ )
168
+ console.error(
169
+ ' npm uninstall -g dimcode && npm install -g dimcode@beta',
170
+ )
171
+ }
172
+ }
173
+ process.exit(1)
174
+ }
175
+ if (result.status !== 0 && result.status !== null) {
176
+ if (process.env.DIMCODE_DEBUG)
177
+ console.error('[dim] Binary exited with code: ' + result.status)
178
+ }
179
+ process.exit(typeof result.status === 'number' ? result.status : 0)
180
+ }