Skip to content

feat(tools): let export_memories write to a file path - #54

Merged
7vignesh merged 2 commits into
mainfrom
feat/export-to-file
Oct 13, 2026
Merged

7vignesh merged 2 commits into
mainfrom
feat/export-to-file

Conversation

@7vignesh

Copy link
Copy Markdown
Owner

Closes #35.

Problem

export_memories returned the entire envelope as one JSON blob in the tool response. For a repo with many memories that is an unwieldy payload to round-trip through the client, and it competes with the model's context budget.

Fix

Add an optional path argument:

  • With path: the envelope is written to that file and the response is a short summary (memory/alias counts + the resolved path) instead of the full JSON.
  • Without path: unchanged - the full JSON is returned inline. Backward compatible.

Safe path handling: the path is resolved against the workspace root (FOSSEL_WORKSPACE), and rejected if it escapes - a relative ../... or an absolute path pointing outside the workspace both fail with a clear error. This stops a tool call from writing anywhere on disk.

Example:

export_memories({ path: "fossel-backup.json" })
-> "Exported 42 memory(s) and 3 alias(es) to /workspace/fossel-backup.json."

Tests

tests/export-tool.test.ts (drives the real handler via initDb + a captured handler): inline mode, file mode (asserts the file content and the summary), a nested in-workspace path, and both traversal-guard rejections (relative ../ and absolute-outside).

Verification

npm run typecheck clean; full suite 257/257 pass; npm run smoke passes; npm run build succeeds.

Note

Does not create missing parent directories - the target directory must exist (standard writeFileSync behavior). Can add mkdir -p semantics later if wanted; left out to keep the change minimal.

export_memories returned the whole envelope as one JSON blob in the tool
response, which is an unwieldy payload for a large repo and competes with
the model's context budget. Add an optional `path` argument: when set, the
envelope is written to that file and the response is a short summary
(counts + path) instead of the full JSON. Omitting `path` keeps the
current inline behavior, so this is backward compatible.

Path handling is safe: the path is resolved against the workspace root and
rejected if it escapes (relative ../ or an absolute path pointing
elsewhere), preventing a tool call from writing outside the project.

Covered by tests: inline mode, file mode, a nested in-workspace path, and
both traversal-guard rejections.
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
fossel Ready Ready Preview Oct 13, 2026 11:09am UTC

@7vignesh
7vignesh merged commit a1f4899 into main Oct 13, 2026
6 checks passed

This branch was successfully deployed

1 active deployment
Preview — 3cb8ca56 Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support writing export_memories output to a file path

1 participant