Find a file
KJ7LNW 1be30fc8c2
fix: use safeWriteJson for all JSON file writes (#3772)
* feat: Add safeWriteJson utility for atomic file operations

Implements a robust JSON file writing utility that:
- Prevents concurrent writes to the same file using in-memory locks
- Ensures atomic operations with temporary file and backup strategies
- Handles error cases with proper rollback mechanisms
- Cleans up temporary files even when operations fail
- Provides comprehensive test coverage for success and failure scenarios

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* fix: use safeWriteJson for all JSON file writes

This change refactors all direct JSON file writes to use the safeWriteJson
utility, which implements atomic file writes to prevent data corruption
during write operations.

- Modified safeWriteJson to accept optional replacer and space arguments
- Updated tests to verify correct behavior with the new implementation

Fixes: #722
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* feat: Implement inter-process file locking for safeWriteJson

Replaces the previous in-memory lock in `safeWriteJson` with
`proper-lockfile` to provide robust, cross-process advisory file
locking. This enhances safety when multiple processes might attempt
concurrent writes to the same JSON file.

Key changes:
- Added `proper-lockfile` and `@types/proper-lockfile` dependencies.
- `safeWriteJson` now uses `proper-lockfile.lock()` with configured
  retries, staleness checks (31s), and lock update intervals (10s).
- An `onCompromised` handler is included to manage scenarios where
  the lock state is unexpectedly altered.
- Logging and comments within `safeWriteJson` have been refined for
  clarity, ensuring error logs include backtraces.
- The test suite `safeWriteJson.test.ts` has been significantly
  updated to:
    - Use real timers (`jest.useRealTimers()`).
    - Employ a more comprehensive mock for `fs/promises`.
    - Correctly manage file pre-existence for various scenarios.
    - Simulate lock contention by mocking `proper-lockfile.lock()`
      using `jest.doMock` and a dynamic require for the SUT.
    - Verify lock release by checking for the absence of the `.lock`
      file.

All tests are passing with these changes.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* feat: implement streaming JSON write in safeWriteJson

Refactor safeWriteJson to use stream-json for memory-efficient JSON serialization:
- Replace in-memory string creation with streaming pipeline
- Add Disassembler and Stringer from stream-json library
- Extract streaming logic to a dedicated helper function
- Add proper-lockfile and stream-json dependencies

This implementation reduces memory usage when writing large JSON objects.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* fix: improve safeWriteJson locking mechanism

- Use file path itself for locking instead of separate lock file
- Improve error handling and clarity of code
- Enhance cleanup of temporary files

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* test: fix safeWriteJson test failures

- Ensure test file exists before locking
- Add proper mocking for fs.createWriteStream
- Fix test assertions to match expected behavior
- Improve test comments to follow project guidelines

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* test: update tests to work with safeWriteJson

Updated tests to work with safeWriteJson instead of direct fs.writeFile calls:

- Updated importExport.test.ts to expect safeWriteJson calls instead of fs.writeFile
- Fixed McpHub.test.ts by properly mocking fs/promises module:
  - Moved jest.mock() to the top of the file before any imports
  - Added mock implementations for all fs functions used by safeWriteJson
  - Updated the test setup to work with the mocked fs module

All tests now pass successfully.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* refactor: replace JSON.stringify with safeWriteJson for file operations

Replace all non-test instances of JSON.stringify used for writing to JSON files with safeWriteJson to ensure safer file operations with proper locking, error handling, and atomic writes.

- Updated src/services/mcp/McpHub.ts
- Updated src/services/code-index/cache-manager.ts
- Updated src/api/providers/fetchers/modelEndpointCache.ts
- Updated src/api/providers/fetchers/modelCache.ts
- Updated tests to match the new implementation

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* docs: add rules for using safeWriteJson

Add concise rules for using safeWriteJson instead of JSON.stringify with file operations to ensure atomic writes and prevent data corruption.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

---------

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com>
2025-06-08 07:17:20 -07:00
.changeset Bug fix for trailing slash error when using LiteLLM provider (#4275) 2025-06-07 17:21:11 -07:00
.github Update CODEOWNERS (#4387) 2025-06-05 15:10:24 -04:00
.husky Improve POSIX shell compatibility in pre-push hook (#4053) 2025-05-28 14:46:40 -07:00
.roo fix: use safeWriteJson for all JSON file writes (#3772) 2025-06-08 07:17:20 -07:00
.vscode Bring back #4128 (#4292) 2025-06-03 14:03:19 -07:00
apps Harden evals with retry logic + centralize logs on Docker host (#4440) 2025-06-07 08:58:09 -07:00
locales Update contributors list (#4224) 2025-06-04 17:01:10 -04:00
packages feat: add experimental flag to disable command execution in attempt_c… (#4352) 2025-06-08 07:14:57 -07:00
scripts Fix: Correct spawnSync parameters for pnpm check in bootstrap.mjs (cl… (#3952) 2025-05-24 21:19:52 -07:00
src fix: use safeWriteJson for all JSON file writes (#3772) 2025-06-08 07:17:20 -07:00
webview-ui feat: add experimental flag to disable command execution in attempt_c… (#4352) 2025-06-08 07:14:57 -07:00
.dockerignore Improve Docker setup for evals (#4327) 2025-06-05 12:16:36 -07:00
.env.sample Roo Code Cloud (#4069) 2025-05-28 20:43:30 -07:00
.git-blame-ignore-revs Moved repo to new org (#3756) 2025-05-20 16:42:18 -04:00
.gitattributes PNPM + Turbo monorepo + Nightly releases (#3407) 2025-05-21 21:01:20 -07:00
.gitconfig Set up ignoring revisions for git blame 2025-01-17 11:21:25 -08:00
.gitignore Remove mcp.json configuration and add it to .gitignore (#4422) 2025-06-06 12:33:35 -04:00
.nvmrc Upgrade Node.js to v20.19.2 for security enhancements (#4212) 2025-06-01 17:02:44 -04:00
.prettierrc.json Fix Posthog by correctly copying .env in the build process (#4049) 2025-05-27 11:19:21 -07:00
.rooignore Add telemetry and privacy policy 2025-03-07 03:03:44 -05:00
.roomodes Convert .roomodes to YAML (#3792) 2025-05-21 15:14:10 -04:00
.tool-versions chore(deps): update node.js to v20.19.2 (#4159) 2025-05-30 22:48:46 -04:00
CHANGELOG.md Changeset version bump (#4403) 2025-06-05 23:36:29 -07:00
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT and CONTRIBUTING documents across multiple lan… (#3254) 2025-05-07 00:45:24 -04:00
CONTRIBUTING.md PNPM + Turbo monorepo + Nightly releases (#3407) 2025-05-21 21:01:20 -07:00
ellipsis.yaml Revert "Turn off ellipsis quiet mode" 2025-03-07 02:26:25 -05:00
knip.json Move evals into pnpm workspace, switch from SQLite to Postgres (#4278) 2025-06-03 01:38:08 -07:00
LICENSE Update LICENSE (#2275) 2025-04-03 23:54:26 -04:00
MONOREPO.md Improve turbo task dependency declarations (#4323) 2025-06-04 09:32:27 -07:00
package.json Fix git clone in evals setup script (#4418) 2025-06-06 08:47:43 -07:00
pnpm-lock.yaml fix: use safeWriteJson for all JSON file writes (#3772) 2025-06-08 07:17:20 -07:00
pnpm-workspace.yaml Move e2e into apps (#3823) 2025-05-22 08:41:58 -07:00
PRIVACY.md Add telemetry and privacy policy 2025-03-07 03:03:44 -05:00
README.md Update contributors list (#4224) 2025-06-04 17:01:10 -04:00
renovate.json Ignore @vscode/vsce in renovate (#4170) 2025-05-31 00:22:14 -04:00
SECURITY.md Create SECURITY.md 2025-06-05 10:22:15 -04:00
turbo.json Improve turbo task dependency declarations (#4323) 2025-06-04 09:32:27 -07:00


Roo Code (prev. Roo Cline)

Connect with developers, contribute ideas, and stay ahead with the latest AI-powered coding tools.

Join Discord Join Reddit



Download on VS Marketplace Feature Requests Rate & Review Documentation

Roo Code is an AI-powered autonomous coding agent that lives in your editor. It can:

  • Communicate in natural language
  • Read and write files directly in your workspace
  • Run terminal commands
  • Automate browser actions
  • Integrate with any OpenAI-compatible or custom API/model
  • Adapt its “personality” and capabilities through Custom Modes

Whether youre seeking a flexible coding partner, a system architect, or specialized roles like a QA engineer or product manager, Roo Code can help you build software more efficiently.

Check out the CHANGELOG for detailed updates and fixes.


🎉 Roo Code 3.19 Released

Roo Code 3.19 brings intelligent context management improvements and enhanced user experience!

  • Intelligent Context Condensing Enabled by Default - Context condensing is now enabled by default with configurable settings for when automatic condensing happens.
  • Manual Condensing Button - New button in the task header allows you to manually trigger context condensing at any time.
  • Enhanced Condensing Settings - Fine-tune when and how automatic condensing occurs through the Context Settings panel.

What Can Roo Code Do?

  • 🚀 Generate Code from natural language descriptions
  • 🔧 Refactor & Debug existing code
  • 📝 Write & Update documentation
  • 🤔 Answer Questions about your codebase
  • 🔄 Automate repetitive tasks
  • 🏗️ Create new files and projects

Quick Start

  1. Install Roo Code
  2. Connect Your AI Provider
  3. Try Your First Task

Key Features

Multiple Modes

Roo Code adapts to your needs with specialized modes:

  • Code Mode: For general-purpose coding tasks
  • Architect Mode: For planning and technical leadership
  • Ask Mode: For answering questions and providing information
  • Debug Mode: For systematic problem diagnosis
  • Custom Modes: Create unlimited specialized personas for security auditing, performance optimization, documentation, or any other task

Smart Tools

Roo Code comes with powerful tools that can:

  • Read and write files in your project
  • Execute commands in your VS Code terminal
  • Control a web browser
  • Use external tools via MCP (Model Context Protocol)

MCP extends Roo Code's capabilities by allowing you to add unlimited custom tools. Integrate with external APIs, connect to databases, or create specialized development tools - MCP provides the framework to expand Roo Code's functionality to meet your specific needs.

Customization

Make Roo Code work your way with:

Resources

Documentation

Community


Local Setup & Development

  1. Clone the repo:
git clone https://github.com/RooCodeInc/Roo-Code.git
  1. Install dependencies:
pnpm install
  1. Run the extension:

Press F5 (or RunStart Debugging) in VSCode to open a new window with Roo Code running.

Changes to the webview will appear immediately. Changes to the core extension will require a restart of the extension host.

Alternatively you can build a .vsix and install it directly in VSCode:

pnpm vsix

A .vsix file will appear in the bin/ directory which can be installed with:

code --install-extension bin/roo-cline-<version>.vsix

We use changesets for versioning and publishing. Check our CHANGELOG.md for release notes.


Disclaimer

Please note that Roo Code, Inc does not make any representations or warranties regarding any code, models, or other tools provided or made available in connection with Roo Code, any associated third-party tools, or any resulting outputs. You assume all risks associated with the use of any such tools or outputs; such tools are provided on an "AS IS" and "AS AVAILABLE" basis. Such risks may include, without limitation, intellectual property infringement, cyber vulnerabilities or attacks, bias, inaccuracies, errors, defects, viruses, downtime, property loss or damage, and/or personal injury. You are solely responsible for your use of any such tools or outputs (including, without limitation, the legality, appropriateness, and results thereof).


Contributing

We love community contributions! Get started by reading our CONTRIBUTING.md.


Contributors

Thanks to all our contributors who have helped make Roo Code better!

mrubens
mrubens
saoudrizwan
saoudrizwan
cte
cte
samhvw8
samhvw8
daniel-lxs
daniel-lxs
a8trejo
a8trejo
KJ7LNW
KJ7LNW
ColemanRoo
ColemanRoo
canrobins13
canrobins13
hannesrudolph
hannesrudolph
stea9499
stea9499
joemanley201
joemanley201
System233
System233
nissa-seru
nissa-seru
jquanton
jquanton
NyxJae
NyxJae
MuriloFP
MuriloFP
d-oit
d-oit
punkpeye
punkpeye
jr
jr
wkordalski
wkordalski
elianiva
elianiva
monotykamary
monotykamary
cannuri
cannuri
Smartsheet-JB-Brown
Smartsheet-JB-Brown
zhangtony239
zhangtony239
sachasayan
sachasayan
xyOz-dev
xyOz-dev
feifei325
feifei325
qdaxb
qdaxb
vigneshsubbiah16
vigneshsubbiah16
shariqriazz
shariqriazz
lloydchang
lloydchang
pugazhendhi-m
pugazhendhi-m
Szpadel
Szpadel
dtrugman
dtrugman
diarmidmackenzie
diarmidmackenzie
psv2522
psv2522
Premshay
Premshay
lupuletic
lupuletic
aheizi
aheizi
PeterDaveHello
PeterDaveHello
olweraltuve
olweraltuve
ChuKhaLi
ChuKhaLi
nbihan-mediware
nbihan-mediware
RaySinner
RaySinner
kiwina
kiwina
afshawnlotfi
afshawnlotfi
pdecat
pdecat
noritaka1166
noritaka1166
kyle-apex
kyle-apex
emshvac
emshvac
chrarnoldus
chrarnoldus
Lunchb0ne
Lunchb0ne
SmartManoj
SmartManoj
vagadiya
vagadiya
slytechnical
slytechnical
arthurauffray
arthurauffray
upamune
upamune
StevenTCramer
StevenTCramer
sammcj
sammcj
p12tic
p12tic
gtaylor
gtaylor
aitoroses
aitoroses
mr-ryan-james
mr-ryan-james
heyseth
heyseth
taisukeoe
taisukeoe
taylorwilsdon
taylorwilsdon
NamesMT
NamesMT
avtc
avtc
dlab-anton
dlab-anton
eonghk
eonghk
ronyblum
ronyblum
teddyOOXX
teddyOOXX
vincentsong
vincentsong
yongjer
yongjer
zeozeozeo
zeozeozeo
ashktn
ashktn
franekp
franekp
yt3trees
yt3trees
anton-otee
anton-otee
benzntech
benzntech
axkirillov
axkirillov
bramburn
bramburn
hassoncs
hassoncs
snoyiatk
snoyiatk
GitlyHallows
GitlyHallows
jcbdev
jcbdev
Chenjiayuan195
Chenjiayuan195
julionav
julionav
SplittyDev
SplittyDev
mdp
mdp
napter
napter
Ruakij
Ruakij
ross
ross
philfung
philfung
GOODBOY008
GOODBOY008
hatsu38
hatsu38
hongzio
hongzio
im47cn
im47cn
shoopapa
shoopapa
jwcraig
jwcraig
kcwhite
kcwhite
kinandan
kinandan
kohii
kohii
nevermorec
nevermorec
dqroid
dqroid
dairui1
dairui1
bannzai
bannzai
axmo
axmo
asychin
asychin
amittell
amittell
Yoshino-Yukitaro
Yoshino-Yukitaro
Yikai-Liao
Yikai-Liao
zxdvd
zxdvd
vladstudio
vladstudio
tmsjngx0
tmsjngx0
PretzelVector
PretzelVector
zetaloop
zetaloop
cdlliuy
cdlliuy
student20880
student20880
shohei-ihaya
shohei-ihaya
shaybc
shaybc
seedlord
seedlord
samir-nimbly
samir-nimbly
robertheadley
robertheadley
refactorthis
refactorthis
qingyuan1109
qingyuan1109
pokutuna
pokutuna
philipnext
philipnext
oprstchn
oprstchn
nobu007
nobu007
mosleyit
mosleyit
moqimoqidea
moqimoqidea
mlopezr
mlopezr
mecab
mecab
olup
olup
lightrabbit
lightrabbit
celestial-vault
celestial-vault
linegel
linegel
dbasclpy
dbasclpy
Deon588
Deon588
dleen
dleen
devxpain
devxpain
chadgauth
chadgauth
olearycrew
olearycrew
bogdan0083
bogdan0083
Atlogit
Atlogit
atlasgong
atlasgong
andreastempsch
andreastempsch
alasano
alasano
QuinsZouls
QuinsZouls
HadesArchitect
HadesArchitect
alarno
alarno
nexon33
nexon33
adilhafeez
adilhafeez
adamwlarson
adamwlarson
adamhill
adamhill
AMHesch
AMHesch
tgfjt
tgfjt
maekawataiki
maekawataiki
SannidhyaSah
SannidhyaSah
samsilveira
samsilveira
01Rian
01Rian
RSO
RSO
R-omk
R-omk
Sarke
Sarke
kvokka
kvokka
ecmasx
ecmasx
mollux
mollux
marvijo-code
marvijo-code
mamertofabian
mamertofabian
monkeyDluffy6017
monkeyDluffy6017
libertyteeth
libertyteeth
shtse8
shtse8
ksze
ksze
Jdo300
Jdo300
hesara
hesara
DeXtroTip
DeXtroTip
pfitz
pfitz

License

Apache 2.0 © 2025 Roo Code, Inc.


Enjoy Roo Code! Whether you keep it on a short leash or let it roam autonomously, we cant wait to see what you build. If you have questions or feature ideas, drop by our Reddit community or Discord. Happy coding!