{"record":{"id":"806dedc97c957634","repo":"Hmbown/CodeWhale","slug":"refusing-to-mutate-non-owned-root","errorCode":null,"errorMessage":"refusing to mutate non-owned root {}","messagePattern":"refusing to mutate non-owned root (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/skills/mutation.rs","lineNumber":264,"sourceCode":"    if !checked_real_directory(anchor)? {\n        bail!(\"owned skill anchor {} does not exist\", anchor.display());\n    }\n\n    let codewhale_dir = anchor.join(\".codewhale\");\n    if !checked_real_directory(&codewhale_dir)? {\n        create_owned_directory(&codewhale_dir)?;\n    }\n    validate_owned_target_chain(anchor, &skills_dir, false)?;\n    if !checked_real_directory(&skills_dir)? {\n        create_owned_directory(&skills_dir)?;\n    }\n    validate_owned_target_chain(anchor, &skills_dir, true)?;\n    Ok(skills_dir)\n}\n\nfn target_scope_for_root(root: &SkillRootDescriptor) -> Result<SkillTargetScope> {\n    if !root.is_writable_owned() {\n        bail!(\"refusing to mutate non-owned root {}\", root.path.display());\n    }\n    match root.kind {\n        SkillRootKind::CodeWhaleProject => Ok(SkillTargetScope::Project),\n        SkillRootKind::CodeWhaleGlobal => Ok(SkillTargetScope::Global),\n        _ => bail!(\"refusing to mutate non-owned root {}\", root.path.display()),\n    }\n}\n\nfn validate_owned_root_descriptor(\n    ctx: &MutationContext<'_>,\n    root: &SkillRootDescriptor,\n) -> Result<PathBuf> {\n    let target = target_scope_for_root(root)?;\n    let expected = resolve_owned_target(ctx.workspace, ctx.home, target)?;\n    if root.path != expected {\n        bail!(\n            \"audited owned root {} does not match mutation target {}\",\n            root.path.display(),","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/skills/mutation.rs#L246-L282","documentation":"`target_scope_for_root` refuses to mutate any skill root that is not a writable, Codewhale-owned root: the descriptor must pass `is_writable_owned()` AND its kind must be `CodeWhaleProject` or `CodeWhaleGlobal`. This protects third-party/user-managed roots (e.g. a project's checked-in `.claude/skills` or any external directory) from being written by Codewhale's skill mutation operations.","triggerScenarios":"Calling `validate_owned_root_descriptor` with a `SkillRootDescriptor` whose kind is a foreign root (not `CodeWhaleProject`/`CodeWhaleGlobal`) or that is not marked writable-owned; passing a user- or project-managed root discovered by a scan into an install/import operation that expects an owned root; constructing a descriptor manually with the wrong `kind` or writability flag.","commonSituations":"Pointing a skill install at a shared team skills directory checked into the repo instead of `.codewhale/skills`; a root descriptor loaded from config that was created before Codewhale-owned roots existed and carries a legacy kind; tests or scripts building `SkillRootDescriptor` values by hand with mismatched kind/writability.","solutions":["Target the Codewhale-owned root instead: use `SkillTargetScope::Project` (workspace `.codewhale/skills`) or `SkillTargetScope::Global` (home `.codewhale/skills`) with `prepare_owned_target`/`install_remote`","If the descriptor comes from config, update its `kind` to `CodeWhaleProject`/`CodeWhaleGlobal` only if the path really is the owned root; otherwise leave it read-only and copy skills in manually","Verify with `root.is_writable_owned()` before calling mutation APIs; route non-owned roots to read-only listing paths","If you intended to mutate a foreign root, that is intentionally unsupported — sync the files yourself or add an explicit integration, not a bypass of this guard"],"exampleFix":"// before: mutating a foreign (user-managed) root descriptor\nlet scope = target_scope_for_root(&user_root)?; // bails: non-owned root\n// after: install into the owned project root instead\nlet skills_dir = prepare_owned_target(workspace, None, SkillTargetScope::Project)?;","handlingStrategy":"type-guard","validationCode":"if !root.is_writable_owned() {\n    return Err(format!(\"{} is not a Codewhale-owned root; pick .codewhale/skills instead\", root.path.display()));\n}\nif !matches!(root.kind, SkillRootKind::CodeWhaleProject | SkillRootKind::CodeWhaleGlobal) {\n    return Err(format!(\"{} has foreign kind {:?}; mutation refused\", root.path.display(), root.kind));\n}","typeGuard":"fn is_mutable_owned_root(root: &SkillRootDescriptor) -> bool {\n    root.is_writable_owned()\n        && matches!(root.kind, SkillRootKind::CodeWhaleProject | SkillRootKind::CodeWhaleGlobal)\n}","tryCatchPattern":"match install_remote(workspace, home, scope) {\n    Err(e) if e.to_string().contains(\"refusing to mutate non-owned root\") => {\n        eprintln!(\"{} — target the owned .codewhale/skills root instead\", e);\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Check root.is_writable_owned() and the kind before invoking mutation APIs","Treat user- and project-managed roots as read-only; copy content into the owned root if needed","Do not hand-construct SkillRootDescriptor kinds for paths that are not the owned chain","Update stale config entries that still carry legacy root kinds"],"tags":["permissions","ownership","unsupported-operation","skills"],"backgroundTag":"permission-denied","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}