agent-personalizer 0.10.0 → 0.10.1
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 +11 -1
- package/CONTRIBUTING.md +1 -1
- package/README.md +4 -4
- package/SECURITY.md +1 -1
- package/bin/agent-personalizer.js +107 -6
- package/bin/global.cjs +155 -29
- package/bin/home.cjs +69 -4
- package/bin/learn.cjs +5 -4
- package/bin/sessions.cjs +40 -9
- package/docs/companions.md +5 -5
- package/docs/guarantees.md +3 -3
- package/docs/install.md +1 -1
- package/docs/learning.md +5 -5
- package/docs/paste-guide.md +8 -7
- package/hooks/README.md +1 -1
- package/package.json +1 -1
- package/render/onboarding.cjs +1 -1
- package/render/render.cjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ Every entry names the adversarial audit round that produced it where one did. Au
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.10.1] - 2026-11-18
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Respect `CODEX_HOME` for `--global --ai agents` (install, re-run, atomic rollback, `learn` and `--uninstall`), pre-selection and session discovery, and warn without modifying `AGENTS.override.md` when a non-empty override shadows `AGENTS.md` (#51).
|
|
14
|
+
- Replace blanket ChatGPT file-access copy with surface-specific wording, and describe Codex memory notes as local to the machine or connected host (`~/.codex` or `$CODEX_HOME`) rather than global to an account (#52).
|
|
15
|
+
- Document the enclosing Git `info/exclude` (and level-3 `--precommit`) exception to the project write boundary in `README.md` (#53).
|
|
16
|
+
- Align `docs/learning.md` and `docs/paste-guide.md` with full declined-entry ChatGPT exports and `OVER BUDGET` / `--strict` behavior, and scope `docs/companions.md` enforcement claims to operations routed through the configured companion (#54).
|
|
17
|
+
|
|
9
18
|
## [0.10.0] - 2026-11-18
|
|
10
19
|
|
|
11
20
|
### Added
|
|
@@ -393,7 +402,8 @@ Thirteen issues (#3 to #15) filed against `5972b32` by an independent installati
|
|
|
393
402
|
- Installer: safe destination resolution, strict options, duplicate `--ai` refused, `--dir` created one level at a time.
|
|
394
403
|
- Harness: exact exit codes, adversarial fixtures, fault injection for the rollback path.
|
|
395
404
|
|
|
396
|
-
[Unreleased]: https://github.com/aunysillyme/agent-personalizer/compare/v0.10.
|
|
405
|
+
[Unreleased]: https://github.com/aunysillyme/agent-personalizer/compare/v0.10.1...HEAD
|
|
406
|
+
[0.10.1]: https://github.com/aunysillyme/agent-personalizer/compare/v0.10.0...v0.10.1
|
|
397
407
|
[0.10.0]: https://github.com/aunysillyme/agent-personalizer/compare/v0.9.1...v0.10.0
|
|
398
408
|
[0.9.1]: https://github.com/aunysillyme/agent-personalizer/compare/v0.9.0...v0.9.1
|
|
399
409
|
[0.9.0]: https://github.com/aunysillyme/agent-personalizer/compare/v0.8.7...v0.9.0
|
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:
|
|
13
|
+
npm test # sh test/run.sh: 103 checks, exact exit codes, Linux and macOS
|
|
14
14
|
node test/rollback.test.js
|
|
15
15
|
node check/gate.cjs --self-test
|
|
16
16
|
```
|
package/README.md
CHANGED
|
@@ -84,13 +84,13 @@ For every project, install one global level-1 profile:
|
|
|
84
84
|
npx agent-personalizer --global --ai claude,agents,gemini,hermes --yes
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
The source lives in `~/.agent-personalizer/`; marked blocks go to `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md
|
|
87
|
+
The source lives in `~/.agent-personalizer/`; marked blocks go to `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md` (or `$CODEX_HOME/AGENTS.md`), `~/.gemini/GEMINI.md` and `~/.hermes/SOUL.md` for the selected targets. User text outside the blocks stays byte for byte. For Hermes in a project, use `--ai agents` for `AGENTS.md`. `--global` supports these four 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).
|
|
88
88
|
|
|
89
89
|
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.
|
|
90
90
|
|
|
91
91
|
Node 24 or 26 (active LTS) is recommended; 22 or later runs. Published on npm with provenance. [Installation](docs/install.md) covers scripted answers, every flag, notes tools and manual copying.
|
|
92
92
|
|
|
93
|
-
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;
|
|
93
|
+
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, except inside a Git work tree where install updates the enclosing repository's Git `info/exclude` (and `hooks/pre-commit` only when you pass `--precommit` at level 3; see [preflight and writes](docs/guarantees.md#preflight-and-writes)). Global writes (`--global`) use only `~/.agent-personalizer/` and the selected AI home paths above. Edited source files are preserved and named.
|
|
94
94
|
|
|
95
95
|
## Privacy
|
|
96
96
|
|
|
@@ -150,7 +150,7 @@ Select your notes tool through saved onboarding answers or an answers file:
|
|
|
150
150
|
npx agent-personalizer --dir . --answers my-answers.json
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
[Companion setup](docs/companions.md) explains notes connectors and how to
|
|
153
|
+
[Companion setup](docs/companions.md) explains notes connectors and how to apply onboarding answers to operations routed through a configured companion.
|
|
154
154
|
|
|
155
155
|
| Tool | What it gives you |
|
|
156
156
|
|---|---|
|
|
@@ -215,7 +215,7 @@ Contributions are welcome: a new AI target, a notes tool, an example user, or a
|
|
|
215
215
|
|
|
216
216
|
Pull requests are accepted under the [contributor license agreement](CLA.md); the checkbox in the pull request template records your agreement.
|
|
217
217
|
|
|
218
|
-
The harness (`test/run.sh:
|
|
218
|
+
The harness (`test/run.sh: 103 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.
|
|
219
219
|
|
|
220
220
|
## License
|
|
221
221
|
|
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
|
|
21
|
+
Every release passes an adversarial read-only audit (see `CHANGELOG.md`, each entry names its round) and a 103-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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const readline = require('readline');
|
|
13
|
-
const { resolveHome } = require('./home.cjs');
|
|
13
|
+
const { resolveHome, resolveCodexHome, walkRealChain, hasNonEmptyOverride } = require('./home.cjs');
|
|
14
14
|
const { sha256, parseCliArgs } = require('./cli-util.cjs');
|
|
15
15
|
const crypto = require('crypto');
|
|
16
16
|
const { execFileSync } = require('child_process');
|
|
@@ -157,7 +157,7 @@ function resolveDestination(dir) {
|
|
|
157
157
|
|
|
158
158
|
|
|
159
159
|
// One transaction for project and global plans: snapshot before writes, replace atomically, restore on failure.
|
|
160
|
-
async function commitPlan(root, { writes, removals = [], outputPaths, prepare, finalize }) {
|
|
160
|
+
async function commitPlan(root, { writes, removals = [], external = [], outputPaths, prepare, finalize }) {
|
|
161
161
|
for (const rel of outputPaths) {
|
|
162
162
|
let parent = path.posix.dirname(rel);
|
|
163
163
|
while (parent !== '.') {
|
|
@@ -182,7 +182,38 @@ async function commitPlan(root, { writes, removals = [], outputPaths, prepare, f
|
|
|
182
182
|
while (!fs.existsSync(ancestor)) ancestor = path.dirname(ancestor);
|
|
183
183
|
try { fs.accessSync(ancestor, fs.constants.W_OK); } catch (_) { die(`${rel}: parent is not writable; nothing was written`); }
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
const savedExternal = new Map(), externalNewDirs = [];
|
|
186
|
+
const checkExternalBase = base => {
|
|
187
|
+
try {
|
|
188
|
+
const chain = walkRealChain(base, { allowDarwinRootLink: false, action: 'nothing was written' });
|
|
189
|
+
if (chain.missingDirs.length) die(`${base} does not exist; nothing was written`);
|
|
190
|
+
} catch (e) { if (e instanceof markers.Refusal) die(e.message); throw e; }
|
|
191
|
+
};
|
|
192
|
+
for (const ext of external) {
|
|
193
|
+
checkExternalBase(ext.base);
|
|
194
|
+
const full = path.join(ext.base, ...(ext.missingDirs || []), ext.file);
|
|
195
|
+
ext.full = full;
|
|
196
|
+
if (savedExternal.has(full)) die(`${full}: duplicate external target; nothing was written`);
|
|
197
|
+
let st = null;
|
|
198
|
+
try { st = fs.lstatSync(full); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
199
|
+
if (st) {
|
|
200
|
+
if (st.isSymbolicLink()) die(`${full} is a symlink; refusing to write through it`);
|
|
201
|
+
if (!st.isFile()) die(`${full} is not a regular file; nothing was written`);
|
|
202
|
+
savedExternal.set(full, { bytes: fs.readFileSync(full), mode: st.mode & 0o777, dev: st.dev, ino: st.ino });
|
|
203
|
+
} else savedExternal.set(full, null);
|
|
204
|
+
try { fs.accessSync(ext.base, fs.constants.W_OK); } catch (_) { die(`${full}: parent is not writable; nothing was written`); }
|
|
205
|
+
let cur = ext.base;
|
|
206
|
+
for (const part of ext.missingDirs || []) {
|
|
207
|
+
cur = path.join(cur, part);
|
|
208
|
+
let dirSt = null;
|
|
209
|
+
try { dirSt = fs.lstatSync(cur); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
210
|
+
if (dirSt) {
|
|
211
|
+
if (dirSt.isSymbolicLink()) die(`${cur} is a symlink; refusing to write through it`);
|
|
212
|
+
if (!dirSt.isDirectory()) die(`${cur} exists and is not a directory`);
|
|
213
|
+
} else if (!externalNewDirs.includes(cur)) externalNewDirs.push(cur);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (prepare) prepare(newDirectories, externalNewDirs);
|
|
186
217
|
const replace = (rel, bytes, mode) => {
|
|
187
218
|
const destination = safeDest(root, rel);
|
|
188
219
|
const tmp = path.join(path.dirname(destination.full), `.${path.basename(rel)}.${crypto.randomBytes(8).toString('hex')}.agent-personalizer.tmp`);
|
|
@@ -193,6 +224,18 @@ async function commitPlan(root, { writes, removals = [], outputPaths, prepare, f
|
|
|
193
224
|
fs.renameSync(tmp, destination.full);
|
|
194
225
|
} finally { if (fs.existsSync(tmp)) fs.unlinkSync(tmp); }
|
|
195
226
|
};
|
|
227
|
+
const replaceExternal = (full, bytes, mode) => {
|
|
228
|
+
checkExternalBase(path.dirname(full));
|
|
229
|
+
const tmp = path.join(path.dirname(full), `.${path.basename(full)}.${crypto.randomBytes(8).toString('hex')}.agent-personalizer.tmp`);
|
|
230
|
+
try {
|
|
231
|
+
fs.writeFileSync(tmp, bytes, { flag: 'wx', ...(mode === undefined ? {} : { mode }) });
|
|
232
|
+
if (mode !== undefined) fs.chmodSync(tmp, mode);
|
|
233
|
+
let st = null;
|
|
234
|
+
try { st = fs.lstatSync(full); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
235
|
+
if (st && st.isSymbolicLink()) die(`${full} is a symlink; refusing to write through it`);
|
|
236
|
+
fs.renameSync(tmp, full);
|
|
237
|
+
} finally { if (fs.existsSync(tmp)) fs.unlinkSync(tmp); }
|
|
238
|
+
};
|
|
196
239
|
const assertSaved = rel => {
|
|
197
240
|
const destination = probe(root, rel), before = saved.get(rel);
|
|
198
241
|
if (!!before !== destination.exists) die(`${rel} changed during preflight; nothing was written`);
|
|
@@ -201,11 +244,41 @@ async function commitPlan(root, { writes, removals = [], outputPaths, prepare, f
|
|
|
201
244
|
if (info.dev !== before.dev || info.ino !== before.ino || !fs.readFileSync(destination.full).equals(before.bytes)) die(`${rel} changed during preflight; nothing was written`);
|
|
202
245
|
}
|
|
203
246
|
};
|
|
247
|
+
const assertSavedExternal = full => {
|
|
248
|
+
let dirExists = true;
|
|
249
|
+
try {
|
|
250
|
+
const chain = walkRealChain(path.dirname(full), { allowDarwinRootLink: false, action: 'nothing was written' });
|
|
251
|
+
dirExists = chain.missingDirs.length === 0;
|
|
252
|
+
} catch (e) { if (e instanceof markers.Refusal) die(e.message); throw e; }
|
|
253
|
+
let st = null;
|
|
254
|
+
if (dirExists) {
|
|
255
|
+
try { st = fs.lstatSync(full); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
256
|
+
}
|
|
257
|
+
if (st && st.isSymbolicLink()) die(`${full} is a symlink; refusing to write through it`);
|
|
258
|
+
const before = savedExternal.get(full);
|
|
259
|
+
if (!!before !== !!st) die(`${full} changed during preflight; nothing was written`);
|
|
260
|
+
if (before && (st.dev !== before.dev || st.ino !== before.ino || !fs.readFileSync(full).equals(before.bytes))) die(`${full} changed during preflight; nothing was written`);
|
|
261
|
+
};
|
|
204
262
|
committing = true;
|
|
205
|
-
const touched = new Set();
|
|
263
|
+
const touched = new Set(), touchedExternal = [], touchedExternalDirs = [];
|
|
206
264
|
try {
|
|
207
265
|
for (const rel of outputPaths) assertSaved(rel);
|
|
266
|
+
for (const full of savedExternal.keys()) assertSavedExternal(full);
|
|
267
|
+
for (const dir of externalNewDirs) {
|
|
268
|
+
let st = null;
|
|
269
|
+
try { st = fs.lstatSync(dir); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
270
|
+
if (st) die(`${dir} changed during preflight; nothing was written`);
|
|
271
|
+
fs.mkdirSync(dir);
|
|
272
|
+
touchedExternalDirs.push(dir);
|
|
273
|
+
}
|
|
208
274
|
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); }
|
|
275
|
+
for (const ext of external) {
|
|
276
|
+
assertSavedExternal(ext.full);
|
|
277
|
+
touchedExternal.push(ext.full);
|
|
278
|
+
if (ext.remove) fs.unlinkSync(ext.full);
|
|
279
|
+
else replaceExternal(ext.full, ext.bytes, savedExternal.get(ext.full)?.mode);
|
|
280
|
+
if (ext.report) console.log(ext.report);
|
|
281
|
+
}
|
|
209
282
|
for (const p of writes) {
|
|
210
283
|
assertSaved(p.rel);
|
|
211
284
|
touched.add(p.rel);
|
|
@@ -218,6 +291,17 @@ async function commitPlan(root, { writes, removals = [], outputPaths, prepare, f
|
|
|
218
291
|
if (finalize) await finalize();
|
|
219
292
|
} catch (e) {
|
|
220
293
|
const incomplete = [];
|
|
294
|
+
for (const full of [...touchedExternal].reverse()) {
|
|
295
|
+
try {
|
|
296
|
+
checkExternalBase(path.dirname(full));
|
|
297
|
+
const before = savedExternal.get(full);
|
|
298
|
+
let st = null;
|
|
299
|
+
try { st = fs.lstatSync(full); } catch (_) { st = null; }
|
|
300
|
+
if (st && st.isSymbolicLink()) throw new Error('refusing symlink during restore');
|
|
301
|
+
if (before) replaceExternal(full, before.bytes, before.mode);
|
|
302
|
+
else if (st) fs.unlinkSync(full);
|
|
303
|
+
} catch (failure) { incomplete.push(`${full}: ${failure.message}`); }
|
|
304
|
+
}
|
|
221
305
|
for (const rel of [...touched].reverse()) {
|
|
222
306
|
try {
|
|
223
307
|
const before = saved.get(rel), destination = probe(root, rel);
|
|
@@ -225,6 +309,12 @@ async function commitPlan(root, { writes, removals = [], outputPaths, prepare, f
|
|
|
225
309
|
else if (destination.exists) fs.unlinkSync(destination.full);
|
|
226
310
|
} catch (failure) { incomplete.push(`${rel}: ${failure.message}`); }
|
|
227
311
|
}
|
|
312
|
+
for (const dir of [...touchedExternalDirs].reverse()) {
|
|
313
|
+
try {
|
|
314
|
+
const chain = walkRealChain(dir, { allowDarwinRootLink: false, action: 'nothing was written' });
|
|
315
|
+
if (!chain.missingDirs.length && fs.readdirSync(dir).length === 0) fs.rmdirSync(dir);
|
|
316
|
+
} catch (failure) { incomplete.push(`${dir}/: ${failure.message}`); }
|
|
317
|
+
}
|
|
228
318
|
for (const rel of [...newDirectories].sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
229
319
|
try { const destination = probe(root, rel); if (destination.exists && fs.readdirSync(destination.full).length === 0) fs.rmdirSync(destination.full); }
|
|
230
320
|
catch (failure) { incomplete.push(`${rel}/: ${failure.message}`); }
|
|
@@ -278,8 +368,16 @@ async function main() {
|
|
|
278
368
|
let home;
|
|
279
369
|
try { home = resolveHome(); }
|
|
280
370
|
catch (e) { if (!(e instanceof markers.Refusal)) throw e; }
|
|
281
|
-
|
|
282
|
-
|
|
371
|
+
let codexDir = null;
|
|
372
|
+
if (home) {
|
|
373
|
+
try { codexDir = resolveCodexHome(home); }
|
|
374
|
+
catch (e) { if (!(e instanceof markers.Refusal)) throw e; }
|
|
375
|
+
}
|
|
376
|
+
const found = home ? [
|
|
377
|
+
[path.join(home, '.claude'), 'claude'],
|
|
378
|
+
...(codexDir ? [[codexDir, 'agents']] : []),
|
|
379
|
+
[path.join(home, '.gemini'), 'gemini'],
|
|
380
|
+
].filter(([folder]) => fs.existsSync(folder)).map(([, ai]) => ai) : [];
|
|
283
381
|
ais = await ask('\nAIs', ais || (found.length ? found.join(',') : 'claude,agents'));
|
|
284
382
|
}
|
|
285
383
|
if (!/^[1-4]$/.test(String(level))) die('level must be 1, 2 or 3 (4 is accepted as 3)');
|
|
@@ -596,6 +694,9 @@ async function main() {
|
|
|
596
694
|
});
|
|
597
695
|
|
|
598
696
|
require('./git-exclude.cjs').protect(root);
|
|
697
|
+
if (targets.includes('agents') && hasNonEmptyOverride(root)) {
|
|
698
|
+
console.warn(`Warning: ${path.join(root, 'AGENTS.override.md')} is non-empty and overrides ${path.join(root, 'AGENTS.md')} in Codex; Codex ignores AGENTS.md in that directory while AGENTS.override.md has content.`);
|
|
699
|
+
}
|
|
599
700
|
|
|
600
701
|
if (interactive && !cfgExists && !learnRequested) console.log('Nothing was read. Run npx agent-personalizer learn any time.');
|
|
601
702
|
|
package/bin/global.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// Global targets have fixed home-relative names; profile ownership stays inside its own folder.
|
|
2
|
+
// Global targets have fixed home-relative names (except CODEX_HOME when set); profile ownership stays inside its own folder.
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const { resolveHome } = require('./home.cjs');
|
|
4
|
+
const { rootedAbsolute, resolveHome, resolveCodexHome, walkRealChain, hasNonEmptyOverride } = require('./home.cjs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const renderer = require('../render/render.cjs');
|
|
7
7
|
const onboarding = require('../render/onboarding.cjs');
|
|
@@ -21,6 +21,15 @@ function blockHash(text, rel) {
|
|
|
21
21
|
if (ms.kind === 'malformed') refuse(`${rel}: malformed marker block; nothing was changed`);
|
|
22
22
|
return ms.kind === 'one' ? sha256(Buffer.from(text.slice(ms.bStart, ms.eEnd))) : null;
|
|
23
23
|
}
|
|
24
|
+
function stripOwnedBlock(text, ms, owned) {
|
|
25
|
+
let before = text.slice(0, ms.bStart), after = text.slice(ms.eEnd);
|
|
26
|
+
if (after.startsWith('\r\n')) after = after.slice(2);
|
|
27
|
+
else if (after.startsWith('\n')) after = after.slice(1);
|
|
28
|
+
if (owned.appended && owned.separator && before.endsWith(owned.separator)) {
|
|
29
|
+
before = before.slice(0, -owned.separator.length);
|
|
30
|
+
}
|
|
31
|
+
return before + after;
|
|
32
|
+
}
|
|
24
33
|
function validateGlobal(cfg) {
|
|
25
34
|
if (!cfg.global || cfg.level !== 1) refuse('global profile config must identify a level-1 global install');
|
|
26
35
|
for (const target of cfg.targets || []) if (!Object.hasOwn(TARGETS, target) && target !== 'onboarding') refuse(`unsupported global target: ${target}`);
|
|
@@ -28,10 +37,45 @@ function validateGlobal(cfg) {
|
|
|
28
37
|
for (const [key, info] of Object.entries(cfg.globalFiles || {})) {
|
|
29
38
|
if (!Object.hasOwn(TARGETS, key) || !info || typeof info.created !== 'boolean' || !HASH.test(info.blockHash) || !HASH.test(info.fileHash)
|
|
30
39
|
|| !['', '\n', '\n\n'].includes(info.separator) || typeof info.appended !== 'boolean') refuse('invalid global target ownership');
|
|
40
|
+
if (info.path !== undefined && (key !== 'agents' || !rootedAbsolute(info.path))) refuse('invalid global target path');
|
|
41
|
+
if (info.createdDirs !== undefined && (key !== 'agents' || !Array.isArray(info.createdDirs) || info.createdDirs.some(d => !rootedAbsolute(d)))) {
|
|
42
|
+
refuse('invalid global target directory ownership');
|
|
43
|
+
}
|
|
31
44
|
}
|
|
32
45
|
if (cfg.globalDirectories !== undefined && (!Array.isArray(cfg.globalDirectories) || cfg.globalDirectories.some(rel => ![SOURCE, '.claude', '.codex', '.gemini', '.hermes'].includes(rel)))) refuse('invalid global directory inventory');
|
|
33
46
|
}
|
|
34
47
|
|
|
48
|
+
function resolveCodexTarget(root, profileRoot) {
|
|
49
|
+
const raw = resolveCodexHome(root);
|
|
50
|
+
const { base, missingDirs, dir } = walkRealChain(raw, { allowDarwinRootLink: true, action: 'nothing was written' });
|
|
51
|
+
if (dir === profileRoot || (dir + path.sep).startsWith(profileRoot + path.sep)) {
|
|
52
|
+
refuse('CODEX_HOME cannot point inside ~/.agent-personalizer; nothing was written');
|
|
53
|
+
}
|
|
54
|
+
const defaultDir = path.join(root, '.codex');
|
|
55
|
+
if (dir === defaultDir) return { external: false, dir, rel: TARGETS.agents, full: path.join(dir, 'AGENTS.md') };
|
|
56
|
+
const full = path.join(dir, 'AGENTS.md');
|
|
57
|
+
if (!missingDirs.length) {
|
|
58
|
+
let fileSt = null;
|
|
59
|
+
try { fileSt = fs.lstatSync(full); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
60
|
+
if (fileSt) {
|
|
61
|
+
if (fileSt.isSymbolicLink()) refuse(`${full} is a symlink; refusing to write through it`);
|
|
62
|
+
if (!fileSt.isFile()) refuse(`${full} is not a regular file; nothing was written`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { external: true, base, missingDirs, dir, file: 'AGENTS.md', full };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function readExternalFile(full, label, action = 'nothing was changed') {
|
|
69
|
+
const dir = path.dirname(full);
|
|
70
|
+
const chain = walkRealChain(dir, { allowDarwinRootLink: false, action });
|
|
71
|
+
if (chain.missingDirs.length) return null;
|
|
72
|
+
let st = null;
|
|
73
|
+
try { st = fs.lstatSync(full); } catch (e) { if (e.code === 'ENOENT') return null; throw e; }
|
|
74
|
+
if (st.isSymbolicLink()) refuse(`${label} is a symlink; ${action}`);
|
|
75
|
+
if (!st.isFile()) refuse(`${label} is not a regular file; ${action}`);
|
|
76
|
+
return fs.readFileSync(full);
|
|
77
|
+
}
|
|
78
|
+
|
|
35
79
|
async function run({ args, commitPlan, probe, readConfig, ask }) {
|
|
36
80
|
const prior = renderer.DIE_THROWS;
|
|
37
81
|
renderer.DIE_THROWS = true;
|
|
@@ -78,9 +122,10 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
|
|
|
78
122
|
try { answers = onboarding.validate(JSON.parse(fs.readFileSync(file === '-' ? 0 : path.resolve(file), 'utf8'))); }
|
|
79
123
|
catch (e) { refuse(`--answers: ${e.message}`); }
|
|
80
124
|
}
|
|
125
|
+
const codexTarget = targets.includes('agents') ? resolveCodexTarget(root, profileRoot) : null;
|
|
81
126
|
const old = stored.cfg;
|
|
82
127
|
const installed = { ...(old.installed || {}) };
|
|
83
|
-
const writes = [];
|
|
128
|
+
const writes = [], removals = [], external = [], pruneExternalDirs = [];
|
|
84
129
|
const read = rel => {
|
|
85
130
|
const found = probe(root, `${SOURCE}/${rel}`);
|
|
86
131
|
if (!found.exists) return null;
|
|
@@ -116,35 +161,101 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
|
|
|
116
161
|
.replace(/`USER\.md` sits next to `(?:CLAUDE|AGENTS|GEMINI)\.md`\.(?: In (?:Claude Code|Gemini CLI and Google Antigravity), `(?:CLAUDE|GEMINI)\.md` loads automatically;)?/g, 'Read `USER.md` from the global profile source.')
|
|
117
162
|
.replace(/"npx agent-personalizer --dir \.", or "node render\/render\.cjs --dir \." at level 3/g, '"npx agent-personalizer --global"')
|
|
118
163
|
.replace(/(^|[^A-Za-z0-9_./-])(USER\.md|LEARNED\.md|AGENT_ONBOARDING\.md|\.agent-personalizer\.json|\.agent-personalizer\/digest\.md)(?![A-Za-z0-9_/-])/g, (_, prefix, rel) => prefix + path.join(profileRoot, rel));
|
|
164
|
+
|
|
165
|
+
// If agents moved between ~/.codex and a custom CODEX_HOME, retire the unedited block at the old location.
|
|
166
|
+
const oldAgents = old.globalFiles?.agents;
|
|
167
|
+
if (codexTarget && oldAgents) {
|
|
168
|
+
const oldFull = oldAgents.path || path.join(root, TARGETS.agents);
|
|
169
|
+
if (oldFull !== codexTarget.full) {
|
|
170
|
+
if (!oldAgents.path) {
|
|
171
|
+
const prevFound = probe(root, TARGETS.agents);
|
|
172
|
+
if (prevFound.exists) {
|
|
173
|
+
if (!fs.lstatSync(prevFound.full).isFile()) refuse(`${TARGETS.agents} is not a regular file`);
|
|
174
|
+
const prevText = decode(fs.readFileSync(prevFound.full), TARGETS.agents);
|
|
175
|
+
const prevMs = renderer.markerState(prevText, TARGETS.agents);
|
|
176
|
+
const prevHash = blockHash(prevText, TARGETS.agents);
|
|
177
|
+
if (prevMs.kind === 'one' && prevHash === oldAgents.blockHash) {
|
|
178
|
+
const stripped = stripOwnedBlock(prevText, prevMs, oldAgents);
|
|
179
|
+
if (oldAgents.created && stripped === '') removals.push({ rel: TARGETS.agents });
|
|
180
|
+
else writes.push({ rel: TARGETS.agents, bytes: Buffer.from(stripped) });
|
|
181
|
+
} else if (prevMs.kind === 'one') console.log(`kept ${TARGETS.agents} (edited)`);
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
const prevBytes = readExternalFile(oldAgents.path, oldAgents.path);
|
|
185
|
+
if (prevBytes) {
|
|
186
|
+
const prevText = decode(prevBytes, oldAgents.path);
|
|
187
|
+
const prevMs = renderer.markerState(prevText, oldAgents.path);
|
|
188
|
+
const prevHash = blockHash(prevText, oldAgents.path);
|
|
189
|
+
if (prevMs.kind === 'one' && prevHash === oldAgents.blockHash) {
|
|
190
|
+
const stripped = stripOwnedBlock(prevText, prevMs, oldAgents);
|
|
191
|
+
if (oldAgents.created && stripped === '') external.push({ base: path.dirname(oldAgents.path), missingDirs: [], file: path.basename(oldAgents.path), remove: true });
|
|
192
|
+
else external.push({ base: path.dirname(oldAgents.path), missingDirs: [], file: path.basename(oldAgents.path), bytes: Buffer.from(stripped) });
|
|
193
|
+
for (const d of oldAgents.createdDirs || []) pruneExternalDirs.push(d);
|
|
194
|
+
} else if (prevMs.kind === 'one') console.log(`kept ${oldAgents.path} (edited)`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
119
200
|
const rendered = renderer.renderedContents(profileRoot, renderCfg, { profileSource: decode(user, 'USER.md'), learned, boilerplate: qualify });
|
|
120
201
|
for (const entry of rendered) {
|
|
121
202
|
if (entry.key === 'onboarding') { writeSource(entry.rel, Buffer.from(renderer.splice(null, entry.block, entry.rel))); continue; }
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
203
|
+
const isExternalAgents = entry.key === 'agents' && codexTarget && codexTarget.external;
|
|
204
|
+
const label = isExternalAgents ? codexTarget.full : TARGETS[entry.key];
|
|
205
|
+
let text = null, exists = false;
|
|
206
|
+
if (isExternalAgents) {
|
|
207
|
+
const existingBytes = fs.existsSync(codexTarget.full) ? fs.readFileSync(codexTarget.full) : null;
|
|
208
|
+
exists = !!existingBytes;
|
|
209
|
+
if (existingBytes) text = decode(existingBytes, label);
|
|
210
|
+
} else {
|
|
211
|
+
const found = probe(root, label);
|
|
212
|
+
exists = found.exists;
|
|
213
|
+
if (found.exists && !fs.lstatSync(found.full).isFile()) refuse(`${label} is not a regular file`);
|
|
214
|
+
if (found.exists) text = decode(fs.readFileSync(found.full), label);
|
|
215
|
+
}
|
|
216
|
+
const ms = text === null ? { kind: 'none' } : renderer.markerState(text, label);
|
|
217
|
+
if (ms.kind === 'malformed') refuse(`${label}: malformed marker block`);
|
|
218
|
+
const samePriorPath = Object.hasOwn(cfg.globalFiles, entry.key)
|
|
219
|
+
&& ((entry.key !== 'agents') || (cfg.globalFiles.agents?.path || path.join(root, TARGETS.agents)) === (isExternalAgents ? codexTarget.full : path.join(root, TARGETS.agents)));
|
|
220
|
+
if (ms.kind === 'one' && !samePriorPath) {
|
|
221
|
+
refuse(`${label}: foreign agent-personalizer block; remove the block from <!-- agent-personalizer:begin --> through <!-- agent-personalizer:end -->, then re-run --global. Nothing was written`);
|
|
130
222
|
}
|
|
131
223
|
const block = `Profile source: \`${path.join(profileRoot, 'USER.md')}\`. Read \`${path.join(profileRoot, 'AGENT_ONBOARDING.md')}\` for working preferences.\n\n` + entry.block;
|
|
132
|
-
const output = renderer.splice(text, block,
|
|
133
|
-
if (output.length > renderer.FILE_BUDGET) console.log(`OVER BUDGET ${
|
|
134
|
-
if (renderer.markerState(output,
|
|
135
|
-
const prior = ms.kind === 'one' ? cfg.globalFiles[entry.key] : null;
|
|
136
|
-
|
|
224
|
+
const output = renderer.splice(text, block, label);
|
|
225
|
+
if (output.length > renderer.FILE_BUDGET) console.log(`OVER BUDGET ${label} (${output.length} characters, budget ${renderer.FILE_BUDGET}; --compact shortens rules)`);
|
|
226
|
+
if (renderer.markerState(output, label).kind !== 'one' || renderer.between(output, label) !== block) refuse(`${label}: generated block would not re-parse; nothing was written`);
|
|
227
|
+
const prior = ms.kind === 'one' && samePriorPath ? cfg.globalFiles[entry.key] : null;
|
|
228
|
+
const meta = { created: !exists || !!prior?.created, blockHash: blockHash(output, label), fileHash: sha256(Buffer.from(output)),
|
|
137
229
|
appended: prior ? prior.appended : ms.kind === 'none', separator: prior ? prior.separator : (text === null ? '' : text.endsWith('\n') ? '\n' : '\n\n') };
|
|
138
|
-
|
|
230
|
+
if (isExternalAgents) {
|
|
231
|
+
meta.path = codexTarget.full;
|
|
232
|
+
if (prior?.createdDirs?.length) meta.createdDirs = [...prior.createdDirs];
|
|
233
|
+
external.push({ base: codexTarget.base, missingDirs: codexTarget.missingDirs, file: codexTarget.file, bytes: Buffer.from(output), report: `update ${label} (global profile)` });
|
|
234
|
+
} else {
|
|
235
|
+
writes.push({ rel: label, bytes: Buffer.from(output), report: `update ${label} (global profile)` });
|
|
236
|
+
}
|
|
237
|
+
cfg.globalFiles[entry.key] = meta;
|
|
139
238
|
}
|
|
140
239
|
const learnRequested = interactive && !stored.cfgExists ? await require('./learn.cjs').requestConsent({ allProjects: true }) : false;
|
|
141
|
-
const outputPaths = new Set([CONFIG, ...writes.map(p => p.rel)]);
|
|
142
|
-
await commitPlan(root, { writes, outputPaths,
|
|
143
|
-
prepare(newDirectories) {
|
|
240
|
+
const outputPaths = new Set([CONFIG, ...writes.map(p => p.rel), ...removals.map(p => p.rel)]);
|
|
241
|
+
await commitPlan(root, { writes, removals, external, outputPaths,
|
|
242
|
+
prepare(newDirectories, externalNewDirs = []) {
|
|
243
|
+
if (codexTarget?.external && cfg.globalFiles.agents && externalNewDirs.length) {
|
|
244
|
+
cfg.globalFiles.agents.createdDirs = [...new Set([...(cfg.globalFiles.agents.createdDirs || []), ...externalNewDirs])];
|
|
245
|
+
}
|
|
144
246
|
cfg.globalDirectories = [...new Set([...(old.globalDirectories || []), ...[...newDirectories].filter(rel => [SOURCE, '.claude', '.codex', '.gemini', '.hermes'].includes(rel))])].sort();
|
|
145
247
|
writes.push({ rel: CONFIG, bytes: Buffer.from(JSON.stringify(cfg, null, 2) + '\n') });
|
|
146
248
|
}
|
|
147
249
|
});
|
|
250
|
+
for (const dir of pruneExternalDirs.sort((a, b) => b.length - a.length)) {
|
|
251
|
+
try {
|
|
252
|
+
const chain = walkRealChain(dir, { allowDarwinRootLink: false, action: 'nothing was removed' });
|
|
253
|
+
if (!chain.missingDirs.length && fs.readdirSync(dir).length === 0) fs.rmdirSync(dir);
|
|
254
|
+
} catch (_) {}
|
|
255
|
+
}
|
|
256
|
+
if (codexTarget && hasNonEmptyOverride(codexTarget.dir)) {
|
|
257
|
+
console.warn(`Warning: ${path.join(codexTarget.dir, 'AGENTS.override.md')} is non-empty and overrides ${codexTarget.full} in Codex; Codex ignores AGENTS.md in that directory while AGENTS.override.md has content.`);
|
|
258
|
+
}
|
|
148
259
|
if (targets.includes('hermes') && process.env.HERMES_HOME) {
|
|
149
260
|
let hermesHome = path.resolve(process.env.HERMES_HOME);
|
|
150
261
|
try { hermesHome = fs.realpathSync(hermesHome); } catch (_) {}
|
|
@@ -156,7 +267,7 @@ async function execute({ args, commitPlan, probe, readConfig, ask }) {
|
|
|
156
267
|
|
|
157
268
|
async function uninstall({ root, cfg, dry, commitPlan, probe }) {
|
|
158
269
|
validateInventory(cfg);
|
|
159
|
-
const writes = [], removals = [], retained = [];
|
|
270
|
+
const writes = [], removals = [], external = [], retained = [], externalDirs = [];
|
|
160
271
|
const read = rel => {
|
|
161
272
|
const found = probe(root, rel);
|
|
162
273
|
if (!found.exists) return null;
|
|
@@ -164,19 +275,26 @@ async function uninstall({ root, cfg, dry, commitPlan, probe }) {
|
|
|
164
275
|
return fs.readFileSync(found.full);
|
|
165
276
|
};
|
|
166
277
|
for (const [key, owned] of Object.entries(cfg.globalFiles || {})) {
|
|
278
|
+
if (owned.path) {
|
|
279
|
+
const bytes = readExternalFile(owned.path, owned.path, 'nothing was removed');
|
|
280
|
+
for (const d of owned.createdDirs || []) externalDirs.push(d);
|
|
281
|
+
if (!bytes) continue;
|
|
282
|
+
const text = decode(bytes, owned.path), ms = renderer.markerState(text, owned.path);
|
|
283
|
+
const currentHash = blockHash(text, owned.path);
|
|
284
|
+
if (ms.kind === 'none') continue;
|
|
285
|
+
if (currentHash !== owned.blockHash) { retained.push(owned.path); continue; }
|
|
286
|
+
const output = stripOwnedBlock(text, ms, owned);
|
|
287
|
+
if (owned.created && output === '') external.push({ base: path.dirname(owned.path), missingDirs: [], file: path.basename(owned.path), remove: true, display: owned.path });
|
|
288
|
+
else external.push({ base: path.dirname(owned.path), missingDirs: [], file: path.basename(owned.path), bytes: Buffer.from(output), display: owned.path });
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
167
291
|
const rel = TARGETS[key], bytes = read(rel);
|
|
168
292
|
if (!bytes) continue;
|
|
169
293
|
const text = decode(bytes, rel), ms = renderer.markerState(text, rel);
|
|
170
294
|
const currentHash = blockHash(text, rel);
|
|
171
295
|
if (ms.kind === 'none') continue;
|
|
172
296
|
if (currentHash !== owned.blockHash) { retained.push(rel); continue; }
|
|
173
|
-
|
|
174
|
-
if (after.startsWith('\r\n')) after = after.slice(2);
|
|
175
|
-
else if (after.startsWith('\n')) after = after.slice(1);
|
|
176
|
-
if (owned.appended) {
|
|
177
|
-
if (owned.separator && before.endsWith(owned.separator)) before = before.slice(0, -owned.separator.length);
|
|
178
|
-
}
|
|
179
|
-
const output = before + after;
|
|
297
|
+
const output = stripOwnedBlock(text, ms, owned);
|
|
180
298
|
if (owned.created && output === '') removals.push({ rel });
|
|
181
299
|
else writes.push({ rel, bytes: Buffer.from(output) });
|
|
182
300
|
}
|
|
@@ -191,14 +309,22 @@ async function uninstall({ root, cfg, dry, commitPlan, probe }) {
|
|
|
191
309
|
const found = probe(root, rel);
|
|
192
310
|
if (found.exists && !fs.lstatSync(found.full).isDirectory()) refuse(`${rel} is not a directory`);
|
|
193
311
|
}
|
|
312
|
+
for (const dir of externalDirs) {
|
|
313
|
+
walkRealChain(dir, { allowDarwinRootLink: false, action: 'nothing was removed' });
|
|
314
|
+
}
|
|
194
315
|
if (!retained.length) removals.push({ rel: CONFIG });
|
|
195
316
|
for (const rel of retained) console.log(`kept ${rel} (edited)`);
|
|
196
317
|
if (dry) {
|
|
197
318
|
for (const p of [...writes, ...removals]) console.log(`would ${p.bytes ? 'update' : 'remove'} ${p.rel}`);
|
|
319
|
+
for (const ext of external) console.log(`would ${ext.remove ? 'remove' : 'update'} ${ext.display}`);
|
|
198
320
|
return;
|
|
199
321
|
}
|
|
200
322
|
const outputPaths = new Set([...writes, ...removals].map(p => p.rel));
|
|
201
|
-
await commitPlan(root, { writes, removals, outputPaths });
|
|
323
|
+
await commitPlan(root, { writes, removals, external, outputPaths });
|
|
324
|
+
for (const dir of externalDirs.sort((a, b) => b.length - a.length)) {
|
|
325
|
+
const chain = walkRealChain(dir, { allowDarwinRootLink: false, action: 'nothing was removed' });
|
|
326
|
+
if (!chain.missingDirs.length && fs.readdirSync(dir).length === 0) fs.rmdirSync(dir);
|
|
327
|
+
}
|
|
202
328
|
for (const rel of directories.sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
203
329
|
const found = probe(root, rel);
|
|
204
330
|
if (found.exists && fs.readdirSync(found.full).length === 0) fs.rmdirSync(found.full);
|
package/bin/home.cjs
CHANGED
|
@@ -1,15 +1,80 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
const fs = require('fs');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const { Refusal } = require('../render/render.cjs');
|
|
4
5
|
|
|
6
|
+
function rootedAbsolute(dir) {
|
|
7
|
+
// On Windows a root-relative path such as \foo is "absolute" but lands on the current drive; require a drive or UNC root.
|
|
8
|
+
const rooted = path.sep !== '\\' || /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/?.]+[\\/][^\\/]+)/.test(dir || '');
|
|
9
|
+
return typeof dir === 'string' && dir.length > 0 && path.isAbsolute(dir) && rooted;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
function resolveHome(home = process.env.HOME) {
|
|
6
13
|
if (process.platform === 'win32' && (home === undefined || home === '')) home = process.env.USERPROFILE;
|
|
7
|
-
|
|
8
|
-
const rooted = path.sep !== '\\' || /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/?.]+[\\/][^\\/]+)/.test(home || '');
|
|
9
|
-
if (typeof home !== 'string' || !home || !path.isAbsolute(home) || !rooted) {
|
|
14
|
+
if (!rootedAbsolute(home)) {
|
|
10
15
|
throw new Refusal('HOME (or USERPROFILE on Windows) must be set to a non-empty absolute path; nothing was written');
|
|
11
16
|
}
|
|
12
17
|
return home;
|
|
13
18
|
}
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
function resolveCodexHome(home = resolveHome(), codexHome = process.env.CODEX_HOME) {
|
|
21
|
+
const resolvedHome = resolveHome(home);
|
|
22
|
+
if (codexHome === undefined || codexHome === '') return path.join(resolvedHome, '.codex');
|
|
23
|
+
if (!rootedAbsolute(codexHome)) {
|
|
24
|
+
throw new Refusal('CODEX_HOME must be set to a non-empty absolute path; nothing was written');
|
|
25
|
+
}
|
|
26
|
+
return path.resolve(codexHome);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Walk every path component from the filesystem root without following symlinks.
|
|
30
|
+
// On macOS, top-level /tmp, /var and /etc are system symlinks to /private/*; allowDarwinRootLink
|
|
31
|
+
// resolves only that depth-0 OS link on user-supplied paths, never on stored canonical paths.
|
|
32
|
+
function walkRealChain(absPath, { allowDarwinRootLink = false, action = 'nothing was written' } = {}) {
|
|
33
|
+
const normalized = path.resolve(absPath);
|
|
34
|
+
const { root } = path.parse(normalized);
|
|
35
|
+
const rest = normalized.slice(root.length);
|
|
36
|
+
const parts = rest ? rest.split(path.sep).filter(Boolean) : [];
|
|
37
|
+
let cur = root;
|
|
38
|
+
const missingDirs = [];
|
|
39
|
+
for (let i = 0; i < parts.length; i++) {
|
|
40
|
+
if (missingDirs.length) {
|
|
41
|
+
missingDirs.push(parts[i]);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const next = path.join(cur, parts[i]);
|
|
45
|
+
let st;
|
|
46
|
+
try { st = fs.lstatSync(next); }
|
|
47
|
+
catch (e) {
|
|
48
|
+
if (e.code === 'ENOENT') {
|
|
49
|
+
missingDirs.push(parts[i]);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
if (st.isSymbolicLink()) {
|
|
55
|
+
if (allowDarwinRootLink && process.platform === 'darwin' && i === 0 && (next === '/tmp' || next === '/var' || next === '/etc')) {
|
|
56
|
+
cur = fs.realpathSync(next);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
throw new Refusal(`${next} is a symlink; ${action}`);
|
|
60
|
+
}
|
|
61
|
+
if (!st.isDirectory()) {
|
|
62
|
+
throw new Refusal(`${next} is not a directory; ${action}`);
|
|
63
|
+
}
|
|
64
|
+
cur = next;
|
|
65
|
+
}
|
|
66
|
+
return { base: cur, missingDirs, dir: path.join(cur, ...missingDirs) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function hasNonEmptyOverride(dir) {
|
|
70
|
+
const file = path.join(dir, 'AGENTS.override.md');
|
|
71
|
+
try {
|
|
72
|
+
const stat = fs.statSync(file);
|
|
73
|
+
if (!stat.isFile() || stat.size === 0) return false;
|
|
74
|
+
return fs.readFileSync(file, 'utf8').replace(/^\ufeff/, '').trim().length > 0;
|
|
75
|
+
} catch (_) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = { rootedAbsolute, resolveHome, resolveCodexHome, walkRealChain, hasNonEmptyOverride };
|
package/bin/learn.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Consent separates project inspection from access to the AI apps' private history.
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const { resolveHome } = require('./home.cjs');
|
|
5
|
+
const { resolveHome, resolveCodexHome } = require('./home.cjs');
|
|
6
6
|
const { sha256 } = require('./cli-util.cjs');
|
|
7
7
|
const crypto = require('crypto');
|
|
8
8
|
const readline = require('readline');
|
|
@@ -28,8 +28,8 @@ that Claude Code, Codex and Gemini CLI still keep, to find corrections you repea
|
|
|
28
28
|
· Other people's details in there? Add their names to your private list first.
|
|
29
29
|
· Delete it any time: npx agent-personalizer learn --forget
|
|
30
30
|
(your AI app's own history stays as it is)
|
|
31
|
-
· Codex
|
|
32
|
-
They
|
|
31
|
+
· Local Codex memory notes from your Codex home are included when you choose Codex.
|
|
32
|
+
They span sessions on this machine (or connected host), not just this folder.
|
|
33
33
|
· When your AI reads the file, its provider sees these messages again.
|
|
34
34
|
· Work or client accounts: check your agreement before reusing their sessions.
|
|
35
35
|
· Not affiliated with Anthropic, OpenAI or Google. Their formats can change.
|
|
@@ -163,7 +163,8 @@ async function learn({ dir = '.', yes = false, consented = false, allProjects =
|
|
|
163
163
|
const entries = renderer.readLearned(root);
|
|
164
164
|
const sources = [...new Set((cfg.targets || []).map(target => SOURCE[target]).filter(Boolean))];
|
|
165
165
|
const home = resolveHome();
|
|
166
|
-
const
|
|
166
|
+
const codexHome = sources.includes('codex') ? resolveCodexHome(home) : path.join(home, '.codex');
|
|
167
|
+
const data = await require('./sessions.cjs').readSessions({ home, codexHome, projectDir: root, allProjects, sources, limit: 20, privateTerms: terms });
|
|
167
168
|
const now = new Date().toISOString();
|
|
168
169
|
const text = digestText(data, entries, { sources, home, terms, now });
|
|
169
170
|
const folder = probe(root, FOLDER, 'dir');
|
package/bin/sessions.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
4
|
const path = require('node:path');
|
|
5
|
-
const { resolveHome } = require('./home.cjs');
|
|
5
|
+
const { resolveHome, resolveCodexHome, walkRealChain } = require('./home.cjs');
|
|
6
6
|
const crypto = require('node:crypto');
|
|
7
7
|
|
|
8
8
|
const MAX_LINE = 8 * 1024 * 1024;
|
|
@@ -221,8 +221,19 @@ async function discover(home, sources, state) {
|
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
if (sources.has('codex')) {
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
let app = state.codexHome || path.join(home, '.codex');
|
|
225
|
+
let chainOk = true;
|
|
226
|
+
if (app !== path.join(home, '.codex')) {
|
|
227
|
+
try {
|
|
228
|
+
const chain = walkRealChain(app, { allowDarwinRootLink: true, action: 'skipped' });
|
|
229
|
+
if (chain.missingDirs.length) chainOk = false;
|
|
230
|
+
else app = chain.dir;
|
|
231
|
+
} catch (err) {
|
|
232
|
+
bump(state, /is a symlink/.test(err.message) ? 'symlink' : 'non_regular');
|
|
233
|
+
chainOk = false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (chainOk && await statPath(app, 'directory', state)) {
|
|
226
237
|
async function walk(dir) {
|
|
227
238
|
for (const name of await children(dir, state)) {
|
|
228
239
|
const file = path.join(dir, name);
|
|
@@ -269,10 +280,26 @@ async function discover(home, sources, state) {
|
|
|
269
280
|
}
|
|
270
281
|
|
|
271
282
|
async function safeOpen(file, state) {
|
|
272
|
-
// Recheck each path within HOME immediately before opening to catch replaced links.
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
|
|
283
|
+
// Recheck each path within HOME (or active CODEX_HOME) immediately before opening to catch replaced links.
|
|
284
|
+
let codexRoot = null;
|
|
285
|
+
if (state.codexHome && state.codexHome !== path.join(state.home, '.codex')) {
|
|
286
|
+
try {
|
|
287
|
+
const chain = walkRealChain(state.codexHome, { allowDarwinRootLink: true, action: 'skipped' });
|
|
288
|
+
if (!chain.missingDirs.length) codexRoot = chain.dir;
|
|
289
|
+
} catch { return null; }
|
|
290
|
+
}
|
|
291
|
+
const roots = codexRoot ? [codexRoot, state.home] : [state.home];
|
|
292
|
+
let baseRoot = null, relative = null;
|
|
293
|
+
for (const candidateRoot of roots) {
|
|
294
|
+
const rel = path.relative(candidateRoot, file);
|
|
295
|
+
if (!rel.startsWith(`..${path.sep}`) && rel !== '..' && !path.isAbsolute(rel)) {
|
|
296
|
+
baseRoot = candidateRoot;
|
|
297
|
+
relative = rel;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (!baseRoot) return null;
|
|
302
|
+
let current = baseRoot;
|
|
276
303
|
if (!await statPath(current, 'directory', state)) return null;
|
|
277
304
|
const parts = relative.split(path.sep);
|
|
278
305
|
for (const name of parts.slice(0, -1)) {
|
|
@@ -602,12 +629,16 @@ async function readMemory(file, state) {
|
|
|
602
629
|
return { file: file.file, text, date: new Date(file.mtimeMs).toISOString() };
|
|
603
630
|
}
|
|
604
631
|
|
|
605
|
-
async function readSessions({ home
|
|
632
|
+
async function readSessions({ home, codexHome, projectDir = process.cwd(), allProjects = false, sources = [], limit = 20, privateTerms = [] } = {}) {
|
|
606
633
|
const selectedSources = new Set(Array.isArray(sources) ? sources.filter(source => SOURCES.has(source)) : []);
|
|
607
634
|
const maximum = Number.isInteger(limit) && limit >= 0 ? Math.min(limit, 20) : 20;
|
|
608
635
|
projectDir = path.resolve(projectDir);
|
|
636
|
+
const resolvedHome = path.resolve(resolveHome(home));
|
|
637
|
+
const resolvedCodexHome = codexHome !== undefined
|
|
638
|
+
? path.resolve(resolveCodexHome(resolvedHome, codexHome))
|
|
639
|
+
: (home === undefined ? path.resolve(resolveCodexHome(resolvedHome)) : path.join(resolvedHome, '.codex'));
|
|
609
640
|
const state = {
|
|
610
|
-
home:
|
|
641
|
+
home: resolvedHome, codexHome: resolvedCodexHome, projectDir, allProjects,
|
|
611
642
|
geminiProjectHash: crypto.createHash('sha256').update(projectDir).digest('hex'),
|
|
612
643
|
candidates: [], memoryFiles: [], filesRead: [], filesChecked: 0, skipped: {},
|
|
613
644
|
privateTerms: Array.isArray(privateTerms) ? privateTerms.filter(term => typeof term === 'string' && fold(term).trim()).map(fold) : []
|
package/docs/companions.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Companion tools
|
|
2
2
|
|
|
3
|
-
This repo tells an AI *how to behave with you*. Two companions govern
|
|
3
|
+
This repo tells an AI *how to behave with you*. Two optional companions govern operations routed through them. Properly configured, they enforce folder ACLs, approval gates or context receipts on calls through that companion; they do not block direct filesystem tools, shell commands or other connectors unless your host's own tool permissions or OS sandbox restrict those paths.
|
|
4
4
|
|
|
5
|
-
| Your saved setting |
|
|
5
|
+
| Your saved setting | Without a companion | Through a configured companion |
|
|
6
6
|
|---|---|---|
|
|
7
7
|
| **Always ask before** delete / publish / send / spend | the AI remembering | obsidian-tc: destructive tools fail closed until a human confirms |
|
|
8
8
|
| **Off limits** folders | the AI remembering | obsidian-tc: folder ACL deny, per caller |
|
|
@@ -27,7 +27,7 @@ npx obsidian-tc /path/to/vault
|
|
|
27
27
|
```
|
|
28
28
|
Lexical search and every note tool work immediately; semantic and graph retrieval need an embeddings backend (Ollama by default). Also ships as a Docker image, an `.mcpb` bundle, and standalone binaries.
|
|
29
29
|
|
|
30
|
-
**How it pairs with this repo.** Answer `notes_tool: obsidian` and `obsidian_tc: yes` and the rendered `AGENT_ONBOARDING.md` tells the AI to reach the vault through obsidian-tc rather than the filesystem; your **off-limits** and **always-ask** answers
|
|
30
|
+
**How it pairs with this repo.** Answer `notes_tool: obsidian` and `obsidian_tc: yes` and the rendered `AGENT_ONBOARDING.md` tells the AI to reach the vault through obsidian-tc rather than the filesystem; your **off-limits** and **always-ask** answers map to the folder ACL and human-in-the-loop list you configure in obsidian-tc. Calls routed through obsidian-tc enforce those rules; disable or sandbox raw filesystem and shell access in your AI host if you want the agent confined to that door. Answer `obsidian_tc: no` (the default) and the AI works on the vault folder directly, with the onboarding file naming what obsidian-tc would add.
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
@@ -43,7 +43,7 @@ Lexical search and every note tool work immediately; semantic and graph retrieva
|
|
|
43
43
|
- **Write policy** "logs and inbox only" or "ask before every write" is the Layer's rule that memory writes remain proposals until approved.
|
|
44
44
|
- **Off limits** is the Layer's vault stage: originals that never enter a bundle.
|
|
45
45
|
- **Always ask before** is the Layer's decide stage: allow, reduce, approve or deny by action and recipient.
|
|
46
|
-
Running several agents is where it earns its keep (the hand-off layer, which this repo does not install): each delegation carries a purpose-bound bundle and returns a receipt, so you can answer "who saw what, and why" after the fact. The repo's `AGENT_ONBOARDING.md` is the human-readable policy; the Context Layer
|
|
46
|
+
Running several agents is where it earns its keep (the hand-off layer, which this repo does not install): each delegation carries a purpose-bound bundle and returns a receipt, so you can answer "who saw what, and why" after the fact. The repo's `AGENT_ONBOARDING.md` is the human-readable policy; the Context Layer enforces and records it for context bundles and actions mediated by the Layer, alongside whatever host permissions or sandboxing govern direct local tools.
|
|
47
47
|
|
|
48
48
|
---
|
|
49
49
|
|
|
@@ -51,7 +51,7 @@ Running several agents is where it earns its keep (the hand-off layer, which thi
|
|
|
51
51
|
|
|
52
52
|
| `notes_tool` answer | How an AI reaches it | Write posture rendered into the onboarding file |
|
|
53
53
|
|---|---|---|
|
|
54
|
-
| `obsidian` | obsidian-tc (above) when `obsidian_tc: yes`, else the vault folder on disk | your write policy
|
|
54
|
+
| `obsidian` | obsidian-tc (above) when `obsidian_tc: yes`, else the vault folder on disk | your write policy; enforced on obsidian-tc calls when its ACL is configured (host permissions still govern direct disk tools) |
|
|
55
55
|
| `logseq` / `folder` | the folder on disk | your write policy, under each folder's README |
|
|
56
56
|
| `notion` | Notion's own MCP connector | writes only into the pages or databases you name; the AI proposes new top-level pages, never creates them unasked |
|
|
57
57
|
| `google-docs` | the Google Drive / Docs connector | the AI drafts into a doc named for the topic and never edits a shared doc's existing text without being asked |
|
package/docs/guarantees.md
CHANGED
|
@@ -21,12 +21,12 @@ The check measures rendered-file consistency. The [instruction tiers](tiers.md)
|
|
|
21
21
|
The installer validates answers, configuration, source files and target marker structure before its write phase. The renderer validates its full target plan before replacing files.
|
|
22
22
|
|
|
23
23
|
- **Paths:** paths beneath the installation root must be real files and directories. Symlinks and paths outside the root are refused. Local notes paths must sit outside tool-owned paths, including `.agent-personalizer/`.
|
|
24
|
-
- **Git
|
|
24
|
+
- **Git metadata:** local Git metadata in an enclosing Git work tree is the only write target outside the installed folder, and is never committed. On install, the installer adds `USER.md`, `LEARNED.md`, `.agent-personalizer.json` and the ChatGPT paste files to the repo's `.git/info/exclude` (the path `git rev-parse --git-path info/exclude` names) in one block marked with the install folder; re-runs replace that block. At level 3, passing `--precommit` also wraps the repo's local `hooks/pre-commit` and preserves any prior hook as `pre-commit.agent-personalizer-original` (see [Forbidden-string gate](#forbidden-string-gate)). A folder git already ignores is left alone, a symlinked or unwritable exclude file gets a warning instead, and so does a private file git already tracks. `CLAUDE.md`, `AGENTS.md`, `GEMINI.md` and `AGENT_ONBOARDING.md` stay committable with a note to review them.
|
|
25
25
|
- **Markers:** each target may have one correctly ordered generated block or be ready for its first block. Malformed blocks are refused.
|
|
26
26
|
- **Encoding:** sources and targets must contain valid UTF-8; invalid bytes are refused instead of re-encoded.
|
|
27
27
|
- **Existing work:** edited and pre-existing profiles, notes templates, rules and tools are kept and named. Untouched installer-owned files update to the current answers and package. Obsolete untouched copies are removed; edited copies stay and are named.
|
|
28
28
|
- **Recovery:** the installer validates its complete plan before writing and restores changed files on failure. The renderer stages targets and their ownership configuration together with backups and rolls back a failed write. An incomplete restore keeps and names its backup with exit `2`.
|
|
29
|
-
- **Local operation:** the tool uses HOME to find the AI apps' folders. Before consent, it may check whether `~/.claude`, `~/.codex` and `~/.gemini` exist for target pre-selection; it opens or lists their contents only after a yes. A non-interactive install and a re-run never read sessions. The tool makes no network calls and sends no telemetry. `npx` fetches the package before execution.
|
|
29
|
+
- **Local operation:** the tool uses `HOME` (and `CODEX_HOME` when set) to find the AI apps' folders. Before consent, it may check whether `~/.claude`, `~/.codex` (or `$CODEX_HOME`) and `~/.gemini` exist for target pre-selection; it opens or lists their contents only after a yes. A non-interactive install and a re-run never read sessions. The tool makes no network calls and sends no telemetry. `npx` fetches the package before execution.
|
|
30
30
|
|
|
31
31
|
On a re-run, each home-file line that byte-matches the previous template is migrated to the new template or removed when obsolete. An edited pointer stays byte for byte and is named with its file and line for manual review. Other outer text stays byte for byte. The renderer owns only the marked block.
|
|
32
32
|
|
|
@@ -82,4 +82,4 @@ To make those answers govern tool access, configure a [companion](companions.md)
|
|
|
82
82
|
- **obsidian-tc:** folder access controls and human approval for destructive Obsidian operations.
|
|
83
83
|
- **The Context Layer:** purpose-bound context, approval decisions and receipts for actions and disclosures.
|
|
84
84
|
|
|
85
|
-
These controls live in the companion's configuration. Saved onboarding answers record the policy and render the instructions that refer to it.
|
|
85
|
+
These controls live in the companion's configuration and apply to calls routed through that companion; direct filesystem, shell or other connector access still depends on your AI host's tool permissions and sandbox. Saved onboarding answers record the policy and render the instructions that refer to it.
|
package/docs/install.md
CHANGED
|
@@ -93,7 +93,7 @@ npx agent-personalizer --global --uninstall --dry
|
|
|
93
93
|
npx agent-personalizer --global --uninstall
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
`--global` keeps the level-1 profile source (`USER.md`, `LEARNED.md`, onboarding and configuration) in `~/.agent-personalizer/`. It writes a marked block to `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md
|
|
96
|
+
`--global` keeps the level-1 profile source (`USER.md`, `LEARNED.md`, onboarding and configuration) in `~/.agent-personalizer/`. It writes a marked block to `~/.claude/CLAUDE.md`, `~/.codex/AGENTS.md` (or `$CODEX_HOME/AGENTS.md` when `CODEX_HOME` is set to a non-empty absolute path), `~/.gemini/GEMINI.md` and `~/.hermes/SOUL.md` for the selected targets. When a non-empty `AGENTS.override.md` exists in the active Codex home, Codex gives it precedence over `AGENTS.md`; the installer warns without modifying the override. For Hermes in a project, use `--ai agents` to write `AGENTS.md`. Hermes reads its global `SOUL.md` from `HERMES_HOME` when set; the installer warns if that differs from `~/.hermes`. Paths use `HOME`, with `USERPROFILE` as the Windows fallback when `HOME` is missing or empty. `HOME` (and `CODEX_HOME` when set) must be a non-empty absolute path, never a symlink. Global instructions name the profile's full path so they work from any project. Start a new AI session to load them; client instruction precedence still applies.
|
|
97
97
|
|
|
98
98
|
Select only `claude`, `agents`, `gemini` and `hermes`. Other targets, `--dir` and levels 2/3 are refused. A headless first install needs `--ai` and `--yes`; level 1 is implicit. `--answers` and `--defaults` work as with project installs. A re-run keeps saved targets and answers.
|
|
99
99
|
|
package/docs/learning.md
CHANGED
|
@@ -18,8 +18,8 @@ that Claude Code, Codex and Gemini CLI still keep, to find corrections you repea
|
|
|
18
18
|
· Other people's details in there? Add their names to your private list first.
|
|
19
19
|
· Delete it any time: npx agent-personalizer learn --forget
|
|
20
20
|
(your AI app's own history stays as it is)
|
|
21
|
-
· Codex
|
|
22
|
-
They
|
|
21
|
+
· Local Codex memory notes from your Codex home are included when you choose Codex.
|
|
22
|
+
They span sessions on this machine (or connected host), not just this folder.
|
|
23
23
|
· When your AI reads the file, its provider sees these messages again.
|
|
24
24
|
· Work or client accounts: check your agreement before reusing their sessions.
|
|
25
25
|
· Not affiliated with Anthropic, OpenAI or Google. Their formats can change.
|
|
@@ -43,13 +43,13 @@ The saved AI selection chooses the sources. The reader takes up to 20 of the new
|
|
|
43
43
|
| Selected target | Local source |
|
|
44
44
|
|---|---|
|
|
45
45
|
| `claude` | Claude Code: `~/.claude/projects/<project>/<session>.jsonl`, directly inside each project folder |
|
|
46
|
-
| `agents` | Codex: `~/.codex/sessions/**/rollout-*.jsonl`, plus `~/.codex/memories/*.md` and `~/.codex/memories_v2/**/*.md` |
|
|
46
|
+
| `agents` | Codex: `~/.codex/sessions/**/rollout-*.jsonl`, plus `~/.codex/memories/*.md` and `~/.codex/memories_v2/**/*.md` (or under `$CODEX_HOME` when set) |
|
|
47
47
|
| `gemini` | Gemini CLI: `~/.gemini/tmp/<slug-or-hash>/chats/session-*.jsonl` (and `.json`), `~/.cache/.gemini/tmp/<slug>/chats/` when sandboxed, and older `logs.json` |
|
|
48
48
|
| `chatgpt`, `prompt` | No local session reader |
|
|
49
49
|
|
|
50
50
|
By default, only sessions associated with the `--dir` folder or one of its subfolders are included. Claude Code and Codex sessions are matched by their recorded working directory; Gemini CLI resolves project slugs from `~/.gemini/projects.json` and `.project_root` markers, with its legacy SHA-256 project folder as a fallback. If a session does not provide enough path information to match it safely, it is skipped. Use `npx agent-personalizer learn --dir . --all-projects` to include sessions from every project.
|
|
51
51
|
|
|
52
|
-
The digest contains typed user messages and, when Codex is selected, up to 20 of the newest Codex memory files in a separate section. These memory notes
|
|
52
|
+
The digest contains typed user messages and, when Codex is selected, up to 20 of the newest Codex memory files in a separate section. These memory notes live in the local Codex store for this machine or connected host (`~/.codex` or `$CODEX_HOME`), so they span local Codex work beyond this folder rather than syncing across your OpenAI account. AI replies, tool output, reasoning, automation sessions and injected context are dropped. Messages and memory notes over 2,000 characters are dropped whole. Gemini chat records reconstruct final conversation state across append-only records, snapshots, patches and rewinds; a message repeated in the chat and logs is included once. The all-projects option affects session history; the memory file limit still applies.
|
|
53
53
|
|
|
54
54
|
The reader streams session files, skips oversized lines and stops a file at its size limit. Symlinks, unreadable files, other-project sessions and unknown or malformed formats are skipped and counted. Codex session headers are inspected to determine their project; message content from other projects is not scanned. The terminal lists files read and skip counts; message text is never printed there. Vendor format changes may mean fewer usable sessions until the reader is updated.
|
|
55
55
|
|
|
@@ -81,7 +81,7 @@ Each question includes a count and one short quote, such as "You've asked me to
|
|
|
81
81
|
- digest: <ISO timestamp>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
Confirmed entries reach `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, the ChatGPT paste exports and the session-start contract. Declined entries become a "Never ask again" list; the
|
|
84
|
+
Confirmed entries reach `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, global `SOUL.md` when Hermes is selected, the ChatGPT paste exports and the session-start contract. Declined entries become a "Never ask again" list; ChatGPT exports include the complete declined list in full, flag `OVER BUDGET` in the preview when a box exceeds its target limit, and refuse to write when `--strict` is passed. Proposed entries render nowhere. The shareable system prompt carries no entries.
|
|
85
85
|
|
|
86
86
|
After recording answers, the AI marks the digest as asked and re-renders. If it has no shell, it asks you to run `npx agent-personalizer --dir .`. At level 3 you can run `node render/render.cjs --dir .` and `node render/render.cjs --dir . --check`. Re-paste changed ChatGPT exports. As you work, a second correction of the same thing prompts one evidence-backed "Make it a rule?" question.
|
|
87
87
|
|
package/docs/paste-guide.md
CHANGED
|
@@ -5,8 +5,8 @@ The renderer writes one file per AI. This page says where each AI reads it, and
|
|
|
5
5
|
| Rendered file | Who reads it | How it is read |
|
|
6
6
|
|---|---|---|
|
|
7
7
|
| `CLAUDE.md` | Claude Code | Automatically, from the project, or `~/.claude/CLAUDE.md` for every project with `--global`. Nothing to paste. |
|
|
8
|
-
| `AGENT_ONBOARDING.md` | any AI | Named as the second thing to read in `CLAUDE.md`, `AGENTS.md` and `GEMINI.md`. Paste it
|
|
9
|
-
| `AGENTS.md` | Codex CLI, Cursor, Hermes Agent, and other agents that adopted the AGENTS.md convention | Automatically, from the repository root; `--global` writes `~/.codex/AGENTS.md` for all projects. Nothing to paste. |
|
|
8
|
+
| `AGENT_ONBOARDING.md` | any AI | Named as the second thing to read in `CLAUDE.md`, `AGENTS.md` and `GEMINI.md`. Paste or upload it where the AI does not read your local folder directly (below). |
|
|
9
|
+
| `AGENTS.md` | Codex CLI, Cursor, Hermes Agent, and other agents that adopted the AGENTS.md convention | Automatically, from the repository root; `--global` writes `~/.codex/AGENTS.md` (or `$CODEX_HOME/AGENTS.md` when `CODEX_HOME` is set) for all projects. Nothing to paste. |
|
|
10
10
|
| `GEMINI.md` | Gemini CLI and Google Antigravity | Automatically, from the folder; `--global` writes `~/.gemini/GEMINI.md` for all projects (also read by Google Antigravity alongside `~/.gemini/config/GEMINI.md`). Nothing to paste. |
|
|
11
11
|
| `SOUL.md` | Hermes Agent | `--global --ai hermes` appends a marked block to `~/.hermes/SOUL.md`. In a project, use `--ai agents` for `AGENTS.md`. A different `HERMES_HOME` changes where Hermes reads the global file. |
|
|
12
12
|
| `chatgpt-box1.txt`, `chatgpt-box2.txt` and `chatgpt-custom-instructions.md` | ChatGPT | Profile and response text to paste, with a preview and counts. |
|
|
@@ -32,24 +32,25 @@ Re-paste after every re-render. `--check` verifies the files on disk; it cannot
|
|
|
32
32
|
|
|
33
33
|
## ChatGPT
|
|
34
34
|
|
|
35
|
-
Open Settings → Personalization and enable customization. Copy the exported profile and response instructions into the fields your current interface provides, checking its displayed limits.
|
|
35
|
+
Open Settings → Personalization (or Settings → Customize ChatGPT on iOS and Android) and enable customization. Copy the exported profile and response instructions into the fields your current interface provides, checking its displayed limits.
|
|
36
36
|
|
|
37
37
|
- **Profile:** `chatgpt-box1.txt` is the plain profile text. An edited or pre-existing `USER.md` is its source too. Confirmed entries from `LEARNED.md` reach the ChatGPT exports.
|
|
38
38
|
- **Response instructions:** `chatgpt-box2.txt` is the plain onboarding and selected rule text.
|
|
39
39
|
- **Preview:** `chatgpt-custom-instructions.md` carries both exports inside fences with their character counts.
|
|
40
40
|
|
|
41
|
-
The configured baseline budget is 1,500 characters per export in `render/targets.json`: ChatGPT Free and Go accounts cap
|
|
41
|
+
The configured baseline budget is 1,500 characters per export in `render/targets.json`: ChatGPT Free and Go accounts cap Custom Instructions at 1,500 characters, while Plus, Pro, Business, Enterprise and Edu accounts allow up to 5,000 characters under Settings → Personalization (`More about you` and `Custom instructions`; `Customize ChatGPT` on mobile). With onboarding answers, box 1 compacts the generated profile while its structure still parses, and preserves custom profile text in full when it does not. Box 2 places the onboarding block (always-ask, off-limits, write policy, then style) before the selected session rules. Confirmed entries and declined "Never ask again" entries are both appended in full; nothing is truncated silently. Proposed entries are omitted. The preview reports each count; over-budget text is written in full and flagged `OVER BUDGET`, while `--strict` refuses the write. Review the text against your account's displayed limits. Account-level Custom Instructions do not read your local project folder directly, whereas file access in ChatGPT depends on the surface, uploads and enabled tools; for the full onboarding, entries and rule source in a ChatGPT Project, upload `AGENT_ONBOARDING.md`, `LEARNED.md` and `rules/` as project files (or add Project instructions under Project settings).
|
|
42
42
|
|
|
43
43
|
## Codex CLI
|
|
44
44
|
|
|
45
45
|
Run the installer at the repo root, then start Codex in that project. Codex builds its instruction chain once per run:
|
|
46
46
|
|
|
47
|
-
- **Global guidance:** the first non-empty `AGENTS.override.md` or `AGENTS.md` in the Codex home directory
|
|
47
|
+
- **Global guidance:** the first non-empty `AGENTS.override.md` or `AGENTS.md` in the Codex home directory (`~/.codex`, or `$CODEX_HOME` when set). `--global --ai agents` writes to that effective Codex home and warns without modifying `AGENTS.override.md` when a non-empty override shadows `AGENTS.md`.
|
|
48
48
|
- **Project guidance:** files from the repository root down to the working directory are merged in that order. Deeper files take precedence over earlier guidance. With no project root, discovery checks the working directory.
|
|
49
|
-
- **Per directory:** `AGENTS.override.md` is tried before `AGENTS.md`, followed by configured fallback filenames. At most one file is selected per directory.
|
|
49
|
+
- **Per directory:** `AGENTS.override.md` is tried before `AGENTS.md`, followed by configured fallback filenames. At most one file is selected per directory; project installs warn if a non-empty `AGENTS.override.md` in the target folder shadows `AGENTS.md`.
|
|
50
50
|
- **Size cap:** the combined guidance has a default limit of 32 KiB, configurable with `project_doc_max_bytes`.
|
|
51
|
+
- **Verify in a fresh session:** run `codex --ask-for-approval never "Summarize the current instructions."` (or `"List the instruction sources you loaded."`) from your repository root, check `echo $CODEX_HOME` if global guidance is missing, or inspect `codex -c log_dir=./.codex-log` (`./.codex-log/codex-tui.log`) to confirm which instruction files loaded.
|
|
51
52
|
|
|
52
|
-
Verified against [OpenAI's Codex AGENTS.md documentation](https://
|
|
53
|
+
Verified against [OpenAI's Codex AGENTS.md documentation](https://developers.openai.com/codex/guides/agents-md) on 2026-11-18. Restart Codex after an update so it rebuilds the instruction chain.
|
|
53
54
|
|
|
54
55
|
## Cursor
|
|
55
56
|
|
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.10.
|
|
3
|
+
Tier 3 from the tiers doc (https://github.com/aunysillyme/agent-personalizer/blob/v0.10.1/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-personalizer",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
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",
|
package/render/onboarding.cjs
CHANGED
|
@@ -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.10.
|
|
20
|
+
const VERSION = '0.10.1';
|
|
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
|
@@ -412,7 +412,7 @@ function renderTarget(key, target, profile, rules, cfg, root, learned, boilerpla
|
|
|
412
412
|
lines.push('### Box 1: Profile ("More about you" / "What would you like ChatGPT to know about you?")', '', '_Copy only the text inside the fence below (or paste the whole of `chatgpt-box1.txt`, the same text as a plain file)._', '', f1, box1, f1, warn('Box 1', box1), '');
|
|
413
413
|
lines.push('### Box 2: Response instructions ("Custom instructions" / "How would you like ChatGPT to respond?")', '', '_Copy only the text inside the fence below (or paste the whole of `chatgpt-box2.txt`)._', '', f2, box2, f2, warn('Box 2', box2));
|
|
414
414
|
if (!answers) lines.push('', '> No onboarding answers in `.agent-personalizer.json`, so this is the full profile and every rule. Run the installer for the compact, budgeted form.');
|
|
415
|
-
else lines.push('', `>
|
|
415
|
+
else lines.push('', `> Account-level Custom Instructions do not read your local project folder directly (file access in ChatGPT depends on the surface, uploads and enabled tools), so only the rules marked \`inject: true\` are included here (${picked.length}). Free and Go plans allow up to 1,500 characters in Custom Instructions; Plus, Pro, Business, Enterprise and Edu plans allow up to 5,000 characters (check the limits and field names shown in Settings → Personalization, or Customize ChatGPT on mobile). The remaining rules live in \`rules/\`; for a ChatGPT Project, upload \`AGENT_ONBOARDING.md\`, \`LEARNED.md\` and \`rules/\` as project files.`);
|
|
416
416
|
renderTarget.overBudget = (renderTarget.overBudget || []).concat(over.map(l => `${target.file}: ${l}`));
|
|
417
417
|
return lines.join('\n');
|
|
418
418
|
}
|