#1 Persistent memory for AI coding agents based on real-world benchmarks
TypeScript agentmemoryagentsaiclaudeclaudecodecodexcopilotcursorgenaiharnesshermesmemoryompopenclawopencodepi
fix(replay,cli): cap walker traversal, validate maxFiles, harden flag parsing
Rohit Ghumarea334ea06115a
diff --git a/src/cli.ts b/src/cli.tsindex 2b51ec8f..6c8de462 100644--- a/src/cli.ts+++ b/src/cli.ts@@ -36,7 +36,7 @@ Commands:upgrade Upgrade local deps + iii runtime (best effort)mcp Start standalone MCP server (no engine required)import-jsonl [p] Import Claude Code JSONL transcripts (default: ~/.claude/projects)- Use --max-files <N> to override the 200-file scan cap (default: 200)+ Use --max-files <N> or --max-files=<N> to override the 200-file scan cap (default: 200)Options:--help, -h Show this help@@ -961,21 +961,36 @@ async function runMcp(): Promise<void> {}async function runImportJsonl(): Promise<void> {- const nonFlagArgs = args.slice(1).filter((a) => !a.startsWith("-"));- const pathArg = nonFlagArgs[0];-let maxFiles: number | undefined;- const flagIdx = args.findIndex((a) => a === "--max-files");- if (flagIdx !== -1 && args[flagIdx + 1]) {- const parsed = parseInt(args[flagIdx + 1]!, 10);- if (!Number.isNaN(parsed) && parsed > 0) maxFiles = parsed;- } else {- const eqArg = args.find((a) => a.startsWith("--max-files="));- if (eqArg) {- const parsed = parseInt(eqArg.slice("--max-files=".length), 10);- if (!Number.isNaN(parsed) && parsed > 0) maxFiles = parsed;+ const tail = args.slice(1);+ const positional: string[] = [];+ for (let i = 0; i < tail.length; i++) {+ const a = tail[i]!;+ if (a === "--max-files") {+ const raw = tail[i + 1];+ const parsed = raw !== undefined ? parseInt(raw, 10) : NaN;+ if (Number.isInteger(parsed) && parsed > 0) {+ maxFiles = parsed;+ } else if (raw !== undefined) {+ p.log.warn(`Ignoring --max-files ${raw}: expected a positive integer.`);+ }+ i++;+ continue;+ }+ if (a.startsWith("--max-files=")) {+ const raw = a.slice("--max-files=".length);+ const parsed = parseInt(raw, 10);+ if (Number.isInteger(parsed) && parsed > 0) {+ maxFiles = parsed;+ } else {+ p.log.warn(`Ignoring --max-files=${raw}: expected a positive integer.`);+ }+ continue;}+ if (a.startsWith("-")) continue;+ positional.push(a);}+ const pathArg = positional[0];const port = getRestPort();const base = `http://localhost:${port}`;diff --git a/src/functions/replay.ts b/src/functions/replay.tsindex 11c38e16..e89a5411 100644--- a/src/functions/replay.ts+++ b/src/functions/replay.ts@@ -206,7 +206,13 @@ async function findJsonlFiles(): Promise<{ files: string[]; truncated: boolean; discovered: number }> {const out: string[] = [];let discovered = 0;+ // Cap how far we walk past the user's requested limit. We keep counting+ // beyond `limit` so we can report `truncated`/`discovered` accurately,+ // but we stop the walk well before million-file trees can lock the+ // 30s function timeout.+ const traversalCap = Math.max(limit * 10, 10_000);async function walk(dir: string) {+ if (discovered >= traversalCap) return;let names: string[];try {names = await readdir(dir);@@ -214,6 +220,7 @@ async function findJsonlFiles(return;}for (const name of names) {+ if (discovered >= traversalCap) return;const full = join(dir, name);let st;try {@@ -299,7 +306,14 @@ export function registerReplayFunctions(sdk: ISdk, kv: StateKV): void {return { success: false, error: "path not found" };}- const maxFiles = data.maxFiles && data.maxFiles > 0 ? data.maxFiles : 200;+ const MAX_FILES_DEFAULT = 200;+ const MAX_FILES_UPPER_BOUND = 1000;+ const maxFiles =+ Number.isInteger(data.maxFiles) &&+ (data.maxFiles as number) > 0 &&+ (data.maxFiles as number) <= MAX_FILES_UPPER_BOUND+ ? (data.maxFiles as number)+ : MAX_FILES_DEFAULT;let files: string[] = [];let truncated = false;let discovered = 0;