@magclaw/cli-core 0.1.26 → 0.1.27
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.
- package/package.json +1 -1
- package/src/cli.js +77 -17
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -785,17 +785,66 @@ export function selectRuntimeCommandPath(output, fallback = '', platform = proce
|
|
|
785
785
|
.sort((left, right) => left.score - right.score || left.index - right.index)[0]?.file || paths[0];
|
|
786
786
|
}
|
|
787
787
|
|
|
788
|
+
function homeDirForEnv(env = process.env) {
|
|
789
|
+
return String(env.HOME || env.USERPROFILE || os.homedir() || '').trim();
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function uniquePathEntries(entries = []) {
|
|
793
|
+
const seen = new Set();
|
|
794
|
+
const result = [];
|
|
795
|
+
for (const entry of entries) {
|
|
796
|
+
const value = String(entry || '').trim();
|
|
797
|
+
if (!value) continue;
|
|
798
|
+
const key = durablePathKey(value);
|
|
799
|
+
if (seen.has(key)) continue;
|
|
800
|
+
seen.add(key);
|
|
801
|
+
result.push(value);
|
|
802
|
+
}
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export function runtimeSearchPathEntries(env = process.env) {
|
|
807
|
+
const home = homeDirForEnv(env);
|
|
808
|
+
const userEntries = home ? [
|
|
809
|
+
path.join(home, '.local', 'bin'),
|
|
810
|
+
path.join(home, 'bin'),
|
|
811
|
+
path.join(home, '.npm-global', 'bin'),
|
|
812
|
+
path.join(home, '.volta', 'bin'),
|
|
813
|
+
path.join(home, '.bun', 'bin'),
|
|
814
|
+
process.platform === 'win32' ? path.join(home, 'AppData', 'Roaming', 'npm') : '',
|
|
815
|
+
] : [];
|
|
816
|
+
const platformEntries = process.platform === 'darwin'
|
|
817
|
+
? ['/opt/homebrew/bin', '/opt/homebrew/sbin', '/usr/local/bin', '/usr/local/sbin']
|
|
818
|
+
: process.platform === 'win32'
|
|
819
|
+
? []
|
|
820
|
+
: ['/usr/local/bin', '/usr/local/sbin'];
|
|
821
|
+
return uniquePathEntries([
|
|
822
|
+
...pathDirs(env),
|
|
823
|
+
env.NVM_BIN,
|
|
824
|
+
env.VOLTA_HOME ? path.join(env.VOLTA_HOME, 'bin') : '',
|
|
825
|
+
env.BUN_INSTALL ? path.join(env.BUN_INSTALL, 'bin') : '',
|
|
826
|
+
path.dirname(process.execPath),
|
|
827
|
+
...userEntries,
|
|
828
|
+
...platformEntries,
|
|
829
|
+
]);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function runtimeDetectionEnv(env = process.env) {
|
|
833
|
+
return {
|
|
834
|
+
...env,
|
|
835
|
+
PATH: runtimeSearchPathEntries(env).join(path.delimiter),
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
|
|
788
839
|
function commandExists(command, env = process.env) {
|
|
840
|
+
const runtimeEnv = runtimeDetectionEnv(env);
|
|
789
841
|
const checker = process.platform === 'win32' ? 'where' : 'command';
|
|
790
842
|
const args = process.platform === 'win32' ? [command] : ['-v', command];
|
|
791
843
|
const result = process.platform === 'win32'
|
|
792
|
-
? commandOutput(checker, args, { env, timeoutMs: 1500 })
|
|
793
|
-
: commandOutput('/bin/sh', ['-lc', `command -v ${JSON.stringify(command)}`], { env, timeoutMs: 1500 });
|
|
844
|
+
? commandOutput(checker, args, { env: runtimeEnv, timeoutMs: 1500 })
|
|
845
|
+
: commandOutput('/bin/sh', ['-lc', `command -v ${JSON.stringify(command)}`], { env: runtimeEnv, timeoutMs: 1500 });
|
|
794
846
|
if (result.ok) return selectRuntimeCommandPath(result.stdout, command);
|
|
795
|
-
for (const candidate of
|
|
796
|
-
path.join(path.dirname(process.execPath), command),
|
|
797
|
-
path.join(os.homedir(), '.local', 'bin', command),
|
|
798
|
-
]) {
|
|
847
|
+
for (const candidate of runtimeSearchPathEntries(runtimeEnv).map((dir) => path.join(dir, command))) {
|
|
799
848
|
if (existsSync(candidate)) return candidate;
|
|
800
849
|
}
|
|
801
850
|
return '';
|
|
@@ -1046,13 +1095,15 @@ async function tryInstallCliShim(options = {}, env = process.env) {
|
|
|
1046
1095
|
}
|
|
1047
1096
|
|
|
1048
1097
|
function runtimeVersion(command, env = process.env) {
|
|
1049
|
-
const
|
|
1098
|
+
const runtimeEnv = runtimeDetectionEnv(env);
|
|
1099
|
+
const result = commandOutput(command, ['--version'], { env: runtimeEnv, timeoutMs: 3000 });
|
|
1050
1100
|
if (!result.ok && result.error?.code === 'ENOENT') return '';
|
|
1051
1101
|
return result.stdout || result.stderr || '';
|
|
1052
1102
|
}
|
|
1053
1103
|
|
|
1054
1104
|
function codexAppServerCapable(command, env = process.env) {
|
|
1055
|
-
const
|
|
1105
|
+
const runtimeEnv = runtimeDetectionEnv(env);
|
|
1106
|
+
const result = commandOutput(command, ['app-server', '--help'], { env: runtimeEnv, timeoutMs: 3000 });
|
|
1056
1107
|
if (result.error?.code === 'ENOENT') return false;
|
|
1057
1108
|
if (result.ok) return true;
|
|
1058
1109
|
const output = `${result.stdout}\n${result.stderr}`.toLowerCase();
|
|
@@ -1060,6 +1111,7 @@ function codexAppServerCapable(command, env = process.env) {
|
|
|
1060
1111
|
}
|
|
1061
1112
|
|
|
1062
1113
|
function defaultCodexCommand(env = process.env) {
|
|
1114
|
+
const runtimeEnv = runtimeDetectionEnv(env);
|
|
1063
1115
|
const macAppBinary = '/Applications/Codex.app/Contents/Resources/codex';
|
|
1064
1116
|
const candidates = [env.CODEX_PATH, env.MAGCLAW_CODEX_PATH, macAppBinary, 'codex']
|
|
1065
1117
|
.map((item) => String(item || '').trim())
|
|
@@ -1067,9 +1119,9 @@ function defaultCodexCommand(env = process.env) {
|
|
|
1067
1119
|
for (const candidate of [...new Set(candidates)]) {
|
|
1068
1120
|
const command = runtimeCommandHasPathSeparator(candidate)
|
|
1069
1121
|
? candidate
|
|
1070
|
-
: commandExists(candidate,
|
|
1122
|
+
: commandExists(candidate, runtimeEnv) || candidate;
|
|
1071
1123
|
if (runtimeCommandHasPathSeparator(command) && !existsSync(command)) continue;
|
|
1072
|
-
const result = commandOutput(command, ['--version'], { env, timeoutMs: 3000 });
|
|
1124
|
+
const result = commandOutput(command, ['--version'], { env: runtimeEnv, timeoutMs: 3000 });
|
|
1073
1125
|
if (result.ok) return command;
|
|
1074
1126
|
}
|
|
1075
1127
|
return candidates[0] || 'codex';
|
|
@@ -1088,7 +1140,7 @@ function codexRuntimeModels(command, env = process.env) {
|
|
|
1088
1140
|
reasoningEffort: ['low', 'medium', 'high', 'xhigh'],
|
|
1089
1141
|
defaultReasoningEffort: 'medium',
|
|
1090
1142
|
};
|
|
1091
|
-
const result = commandOutput(command, ['debug', 'models'], { env, timeoutMs: 5000 });
|
|
1143
|
+
const result = commandOutput(command, ['debug', 'models'], { env: runtimeDetectionEnv(env), timeoutMs: 5000 });
|
|
1092
1144
|
if (!result.ok) return fallback;
|
|
1093
1145
|
try {
|
|
1094
1146
|
const data = JSON.parse(result.stdout || '{}');
|
|
@@ -1121,14 +1173,15 @@ function codexRuntimeModels(command, env = process.env) {
|
|
|
1121
1173
|
}
|
|
1122
1174
|
|
|
1123
1175
|
export async function detectRuntimes(env = process.env) {
|
|
1124
|
-
const
|
|
1176
|
+
const runtimeEnv = runtimeDetectionEnv(env);
|
|
1177
|
+
const codexCommand = defaultCodexCommand(runtimeEnv);
|
|
1125
1178
|
const candidates = [
|
|
1126
1179
|
{
|
|
1127
1180
|
id: 'codex',
|
|
1128
1181
|
name: 'Codex CLI',
|
|
1129
1182
|
command: codexCommand,
|
|
1130
1183
|
createSupported: true,
|
|
1131
|
-
modelsFor: (command) => codexRuntimeModels(command,
|
|
1184
|
+
modelsFor: (command) => codexRuntimeModels(command, runtimeEnv),
|
|
1132
1185
|
},
|
|
1133
1186
|
{
|
|
1134
1187
|
id: 'claude-code',
|
|
@@ -1180,10 +1233,10 @@ export async function detectRuntimes(env = process.env) {
|
|
|
1180
1233
|
},
|
|
1181
1234
|
];
|
|
1182
1235
|
return candidates.map((item) => {
|
|
1183
|
-
const pathValue = runtimeCommandHasPathSeparator(item.command) ? (existsSync(item.command) ? item.command : '') : commandExists(item.command,
|
|
1236
|
+
const pathValue = runtimeCommandHasPathSeparator(item.command) ? (existsSync(item.command) ? item.command : '') : commandExists(item.command, runtimeEnv);
|
|
1184
1237
|
const runtimeCommand = pathValue || item.command;
|
|
1185
1238
|
const installed = Boolean(pathValue);
|
|
1186
|
-
const version = installed ? runtimeVersion(runtimeCommand,
|
|
1239
|
+
const version = installed ? runtimeVersion(runtimeCommand, runtimeEnv) : '';
|
|
1187
1240
|
const modelInfo = installed && item.modelsFor ? item.modelsFor(runtimeCommand) : {
|
|
1188
1241
|
models: item.models || [],
|
|
1189
1242
|
modelNames: (item.models || []).map((model) => ({ slug: model, name: model })),
|
|
@@ -1199,7 +1252,7 @@ export async function detectRuntimes(env = process.env) {
|
|
|
1199
1252
|
installed,
|
|
1200
1253
|
version,
|
|
1201
1254
|
createSupported: item.createSupported !== false,
|
|
1202
|
-
appServer: item.id === 'codex' && installed ? codexAppServerCapable(runtimeCommand,
|
|
1255
|
+
appServer: item.id === 'codex' && installed ? codexAppServerCapable(runtimeCommand, runtimeEnv) : false,
|
|
1203
1256
|
...modelInfo,
|
|
1204
1257
|
};
|
|
1205
1258
|
});
|
|
@@ -4271,6 +4324,10 @@ async function writeLauncher(profile, env = process.env) {
|
|
|
4271
4324
|
const npmPath = commandExists('npm', env);
|
|
4272
4325
|
const nodeDir = path.dirname(process.execPath);
|
|
4273
4326
|
const npmDir = npmPath ? path.dirname(npmPath) : '';
|
|
4327
|
+
const launchPathEntries = runtimeSearchPathEntries({
|
|
4328
|
+
...env,
|
|
4329
|
+
PATH: [nodeDir, npmDir, env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin'].filter(Boolean).join(path.delimiter),
|
|
4330
|
+
});
|
|
4274
4331
|
const commandMode = String(env.MAGCLAW_DAEMON_COMMAND_MODE || '').trim().toLowerCase();
|
|
4275
4332
|
const useNpmLauncher = Boolean(npmPath) && !['local', 'local-repo', 'repo', 'source'].includes(commandMode);
|
|
4276
4333
|
const launcher = path.join(paths.runDir, 'launcher.js');
|
|
@@ -4322,6 +4379,8 @@ async function writeLauncher(profile, env = process.env) {
|
|
|
4322
4379
|
`const useNpmLauncher = ${JSON.stringify(useNpmLauncher)};`,
|
|
4323
4380
|
`const nodeDir = ${JSON.stringify(nodeDir)};`,
|
|
4324
4381
|
`const npmDir = ${JSON.stringify(npmDir)};`,
|
|
4382
|
+
`const pathDelimiter = ${JSON.stringify(path.delimiter)};`,
|
|
4383
|
+
`const launchPathEntries = ${JSON.stringify(launchPathEntries)};`,
|
|
4325
4384
|
`const fallbackBin = ${JSON.stringify(fallbackBin)};`,
|
|
4326
4385
|
`const profile = ${JSON.stringify(paths.profile)};`,
|
|
4327
4386
|
`const daemonHome = ${JSON.stringify(daemonRoot(env))};`,
|
|
@@ -4344,7 +4403,7 @@ async function writeLauncher(profile, env = process.env) {
|
|
|
4344
4403
|
"const args = useNpmLauncher",
|
|
4345
4404
|
" ? ['exec', '--yes', '--package', packageSpec, '--', packageBin, 'connect', '--profile', profile]",
|
|
4346
4405
|
" : [fallbackBin, 'connect', '--profile', profile];",
|
|
4347
|
-
"const launchPath = [nodeDir, npmDir, process.env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin'].filter(Boolean).join(
|
|
4406
|
+
"const launchPath = [...launchPathEntries, nodeDir, npmDir, process.env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin'].filter(Boolean).join(pathDelimiter);",
|
|
4348
4407
|
"const childEnv = {",
|
|
4349
4408
|
" ...process.env,",
|
|
4350
4409
|
" MAGCLAW_DAEMON_HOME: daemonHome,",
|
|
@@ -5289,6 +5348,7 @@ async function runComputerSetup(flags, env = process.env) {
|
|
|
5289
5348
|
...result,
|
|
5290
5349
|
cli,
|
|
5291
5350
|
computerId: config.computerId,
|
|
5351
|
+
computerName: config.computerName || config.name || displayName,
|
|
5292
5352
|
profile: config.profile,
|
|
5293
5353
|
serverName: config.serverName,
|
|
5294
5354
|
serverSlug: approved.serverSlug || serverSlug,
|