agent-personalizer 0.5.1 → 0.6.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/README.md CHANGED
@@ -2,171 +2,204 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/agent-personalizer.svg)](https://www.npmjs.com/package/agent-personalizer) [![harness](https://github.com/aunysillyme/agent-personalizer/actions/workflows/harness.yml/badge.svg)](https://github.com/aunysillyme/agent-personalizer/actions/workflows/harness.yml) [![release](https://img.shields.io/github/v/tag/aunysillyme/agent-personalizer?label=release)](https://github.com/aunysillyme/agent-personalizer/blob/main/CHANGELOG.md) [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4
4
 
5
- ### Personalize any AI with dynamic instructions. One profile, one rule source, rendered everywhere.
5
+ **Answer a few questions once, and every AI you use gets the same profile and rules:** Claude Code, Codex, Cursor, Gemini and ChatGPT, rendered from one source and kept in sync.
6
6
 
7
- Most people set up custom instructions once, in one app, and still get generic output. The instructions decay over a long chat, the AI forgets where things are, every app has its own copy that drifts, and the AI treats its own guesses about you as your rulings.
7
+ **The problem:** custom instructions live in each app separately, drift apart, fade over a long chat, and an AI's guesses about you start to read like your rules.
8
8
 
9
- This repo is the fix, in three install levels. Stop at the level you need. A level is the only thing the installer asks you to pick.
9
+ **What you get:** one profile and one rule source, rendered into the exact file each AI reads, with a check that fails when a copy drifts and a status on every remembered fact.
10
10
 
11
- | Level | You have | It writes |
12
- |---|---|---|
13
- | **1. Profile and home file** | one AI, one app | four files and no folders: a profile of you (`USER.md`), an agent onboarding file written from your answers (`AGENT_ONBOARDING.md`), a home file the AI reads first (`CLAUDE.md` or `AGENTS.md`) with the rules rendered into it, and the installer's own `.agent-personalizer.json`. Nothing else, and the home file names nothing that is not there. |
14
- | **2. Dynamic docs** | a notes folder the AI may edit | everything in level 1, plus the notes folder itself: a folder index, a weekly session log, a decisions log and an inbox, each with the rules the AI follows when it writes there. Instructions, not automation: the AI does the keeping. |
15
- | **3. Mechanisms** | a coding agent (Claude Code, Codex, Cursor) | everything above, plus the automation: your own copy of `rules/` to edit, one rule source rendered per AI, a session-start contract that puts your rules in context at decision time, a drift check that fails loudly, a forbidden-string gate. |
11
+ ## Quick start
16
12
 
17
- Level 3 is the top. There is a fourth tier of this system, the hand-off layer, but it ships no files yet and the installer does not offer it: [read what it is](#the-hand-off-layer-not-an-install-level) rather than installing it.
13
+ ```bash
14
+ npx agent-personalizer
15
+ ```
18
16
 
19
- Everything here is the generalized shape of a system that runs in production every day. The examples are invented. The failures the rules prevent are real.
17
+ The installer asks for the folder, which AIs you use, and the level. The short interview asks seven questions by default, plus any that apply to your notes tool. Enter accepts each default.
20
18
 
21
- **What this tool does, and does not do.** It writes files: a profile, an onboarding manual generated from your answers, rule files, rendered instruction files, a session-start hook, a drift check and a privacy gate. Those are the implemented parts and the harness tests every one of them. What it does not do: make an AI comply. Text in a file, or injected at session start, is the strongest placement available, and the stories in `docs/tiers.md` are one setup's experience of what held; they are not a measured guarantee across models or hosts, and nothing here measures compliance. Anything described as the AI "keeping" or "doing" is an instruction the AI is given, not a process this repo runs. The two [companion tools](#companion-tools) are where a rule becomes something a machine enforces.
19
+ ![Terminal recording of the short interview, its answers, and the profile, onboarding and AI instruction files it writes.](docs/demo.gif)
22
20
 
23
- **Privacy:** the tool itself runs entirely on your machine: no network calls, no telemetry, no environment variables read, writes only into the folder you name. The one network step is `npx` fetching the package from the npm registry (or GitHub) before the tool runs; nothing in this repo opens a connection after that. Runs on macOS and Linux, and the Node entry points (installer, renderer, gate) are smoke-tested on Windows in CI; the harness and the session hook are POSIX shell, so on Windows run those under WSL or Git Bash.
21
+ For a headless install with defaults:
24
22
 
25
- ---
23
+ ```bash
24
+ npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --defaults
25
+ ```
26
26
 
27
- ## Quick start
27
+ For the full interview, asking up to 23 questions, only the ones that apply to your notes tool:
28
28
 
29
29
  ```bash
30
- npx agent-personalizer
30
+ npx agent-personalizer --full
31
31
  ```
32
32
 
33
- Published on npm with provenance from this repository's own workflow (`npx github:aunysillyme/agent-personalizer` still works and runs the same code straight from the tag). The installer asks which AIs you use and which level you want, then writes only the matching files into the folder you point it at. It never writes secrets. `--help` lists every flag.
33
+ Requires Node 18 or later. The npm package is published with provenance from this repository's workflow. To pin the GitHub source to this release, use `npx github:aunysillyme/agent-personalizer#v0.6.0`. See [installation](docs/install.md) for scripted answers, the npm cache fix, manual copying, and every flag.
34
34
 
35
- **The interview is short by default.** A bare `npx agent-personalizer` asks the seven questions that change behaviour (name, tone, length, notes tool and path, write policy, always-ask) plus any question the notes tool you pick makes apply, and defaults the rest. `--full` asks all 23.
35
+ Privacy:
36
36
 
37
- **`--yes` and `--defaults` are not the same flag.**
37
+ - **Runs locally:** after `npx` fetches the package from npm or GitHub, the tool runs on your machine. That fetch is the one network step.
38
+ - **No telemetry:** the installer and renderer make no network calls and read no environment variables.
39
+ - **Writes only into the folder you name:** existing user files are preserved, and generated blocks update from their sources.
38
40
 
39
- - `--defaults` is the ANSWER SOURCE: accept every default without being asked. Use it with or without `--yes`.
40
- - `--yes` is NON-INTERACTIVE MODE. It needs `--dir`, `--ai` and `--level`; without those it exits 2. With no `--answers` it falls back to the defaults.
41
- - `--answers file.json` (or `--answers -` from stdin) is the other answer source, and scripts the whole interview.
41
+ ## What it writes
42
42
 
43
- ```bash
44
- npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --defaults
43
+ - **`USER.md`:** your profile, communication preferences, output shape, and the difference between your preferences and rules.
44
+ - **`AGENT_ONBOARDING.md`:** the AI's manual, including what to read first, where it may write, and what needs your approval.
45
+ - **AI instruction files:** your profile and rules in each selected AI's format.
46
+ - **`.agent-personalizer.json`:** the selected targets, level, and onboarding answers used by later runs.
47
+
48
+ Here is a real excerpt from the invented [freelance illustrator example](examples/freelance-illustrator/). The renderer copies the same profile into both home files.
49
+
50
+ [`USER.md`](examples/freelance-illustrator/USER.md):
51
+
52
+ ```markdown
53
+ ## Who I am
54
+
55
+ - **Name and pronouns:** Mara, she/her
56
+ - **What I do:** freelance illustrator. Book covers and editorial work, some client branding on the side.
45
57
  ```
46
58
 
47
- No Node? Copy `templates/USER.md` and `templates/CLAUDE.md` (or `templates/AGENTS.md`) into your project by hand. That is level 1.
59
+ Inside the generated block in [`CLAUDE.md`](examples/freelance-illustrator/CLAUDE.md):
48
60
 
49
- If `npx` stops with `EPERM` and a note about root-owned files in `~/.npm`, npm cannot write its cache. Point it at a local one for this run, no `sudo` needed:
61
+ ```markdown
62
+ ## Who I am
50
63
 
51
- ```bash
52
- npm_config_cache=./.npm-cache npx agent-personalizer
64
+ - **Name and pronouns:** Mara, she/her
65
+ - **What I do:** freelance illustrator. Book covers and editorial work, some client branding on the side.
53
66
  ```
54
67
 
55
- ---
68
+ Inside the generated block in [`AGENTS.md`](examples/freelance-illustrator/AGENTS.md):
56
69
 
57
- ## Why this works: the five places instructions live
70
+ ```markdown
71
+ ## Who I am
58
72
 
59
- **These are not the install levels, and there is nothing to pick here.** The levels above are what the installer writes. The five tiers below are where instructions live once they are written, and why each placement exists. Read [docs/tiers.md](docs/tiers.md) before writing a rule of your own.
73
+ - **Name and pronouns:** Mara, she/her
74
+ - **What I do:** freelance illustrator. Book covers and editorial work, some client branding on the side.
75
+ ```
76
+
77
+ ## Works with
60
78
 
61
- | Tier | What | Prevents |
79
+ | AI | File | How it loads |
62
80
  |---|---|---|
63
- | 1 | Style in the system prompt | rules decaying over a long chat |
64
- | 2 | One always-loaded home file | the AI not knowing where anything is |
65
- | 3 | Session-start injection | a tool's own instructions beating yours at the moment of decision |
66
- | 4 | One owning document per rule | the same rule drifting in five copies |
67
- | 5 | Memory with a status on every fact | the AI treating its own guess as your ruling |
81
+ | Claude Code | `CLAUDE.md` | Reads it from the working folder automatically. |
82
+ | Codex and Cursor | `AGENTS.md` | Read it from the project root automatically. |
83
+ | Gemini CLI | `GEMINI.md` | Reads it from the folder automatically. |
84
+ | claude.ai and Claude Projects | `USER.md` and `AGENT_ONBOARDING.md` | Paste their bodies into custom or project instructions. |
85
+ | ChatGPT | `chatgpt-box1.txt` and `chatgpt-box2.txt` | Paste into the custom-instruction boxes; `chatgpt-custom-instructions.md` shows the same text with counts. |
86
+ | Other chat apps, bots and APIs | `system-prompt.md` | Paste into the system-prompt field. It contains the shareable universal rules. |
68
87
 
69
- ---
88
+ The [paste guide](docs/paste-guide.md) covers each app, ChatGPT's box budget, and what to re-paste after an update.
70
89
 
71
- ## Where each rendered file goes
90
+ ## Levels
72
91
 
73
- [docs/paste-guide.md](docs/paste-guide.md): which file each AI reads and how (Claude Code and Codex, Cursor and Gemini read theirs from the folder automatically; claude.ai and ChatGPT take a paste), and what to re-paste when you change an answer.
92
+ Choose the files and tools you want the installer to add:
74
93
 
75
- ## The agent onboarding file
94
+ | Level | What it gives you | What it writes |
95
+ |---|---|---|
96
+ | **1. Profile and home files** | The same profile and rules for the AIs you pick. | `USER.md`, `AGENT_ONBOARDING.md`, one home file per AI, and `.agent-personalizer.json`. ChatGPT also gets plain paste files for its boxes. |
97
+ | **2. Dynamic docs** | A notes folder the AI keeps under your writing rules. | Everything in level 1, plus a folder index, weekly session-log template, decisions log and inbox for local notes tools. |
98
+ | **3. Mechanisms** | Editable rules and tools that keep the generated files in sync. | Everything above, plus your own `rules/`, renderer, session-start hook, drift check and forbidden-string gate. |
76
99
 
77
- The installer asks you how an AI should work with you, then writes the answers to `AGENT_ONBOARDING.md`: how to talk to you, how to shape output, what to read first and in what order, where it may write, how to save a file, and what it must always ask before doing. It is generated from your answers in `.agent-personalizer.json`, so every AI you point at the folder gets the same manual, and re-running the installer changes it everywhere at once.
100
+ Level 2 creates a local notes folder for disk tools such as Obsidian, Logseq and plain markdown. OneNote, Evernote and other tools use a local fallback. Cloud tools such as Notion get connector pointers and keep their notes in the cloud. Existing local notes scaffolds are detected at any level.
78
101
 
79
- - **Interactive**: run the installer without `--yes` and answer the questions. Enter accepts the default. The short interview is the default: seven questions, plus any the notes tool you pick makes apply. `--full` asks all 23. A question that applies to one notes tool is never asked about another, so nobody answers the Obsidian question about Notion.
80
- - **Scripted**: `--answers my-answers.json` (see [`test/fixtures/answers.json`](test/fixtures/answers.json) for the shape), or `--answers -` to read the JSON from stdin. Unknown keys, wrong types or unknown choices are refused before anything is written.
81
- - **Defaults**: `--defaults`. That is the answer source, and it is not `--yes`, which is non-interactive mode and needs `--dir`, `--ai` and `--level`. A non-interactive run with no answer source falls back to the defaults and says so. The defaults are one working setup: direct, short, one-line corrections, settle facts yourself and ask only when the answer changes what gets built, verdict first, bullets, evidence inline, sign every edit, always ask before delete / publish / send / spend / settings / standing rules. Every one is a question you can answer differently.
102
+ The notes templates give the AI a place for session notes, decisions and inbox items. When you answer yes to signing edits, its instructions include `Last edited by: <ai> <model> <date> · <ten words>`, overwritten on each edit. The AI maintains these notes according to your instructions.
82
103
 
83
- `USER.md` is generated from the same answers the first time and is then yours to edit. Re-running with changed answers regenerates `AGENT_ONBOARDING.md` and every rendered block; `USER.md` is regenerated only if you never edited it (it still equals the render of the previous answers), otherwise it is kept and the installer names the answers that changed so you can carry them over by hand. Two rules depend on answers: the signature rule renders only when you answered yes, and the output-style rule defers to your stated shape instead of imposing one. The session-start contract carries a short version of the onboarding block, restrictions first, so it is present at the moment of decision, not only in a file.
104
+ Level 3 adds four pieces:
84
105
 
85
- ChatGPT has two custom-instruction boxes with a character budget, so its render is the compact profile plus the onboarding block and only the `inject: true` rules, each box measured against the budget, and written twice: inside `chatgpt-custom-instructions.md` with the counts, and as two plain paste files, `chatgpt-box1.txt` and `chatgpt-box2.txt`. `render.cjs --strict` exits 1 instead of writing when a box is over budget, for people who wire the render into CI. Nothing is cut silently: an over-budget box is written in full and flagged, ordered so the last lines are the cheapest to trim. For the rest of the rules, use a ChatGPT Project and upload `AGENT_ONBOARDING.md` and `rules/` as files.
106
+ - **Rule source and renderer:** edit one file in `rules/`; render its universal, personal and AI-specific text into each target.
107
+ - **Session-start contract:** put the onboarding restrictions and `inject: true` rules into context when a Claude Code session starts. [Register the hook](hooks/README.md), or generate a plain prompt for another AI.
108
+ - **Drift check:** compare generated blocks with what their sources render now, and fail when they differ.
109
+ - **Forbidden-string gate:** check file text and paths for strings in your private list before sharing. [Configure the gate](docs/guarantees.md#forbidden-string-gate).
86
110
 
87
- ## Level 1: the profile and one home file
111
+ The [five instruction tiers](docs/tiers.md) explain where style, home files, session contracts, rule owners and memory belong. [Guarantees](docs/guarantees.md) explains what the code enforces and how the instructions reach the AI.
88
112
 
89
- 1. Fill in [`templates/USER.md`](templates/USER.md), or let the installer generate it from your onboarding answers. Who you are, how to talk to you, how firmly you mean things, how you want output shaped.
90
- 2. Copy [`templates/CLAUDE.md`](templates/CLAUDE.md) for Claude, or [`templates/AGENTS.md`](templates/AGENTS.md) for Codex, Cursor and most other coding agents. Both are pointers: they tell the AI to read `USER.md` first and where everything else lives.
91
- 3. Paste the `USER.md` body into the "custom instructions" box of any chat app that has one.
113
+ ## Keep it in sync
92
114
 
93
- Level 1 creates no notes folder, so none of the files it writes names one. The home file points at `AGENT_ONBOARDING.md` for where the AI may write; `AGENT_ONBOARDING.md` and `USER.md` say outright that the folder is not on disk yet and that the AI is to propose writes rather than create it. Level 2 creates the folder and repoints all three at it in the same run.
115
+ Re-run the installer to change your answers. Use the interview or supply a JSON file:
94
116
 
95
- **The one idea in level 1:** the home file carries pointers, not hand-maintained copies. Text you retype drifts. A pointer does not, and neither does a block the renderer regenerates and `--check` compares (level 3): that block is a generated snapshot, with one owner and a drift check, which is the other acceptable shape.
117
+ ```bash
118
+ npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --answers my-answers.json
119
+ ```
96
120
 
97
- ## Level 2: dynamic docs
121
+ `AGENT_ONBOARDING.md` and the selected rendered blocks update together. `USER.md` updates when it still matches the previous answers byte for byte. An edited profile stays yours; the installer names changed answers for you to carry over.
98
122
 
99
- The AI edits your notes under rules that keep them trustworthy. Templates in [`templates/`](templates/):
123
+ At level 3, edit `USER.md` or `rules/`, then render and check:
100
124
 
101
- - **`FOLDER_README.md`**: every folder has an index. Any write to a folder means the index is corrected in the same pass. A stale index is worse than none, because the AI believes it.
102
- - **`session-log.md`**: one note per week. Each session appends a dated section: decisions, corrections, preferences learned.
103
- - **`decisions-log.md`**: one running file. What was decided, why, when. Read before re-deciding anything.
104
- - **Signature line**: every AI edit ends with `Last edited by: <ai> <model> <date> · <ten words>`. One line, overwritten, never stacked.
105
- - **Inbox pattern**: the AI drops notes in an inbox folder, one file per item. Finished items are deleted, not marked done. A resolved file in an inbox reads as open to the next agent.
125
+ ```bash
126
+ node render/render.cjs --dir .
127
+ node render/render.cjs --dir . --check
128
+ ```
106
129
 
107
- A worked week for an invented user is in [`examples/freelance-illustrator/`](examples/freelance-illustrator/).
130
+ `--check` exits 0 when current, 1 on drift, and 2 on invalid input. Files your AI reads automatically are ready for the next session. Re-paste the updated text into chat apps. See [installation](docs/install.md#updating-an-install) for the full update flow.
108
131
 
109
- ## Level 3: mechanisms
132
+ ## Part of a set
110
133
 
111
- Three pieces, all in this repo, no dependencies beyond Node.
134
+ Three open-source tools that work on their own and fit together:
112
135
 
113
- - **Rule source + renderer.** Each rule is one file in [`rules/`](rules/), copied into your folder at level 3 (levels 1 and 2 render from the package's rules and copy nothing), with three fenced blocks: `universal` (any AI), `personal` (your curation), `binding:<ai>` (tool names and paths for one AI). [`render/render.cjs`](render/render.cjs) renders `USER.md` plus the rules into `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, ChatGPT custom-instruction boxes, or a plain system prompt. A rule can say `requires: signature=yes` and then renders only when the answer matches. `--check` fails if any rendered file drifted from its source. The runtime files are `.cjs` so they run inside a `"type": "module"` project too.
114
- - **Session-start contract.** [`hooks/`](hooks/) shows how to inject the rules in full at the start of every Claude Code session, and the plain-prompt fallback for AIs without hooks. The contract carries the onboarding block first, in order of consequence (always-ask, off-limits, write policy, then style), so a token budget trims style before it trims a restriction. Injection puts the text in context; whether the model follows it is host- and model-dependent.
115
- - **Drift check.** `node render/render.cjs --dir . --check` in CI or a pre-commit hook (`npm run check` inside this repo). It compares each rendered block with what the sources would render now: it detects rendering drift, not whether two hand-written files agree in meaning.
116
- - **Forbidden-string gate.** [`check/gate.cjs`](check/gate.cjs) scans every file git would ship (or every file under a folder, with `--all`), text and file paths, for the exact strings in a gitignored list, never follows symlinks, and fails closed when the list is missing. This repo runs it on itself before every push. Copy `check/forbidden.example.txt` to `check/forbidden.local.txt` and fill it in. It is a check for the strings you listed, not a proof that no personal data ships: unknown terms, git history and binary files are outside it.
136
+ | Repo | What it gives you |
137
+ |---|---|
138
+ | **agent-personalizer** | One interview writes the profile and rules every AI you use reads, kept in sync from one source. |
139
+ | [model-orchestrator](https://github.com/aunysillyme/model-orchestrator) | Routing rules that tell your agent which model handles each task, so frontier models do the hard work and cheaper tiers do the rest. |
140
+ | [website-build-skill](https://github.com/aunysillyme/website-build-skill) | A skill pack that teaches your AI current website-building expertise: research, design, code, accessibility, performance, search and security. |
117
141
 
118
142
  ## Companion tools
119
143
 
120
- Two companions turn the onboarding answers from advice into enforcement. Neither is required. [docs/companions.md](docs/companions.md) has the detail and a table of how each note tool is reached.
144
+ These optional tools turn onboarding answers into access controls and approval steps. [Companion setup](docs/companions.md) covers their configuration and how each notes tool is reached.
121
145
 
122
- - **[obsidian-tc](https://github.com/The-40-Thieves/obsidian-tc)** for Obsidian vaults: governed MCP access. Your **off-limits** answer becomes a folder ACL, your **always-ask** answer becomes its human-in-the-loop list, and destructive tools fail closed until you confirm. `npx obsidian-tc /path/to/vault`.
123
- - **[The Context Layer](https://sierracatalina.com/context-layer)** by Sierra Catalina: purpose-bound context with receipts. Capture → normalize → vault → decide → bundle → act; memory writes remain proposals. Your **write policy** and **off-limits** answers are its decide and vault stages in miniature. Read the essay first, then run the starter.
146
+ | Tool | What it gives you |
147
+ |---|---|
148
+ | [obsidian-tc](https://github.com/The-40-Thieves/obsidian-tc) | Governed Obsidian access: configure folder permissions from your off-limits answer and human approval from your always-ask answer. |
149
+ | [The Context Layer](https://sierracatalina.com/context-layer) | Purpose-bound context with receipts; its decide and vault stages apply your write policy and off-limits boundaries. |
124
150
 
125
- ## The hand-off layer (not an install level)
151
+ ## Uninstall
126
152
 
127
- Once you run several AIs, personalization is not the problem any more; routing is. That is a separate layer: which model handles which task, task bundles for every delegation, and CLI runs that only count as success when a deliverable exists. It is being built as its own repo and will link from here when it ships. This repo stays the beginner tier of that stack.
153
+ Preview removal, then run it:
128
154
 
129
- Nothing here installs it, so the installer stops at level 3. `--level 4` is still accepted, because it once was offered, and it writes exactly what `--level 3` writes.
155
+ ```bash
156
+ npx agent-personalizer --uninstall --dir . --dry
157
+ npx agent-personalizer --uninstall --dir .
158
+ ```
130
159
 
131
- ---
160
+ The uninstaller compares files with the current render and templates. Unchanged generated files are removed. Edited files and your notes stay, and kept files are named. Existing home files keep their own text; only an unchanged generated block is removed. Remove any session-start hook registration from your AI's settings when prompted. See [removal details](docs/install.md#uninstall).
161
+
162
+ ## For agents
163
+
164
+ Read [`llms.txt`](llms.txt) for documentation links and [`AGENTS.md`](AGENTS.md) for contributor instructions. Headless setup: `npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --defaults`.
132
165
 
133
166
  ## Every rule carries its story
134
167
 
135
- Open any file in [`rules/`](rules/). Each ends with an `origin` block: the failure that produced the rule and the failure it prevents. Rules without a story get argued with. Rules with one get followed, by people and by models. When you write your own, fill the block in. It is the most useful thing in the file.
168
+ Each file in [`rules/`](rules/) ends with an `origin` block: the failure that produced the rule and the failure it prevents. Fill it in when you add a rule so a reader can see why it exists and when it applies.
136
169
 
137
- ---
170
+ ## Docs
138
171
 
139
- ## Repo map
172
+ Start at the [documentation index](docs/README.md):
140
173
 
141
- ```
142
- templates/ USER.md, CLAUDE.md, AGENTS.md, FOLDER_README.md, session-log.md, decisions-log.md, INBOX_README.md
143
- render/onboarding.cjs the interview questions, their defaults, and the USER.md / AGENT_ONBOARDING.md / contract renders
144
- rules/ example rules in the three-fence format, plus the format spec
145
- render/ render.cjs and the target table
146
- hooks/ Claude Code session-start contract, plain-prompt fallback
147
- check/ gate.cjs, the forbidden-string gate this repo runs on itself
148
- bin/ the npx installer
149
- examples/ one invented user, end to end
150
- docs/ tiers.md, companions.md, paste-guide.md
151
- CHANGELOG.md keyed on audit rounds
152
- .github/ harness.yml: the checks on every push and PR, Ubuntu and macOS x Node 18/20/22, plus a Windows smoke job; publish.yml: npm publish with provenance, dispatched per tag
153
- test/ run.sh: 89 checks, exact exit codes, adversarial fixtures (symlinks, traversal, malformed markers, CRLF, partial renders)
154
- ```
174
+ - **[Install and uninstall](docs/install.md):** flags, scripted answers, updates and removal.
175
+ - **[Instruction tiers](docs/tiers.md):** where each kind of instruction belongs.
176
+ - **[Paste guide](docs/paste-guide.md):** how each AI loads its files.
177
+ - **[Companions](docs/companions.md):** notes connectors and enforcement tools.
178
+ - **[Guarantees](docs/guarantees.md):** rendering, checks, preflight and runtime safety.
179
+ - **[Changelog](CHANGELOG.md):** release history.
180
+
181
+ ## Common questions
182
+
183
+ **How do I keep the same custom instructions across Claude Code, Codex, Cursor and ChatGPT?** One interview writes `USER.md` and `rules/` once, and the renderer copies that same profile and rules into every AI's own file. Run `npx agent-personalizer` and pick every AI you use, for example `--ai claude,agents,gemini,chatgpt,prompt`.
184
+
185
+ **Which files does it write for each AI?** Claude Code reads `CLAUDE.md`, Codex and Cursor read `AGENTS.md`, Gemini CLI reads `GEMINI.md`, and ChatGPT takes `chatgpt-box1.txt` and `chatgpt-box2.txt` pasted into its two custom-instruction boxes. See [Works with](#works-with) for the full table and the [paste guide](docs/paste-guide.md) for every app.
186
+
187
+ **How do I change an answer later?** Re-run the installer with the interview, or supply a JSON answers file: `npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --answers my-answers.json`. `AGENT_ONBOARDING.md` and the rendered blocks update together, and `USER.md` regenerates only when it still matches your previous answers byte for byte. See [updating an install](docs/install.md#updating-an-install).
155
188
 
156
- ## Changelog
189
+ **How do I check that nothing drifted?** At level 3, run `node render/render.cjs --dir . --check`. It exits 0 when every generated file matches what its sources render now, and 1 when one has drifted.
157
190
 
158
- [CHANGELOG.md](CHANGELOG.md). Every entry names the audit round that produced it.
191
+ **How do I remove it?** Preview first with `npx agent-personalizer --uninstall --dir . --dry`, then run `npx agent-personalizer --uninstall --dir .`. Unchanged generated files are removed, while edited files, your notes and a pre-existing home file's own text stay. See [removal details](docs/install.md#uninstall).
159
192
 
160
193
  ## Contributing
161
194
 
162
- Open an issue with the failure you hit, not the feature you want. Rules come from failures. [CONTRIBUTING.md](CONTRIBUTING.md) has the checks, the rule format and how to add a notes tool or an AI target. Every push and pull request runs the harness on Ubuntu and macOS ([.github/workflows/harness.yml](.github/workflows/harness.yml)); the privacy gate against a real forbidden list stays local by design, so CI shows that one check as a skip.
195
+ Contributions are welcome: a new AI target, a notes tool, an example user, or a failure you hit with steps to reproduce it. [CONTRIBUTING.md](CONTRIBUTING.md) covers the rule format and checks.
163
196
 
164
- ---
197
+ The harness (`test/run.sh: 91 checks`) tests exact exit codes and adversarial fixtures. Every push and pull request runs it on Ubuntu and macOS; Windows CI smoke-tests the Node entry points. The shell harness and hook run under WSL or Git Bash on Windows. The real forbidden-list check stays local and prints a skip when the private list is absent.
165
198
 
166
199
  ## License
167
200
 
168
- MIT ([LICENSE](LICENSE)). You may use, change, share and sell copies for any purpose; keep the notice; no warranty, no endorsement implied. Attribution is appreciated, not required: *Built with agent-personalizer (https://github.com/aunysillyme/agent-personalizer)*.
201
+ [MIT](LICENSE). Use, change, share and sell copies under its terms. Attribution is appreciated: *Built with agent-personalizer (https://github.com/aunysillyme/agent-personalizer)*.
169
202
 
170
- Security reports: [SECURITY.md](SECURITY.md). Contributing: [CONTRIBUTING.md](CONTRIBUTING.md). Releases: [RELEASING.md](RELEASING.md).
203
+ Security reports: [SECURITY.md](SECURITY.md). Releases: [RELEASING.md](RELEASING.md).
171
204
 
172
205
  Built in public by [@AunySillyMe](https://x.com/AunySillyMe).
@@ -34,23 +34,31 @@
34
34
  const fs = require('fs');
35
35
  const path = require('path');
36
36
  const readline = require('readline');
37
+ const crypto = require('crypto');
37
38
  const { execFileSync } = require('child_process');
39
+ const sha256 = (bytes) => crypto.createHash('sha256').update(bytes).digest('hex');
40
+ // CLAUDE.md and AGENTS.md are written here as a pointer template only; render.cjs (run at the
41
+ // end of main()) splices in the rendered block and records the final bytes it wrote, so their
42
+ // hash is recorded there, once, against the complete file.
43
+ const HOME_NAMES = new Set(['CLAUDE.md', 'AGENTS.md']);
38
44
 
39
45
  const PKG = path.resolve(__dirname, '..');
40
46
  const onboarding = require(path.join(PKG, 'render', 'onboarding.cjs'));
41
47
  const markers = require(path.join(PKG, 'render', 'render.cjs')); // markerState, for the preflight; render.cjs runs nothing on require
48
+ const { installPlan } = require('./install-plan.cjs');
42
49
  const AIS = ['claude', 'agents', 'gemini', 'chatgpt', 'prompt'];
43
50
  const AI_LABEL = { claude: 'Claude (Claude Code, Claude apps)', agents: 'Codex / Cursor / anything that reads AGENTS.md', gemini: 'Gemini', chatgpt: 'ChatGPT custom instructions', prompt: 'a plain system prompt (shareable, no profile)' };
44
51
 
45
52
  function die(msg) { console.error(`agent-personalizer: ${msg}`); process.exit(2); }
46
53
 
47
54
  const VALUE_OPTS = ['--dir', '--ai', '--level', '--answers'];
48
- const FLAG_OPTS = ['--yes', '--defaults', '--quick', '--full', '--help', '--version', '-h', '-v'];
55
+ const FLAG_OPTS = ['--yes', '--defaults', '--quick', '--full', '--uninstall', '--dry', '--help', '--version', '-h', '-v'];
49
56
  const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).version}
50
57
 
51
58
  npx agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3]
52
59
  [--answers <file.json> | --answers - | --defaults] [--full] [--yes]
53
60
  [--help | -h] [--version | -v]
61
+ npx agent-personalizer --uninstall --dir <folder> [--dry]
54
62
 
55
63
  Interactive when flags are missing and stdin is a terminal; the onboarding interview runs then.
56
64
  The interview is SHORT by default: the seven questions that change behaviour (name, tone, length,
@@ -62,6 +70,8 @@ const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).vers
62
70
  --defaults the ANSWER SOURCE: accept every default without being asked. With or without --yes.
63
71
  --yes NON-INTERACTIVE MODE, not an answer source. It needs --dir, --ai and --level, and with no
64
72
  --answers it falls back to the defaults.
73
+ --uninstall remove unchanged installed files; keep and name edited files and user text.
74
+ --dry preview --uninstall without changing files.
65
75
  Levels: 1 profile, onboarding and home file(s); nothing else (the rules render from the package)
66
76
  2 + the notes folder: its README, a weekly session log, a decisions log and an inbox
67
77
  3 + the renderer, the session-start hook, the gate and a copy of rules/ to edit
@@ -146,6 +156,13 @@ function copyIfAbsent(src, root, rel) {
146
156
  }
147
157
 
148
158
  async function main() {
159
+ if (ARGS['--uninstall']) {
160
+ if (!ARGS['--dir']) die('--uninstall needs --dir <folder>');
161
+ for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full'])
162
+ if (opt in ARGS) die(`${opt} is an install option; --uninstall reads the stored config`);
163
+ return require('./uninstall.cjs').uninstall(ARGS['--dir'], { dry: !!ARGS['--dry'] });
164
+ }
165
+ if (ARGS['--dry']) die('--dry needs --uninstall');
149
166
  const interactive = process.stdin.isTTY && !!!ARGS['--yes'];
150
167
  let dir = arg('--dir', null);
151
168
  let ais = arg('--ai', null);
@@ -163,9 +180,8 @@ async function main() {
163
180
  if (!dir || !ais || !level) die('non-interactive run needs --dir, --ai and --level (and --yes)');
164
181
  if (!/^[1-4]$/.test(String(level))) die('level must be exactly 1, 2 or 3');
165
182
  level = Number(level);
166
- // 4 was once offered as a peer of 1-3 and installed exactly what 3 installs: the hand-off layer is
167
- // reading material, not files. It is no longer offered, and still accepted so older scripts run.
168
- if (level === 4) console.log('note: --level 4 installs exactly what --level 3 installs. The hand-off layer (routing, task bundles, verified CLI runs) is reading material until it ships, so 3 is the top install level.');
183
+ // Keep the former level accepted so existing scripts run. Routing has its own package.
184
+ if (level === 4) console.log('note: --level 4 installs exactly what --level 3 installs. For model routing, see https://github.com/aunysillyme/model-orchestrator');
169
185
  const targets = String(ais).split(',').map(s => s.trim()).filter(Boolean);
170
186
  const bad = targets.filter(t => !AIS.includes(t));
171
187
  if (bad.length) die(`unknown AI: ${bad.join(', ')} (known: ${AIS.join(', ')})`);
@@ -194,7 +210,7 @@ async function main() {
194
210
  console.log('\nOnboarding: how should an AI work with you? Enter accepts the default in brackets.');
195
211
  console.log(full
196
212
  ? `Full interview: up to ${onboarding.QUESTIONS.length} questions, some of which apply only to certain notes tools.\n`
197
- : `Short interview: the ${onboarding.QUICK.length} questions that change behaviour, plus any the notes tool you pick makes apply. Every other answer takes its default; --full asks all ${onboarding.QUESTIONS.length}.\n`);
213
+ : `Short interview: the ${onboarding.QUICK.length} questions that change behaviour, plus any the notes tool you pick makes apply. Every other answer takes its default; --full asks up to ${onboarding.QUESTIONS.length}, skipping questions that do not apply to your notes tool.\n`);
198
214
  const raw = {};
199
215
  for (const q of onboarding.QUESTIONS) {
200
216
  if (!onboarding.asks(q, raw, full)) continue;
@@ -233,6 +249,10 @@ async function main() {
233
249
  if (new Set(cfg.targets).size !== cfg.targets.length) die('.agent-personalizer.json lists a target twice');
234
250
  }
235
251
  if ('level' in cfg && !(Number.isInteger(cfg.level) && cfg.level >= 1 && cfg.level <= 4)) die(`.agent-personalizer.json "level" must be an integer 1-4 (found ${JSON.stringify(cfg.level)})`);
252
+ markers.DIE_THROWS = true;
253
+ try { markers.validatePreservedTargets(cfg); }
254
+ catch (e) { if (e instanceof markers.Refusal) die(e.message); throw e; }
255
+ finally { markers.DIE_THROWS = false; }
236
256
  if (cfg.onboarding) {
237
257
  try { prevAnswers = onboarding.validate(cfg.onboarding); } catch (e) { die(`.agent-personalizer.json onboarding answers: ${e.message}`); }
238
258
  if (!answersFile && answersSource.startsWith('defaults')) { answers = prevAnswers; answersSource = 'kept from .agent-personalizer.json'; }
@@ -241,67 +261,19 @@ async function main() {
241
261
  const allTargets = [...new Set([...(Array.isArray(cfg.targets) ? cfg.targets : []), ...targets, 'onboarding'])];
242
262
  const base = onboarding.baseFor(answers); // the folder scaffolds and home-file pointers use
243
263
  const kind = onboarding.kindOf(answers);
264
+ // Bytes actually written, by tracked path, so --uninstall never has to re-derive them from
265
+ // whatever package version happens to be running at removal time. Carried forward across runs;
266
+ // only ever added to here, never pruned (a config predating this field has none, and falls
267
+ // back to the older comparison; see uninstall.cjs).
268
+ const installedHashes = { ...(cfg.installed && typeof cfg.installed === 'object' ? cfg.installed : {}) };
244
269
 
245
270
  console.log(`\nInstalling level ${level} for ${targets.join(', ')} into ${root}\nOnboarding answers: ${answersSource}\n`);
246
271
 
247
272
  // ---- PLAN: every file this run would create, computed before anything is written ----
248
- const plan = []; // { rel, src | text }
249
- // signature=no: the signature rule file is not installed (a `requires:` rule that is absent cannot drift back in),
250
- // and every copied markdown loses its `Last edited by:` template line and its pointer to the rule.
251
- const noSig = answers.signature === 'no';
252
- const stripSig = (t) => noSig ? t.split('\n').filter(l => !l.includes('40-sign-every-edit.md') && !/^`?Last edited by:/.test(l)).join('\n') : t;
253
- const mdCopy = (rel, src) => plan.push({ rel, text: stripSig(fs.readFileSync(src, 'utf8')) });
254
- // rules/ is copied at level 3, where it becomes yours to edit; levels 1 and 2 render from the package's rules
255
- if (level >= 3) for (const f of fs.readdirSync(path.join(PKG, 'rules')).sort()) {
256
- if (noSig && f === '40-sign-every-edit.md') continue;
257
- mdCopy(`rules/${f}`, path.join(PKG, 'rules', f));
258
- }
259
- // The home templates carry four `notes/...` pointer lines. They collapse to ONE line whenever the
260
- // folder they name will not be there to read: a cloud notes tool has no local folder at all, and no
261
- // level below 2 creates one, so a level-1 install used to hand the first session four broken
262
- // pointers. NOTES_ONE_LINE is also what the level-2 upgrade looks for, byte for byte.
263
- const NOTES_ONE_LINE = (why) => `- Notes: see \`AGENT_ONBOARDING.md\` § Where you may write (${why})`;
264
- const NOTES_LATER = `no local notes folder at level 1; level 2 creates \`${base}/\``;
265
- // Is the folder every notes pointer names going to be there to read? The README is the file the AI
266
- // is told to read before it writes, and the level-2 scaffold creates it with the folder. The LEVEL
267
- // alone is a proxy that is wrong in both directions: a level-1 install can land beside a notes
268
- // folder that already exists, and a re-run at a lower level does not delete what a higher one made
269
- // (round 1, findings 4 and 5). One boolean drives the home-file collapse and both rendered files,
270
- // so they can never disagree about the same folder.
271
273
  const scaffoldExists = (() => { try { return fs.statSync(path.join(root, base, 'README.md')).isFile(); } catch (_) { return false; } })();
272
274
  const willScaffold = level >= 2 && kind !== 'cloud'; // this run's own scaffold, written further down
273
275
  const notesScaffolded = kind !== 'cloud' && (scaffoldExists || willScaffold);
274
- const notesWhy = kind === 'cloud' ? 'reached through its connector, no local files'
275
- : !notesScaffolded ? NOTES_LATER
276
- : kind !== 'disk' ? 'local fallback folder `notes/`'
277
- : null; // disk, scaffold present: the four paths, retargeted at notes_path
278
- const home = (name) => {
279
- let t = fs.readFileSync(path.join(PKG, 'templates', name), 'utf8');
280
- if (level < 3) {
281
- // no local rules/: the pointers point at the rendered block below, which carries the full text
282
- t = t.split('\n').filter(l => !/Rules, one file each, the owning copy/.test(l)).join('\n');
283
- t = t.replace(/`\[owner: rules\/[^\]]+\]`/g, '`[owner: the rendered block below]`');
284
- }
285
- if (notesWhy) {
286
- let done = false;
287
- t = t.split('\n').filter(l => { if (!/`notes\//.test(l)) return true; if (done) return false; done = true; return true; })
288
- .map(l => /`notes\//.test(l) ? NOTES_ONE_LINE(notesWhy) : l).join('\n');
289
- } else if (base !== 'notes') t = t.replace(/\bnotes\//g, `${base}/`);
290
- return stripSig(t);
291
- };
292
- const POINTER = 'pointer file; the renderer fills its block below';
293
- if (targets.includes('claude')) plan.push({ rel: 'CLAUDE.md', text: home('CLAUDE.md'), note: POINTER });
294
- if (targets.includes('agents')) plan.push({ rel: 'AGENTS.md', text: home('AGENTS.md'), note: POINTER });
295
- if (level >= 2 && kind !== 'cloud') { // a cloud tool's notes are not local files; no folder named after a workspace
296
- mdCopy(`${base}/README.md`, path.join(PKG, 'templates', 'FOLDER_README.md'));
297
- mdCopy(`${base}/sessions/TEMPLATE-week.md`, path.join(PKG, 'templates', 'session-log.md'));
298
- mdCopy(`${base}/decisions.md`, path.join(PKG, 'templates', 'decisions-log.md'));
299
- mdCopy(`${base}/inbox/README.md`, path.join(PKG, 'templates', 'INBOX_README.md'));
300
- }
301
- if (level >= 3) {
302
- for (const rel of ['render/render.cjs', 'render/targets.json', 'render/onboarding.cjs', 'hooks/README.md', 'hooks/claude-code/session-start.sh', 'check/gate.cjs', 'check/forbidden.example.txt'])
303
- plan.push({ rel, src: path.join(PKG, rel) });
304
- }
276
+ const { plan, stripSig, notesWhy, NOTES_ONE_LINE, NOTES_LATER } = installPlan({ answers, level, targets, notesScaffolded });
305
277
 
306
278
  // ---- PREFLIGHT: refuse now, with nothing written, everything the renderer would refuse later ----
307
279
  for (const p of plan) probe(root, p.rel); // symlinks and non-directories on the way
@@ -311,10 +283,12 @@ async function main() {
311
283
  catch (e) { if (e instanceof markers.Refusal) die(`${e.message}. The renderer would refuse this folder; nothing was written`); throw e; }
312
284
  finally { markers.DIE_THROWS = false; }
313
285
  const TARGETS = JSON.parse(fs.readFileSync(path.join(PKG, 'render', 'targets.json'), 'utf8'));
286
+ const preservedTargets = new Set(cfg.preservedTargets || []);
314
287
  for (const t of allTargets) {
315
288
  const rel = TARGETS[t].file;
316
289
  const { full, exists } = probe(root, rel);
317
290
  if (exists) {
291
+ if (!cfgExists || !(cfg.targets || []).includes(t)) preservedTargets.add(t);
318
292
  const st = fs.lstatSync(full);
319
293
  if (!st.isFile()) die(`${rel} exists and is not a regular file; nothing was written`);
320
294
  let text; try { text = new TextDecoder('utf-8', { fatal: true }).decode(fs.readFileSync(full)); } catch (_) { die(`${rel} is not valid UTF-8; the renderer would refuse it. Nothing was written`); }
@@ -390,9 +364,14 @@ async function main() {
390
364
 
391
365
  // ---- WRITE ----
392
366
  for (const u of upgrades) { fs.writeFileSync(u.full, u.text); console.log(`update ${u.name} (${u.why.join('; ')})`); }
393
- if (userAction === 'create') { fs.writeFileSync(user.full, onboarding.renderUser(answers, { notesScaffolded }), { flag: 'wx' }); console.log('wrote USER.md (from your answers)'); }
394
- else if (userAction === 'regenerate') { fs.writeFileSync(user.full, onboarding.renderUser(answers, { notesScaffolded })); console.log(`update USER.md (regenerated: it matched your previous answers byte for byte; changed: ${changedKeys.join(', ')})`); }
395
- else if (userAction === 'relevel') { fs.writeFileSync(user.full, onboarding.renderUser(answers, { notesScaffolded })); console.log(`update USER.md (notes pointers now name ${base}/, which is there; it matched the render that said it was not, byte for byte)`); }
367
+ if (userAction === 'create' || userAction === 'regenerate' || userAction === 'relevel') {
368
+ const rendered = onboarding.renderUser(answers, { notesScaffolded });
369
+ fs.writeFileSync(user.full, rendered, userAction === 'create' ? { flag: 'wx' } : undefined);
370
+ installedHashes['USER.md'] = sha256(Buffer.from(rendered));
371
+ if (userAction === 'create') console.log('wrote USER.md (from your answers)');
372
+ else if (userAction === 'regenerate') console.log(`update USER.md (regenerated: it matched your previous answers byte for byte; changed: ${changedKeys.join(', ')})`);
373
+ else console.log(`update USER.md (notes pointers now name ${base}/, which is there; it matched the render that said it was not, byte for byte)`);
374
+ }
396
375
  else if (userAction === 'conflict') {
397
376
  console.log(`kept USER.md (you edited it, so it was not regenerated)`);
398
377
  console.log(` ANSWERS CHANGED: ${changedKeys.join(', ')}. USER.md still carries the old value(s) and the rendered profile sections come from USER.md.`);
@@ -402,11 +381,18 @@ async function main() {
402
381
  if (staleNotesInUser) console.log(` NOTE: you edited USER.md while it still said there is no local notes folder. ${base}/ exists now. Fix the two "Where things live" lines by hand, or delete USER.md and re-run.`);
403
382
  }
404
383
  for (const p of plan) {
405
- if (p.src) copyIfAbsent(p.src, root, p.rel);
406
- else {
384
+ if (p.src) {
385
+ if (copyIfAbsent(p.src, root, p.rel)) installedHashes[p.rel] = sha256(fs.readFileSync(p.src));
386
+ } else {
407
387
  const { full, exists } = safeDest(root, p.rel);
408
388
  if (exists) console.log(`kept ${p.rel} (exists)`);
409
- else { fs.writeFileSync(full, p.text, { flag: 'wx' }); console.log(`wrote ${p.rel}${p.note ? ` (${p.note})` : ''}`); }
389
+ else {
390
+ fs.writeFileSync(full, p.text, { flag: 'wx' });
391
+ console.log(`wrote ${p.rel}${p.note ? ` (${p.note})` : ''}`);
392
+ // CLAUDE.md/AGENTS.md are only a pointer template here; render.cjs below splices in the
393
+ // rendered block and records the finished file's hash itself.
394
+ if (!HOME_NAMES.has(p.rel)) installedHashes[p.rel] = sha256(Buffer.from(p.text));
395
+ }
410
396
  }
411
397
  }
412
398
  if (level >= 3) {
@@ -415,7 +401,7 @@ async function main() {
415
401
  if (!st.isFile() || st.isSymbolicLink()) die('hook file changed underneath the installer; not chmod-ing it');
416
402
  fs.chmodSync(hp, 0o755);
417
403
  }
418
- cfg = { ...cfg, targets: allTargets, level: Math.max(level, cfg.level || 0), onboarding: onboarding.sparse(answers) }; // only what differs from the defaults
404
+ cfg = { ...cfg, targets: allTargets, level: Math.max(level, cfg.level || 0), onboarding: onboarding.sparse(answers), preservedTargets: [...preservedTargets], installed: installedHashes }; // sparse answers, original home ownership, and the bytes written so far (render.cjs below adds the home files)
419
405
  fs.writeFileSync(cfgPath, JSON.stringify(cfg, null, 2) + '\n');
420
406
  console.log(`${cfgExists ? 'update' : 'wrote '} .agent-personalizer.json (onboarding: ${answersSource})`);
421
407