@yeaft/webchat-agent 1.0.199 → 1.0.200
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/local-runtime/version.json +1 -1
- package/package.json +1 -1
- package/sdk/utils.js +36 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.200"}
|
package/package.json
CHANGED
package/sdk/utils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { platform, homedir } from 'os';
|
|
7
|
-
import { join,
|
|
7
|
+
import { join, win32 } from 'path';
|
|
8
8
|
import { existsSync, readFileSync } from 'fs';
|
|
9
9
|
import { execSync } from 'child_process';
|
|
10
10
|
|
|
@@ -152,42 +152,48 @@ export function isWindows() {
|
|
|
152
152
|
return platform() === 'win32';
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Resolve a Windows npm .cmd shim to the real Claude entrypoint.
|
|
157
|
+
*
|
|
158
|
+
* Earlier Claude Code releases exposed a JavaScript CLI. Current releases expose
|
|
159
|
+
* a native `bin/claude.exe`. Calling the generated PowerShell shim is unsafe for
|
|
160
|
+
* our long-lived stream-json stdin: the shim pipes `$input` and waits for EOF
|
|
161
|
+
* before starting Claude, so the first user message never reaches the CLI.
|
|
162
|
+
*/
|
|
163
|
+
export function resolveWindowsClaudeCommand(execPath, {
|
|
164
|
+
readFile = path => readFileSync(path, 'utf-8'),
|
|
165
|
+
fileExists = existsSync,
|
|
166
|
+
nodeExecutable = process.execPath,
|
|
167
|
+
} = {}) {
|
|
168
|
+
let cmdContent;
|
|
169
|
+
try {
|
|
170
|
+
cmdContent = readFile(execPath);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw new Error(`Failed to read Claude Code command shim at ${execPath}: ${error.message}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const targetPaths = [...cmdContent.matchAll(/%dp0%\\([^"\r\n]+?\.(?:exe|js))(?=["\s])/gi)]
|
|
176
|
+
.map(match => win32.resolve(win32.dirname(execPath), match[1]));
|
|
177
|
+
const targetPath = targetPaths.find(path => path.toLowerCase().endsWith('.js') && fileExists(path))
|
|
178
|
+
|| targetPaths.find(path => win32.basename(path).toLowerCase() === 'claude.exe' && fileExists(path));
|
|
179
|
+
if (!targetPath) {
|
|
180
|
+
throw new Error(`Claude Code command shim at ${execPath} could not resolve the executable target`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (targetPath.toLowerCase().endsWith('.js')) {
|
|
184
|
+
return { command: nodeExecutable, prefixArgs: [targetPath], spawnOpts: {} };
|
|
185
|
+
}
|
|
186
|
+
return { command: targetPath, prefixArgs: [], spawnOpts: {} };
|
|
187
|
+
}
|
|
188
|
+
|
|
155
189
|
/**
|
|
156
190
|
* Resolve Claude executable into { command, prefixArgs, spawnOpts } for spawn().
|
|
157
|
-
* On Windows (npm install): parses .cmd wrapper to find cli.js, then calls node directly.
|
|
158
|
-
* This avoids cmd.exe flash and PowerShell script execution policy issues.
|
|
159
191
|
*/
|
|
160
192
|
export function resolveClaudeCommand() {
|
|
161
193
|
const execPath = getDefaultClaudeCodePath();
|
|
162
194
|
|
|
163
195
|
if (isWindows() && execPath.toLowerCase().endsWith('.cmd')) {
|
|
164
|
-
|
|
165
|
-
// "%_prog%" "%dp0%\node_modules\@anthropic-ai\claude-code\cli.js" %*
|
|
166
|
-
// 解析出 cli.js 的相对路径,拼成绝对路径后用 node 直接调用
|
|
167
|
-
try {
|
|
168
|
-
const cmdContent = readFileSync(execPath, 'utf-8');
|
|
169
|
-
const match = cmdContent.match(/%dp0%\\(.+?\.js)"/i) ||
|
|
170
|
-
cmdContent.match(/%dp0%\\(.+?\.js)/i);
|
|
171
|
-
if (match) {
|
|
172
|
-
const cliJsPath = join(dirname(execPath), match[1]);
|
|
173
|
-
if (existsSync(cliJsPath)) {
|
|
174
|
-
return {
|
|
175
|
-
command: process.execPath, // node
|
|
176
|
-
prefixArgs: [cliJsPath],
|
|
177
|
-
spawnOpts: {},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
} catch {}
|
|
182
|
-
// 解析失败时 fallback: 用 powershell 执行 .ps1
|
|
183
|
-
const ps1Path = execPath.slice(0, -4) + '.ps1';
|
|
184
|
-
if (existsSync(ps1Path)) {
|
|
185
|
-
return {
|
|
186
|
-
command: 'powershell.exe',
|
|
187
|
-
prefixArgs: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', ps1Path],
|
|
188
|
-
spawnOpts: {},
|
|
189
|
-
};
|
|
190
|
-
}
|
|
196
|
+
return resolveWindowsClaudeCommand(execPath);
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
return { command: execPath, prefixArgs: [], spawnOpts: {} };
|