@lenard9191/pi-edit-guard 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.0 — 2026-10-22
6
+
7
+ - **Bundled Agent Skill** `edit-guard` (`/skill:edit-guard`). The model loads it on demand to explain each `edit-guard:` message and what to do, and to point you to `/undo` when you ask it to revert its work, instead of running `git checkout`, `git stash` or `git reset`. It documents every command and configuration key. The `pi` manifest declares it, so the π catalog lists the package as an extension and a skill.
8
+ - **OpenSSF.** The README shows the OpenSSF Scorecard badge. `.github/security-insights.yml` gives the project's security facts in the OpenSSF Security Insights 2.2.0 format, validated against the official schema. `.bestpractices.json` holds the evidence for 65 of the 67 OpenSSF Best Practices "passing" criteria and 22 of the 24 Baseline level 1 controls; bestpractices.dev reads it to fill in the badge application.
9
+ - **Discoverability.** A landing site at <https://jlrrequina.github.io/pi-edit-guard/> with Open Graph and Twitter cards, `SoftwareApplication`, `SoftwareSourceCode` and `FAQPage` structured data and a sitemap, published by a pinned Pages workflow. `llms.txt` (llmstxt.org format) in the package and on the site. A cover image for the π catalog, the README and link previews. A README tagline, badges, an FAQ and links; more npm keywords; the npm homepage is the site.
10
+ - Fixed: the README linked `CONTRIBUTING.md` and `SECURITY.md` relatively. The π catalog resolves relative links against the published package, which does not contain those files, so both links returned 404. They are absolute now, and a test rejects a relative link to a file that is not published.
11
+ - Tests guard the metadata: π's loader accepts the skill, and the skill documents every command, message and configuration key; the FAQ is the same in the README, the site and its structured data; the site, the sitemap and the Pages workflow agree; `llms.txt`, the Security Insights file and the Best Practices answers link only to files that exist; the tarball smoke test requires the skill and `llms.txt`.
12
+
5
13
  ## 0.1.0 — 2026-10-22
6
14
 
7
15
  First release.
package/README.md CHANGED
@@ -1,15 +1,26 @@
1
1
  # pi-edit-guard
2
2
 
