mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 00:11:19 +00:00
fix(qa): reject loose code-mode live task limits
This commit is contained in:
parent
319e41d0c5
commit
fd166a5318
4 changed files with 60 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env -S node --import tsx
|
||||
// Code Mode Namespace Live script supports OpenClaw repository automation.
|
||||
import { performance } from "node:perf_hooks";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { Type } from "typebox";
|
||||
import type { Model } from "../../packages/agent-core/src/llm.js";
|
||||
import type { AgentEvent, AgentTool } from "../../packages/agent-core/src/types.js";
|
||||
|
|
@ -80,6 +81,7 @@ type RunMetrics = {
|
|||
};
|
||||
|
||||
const PLUGIN_ID = "fictions-live";
|
||||
const POSITIVE_INTEGER_PATTERN = /^[1-9]\d*$/u;
|
||||
|
||||
function cloneState(): FictionServiceState {
|
||||
return {
|
||||
|
|
@ -598,19 +600,32 @@ function readArg(name: string): string | undefined {
|
|||
return match?.slice(prefix.length);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
export function parseTaskLimit(raw: string | undefined, label: string): number {
|
||||
const text = raw?.trim() ?? "3";
|
||||
if (!POSITIVE_INTEGER_PATTERN.test(text)) {
|
||||
throw new Error(`${label} must be a positive integer`);
|
||||
}
|
||||
const parsed = Number(text);
|
||||
if (!Number.isSafeInteger(parsed)) {
|
||||
throw new Error(`${label} must be a safe positive integer`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export async function main() {
|
||||
const model = readArg("model") ?? process.env.OPENCLAW_CODE_MODE_LIVE_MODEL ?? "gpt-5.4-mini";
|
||||
const modeArg = readArg("modes");
|
||||
const modes = (modeArg ? modeArg.split(",") : ["regular", "code-namespace"]) as Mode[];
|
||||
const taskArg = readArg("tasks");
|
||||
const taskLimit = parseTaskLimit(
|
||||
taskArg ?? process.env.OPENCLAW_CODE_MODE_LIVE_TASKS,
|
||||
taskArg === undefined ? "OPENCLAW_CODE_MODE_LIVE_TASKS" : "--tasks",
|
||||
);
|
||||
const apiKey = process.env.OPENAI_API_KEY?.trim();
|
||||
if (!apiKey) {
|
||||
throw new Error("OPENAI_API_KEY is required");
|
||||
}
|
||||
const model = readArg("model") ?? process.env.OPENCLAW_CODE_MODE_LIVE_MODEL ?? "gpt-5.4-mini";
|
||||
const modeArg = readArg("modes");
|
||||
const modes = (modeArg ? modeArg.split(",") : ["regular", "code-namespace"]) as Mode[];
|
||||
const taskLimit = Number(readArg("tasks") ?? process.env.OPENCLAW_CODE_MODE_LIVE_TASKS ?? "3");
|
||||
const selectedTasks = tasks.slice(
|
||||
0,
|
||||
Number.isFinite(taskLimit) && taskLimit > 0 ? taskLimit : tasks.length,
|
||||
);
|
||||
const selectedTasks = tasks.slice(0, taskLimit);
|
||||
const results: RunMetrics[] = [];
|
||||
for (const task of selectedTasks) {
|
||||
for (const mode of modes) {
|
||||
|
|
@ -640,6 +655,8 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
await main().finally(() => {
|
||||
clearCodeModeNamespacesForPlugin(PLUGIN_ID);
|
||||
});
|
||||
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
||||
await main().finally(() => {
|
||||
clearCodeModeNamespacesForPlugin(PLUGIN_ID);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue