agent-personalizer 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/README.md +23 -12
- package/RELEASING.md +7 -1
- package/SECURITY.md +3 -1
- package/bin/agent-personalizer.js +130 -81
- package/bin/global.cjs +201 -0
- package/bin/home.cjs +15 -0
- package/bin/install-plan.cjs +7 -2
- package/bin/known-hashes.json +78 -0
- package/bin/learn.cjs +2 -2
- package/bin/sessions.cjs +48 -15
- package/bin/uninstall.cjs +2 -1
- package/docs/guarantees.md +2 -2
- package/docs/install.md +27 -5
- package/docs/learning.md +1 -1
- package/docs/paste-guide.md +5 -3
- package/examples/freelance-illustrator/.agent-personalizer.json +1 -1
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +1 -1
- package/examples/freelance-illustrator/rules/README.md +2 -0
- package/examples/lab-technician/rules/README.md +2 -0
- package/examples/product-designer/rules/README.md +2 -0
- package/hooks/README.md +1 -1
- package/llms.txt +8 -2
- package/package.json +1 -1
- package/render/onboarding.cjs +1 -1
- package/render/render.cjs +14 -6
- package/rules/README.md +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,32 @@ Every entry names the adversarial audit round that produced it where one did. Au
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.8.4] - 2026-10-28
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `--global` applies a level-1 profile across Claude Code, Codex and Gemini CLI projects, with byte-preserving marked blocks, safe uninstall and shared atomic rollback (#29).
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Levels 1 and 2 render the Core 5 rules; level 3 keeps all eleven and editable rule sources. Untouched older generated files refresh through recorded ownership; edited files stay for review (#33).
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- The 0.8.4 follow-up audit adds the Windows `USERPROFILE` fallback and home-free project AI defaults, preserves outside edits when uninstalling adopted pre-existing targets, and checks Markdown links after blank lines and escaped backticks.
|
|
22
|
+
- The 0.8.4 follow-up audit fixes bound Claude and Codex session reads to contenders for the newest 20, validate and clamp message timestamps to file mtime, refuse foreign global blocks and invalid HOME values before writes, adopt explicitly re-rendered Core 5 upgrades, and keep code examples containing HTML comment openers from hiding later Markdown links.
|
|
23
|
+
- Session learning selects the newest 20 usable sessions by latest message timestamp across all sources, including legacy Gemini logs, with file mtime used only when a session has no valid timestamp (#38).
|
|
24
|
+
- Digest removal documentation now agrees with recorded-hash ownership and preserves edited or unrecorded files (#39).
|
|
25
|
+
- Markdown link checking strips nested and unterminated HTML comments completely (CodeQL `js/incomplete-multi-character-sanitization`).
|
|
26
|
+
- Security reporting links directly to private advisories and states the existing acknowledgement and fix windows (Scorecard Security-Policy).
|
|
27
|
+
- Publishing uses Node 24 and checks bundled npm is at least 11.5.1, replacing the mutable global npm install while retaining the pinned setup action (Scorecard Pinned-Dependencies).
|
|
28
|
+
|
|
29
|
+
## [0.8.3] - 2026-10-19
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- The README and llms.txt "Part of a set" section now renders from the shared set file. The README table has four rows, adds repo-build-skill, and uses each package's npm description. CI checks the rendered blocks and locked file hashes for drift offline.
|
|
34
|
+
|
|
9
35
|
## [0.8.2] - 2026-10-18
|
|
10
36
|
|
|
11
37
|
### Changed
|
|
@@ -305,7 +331,9 @@ Thirteen issues (#3 to #15) filed against `5972b32` by an independent installati
|
|
|
305
331
|
- Installer: safe destination resolution, strict options, duplicate `--ai` refused, `--dir` created one level at a time.
|
|
306
332
|
- Harness: exact exit codes, adversarial fixtures, fault injection for the rollback path.
|
|
307
333
|
|
|
308
|
-
[Unreleased]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.
|
|
334
|
+
[Unreleased]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.4...HEAD
|
|
335
|
+
[0.8.4]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.3...v0.8.4
|
|
336
|
+
[0.8.3]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.2...v0.8.3
|
|
309
337
|
[0.8.2]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.1...v0.8.2
|
|
310
338
|
[0.8.1]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.0...v0.8.1
|
|
311
339
|
[0.8.0]: https://github.com/aunysillyme/agent-personalizer/compare/v0.7.2...v0.8.0
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# agent-personalizer
|
|
2
2
|
|
|
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)
|
|
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) [](https://scorecard.dev/viewer/?uri=github.com/aunysillyme/agent-personalizer)
|
|
4
4
|
|
|
5
5
|
**Every AI you use gets the same profile and the rules it can carry:** Claude Code, Codex, Cursor, Gemini CLI and ChatGPT, rendered from one source and kept in sync.
|
|
6
6
|
|
|
@@ -47,15 +47,16 @@ For ChatGPT, open Settings → Personalization and enable customization. Copy th
|
|
|
47
47
|
|
|
48
48
|
File generation, re-runs and uninstall run in CI on Linux, macOS and Windows; your client's context view confirms loading on your setup.
|
|
49
49
|
|
|
50
|
+
<!-- set:start -->
|
|
50
51
|
## Part of a set
|
|
51
52
|
|
|
52
|
-
Three open-source tools that work on their own and fit together:
|
|
53
|
-
|
|
54
53
|
| Repo | What it gives you |
|
|
55
54
|
|---|---|
|
|
56
|
-
| **agent-personalizer** |
|
|
57
|
-
| [model-orchestrator](https://github.com/aunysillyme/model-orchestrator) | Model router for AI coding agents: routes routine work to cheaper models with routing rules, 8 subagents, hooks and a CLI runner
|
|
58
|
-
| [
|
|
55
|
+
| **agent-personalizer** | AI custom instructions from approved entries: a profile and rules for Claude Code, Codex, Cursor, Gemini CLI and ChatGPT, kept in sync from one source. |
|
|
56
|
+
| [model-orchestrator](https://github.com/aunysillyme/model-orchestrator) | Model router for AI coding agents: routes routine work to cheaper models with routing rules, 8 subagents, hooks and a CLI runner |
|
|
57
|
+
| [repo-build-skill](https://github.com/aunysillyme/repo-build-skill) | Skill pack that teaches your AI to build, release and launch a GitHub repo: stack pick, README, AGENTS.md, llms.txt, repo SEO and AEO, trusted publishing. |
|
|
58
|
+
| [website-build-skill](https://github.com/aunysillyme/website-build-skill) | A skill pack that turns your AI into an expert website builder: current research, design, code, accessibility, speed, SEO and security, alone or as a team. |
|
|
59
|
+
<!-- set:end -->
|
|
59
60
|
|
|
60
61
|
## Choose your setup
|
|
61
62
|
|
|
@@ -63,9 +64,9 @@ The first install asks for a folder if `--dir` is missing, then which AIs you us
|
|
|
63
64
|
|
|
64
65
|
| Level | What you get |
|
|
65
66
|
|---|---|
|
|
66
|
-
| **1. Profile and home files** | The profile, onboarding and
|
|
67
|
+
| **1. Profile and home files** | The profile, onboarding and five core rules for the AIs you pick. |
|
|
67
68
|
| **2. Dynamic docs** | Everything above, plus local notes templates maintained under your writing policy. Cloud notes tools use connector pointers. |
|
|
68
|
-
| **3. Mechanisms** |
|
|
69
|
+
| **3. Mechanisms** | All eleven rules, plus editable rule sources, the renderer, drift check, hook and forbidden-string gate. |
|
|
69
70
|
|
|
70
71
|
For a headless install with defaults:
|
|
71
72
|
|
|
@@ -73,15 +74,25 @@ For a headless install with defaults:
|
|
|
73
74
|
npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --defaults
|
|
74
75
|
```
|
|
75
76
|
|
|
77
|
+
For every project, install one global level-1 profile:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npx agent-personalizer --global --ai claude,agents,gemini --yes
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The source lives in `~/.agent-personalizer/`; marked blocks go to `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md` and `~/.gemini/GEMINI.md`. User text outside the blocks stays byte for byte. `--global` supports those three targets and level 1; it excludes `--dir`. Re-run with `--global`, learn across all projects with `learn --global`, and remove owned global content with `--global --uninstall`. See [global installation](docs/install.md#every-project-with-one-profile).
|
|
84
|
+
|
|
85
|
+
Levels 1 and 2 carry the Core 5: read the profile first, evidence before assertion, output style, act or ask, and ask before it repeats. Level 3 retains all eleven, with each target's existing surface and signature selection.
|
|
86
|
+
|
|
76
87
|
Node 22 or 24 (active LTS) is recommended; 18 or later runs. Published on npm with provenance. [Installation](docs/install.md) covers scripted answers, every flag, notes tools and manual copying.
|
|
77
88
|
|
|
78
|
-
The tool runs locally after `npx` fetches the package. The installer and renderer make no network calls and send no telemetry.
|
|
89
|
+
The tool runs locally after `npx` fetches the package. The installer and renderer make no network calls and send no telemetry. Project writes stay inside the folder you name; global writes use the profile and selected home paths above. Edited source files are preserved and named.
|
|
79
90
|
|
|
80
91
|
## Privacy
|
|
81
92
|
|
|
82
93
|
With your yes, learning reads up to 20 recent sessions kept by your selected Claude Code, Codex or Gemini CLI apps, plus Codex memory notes. It keeps typed messages, drops AI replies and tool output, and saves one local `.agent-personalizer/digest.md` ignored by git. The terminal lists files and counts, never message text. Your AI reads the digest, so its contents go to that provider again, like anything you paste in.
|
|
83
94
|
|
|
84
|
-
Reuse only history you are allowed to share. Past sessions can include other people's details; put their names or other private terms in `check/forbidden.local.txt` before accepting. Check your agreement for work or client accounts. `npx agent-personalizer learn --forget` deletes the digest, and uninstall removes
|
|
95
|
+
Reuse only history you are allowed to share. Past sessions can include other people's details; put their names or other private terms in `check/forbidden.local.txt` before accepting. Check your agreement for work or client accounts. `npx agent-personalizer learn --forget` deletes the digest, and uninstall removes unchanged recorded digest files; both leave your AI apps' history alone. agent-personalizer is not affiliated with Anthropic, OpenAI or Google, and their saved formats can change. See [learning and privacy](docs/learning.md).
|
|
85
96
|
|
|
86
97
|
## Keep it in sync
|
|
87
98
|
|
|
@@ -166,11 +177,11 @@ Re-run `npx agent-personalizer --dir . --ai claude,agents --level 3 --yes --defa
|
|
|
166
177
|
|
|
167
178
|
### How do I uninstall agent-personalizer and keep my notes?
|
|
168
179
|
|
|
169
|
-
Preview with `npx agent-personalizer --uninstall --dir . --dry`, then run `npx agent-personalizer --uninstall --dir .`. Edited files, user-written notes and a `LEARNED.md` with entries stay;
|
|
180
|
+
Preview with `npx agent-personalizer --uninstall --dir . --dry`, then run `npx agent-personalizer --uninstall --dir .`. Edited files, user-written notes and a `LEARNED.md` with entries stay; unchanged recorded digest files are removed and untouched files return byte for byte.
|
|
170
181
|
|
|
171
182
|
## Uninstall
|
|
172
183
|
|
|
173
|
-
Preview with --uninstall --dry. Removal compares recorded install hashes, keeps edited files, notes and a `LEARNED.md` with entries, removes
|
|
184
|
+
Preview with --uninstall --dry. Removal compares recorded install hashes, keeps edited files, notes and a `LEARNED.md` with entries, removes unchanged recorded digest files, and lists any hook registration you must remove.
|
|
174
185
|
|
|
175
186
|
```bash
|
|
176
187
|
npx agent-personalizer --uninstall --dir . --dry
|
package/RELEASING.md
CHANGED
|
@@ -13,10 +13,16 @@ Maintainer notes. Follow the steps below for version sites, rendering, checks an
|
|
|
13
13
|
|
|
14
14
|
**Verify.** `npm view agent-personalizer@X.Y.Z version` prints `X.Y.Z` (query the exact version: the bare `npm view agent-personalizer version` can lag a minute behind the run), and `https://registry.npmjs.org/-/npm/v1/attestations/agent-personalizer@X.Y.Z` returns a Sigstore bundle. In a fresh temp dir, `npx --yes agent-personalizer@X.Y.Z --version` prints the new version.
|
|
15
15
|
|
|
16
|
-
**How `publish.yml` works.** Manual `workflow_dispatch` with the tag as its input, live since 0.4.1. 0.4.0 was published by hand from the tag checkout by a logged-in maintainer (`npm publish --access public`, no provenance is possible from a laptop), because npm only lets a trusted publisher be configured in the settings of a package that already exists. The job resolves the input through `refs/tags/` and checks out that commit by SHA, so a branch with a tag-like name cannot be published; the tag must equal the `package.json` version; it
|
|
16
|
+
**How `publish.yml` works.** Manual `workflow_dispatch` with the tag as its input, live since 0.4.1. 0.4.0 was published by hand from the tag checkout by a logged-in maintainer (`npm publish --access public`, no provenance is possible from a laptop), because npm only lets a trusted publisher be configured in the settings of a package that already exists. The job resolves the input through `refs/tags/` and checks out that commit by SHA, so a branch with a tag-like name cannot be published; the tag must equal the `package.json` version; it runs on Node 24 and fails unless the bundled npm is 11.5.1 or later (the trusted-publishing minimum; no global npm install, since 0.8.4), runs the harness, then `npm publish --provenance --access public` with `id-token: write`. No npm token is stored anywhere. The trusted publisher on npm is GitHub Actions, this repository, workflow file `publish.yml`, direct publish allowed.
|
|
17
17
|
|
|
18
18
|
**Two things GitHub will not tell you.** A workflow file it cannot parse is dropped silently: `gh workflow run` says the workflow has no `workflow_dispatch` trigger, and the workflow list shows the file path where its name should be. It happened here once over an unquoted `: ` in a step name; the harness now parses both workflow files. This guide ships in the tarball so its offline links work. Workflow-only changes can land without a package release.
|
|
19
19
|
|
|
20
20
|
Optional hardening: put the publish job behind a protected GitHub environment with a required reviewer (a repository setting, not a file change).
|
|
21
21
|
|
|
22
|
+
## Shared set rows
|
|
23
|
+
|
|
24
|
+
The README and llms.txt "Part of a set" rows come from https://raw.githubusercontent.com/aunysillyme/.github/HEAD/set.json; each row's line is that package's npm description. Refresh with `npx repo-build-skill@0.1.1 set sync` outside CI and commit the result. Keep `.repo-build/*` and the text between the set markers generated. CI only checks drift offline with `node scripts/check-set.mjs` in the harness job on pushes and pull requests, using the existing Node matrix.
|
|
25
|
+
|
|
26
|
+
The check reads README.md, llms.txt, package.json and the vendored renderer, set file and lock. It renders in memory and compares both SHA-256 hashes with the lock, with no writes or network calls. Exit 0 prints one match line; exit 1 names each drifted file with `SET_DRIFT:` and the refresh command; exit 2 reports a missing or unreadable file, invalid input or bad usage. Run `node test/check-set.test.cjs` to verify clean and seeded-drift copies in temp directories; `--root <dir>` checks another copy. The shared source and generated lock own the rows and hashes; the harness watches them when CI runs, with no separate watcher. Resolve failures by refreshing outside CI and rerunning the check before release.
|
|
27
|
+
|
|
22
28
|
`npx agent-personalizer` is the install path; `npx github:aunysillyme/agent-personalizer` still runs the tag directly.
|
package/SECURITY.md
CHANGED
|
@@ -4,12 +4,14 @@ This is a small local tool: it reads your files, writes files into a folder you
|
|
|
4
4
|
|
|
5
5
|
## Reporting a vulnerability
|
|
6
6
|
|
|
7
|
-
Use GitHub's private vulnerability reporting on this repository (Security tab → "Report a vulnerability"). That opens a private advisory only the maintainer can see. Please do not open a public issue for anything that could let an installer or renderer write outside the folder the user named, read a file it should not, or let `check/forbidden.local.txt` reach a commit.
|
|
7
|
+
Use [GitHub's private vulnerability reporting](https://github.com/aunysillyme/agent-personalizer/security/advisories/new) on this repository (Security tab → "Report a vulnerability"). That opens a private advisory only the maintainer can see. Please do not open a public issue for anything that could let an installer or renderer write outside the folder the user named, read a file it should not, or let `check/forbidden.local.txt` reach a commit.
|
|
8
8
|
|
|
9
9
|
Report a leak of session data through that private route too; describe the reproduction with invented messages and keep real session text out of the report.
|
|
10
10
|
|
|
11
11
|
You will get an acknowledgement within 7 days and a fix or a reasoned "won't fix" within 30. Credit is given in the changelog unless you ask otherwise.
|
|
12
12
|
|
|
13
|
+
Disclosure timeline: allow the 7-day acknowledgement and 30-day fix window before coordinated public disclosure.
|
|
14
|
+
|
|
13
15
|
## Scope
|
|
14
16
|
|
|
15
17
|
In scope: `bin/`, including session reading, learning and removal, `render/`, `check/gate.cjs`, `hooks/`, the templates and the harness. Out of scope: the AI products this repo writes files for, and the companion tools it links to (report those to their own projects).
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const readline = require('readline');
|
|
13
|
-
const
|
|
13
|
+
const { resolveHome } = require('./home.cjs');
|
|
14
14
|
const crypto = require('crypto');
|
|
15
15
|
const { execFileSync } = require('child_process');
|
|
16
16
|
const sha256 = (bytes) => crypto.createHash('sha256').update(bytes).digest('hex');
|
|
@@ -30,12 +30,14 @@ let committing = false;
|
|
|
30
30
|
function die(msg) { if (committing) throw new markers.Refusal(msg); console.error(`agent-personalizer: ${msg}`); process.exit(2); }
|
|
31
31
|
|
|
32
32
|
const VALUE_OPTS = ['--dir', '--ai', '--level', '--answers'];
|
|
33
|
-
const FLAG_OPTS = ['--forget', '--all-projects', '--yes', '--defaults', '--quick', '--full', '--uninstall', '--dry', '--help', '--version', '-h', '-v'];
|
|
33
|
+
const FLAG_OPTS = ['--global', '--forget', '--all-projects', '--yes', '--defaults', '--quick', '--full', '--uninstall', '--dry', '--help', '--version', '-h', '-v'];
|
|
34
34
|
const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).version}
|
|
35
35
|
|
|
36
36
|
npx agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3]
|
|
37
37
|
[--answers <file.json> | --answers - | --defaults] [--full] [--yes]
|
|
38
38
|
[--help | -h] [--version | -v]
|
|
39
|
+
npx agent-personalizer --global [--ai claude,agents,gemini] [--yes]
|
|
40
|
+
npx agent-personalizer --global --uninstall [--dry]
|
|
39
41
|
npx agent-personalizer --uninstall --dir <folder> [--dry]
|
|
40
42
|
|
|
41
43
|
npx agent-personalizer learn [--dir <folder>] [--all-projects] [--yes]
|
|
@@ -43,6 +45,7 @@ const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).vers
|
|
|
43
45
|
|
|
44
46
|
First interactive install: choose your AIs, then choose whether to read your recent sessions.
|
|
45
47
|
Saved installs ask nothing and keep their AIs, level and answers unless you give replacements.
|
|
48
|
+
--global level-1 profile in ~/.agent-personalizer, applied across projects; excludes --dir.
|
|
46
49
|
--full accepted for older commands; the interview is gone.
|
|
47
50
|
--quick accepted for older commands; the interview is gone.
|
|
48
51
|
--answers a JSON file of answers, or "-" to read JSON from stdin. Saved legacy keys stay valid.
|
|
@@ -166,7 +169,88 @@ function resolveDestination(dir) {
|
|
|
166
169
|
return { requested, realExisting, missing, root: path.join(realExisting, ...missing) };
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
|
|
173
|
+
// One transaction for project and global plans: snapshot before writes, replace atomically, restore on failure.
|
|
174
|
+
async function commitPlan(root, { writes, removals = [], outputPaths, prepare, finalize }) {
|
|
175
|
+
for (const rel of outputPaths) {
|
|
176
|
+
let parent = path.posix.dirname(rel);
|
|
177
|
+
while (parent !== '.') {
|
|
178
|
+
if (outputPaths.has(parent)) die(`${parent}: install path is both a file and a directory; nothing was written`);
|
|
179
|
+
parent = path.posix.dirname(parent);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const saved = new Map(), newDirectories = new Set();
|
|
183
|
+
for (const rel of outputPaths) {
|
|
184
|
+
const destination = probe(root, rel);
|
|
185
|
+
if (destination.exists) {
|
|
186
|
+
const info = fs.lstatSync(destination.full);
|
|
187
|
+
if (!info.isFile()) die(`${rel} is not a regular file; nothing was written`);
|
|
188
|
+
saved.set(rel, { bytes: fs.readFileSync(destination.full), mode: info.mode & 0o777, dev: info.dev, ino: info.ino });
|
|
189
|
+
} else saved.set(rel, null);
|
|
190
|
+
let parent = path.posix.dirname(rel);
|
|
191
|
+
while (parent !== '.') {
|
|
192
|
+
if (!probe(root, parent).exists) newDirectories.add(parent);
|
|
193
|
+
parent = path.posix.dirname(parent);
|
|
194
|
+
}
|
|
195
|
+
let ancestor = path.dirname(destination.full);
|
|
196
|
+
while (!fs.existsSync(ancestor)) ancestor = path.dirname(ancestor);
|
|
197
|
+
try { fs.accessSync(ancestor, fs.constants.W_OK); } catch (_) { die(`${rel}: parent is not writable; nothing was written`); }
|
|
198
|
+
}
|
|
199
|
+
if (prepare) prepare(newDirectories);
|
|
200
|
+
const replace = (rel, bytes, mode) => {
|
|
201
|
+
const destination = safeDest(root, rel);
|
|
202
|
+
const tmp = path.join(path.dirname(destination.full), `.${path.basename(rel)}.${crypto.randomBytes(8).toString('hex')}.agent-personalizer.tmp`);
|
|
203
|
+
try {
|
|
204
|
+
fs.writeFileSync(tmp, bytes, { flag: 'wx', ...(mode === undefined ? {} : { mode }) });
|
|
205
|
+
if (mode !== undefined) fs.chmodSync(tmp, mode);
|
|
206
|
+
probe(root, rel);
|
|
207
|
+
fs.renameSync(tmp, destination.full);
|
|
208
|
+
} finally { if (fs.existsSync(tmp)) fs.unlinkSync(tmp); }
|
|
209
|
+
};
|
|
210
|
+
const assertSaved = rel => {
|
|
211
|
+
const destination = probe(root, rel), before = saved.get(rel);
|
|
212
|
+
if (!!before !== destination.exists) die(`${rel} changed during preflight; nothing was written`);
|
|
213
|
+
if (before) {
|
|
214
|
+
const info = fs.lstatSync(destination.full);
|
|
215
|
+
if (info.dev !== before.dev || info.ino !== before.ino || !fs.readFileSync(destination.full).equals(before.bytes)) die(`${rel} changed during preflight; nothing was written`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
committing = true;
|
|
219
|
+
const touched = new Set();
|
|
220
|
+
try {
|
|
221
|
+
for (const rel of outputPaths) assertSaved(rel);
|
|
222
|
+
for (const p of removals) { assertSaved(p.rel); fs.unlinkSync(probe(root, p.rel).full); touched.add(p.rel); if (p.report) console.log(p.report); }
|
|
223
|
+
for (const p of writes) {
|
|
224
|
+
assertSaved(p.rel);
|
|
225
|
+
touched.add(p.rel);
|
|
226
|
+
const mode = p.rel === 'hooks/claude-code/session-start.sh' ? 0o755 : saved.get(p.rel)?.mode;
|
|
227
|
+
replace(p.rel, p.bytes, mode);
|
|
228
|
+
if (p.report) console.log(p.report);
|
|
229
|
+
}
|
|
230
|
+
// Include renderer outputs in rollback even when it committed before reporting a failure.
|
|
231
|
+
for (const rel of outputPaths) touched.add(rel);
|
|
232
|
+
if (finalize) await finalize();
|
|
233
|
+
} catch (e) {
|
|
234
|
+
const incomplete = [];
|
|
235
|
+
for (const rel of [...touched].reverse()) {
|
|
236
|
+
try {
|
|
237
|
+
const before = saved.get(rel), destination = probe(root, rel);
|
|
238
|
+
if (before) replace(rel, before.bytes, before.mode);
|
|
239
|
+
else if (destination.exists) fs.unlinkSync(destination.full);
|
|
240
|
+
} catch (failure) { incomplete.push(`${rel}: ${failure.message}`); }
|
|
241
|
+
}
|
|
242
|
+
for (const rel of [...newDirectories].sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
243
|
+
try { const destination = probe(root, rel); if (destination.exists && fs.readdirSync(destination.full).length === 0) fs.rmdirSync(destination.full); }
|
|
244
|
+
catch (failure) { incomplete.push(`${rel}/: ${failure.message}`); }
|
|
245
|
+
}
|
|
246
|
+
console.error(incomplete.length ? `agent-personalizer: ROLLBACK INCOMPLETE\n${incomplete.join('\n')}` : 'agent-personalizer: install failed; every changed file was restored');
|
|
247
|
+
throw e;
|
|
248
|
+
} finally { committing = false; }
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
169
252
|
async function main() {
|
|
253
|
+
if (ARGS['--global']) return require('./global.cjs').run({ args: ARGS, commitPlan, probe, readConfig, ask });
|
|
170
254
|
if (ARGS.command === 'learn') {
|
|
171
255
|
for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--uninstall', '--dry'])
|
|
172
256
|
if (opt in ARGS) die(`${opt} is not a learn option`);
|
|
@@ -203,8 +287,11 @@ async function main() {
|
|
|
203
287
|
console.log('\nWhich AIs do you use? Comma-separated from:');
|
|
204
288
|
for (const k of AIS) console.log(` ${k.padEnd(8)} ${AI_LABEL[k]}`);
|
|
205
289
|
// Existence is the only inspection of app folders permitted before consent.
|
|
206
|
-
|
|
207
|
-
|
|
290
|
+
let home;
|
|
291
|
+
try { home = resolveHome(); }
|
|
292
|
+
catch (e) { if (!(e instanceof markers.Refusal)) throw e; }
|
|
293
|
+
const found = home ? [['.claude', 'claude'], ['.codex', 'agents'], ['.gemini', 'gemini']]
|
|
294
|
+
.filter(([folder]) => fs.existsSync(path.join(home, folder))).map(([, ai]) => ai) : [];
|
|
208
295
|
ais = await ask('\nAIs', ais || (found.length ? found.join(',') : 'claude,agents'));
|
|
209
296
|
}
|
|
210
297
|
if (!/^[1-4]$/.test(String(level))) die('level must be exactly 1, 2 or 3');
|
|
@@ -279,7 +366,7 @@ async function main() {
|
|
|
279
366
|
const previousBase = prevAnswers ? onboarding.baseFor(prevAnswers) : null;
|
|
280
367
|
const previousNotesExists = previousBase && !!probe(root, `${previousBase}/README.md`).exists;
|
|
281
368
|
const previousNotesScaffolded = prevAnswers && onboarding.kindOf(prevAnswers) !== 'cloud' && ((cfg.level || 1) >= 2 || previousNotesExists);
|
|
282
|
-
const previousPlan = prevAnswers ? installPlan({ answers: prevAnswers, level: Math.min(cfg.level || 1, 3), targets: cfg.targets || [], notesScaffolded: previousNotesScaffolded }).plan : [];
|
|
369
|
+
const previousPlan = prevAnswers ? installPlan({ answers: prevAnswers, level: Math.min(cfg.level || 1, 3), targets: cfg.targets || [], notesScaffolded: previousNotesScaffolded, legacyRules: cfg.ruleSet !== 'core-5' }).plan : [];
|
|
283
370
|
|
|
284
371
|
// ---- PREFLIGHT: refuse now, with nothing written, everything the renderer would refuse later ----
|
|
285
372
|
for (const p of plan) {
|
|
@@ -298,6 +385,12 @@ async function main() {
|
|
|
298
385
|
finally { markers.DIE_THROWS = false; }
|
|
299
386
|
const TARGETS = JSON.parse(fs.readFileSync(path.join(PKG, 'render', 'targets.json'), 'utf8'));
|
|
300
387
|
const preservedTargets = new Set(cfg.preservedTargets || []);
|
|
388
|
+
// A smaller rule set refreshes only an untouched older generated file. Keep an edited
|
|
389
|
+
// older target until the user explicitly re-renders or restores its recorded bytes.
|
|
390
|
+
const keptRuleTargets = new Set();
|
|
391
|
+
const adoptedRuleTargets = new Set();
|
|
392
|
+
const coreUpgrade = cfgExists && effectiveLevel < 3 && cfg.ruleSet !== 'core-5';
|
|
393
|
+
|
|
301
394
|
for (const t of allTargets) {
|
|
302
395
|
const rel = TARGETS[t].file;
|
|
303
396
|
const { full, exists } = probe(root, rel);
|
|
@@ -343,6 +436,27 @@ async function main() {
|
|
|
343
436
|
if (userAction === 'keep' && notesScaffolded && !current.includes(`\`${base}/README.md\``)) staleNotesInUser = true;
|
|
344
437
|
}
|
|
345
438
|
|
|
439
|
+
const profileSource = ['keep', 'conflict'].includes(userAction) ? fs.readFileSync(user.full, 'utf8') : onboarding.renderUser(answers, { notesScaffolded, entries });
|
|
440
|
+
let currentRenders;
|
|
441
|
+
for (const t of allTargets) {
|
|
442
|
+
if (t === 'onboarding' || (!coreUpgrade && !(cfg.keptRuleTargets || []).includes(t))) continue;
|
|
443
|
+
const rel = TARGETS[t].file, destination = probe(root, rel), hash = recordedHash(cfg, rel);
|
|
444
|
+
if (destination.exists && hash && sha256(fs.readFileSync(destination.full)) !== hash) {
|
|
445
|
+
currentRenders ||= markers.renderedContents(root, { ...cfg, targets: allTargets, level: effectiveLevel, ruleSet: 'core-5', onboarding: answers }, { profileSource, learned: entries });
|
|
446
|
+
const current = fs.readFileSync(destination.full, 'utf8');
|
|
447
|
+
if (markers.markerState(current, rel).kind === 'one' && markers.between(current, rel) === currentRenders.find(entry => entry.key === t).block) {
|
|
448
|
+
// Adoption always marks the target preserved, so record the block hash uninstall compares for preserved files.
|
|
449
|
+
installedHashes[rel] = sha256(Buffer.from(markers.between(current, rel)));
|
|
450
|
+
adoptedRuleTargets.add(t);
|
|
451
|
+
preservedTargets.add(t);
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
keptRuleTargets.add(t);
|
|
455
|
+
const quote = value => `'${value.replace(/'/g, "'\\''")}'`;
|
|
456
|
+
console.log(`kept ${rel} (edited older generated file; re-render with: node ${quote(path.join(PKG, 'render/render.cjs'))} --dir ${quote(root)} --targets ${t})`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
346
460
|
// Previous answers identify the exact installer lines to migrate. Each unchanged line is
|
|
347
461
|
// replaced or removed on its own; all other outside-marker bytes stay exactly as read.
|
|
348
462
|
const upgrades = [];
|
|
@@ -351,6 +465,7 @@ async function main() {
|
|
|
351
465
|
return ms.kind === 'one' ? text.slice(0, ms.bStart) + text.slice(ms.eEnd) : text;
|
|
352
466
|
};
|
|
353
467
|
for (const name of ['CLAUDE.md', 'AGENTS.md']) {
|
|
468
|
+
if (keptRuleTargets.has(name === 'CLAUDE.md' ? 'claude' : 'agents') || adoptedRuleTargets.has(name === 'CLAUDE.md' ? 'claude' : 'agents')) continue;
|
|
354
469
|
const prior = previousPlan.find(p => p.rel === name);
|
|
355
470
|
const next = plan.find(p => p.rel === name);
|
|
356
471
|
if (!prior || !next) continue;
|
|
@@ -464,83 +579,17 @@ async function main() {
|
|
|
464
579
|
outputPaths.add(target.file);
|
|
465
580
|
for (const rel of Object.values(target.boxFiles || {})) outputPaths.add(rel);
|
|
466
581
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const destination = probe(root, rel);
|
|
477
|
-
if (destination.exists) {
|
|
478
|
-
const info = fs.lstatSync(destination.full);
|
|
479
|
-
if (!info.isFile()) die(`${rel} is not a regular file; nothing was written`);
|
|
480
|
-
saved.set(rel, { bytes: fs.readFileSync(destination.full), mode: info.mode & 0o777, dev: info.dev, ino: info.ino });
|
|
481
|
-
} else saved.set(rel, null);
|
|
482
|
-
let parent = path.posix.dirname(rel);
|
|
483
|
-
while (parent !== '.') {
|
|
484
|
-
if (!probe(root, parent).exists) newDirectories.add(parent);
|
|
485
|
-
parent = path.posix.dirname(parent);
|
|
486
|
-
}
|
|
487
|
-
let ancestor = path.dirname(destination.full);
|
|
488
|
-
while (!fs.existsSync(ancestor)) ancestor = path.dirname(ancestor);
|
|
489
|
-
try { fs.accessSync(ancestor, fs.constants.W_OK); } catch (_) { die(`${rel}: parent is not writable; nothing was written`); }
|
|
490
|
-
}
|
|
491
|
-
for (const rel of newDirectories) createdDirectories.add(rel);
|
|
492
|
-
cfg = { ...cfg, targets: allTargets, level: installedLevel, onboarding: onboarding.sparse(answers), preservedTargets: [...preservedTargets].filter(t => allTargets.includes(t)), installed: installedHashes, createdDirectories: [...createdDirectories].sort(), toolingVersion, toolingVersions };
|
|
493
|
-
writes.push({ rel: '.agent-personalizer.json', bytes: Buffer.from(JSON.stringify(cfg, null, 2) + '\n'), report: `${cfgExists ? 'update' : 'wrote '} .agent-personalizer.json (onboarding: ${answersSource})` });
|
|
494
|
-
const replace = (rel, bytes, mode) => {
|
|
495
|
-
const destination = safeDest(root, rel);
|
|
496
|
-
const tmp = path.join(path.dirname(destination.full), `.${path.basename(rel)}.${crypto.randomBytes(8).toString('hex')}.agent-personalizer.tmp`);
|
|
497
|
-
try {
|
|
498
|
-
fs.writeFileSync(tmp, bytes, { flag: 'wx', ...(mode === undefined ? {} : { mode }) });
|
|
499
|
-
if (mode !== undefined) fs.chmodSync(tmp, mode);
|
|
500
|
-
probe(root, rel);
|
|
501
|
-
fs.renameSync(tmp, destination.full);
|
|
502
|
-
} finally { if (fs.existsSync(tmp)) fs.unlinkSync(tmp); }
|
|
503
|
-
};
|
|
504
|
-
const assertSaved = rel => {
|
|
505
|
-
const destination = probe(root, rel), before = saved.get(rel);
|
|
506
|
-
if (!!before !== destination.exists) die(`${rel} changed during preflight; nothing was written`);
|
|
507
|
-
if (before) {
|
|
508
|
-
const info = fs.lstatSync(destination.full);
|
|
509
|
-
if (info.dev !== before.dev || info.ino !== before.ino || !fs.readFileSync(destination.full).equals(before.bytes)) die(`${rel} changed during preflight; nothing was written`);
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
committing = true;
|
|
513
|
-
const touched = new Set();
|
|
514
|
-
try {
|
|
515
|
-
for (const rel of outputPaths) assertSaved(rel);
|
|
516
|
-
for (const p of removals) { assertSaved(p.rel); fs.unlinkSync(probe(root, p.rel).full); touched.add(p.rel); console.log(p.report); }
|
|
517
|
-
for (const p of writes) {
|
|
518
|
-
assertSaved(p.rel);
|
|
519
|
-
touched.add(p.rel);
|
|
520
|
-
const mode = p.rel === 'hooks/claude-code/session-start.sh' ? 0o755 : saved.get(p.rel)?.mode;
|
|
521
|
-
replace(p.rel, p.bytes, mode);
|
|
522
|
-
if (p.report) console.log(p.report);
|
|
582
|
+
await commitPlan(root, { writes, removals, outputPaths,
|
|
583
|
+
prepare(newDirectories) {
|
|
584
|
+
for (const rel of newDirectories) createdDirectories.add(rel);
|
|
585
|
+
cfg = { ...cfg, targets: allTargets, level: installedLevel, ruleSet: 'core-5', keptRuleTargets: [...keptRuleTargets], onboarding: onboarding.sparse(answers), preservedTargets: [...preservedTargets].filter(t => allTargets.includes(t)), installed: installedHashes, createdDirectories: [...createdDirectories].sort(), toolingVersion, toolingVersions };
|
|
586
|
+
writes.push({ rel: '.agent-personalizer.json', bytes: Buffer.from(JSON.stringify(cfg, null, 2) + '\n'), report: `${cfgExists ? 'update' : 'wrote '} .agent-personalizer.json (onboarding: ${answersSource})` });
|
|
587
|
+
},
|
|
588
|
+
async finalize() {
|
|
589
|
+
if (learnRequested) await require('./learn.cjs').learn({ dir: root, consented: true });
|
|
590
|
+
execFileSync(process.execPath, [path.join(PKG, 'render', 'render.cjs'), '--dir', root, '--targets', allTargets.filter(t => !keptRuleTargets.has(t) && !adoptedRuleTargets.has(t)).join(',')], { stdio: 'inherit' });
|
|
523
591
|
}
|
|
524
|
-
|
|
525
|
-
for (const rel of outputPaths) touched.add(rel);
|
|
526
|
-
if (learnRequested) await require('./learn.cjs').learn({ dir: root, consented: true });
|
|
527
|
-
execFileSync(process.execPath, [path.join(PKG, 'render', 'render.cjs'), '--dir', root, '--targets', allTargets.join(',')], { stdio: 'inherit' });
|
|
528
|
-
} catch (e) {
|
|
529
|
-
const incomplete = [];
|
|
530
|
-
for (const rel of [...touched].reverse()) {
|
|
531
|
-
try {
|
|
532
|
-
const before = saved.get(rel), destination = probe(root, rel);
|
|
533
|
-
if (before) replace(rel, before.bytes, before.mode);
|
|
534
|
-
else if (destination.exists) fs.unlinkSync(destination.full);
|
|
535
|
-
} catch (failure) { incomplete.push(`${rel}: ${failure.message}`); }
|
|
536
|
-
}
|
|
537
|
-
for (const rel of [...newDirectories].sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
538
|
-
try { const destination = probe(root, rel); if (destination.exists && fs.readdirSync(destination.full).length === 0) fs.rmdirSync(destination.full); }
|
|
539
|
-
catch (failure) { incomplete.push(`${rel}/: ${failure.message}`); }
|
|
540
|
-
}
|
|
541
|
-
console.error(incomplete.length ? `agent-personalizer: ROLLBACK INCOMPLETE\n${incomplete.join('\n')}` : 'agent-personalizer: install failed; every changed file was restored');
|
|
542
|
-
throw e;
|
|
543
|
-
} finally { committing = false; }
|
|
592
|
+
});
|
|
544
593
|
|
|
545
594
|
require('./git-exclude.cjs').protect(root);
|
|
546
595
|
|