fix(qa): reject loose code-mode live task limits

This commit is contained in:
Vincent Koc 2026-06-16 21:11:16 +02:00
parent 319e41d0c5
commit fd166a5318
No known key found for this signature in database
4 changed files with 60 additions and 12 deletions

View file

@ -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);
});
}