agent-personalizer 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/home.cjs ADDED
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+ const { Refusal } = require('../render/render.cjs');
4
+
5
+ function resolveHome(home = process.env.HOME) {
6
+ if (process.platform === 'win32' && (home === undefined || home === '')) home = process.env.USERPROFILE;
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(home || '');
9
+ if (typeof home !== 'string' || !home || !path.isAbsolute(home) || !rooted) {
10
+ throw new Refusal('HOME (or USERPROFILE on Windows) must be set to a non-empty absolute path; nothing was written');
11
+ }
12
+ return home;
13
+ }
14
+
15
+ module.exports = { resolveHome };
@@ -90,7 +90,7 @@ function migrateHome(current, previous, next, markerState) {
90
90
  return { text: lines.map(line => line.raw).join(''), edited, changed };
91
91
  }
92
92
 
93
- function installPlan({ answers, level, targets, notesScaffolded }) {
93
+ function installPlan({ answers, level, targets, notesScaffolded, legacyRules = false }) {
94
94
  const base = onboarding.baseFor(answers);
95
95
  const kind = onboarding.kindOf(answers);
96
96
  const plan = []; // { rel, src | text }
@@ -127,7 +127,12 @@ function installPlan({ answers, level, targets, notesScaffolded }) {
127
127
  let t = fs.readFileSync(path.join(PKG, 'templates', name), 'utf8');
128
128
  if (level < 3) {
129
129
  // no local rules/: the pointers point at the rendered block below, which carries the full text
130
- t = t.split('\n').filter(l => !/Rules, one file each, the owning copy/.test(l)).join('\n');
130
+ const core = require('../render/render.cjs').CORE_RULE_FILES;
131
+ t = t.split('\n').filter(l => {
132
+ if (/Rules, one file each, the owning copy/.test(l)) return false;
133
+ const rule = /\[owner: rules\/([^\]]+)\]/.exec(l);
134
+ return legacyRules || !rule || core.has(rule[1]);
135
+ }).join('\n');
131
136
  t = t.replace(/`\[owner: rules\/[^\]]+\]`/g, '`[owner: the rendered block below]`');
132
137
  }
133
138
  if (notesWhy) {
@@ -52,6 +52,9 @@
52
52
  },
53
53
  "v0.7.2": {
54
54
  "original": "ba6495eedfff5c5ea3658e4b7c4072f7505b0860414d67150e090366ca87e772"
55
+ },
56
+ "v0.8.4": {
57
+ "original": "ba6495eedfff5c5ea3658e4b7c4072f7505b0860414d67150e090366ca87e772"
55
58
  }
56
59
  },
57
60
  "check/gate.cjs": {
@@ -99,6 +102,9 @@
99
102
  },
100
103
  "v0.7.2": {
101
104
  "original": "52e959a266d68e1e9f0de1373786bdfb5a7792c093145813623714d7d4f83c86"
105
+ },
106
+ "v0.8.4": {
107
+ "original": "f9e1fb60929fd97cc52df93662b6faa39a022d95d83115c925b7c2047b12ab7c"
102
108
  }
103
109
  },
104
110
  "hooks/README.md": {
@@ -169,6 +175,10 @@
169
175
  "v0.7.2": {
170
176
  "original": "fb1daf41acd72d3bf01fb620b8f8f09f118154b983d634547352b944c07f72bc",
171
177
  "withoutSignature": "fb1daf41acd72d3bf01fb620b8f8f09f118154b983d634547352b944c07f72bc"
178
+ },
179
+ "v0.8.4": {
180
+ "original": "7dbb140c6b56a895500d43c71a95e36b2c8ab90b0a240e2f8a042368fed3ea67",
181
+ "withoutSignature": "7dbb140c6b56a895500d43c71a95e36b2c8ab90b0a240e2f8a042368fed3ea67"
172
182
  }
173
183
  },
174
184
  "hooks/claude-code/session-start.sh": {
@@ -222,6 +232,9 @@
222
232
  },
223
233
  "v0.7.2": {
224
234
  "original": "282024ff74e8a7168c49dcd75e45d61da6709c8901f5f91938fc02cdc7c5cfed"
235
+ },
236
+ "v0.8.4": {
237
+ "original": "282024ff74e8a7168c49dcd75e45d61da6709c8901f5f91938fc02cdc7c5cfed"
225
238
  }
226
239
  },
227
240
  "render/onboarding.cjs": {
@@ -269,6 +282,9 @@
269
282
  },
270
283
  "v0.7.2": {
271
284
  "original": "0a06b8fec458b98ed9a5219c02a592d3b3692187d279f2809db6058f7cb2d395"
285
+ },
286
+ "v0.8.4": {
287
+ "original": "eda6c3c068afed1ad195b6a5824e3feacdafb030c4678320634db1a29f74f090"
272
288
  }
273
289
  },
274
290
  "render/render.cjs": {
@@ -316,6 +332,9 @@
316
332
  },
317
333
  "v0.7.2": {
318
334
  "original": "a1ed005b082508c357569212d09f3e72b4b6cf3062c76d18796c6902a7195d1a"
335
+ },
336
+ "v0.8.4": {
337
+ "original": "b460b61a32f1fad0335cdd8cba6aaba25b8da52d0ddaebfd0ad8b06f9b8bedd6"
319
338
  }
320
339
  },
321
340
  "render/targets.json": {
@@ -369,6 +388,9 @@
369
388
  },
