agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

fix(fs-watcher): load agentmemory env file

Open EvanWangZ opened this issue 6 months ago β€’ 2 comments

Summary

  • load ~/.agentmemory/.env and $XDG_CONFIG_HOME/agentmemory/.env in @agentmemory/fs-watcher
  • keep explicit process environment values higher priority than file values
  • document the fallback and add tests for file loading and env override behavior

This addresses the filesystem watcher part of #298, where a watcher running under a process manager/container could fall back to localhost even though the shared server URL lives in agentmemory's documented env file.

Conflict check

  • Current open PRs do not touch integrations/filesystem-watcher/* or test/fs-watcher.test.ts.

Tests

  • npm test -- test/fs-watcher.test.ts
  • node --check integrations/filesystem-watcher/watcher.mjs
  • git diff --check
  • npm run build
  • npm test

Summary by CodeRabbit

  • Documentation

    • Clarified how configuration is loaded from .env files for the filesystem watcher.
  • New Features

    • Filesystem watcher can load configuration from .env files in user config locations, with explicit process environment variables taking precedence.
  • Tests

    • Added tests covering .env parsing, quoting/comments handling, XDG_HOME support, and environment-variable precedence.

Review Change Stack

EvanWangZ avatar May 13 '26 03:05 EvanWangZ

@Zavianx is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 13 '26 03:05 vercel[bot]

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 41950be1-89d3-4423-bee4-bca786a9e2b7

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b8ca80a93010a3e760f57fc438a0956cc3d2d8d3 and 1a1f409968f88cd9306f15a6358f9b702769a346.

πŸ“’ Files selected for processing (2)
  • integrations/filesystem-watcher/README.md
  • test/fs-watcher.test.ts
βœ… Files skipped from review due to trivial changes (1)
  • integrations/filesystem-watcher/README.md

πŸ“ Walkthrough

Walkthrough

Adds support for loading watcher configuration from ~/.agentmemory/.env and $XDG_CONFIG_HOME/agentmemory/.env; implements parsing/loading helpers, merges file-sourced values with process env in configFromEnv (process env wins), expands tests, and updates README.

Changes

Environment file configuration loading

Layer / File(s) Summary
Env-file parsing and loading helpers
integrations/filesystem-watcher/watcher.mjs
parseEnvFile parses key/value pairs (comments, blank lines, basic quoting), loadAgentMemoryEnv best-effort loads .env from ~/.agentmemory/.env and $XDG_CONFIG_HOME/agentmemory/.env. fs import reformatted.
ConfigFromEnv env merging
integrations/filesystem-watcher/watcher.mjs
configFromEnv merges file-loaded env values with the provided env (file first, explicit env overrides) and derives roots, baseUrl, secret, project, sessionId, ignorePatterns, and allowBinary.
Test coverage for env file loading
test/fs-watcher.test.ts
Adds Vitest cases to verify loading from ~/.agentmemory/.env, parsing edge cases (quoting, inline comments, open quotes, empty/malformed lines), XDG_CONFIG_HOME precedence, and explicit AGENTMEMORY_* overrides. Temporary HOME/XDG dirs are used and cleaned up.
Documentation of env file loading
integrations/filesystem-watcher/README.md
README documents the .env loading order and that process environment variables override file values.

Possibly related PRs

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 In burrows of code I softly comb,
I read .env from home and XDG home,
I stitch their keys with process light,
so watcher wakes configured right,
and hops along the filesystem loam.

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (4 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title 'fix(fs-watcher): load agentmemory env file' accurately summarizes the main change: enabling the filesystem watcher to load environment configuration from agentmemory env files, which directly addresses the PR's primary objective.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 13 '26 03:05 coderabbitai[bot]