agentleFS
alipajandalipajand/agent-readiness-kit/.cursor/rules/SAFE_WRITE.mdc

agent-readiness-kit / rules

Cursor rule1 starsChanged 2 months agoMITView on GitHub

Safe-write semantics for file generation in src/generate/ and src/fs/

The file

We split this SAFE_WRITE.mdc into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When adding a new generate template:

    line 27
  2. Very specific:

    Add the template string in src/generate/templates/.

    line 29
  3. Very specific:

    Use writeFileSafe for every write — never fs.writeFile directly.

    line 31
  4. Very specific:

    Add a test in tests/cursorGenerate.spec.ts (or a new spec) that asserts 'skipped' on second invocation without --force.

    line 32

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SAFE_WRITE.mdc
---
description: Safe-write semantics for file generation in src/generate/ and src/fs/
globs: src/{generate,fs}/**/*.ts
alwaysApply: false
---

# Safe-write semantics

## Rule

`writeFileSafe` skips writing if the target file already exists, **unless** `--force` is passed. Never bypass this.

```ts
// ✅ correct — respects existing files
await writeFileSafe(targetPath, content, { force: options.force });

// ❌ wrong — overwrites silently
await fs.writeFile(targetPath, content);
```

## Return value

`writeFileSafe` returns `'wrote' | 'skipped'`. Surface the result to the caller so the CLI can report what happened.

## New templates

When adding a new generate template:

1. Add the template string in `src/generate/templates/`.
2. Wire it through `src/generate/index.ts`.
3. Use `writeFileSafe` for every write — never `fs.writeFile` directly.
4. Add a test in `tests/cursorGenerate.spec.ts` (or a new spec) that asserts `'skipped'` on second invocation without `--force`.

## Placeholder markers

Generated starter files may include `TODO:` or `[PLACEHOLDER]` markers so users know what to customise. The audit's `placeholderDetection.ts` warns when these are still present in committed files. This is intentional — do not remove the warning logic.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.