370
389
  "v0.7.2": {
371
390
  "original": "070209f11e929c89384d507975086955824014974886e2f84353d8b91d08fc83"
391
+ },
392
+ "v0.8.4": {
393
+ "original": "070209f11e929c89384d507975086955824014974886e2f84353d8b91d08fc83"
372
394
  }
373
395
  },
374
396
  "rules/00-read-the-profile-first.md": {
@@ -439,6 +461,10 @@
439
461
  "v0.7.2": {
440
462
  "original": "3806ff9a3f4bd539d1689c56bfa6397eb29938f9400117cecc1f487cdf6506a2",
441
463
  "withoutSignature": "3806ff9a3f4bd539d1689c56bfa6397eb29938f9400117cecc1f487cdf6506a2"
464
+ },
465
+ "v0.8.4": {
466
+ "original": "b937d12b1987a8b13e8d80ae143e1d7b74f84dda4541c361813367bd2f6002a9",
467
+ "withoutSignature": "b937d12b1987a8b13e8d80ae143e1d7b74f84dda4541c361813367bd2f6002a9"
442
468
  }
443
469
  },
444
470
  "rules/10-evidence-before-assertion.md": {
@@ -509,6 +535,10 @@
509
535
  "v0.7.2": {
510
536
  "original": "ce6f7862af2078617433899aec3419227c116dd2722d47e7234d5b7615e1559d",
511
537
  "withoutSignature": "ce6f7862af2078617433899aec3419227c116dd2722d47e7234d5b7615e1559d"
538
+ },
539
+ "v0.8.4": {
540
+ "original": "ce6f7862af2078617433899aec3419227c116dd2722d47e7234d5b7615e1559d",
541
+ "withoutSignature": "ce6f7862af2078617433899aec3419227c116dd2722d47e7234d5b7615e1559d"
512
542
  }
513
543
  },
514
544
  "rules/20-one-owner-per-rule.md": {
@@ -579,6 +609,10 @@
579
609
  "v0.7.2": {
580
610
  "original": "5268e490404da41e4474a368e9b4ff38ba6375bcbc5c643ee742ceacd9c8535c",
581
611
  "withoutSignature": "5268e490404da41e4474a368e9b4ff38ba6375bcbc5c643ee742ceacd9c8535c"
612
+ },
613
+ "v0.8.4": {
614
+ "original": "5268e490404da41e4474a368e9b4ff38ba6375bcbc5c643ee742ceacd9c8535c",
615
+ "withoutSignature": "5268e490404da41e4474a368e9b4ff38ba6375bcbc5c643ee742ceacd9c8535c"
582
616
  }
583
617
  },
584
618
  "rules/30-folder-index-is-part-of-the-change.md": {
@@ -649,6 +683,10 @@
649
683
  "v0.7.2": {
650
684
  "original": "50863f6b0ea933c6c7209bf4bbfbfc28c7481aabe9001cdd49b730f58dd3010f",
651
685
  "withoutSignature": "50863f6b0ea933c6c7209bf4bbfbfc28c7481aabe9001cdd49b730f58dd3010f"
686
+ },
687
+ "v0.8.4": {
688
+ "original": "50863f6b0ea933c6c7209bf4bbfbfc28c7481aabe9001cdd49b730f58dd3010f",
689
+ "withoutSignature": "50863f6b0ea933c6c7209bf4bbfbfc28c7481aabe9001cdd49b730f58dd3010f"
652
690
  }
653
691
  },
654
692
  "rules/40-sign-every-edit.md": {
@@ -719,6 +757,10 @@
719
757
  "v0.7.2": {
720
758
  "original": "ec73f0d745eb106a3632f22383ecf4ab5f7b0f89657a9dd5f1bf3657c7d96562",
721
759
  "withoutSignature": "ec73f0d745eb106a3632f22383ecf4ab5f7b0f89657a9dd5f1bf3657c7d96562"
760
+ },
761
+ "v0.8.4": {
762
+ "original": "ec73f0d745eb106a3632f22383ecf4ab5f7b0f89657a9dd5f1bf3657c7d96562",
763
+ "withoutSignature": "ec73f0d745eb106a3632f22383ecf4ab5f7b0f89657a9dd5f1bf3657c7d96562"
722
764
  }
723
765
  },
724
766
  "rules/50-output-style.md": {
@@ -789,6 +831,10 @@
789
831
  "v0.7.2": {
790
832
  "original": "56a8f916863e730185c092c5b78750c12fadf926d41e435f151f251d94d933c4",
791
833
  "withoutSignature": "56a8f916863e730185c092c5b78750c12fadf926d41e435f151f251d94d933c4"
834
+ },
835
+ "v0.8.4": {
836
+ "original": "56a8f916863e730185c092c5b78750c12fadf926d41e435f151f251d94d933c4",
837
+ "withoutSignature": "56a8f916863e730185c092c5b78750c12fadf926d41e435f151f251d94d933c4"
792
838
  }
793
839
  },
794
840
  "rules/60-act-or-ask.md": {
@@ -859,6 +905,10 @@
859
905
  "v0.7.2": {
860
906
  "original": "77e3fc8f0064c5f537f4ee6991aef77b865fee756e20c9cab8ccc1137f520b30",
861
907
  "withoutSignature": "77e3fc8f0064c5f537f4ee6991aef77b865fee756e20c9cab8ccc1137f520b30"
908
+ },
909
+ "v0.8.4": {
910
+ "original": "77e3fc8f0064c5f537f4ee6991aef77b865fee756e20c9cab8ccc1137f520b30",
911
+ "withoutSignature": "77e3fc8f0064c5f537f4ee6991aef77b865fee756e20c9cab8ccc1137f520b30"
862
912
  }
863
913
  },
