agent-personalizer 0.5.2 → 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 +129 -96
- package/bin/agent-personalizer.js +52 -66
- package/bin/install-plan.cjs +69 -0
- package/bin/uninstall.cjs +248 -0
- package/docs/README.md +13 -0
- package/docs/guarantees.md +61 -0
- package/docs/install.md +140 -0
- package/docs/paste-guide.md +4 -4
- package/docs/tiers.md +10 -1
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +1 -1
- package/hooks/README.md +1 -1
- package/llms.txt +26 -0
- package/package.json +6 -5
- package/render/onboarding.cjs +1 -1
- package/render/render.cjs +54 -1
package/README.md
CHANGED
|
@@ -2,171 +2,204 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/agent-personalizer) [](https://github.com/aunysillyme/agent-personalizer/actions/workflows/harness.yml) [](https://github.com/aunysillyme/agent-personalizer/blob/main/CHANGELOG.md) [](LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npx agent-personalizer
|
|
15
|
+
```
|
|
18
16
|
|
|
19
|
-
|
|
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
|
-
|
|
19
|
+

|
|
22
20
|
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
+
Privacy:
|
|
36
36
|
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
59
|
+
Inside the generated block in [`CLAUDE.md`](examples/freelance-illustrator/CLAUDE.md):
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
```markdown
|
|
62
|
+
## Who I am
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
70
|
+
```markdown
|
|
71
|
+
## Who I am
|
|
58
72
|
|
|
59
|
-
**
|
|
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
|
-
|
|
|
79
|
+
| AI | File | How it loads |
|
|
62
80
|
|---|---|---|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
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
|
-
##
|
|
90
|
+
## Levels
|
|
72
91
|
|
|
73
|
-
|
|
92
|
+
Choose the files and tools you want the installer to add:
|
|
74
93
|
|
|
75
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
104
|
+
Level 3 adds four pieces:
|
|
84
105
|
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
115
|
+
Re-run the installer to change your answers. Use the interview or supply a JSON file:
|
|
94
116
|
|
|
95
|
-
|
|
117
|
+
```bash
|
|
118
|
+
npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --answers my-answers.json
|
|
119
|
+
```
|
|
96
120
|
|
|
97
|
-
|
|
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
|
-
|
|
123
|
+
At level 3, edit `USER.md` or `rules/`, then render and check:
|
|
100
124
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
132
|
+
## Part of a set
|
|
110
133
|
|
|
111
|
-
Three
|
|
134
|
+
Three open-source tools that work on their own and fit together:
|
|
112
135
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
##
|
|
151
|
+
## Uninstall
|
|
126
152
|
|
|
127
|
-
|
|
153
|
+
Preview removal, then run it:
|
|
128
154
|
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
172
|
+
Start at the [documentation index](docs/README.md):
|
|
140
173
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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).
|
|
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
|
-
//
|
|
167
|
-
|
|
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
|
|
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
|
|
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'
|
|
394
|
-
|
|
395
|
-
|
|
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)
|
|
406
|
-
|
|
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 {
|
|
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) }; //
|
|
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
|
|