Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions nemoclaw/src/blueprint/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { randomUUID } from "node:crypto";
import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { join, sep } from "node:path";

import { execa } from "execa";
import YAML from "yaml";
Expand Down Expand Up @@ -340,13 +340,28 @@ export async function actionApply(
log(`Inference: ${providerName} -> ${model} @ ${endpoint}`);
}

function validateRunId(rid: string): void {
if (!/^[a-zA-Z0-9_-]+$/.test(rid)) {
throw new Error(`Invalid run ID: '${rid}'`);
}
}

function safeRunDir(runsDir: string, rid: string): string {
validateRunId(rid);
const resolved = join(runsDir, rid);
if (!resolved.startsWith(runsDir + sep)) {
throw new Error("Run ID resolves outside expected directory");
}
return resolved;
}

export function actionStatus(rid?: string): void {
emitRunId();
const runsDir = join(homedir(), ".nemoclaw", "state", "runs");

let runDir: string;
if (rid) {
runDir = join(runsDir, rid);
runDir = safeRunDir(runsDir, rid);
} else {
let runs: string[];
try {
Expand All @@ -373,7 +388,8 @@ export function actionStatus(rid?: string): void {
export async function actionRollback(rid: string): Promise<void> {
emitRunId();

const stateDir = join(homedir(), ".nemoclaw", "state", "runs", rid);
const runsDir = join(homedir(), ".nemoclaw", "state", "runs");
const stateDir = safeRunDir(runsDir, rid);
try {
readdirSync(stateDir);
} catch {
Expand Down