864
914
  "rules/README.md": {
@@ -929,6 +979,34 @@
929
979
  "v0.7.2": {
930
980
  "original": "d5a069dca7b498041992df74bbffd9907b68157709b239cece3d47106862eb48",
931
981
  "withoutSignature": "e6bf5ac7404aaa264a0b7a1889389e891cb759667d99dd5bef803d96440b8607"
982
+ },
983
+ "v0.8.4": {
984
+ "original": "ef9e995f8a72fcaaac48eb1d2bde567a9f39559f64a6b921f924e7f460e76db8",
985
+ "withoutSignature": "534c18e439aced0f80ddaea04db31cf0df01f0cfcce17cfb84e88bffb740ff53"
986
+ }
987
+ },
988
+ "rules/65-ask-before-it-repeats.md": {
989
+ "v0.8.4": {
990
+ "original": "cbb8a463ab3ad3ac0d27a77fc99f98b773b355ce336f9c727ce8bb56c3a27dab",
991
+ "withoutSignature": "cbb8a463ab3ad3ac0d27a77fc99f98b773b355ce336f9c727ce8bb56c3a27dab"
992
+ }
993
+ },
994
+ "rules/70-their-words-point-at-the-thing.md": {
995
+ "v0.8.4": {
996
+ "original": "7d2765cc47762494634a5ec691f7f706ddc6e6f672a99ab8b60eb9d6bdcea505",
997
+ "withoutSignature": "7d2765cc47762494634a5ec691f7f706ddc6e6f672a99ab8b60eb9d6bdcea505"
998
+ }
999
+ },
1000
+ "rules/80-symptoms-are-not-causes.md": {
1001
+ "v0.8.4": {
1002
+ "original": "a6b67644715fa291acfa7db16d169b58599b1b70975a5488b901b332c609cc5d",
1003
+ "withoutSignature": "a6b67644715fa291acfa7db16d169b58599b1b70975a5488b901b332c609cc5d"
1004
+ }
1005
+ },
1006
+ "rules/90-surface-what-they-cant-see.md": {
1007
+ "v0.8.4": {
1008
+ "original": "27f16a59ab223195e8bdec69a92bf6edbd84423ecd85c797bb3288658b5982e1",
1009
+ "withoutSignature": "27f16a59ab223195e8bdec69a92bf6edbd84423ecd85c797bb3288658b5982e1"
932
1010
  }
933
1011
  }
934
1012
  }
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 os = require('os');
5
+ const { resolveHome } = require('./home.cjs');
6
6
  const crypto = require('crypto');
7
7
  const readline = require('readline');
8
8
  const renderer = require('../render/render.cjs');
@@ -155,7 +155,7 @@ async function learn({ dir = '.', yes = false, consented = false, allProjects =
155
155
  const terms = list.exists ? require('../check/gate.cjs').loadList(list.full, { allowEmpty: true }).terms : [];
156
156
  const entries = renderer.readLearned(root);
157
157
  const sources = [...new Set((cfg.targets || []).map(target => SOURCE[target]).filter(Boolean))];
158
- const home = os.homedir();
158
+ const home = resolveHome();
159
159
  const data = await require('./sessions.cjs').readSessions({ home, projectDir: root, allProjects, sources, limit: 20, privateTerms: terms });
160
160
  const now = new Date().toISOString();
161
161
  const text = digestText(data, entries, { sources, home, terms, now });
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 os = require('node:os');
5
+ const { resolveHome } = require('./home.cjs');
6
6
  const crypto = require('node:crypto');
7
7
 
8
8
  const MAX_LINE = 8 * 1024 * 1024;
@@ -249,7 +249,21 @@ function parsedLine(line, state) {
249
249
  }
250
250
 
251
251
  function baseSession(file) {
252
- return { source: file.source, date: new Date(file.mtimeMs).toISOString(), project: file.project, sessionId: path.basename(file.file), file: file.file, mtimeMs: file.mtimeMs, messages: [] };
252
+ return { source: file.source, date: new Date(file.mtimeMs).toISOString(), project: file.project, sessionId: path.basename(file.file), file: file.file, mtimeMs: file.mtimeMs, timestampMs: null, messages: [] };
253
+ }
254
+
255
+ function messageTimestamp(session, timestamp) {
256
+ const iso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/;
257
+ let parsed = NaN;
258
+ if (typeof timestamp === 'string' && iso.test(timestamp)) {
259
+ const calendar = new Date(`${timestamp.slice(0, 10)}T00:00:00Z`);
260
+ if (Number.isFinite(calendar.getTime()) && calendar.toISOString().slice(0, 10) === timestamp.slice(0, 10)) parsed = Date.parse(timestamp);
261
+ } else if (typeof timestamp === 'number' && timestamp >= 1e11) parsed = new Date(timestamp).getTime();
262
+ const time = Math.min(parsed, session.mtimeMs);
263
+ if (Number.isFinite(time) && (session.timestampMs === null || time > session.timestampMs)) {
264
+ session.timestampMs = time;
265
+ session.date = new Date(time).toISOString();
266
+ }
253
267
  }
254
268
 
255
269
  async function readClaude(file, state) {
@@ -261,6 +275,7 @@ async function readClaude(file, state) {
261
275
  if (!record) return;
262
276
  if (typeof record.cwd === 'string') sessionCwd = record.cwd;
263
277
  if (typeof record.entrypoint === 'string' && record.entrypoint.startsWith('sdk')) automation = true;
278
+ if (record.type === 'user' || record.type === 'assistant') messageTimestamp(session, record.timestamp);
264
279
  if (record.type !== 'user') return;
265
280
  known = true;
266
281
  if (!state.allProjects && !belongsToProject(sessionCwd, state.projectDir)) {
@@ -299,7 +314,9 @@ async function readCodex(file, state) {
299
314
  if (typeof meta.cwd === 'string') session.project = path.basename(meta.cwd);
300
315
  return;
301
316
  }
302
- if (record.type !== 'response_item' || !record.payload || record.payload.type !== 'message' || record.payload.role !== 'user') return;
317
+ if (record.type !== 'response_item' || !record.payload || record.payload.type !== 'message') return;
318
+ messageTimestamp(session, record.timestamp);
319
+ if (record.payload.role !== 'user') return;
303
320
  known = true;
304
321
  if (!projectMatches) {
305
322
  if (!state.allProjects) bump(state, 'project_unknown');
@@ -330,7 +347,9 @@ async function readGemini(file, state) {
330
347
  });
331
348
  if (!ok) return [];
332
349
  for (const message of messages) {
333
- if (!message || message.type !== 'user') continue;
350
+ if (!message) continue;
351
+ messageTimestamp(session, message.timestamp);
352
+ if (message.type !== 'user') continue;
334
353
  const items = Array.isArray(message.content) ? message.content.filter(item => item && typeof item.text === 'string' && (!item.type || item.type === 'text')).map(item => item.text) : [];
335
354
  const text = typedText(items, state);
336
355
  if (text) session.messages.push(text);
@@ -346,16 +365,19 @@ async function readGeminiLogs(file, state) {
346
365
  function accept() {
347
366
  if (oversize) { bump(state, 'oversize_line'); return; }
348
367
  const record = parsedLine(entry, state);
349
- if (!record || record.type !== 'user') return;
350
- if (typeof record.sessionId !== 'string' || typeof record.message !== 'string') { bump(state, 'unknown_format'); return; }
351
- const text = typedText([record.message], state);
352
- if (!text) return;
368
+ if (!record || !['user', 'gemini', 'assistant'].includes(record.type)) return;
369
+ if (typeof record.sessionId !== 'string' || (record.type === 'user' && typeof record.message !== 'string')) { bump(state, 'unknown_format'); return; }
353
370
  if (!grouped.has(record.sessionId)) {
354
371
  const session = baseSession(file);
355
372
  session.sessionId = record.sessionId;
356
373
  grouped.set(record.sessionId, session);
357
374
  }
358
- grouped.get(record.sessionId).messages.push(text);
375
+ const session = grouped.get(record.sessionId);
376
+ messageTimestamp(session, record.timestamp);
377
+ if (record.type === 'user') {
378
+ const text = typedText([record.message], state);
379
+ if (text) session.messages.push(text);
380
+ }
359
381
  }
360
382
  const ok = await scanLines(file.file, state, line => {
361
383
  for (const character of `${line}\n`) {
@@ -393,7 +415,7 @@ async function readGeminiLogs(file, state) {
393
415
  if (!ok) return [];
394
416
  if (!started || invalid) { bump(state, 'unknown_format'); return []; }
395
417
  if (!finished || depth) bump(state, 'malformed_line');
396
- return [...grouped.values()];
418
+ return [...grouped.values()].filter(session => session.messages.length);
397
419
  }
398
420
 
399
421
  async function readMemory(file, state) {
@@ -405,12 +427,12 @@ async function readMemory(file, state) {
405
427
  return { file: file.file, text, date: new Date(file.mtimeMs).toISOString() };
406
428
  }
407
429
 
408
- async function readSessions({ home = os.homedir(), projectDir = process.cwd(), allProjects = false, sources = [], limit = 20, privateTerms = [] } = {}) {
430
+ async function readSessions({ home = resolveHome(), projectDir = process.cwd(), allProjects = false, sources = [], limit = 20, privateTerms = [] } = {}) {
409
431
  const selectedSources = new Set(Array.isArray(sources) ? sources.filter(source => SOURCES.has(source)) : []);
410
432
  const maximum = Number.isInteger(limit) && limit >= 0 ? Math.min(limit, 20) : 20;
411
433
  projectDir = path.resolve(projectDir);
412
434
  const state = {
413
- home: path.resolve(home), projectDir, allProjects,
435
+ home: path.resolve(resolveHome(home)), projectDir, allProjects,
414
436
  geminiProjectHash: crypto.createHash('sha256').update(projectDir).digest('hex'),
415
437
  candidates: [], memoryFiles: [], filesRead: [], filesChecked: 0, skipped: {},
416
438
  privateTerms: Array.isArray(privateTerms) ? privateTerms.filter(term => typeof term === 'string' && fold(term).trim()).map(fold) : []
@@ -418,22 +440,33 @@ async function readSessions({ home = os.homedir(), projectDir = process.cwd(), a
418
440
  await discover(state.home, selectedSources, state);
419
441
  state.candidates.sort((a, b) => b.mtimeMs - a.mtimeMs || a.file.localeCompare(b.file));
420
442
  const sessions = [], geminiSessions = new Map();
443
+ // Multiple Gemini files can contribute to the same session, including its fallback timestamp.
444
+ // Keep that full merge; independent sessions admit an mtime bound.
445
+ const bounded = state.candidates.filter(file => file.source === 'gemini-cli').length < 2;
446
+ const sortKey = session => session.timestampMs ?? session.mtimeMs;
447
+ const compare = (a, b) => sortKey(b) - sortKey(a) || a.file.localeCompare(b.file) || a.sessionId.localeCompare(b.sessionId);
421
448
  const readers = { claude: readClaude, codex: readCodex, gemini: readGemini, 'gemini-logs': readGeminiLogs };
422
449
  for (const file of state.candidates) {
423
- if (sessions.length >= maximum) break;
450
+ if (!maximum) break;
451
+ if (bounded && sessions.length === maximum && file.mtimeMs < sortKey(sessions[maximum - 1])) break;
424
452
  const found = await readers[file.format](file, state);
425
453
  for (const session of found) {
426
454
  if (session.source === 'gemini-cli' && geminiSessions.has(session.sessionId)) {
427
455
  const existing = geminiSessions.get(session.sessionId);
456
+ if (session.timestampMs !== null) messageTimestamp(existing, session.timestampMs);
428
457
  for (const text of session.messages) {
429
458
  if (existing.messages.includes(text)) bump(state, 'duplicate_message');
430
459
  else existing.messages.push(text);
431
460
  }
432
- } else if (sessions.length < maximum) {
461
+ } else {
433
462
  if (session.source === 'gemini-cli') geminiSessions.set(session.sessionId, session);
434
463
  sessions.push(session);
435
464
  }
436
465
  }
466
+ sessions.sort(compare);
467
+ if (bounded) for (const session of sessions.splice(maximum)) {
468
+ if (session.source === 'gemini-cli') geminiSessions.delete(session.sessionId);
469
+ }
437
470
  }
438
471
  const memories = [];
439
472
  state.memoryFiles.sort((a, b) => b.mtimeMs - a.mtimeMs || a.file.localeCompare(b.file));
@@ -442,7 +475,7 @@ async function readSessions({ home = os.homedir(), projectDir = process.cwd(), a
442
475
  const memory = await readMemory(file, state);
443
476
  if (memory) memories.push(memory);
444
477
  }
445
- return { sessions, memories, filesRead: state.filesRead, filesChecked: state.filesChecked, skipped: state.skipped };
478
+ return { sessions: sessions.slice(0, maximum), memories, filesRead: state.filesRead, filesChecked: state.filesChecked, skipped: state.skipped };
446
479
  }
447
480
 
448
481
  module.exports = { readSessions };
package/bin/uninstall.cjs CHANGED
@@ -176,7 +176,8 @@ function run(dir, dry) {
176
176
  // later package release changing rules/ or USER.md cannot make an untouched block look
177
177
  // edited (or vice versa).
178
178
  const currentBlock = renderer.between(existing, rel);
179
- const blockUnedited = recorded ? (currentBlock !== null && sha256(Buffer.from(currentBlock)) === recorded) : matchesBlock;
179
+ // Explicit adoption of an older target can record the whole file; its outer text stays user-owned.
180
+ const blockUnedited = recorded ? (currentBlock !== null && (sha256(Buffer.from(currentBlock)) === recorded || sha256(bytes) === recorded)) : matchesBlock;
180
181
  if (blockUnedited) add(rel, 'strip', Buffer.from(stripBlock(existing, ms)), 'pre-existing file; removed only the marked block');
181
182
  else add(rel, 'keep', null, ms.kind === 'none' ? 'pre-existing file; block already absent' : 'edited');
182
183
  continue;
@@ -36,7 +36,7 @@ On a re-run, each home-file line that byte-matches the previous template is migr
36
36
  - **Notes history:** changing the notes path creates the new scaffold and keeps the old folder. The log names both paths once; the recorded files from both remain available to uninstall.
37
37
  - **Tool updates:** a recorded install hash recognizes untouched tools and rules. For older installs without hashes, a shipped table of earlier release hashes recognizes untouched verbatim copies. Edited tools remain intact; the log names the known origin version and the replacement step. The configuration records the installed tooling version.
38
38
  - **Removal inventory:** uninstall checks the union of recorded installed paths across all runs. A matching hash permits removal, a changed file is kept and named, and a missing file is skipped. An unrecorded file is left alone. Legacy configurations without hashes use their known install recipe.
39
- - **Entries and evidence:** uninstall keeps `LEARNED.md` once it holds anything you wrote (an untouched template is removed). It removes a digest and `.gitignore` only with matching creation hashes, and a recorded private folder only when empty. Unrecorded or edited files in that folder stay, including digests from older installs without creation records. `learn --forget` removes only agent-personalizer's digest and its empty folder. Neither changes the AI apps' own history.
39
+ - **Entries and evidence:** uninstall keeps `LEARNED.md` once it holds anything you wrote (an untouched template is removed). It removes the digest and its `.gitignore` only when their bytes match recorded creation hashes, and removes the private folder only when recorded as installer-created and empty. Edited or unrecorded files stay, including digests from older installs without creation records. `learn --forget` removes only agent-personalizer's digest and its empty folder. Neither changes the AI apps' own history.
40
40
  - **Removal paths:** every tracked path is validated before the first unlink and re-probed before each unlink. Removal is file by file. Only recorded install-created, empty directories are removed.
41
41
  - **Configuration last:** the configuration is removed after tracked files are gone. Retained tracked files are named and keep the configuration for review.
42
42
  - **Preview and manual steps:** `--uninstall --dry` makes the same decisions as removal and changes no files. A missing configuration exits `2` naming its path. Hook registration and pasted instructions are printed as manual cleanup steps.
@@ -69,7 +69,7 @@ Learning reads up to 20 recent usable sessions from the selected Claude Code, Co
69
69
 
70
70
  The digest stays in `.agent-personalizer/digest.md`, with its contents ignored by git. Filesystem access, backups and sync services still apply. The terminal prints file names and counts, never message text. The digest is data, and the AI is instructed never to follow instructions within it. When your AI reads it, the contents go to that AI's provider again, like anything you share with it.
71
71
 
72
- Reuse only sessions you are allowed to share. Past messages can contain other people's details; add private terms before accepting. Check employer or client agreements for work accounts. agent-personalizer is not affiliated with Anthropic, OpenAI or Google; their stored formats can change. `learn --forget` and uninstall remove the digest from this install, not copies a provider, backup or sync service already received.
72
+ Reuse only sessions you are allowed to share. Past messages can contain other people's details; add private terms before accepting. Check employer or client agreements for work accounts. agent-personalizer is not affiliated with Anthropic, OpenAI or Google; their stored formats can change. `learn --forget` removes the digest from this install; uninstall removes it only under the recorded-hash conditions above. Neither removes copies a provider, backup or sync service already received.
73
73
 
74
74
  ## Instructions and companions
75
75
 
package/docs/install.md CHANGED
@@ -65,6 +65,7 @@ Use [`examples/answers.json`](../examples/answers.json) as a complete example, i
65
65
  | Flag | Purpose |
66
66
  |---|---|
67
67
  | `--dir <folder>` | Destination folder; prompted in interactive mode. |
68
+ | `--global` | Apply a level-1 profile across projects through Claude Code, Codex and Gemini CLI home files. Excludes `--dir` and levels 2/3. |
68
69
  | `--ai claude,agents,gemini,chatgpt,prompt` | Comma-separated targets. Choose the ones you use. |
69
70
  | `--level 1`, `--level 2`, `--level 3` | Profile and home files; add local notes; add editable rules and mechanisms. |
70
71
  | `--answers <file.json>` or `--answers -` | Set onboarding answers without questions. |
@@ -80,6 +81,26 @@ For compatibility with older scripts, `--level 4` remains an alias of `--level 3
80
81
 
81
82
  Installer exit codes: `0` completed, `1` unexpected error, `2` refused or invalid input.
82
83
 
84
+ ## Every project with one profile
85
+
86
+ ```bash
87
+ npx agent-personalizer --global --ai claude,agents,gemini --yes
88
+ npx agent-personalizer --global
89
+ npx agent-personalizer learn --global --yes
90
+ npx agent-personalizer --global --uninstall --dry
91
+ npx agent-personalizer --global --uninstall
92
+ ```
93
+
94
+ `--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` and `~/.gemini/GEMINI.md` for the selected targets. Paths use `HOME`, with `USERPROFILE` as the Windows fallback when `HOME` is missing or empty. The selected value must be a non-empty absolute path. 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.
95
+
96
+ Select only `claude`, `agents` and `gemini`. 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.
97
+
98
+ Global learning always includes sessions from all projects and still needs consent. Its digest is `~/.agent-personalizer/.agent-personalizer/digest.md`; use `learn --global --forget` to remove it. The learning procedure is included in each selected home file.
99
+
100
+ Global files keep user text outside the markers byte for byte, including line endings and a missing final newline. Existing files and parents must be regular files and directories, never symlinks. The whole plan is checked before writes; a failed write restores changed files and newly created empty directories through the project installer's atomic rename and rollback path.
101
+
102
+ Global uninstall removes unchanged marked blocks and owned profile files. It deletes a home file only if install created it and no other content remains. Edited blocks, profiles and learned entries stay, with the configuration kept for review. Install-created empty directories are removed; other home files and settings stay in place.
103
+
83
104
  ## Learning commands
84
105
 
85
106
  ```bash
@@ -92,11 +113,11 @@ npx agent-personalizer learn --forget --dir .
92
113
 
93
114
  ## What each level adds
94
115
 
95
- - **Level 1:** `USER.md`, `LEARNED.md`, `AGENT_ONBOARDING.md`, the files for your AI targets, and `.agent-personalizer.json`. Claude Code also receives `.claude/commands/personalize.md`. Rules render from the package. With no installed apps detected, the default selection is `claude,agents`.
96
- - **Level 2:** a local notes scaffold with `README.md`, `sessions/TEMPLATE-week.md`, `decisions.md` and `inbox/README.md`. Disk tools use your `notes_path`; read-only and other tools use the local `notes/` fallback. Cloud tools get connector pointers and keep their notes in their service.
97
- - **Level 3:** your editable `rules/` copy, `render/` tools, the Claude Code session-start hook and the forbidden-string gate. [Register the hook](../hooks/README.md) in your AI settings and [configure the gate](guarantees.md#forbidden-string-gate).
116
+ - **Level 1:** `USER.md`, `LEARNED.md`, `AGENT_ONBOARDING.md`, the files for your AI targets, and `.agent-personalizer.json`. Claude Code also receives `.claude/commands/personalize.md`. The Core 5 render from the package: read the profile first, evidence before assertion, output style, act or ask, and ask before it repeats. With no installed apps detected, the default selection is `claude,agents`.
117
+ - **Level 2:** the same five rules, plus a local notes scaffold with `README.md`, `sessions/TEMPLATE-week.md`, `decisions.md` and `inbox/README.md`. Disk tools use your `notes_path`; read-only and other tools use the local `notes/` fallback. Cloud tools get connector pointers and keep their notes in their service.
118
+ - **Level 3:** all eleven rules (subject to target and signature selection), your editable `rules/` copy, `render/` tools, the Claude Code session-start hook and the forbidden-string gate. [Register the hook](../hooks/README.md) in your AI settings and [configure the gate](guarantees.md#forbidden-string-gate).
98
119
 
99
- An existing local notes scaffold is detected at any level. Edited notes and rule files stay yours and are named in the install log. Untouched installer copies update on re-runs. A `signature: no` answer omits the signature rule and its template lines; answering yes includes the signature line.
120
+ An existing local notes scaffold is detected at any level. Edited notes and rule files stay yours and are named in the install log. Untouched installer copies update on re-runs. At level 3, a `signature: no` answer omits the signature rule and its template lines; answering yes includes the signature line.
100
121
 
101
122
  ## Updating an install
102
123
 
@@ -109,6 +130,7 @@ Re-run the installer with `npx agent-personalizer --dir .`. An existing config m
109
130
  - **Re-runs:** untouched installer files converge to the files a fresh install with the new answers would create. Current notes templates and rule copies update together. An obsolete file, such as the signing rule after `signature: no`, is removed only while it is untouched.
110
131
  - **Home pointers:** each line outside the markers that exactly matches the previous install template is updated or removed to match the new answers. An edited line stays byte for byte and the log names its file and line for manual review. Other text outside the markers stays byte for byte.
111
132
  - **Notes path:** when you change `notes_path`, the old folder stays where it is. The log names the old and new folders once. Previously installed files remain in the uninstall inventory; your own notes stay yours.
133
+ - **Core 5 upgrade:** an untouched older level-1/2 generated file shrinks to the five rules on re-run. An edited older file stays byte for byte and the installer prints the exact re-render command for that target. Run that command to take the update, then re-run the installer to adopt the current file and clear the kept notice. Text outside the block stays byte for byte.
112
134
  - **Upgrades:** re-running a newer package refreshes untouched installed tools and rule copies. Recorded hashes establish ownership; older installs without hashes can be recognized from shipped release hashes. Edited copies stay byte for byte. The log identifies the edited file, its known origin version and how to take the new copy. Previously installed levels and targets remain available on a re-run.
113
135
 
114
136
  At level 3, render your edited profile and rules:
@@ -151,7 +173,7 @@ The uninstaller reads `/path/to/project/.agent-personalizer.json` and compares f
151
173
  - **Existing home files:** user text stays; only an unchanged generated block and the blank separator line the installer added are removed, so an untouched file returns byte for byte. (A file that had no final newline before install keeps the one the installer added.)
152
174
  - **`USER.md`:** removed only when it matches its recorded install hash. Edited and pre-existing profiles stay.
153
175
  - **`LEARNED.md`:** kept once it holds anything you wrote, and kept if it existed before install. An untouched template that matches its recorded install hash is removed.
154
- - **Session digest:** `.agent-personalizer/digest.md`, its `.gitignore` and private folder are removed. Your AI apps' history is untouched.
176
+ - **Session digest:** files under `.agent-personalizer/` are removed only when they match recorded install hashes. Edited or unrecorded files stay. The private folder is removed only when recorded as install-created and empty. Your AI apps' history is untouched.
155
177
  - **Notes scaffold:** unchanged historically installed templates are removed. Edited templates are kept and named; user-written notes stay byte for byte. A directory is removed only when the install recorded that it created it and it is empty.
156
178
  - **Git exclude:** after the configuration is removed, the block install added to `.git/info/exclude` for this folder is removed, and the rest of the file stays byte for byte. While an edited file keeps the configuration, the block stays too.
157
179
  - **Rules and tools:** unchanged installed copies are removed file by file, including the session-start hook. Edited copies stay.
package/docs/learning.md CHANGED
@@ -90,7 +90,7 @@ npx agent-personalizer --uninstall --dir . --dry
90
90
  npx agent-personalizer --uninstall --dir .
91
91
  ```
92
92
 
93
- `learn --forget` deletes agent-personalizer's digest and removes its empty private folder. It keeps approved entries. Uninstall removes the digest, its `.gitignore` and private folder, and keeps `LEARNED.md` once it holds anything you wrote; an untouched template is removed. Neither changes the AI apps' own history. To stop questions, decline the consent screen and do not run `learn --yes`; to change an entry, edit its owning line and re-render.
93
+ `learn --forget` deletes agent-personalizer's digest and removes its empty private folder. It keeps approved entries. Uninstall removes the digest and its `.gitignore` only when their bytes match recorded creation hashes, and removes the private folder only when recorded as installer-created and empty. Edited or unrecorded files stay, including digests from older installs without creation records. It keeps `LEARNED.md` once it holds anything you wrote; an untouched template is removed. Neither changes the AI apps' own history. To stop questions, decline the consent screen and do not run `learn --yes`; to change an entry, edit its owning line and re-render.
94
94
 
95
95
  ## How the loop closes
96
96
 
@@ -4,13 +4,15 @@ The renderer writes one file per AI. This page says where each AI reads it, and
4
4
 
5
5
  | Rendered file | Who reads it | How it is read |
6
6
  |---|---|---|
7
- | `CLAUDE.md` | Claude Code | Automatically, from the folder you run it in (and from `~/.claude/CLAUDE.md` for every folder). Nothing to paste. |
7
+ | `CLAUDE.md` | Claude Code | Automatically, from the project, or `~/.claude/CLAUDE.md` for every project with `--global`. Nothing to paste. |
8
8
  | `AGENT_ONBOARDING.md` | any AI | Named as the second thing to read in `CLAUDE.md` and `AGENTS.md`. Paste it wherever the AI has no file access (below). |
9
- | `AGENTS.md` | Codex CLI, Cursor, and other agents that adopted the AGENTS.md convention | Automatically, from the repository root. Nothing to paste. |
10
- | `GEMINI.md` | Gemini CLI | Automatically, from the folder. Nothing to paste. |
9
+ | `AGENTS.md` | Codex CLI, Cursor, 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. |
10
+ | `GEMINI.md` | Gemini CLI | Automatically, from the folder; `--global` writes `~/.gemini/GEMINI.md` for all projects. Nothing to paste. |
11
11
  | `chatgpt-box1.txt`, `chatgpt-box2.txt` and `chatgpt-custom-instructions.md` | ChatGPT | Profile and response text to paste, with a preview and counts. |
12
12
  | `system-prompt.md` | anything with a system-prompt field, shared bots, API calls | Paste as the system prompt. Universal rules only, no profile, safe to share. |
13
13
 
14
+ Use `npx agent-personalizer --global --ai claude,agents,gemini --yes` for one profile across projects. Its source lives in `~/.agent-personalizer/`; re-run with `--global` after editing it and start a new client session. Global mode accepts only these three targets and level 1, excludes `--dir`, preserves text outside its markers and supports `--global --uninstall`. See [global installation](install.md#every-project-with-one-profile).
15
+
14
16
  ---
15
17
 
16
18
  ## Claude Code
@@ -52,6 +52,6 @@
52
52
  "installed": {
53
53
  "CLAUDE.md": "3ea7661f6ea1ad2f23072c20bc952ea0cf3d2acafdc486edee86f095266dc979",
54
54
  "AGENTS.md": "e870580a758b363c07e767e040f683e32890d0248726d0bcd4f0be0d83f3f423",
55
- "AGENT_ONBOARDING.md": "6361496d10eab4eca58017033a2274335ea6982944ff08e92645ff755dd53551"
55
+ "AGENT_ONBOARDING.md": "d4657e01cf5e8f1ac87e29e67e7bd1fe8a43152736611efc3f246ecc99aeb8b5"
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.3/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.8.4/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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  One rule per file. Each file is the owning copy of that rule; everything else points here. `render/render.cjs` turns these files plus `USER.md` into the per-AI instruction files.
4
4
 
5
+ Install levels 1 and 2 render the Core 5: `00-read-the-profile-first.md`, `10-evidence-before-assertion.md`, `50-output-style.md`, `60-act-or-ask.md` and `65-ask-before-it-repeats.md`. Level 3 copies all eleven rules here for editing and renders them with the existing surface and preference filters; the signature rule still follows the signature preference. The source rule files below remain the full set.
6
+
5
7
  ## Format
6
8
 
7
9
  ```markdown
@@ -2,6 +2,8 @@
2
2
 
3
3
  One rule per file. Each file is the owning copy of that rule; everything else points here. `render/render.cjs` turns these files plus `USER.md` into the per-AI instruction files.
4
4
 
5
+ Install levels 1 and 2 render the Core 5: `00-read-the-profile-first.md`, `10-evidence-before-assertion.md`, `50-output-style.md`, `60-act-or-ask.md` and `65-ask-before-it-repeats.md`. Level 3 copies all eleven rules here for editing and renders them with the existing surface and preference filters; the signature rule still follows the signature preference. The source rule files below remain the full set.
6
+
5
7
  ## Format
6
8
 
7
9
  ```markdown
@@ -2,6 +2,8 @@
2
2
 
3
3
  One rule per file. Each file is the owning copy of that rule; everything else points here. `render/render.cjs` turns these files plus `USER.md` into the per-AI instruction files.
4
4
 
5
+ Install levels 1 and 2 render the Core 5: `00-read-the-profile-first.md`, `10-evidence-before-assertion.md`, `50-output-style.md`, `60-act-or-ask.md` and `65-ask-before-it-repeats.md`. Level 3 copies all eleven rules here for editing and renders them with the existing surface and preference filters; the signature rule still follows the signature preference. The source rule files below remain the full set.
6
+
5
7
  ## Format
6
8
 
7
9
  ```markdown
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.3/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.8.4/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.8.3",
3
+ "version": "0.8.4",
4
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.",
5
5
  "author": "aunysillyme (https://github.com/aunysillyme)",
6
6
  "license": "MIT",
@@ -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.3';
20
+ const VERSION = '0.8.4';
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