Skip to content

feat(state): auto-create .gitignore in Loop state directory - #198

Open
zhek wants to merge 1 commit into
ByBrawe:mainfrom
zhek:feat/state-dir-gitignore
Open

zhek wants to merge 1 commit into
ByBrawe:mainfrom
zhek:feat/state-dir-gitignore

Conversation

@zhek

@zhek zhek commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

OpenCode Loop now creates .opencode/opencode-loop/.gitignore automatically when it first creates its runtime state directory. The file contains an explanatory comment and *, preventing logs, checkpoints, and session state from being committed to the project repository by accident.

An existing .gitignore is never overwritten, so user-owned or customized ignore rules survive updates.

Changes

  • Add ensureStateDir() in src/source/core/state.js:
    • creates the Loop state directory;
    • writes .gitignore with a short comment and *;
    • uses exclusive creation (wx) and ignores EEXIST, leaving existing files untouched.
  • Use ensureStateDir() everywhere the state directory may be created:
    • state locking and corrupt-state backups;
    • loop.log writes;
    • patch checkpoints;
    • Goal reports;
    • pulse-check state.
  • Rebuild the shipped bundles: src/index.js, src/server.js, src/native.js.
  • Update README.md, docs/SCHEDULING.md, and CHANGELOG.md.
  • Extend scripts/state-integrity-test.mjs to verify:
    • the ignore file is created with the expected content;
    • an existing .gitignore is not overwritten.

Generated file

# OpenCode Loop runtime state and logs; do not commit this directory.
*
Tests
Passing:
- npm run check
- state-integrity-test
- state-process-test
- state-exfat-lock-test
- job-workspace-test
- tui-status-test
- goal-companion-test
- v2-logging-test
- all remaining tests in the suite except the unrelated failure below
Known unrelated failure on main:
scripts/publish-workflow-test.mjs
ENOENT: .github/workflows/publish-npm.yml
The workflow file was removed in 45ef001 (chore(actions): remove all GitHub Actions workflows...), while the test still expects it. This is not caused by this PR.

Create .opencode/opencode-loop/.gitignore containing '*' whenever the state directory is first created, so logs, checkpoints and session state cannot be committed accidentally. Never overwrite an existing .gitignore file.
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.

1 participant