agent-personalizer 0.8.6 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ Every entry names the adversarial audit round that produced it where one did. Au
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.9.0] - 2026-11-04
10
+
11
+ ### Added
12
+
13
+ - Add opt-in compact rule rendering and a warn-only instruction file size budget.
14
+ - Add an opt-in level-3 git pre-commit hook for the forbidden-string gate.
15
+
16
+ ## [0.8.7] - 2026-11-03
17
+
18
+ ### Changed
19
+
20
+ - Name Hermes Agent among the supported AIs in the package description, README, llms.txt, the skill description and the project page.
21
+
9
22
  ## [0.8.6] - 2026-11-03
10
23
 
11
24
  ### Added
@@ -353,7 +366,9 @@ Thirteen issues (#3 to #15) filed against `5972b32` by an independent installati
353
366
  - Installer: safe destination resolution, strict options, duplicate `--ai` refused, `--dir` created one level at a time.
354
367
  - Harness: exact exit codes, adversarial fixtures, fault injection for the rollback path.
355
368
 
356
- [Unreleased]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.6...HEAD
369
+ [Unreleased]: https://github.com/aunysillyme/agent-personalizer/compare/v0.9.0...HEAD
370
+ [0.9.0]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.7...v0.9.0
371
+ [0.8.7]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.6...v0.8.7
357
372
  [0.8.6]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.5...v0.8.6
358
373
  [0.8.5]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.4...v0.8.5
359
374
  [0.8.4]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.3...v0.8.4
package/CONTRIBUTING.md CHANGED
@@ -10,7 +10,7 @@ Contributions are welcome: a **new AI target**, a **notes tool**, an **example u
10
10
  ## Running the checks
11
11
 
12
12
  ```bash
13
- npm test # sh test/run.sh: 99 checks, exact exit codes, Linux and macOS
13
+ npm test # sh test/run.sh: 101 checks, exact exit codes, Linux and macOS
14
14
  node test/rollback.test.js "$(mktemp -d)" # after copying examples/freelance-illustrator into it
15
15
  node check/gate.cjs --self-test
16
16
  ```
package/README.md CHANGED
@@ -2,7 +2,7 @@
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) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/aunysillyme/agent-personalizer/badge)](https://scorecard.dev/viewer/?uri=github.com/aunysillyme/agent-personalizer)
4
4
 
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.
5
+ **Every AI you use gets the same profile and the rules it can carry:** Claude Code, Codex, Cursor, Gemini CLI, Hermes Agent 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 and fade over a long chat.
8
8
 
@@ -213,7 +213,7 @@ Contributions are welcome: a new AI target, a notes tool, an example user, or a
213
213
 
214
214
  Pull requests are accepted under the [contributor license agreement](CLA.md); the checkbox in the pull request template records your agreement.
215
215
 
216
- The harness (`test/run.sh: 99 checks`) tests exact exit codes and adversarial fixtures. The real forbidden-list check stays local and prints a skip when the private list is absent.
216
+ The harness (`test/run.sh: 101 checks`) tests exact exit codes and adversarial fixtures. The real forbidden-list check stays local and prints a skip when the private list is absent.
217
217
 
218
218
  ## License
219
219
 
package/SECURITY.md CHANGED
@@ -18,4 +18,4 @@ In scope: `bin/`, including session reading, learning and removal, `render/`, `c
18
18
 
19
19
  ## What is already done
20
20
 
21
- Every release passes an adversarial read-only audit (see `CHANGELOG.md`, each entry names its round) and a 99-check harness with exact exit codes, on Linux and macOS in CI. The deferred residuals are stated in the code headers: TOCTOU between check and write, unicode look-alikes in the gate, the named `--dir` being followed once via realpath, and a hard process kill between two renames. On Windows, `O_NOFOLLOW` is unavailable to the flag the uninstaller opens tracked files with; nothing depends on it there, because the delete loop re-probes every path with `lstat` immediately before each unlink, so no destructive path exists without it.
21
+ Every release passes an adversarial read-only audit (see `CHANGELOG.md`, each entry names its round) and a 101-check harness with exact exit codes, on Linux and macOS in CI. The deferred residuals are stated in the code headers: TOCTOU between check and write, unicode look-alikes in the gate, the named `--dir` being followed once via realpath, and a hard process kill between two renames. On Windows, `O_NOFOLLOW` is unavailable to the flag the uninstaller opens tracked files with; nothing depends on it there, because the delete loop re-probes every path with `lstat` immediately before each unlink, so no destructive path exists without it.
@@ -30,7 +30,7 @@ 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 = ['--global', '--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', '--compact', '--precommit', '--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]
@@ -52,9 +52,11 @@ const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).vers
52
52
  --answers a JSON file of answers, or "-" to read JSON from stdin. Saved legacy keys stay valid.
53
53
  --defaults accept defaults on first install; a re-run keeps saved answers.
54
54
  --yes scripted first install: needs --dir, --ai and --level. Never reads session history.
55
+ --compact shorten non-injected rules in file targets; save this preference for re-renders.
55
56
  learn with your yes, write a local digest for up to five evidence-backed questions.
56
57
  --all-projects include sessions from projects other than --dir; default reads only --dir.
57
58
  --forget with learn, remove the digest; your AI apps' own history stays as it is.
59
+ --precommit install the level-3 forbidden-string gate as a git pre-commit hook.
58
60
  --uninstall remove unchanged installed files; keep edited files and LEARNED.md with entries.
59
61
  --dry preview --uninstall without changing files.
60
62
  Levels: 1 profile, onboarding and home file(s); nothing else (the rules render from the package)
@@ -149,6 +151,7 @@ function readConfig(root, level) {
149
151
  if (new Set(cfg.targets).size !== cfg.targets.length) die('.agent-personalizer.json lists a target twice');
150
152
  }
151
153
  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)})`);
