Files
deepagentsjs/libs/deepagents/src
Kowshik Padala 8efde93792 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).
2026-07-08 13:20:36 -07:00
..
2026-01-09 15:10:42 -08:00
2026-01-09 15:10:42 -08:00