agent-personalizer 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/CONTRIBUTING.md +3 -3
  3. package/README.md +12 -10
  4. package/RELEASING.md +2 -2
  5. package/SECURITY.md +1 -1
  6. package/bin/agent-personalizer.js +21 -32
  7. package/bin/cli-util.cjs +28 -0
  8. package/bin/global.cjs +4 -4
  9. package/bin/install-plan.cjs +4 -3
  10. package/bin/learn.cjs +10 -3
  11. package/bin/sessions.cjs +195 -35
  12. package/bin/uninstall.cjs +3 -3
  13. package/check/gate.cjs +46 -6
  14. package/docs/guarantees.md +1 -1
  15. package/docs/install.md +6 -6
  16. package/docs/learning.md +7 -7
  17. package/docs/paste-guide.md +8 -6
  18. package/docs/tiers.md +1 -1
  19. package/hooks/README.md +17 -1
  20. package/hooks/gemini-cli/session-start.sh +15 -0
  21. package/llms.txt +6 -4
  22. package/package.json +6 -3
  23. package/render/onboarding.cjs +30 -47
  24. package/render/render.cjs +24 -15
  25. package/rules/00-read-the-profile-first.md +3 -0
  26. package/rules/20-one-owner-per-rule.md +3 -0
  27. package/rules/30-folder-index-is-part-of-the-change.md +3 -0
  28. package/rules/40-sign-every-edit.md +4 -1
  29. package/skills/agent-personalizer/SKILL.md +104 -0
  30. package/templates/GEMINI.md +30 -0
  31. package/examples/freelance-illustrator/.agent-personalizer.json +0 -57
  32. package/examples/freelance-illustrator/AGENTS.md +0 -244
  33. package/examples/freelance-illustrator/AGENT_ONBOARDING.md +0 -67
  34. package/examples/freelance-illustrator/CLAUDE.md +0 -248
  35. package/examples/freelance-illustrator/LEARNED.md +0 -14
  36. package/examples/freelance-illustrator/USER.md +0 -54
  37. package/examples/freelance-illustrator/notes/README.md +0 -39
  38. package/examples/freelance-illustrator/notes/decisions.md +0 -18
  39. package/examples/freelance-illustrator/notes/inbox/2026-09-03-shot-list-for-six-prints.md +0 -14
  40. package/examples/freelance-illustrator/notes/inbox/README.md +0 -19
  41. package/examples/freelance-illustrator/notes/sessions/2026-W36.md +0 -41
  42. package/examples/freelance-illustrator/rules/00-read-the-profile-first.md +0 -24
  43. package/examples/freelance-illustrator/rules/10-evidence-before-assertion.md +0 -24
  44. package/examples/freelance-illustrator/rules/20-one-owner-per-rule.md +0 -24
  45. package/examples/freelance-illustrator/rules/30-folder-index-is-part-of-the-change.md +0 -26
  46. package/examples/freelance-illustrator/rules/40-sign-every-edit.md +0 -25
  47. package/examples/freelance-illustrator/rules/50-output-style.md +0 -21
  48. package/examples/freelance-illustrator/rules/60-act-or-ask.md +0 -30
  49. package/examples/freelance-illustrator/rules/65-ask-before-it-repeats.md +0 -18
  50. package/examples/freelance-illustrator/rules/70-their-words-point-at-the-thing.md +0 -15
  51. package/examples/freelance-illustrator/rules/80-symptoms-are-not-causes.md +0 -15
  52. package/examples/freelance-illustrator/rules/90-surface-what-they-cant-see.md +0 -15
  53. package/examples/freelance-illustrator/rules/README.md +0 -61
  54. package/examples/lab-technician/.agent-personalizer.json +0 -38
  55. package/examples/lab-technician/AGENTS.md +0 -243
  56. package/examples/lab-technician/AGENT_ONBOARDING.md +0 -64
  57. package/examples/lab-technician/CLAUDE.md +0 -247
  58. package/examples/lab-technician/LEARNED.md +0 -14
  59. package/examples/lab-technician/USER.md +0 -53
  60. package/examples/lab-technician/notes/README.md +0 -26
  61. package/examples/lab-technician/notes/decisions.md +0 -4
  62. package/examples/lab-technician/notes/inbox/2026-10-06-observation-table.md +0 -3
  63. package/examples/lab-technician/notes/inbox/README.md +0 -7
  64. package/examples/lab-technician/notes/sessions/2026-W41.md +0 -7
  65. package/examples/lab-technician/rules/00-read-the-profile-first.md +0 -24
  66. package/examples/lab-technician/rules/10-evidence-before-assertion.md +0 -24
  67. package/examples/lab-technician/rules/20-one-owner-per-rule.md +0 -24
  68. package/examples/lab-technician/rules/30-folder-index-is-part-of-the-change.md +0 -26
  69. package/examples/lab-technician/rules/40-sign-every-edit.md +0 -25
  70. package/examples/lab-technician/rules/50-output-style.md +0 -21
  71. package/examples/lab-technician/rules/60-act-or-ask.md +0 -30
  72. package/examples/lab-technician/rules/65-ask-before-it-repeats.md +0 -18
  73. package/examples/lab-technician/rules/70-their-words-point-at-the-thing.md +0 -15
  74. package/examples/lab-technician/rules/80-symptoms-are-not-causes.md +0 -15
  75. package/examples/lab-technician/rules/90-surface-what-they-cant-see.md +0 -15
  76. package/examples/lab-technician/rules/README.md +0 -61
  77. package/examples/product-designer/.agent-personalizer.json +0 -38
  78. package/examples/product-designer/AGENTS.md +0 -243
  79. package/examples/product-designer/AGENT_ONBOARDING.md +0 -63
  80. package/examples/product-designer/CLAUDE.md +0 -247
  81. package/examples/product-designer/LEARNED.md +0 -14
  82. package/examples/product-designer/USER.md +0 -53
  83. package/examples/product-designer/notes/README.md +0 -26
  84. package/examples/product-designer/notes/decisions.md +0 -4
  85. package/examples/product-designer/notes/inbox/2026-10-06-cancellation-wording.md +0 -8
  86. package/examples/product-designer/notes/inbox/README.md +0 -7
  87. package/examples/product-designer/notes/sessions/2026-W41.md +0 -7
  88. package/examples/product-designer/rules/00-read-the-profile-first.md +0 -24
  89. package/examples/product-designer/rules/10-evidence-before-assertion.md +0 -24
  90. package/examples/product-designer/rules/20-one-owner-per-rule.md +0 -24
  91. package/examples/product-designer/rules/30-folder-index-is-part-of-the-change.md +0 -26
  92. package/examples/product-designer/rules/40-sign-every-edit.md +0 -25
  93. package/examples/product-designer/rules/50-output-style.md +0 -21
  94. package/examples/product-designer/rules/60-act-or-ask.md +0 -30
  95. package/examples/product-designer/rules/65-ask-before-it-repeats.md +0 -18
  96. package/examples/product-designer/rules/70-their-words-point-at-the-thing.md +0 -15
  97. package/examples/product-designer/rules/80-symptoms-are-not-causes.md +0 -15
  98. package/examples/product-designer/rules/90-surface-what-they-cant-see.md +0 -15
  99. package/examples/product-designer/rules/README.md +0 -61
