{"record":{"id":"4a0f3bf576b55526","repo":"JuliusBrussee/caveman","slug":"cave-execution-authorization-private","errorCode":"cave_execution_authorization_private","errorMessage":"cave_execution_authorization_private","messagePattern":"cave_execution_authorization_private","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/claude-runtime.ts","lineNumber":591,"sourceCode":"  // OAuth subscription runs still expose provider token counts, but catalog\n  // list price is not money this run paid. Unknown auth also fails closed to\n  // the honest zero rather than guessing a metered credential.\n  return { ...usage, priced: false, catalogCostUsd: 0 };\n}\n\nfunction integer(value: unknown): number {\n  return Number.isSafeInteger(value) && Number(value) >= 0 ? Number(value) : 0;\n}\n\nfunction unprefixClaudeTool(name: string): string {\n  const prefix = \"mcp__caveman_agent__\";\n  return name.startsWith(prefix) ? name.slice(prefix.length) : name;\n}\n\nfunction rejectInternalOptions(options: ClaudeRunOptions): void {\n  const value = options as Record<string, unknown>;\n  if (\"lockedBuild\" in value || \"candidatePlan\" in value || \"queryFn\" in value) {\n    throw new Error(\"cave_execution_authorization_private\");\n  }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n","sourceCodeStart":573,"sourceCodeEnd":598,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/claude-runtime.ts#L573-L598","documentation":"rejectInternalOptions is a fail-closed guard on the public Claude executor: if a caller passes options named lockedBuild, candidatePlan, or queryFn, it throws because those fields are framework-internal build/plan identity and transport injection. Public calls can never forge locked-build provenance or substitute the SDK query function.","triggerScenarios":"Spreading an internal options object (or a captured object from a framework-internal path) into the public run call; constructing options with those keys to try to reuse a compiled build or mock the provider from outside the package.","commonSituations":"Copying internal test/setup code that sets lockedBuild or queryFn into application code; forwarding rest-spread options from a wrapper that inadvertently picked up internal keys.","solutions":["Remove lockedBuild, candidatePlan, and queryFn from the options you pass; use the public compiler/CLI path (build command) for locked execution.","If you spread user/parent options, explicitly strip internal keys before forwarding.","For provider mocking in tests, use the package's own internal test entry points rather than the public facade."],"exampleFix":"// before\nawait runClaudeAgent({ ...internalOptions, prompt });\n// after\nconst { lockedBuild, candidatePlan, queryFn, ...publicOptions } = internalOptions;\nawait runClaudeAgent({ ...publicOptions, prompt });","handlingStrategy":"type-guard","validationCode":"const INTERNAL_KEYS = [\"lockedBuild\", \"candidatePlan\", \"queryFn\"];\nfunction stripInternalOptions(options) {\n  const out = { ...options };\n  for (const k of INTERNAL_KEYS) delete out[k];\n  return out;\n}","typeGuard":"function isPublicOptions(v) { return v != null && !(\"lockedBuild\" in v) && !(\"candidatePlan\" in v) && !(\"queryFn\" in v); }","tryCatchPattern":"try {\n  await runClaudeAgent(options);\n} catch (e) {\n  if (e.message === \"cave_execution_authorization_private\") {\n    throw new Error(\"Internal framework options must not be passed to the public Claude executor\");\n  }\n  throw e;\n}","preventionTips":["Never spread opaque/internal option objects into public run calls","Define an explicit public options type and construct options field-by-field","Strip reserved keys when forwarding caller-supplied options through wrappers"],"tags":["security","encapsulation","claude","invalid-argument"],"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"}