{"record":{"id":"f4087f18146a29aa","repo":"JuliusBrussee/caveman","slug":"cave-internal-run-option","errorCode":"cave_internal_run_option","errorMessage":"cave_internal_run_option: Cave Build execution is available through caveman-agent dev/build after lock validation","messagePattern":"cave_internal_run_option: Cave Build execution is available through caveman-agent dev/build after lock validation","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":5003,"sourceCode":"    }\n  }\n  return false;\n}\n\n/**\n * Refuse caller-supplied build identity, plan, or routing.\n *\n * Exported for the other public entry points that forward caller options into\n * `runAgentInternal` (`./code`): the guard belongs to whoever accepts the\n * untrusted object, and it must run BEFORE any session-internal field is merged\n * in, or the session's own plan and route would trip it.\n */\nexport function rejectInternalRunOptions(options: RunOptions): void {\n  const value = options as Record<string, unknown>;\n  if (\"buildIdentity\" in value || \"efficiencyPlan\" in value ||\n      \"lockedBuild\" in value || \"candidatePlan\" in value || \"caveRoute\" in value ||\n      \"invocationTrace\" in value || \"invocationState\" in value) {\n    throw new Error(\n      \"cave_internal_run_option: Cave Build execution is available through caveman-agent dev/build after lock validation\",\n    );\n  }\n}\n\nfunction sandboxDependencyReadRoots(): string[] {\n  const resolved = [\n    import.meta.resolve(\"@earendil-works/pi-agent-core\"),\n    import.meta.resolve(\"@earendil-works/pi-ai\"),\n  ].map((url) => fileURLToPath(url));\n  const roots = new Set<string>();\n  for (const path of resolved) {\n    const pnpm = path.indexOf(\"/node_modules/.pnpm/\");\n    if (pnpm >= 0) {\n      roots.add(path.slice(0, pnpm + \"/node_modules/.pnpm\".length));\n    } else {\n      roots.add(dirname(dirname(path)));\n    }","sourceCodeStart":4985,"sourceCodeEnd":5021,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L4985-L5021","documentation":"`rejectInternalRunOptions` guards the public `run()` surface: caller-supplied RunOptions may not carry framework-internal fields (`buildIdentity`, `efficiencyPlan`, `lockedBuild`, `candidatePlan`, `caveRoute`, `invocationTrace`, `invocationState`). These belong to the package-internal compiler/CLI path only; Cave Build execution must go through `caveman-agent dev/build` after lock validation. The throw prevents untrusted callers from injecting build identity, plans, or routing into a public run.","triggerScenarios":"Calling `run(options)` (or a public entry point that forwards into it) with any of the seven reserved keys present in the options object — typically by spreading an internal/session object into user options, replaying a serialized options blob that captured internal fields, or forwarding `caveRoute` from a coding session into a fresh public call.","commonSituations":"Piping session-internal options back into a new run, copying options from a compiled/locked build attempt into public `run()`, or an SDK version change where an option was renamed and an old internal key now leaks into the public object.","solutions":["Remove the reserved keys from your options object before calling run() — pass only documented public RunOptions","If you need locked-build execution, use the `caveman-agent dev/build` CLI path with lock validation instead of injecting plan/identity fields","Construct options explicitly (whitelist fields) rather than spreading an unknown object"],"exampleFix":"// before\nawait run({ ...sessionOptions, prompt }); // contains caveRoute/invocationState\n// after\nawait run({ prompt, model: sessionOptions.model }); // only public fields","handlingStrategy":"validation","validationCode":"const RESERVED = ['buildIdentity','efficiencyPlan','lockedBuild','candidatePlan','caveRoute','invocationTrace','invocationState'];\nconst leaked = RESERVED.filter((k) => k in options);\nif (leaked.length) throw new Error(`reserved internal options not allowed: ${leaked.join(',')}`);","typeGuard":"function isPublicRunOptions(o: object): boolean { return !['buildIdentity','efficiencyPlan','lockedBuild','candidatePlan','caveRoute','invocationTrace','invocationState'].some((k) => k in o); }","tryCatchPattern":"try { await run(options); } catch (e) { if (String((e as Error).message).startsWith('cave_internal_run_option:')) { /* strip reserved keys and retry */ } else throw e; }","preventionTips":["Never spread unknown/session-internal objects into run() options","Build options objects with an explicit whitelist of public RunOptions fields","Sanitize any serialized options blob before replaying it"],"tags":["security","api-misuse","options"],"backgroundTag":"invalid-argument-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}