SIGN IN SIGN UP

fix: scaffold-codemod crashes for missing directories and mishandles unsafe or repeated names (#19231)

## Background

The repository's codemod scaffold command crashed with ENOENT when
nested target directories were absent, duplicated existing bundle
entries, and allowed path-traversing names.

## Root Cause

The script wrote files without creating parent directories, interpolated
an unvalidated name into filesystem paths, and appended bundle entries
without deduplication; the recorded reproduction confirmed all three
outcomes.

## Summary

The scaffold now validates name segments, recursively creates parent
directories, generates correct nested test imports, and keeps bundle
entries unique.

## Testing

Added regression tests covering missing nested directories, generated
imports, duplicate bundle entries, and path-traversal rejection, plus a
patch changeset for @ai-sdk/codemod.

## End-to-end Validation

- `pnpm -C examples/ai-functions exec tsx
src/reproduction/issue-14856-scaffold-codemod-missing-directories.ts`
exited successfully, generated all expected files, preserved one bundle
entry, and rejected the invalid name.

## Related Issues

Fixes #14856

Closes #17061

---------

Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com>
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Co-authored-by: MuzzaiyyanHussain <175098529+MuzzaiyyanHussain@users.noreply.github.com>
A
ai-sdk-factory[bot] committed
e493ed7fbf044d918ffdb4f720cf3fd98e0dc1dd
Parent: 602348d
Committed by GitHub <noreply@github.com> on 8/24/2026, 10:42:01 PM