154
+ if ('compact' in cfg && typeof cfg.compact !== 'boolean') die('.agent-personalizer.json "compact" must be true or false');
152
155
  try { validateInventory(cfg); } catch (e) { die(`.agent-personalizer.json: ${e.message}; nothing was written`); }
153
156
  markers.DIE_THROWS = true;
154
157
  try { markers.validatePreservedTargets(cfg); }
@@ -251,10 +254,11 @@ async function commitPlan(root, { writes, removals = [], outputPaths, prepare, f
251
254
  }
252
255
 
253
256
  async function main() {
257
+ if (ARGS['--global'] && ARGS['--precommit']) die('--precommit needs a level 3 project install');
254
258
  if (ARGS['--global']) return require('./global.cjs').run({ args: ARGS, commitPlan, probe, readConfig, ask });
255
259
  if (ARGS['--ai'] && ARGS['--ai'].split(',').some(t => t.trim() === 'hermes')) die('Hermes reads AGENTS.md inside a project; use --ai agents (or --global --ai hermes for every Hermes session).');
256
260
  if (ARGS.command === 'learn') {
257
- for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--uninstall', '--dry'])
261
+ for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--compact', '--precommit', '--uninstall', '--dry'])
258
262
  if (opt in ARGS) die(`${opt} is not a learn option`);
259
263
  if (ARGS['--forget'] && ARGS['--all-projects']) die('--all-projects cannot be used with --forget');
260
264
  if (ARGS['--forget'] && ARGS['--yes']) die('--forget and --yes are exclusive');
@@ -265,7 +269,7 @@ async function main() {
265
269
  if (ARGS['--all-projects']) die('--all-projects needs learn');
266
270
  if (ARGS['--uninstall']) {
267
271
  if (!ARGS['--dir']) die('--uninstall needs --dir <folder>');
268
- for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full'])
272
+ for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--compact', '--precommit'])
269
273
  if (opt in ARGS) die(`${opt} is an install option; --uninstall reads the stored config`);
270
274
  return require('./uninstall.cjs').uninstall(ARGS['--dir'], { dry: !!ARGS['--dry'] });
271
275
  }
@@ -298,6 +302,8 @@ async function main() {
298
302
  }
299
303
  if (!/^[1-4]$/.test(String(level))) die('level must be 1, 2 or 3 (4 is accepted as 3)');
300
304
  level = Number(level);
305
+ const precommitEnabled = !!ARGS['--precommit'] || !!stored.cfg.precommit;
306
+ if (precommitEnabled && level < 3) die('--precommit requires level 3');
301
307
  if (level === 4) console.log('note: --level 4 installs exactly what --level 3 installs. For model routing, see https://github.com/aunysillyme/model-orchestrator');
302
308
  const targets = String(ais || '').split(',').map(s => s.trim()).filter(Boolean);
303
309
  const bad = targets.filter(t => !AIS.includes(t));
@@ -337,6 +343,11 @@ async function main() {
337
343
  if (prevAnswers && !answersFile && answersSource.startsWith('defaults')) {
338
344
  answers = prevAnswers; answersSource = 'kept from .agent-personalizer.json';
339
345
  }
346
+ let hookPlan;
347
+ if (precommitEnabled) {
348
+ try { hookPlan = require('./precommit.cjs').plan(root, cfg.precommit || null); }
349
+ catch (e) { if (e instanceof markers.Refusal) die(e.message); throw e; }
350
+ }
340
351
  const allTargets = [...new Set([...targets, 'onboarding'])];
341
352
  const installedLevel = level;
342
353
  const effectiveLevel = Math.min(installedLevel, 3);
@@ -584,12 +595,14 @@ async function main() {
584
595
  await commitPlan(root, { writes, removals, outputPaths,
585
596
  prepare(newDirectories) {
586
597
  for (const rel of newDirectories) createdDirectories.add(rel);
587
- 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 };
598
+ cfg = { ...cfg, ...(hookPlan ? { precommit: hookPlan.saved } : {}), 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 };
599
+ if (ARGS['--compact']) cfg.compact = true;
588
600
  writes.push({ rel: '.agent-personalizer.json', bytes: Buffer.from(JSON.stringify(cfg, null, 2) + '\n'), report: `${cfgExists ? 'update' : 'wrote '} .agent-personalizer.json (onboarding: ${answersSource})` });
589
601
  },
590
602
  async finalize() {
591
603
  if (learnRequested) await require('./learn.cjs').learn({ dir: root, consented: true });
592
604
  execFileSync(process.execPath, [path.join(PKG, 'render', 'render.cjs'), '--dir', root, '--targets', allTargets.filter(t => !keptRuleTargets.has(t) && !adoptedRuleTargets.has(t)).join(',')], { stdio: 'inherit' });
605
+ if (hookPlan) require('./precommit.cjs').install(hookPlan);
593
606
  }
594
607
  });
595
608
 
package/bin/global.cjs CHANGED
@@ -51,7 +51,7 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
51
51
  const stored = readConfig(profileRoot, 1);
52
52
  if (stored.cfgExists) validateGlobal(stored.cfg);
53
53
  if (args.command === 'learn') {
54
- for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--uninstall', '--dry']) if (opt in args) refuse(`${opt} is not a learn option`);
54
+ for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--compact', '--uninstall', '--dry']) if (opt in args) refuse(`${opt} is not a learn option`);
55
55
  if (args['--forget'] && (args['--all-projects'] || args['--yes'])) refuse('--forget cannot be combined with --all-projects or --yes');
56
56
  if (!stored.cfgExists) refuse(`missing config: expected ${path.join(root, CONFIG)}`);
57
57
  const learning = require('./learn.cjs');
@@ -59,7 +59,7 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
59
59
  }
60
60
  if (args['--forget'] || args['--all-projects']) refuse('--forget and --all-projects need learn');
61
61
  if (args['--uninstall']) {
62
- for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full']) if (opt in args) refuse(`${opt} is an install option; --uninstall reads the stored config`);
62
+ for (const opt of ['--ai', '--level', '--answers', '--defaults', '--quick', '--full', '--compact']) if (opt in args) refuse(`${opt} is an install option; --uninstall reads the stored config`);
63
63
  if (!stored.cfgExists) refuse(`missing config: expected ${path.join(root, CONFIG)}`);
64
64
  return uninstall({ root, cfg: stored.cfg, dry: !!args['--dry'], commitPlan, probe });
65
65
  }
@@ -110,6 +110,7 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
110
110
  if (!learnedBytes) writeSource('LEARNED.md', plannedLearned, true);
111
111
  const cfg = { ...old, global: true, targets: [...targets, 'onboarding'], level: 1, ruleSet: 'core-5', onboarding: onboarding.sparse(answers), installed,
112
112
  createdDirectories: old.createdDirectories || [], globalFiles: { ...(old.globalFiles || {}) }, toolingVersion: require('../package.json').version };
113
+ if (args['--compact']) cfg.compact = true;
113
114
  const renderCfg = { ...cfg, onboarding: answers };
114
115
  const rendered = renderer.renderedContents(profileRoot, renderCfg, { profileSource: decode(user, 'USER.md'), learned });
115
116
  const qualify = text => text
@@ -129,6 +130,7 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
129
130
  }
130
131
  const block = `Profile source: \`${path.join(profileRoot, 'USER.md')}\`. Read \`${path.join(profileRoot, 'AGENT_ONBOARDING.md')}\` for working preferences.\n\n` + qualify(entry.block);
131
132
  const output = renderer.splice(text, block, rel);
133
+ if (output.length > renderer.FILE_BUDGET) console.log(`OVER BUDGET ${rel} (${output.length} characters, budget ${renderer.FILE_BUDGET}; --compact shortens rules)`);
132
134
  if (renderer.markerState(output, rel).kind !== 'one' || renderer.between(output, rel) !== block) refuse(`${rel}: generated block would not re-parse; nothing was written`);
133
135
  const prior = ms.kind === 'one' ? cfg.globalFiles[entry.key] : null;
134
136
  cfg.globalFiles[entry.key] = { created: !found.exists || !!cfg.globalFiles[entry.key]?.created, blockHash: blockHash(output, rel), fileHash: sha256(Buffer.from(output)),
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const crypto = require('crypto');
5
+ const { execFileSync } = require('child_process');
6
+ const { Refusal } = require('../render/render.cjs');
7
+ const hash = bytes => crypto.createHash('sha256').update(bytes).digest('hex');
8
+ function refuse(message) { throw new Refusal(message); }
9
+ function inside(base, file) { const rel = path.relative(base, file); return rel === '' || (!rel.startsWith('..' + path.sep) && rel !== '..' && !path.isAbsolute(rel)); }
10
+ function inspect(file, directory = false) {
11
+ let st;
12
+ try { st = fs.lstatSync(file); } catch (e) { if (e.code === 'ENOENT') return null; throw e; }
13
+ if (st.isSymbolicLink()) refuse(`${file} is a symlink; nothing was changed`);
14
+ if (directory ? !st.isDirectory() : !st.isFile()) refuse(`${file} is not a regular ${directory ? 'directory' : 'file'}; nothing was changed`);
15
+ return st;
16
+ }
17
+ function location(root) {
18
+ const git = args => execFileSync('git', ['-C', root, 'rev-parse', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
19
+ let hooks, gitdir, common, worktree;
20
+ try {
21
+ worktree = fs.realpathSync(git(['--show-toplevel']));
22
+ gitdir = path.resolve(root, git(['--absolute-git-dir']));
23
+ common = path.resolve(root, git(['--git-common-dir']));
24
+ hooks = path.resolve(root, git(['--git-path', 'hooks']));
25
+ } catch (_) { refuse('--precommit needs a git work tree'); }
26
+ const dotgit = path.join(worktree, '.git');
27
+ const dotgitStat = fs.lstatSync(dotgit);
28
+ if (dotgitStat.isSymbolicLink()) refuse(`${dotgit} is a symlink; nothing was changed`);
29
+ if (![worktree, gitdir, common].some(base => inside(base, hooks))) refuse('pre-commit hook would land in a shared hooks folder; configure a project-local hooks path');
30
+ // Inspect each existing component from a trusted boundary, including the hooks directory.
31
+ const base = [worktree, gitdir, common].filter(b => inside(b, hooks)).sort((a, b) => b.length - a.length)[0];
32
+ let cur = base;
33
+ inspect(cur, true);
34
+ for (const part of path.relative(base, hooks).split(path.sep).filter(Boolean)) { cur = path.join(cur, part); if (!inspect(cur, true)) break; }
35
+ return { hooks, hook: path.join(hooks, 'pre-commit'), original: path.join(hooks, 'pre-commit.agent-personalizer-original') };
36
+ }
37
+ function quote(s) { return `'${s.replace(/'/g, "'\\''")}'`; }
38
+ function plan(root, saved) {
39
+ const loc = location(root), hookStat = inspect(loc.hook), originalStat = inspect(loc.original);
40
+ const current = hookStat && fs.readFileSync(loc.hook);
41
+ const original = originalStat && fs.readFileSync(loc.original);
42
+ if (saved) {
43
+ if (typeof saved.wrapperHash !== 'string' || !(saved.originalHash === null || typeof saved.originalHash === 'string')) refuse('invalid pre-commit ownership record');
44
+ if (!current || !(hookStat.mode & 0o111) || hash(current) !== saved.wrapperHash) refuse(`${loc.hook} was edited or removed; restore it by hand before continuing`);
45
+ if ((saved.originalHash === null && original) || (saved.originalHash !== null && (!original || hash(original) !== saved.originalHash))) refuse(`${loc.original} was edited or removed; restore the original hook by hand`);
46
+ return { ...loc, root, saved, noop: true };
47
+ }
48
+ if (original) refuse(`${loc.original} already exists; nothing was changed`);
49
+ if (current && /agent-personalizer:(?:begin|end)/.test(current.toString('utf8'))) refuse(`${loc.hook} contains an unowned or malformed agent-personalizer marker; nothing was changed`);
50
+ const bytes = Buffer.from(`#!/bin/sh\n# >>> agent-personalizer:begin\nnode ${quote(path.join(root, 'check/gate.cjs'))} --dir ${quote(root)}\nstatus=$?\n[ "$status" -eq 0 ] || exit "$status"\nif [ -f ${quote(loc.original)} ]; then\n exec ${quote(loc.original)} "$@"\nfi\n# <<< agent-personalizer:end\n`);
51
+ return { ...loc, root, bytes, hookStat, current, saved: { wrapperHash: hash(bytes), originalHash: current ? hash(current) : null } };
52
+ }
53
+ function install(p) {
54
+ const now = location(p.root);
55
+ if (now.hooks !== p.hooks) refuse('hooks path changed during installation');
56
+ if (p.noop) { plan(p.root, p.saved); return; }
57
+ fs.mkdirSync(p.hooks, { recursive: true });
58
+ if (!!inspect(p.hook) !== !!p.current || (p.current && !fs.readFileSync(p.hook).equals(p.current))) refuse(`${p.hook} changed during installation`);
59
+ if (inspect(p.original)) refuse(`${p.original} appeared during installation`);
60
+ let moved = false, created = false, fd;
61
+ try {
62
+ if (p.current) { fs.renameSync(p.hook, p.original); moved = true; }
63
+ fd = fs.openSync(p.hook, 'wx', 0o755); created = true;
64
+ fs.writeFileSync(fd, p.bytes);
65
+ fs.fchmodSync(fd, 0o755);
66
+ fs.closeSync(fd); fd = undefined;
67
+ } catch (e) {
68
+ if (fd !== undefined) fs.closeSync(fd);
69
+ if (created) fs.unlinkSync(p.hook);
70
+ if (moved) {
71
+ if (fs.existsSync(p.hook)) refuse(`${p.hook} appeared during installation; restore ${p.original} by hand`);
72
+ fs.renameSync(p.original, p.hook);
73
+ }
74
+ throw e;
75
+ }
76
+ }
77
+ function remove(p, dry) {
78
+ if (dry) { console.log(`would remove ${p.hook} and restore the original hook if present`); return; }
79
+ // Revalidate the snapshot before changing either file.
80
+ const current = plan(path.resolve(p.root), p.saved);
81
+ const wrapper = fs.readFileSync(current.hook), mode = fs.lstatSync(current.hook).mode & 0o777;
82
+ fs.unlinkSync(current.hook);
83
+ try { if (current.saved.originalHash !== null) fs.renameSync(current.original, current.hook); }
84
+ catch (e) { fs.writeFileSync(current.hook, wrapper, { flag: 'wx', mode }); fs.chmodSync(current.hook, mode); throw e; }
85
+ console.log(`removed ${current.hook} wrapper${current.saved.originalHash !== null ? '; restored original hook' : ''}`);
86
+ }
87
+ module.exports = { plan, install, remove };
package/bin/uninstall.cjs CHANGED
@@ -84,6 +84,7 @@ function run(dir, dry) {
84
84
  if (!Array.isArray(cfg.targets) || !cfg.targets.length || !cfg.onboarding || !Number.isInteger(cfg.level))
85
85
  refuse(`${CONFIG} needs stored targets, level and onboarding answers for --uninstall`);
86
86
  try { validateInventory(cfg); } catch (e) { refuse(`${CONFIG}: ${e.message}; nothing was removed`); }
87
+ const hookPlan = cfg.precommit ? { ...require('./precommit.cjs').plan(root, cfg.precommit), root } : null;
87
88
  const modern = Object.hasOwn(cfg, 'installed');
88
89
  const answers = cfg.onboarding;
89
90
  const level = Math.min(cfg.level, 3);
@@ -257,6 +258,7 @@ function run(dir, dry) {
257
258
  try { fs.accessSync(path.dirname(path.join(root, rel)), fs.constants.W_OK); }
258
259
  catch (_) { refuse(`${rel}: parent directory is not writable; nothing was removed`); }
259
260
  }
261
+ if (hookPlan) require('./precommit.cjs').remove(hookPlan, dry);
260
262
  const label = dry ? 'would ' : '';
261
263
  if (dry) console.log('Dry run: preview only; no files changed.');
262
264
  if (learned && !learnedUntouched) console.log('kept LEARNED.md (your entries)');
@@ -297,7 +299,15 @@ function run(dir, dry) {
297
299
  }
298
300
  console.log(`${label}remove ${CONFIG}`);
299
301
  require('./git-exclude.cjs').unprotect(root, { dry });
300
- } else console.log(`kept ${CONFIG} (tracked files remain; review the kept paths above)`);
302
+ } else {
303
+ if (hookPlan && !dry) {
304
+ const full = probe(CONFIG);
305
+ if (!full || !fs.readFileSync(full).equals(observations.get(CONFIG).bytes)) refuse(`${CONFIG} changed; update it by hand`);
306
+ delete cfg.precommit;
307
+ fs.writeFileSync(full, JSON.stringify(cfg, null, 2) + '\n');
308
+ }
309
+ console.log(`kept ${CONFIG} (tracked files remain; review the kept paths above)`);
310
+ }
301
311
  if (level >= 3) console.log('Manual step: remove any SessionStart entry for hooks/claude-code/session-start.sh from .claude/settings.json or ~/.claude/settings.json if you registered it. Settings are kept.');
302
312
  }
303
313
 
package/check/gate.cjs CHANGED
@@ -100,7 +100,7 @@ function refuseTrackedList(file) {
100
100
  function loadList(file, { allowEmpty = false } = {}) {
101
101
  let st = null;
102
102
  try { st = fs.lstatSync(file); } catch (_) { st = null; }
103
- if (!st) die(`${file} not found.\nCopy check/forbidden.example.txt to that path and fill it in. The gate does not pass without it.`);
103
+ if (!st) die(`${file} not found. Copy check/forbidden.example.txt to that path and fill it in; see docs/guarantees.md#forbidden-string-gate.`);
104
104
  if (st.isSymbolicLink()) die(`${file} is a symlink; the list must be a regular file (a link can point at a tracked copy)`);
105
105
  if (!st.isFile()) die(`${file} is not a regular file`);
106
106
  const real = fs.realpathSync(file); // the REAL path: an alias through a symlinked directory must not hide the repository that tracks it
@@ -117,7 +117,7 @@ function loadList(file, { allowEmpty = false } = {}) {
117
117
  allow.push(a);
118
118
  } else terms.push(line);
119
119
  });
120
- if (!terms.length && !allowEmpty) die('forbidden list has no terms.');
120
+ if (!terms.length && !allowEmpty) die(`${file} has no terms. Fill it in; see docs/guarantees.md#forbidden-string-gate.`);
121
121
  return { terms, allow, real };
122
122
  }
123
123
 
@@ -61,6 +61,8 @@ The gate checks listed strings against file text and relative paths. In a git wo
61
61
  - **Exit `1`:** one or more listed strings were found.
62
62
  - **Exit `2`:** setup was refused, including a missing, empty or tracked private list.
63
63
 
64
+ At level 3, install with `--precommit` to run this gate before each git commit. A missing or empty list blocks the commit and names the setup path. The hook runs before any existing pre-commit hook, which is preserved as `pre-commit.agent-personalizer-original` and restored on uninstall if unchanged. Edited wrappers or originals require manual restoration. Shared hooks folders and symlinks are refused. Git can bypass hooks with `--no-verify`; run the gate separately when needed.
65
+
64
66
  Keep the list current. Review binaries, git history and personal terms outside that list separately; the gate checks the listed strings in the files it scans. Use `node check/gate.cjs --self-test` to verify detection with a seeded fixture.
65
67
 
66
68
  ## Session privacy
package/docs/install.md CHANGED
@@ -67,7 +67,9 @@ Use [`examples/answers.json`](../examples/answers.json) as a complete example, i
67
67
  | `--dir <folder>` | Destination folder; prompted in interactive mode. |
68
68
  | `--global` | Apply a level-1 profile across projects through Claude Code, Codex, Gemini CLI and Hermes Agent home files. Excludes `--dir` and levels 2/3. |
69
69
  | `--ai claude,agents,gemini,chatgpt,prompt` | Comma-separated targets. Choose the ones you use. |
70
+ | `--precommit` | Opt in to the git pre-commit gate at level 3; saved for later runs. |
70
71
  | `--level 1`, `--level 2`, `--level 3` | Profile and home files; add local notes; add editable rules and mechanisms. |
72
+ | `--compact` | Save compact rule rendering for file targets. See [compact mode and the file budget](tiers.md#compact-mode-and-file-budget). |
71
73
  | `--answers <file.json>` or `--answers -` | Set onboarding answers without questions. |
72
74
  | `--defaults` | Accept default answers. |
73
75
  | `--yes` | Run without interactive prompts. |
@@ -142,7 +144,7 @@ node render/render.cjs --dir .
142
144
  node render/render.cjs --dir . --check
143
145
  ```
144
146
 
145
- The check returns `0` silently for current files, `1` for drift, and `2` for invalid inputs. `--targets claude,agents` selects specific renders; `--rules <folder>` selects a rule source. `--strict` returns `1` and writes nothing when a ChatGPT box is over the configured budget. Run `node render/render.cjs --help` for contract and target options.
147
+ The check returns `0` for current files, `1` for drift, and `2` for invalid inputs. It reports files over budget even when current. `--targets claude,agents` selects specific renders; `--rules <folder>` selects a rule source. `--compact` saves compact rendering on a write. `--strict` returns `1` and writes nothing when a ChatGPT box or instruction file is over budget. Run `node render/render.cjs --help` for contract and target options.
146
148
 
147
149
  Re-paste changed text into chat apps. In ChatGPT, open Settings → Personalization and enable customization. Copy `chatgpt-box1.txt` (profile) and `chatgpt-box2.txt` (response instructions) into the fields your current interface provides, checking its displayed limits. See the [paste guide](paste-guide.md) for the files each app needs.
148
150
 
package/docs/tiers.md CHANGED
@@ -43,6 +43,14 @@ A word on the stories below: each is one setup's experience of what held and wha
43
43
 
44
44
  ---
45
45
 
46
+ ## Compact mode and file budget
47
+
48
+ Use `--compact` on the installer or renderer to save `compact: true` in `.agent-personalizer.json`. Re-renders and `--check` use that preference. Set it to `false` to return to full rules. For Claude, agents, Gemini and Hermes file targets, each non-injected rule becomes its title, universal `In practice:` line and a link to the full rule. Levels 1 and 2 link to the version-pinned public rule; level 3 links to the editable local rule. Rules marked `inject: true` stay in full. ChatGPT and prompt targets are unchanged. A custom rule needs an `In practice:` line for compact mode.
49
+
50
+ The four file targets have a 20,000-character warning budget for the whole rendered file, including text outside the generated block. Hermes may truncate context files above roughly that size. A warning leaves the file intact and exits 0; renderer `--strict` exits 1 and writes nothing when a file or ChatGPT box exceeds its budget.
51
+
52
+ ---
53
+
46
54
  ## Tier 3: session-start injection
47
55
 
48
56
  **What.** The handful of rules that must win at the moment of decision, injected in full at the start of every session. Not pointers. Full text.
@@ -52,6 +52,6 @@
52
52
  "installed": {
53
53
  "CLAUDE.md": "4a303e42182c9affef6bcf14cd77045fae24f02ff8f1fef7e1f84e8c03aef2f2",
54
54
  "AGENTS.md": "9cfedced547c961885e57814e3bc2f9122e16bfda2da0e5901dd61f3cf3f3bec",
55
- "AGENT_ONBOARDING.md": "8921de612c1b03c2fd5420fa7fa9928598b5f9c5398ae44e19ff07fd0af01e5d"
55
+ "AGENT_ONBOARDING.md": "ee4fc9f7711e0a0db261501dea9161e94a015cc4faedcb83a04867da5eca134a"
56
56
  }
57
57
  }
@@ -34,7 +34,7 @@ _Generated by agent-personalizer from your saved preferences (stored in `.agent-
34
34
 
35
35
  ### Where you may write
36
36
 
37
- - **Notes live in Obsidian:** reach them as the vault at `notes/`, through **obsidian-tc** (governed MCP: folder ACLs, human-in-the-loop confirmation for destructive tools, audit log) rather than raw filesystem access; see https://github.com/aunysillyme/agent-personalizer/blob/v0.8.6/docs/companions.md.
37
+ - **Notes live in Obsidian:** reach them as the vault at `notes/`, through **obsidian-tc** (governed MCP: folder ACLs, human-in-the-loop confirmation for destructive tools, audit log) rather than raw filesystem access; see https://github.com/aunysillyme/agent-personalizer/blob/v0.9.0/docs/companions.md.
38
38
  - You may create and edit files anywhere under `notes/`, under that folder's rules. Nowhere else without being asked.
39
39
  - **Every folder you write into has a README.** Any write, edit or delete means that README is corrected in the same pass: the file's one-line description, the folder's status, settled decisions, next steps. A stale index is worse than none, because the next agent believes it.
40
40
  - **Session log:** append a dated section to this week's note in `notes/sessions/`. **Decisions:** one line each in `notes/decisions.md`. **Inbox:** one file per item in `notes/inbox/`; finished items are deleted, not marked done.
package/hooks/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # hooks/
2
2
 
3
- Tier 3 from the tiers doc (https://github.com/aunysillyme/agent-personalizer/blob/v0.8.6/docs/tiers.md): the few rules that must be in context at the moment of decision, injected in full at the start of every session. Injection puts the text in front of the model; whether the model follows it is up to the model and the host. This is the strongest placement available, not a guarantee.
3
+ Tier 3 from the tiers doc (https://github.com/aunysillyme/agent-personalizer/blob/v0.9.0/docs/tiers.md): the few rules that must be in context at the moment of decision, injected in full at the start of every session. Injection puts the text in front of the model; whether the model follows it is up to the model and the host. This is the strongest placement available, not a guarantee.
4
4
 
5
5
  Which rules? The ones with `inject: true` in their frontmatter. Keep that set small. Every injected rule costs tokens every session.
6
6
 
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # agent-personalizer
2
2
 
3
- > Answer a few questions once, and 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.
3
+ > Answer a few questions once, and every AI you use gets the same profile and the rules it can carry: Claude Code, Codex, Cursor, Gemini CLI, Hermes Agent and ChatGPT, rendered from one source and kept in sync.
4
4
 
5
5
  Install with `npx agent-personalizer`. Node 22 or 24 (active LTS) is recommended; 18 or later runs. Headless setup: `npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --defaults`.
6
6
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-personalizer",
3
- "version": "0.8.6",
4
- "description": "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.",
3
+ "version": "0.9.0",
4
+ "description": "AI custom instructions from approved entries: a profile and rules for Claude Code, Codex, Cursor, Gemini CLI, Hermes Agent and ChatGPT, kept in sync from one source.",
5
5
  "author": "aunysillyme (https://github.com/aunysillyme)",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/aunysillyme",
@@ -17,7 +17,7 @@
17
17
  DOCS points at the matching tag on GitHub so an installed copy never links to a file the
18
18
  destination does not have.
19
19
  */
20
- const VERSION = '0.8.6';
20
+ const VERSION = '0.9.0';
21
21
  const DOCS = `https://github.com/aunysillyme/agent-personalizer/blob/v${VERSION}/docs`;
22
22
 
23
23
  /* THE single source for notes tools. Add a tool here and nowhere else: the saved choice option, the
package/render/render.cjs CHANGED
@@ -12,7 +12,8 @@
12
12
  or this repo), else the rules/ folder beside this renderer's own package (a level-1
13
13
  or level-2 install renders from the package's rules and copies none). Refused if
14
14
  neither exists.
15
- --strict with the ChatGPT target: exit 1 and write nothing when a box is over its budget.
15
+ --strict exit 1 and write nothing when an output is over its budget.
16
+ --compact shorten non-injected rules in file targets and save the preference.
16
17
 
17
18
  --dir project folder holding USER.md and rules/ (default: cwd). The folder you
18
19
  name is followed once (realpath); nothing beneath it may be a symlink.
@@ -87,7 +88,9 @@ const CORE_RULE_FILES = new Set(['00-read-the-profile-first.md', '10-evidence-be
87
88
 
88
89
 
89
90
  const VALUE_OPTS = ['--dir', '--targets', '--contract-target', '--rules'];
90
- const FLAG_OPTS = ['--check', '--contract', '--no-personal', '--strict', '--help', '-h', '--version', '-v'];
91
+ const FLAG_OPTS = ['--check', '--contract', '--no-personal', '--strict', '--compact', '--help', '-h', '--version', '-v'];
92
+ const FILE_TARGETS = new Set(['claude', 'agents', 'gemini', 'hermes']);
93
+ const FILE_BUDGET = 20000;
91
94
  /* Parse argv once, strictly: value options at most once each, flags at most once, nothing unknown. */
92
95
  function parseArgs() {
93
96
  const out = {};
@@ -232,6 +235,7 @@ function readConfig(root) {
232
235
  if (new Set(cfg.targets).size !== cfg.targets.length) die('config: .agent-personalizer.json lists a target twice');
233
236
  }
234
237
  if ('level' in cfg && !(Number.isInteger(cfg.level) && cfg.level >= 1 && cfg.level <= 4)) die(`config: .agent-personalizer.json "level" must be an integer 1-4 (found ${JSON.stringify(cfg.level)})`);
238
+ if ('compact' in cfg && typeof cfg.compact !== 'boolean') die('config: "compact" must be true or false');
235
239
  validatePreservedTargets(cfg);
236
240
  if ('onboarding' in cfg) {
237
241
  try { cfg.onboarding = onboarding.validate(cfg.onboarding); } catch (e) { die(`config: onboarding answers: ${e.message}`); }
@@ -415,7 +419,14 @@ function renderTarget(key, target, profile, rules, cfg, root, learned) {
415
419
  if (['claude', 'agents', 'gemini', 'hermes'].includes(key)) lines.push(onboarding.learningProcedure(), '');
416
420
  }
417
421
  lines.push('## Rules', '');
418
- for (const r of rulesFor(rules, key, answers)) lines.push(renderRule(r, target), '');
422
+ for (const r of rulesFor(rules, key, answers)) {
423
+ if (cfg && cfg.compact && FILE_TARGETS.has(key) && r.meta.inject !== true) {
424
+ const practice = r.sections.universal.split('\n').find(line => line.startsWith('In practice:'));
425
+ if (!practice) die(`${r.file}: compact mode needs an In practice: line in the universal block`);
426
+ const link = cfg.level === 1 || cfg.level === 2 ? `https://github.com/aunysillyme/agent-personalizer/blob/v${onboarding.VERSION}/rules/${r.file}` : `rules/${r.file}`;
427
+ lines.push(`- **${r.meta.title || r.meta.id || r.file}**: ${practice} [Full rule](${link})`, '');
428
+ } else lines.push(renderRule(r, target), '');
429
+ }
419
430
  return lines.join('\n').trimEnd();
420
431
  }
421
432
 
@@ -469,6 +480,8 @@ function report(label, existing, current, block, raw) {
469
480
  }
470
481
 
471
482
  function main() {
483
+ renderTarget.overBudget = [];
484
+ renderTarget.fileBudget = [];
472
485
  ARGS = parseArgs();
473
486
  if (arg('--version', false) || arg('-v', false)) { process.stdout.write(onboarding.VERSION + '\n'); return; }
474
487
  if (arg('--help', false) || arg('-h', false)) { const src = fs.readFileSync(__filename, 'utf8'); process.stdout.write(src.slice(src.indexOf('/*') + 2, src.indexOf('*/')).trim() + `\n\nagent-personalizer renderer ${onboarding.VERSION}\n`); return; }
@@ -506,7 +519,8 @@ function main() {
506
519
  }
507
520
 
508
521
  let targets;
509
- const cfg = readConfig(root);
522
+ let cfg = readConfig(root);
523
+ if (arg('--compact', false)) cfg = { ...cfg, compact: true };
510
524
  const explicit = arg('--targets', null);
511
525
  if (explicit) targets = explicit.split(',').map(s => s.trim()).filter(Boolean);
512
526
  else if (cfg) {
@@ -535,10 +549,12 @@ function main() {
535
549
  catch (_) { die(`${target.file}: not writable. Nothing was written`); }
536
550
  }
537
551
  const current = existing == null ? null : between(existing, target.file);
538
- const body = check ? null : splice(existing, block, target.file);
552
+ const body = splice(existing, block, target.file);
539
553
  // the generated file must itself re-parse to exactly one block, or the next render would refuse it
540
554
  if (body != null) { const st = markerState(body, `${target.file} (generated)`); if (st.kind !== 'one' || between(body, `${target.file} (generated)`) !== block) die(`${target.file}: generated content would not re-parse cleanly; a fence in USER.md or a rule is unbalanced. Nothing was written`); }
541
- const output = body == null ? null : (hasBom ? '\ufeff' + body : body);
555
+ const output = hasBom ? '\ufeff' + body : body;
556
+ if (FILE_TARGETS.has(key) && output.length > FILE_BUDGET)
557
+ renderTarget.fileBudget.push(`${target.file} (${output.length} characters, budget ${FILE_BUDGET}; --compact shortens rules)`);
542
558
  const mode = existing == null ? 0o644 : (fs.statSync(file).mode & 0o777);
543
559
  const entry = { key, target, file, block, current, existing, existingBytes, output, mode, report: report(target.file, existing, current, block, false) };
544
560
  if (!target.boxes) return entry;
@@ -559,13 +575,14 @@ function main() {
559
575
  });
560
576
  return [entry, ...raws];
561
577
  }).flat();
562
- if (arg('--strict', false) && (renderTarget.overBudget || []).length) {
578
+ if (arg('--strict', false) && ((renderTarget.overBudget || []).length || renderTarget.fileBudget.length)) {
563
579
  for (const o of renderTarget.overBudget) console.error(`render: OVER BUDGET ${o}`);
564
- console.error('render: --strict: a box is over its budget. Nothing was written');
580
+ for (const o of renderTarget.fileBudget) console.error(`OVER BUDGET ${o}`);
581
+ console.error('render: --strict: an output is over its budget. Nothing was written');
565
582
  process.exit(1);
566
583
  }
567
584
  if (!check) {
568
- const config = installedConfig(root, plan);
585
+ const config = installedConfig(root, plan, !!arg('--compact', false));
569
586
  if (config) plan.push(config);
570
587
  }
571
588
 
@@ -576,6 +593,7 @@ function main() {
576
593
  if (finals.some(f => /\.agent-personalizer\.(tmp|bak)$/.test(f))) die('a target file name uses the staging suffix. Nothing was written');
577
594
 
578
595
  if (check) {
596
+ for (const o of renderTarget.fileBudget) console.log(`OVER BUDGET ${o}`);
579
597
  let drift = 0;
580
598
  for (const p of plan) {
581
599
  if (p.current === null) { console.log(`DRIFT ${p.target.file}: ${p.raw ? 'missing' : 'missing or no marker block'}`); drift++; }
@@ -641,6 +659,7 @@ function main() {
641
659
  for (const c of committed) if (c.bak) tryUnlink(c.bak, leftovers, 'backup not removed');
642
660
  for (const s of staged) if (s.report) console.log(s.report);
643
661
  for (const o of (renderTarget.overBudget || [])) console.log(`OVER BUDGET ${o} (written in full; trim by hand, bottom up)`);
662
+ for (const o of renderTarget.fileBudget) console.log(`OVER BUDGET ${o}`);
644
663
  if (leftovers.length) {
645
664
  console.error('render: every target was written, but CLEANUP INCOMPLETE. Remove these by hand (they hold copies of the previous targets):');
646
665
  for (const l of leftovers) console.error(` ${l}`);
@@ -652,13 +671,18 @@ function main() {
652
671
  only from bytes already recorded as ours; an edited outer file keeps its old hash so uninstall
653
672
  retains it. Preserved targets record only the block. User bytes are never adopted on re-render.
654
673
  A config predating the installed map stays without it so legacy recipe fallback still applies. */
655
- function installedConfig(root, plan) {
674
+ function installedConfig(root, plan, compact) {
656
675
  const cfgPath = path.join(root, '.agent-personalizer.json');
657
- if (!mustBe(cfgPath, 'file', '.agent-personalizer.json')) return null;
658
- const raw = readJson(cfgPath, 'config');
659
- try { fs.accessSync(cfgPath, fs.constants.W_OK); }
676
+ const exists = mustBe(cfgPath, 'file', '.agent-personalizer.json');
677
+ if (!exists && !compact) return null;
678
+ const raw = exists ? readJson(cfgPath, 'config') : {};
679
+ if (compact) raw.compact = true;
680
+ try { fs.accessSync(exists ? cfgPath : root, fs.constants.W_OK); }
660
681
  catch (_) { die('.agent-personalizer.json: not writable. Nothing was written'); }
661
- if (!raw.installed || typeof raw.installed !== 'object' || Array.isArray(raw.installed)) return null;
682
+ if (!raw.installed || typeof raw.installed !== 'object' || Array.isArray(raw.installed)) {
683
+ if (!compact) return null;
684
+ return { file: cfgPath, target: { file: '.agent-personalizer.json' }, output: JSON.stringify(raw, null, 2) + '\n', mode: exists ? fs.statSync(cfgPath).mode & 0o777 : 0o644 };
685
+ }
662
686
  const installed = { ...raw.installed };
663
687
  for (const p of plan) {
664
688
  const preserved = !p.raw && Array.isArray(raw.preservedTargets) && raw.preservedTargets.includes(p.key);
@@ -686,6 +710,7 @@ function renderedContents(root, cfg, options = {}) {
686
710
  const learned = options.learned || readLearned(root);
687
711
  renderTarget.boxes = null;
688
712
  renderTarget.overBudget = [];
713
+ renderTarget.fileBudget = [];
689
714
  return cfg.targets.flatMap(key => {
690
715
  const target = TARGETS[key];
691
716
  if (!target) die(`unknown target "${key}"`);
@@ -703,5 +728,5 @@ function renderedContents(root, cfg, options = {}) {
703
728
  /* parseFrontmatter and parseSections are exported so another renderer can read the same rule-file
704
729
  format with the same validation (for example one that renders CLAUDE.md sections and session-start
705
730
  hook bodies from rules in this format). Set DIE_THROWS to get a Refusal instead of an exit. */
706
- module.exports = { CORE_RULE_FILES, readLearned, pendingDigest, main, fenceMap, markerState, splice, between, preflightSources, parseFrontmatter, parseSections, readConfig, validatePreservedTargets, renderedContents, Refusal, DIE_THROWS: false };
731
+ module.exports = { CORE_RULE_FILES, FILE_BUDGET, readLearned, pendingDigest, main, fenceMap, markerState, splice, between, preflightSources, parseFrontmatter, parseSections, readConfig, validatePreservedTargets, renderedContents, Refusal, DIE_THROWS: false };
707
732
  if (require.main === module) main();