package/bin/sessions.cjs CHANGED
@@ -7,6 +7,7 @@ const crypto = require('node:crypto');
7
7
 
8
8
  const MAX_LINE = 8 * 1024 * 1024;
9
9
  const MAX_FILE = 64 * 1024 * 1024;
10
+ const MAX_META = 1024 * 1024;
10
11
  const MAX_MEMORIES = 20;
11
12
  const SOURCES = new Set(['claude-code', 'codex', 'gemini-cli']);
12
13
  const CONTEXT_HEADERS = ['# AGENTS.md instructions', '# Files mentioned by the user', '# Response annotations', '# Browser comments'];
@@ -22,7 +23,9 @@ function claudeProjectNames(projectDir) {
22
23
 
23
24
  function belongsToProject(cwd, projectDir) {
24
25
  if (typeof cwd !== 'string' || !path.isAbsolute(cwd)) return false;
25
- const relative = path.relative(projectDir, path.resolve(cwd));
26
+ const left = process.platform === 'win32' ? path.resolve(projectDir).toLowerCase() : path.resolve(projectDir);
27
+ const right = process.platform === 'win32' ? path.resolve(cwd).toLowerCase() : path.resolve(cwd);
28
+ const relative = path.relative(left, right);
26
29
  return relative === '' || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
27
30
  }
28
31
 
@@ -98,6 +101,16 @@ function textItems(content, type) {
98
101
  return content.filter(item => item && typeof item === 'object' && item.type === type && typeof item.text === 'string').map(item => item.text);
99
102
  }
100
103
 
104
+ function geminiMessageItems(content) {
105
+ if (typeof content === 'string') return [content];
106
+ if (!Array.isArray(content)) return [];
107
+ return content.flatMap(item => {
108
+ if (typeof item === 'string') return [item];
109
+ if (item && typeof item === 'object' && typeof item.text === 'string' && (!item.type || item.type === 'text')) return [item.text];
110
+ return [];
111
+ });
112
+ }
113
+
101
114
  async function statPath(file, kind, state, count = false) {
102
115
  if (count) state.filesChecked += 1;
103
116
  try {
@@ -125,6 +138,70 @@ async function candidate(file, source, project, format, state) {
125
138
  if (stat) state.candidates.push({ file, source, project, format, mtimeMs: stat.mtimeMs });
126
139
  }
127
140
 
141
+ // Streamed bounded read for small metadata files (projects.json, .project_root) without counting as a session file.
142
+ async function readSmallMeta(file, state) {
143
+ const relative = path.relative(state.home, file);
144
+ if (relative.startsWith(`..${path.sep}`) || relative === '..' || path.isAbsolute(relative)) return null;
145
+ let current = state.home;
146
+ if (!await statPath(current, 'directory', state)) return null;
147
+ for (const name of relative.split(path.sep).slice(0, -1)) {
148
+ current = path.join(current, name);
149
+ if (!await statPath(current, 'directory', state)) return null;
150
+ }
151
+ const before = await statPath(file, 'file', state);
152
+ if (!before || before.size > MAX_META) return null;
153
+ try {
154
+ const handle = await fs.promises.open(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW || 0));
155
+ try {
156
+ const after = await handle.stat();
157
+ if (!after.isFile() || before.ino !== after.ino || before.dev !== after.dev || after.size > MAX_META) return null;
158
+ const chunks = [];
159
+ let total = 0;
160
+ const stream = handle.createReadStream({ autoClose: false, highWaterMark: 16 * 1024, start: 0, end: MAX_META - 1 });
161
+ for await (const chunk of stream) {
162
+ total += chunk.length;
163
+ if (total > MAX_META) return null;
164
+ chunks.push(chunk);
165
+ }
166
+ return Buffer.concat(chunks, total).toString('utf8');
167
+ } finally { await handle.close(); }
168
+ } catch { return null; }
169
+ }
170
+
171
+ async function geminiProjectDirs(app, tmp, state) {
172
+ const slugs = new Set([state.geminiProjectHash]);
173
+ const registries = [...new Set([path.join(app, 'projects.json'), path.join(state.home, '.gemini', 'projects.json')])];
174
+ for (const regFile of registries) {
175
+ const registryText = await readSmallMeta(regFile, state);
176
+ if (!registryText) continue;
177
+ try {
178
+ const parsed = JSON.parse(registryText);
179
+ if (parsed && typeof parsed === 'object' && parsed.projects && typeof parsed.projects === 'object' && !Array.isArray(parsed.projects)) {
180
+ for (const [registeredPath, slug] of Object.entries(parsed.projects)) {
181
+ if (typeof slug === 'string' && slug && !slug.includes('/') && !slug.includes('\\') && slug !== '.' && slug !== '..' && belongsToProject(registeredPath, state.projectDir)) {
182
+ slugs.add(slug);
183
+ }
184
+ }
185
+ }
186
+ } catch { /* ignore malformed registry */ }
187
+ }
188
+ for (const name of await children(tmp, state)) {
189
+ if (slugs.has(name)) continue;
190
+ const marker = await readSmallMeta(path.join(tmp, name, '.project_root'), state);
191
+ if (marker && belongsToProject(marker.trim(), state.projectDir)) slugs.add(name);
192
+ }
193
+ return [...slugs];
194
+ }
195
+
196
+ async function collectMemoryDir(dir, state) {
197
+ for (const name of await children(dir, state)) {
198
+ if (!name.endsWith('.md')) continue;
199
+ const file = path.join(dir, name);
200
+ const stat = await statPath(file, 'file', state, true);
201
+ if (stat) state.memoryFiles.push({ file, mtimeMs: stat.mtimeMs });
202
+ }
203
+ }
204
+
128
205
  async function discover(home, sources, state) {
129
206
  if (!await statPath(home, 'directory', state)) return;
130
207
  if (sources.has('claude-code')) {
@@ -157,33 +234,35 @@ async function discover(home, sources, state) {
157
234
  }
158
235
  }
159
236
  await walk(path.join(app, 'sessions'));
160
- const memories = path.join(app, 'memories');
161
- for (const name of await children(memories, state)) {
162
- if (!name.endsWith('.md')) continue;
163
- const file = path.join(memories, name);
164
- const stat = await statPath(file, 'file', state, true);
165
- if (stat) state.memoryFiles.push({ file, mtimeMs: stat.mtimeMs });
237
+ await collectMemoryDir(path.join(app, 'memories'), state);
238
+ const memoriesV2 = path.join(app, 'memories_v2');
239
+ if (await statPath(memoriesV2, 'directory', state)) {
240
+ await collectMemoryDir(memoriesV2, state);
241
+ await collectMemoryDir(path.join(memoriesV2, 'rollout_summaries'), state);
166
242
  }
167
243
  }
168
244
  }
169
245
  if (sources.has('gemini-cli')) {
170
- const app = path.join(home, '.gemini');
171
- if (await statPath(app, 'directory', state)) {
246
+ const geminiRoots = [path.join(home, '.gemini')];
247
+ const cacheRoot = path.join(home, '.cache');
248
+ if (await statPath(cacheRoot, 'directory', state)) geminiRoots.push(path.join(cacheRoot, '.gemini'));
249
+ for (const app of geminiRoots) {
250
+ if (!await statPath(app, 'directory', state)) continue;
172
251
  const tmp = path.join(app, 'tmp');
173
- if (await statPath(tmp, 'directory', state)) {
174
- const projects = state.allProjects ? await children(tmp, state) : [state.geminiProjectHash];
175
- for (const project of projects) {
176
- const dir = path.join(tmp, project);
177
- if (!await statPath(dir, 'directory', state)) continue;
178
- for (const name of await children(path.join(dir, 'chats'), state)) {
179
- if (name.startsWith('session-') && name.endsWith('.jsonl')) await candidate(path.join(dir, 'chats', name), 'gemini-cli', project, 'gemini', state);
180
- }
181
- const logs = path.join(dir, 'logs.json');
182
- try {
183
- await fs.promises.lstat(logs);
184
- await candidate(logs, 'gemini-cli', project, 'gemini-logs', state);
185
- } catch (error) { if (error.code !== 'ENOENT') bump(state, 'unreadable'); }
252
+ if (!await statPath(tmp, 'directory', state)) continue;
253
+ const projects = state.allProjects ? await children(tmp, state) : await geminiProjectDirs(app, tmp, state);
254
+ for (const project of projects) {
255
+ const dir = path.join(tmp, project);
256
+ if (!await statPath(dir, 'directory', state)) continue;
257
+ for (const name of await children(path.join(dir, 'chats'), state)) {
258
+ if (name.startsWith('session-') && name.endsWith('.jsonl')) await candidate(path.join(dir, 'chats', name), 'gemini-cli', project, 'gemini', state);
259
+ else if (name.startsWith('session-') && name.endsWith('.json')) await candidate(path.join(dir, 'chats', name), 'gemini-cli', project, 'gemini-json', state);
186
260
  }
261
+ const logs = path.join(dir, 'logs.json');
262
+ try {
263
+ await fs.promises.lstat(logs);
264
+ await candidate(logs, 'gemini-cli', project, 'gemini-logs', state);
265
+ } catch (error) { if (error.code !== 'ENOENT') bump(state, 'unreadable'); }
187
266
  }
188
267
  }
189
268
  }
@@ -346,31 +425,112 @@ async function readCodex(file, state) {
346
425
  return session.messages.length ? [session] : [];
347
426
  }
348
427
 
428
+ function finalizeGeminiMessages(session, messages, state) {
429
+ for (const message of messages) {
430
+ if (!message || typeof message !== 'object') continue;
431
+ messageTimestamp(session, message.timestamp);
432
+ if (message.type !== 'user') continue;
433
+ const text = typedText(geminiMessageItems(message.content), state);
434
+ if (text) session.messages.push(text);
435
+ }
436
+ }
437
+
349
438
  async function readGemini(file, state) {
350
439
  const session = baseSession(file);
351
- let known = false, messages = [];
440
+ let known = false, automation = false;
441
+ const byId = new Map();
442
+ const putMessage = message => {
443
+ if (!message || typeof message !== 'object') return;
444
+ const key = typeof message.id === 'string' && message.id ? message.id : Symbol();
445
+ byId.set(key, message);
446
+ };
352
447
  const ok = await scanLines(file.file, state, line => {
353
448
  const record = parsedLine(line, state);
354
449
  if (!record) return;
355
450
  if (typeof record.sessionId === 'string') { session.sessionId = record.sessionId; known = true; }
356
- if (record.$set && Object.prototype.hasOwnProperty.call(record.$set, 'messages')) {
357
- if (Array.isArray(record.$set.messages)) { messages = record.$set.messages; known = true; }
358
- else bump(state, 'unknown_format');
451
+ if (record.kind === 'subagent') { automation = true; known = true; }
452
+ if (typeof record.startTime === 'string') messageTimestamp(session, record.startTime);
453
+ if (typeof record.lastUpdated === 'string') messageTimestamp(session, record.lastUpdated);
454
+ if (record.$set && typeof record.$set === 'object' && !Array.isArray(record.$set)) {
455
+ known = true;
456
+ if (typeof record.$set.sessionId === 'string') session.sessionId = record.$set.sessionId;
457
+ if (record.$set.kind === 'subagent') automation = true;
458
+ if (typeof record.$set.lastUpdated === 'string') messageTimestamp(session, record.$set.lastUpdated);
459
+ if (Object.prototype.hasOwnProperty.call(record.$set, 'messages')) {
460
+ if (Array.isArray(record.$set.messages)) {
461
+ byId.clear();
462
+ for (const msg of record.$set.messages) putMessage(msg);
463
+ } else bump(state, 'unknown_format');
464
+ }
465
+ return;
466
+ }
467
+ if (typeof record.$rewindTo === 'string') {
468
+ known = true;
469
+ if (!byId.has(record.$rewindTo)) byId.clear();
470
+ else {
471
+ let drop = false;
472
+ for (const key of [...byId.keys()]) {
473
+ if (key === record.$rewindTo) drop = true;
474
+ if (drop) byId.delete(key);
475
+ }
476
+ }
477
+ return;
478
+ }
479
+ if (record.$patch && typeof record.$patch === 'object' && !Array.isArray(record.$patch)) {
480
+ known = true;
481
+ const patch = record.$patch;
482
+ const updates = Array.isArray(patch.updates) ? patch.updates : (typeof patch.id === 'string' ? [patch] : []);
483
+ for (const u of updates) {
484
+ if (!u || typeof u !== 'object' || typeof u.id !== 'string' || !byId.has(u.id)) continue;
485
+ const current = byId.get(u.id);
486
+ const next = { ...current };
487
+ if (Object.prototype.hasOwnProperty.call(u, 'content')) next.content = u.content;
488
+ if (Object.prototype.hasOwnProperty.call(u, 'displayContent')) next.displayContent = u.displayContent;
489
+ byId.set(u.id, next);
490
+ }
491
+ if (Array.isArray(patch.removeIds)) {
492
+ for (const id of patch.removeIds) if (typeof id === 'string') byId.delete(id);
493
+ }
494
+ if (Array.isArray(patch.orderIds)) {
495
+ const reordered = new Map();
496
+ for (const id of patch.orderIds) if (typeof id === 'string' && byId.has(id)) reordered.set(id, byId.get(id));
497
+ for (const [k, v] of byId.entries()) if (!reordered.has(k)) reordered.set(k, v);
498
+ byId.clear();
499
+ for (const [k, v] of reordered.entries()) byId.set(k, v);
500
+ }
501
+ return;
502
+ }
503
+ if (typeof record.type === 'string' && ['user', 'gemini', 'assistant', 'info', 'error', 'warning'].includes(record.type)) {
504
+ known = true;
505
+ putMessage(record);
359
506
  }
360
507
  });
361
508
  if (!ok) return [];
362
- for (const message of messages) {
363
- if (!message) continue;
364
- messageTimestamp(session, message.timestamp);
365
- if (message.type !== 'user') continue;
366
- const items = Array.isArray(message.content) ? message.content.filter(item => item && typeof item.text === 'string' && (!item.type || item.type === 'text')).map(item => item.text) : [];
367
- const text = typedText(items, state);
368
- if (text) session.messages.push(text);
369
- }
509
+ if (automation) { bump(state, 'automation_session'); return []; }
510
+ finalizeGeminiMessages(session, byId.values(), state);
370
511
  if (!known) bump(state, 'unknown_format');
371
512
  return session.messages.length ? [session] : [];
372
513
  }
373
514
 
515
+ async function readGeminiJson(file, state) {
516
+ const session = baseSession(file);
517
+ const lines = [];
518
+ const ok = await scanLines(file.file, state, line => { lines.push(line); });
519
+ if (!ok) return [];
520
+ let record;
521
+ try { record = JSON.parse(lines.join('\n')); }
522
+ catch { bump(state, 'malformed_line'); return []; }
523
+ if (!record || Array.isArray(record) || typeof record !== 'object') { bump(state, 'unknown_format'); return []; }
524
+ if (record.kind === 'subagent') { bump(state, 'automation_session'); return []; }
525
+ const known = typeof record.sessionId === 'string' || Array.isArray(record.messages);
526
+ if (!known) { bump(state, 'unknown_format'); return []; }
527
+ if (typeof record.sessionId === 'string') session.sessionId = record.sessionId;
528
+ if (typeof record.startTime === 'string') messageTimestamp(session, record.startTime);
529
+ if (typeof record.lastUpdated === 'string') messageTimestamp(session, record.lastUpdated);
530
+ if (Array.isArray(record.messages)) finalizeGeminiMessages(session, record.messages, state);
531
+ return session.messages.length ? [session] : [];
532
+ }
533
+
374
534
  async function readGeminiLogs(file, state) {
375
535
  const grouped = new Map();
376
536
  // Old logs are JSON arrays. Frame one entry at a time instead of buffering the array.
@@ -460,7 +620,7 @@ async function readSessions({ home = resolveHome(), projectDir = process.cwd(),
460
620
  const bounded = state.candidates.filter(file => file.source === 'gemini-cli').length < 2;
461
621
  const sortKey = session => session.timestampMs ?? session.mtimeMs;
462
622
  const compare = (a, b) => sortKey(b) - sortKey(a) || a.file.localeCompare(b.file) || a.sessionId.localeCompare(b.sessionId);
463
- const readers = { claude: readClaude, codex: readCodex, gemini: readGemini, 'gemini-logs': readGeminiLogs };
623
+ const readers = { claude: readClaude, codex: readCodex, gemini: readGemini, 'gemini-json': readGeminiJson, 'gemini-logs': readGeminiLogs };
464
624
  for (const file of state.candidates) {
465
625
  if (!maximum) break;
466
626
  if (bounded && sessions.length === maximum && file.mtimeMs < sortKey(sessions[maximum - 1])) break;
package/bin/uninstall.cjs CHANGED
@@ -8,8 +8,8 @@ const renderer = require('../render/render.cjs');
8
8
  const onboarding = require('../render/onboarding.cjs');
9
9
  const TARGETS = require('../render/targets.json');
10
10
  const { installPlan, recordedHash, validateInventory } = require('./install-plan.cjs');
11
+ const { sha256 } = require('./cli-util.cjs');
11
12
  const CONFIG = '.agent-personalizer.json';
12
- const sha256 = (bytes) => crypto.createHash('sha256').update(bytes).digest('hex');
13
13
 
14
14
  function refuse(message) { throw new renderer.Refusal(message); }
15
15
  // Install appends "\n" + block + "\n" to a pre-existing file that ends in a newline
@@ -92,7 +92,7 @@ function run(dir, dry) {
92
92
  // The renderer consults this path even at level 1. Validate it before rendering.
93
93
  const notesScaffolded = !!probe(`${base}/README.md`);
94
94
  const recipe = installPlan({ answers, level, targets: cfg.targets, notesScaffolded }).plan;
95
- const homeNames = new Set(['CLAUDE.md', 'AGENTS.md']);
95
+ const homeNames = new Set(['CLAUDE.md', 'AGENTS.md', 'GEMINI.md']);
96
96
  const expected = new Map();
97
97
  for (const p of recipe) {
98
98
  if (homeNames.has(p.rel) || p.rel === 'LEARNED.md') continue; // entries always belong to the user
@@ -308,7 +308,7 @@ function run(dir, dry) {
308
308
  }
309
309
  console.log(`kept ${CONFIG} (tracked files remain; review the kept paths above)`);
310
310
  }
311
- if (level >= 3) console.log('Manual step: remove any SessionStart entry for hooks/claude-code/session-start.sh from .claude/settings.json or ~/.claude/settings.json if you registered it. Settings are kept.');
311
+ if (level >= 3) console.log('Manual step: remove any SessionStart entry for hooks/claude-code/session-start.sh or hooks/gemini-cli/session-start.sh from .claude/settings.json, ~/.claude/settings.json, .gemini/settings.json or ~/.gemini/settings.json if you registered it. Settings are kept.');
312
312
  }
313
313
 
314
314
  module.exports = { uninstall };
package/check/gate.cjs CHANGED
@@ -141,10 +141,50 @@ function* walk(root) {
141
141
  }
142
142
  }
143
143
 
144
+ function redactByFold(text, terms) {
145
+ const normalized = String(text).normalize('NFC');
146
+ const foldedTerms = terms.map(fold).filter(Boolean);
147
+ if (!foldedTerms.length || !normalized) return normalized;
148
+ const map = [];
149
+ let lower = '';
150
+ for (let i = 0; i < normalized.length;) {
151
+ const cp = normalized.codePointAt(i);
152
+ const step = cp > 0xffff ? 2 : 1;
153
+ const chunk = normalized.slice(i, i + step).toLowerCase();
154
+ for (let k = 0; k < chunk.length; k++) map.push([i, i + step]);
155
+ lower += chunk;
156
+ i += step;
157
+ }
158
+ const ranges = [];
159
+ for (const t of foldedTerms) {
160
+ let idx = lower.indexOf(t);
161
+ while (idx !== -1) {
162
+ ranges.push([map[idx][0], map[idx + t.length - 1][1]]);
163
+ idx = lower.indexOf(t, idx + 1);
164
+ }
165
+ }
166
+ if (!ranges.length) return normalized;
167
+ ranges.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
168
+ const merged = [ranges[0].slice()];
169
+ for (let i = 1; i < ranges.length; i++) {
170
+ const prev = merged[merged.length - 1];
171
+ if (ranges[i][0] <= prev[1]) prev[1] = Math.max(prev[1], ranges[i][1]);
172
+ else merged.push(ranges[i].slice());
173
+ }
174
+ let out = '', pos = 0;
175
+ for (const [start, end] of merged) {
176
+ out += normalized.slice(pos, start) + '[redacted]';
177
+ pos = end;
178
+ }
179
+ return out + normalized.slice(pos);
180
+ }
181
+
182
+ const fold = text => String(text).normalize('NFC').toLowerCase();
183
+
144
184
  function allowedSpans(lineLower, allow) {
145
185
  const spans = [];
146
186
  for (const a of allow) {
147
- const al = a.toLowerCase();
187
+ const al = fold(a);
148
188
  if (!al.length) continue;
149
189
  let i = lineLower.indexOf(al);
150
190
  while (i !== -1) { spans.push([i, i + al.length]); i = lineLower.indexOf(al, i + al.length); }
@@ -332,19 +372,19 @@ function scan(root, list, listFile, all, history = false) {
332
372
  // the PATH first: one scan per item, labelled "(path)", never covered by allow spans of the text
333
373
  if (!scannedPaths.has(item.rel) || item.history) {
334
374
  if (!item.history) scannedPaths.add(item.rel);
335
- const lower = item.rel.toLowerCase(), spans = allowedSpans(lower, list.allow);
375
+ const lower = fold(item.rel), spans = allowedSpans(lower, list.allow);
336
376
  for (const term of list.terms) {
337
- const t = term.toLowerCase(); let i = lower.indexOf(t);
377
+ const t = fold(term); let i = lower.indexOf(t);
338
378
  while (i !== -1) { if (!spans.some(([x, y]) => i >= x && i + t.length <= y)) hits.push({ file: item.history ? item.label : `${item.rel} (path)`, line: 0, rule: 'P_LIST' }); i = lower.indexOf(t, i + 1); }
339
379
  }
340
380
  }
341
381
  if (!item.history && isBinary(item.bytes)) continue;
342
382
  const lines = item.bytes.toString('utf8').split('\n');
343
383
  lines.forEach((line, n) => {
344
- const lower = line.toLowerCase();
384
+ const lower = fold(line);
345
385
  const spans = allowedSpans(lower, list.allow);
346
386
  for (const term of list.terms) {
347
- const t = term.toLowerCase();
387
+ const t = fold(term);
348
388
  let i = lower.indexOf(t);
349
389
  while (i !== -1) {
350
390
  const inside = spans.some(([a, b]) => i >= a && i + t.length <= b);
@@ -398,7 +438,7 @@ function main() {
398
438
  catch (e) { if (e.code === 'ENOENT') list = { terms: [], allow: [] }; else die(`cannot inspect private list (${e.code || 'unknown error'})`); }
399
439
  } else list = loadList(listFile);
400
440
  const redact = text => {
401
- const clean = list.terms.reduce((value, term) => value.replace(new RegExp(term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'), '[redacted]'), text);
441
+ const clean = redactByFold(text, list.terms);
402
442
  return PRIVATE_CLASSES.some(([, pattern]) => pattern.test(clean)) ? '[redacted path]' : clean;
403
443
  };
404
444
  const { hits, files, skipped } = scan(root, list, listFile, all, history);
@@ -55,7 +55,7 @@ Fill it with the identifiers you want to catch and add `check/forbidden.local.tx
55
55
  node check/gate.cjs --dir .
56
56
  ```
57
57
 
58
- The gate checks listed strings against file text and relative paths. In a git work tree it scans staged blobs, changed working copies and untracked files that git would include. `--all` scans the folder directly. It never follows symlinks.
58
+ The gate normalizes Unicode to NFC and checks listed strings (ignoring case) against file text and relative paths. In a git work tree it scans staged blobs, changed working copies and untracked files that git would include. `--all` scans the folder directly. It never follows symlinks.
59
59
 
60
60
  - **Exit `0`:** the scan completed with no listed strings found.
61
61
  - **Exit `1`:** one or more listed strings were found.
package/docs/install.md CHANGED
@@ -4,7 +4,7 @@ The installer writes a profile, a learning log, an onboarding manual and the ins
4
4
 
5
5
  ## Requirements
6
6
 
7
- Node 22 or 24 (active LTS) is recommended; 18 or later runs. The installer, renderer and gate run on macOS, Linux and Windows. The shell harness and session-start hook need a POSIX shell; use WSL or Git Bash on Windows.
7
+ Node 24 or 26 (active LTS) is recommended; 22 or later runs. The installer, renderer and gate run on macOS, Linux and Windows. The shell harness and session-start hooks need a POSIX shell; use WSL or Git Bash on Windows.
8
8
 
9
9
  ## Interactive setup
10
10
 
@@ -95,7 +95,7 @@ npx agent-personalizer --global --uninstall
95
95
 
96
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`, `~/.gemini/GEMINI.md` and `~/.hermes/SOUL.md` for the selected targets. 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. 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.
97
97
 
98
- 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.
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
 
100
100
  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.
101
101
 
@@ -117,9 +117,9 @@ npx agent-personalizer learn --forget --dir .
117
117
 
118
118
  ## What each level adds
119
119
 
120
- - **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`.
120
+ - **Level 1:** `USER.md`, `LEARNED.md`, `AGENT_ONBOARDING.md`, the files for your AI targets, and `.agent-personalizer.json`. Claude Code receives `.claude/commands/personalize.md` and Gemini CLI receives `.gemini/commands/personalize.toml`. 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`.
121
121
  - **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.
122
- - **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).
122
+ - **Level 3:** all eleven rules (subject to target and signature selection), your editable `rules/` copy, `render/` tools, the Claude Code and Gemini CLI session-start hooks and the forbidden-string gate. [Register the hook](../hooks/README.md) in your AI settings and [configure the gate](guarantees.md#forbidden-string-gate).
123
123
 
124
124
  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.
125
125
 
@@ -158,7 +158,7 @@ npm_config_cache=./.npm-cache npx agent-personalizer
158
158
 
159
159
  ## Manual copying
160
160
 
161
- For a setup without Node, download this repository and copy [`templates/USER.md`](../templates/USER.md) plus [`templates/CLAUDE.md`](../templates/CLAUDE.md) or [`templates/AGENTS.md`](../templates/AGENTS.md) into your project. Fill in the profile and adapt the home template's pointers to the files you keep. For a chat app, paste the profile body into its instruction field.
161
+ For a setup without Node, download this repository and copy [`templates/USER.md`](../templates/USER.md) plus [`templates/CLAUDE.md`](../templates/CLAUDE.md), [`templates/AGENTS.md`](../templates/AGENTS.md) or [`templates/GEMINI.md`](../templates/GEMINI.md) into your project. Fill in the profile and adapt the home template's pointers to the files you keep. For a chat app, paste the profile body into its instruction field.
162
162
 
163
163
  Consent-gated session learning, automatic rendering and the drift check are available when you use the Node installer. [The paste guide](paste-guide.md) covers manual app setup.
164
164
 
@@ -181,7 +181,7 @@ The uninstaller reads `/path/to/project/.agent-personalizer.json` and compares f
181
181
  - **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.
182
182
  - **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.
183
183
  - **Rules and tools:** unchanged installed copies are removed file by file, including the session-start hook. Edited copies stay.
184
- - **Hook registration:** remove the matching `SessionStart` entry from `.claude/settings.json` or `~/.claude/settings.json` yourself. The uninstaller prints this step; it never edits settings outside the installation.
184
+ - **Hook registration:** remove any matching `SessionStart` entry from `.claude/settings.json`, `~/.claude/settings.json`, `.gemini/settings.json` or `~/.gemini/settings.json` yourself. The uninstaller prints this step; it never edits settings outside the installation.
185
185
  - **Paths:** the whole removal plan is preflighted before the first unlink, and each path is re-probed before it is unlinked. The uninstaller never follows symlinks, deletes recursively or removes a path outside the named folder. A refused preflight leaves the removal plan unapplied.
186
186
  - **Configuration:** `.agent-personalizer.json` is removed last, only after every path it tracks is gone or, for a pre-existing home file, has had its block removed. An edited file the uninstaller retained keeps the configuration available for review.
187
187
 
package/docs/learning.md CHANGED
@@ -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` |
47
- | `gemini` | Gemini CLI: `~/.gemini/tmp/<hash>/chats/session-*.jsonl` and the older `logs.json` |
46
+ | `agents` | Codex: `~/.codex/sessions/**/rollout-*.jsonl`, plus `~/.codex/memories/*.md` and `~/.codex/memories_v2/**/*.md` |
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
- 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 uses the SHA-256 project folder it creates from that path. 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.
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 are global to your Codex account, not limited to this folder. 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 snapshots replace earlier messages; a message repeated in the chat and logs is included once. The all-projects option affects session history; the memory file limit still applies.
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 are global to your Codex account, not limited to this folder. 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
 
@@ -65,7 +65,7 @@ Messages and memory notes that look like secrets are dropped whole and counted u
65
65
 
66
66
  ## What your AI asks and keeps
67
67
 
68
- Start your AI in the installed folder. Claude Code has `/personalize`; Codex and Gemini CLI receive the same procedure in their home files. At level 3, the session-start contract points to `/personalize` while a digest has not been handled.
68
+ Start your AI in the installed folder. Claude Code and Gemini CLI have `/personalize`; Codex receives the same procedure in its home file. At level 3, the session-start contract points to `/personalize` (or the home-file procedure for `agents`) while a digest has not been handled.
69
69
 
70
70
  Each question includes a count and one short quote, such as "You've asked me to shorten replies 3 times this week. Make it a rule?" Fewer real patterns means fewer questions. Entries already confirmed or declined are never asked again.
71
71
 
@@ -97,10 +97,10 @@ npx agent-personalizer --uninstall --dir .
97
97
 
98
98
  ## How the loop closes
99
99
 
100
- The installed home files carry the learning procedure; Claude Code also gets `.claude/commands/personalize.md`. At level 3, the session-start contract points at `/personalize` while a digest id is unasked. Your AI asks the questions, writes the statuses and digest id to `LEARNED.md`, then re-renders. Only current confirmed entries apply. A summary in `USER.md` can lag until an installer re-run; `LEARNED.md` owns entry status.
100
+ The installed home files carry the learning procedure; Claude Code also gets `.claude/commands/personalize.md` and Gemini CLI gets `.gemini/commands/personalize.toml`. At level 3, the session-start contract points at `/personalize` (or the home-file procedure for `agents`) while a digest id is unasked. Your AI asks the questions, writes the statuses and digest id to `LEARNED.md`, then re-renders. Only current confirmed entries apply. A summary in `USER.md` can lag until an installer re-run; `LEARNED.md` owns entry status.
101
101
 
102
102
  Nothing watches the digest or verifies model behaviour in the background. You can verify the files with `npx agent-personalizer --dir .`, then at level 3, `node render/render.cjs --dir . --check`. A clean check exits 0; drift exits 1; invalid input exits 2. Check `LEARNED.md` for the approved or declined line and the digest id under `## Asked`. Re-paste ChatGPT's boxes after changes. With no shell, the AI tells you to run the re-render command.
103
103
 
104
- The reader uses Node 18 built-ins and no network. Formats, unreadable files, symlinks, oversized lines and private matches are counted as skips. The digest header records the selected sources, files and counts; the terminal lists read paths without message text. Report a reader failure or leak through the channels in [SECURITY.md](../SECURITY.md).
104
+ The reader uses Node 22 built-ins and no network. Formats, unreadable files, symlinks, oversized lines and private matches are counted as skips. The digest header records the selected sources, files and counts; the terminal lists read paths without message text. Report a reader failure or leak through the channels in [SECURITY.md](../SECURITY.md).
105
105
 
106
106
  The installer does not upload the digest. Other software can sync or share its containing folder; choose a private local folder if you want the copy to stay on this computer. The local `LEARNED.md` is the source of truth for entries; generated blocks and paste files are checked copies, and the digest is disposable evidence.
@@ -5,9 +5,9 @@ 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` 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; `--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. |
8
+ | `AGENT_ONBOARDING.md` | any AI | Named as the second thing to read in `CLAUDE.md`, `AGENTS.md` and `GEMINI.md`. Paste it wherever the AI has no file access (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` for all projects. Nothing to paste. |
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. |
13
13
  | `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. |
@@ -38,7 +38,7 @@ Open Settings → Personalization and enable customization. Copy the exported pr
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 budget is 1,500 characters per export in `render/targets.json`; your current interface displays its own limits. 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 are retained; declined "Never ask again" entries may be shortened to fit the budget. Proposed entries are omitted. The preview reports each count. Over-budget text is written in full and flagged OVER BUDGET; `--strict` refuses the write. Review the text against your displayed limits. For the full onboarding, entries and rule source, create a ChatGPT Project and upload `AGENT_ONBOARDING.md`, `LEARNED.md` and `rules/` as project files.
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 Education accounts allow up to 5,000 characters under Settings → Personalization (`More about you` and `Custom instructions`). 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 are retained; declined "Never ask again" entries may be shortened to fit the budget. Proposed entries are omitted. The preview reports each count. Over-budget text is written in full and flagged OVER BUDGET; `--strict` refuses the write. Review the text against your account's displayed limits. For the full onboarding, entries and rule source, create a ChatGPT Project and upload `AGENT_ONBOARDING.md`, `LEARNED.md` and `rules/` as project files.
42
42
 
43
43
  ## Codex CLI
44
44
 
@@ -55,9 +55,11 @@ Verified against [OpenAI's Codex AGENTS.md documentation](https://learn.chatgpt.
55
55
 
56
56
  Reads `AGENTS.md` at the project root. Older setups use `.cursor/rules/`; if yours does, point one rule file at `AGENTS.md` rather than copying its text, so there is one owner.
57
57
 
58
- ## Gemini CLI
58
+ ## Gemini CLI and Google Antigravity
59
59
 
60
- Reads `GEMINI.md` from the folder (and parent folders). Run the installer with `--ai gemini` and there is nothing to paste.
60
+ Gemini CLI reads `GEMINI.md` from the folder (and parent folders), plus `~/.gemini/GEMINI.md` when installed with `--global --ai gemini`. Project installs also add `.gemini/commands/personalize.toml` for `/personalize`, and level-3 installs provide `hooks/gemini-cli/session-start.sh` for `.gemini/settings.json` (see [`hooks/README.md`](../hooks/README.md)).
61
+
62
+ Google Antigravity also reads project `GEMINI.md` files (from the workspace root up to the current folder) and `~/.gemini/GEMINI.md` for compatibility; its primary global instruction file is `~/.gemini/config/GEMINI.md`, which enforces a 24,000-byte per-file limit after includes. Use `--compact` if a custom rule set approaches the 20,000-character warning budget.
61
63
 
62
64
  ## Anything else
63
65
 
package/docs/tiers.md CHANGED
@@ -55,7 +55,7 @@ The four file targets have a 20,000-character warning budget for the whole rende
55
55
 
56
56
  **What.** The handful of rules that must win at the moment of decision, injected in full at the start of every session. Not pointers. Full text.
57
57
 
58
- **Where.** A session-start hook (Claude Code has these). For AIs without hooks, a block you paste at the top of the first message, or a saved prompt that starts every session.
58
+ **Where.** A session-start hook (Claude Code and Gemini CLI both support `SessionStart` hooks; see [`hooks/README.md`](../hooks/README.md)). For AIs without hooks, a block you paste at the top of the first message, or a saved prompt that starts every session.
59
59
 
60
60
  **Prevents.** A tool's own instructions beating yours by default. Installed skills, plugins and tool descriptions each say "use me." A rule that says "use the other one first" loses that argument if it is only stated in a document the AI may or may not have opened. Injection makes sure your rule is at least in the room; it does not settle the argument on every host.
61
61
 
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.9.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.
3
+ Tier 3 from the tiers doc (https://github.com/aunysillyme/agent-personalizer/blob/v0.10.0/docs/tiers.md): the few rules that must be in context at the moment of decision, injected in full at the start of every session. Injection puts the text in front of the model; whether the model follows it is up to the model and the host. This is the strongest placement available, not a guarantee.
4
4
 
5
5
  Which rules? The ones with `inject: true` in their frontmatter. Keep that set small. Every injected rule costs tokens every session.
6
6
 
@@ -26,6 +26,22 @@ The contract is target-aware: `--contract-target claude` applies each rule's `su
26
26
 
27
27
  **Subagents do not get SessionStart.** A subagent you spawn from a session sees none of this unless you pass it in the task. That is why the rendered `CLAUDE.md` also carries pointers to every rule: the pointer survives, the injection does not.
28
28
 
29
+ ## Gemini CLI
30
+
31
+ `gemini-cli/session-start.sh` wraps `--contract --contract-target gemini` in Gemini CLI's structured `SessionStart` JSON output (`hookSpecificOutput.additionalContext`), so the contract enters model context rather than displaying only as a terminal status message. Register it in the project's `.gemini/settings.json`:
32
+
33
+ ```json
34
+ {
35
+ "hooks": {
36
+ "SessionStart": [
37
+ { "hooks": [ { "type": "command", "command": "sh \"$GEMINI_PROJECT_DIR/hooks/gemini-cli/session-start.sh\"" } ] }
38
+ ]
39
+ }
40
+ }
41
+ ```
42
+
43
+ For user-level `~/.gemini/settings.json`, use the absolute path to the installed project instead, for example `sh "/path/to/project/hooks/gemini-cli/session-start.sh"`.
44
+
29
45
  ## Everything else (plain-prompt fallback)
30
46
 
31
47
  For an AI with no hook system, generate the contract once and paste it at the top of the first message, or save it as the opening block of a reusable prompt:
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+ # Gemini CLI SessionStart hook: injects the rendered session-start contract as JSON additionalContext.
3
+ set -eu
4
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ exec node -e '
6
+ const { spawnSync } = require("child_process");
7
+ const path = require("path");
8
+ const root = process.argv[1];
9
+ const r = spawnSync(process.execPath, [path.join(root, "render/render.cjs"), "--dir", root, "--contract", "--contract-target", "gemini"], { encoding: "utf8" });
10
+ if (r.status !== 0) {
11
+ process.stderr.write(r.stderr || r.stdout || "");
12
+ process.exit(r.status || 1);
13
+ }
14
+ process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: r.stdout } }) + "\n");
15
+ ' "$ROOT"