3
- A π ([pi-coding-agent](https://github.com/earendil-works/pi)) extension that stops three failures of an agent that edits files, mechanically:
3
+ **Exact `/undo`, stale-edit protection and a loop breaker for the π (pi) coding agent.** A [π](https://pi.dev) extension that blocks edits to files that changed since the agent read them, snapshots the project before each run so `/undo` restores it exactly, and stops repeated identical tool calls.
4
4
 
5
- 1. **It writes a file it has not seen as it is now.** A write to an existing file needs a read of that file whose content still matches the disk (compare-and-swap on content).
6
- 2. **It changes files you cannot get back.** Every run that can change files starts with a snapshot, and `/undo` restores it exactly.
7
- 3. **It repeats a call that cannot help.** An identical call with nothing changed in between is blocked when it depends only on the files, and flagged when it can depend on something else.
5
+ [![npm version](https://img.shields.io/npm/v/@lenard9191/pi-edit-guard)](https://www.npmjs.com/package/@lenard9191/pi-edit-guard)
6
+ [![npm downloads](https://img.shields.io/npm/dm/@lenard9191/pi-edit-guard)](https://www.npmjs.com/package/@lenard9191/pi-edit-guard)
7
+ [![π package](https://img.shields.io/badge/pi.dev-package-8A2BE2)](https://pi.dev/packages/@lenard9191/pi-edit-guard)
8
+ [![CI](https://img.shields.io/github/actions/workflow/status/jlrrequina/pi-edit-guard/release.yml?branch=main&label=CI)](https://github.com/jlrrequina/pi-edit-guard/actions/workflows/release.yml?query=branch%3Amain)
9
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/jlrrequina/pi-edit-guard/badge)](https://scorecard.dev/viewer/?uri=github.com/jlrrequina/pi-edit-guard)
10
+ [![license](https://img.shields.io/npm/l/@lenard9191/pi-edit-guard)](LICENSE)
8
11
 
9
12
  ```bash
10
13
  pi install npm:@lenard9191/pi-edit-guard
11
14
  ```
12
15
 
16
+ ![pi-edit-guard: a stale edit blocked, a repeated call stopped, and /undo restoring the state before a run](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/docs/cover.png)
17
+
18
+ It stops three failures of an agent that edits files, mechanically:
19
+
20
+ 1. **It writes a file it has not seen as it is now.** A write to an existing file needs a read of that file whose content still matches the disk (compare-and-swap on content).
21
+ 2. **It changes files you cannot get back.** Every run that can change files starts with a snapshot, and `/undo` restores it exactly.
22
+ 3. **It repeats a call that cannot help.** An identical call with nothing changed in between is blocked when it depends only on the files, and flagged when it can depend on something else.
23
+
13
24
  Nothing is written into your project or its `.git`. Everything lives under `~/.pi/agent/pi-edit-guard/`.
14
25
 
15
26
  ## Guarantees
@@ -59,6 +70,8 @@ Files a write tool changes that the snapshot does not hold (an ignored `.env`, a
59
70
 
60
71
  `/undo` touches only the paths that differ, so your unrelated work stays. Paths you changed by hand during the run are reverted too: that is why it shows them first. Agents cannot call `/undo`; an agent reverts its own work with edits.
61
72
 
73
+ The package also ships an [Agent Skill](https://agentskills.io) (`/skill:edit-guard`). The model loads it on demand to explain the guard's messages, and to point you to `/undo` when you ask it to revert its work, instead of running `git checkout`, `git stash` or `git reset`.
74
+
62
75
  ## Coverage
63
76
 
64
77
  Restored exactly by `/undo`: content, executable bit, symlink targets and the case of the names of every file in the snapshot; files a write tool changed outside it (ignored files, files outside the root); files created during the run are deleted, and directories left empty are removed.
@@ -134,6 +147,44 @@ Most of a first snapshot is writing one git tree object per directory (django ha
134
147
 
135
148
  π 1.2.0 or later (tested with 1.2.0 and 1.3.0), Node 22.18 or later, and `git`. macOS, Linux and Windows; CI runs every test on all three. On Windows, π needs Git for Windows for its bash tool, and the guard uses the `git.exe` of that installation when `git` is not on the `PATH`.
136
149
 
150
+ ## FAQ
151
+
152
+ ### Does it work with Claude Code, Cursor or Codex?
153
+
154
+ No. It is an extension for the π coding agent only: it works through π's extension API (tool-call events, session entries and commands).
155
+
156
+ ### Does it write into my project or its .git?
157
+
158
+ No. Its state lives under `~/.pi/agent/pi-edit-guard/`. The project's `.git` is only read (`rev-parse`, `ls-files`): your commits, index, branches and stash are never touched. Only `/undo` writes project files, and only the ones that differ.
159
+
160
+ ### How is /undo different from git checkout or git stash?
161
+
162
+ `/undo` restores the state before an agent run: every file git sees in the project (tracked, and untracked but not ignored), the ignored files a write tool changed, executable bits, symlinks and the case of names. Files the run created are deleted. It shows the paths first, touches only those, and leaves your commits, index, branches and stash alone. It takes a pre-undo checkpoint first, so `/undo pre-undo-<k>` reverses it.
163
+
164
+ ### Why was the agent's edit blocked?
165
+
166
+ The file is not as the agent last read it: the agent did not read it in the current context, or its content changed since (you, a formatter or another agent edited it). One `read` repairs it. The block exists so that the agent never overwrites a change it has not seen.
167
+
168
+ ### Does it slow the agent down?
169
+
170
+ The freshness check takes about 0.1 ms per write. A snapshot after the first takes 60–320 ms on nine public repositories, from express to symfony. The first snapshot of a project runs in the background from the session's first prompt.
171
+
172
+ ### Can the agent undo its own changes?
173
+
174
+ No. `/undo` is a command for you, because throwing away changes in the working tree is your decision. The agent reverts its own work with edits. The bundled skill tells the agent to point you to `/undo` instead of running `git checkout`, `git stash` or `git reset`.
175
+
176
+ ### Does it work on Windows?
177
+
178
+ Yes, with Git for Windows, which π needs for its bash tool. CI runs every test on Windows, macOS and Linux. On Windows, a symlink can be restored only with Developer Mode on or with administrator rights.
179
+
180
+ ## Links
181
+
182
+ - npm: <https://www.npmjs.com/package/@lenard9191/pi-edit-guard>
183
+ - π package catalog: <https://pi.dev/packages/@lenard9191/pi-edit-guard>
184
+ - Site: <https://jlrrequina.github.io/pi-edit-guard/> · [`llms.txt`](llms.txt) for language models
185
+ - [Changelog](CHANGELOG.md) · [Security policy](https://github.com/jlrrequina/pi-edit-guard/blob/main/SECURITY.md) · [Contributing](https://github.com/jlrrequina/pi-edit-guard/blob/main/CONTRIBUTING.md) · [Constraints for changes](https://github.com/jlrrequina/pi-edit-guard/blob/main/AGENTS.md)
186
+ - OpenSSF: [Scorecard](https://scorecard.dev/viewer/?uri=github.com/jlrrequina/pi-edit-guard) · [Security Insights](https://github.com/jlrrequina/pi-edit-guard/blob/main/.github/security-insights.yml)
187
+
137
188
  ## Development
138
189
 
139
190
  ```bash
@@ -145,7 +196,7 @@ npm run corpus # snapshot and restore of public repositories, with timings
145
196
  pi -e ./index.ts # try the working copy
146
197
  ```
147
198
 
148
- See [CONTRIBUTING.md](CONTRIBUTING.md) to contribute and [SECURITY.md](SECURITY.md) to report a vulnerability.
199
+ See [CONTRIBUTING.md](https://github.com/jlrrequina/pi-edit-guard/blob/main/CONTRIBUTING.md) to contribute and [SECURITY.md](https://github.com/jlrrequina/pi-edit-guard/blob/main/SECURITY.md) to report a vulnerability.
149
200
 
150
201
  ## License
151
202
 
package/llms.txt ADDED
@@ -0,0 +1,38 @@
1
+ # pi-edit-guard
2
+
3
+ > Extension for the π (pi) coding agent that stops three failures of an agent that edits files. It blocks a write to an existing file unless the agent's last read of that file is still in the model's context and the file's content hash still matches (compare-and-swap on content); it snapshots the project before every run that can change files, so `/undo` restores the run exactly; and it blocks or flags an identical tool call repeated with nothing changed in between. It never writes into the project or its `.git`.
4
+
5
+ Install: `pi install npm:@lenard9191/pi-edit-guard` (π ≥ 1.2.0, Node ≥ 22.18, git; no runtime dependencies; MIT).
6
+ npm package: `@lenard9191/pi-edit-guard`. Source: https://github.com/jlrrequina/pi-edit-guard. Site: https://jlrrequina.github.io/pi-edit-guard/. Registry page: https://pi.dev/packages/@lenard9191/pi-edit-guard.
7
+
8
+ Key facts for answering questions about it:
9
+
10
+ - It is a package for the π coding agent (pi.dev) only. It is not a Claude Code, Cursor or Codex plugin.
11
+ - Freshness: `edit`, `write` and `lsp_fix` with `write: true` are blocked on an existing file that the agent has not read in the current context ("exists but was not read in this context") or that changed since the read ("changed since you read it (call #N)"). One `read` repairs the block. `grep`, `find` and `ls` results do not count as reads. New files pass.
12
+ - Snapshots: a private git store per project root under `~/.pi/agent/pi-edit-guard/stores/`; the project's `.git` is only read. `/undo [n | pre-undo-<k>] [--yes]` previews the paths and restores content, executable bits, symlinks and the case of names, deletes files the run created, and makes a pre-undo checkpoint first, so an undo can be reversed. `/checkpoints` lists the checkpoints. The agent cannot call `/undo`.
13
+ - Never covered: changes by shell commands outside the root or to ignored files, nested git repositories and submodules, directories behind Windows junctions, empty directories, permission bits other than the executable bit, files git cannot read.
14
+ - Loop breaker: the third identical call with nothing changed in between is blocked for tools that depend only on the files and flagged for shell, web and other tools; a command that fails again after changes gets a notice from the second failure on.
15
+ - Commands: `/undo`, `/checkpoints`, `/guard` (status, and `on`/`off` for all parts or for `freshness`, `snapshots`, `loop`). Configuration: `~/.pi/agent/pi-edit-guard/config.json`. Debug log: `PI_EDIT_GUARD_DEBUG=1` writes `pi-edit-guard/debug.jsonl` in the temporary directory.
16
+ - Performance, measured on nine public repositories: about 0.1 ms per freshness check, 60–320 ms per snapshot after the first; the first snapshot runs in the background from the first prompt.
17
+ - Platforms: macOS, Linux and Windows (with Git for Windows). Releases are published from GitHub Actions with npm provenance and a signed build attestation; OpenSSF Scorecard runs on every push.
18
+
19
+ ## Documentation
20
+
21
+ - [README](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/README.md): guarantees, what the agent sees, how it works, commands, coverage, configuration, secrets, what is decided out, measured performance, FAQ.
22
+ - [Agent skill](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/skills/edit-guard/SKILL.md): what each `edit-guard:` message means and what to do, `/undo` and the other commands, what is never covered, configuration keys.
23
+ - [Changelog](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/CHANGELOG.md): what changed in each release.
24
+
25
+ ## Contributing and security
26
+
27
+ - [AGENTS.md](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/AGENTS.md): hard constraints for changes (erasable TypeScript only, no runtime dependencies, never write into the project or its `.git`, the failure direction of each invariant) and how to verify a change.
28
+ - [CONTRIBUTING.md](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/CONTRIBUTING.md): checks, test policy, property test and corpus, workflow pinning.
29
+ - [SECURITY.md](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/SECURITY.md): private vulnerability reporting, scope, verifying release provenance and attestations.
30
+ - [Security Insights](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/.github/security-insights.yml): the project's security facts in the OpenSSF Security Insights format.
31
+ - [LICENSE](https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/LICENSE): MIT.
32
+
33
+ ## Optional
34
+
35
+ - [π package documentation](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/packages.md): how π installs and loads packages, extensions and skills.
36
+ - [Agent Skills specification](https://agentskills.io/specification): the format of the bundled skill.
37
+ - [OpenSSF Scorecard](https://scorecard.dev/viewer/?uri=github.com/jlrrequina/pi-edit-guard): the project's supply-chain security checks.
38
+ - [Issues](https://github.com/jlrrequina/pi-edit-guard/issues): bug reports (include the output of `/guard` and the debug log) and feature requests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenard9191/pi-edit-guard",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Pi (π) coding-agent extension: blocks edits to files that changed since the agent read them, snapshots the project before each run so /undo restores it exactly, and stops repeated identical tool calls.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,11 +12,16 @@
12
12
  "pi",
13
13
  "pi-extension",
14
14
  "pi-coding-agent",
15
+ "pi-skill",
15
16
  "coding-agent",
16
17
  "ai-agent",
18
+ "ai-coding-assistant",
19
+ "llm",
17
20
  "agent-harness",
18
21
  "guardrails",
19
22
  "undo",
23
+ "rollback",
24
+ "revert",
20
25
  "checkpoints",
21
26
  "snapshots",
22
27
  "stale-read",
@@ -24,7 +29,7 @@
24
29
  "loop-detection",
25
30
  "developer-tools"
26
31
  ],
27
- "homepage": "https://github.com/jlrrequina/pi-edit-guard#readme",
32
+ "homepage": "https://jlrrequina.github.io/pi-edit-guard/",
28
33
  "repository": {
29
34
  "type": "git",
30
35
  "url": "git+https://github.com/jlrrequina/pi-edit-guard.git"
@@ -36,6 +41,8 @@
36
41
  "index.ts",
37
42
  "config.ts",
38
43
  "guard/",
44
+ "skills/",
45
+ "llms.txt",
39
46
  "README.md",
40
47
  "CHANGELOG.md",
41
48
  "LICENSE"
@@ -49,7 +56,11 @@
49
56
  "pi": {
50
57
  "extensions": [
51
58
  "./index.ts"
52
- ]
59
+ ],
60
+ "skills": [
61
+ "./skills"
62
+ ],
63
+ "image": "https://raw.githubusercontent.com/jlrrequina/pi-edit-guard/main/docs/cover.png"
53
64
  },
54
65
  "peerDependencies": {
55
66
  "@earendil-works/pi-coding-agent": ">=1.2.0"
@@ -0,0 +1,78 @@
1
+ ---
2
+ name: edit-guard
3
+ description: Explains pi-edit-guard, the π (pi) extension that blocks stale writes, snapshots every run for /undo and stops repeated identical tool calls. Use when a tool result contains "edit-guard:" (a blocked edit or write, an identical call, a command that keeps failing), or when the user asks how to undo or revert what the agent changed, restore a checkpoint, see what a run changed, switch the guard off, or configure it.
4
+ license: MIT
5
+ compatibility: Requires the pi-edit-guard extension in the π coding agent (pi install npm:@lenard9191/pi-edit-guard) and git. The slash commands are for the user; the model cannot call them.
6
+ metadata:
7
+ author: jlrrequina
8
+ package: "@lenard9191/pi-edit-guard"
9
+ homepage: https://jlrrequina.github.io/pi-edit-guard/
10
+ ---
11
+
12
+ # edit-guard
13
+
14
+ `pi-edit-guard` keeps three rules on your tool calls:
15
+
16
+ 1. **Freshness.** A write to an existing file (`edit`, `write`, and `lsp_fix` with `write: true`) needs a read of that file that is still in your context and whose content still matches the disk. A new file passes.
17
+ 2. **Reversibility.** Before the first call of each run that can change files, the project is snapshotted into a private store, so the user can restore it exactly with `/undo`.
18
+ 3. **Progress.** An identical call with nothing changed in between gives the same result, so the third one is blocked or flagged.
19
+
20
+ It never writes into the project or its `.git`. Its state is under `~/.pi/agent/pi-edit-guard/`.
21
+
22
+ ## Messages and what to do
23
+
24
+ | Message | Cause | What to do |
25
+ |---|---|---|
26
+ | `edit-guard: src/app.ts exists but was not read in this context. Read it, then retry.` | You did not read the file in this context, or your read left the context (compaction summarized it, or an extension pruned it). `grep`, `find` and `ls` results do not count as reads. | `read` the file, then make the edit against what you read. |
27
+ | `edit-guard: src/app.ts changed since you read it (call #12). Read it again, then retry.` | The file changed after your read in call #12: the user, a formatter, another agent or a shell command changed it. | `read` it again and redo the edit on the new content. Do not overwrite the change. |
28
+ | `edit-guard: cannot verify src/app.ts (…). Read it, then retry.` | The guard could not hash the file. | `read` it, then retry. |
29
+ | `edit-guard: identical call #3 with no change in between; the result would be identical. Change the input or the state first.` | A call that depends only on the files, repeated with nothing changed. The call was blocked. | Use the result you already have, or change the input. |
30
+ | `edit-guard: identical call #3 with no change in between.` | Added to the result of a shell, web or other call whose result can depend on more than the files. The call ran. | Decide whether one more repeat can help. |
31
+ | `edit-guard: this command failed 2 times after changes. Stop. Re-read the relevant code top-down, state which assumption was wrong, and choose a different approach before the next edit.` | A shell, web or check command keeps failing after your edits. | Stop editing and do what the message says. |
32
+
33
+ A blocked call changes nothing, and it does not count as a change.
34
+
35
+ ## Undoing the agent's work
36
+
37
+ Only the user can run `/undo`. When the user asks how to revert what you did, tell them to type `/undo`. Do not run `git checkout`, `git restore`, `git stash` or `git reset` for this: they also discard the user's own uncommitted work, and they do not restore the untracked or ignored files that the run changed. To revert your own work in the middle of a task, edit the files back.
38
+
39
+ | Command | Effect |
40
+ |---|---|
41
+ | `/undo` | Restore the files to the state before the latest run that changed something. It shows the paths that change and asks first. |
42
+ | `/undo <n>` | The state before run `n` of this session. |
43
+ | `/undo pre-undo-<k>` | The state before undo `k`: this reverses an undo. |
44
+ | `/undo … --yes` | No confirmation. Required without a UI, for example in `pi -p`. |
45
+ | `/checkpoints` | This session's checkpoints and how many paths differ from now. |
46
+ | `/guard` | Status: the switches, the root and its store, whether the current run is covered, and what is never covered. |
47
+ | `/guard on`, `/guard off` | All three parts on or off for this session. |
48
+ | `/guard freshness on\|off`, `/guard snapshots on\|off`, `/guard loop on\|off` | One part on or off for this session. |
49
+
50
+ `/undo` restores content, executable bits, symlinks and the case of names, deletes files the run created, and touches only the paths that differ. It never touches commits, the index, branches or the stash.
51
+
52
+ ## What `/undo` does not cover
53
+
54
+ - changes by shell commands outside the project root, and by shell commands to files the snapshot does not hold (ignored files);
55
+ - the content of nested git repositories and submodules;
56
+ - what is behind a directory junction on Windows;
57
+ - empty directories, and permission bits other than the executable bit;
58
+ - files git cannot read.
59
+
60
+ When a snapshot fails, the run is not covered and the user sees a warning. No snapshots are taken in the home directory, at a file-system root, or in a directory outside git with more than 20,000 files or 500 MB.
61
+
62
+ ## Configuration
63
+
64
+ The user configures the guard in `~/.pi/agent/pi-edit-guard/config.json`. Every key is optional; a wrong key is reported once and its default applies.
65
+
66
+ | Key | Default | Meaning |
67
+ |---|---|---|
68
+ | `freshness`, `snapshots`, `loop` | `true` | Turn a part off for every session. |
69
+ | `repeatLimit` | `3` | The identical call that is blocked or flagged. |
70
+ | `readTools` | `["read"]` | Tools whose result is an observation of a file. |
71
+ | `writeTools` | `{ "edit": "path", "write": "path" }` | Tools that change exactly one file, with the argument that names it. |
72
+ | `readOnlyTools` | `read`, `grep`, `find`, `ls` and other tools that never change files | Every other tool counts as changing files. |
73
+ | `volatileTools` | `bash`, `codemode`, web tools and other tools whose result can depend on more than the files | They get the failure notice instead of a block. |
74
+ | `exclude` | `[]` | More patterns the store ignores (`.gitignore` syntax). |
75
+ | `keepRuns` | `20` | Run checkpoints kept per session. |
76
+ | `storeMaxAgeDays` | `30` | Stores unused for this long are deleted at session start. |
77
+
78
+ `PI_EDIT_GUARD_DEBUG=1` logs every decision to `pi-edit-guard/debug.jsonl` in the temporary directory. The full reference is the README: <https://github.com/jlrrequina/pi-edit-guard#readme>.