

























@@ -13,13 +13,28 @@ const bundledRuntimeRootFragments = ["/dist/extensions/", "/dist-runtime/extensi
1313const DEFAULT_PLUGIN_LIST_TIMEOUT_MS = 30_000;
1414const DEFAULT_PLUGIN_LIST_MAX_BUFFER_BYTES = 4 * 1024 * 1024;
151516-function positiveEnvInt(name, fallback) {
16+function readIntegerEnv(name, fallback, minimum) {
1717const raw = process.env[name];
18-if (raw === undefined || raw === "") {
18+if (raw == null || raw === "") {
1919return fallback;
2020}
21-const value = Number.parseInt(raw, 10);
22-return Number.isSafeInteger(value) && value > 0 ? value : fallback;
21+const text = raw.trim();
22+if (!/^\d+$/u.test(text)) {
23+throw new Error(`invalid ${name}: ${text}`);
24+}
25+const value = Number(text);
26+if (!Number.isSafeInteger(value) || value < minimum) {
27+throw new Error(`invalid ${name}: ${text}`);
28+}
29+return value;
30+}
31+32+function readPositiveIntEnv(name, fallback) {
33+return readIntegerEnv(name, fallback, 1);
34+}
35+36+function readNonNegativeIntEnv(name, fallback) {
37+return readIntegerEnv(name, fallback, 0);
2338}
24392540function resolveStateDir() {
@@ -53,15 +68,15 @@ function resolveOpenClawEntry() {
53685469function readPluginsList() {
5570const entry = resolveOpenClawEntry();
56-const timeoutMs = positiveEnvInt(
71+const timeoutMs = readPositiveIntEnv(
5772"OPENCLAW_BUNDLED_PLUGIN_LIST_TIMEOUT_MS",
5873DEFAULT_PLUGIN_LIST_TIMEOUT_MS,
5974);
6075const result = spawnSync(process.execPath, [entry, "plugins", "list", "--json"], {
6176cwd: process.cwd(),
6277encoding: "utf8",
6378env: process.env,
64-maxBuffer: positiveEnvInt(
79+maxBuffer: readPositiveIntEnv(
6580"OPENCLAW_BUNDLED_PLUGIN_LIST_MAX_BUFFER_BYTES",
6681DEFAULT_PLUGIN_LIST_MAX_BUFFER_BYTES,
6782),
@@ -141,14 +156,9 @@ async function loadManifestEntries() {
141156142157async function selectedManifestEntries() {
143158const allEntries = await loadManifestEntries();
144-const total = Number.parseInt(process.env.OPENCLAW_BUNDLED_PLUGIN_SWEEP_TOTAL || "1", 10);
145-const index = Number.parseInt(process.env.OPENCLAW_BUNDLED_PLUGIN_SWEEP_INDEX || "0", 10);
146-if (!Number.isInteger(total) || total < 1) {
147-throw new Error(
148-`OPENCLAW_BUNDLED_PLUGIN_SWEEP_TOTAL must be >= 1, got ${process.env.OPENCLAW_BUNDLED_PLUGIN_SWEEP_TOTAL}`,
149-);
150-}
151-if (!Number.isInteger(index) || index < 0 || index >= total) {
159+const total = readPositiveIntEnv("OPENCLAW_BUNDLED_PLUGIN_SWEEP_TOTAL", 1);
160+const index = readNonNegativeIntEnv("OPENCLAW_BUNDLED_PLUGIN_SWEEP_INDEX", 0);
161+if (index >= total) {
152162throw new Error(
153163`OPENCLAW_BUNDLED_PLUGIN_SWEEP_INDEX must be in [0, ${total - 1}], got ${process.env.OPENCLAW_BUNDLED_PLUGIN_SWEEP_INDEX}`,
154164);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。