mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 10:20:45 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
91
openclaw/scripts/npm-runner.mjs
Normal file
91
openclaw/scripts/npm-runner.mjs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { buildCmdExeCommandLine, resolvePathEnvKey } from "./windows-cmd-helpers.mjs";
|
||||
|
||||
function resolveToolchainNpmRunner(params) {
|
||||
const npmCliCandidates = [
|
||||
params.pathImpl.resolve(params.nodeDir, "../lib/node_modules/npm/bin/npm-cli.js"),
|
||||
params.pathImpl.resolve(params.nodeDir, "node_modules/npm/bin/npm-cli.js"),
|
||||
];
|
||||
const npmCliPath = npmCliCandidates.find((candidate) => params.existsSync(candidate));
|
||||
if (npmCliPath) {
|
||||
return {
|
||||
command:
|
||||
params.platform === "win32"
|
||||
? params.pathImpl.join(params.nodeDir, "node.exe")
|
||||
: params.pathImpl.join(params.nodeDir, "node"),
|
||||
args: [npmCliPath, ...params.npmArgs],
|
||||
shell: false,
|
||||
};
|
||||
}
|
||||
if (params.platform !== "win32") {
|
||||
return null;
|
||||
}
|
||||
const npmExePath = params.pathImpl.resolve(params.nodeDir, "npm.exe");
|
||||
if (params.existsSync(npmExePath)) {
|
||||
return {
|
||||
command: npmExePath,
|
||||
args: params.npmArgs,
|
||||
shell: false,
|
||||
};
|
||||
}
|
||||
const npmCmdPath = params.pathImpl.resolve(params.nodeDir, "npm.cmd");
|
||||
if (params.existsSync(npmCmdPath)) {
|
||||
return {
|
||||
command: params.comSpec,
|
||||
args: ["/d", "/s", "/c", buildCmdExeCommandLine(npmCmdPath, params.npmArgs)],
|
||||
shell: false,
|
||||
windowsVerbatimArguments: true,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function resolveNpmRunner(params = {}) {
|
||||
const execPath = params.execPath ?? process.execPath;
|
||||
const npmArgs = params.npmArgs ?? [];
|
||||
const existsSync = params.existsSync ?? fs.existsSync;
|
||||
const env = params.env ?? process.env;
|
||||
const platform = params.platform ?? process.platform;
|
||||
const comSpec = params.comSpec ?? env.ComSpec ?? "cmd.exe";
|
||||
const pathImpl = platform === "win32" ? path.win32 : path.posix;
|
||||
const nodeDir = pathImpl.dirname(execPath);
|
||||
const npmToolchain = resolveToolchainNpmRunner({
|
||||
comSpec,
|
||||
existsSync,
|
||||
nodeDir,
|
||||
npmArgs,
|
||||
pathImpl,
|
||||
platform,
|
||||
});
|
||||
if (npmToolchain) {
|
||||
return npmToolchain;
|
||||
}
|
||||
if (platform === "win32") {
|
||||
const expectedPaths = [
|
||||
pathImpl.resolve(nodeDir, "../lib/node_modules/npm/bin/npm-cli.js"),
|
||||
pathImpl.resolve(nodeDir, "node_modules/npm/bin/npm-cli.js"),
|
||||
pathImpl.resolve(nodeDir, "npm.exe"),
|
||||
pathImpl.resolve(nodeDir, "npm.cmd"),
|
||||
];
|
||||
throw new Error(
|
||||
`failed to resolve a toolchain-local npm next to ${execPath}. ` +
|
||||
`Checked: ${expectedPaths.join(", ")}. ` +
|
||||
"OpenClaw refuses to shell out to bare npm on Windows; install a Node.js toolchain that bundles npm or run with a matching Node installation.",
|
||||
);
|
||||
}
|
||||
const pathKey = resolvePathEnvKey(env);
|
||||
const currentPath = env[pathKey];
|
||||
return {
|
||||
command: "npm",
|
||||
args: npmArgs,
|
||||
shell: false,
|
||||
env: {
|
||||
...env,
|
||||
[pathKey]:
|
||||
typeof currentPath === "string" && currentPath.length > 0
|
||||
? `${nodeDir}${path.delimiter}${currentPath}`
|
||||
: nodeDir,
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue