SIGN IN SIGN UP

feat(deepagents): implement filesystem state management middleware with atomic update support and testing (#659)

## Problem
Addresses #658.

When using weaker or custom LLMs (e.g., smaller open-source models) in
`deepagents` and consumers like `openwiki`, the agent immediately
crashes with a schema validation error on the first filesystem tool
call:


This occurs because:
1. `ls` defines its directory argument as `path`, but `read_file`,
`write_file`, and `edit_file` expect `file_path`. Models often default
to `path` across all filesystem tools.
2. The description prompt examples in `fs.ts` and `skills.ts` show
`read_file(path, ...)`, instructing models to use the wrong parameter
name.

## Proposed Changes
This PR solves both prompt inconsistencies and schema validation
failures with a fully backward-compatible input normalization helper:

1. **Prompt Alignment**: Fixed references in `fs.ts` and `skills.ts` to
instruct the model to use `file_path` (aligned with the prompt fixes in
#644).
2. **Schema Input Normalization**: Added a `normalizeFilePathInput`
preprocessor helper to the `read_file`, `write_file`, and `edit_file`
Zod schemas using `z.preprocess`. This dynamically maps the `path` key
to `file_path` if the model still passes `path`.

## Verification & Tests
- Added unit tests in `fs.test.ts` to assert that:
- `path` parameter normalization maps correctly to `file_path` for
`read_file`, `write_file`, and `edit_file`.
  - All instruction examples contain only valid schema fields.
- Verified that `zod-to-json-schema` unwraps the `z.preprocess` layer
perfectly, preserving the original schema descriptions and definitions
sent to the LLM.
- Ran all filesystem tests successfully (`npx vitest run
src/middleware/fs.test.ts` passes).
K
Kowshik Padala committed
8efde93792dfc324e70b441eacbb810532f347c4
Parent: ff8cc5c
Committed by GitHub <noreply@github.com> on 7/8/2026, 8:20:36 PM