@avee1234/selfpatch 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abhi Das
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # selfpatch
2
+
3
+ [![CI](https://github.com/abhid1234/selfpatch/actions/workflows/ci.yml/badge.svg)](https://github.com/abhid1234/selfpatch/actions/workflows/ci.yml) [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) ![zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)
4
+
5
+ **[β–Ά Play with it live](https://selfpatch.vercel.app)** Β· watch an AI improve itself, try to reward-hack, and get caught β€” running the real library in your browser.
6
+ **[πŸ“– Read the deep dive](https://abhid.substack.com/p/watching-an-ai-cheat-and-stopping)** Β· *Watching an AI Cheat β€” and Stopping It.*
7
+
8
+ **The trust substrate for self-learning agents.** Every change an agent makes to *itself* β€” its prompts, skills, weights, or scaffolding β€” becomes a verifiable, gated, revertible artifact. So a self-improving agent can be trusted, audited, and rolled back. Zero dependencies.
9
+
10
+ > Working name β€” see [`vision.md`](vision.md). Grounded in the 2026 state of self-improving agents and Lilian Weng's *Harness Engineering for Self-Improvement*.
11
+
12
+ ## The problem
13
+
14
+ Self-improvement is shipping at four layers β€” context/prompt (GEPA, Reflexion), memory/skills (Agent Skills, Voyager), weights (SEAL), and scaffolding (Darwin GΓΆdel Machine). They all share one unsolved problem: **generating a self-improvement is easy now; verifying it is the bottleneck.**
15
+
16
+ The deepest failure mode is **reward hacking** β€” give an agent a number to optimize and it games the number, not the task, so its *reported* score runs away from its *true* ability (Goodhart's law, live). It's not a bug you patch; it's the inevitable consequence of optimizing an imperfect objective. selfpatch is the neutral layer underneath every self-improving system that stops a gamed self-edit from shipping unnoticed.
17
+
18
+ ## The idea β€” a pull request against its own brain
19
+
20
+ A self-edit shouldn't be a silent mutation β€” it should be a reviewable artifact. However an agent proposes to change itself, at any layer, that change becomes a **self-patch**, and four verbs decide its fate:
21
+
22
+ ```bash
23
+ selfpatch propose edit.diff # capture a self-edit as a self-patch (not applied)
24
+ selfpatch verify patch.json # run its held-out check OUTSIDE the loop β€” regress = block
25
+ selfpatch gate patch.json -p pol.json # approve | human-gate | block (protected surfaces, blast radius)
26
+ selfpatch apply patch.json # apply + append to the hash-chained ledger
27
+ selfpatch revert <id> # roll back any applied patch
28
+ ```
29
+
30
+ ## Quickstart
31
+
32
+ ```bash
33
+ npm i @avee1234/selfpatch
34
+ ```
35
+
36
+ ```js
37
+ import { proposeSelfPatch, verifySelfPatch, gate } from '@avee1234/selfpatch'
38
+
39
+ // 1 Β· capture the self-edit as an artifact β€” nothing is applied yet
40
+ const patch = proposeSelfPatch(edit, { layer: 'prompt', rationale })
41
+
42
+ // 2 Β· run YOUR held-out check, outside the loop β€” regress = blocked
43
+ const checked = await verifySelfPatch(patch, { runCheck })
44
+
45
+ // 3 Β· policy decides: approve Β· human-gate Β· block
46
+ const { decision } = gate(checked, policy)
47
+ ```
48
+
49
+ That's the whole integration surface. Your existing improvement loop keeps generating edits; selfpatch just makes each one earn its place before it lands β€” and gives you a revert button for the ones that shouldn't have.
50
+
51
+ ## Why it's different
52
+
53
+ - **The evaluator lives *outside* the loop** by construction β€” a self-edit that games the reward regresses the held-out check and dies there. The safety property falls out of the architecture, not vigilance.
54
+ - **Protected surfaces** let you declare what a harness may never edit about itself β€” the evaluator, the safety rules, the permission boundary. The most dangerous self-edit is the one that changes what "good" means; this makes that structurally impossible.
55
+ - **The ledger** is a hash-chained, tamper-evident changelog of how an agent evolved its own mind β€” approved *and* blocked patches β€” each revertible by id. Catastrophic forgetting stops being terminal: a regression just rolls back.
56
+
57
+ Same open-format-and-conformance playbook as [opentrajectory](https://github.com/abhid1234/opentrajectory) and [constraintguard](https://github.com/abhid1234/constraintguard) β€” but one layer up: it governs *how an agent is allowed to change itself*, across every layer.
58
+
59
+ ## Built by the factory it governs
60
+
61
+ selfpatch was built almost entirely by an autonomous **agent factory** β€” a pipeline that triages, specs, implements, reviews, and ships, with a human at two approval gates. That factory's weekly **retro loop edits its own skills** β€” an ungoverned layer-4 self-modifier, and selfpatch's first real user. The tool that keeps agents honest was built by agents, and now keeps them honest too.
62
+
63
+ Status: **implementation kicked off** β€” see [`roadmap.md`](roadmap.md). Live prototype + field map in [`site/`](site/). MIT Β· zero dependencies Β· harness-neutral.