agent-personalizer 0.7.2 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -1
- package/README.md +23 -14
- package/SECURITY.md +3 -1
- package/bin/agent-personalizer.js +90 -106
- package/bin/git-exclude.cjs +108 -0
- package/bin/install-plan.cjs +3 -0
- package/bin/known-hashes.json +54 -0
- package/bin/learn.cjs +210 -0
- package/bin/sessions.cjs +448 -0
- package/bin/uninstall.cjs +51 -7
- package/check/gate.cjs +4 -3
- package/docs/README.md +2 -1
- package/docs/companions.md +2 -2
- package/docs/guarantees.md +17 -6
- package/docs/install.md +31 -20
- package/docs/learning.md +103 -0
- package/docs/paste-guide.md +4 -4
- package/docs/tiers.md +4 -4
- package/examples/freelance-illustrator/.agent-personalizer.json +3 -3
- package/examples/freelance-illustrator/AGENTS.md +67 -3
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +4 -7
- package/examples/freelance-illustrator/CLAUDE.md +67 -3
- package/examples/freelance-illustrator/LEARNED.md +14 -0
- package/examples/freelance-illustrator/USER.md +6 -1
- package/examples/freelance-illustrator/rules/00-read-the-profile-first.md +1 -1
- package/examples/freelance-illustrator/rules/65-ask-before-it-repeats.md +18 -0
- package/examples/freelance-illustrator/rules/70-their-words-point-at-the-thing.md +15 -0
- package/examples/freelance-illustrator/rules/80-symptoms-are-not-causes.md +15 -0
- package/examples/freelance-illustrator/rules/90-surface-what-they-cant-see.md +15 -0
- package/examples/freelance-illustrator/rules/README.md +59 -0
- package/examples/lab-technician/.agent-personalizer.json +38 -0
- package/examples/lab-technician/AGENTS.md +243 -0
- package/examples/lab-technician/AGENT_ONBOARDING.md +64 -0
- package/examples/lab-technician/CLAUDE.md +247 -0
- package/examples/lab-technician/LEARNED.md +14 -0
- package/examples/lab-technician/USER.md +53 -0
- package/examples/lab-technician/notes/README.md +26 -0
- package/examples/lab-technician/notes/decisions.md +4 -0
- package/examples/lab-technician/notes/inbox/2026-10-06-observation-table.md +3 -0
- package/examples/lab-technician/notes/inbox/README.md +7 -0
- package/examples/lab-technician/notes/sessions/2026-W41.md +7 -0
- package/examples/lab-technician/rules/00-read-the-profile-first.md +24 -0
- package/examples/lab-technician/rules/10-evidence-before-assertion.md +24 -0
- package/examples/lab-technician/rules/20-one-owner-per-rule.md +24 -0
- package/examples/lab-technician/rules/30-folder-index-is-part-of-the-change.md +26 -0
- package/examples/lab-technician/rules/40-sign-every-edit.md +25 -0
- package/examples/lab-technician/rules/50-output-style.md +21 -0
- package/examples/lab-technician/rules/60-act-or-ask.md +30 -0
- package/examples/lab-technician/rules/65-ask-before-it-repeats.md +18 -0
- package/examples/lab-technician/rules/70-their-words-point-at-the-thing.md +15 -0
- package/examples/lab-technician/rules/80-symptoms-are-not-causes.md +15 -0
- package/examples/lab-technician/rules/90-surface-what-they-cant-see.md +15 -0
- package/examples/lab-technician/rules/README.md +59 -0
- package/examples/product-designer/.agent-personalizer.json +38 -0
- package/examples/product-designer/AGENTS.md +243 -0
- package/examples/product-designer/AGENT_ONBOARDING.md +63 -0
- package/examples/product-designer/CLAUDE.md +247 -0
- package/examples/product-designer/LEARNED.md +14 -0
- package/examples/product-designer/USER.md +53 -0
- package/examples/product-designer/notes/README.md +26 -0
- package/examples/product-designer/notes/decisions.md +4 -0
- package/examples/product-designer/notes/inbox/2026-10-06-cancellation-wording.md +8 -0
- package/examples/product-designer/notes/inbox/README.md +7 -0
- package/examples/product-designer/notes/sessions/2026-W41.md +7 -0
- package/examples/product-designer/rules/00-read-the-profile-first.md +24 -0
- package/examples/product-designer/rules/10-evidence-before-assertion.md +24 -0
- package/examples/product-designer/rules/20-one-owner-per-rule.md +24 -0
- package/examples/product-designer/rules/30-folder-index-is-part-of-the-change.md +26 -0
- package/examples/product-designer/rules/40-sign-every-edit.md +25 -0
- package/examples/product-designer/rules/50-output-style.md +21 -0
- package/examples/product-designer/rules/60-act-or-ask.md +30 -0
- package/examples/product-designer/rules/65-ask-before-it-repeats.md +18 -0
- package/examples/product-designer/rules/70-their-words-point-at-the-thing.md +15 -0
- package/examples/product-designer/rules/80-symptoms-are-not-causes.md +15 -0
- package/examples/product-designer/rules/90-surface-what-they-cant-see.md +15 -0
- package/examples/product-designer/rules/README.md +59 -0
- package/hooks/README.md +1 -1
- package/llms.txt +6 -2
- package/package.json +2 -2
- package/render/onboarding.cjs +115 -45
- package/render/render.cjs +98 -39
- package/rules/00-read-the-profile-first.md +1 -1
- package/rules/65-ask-before-it-repeats.md +18 -0
- package/rules/70-their-words-point-at-the-thing.md +15 -0
- package/rules/80-symptoms-are-not-causes.md +15 -0
- package/rules/90-surface-what-they-cant-see.md +15 -0
- package/rules/README.md +4 -0
- package/templates/LEARNED.md +11 -0
package/render/render.cjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
--dir project folder holding USER.md and rules/ (default: cwd). The folder you
|
|
18
18
|
name is followed once (realpath); nothing beneath it may be a symlink.
|
|
19
19
|
--targets which renders to write; default: <dir>/.agent-personalizer.json, else "claude,agents".
|
|
20
|
-
The "onboarding" target renders AGENT_ONBOARDING.md from the
|
|
20
|
+
The "onboarding" target renders AGENT_ONBOARDING.md from the saved preferences
|
|
21
21
|
stored in .agent-personalizer.json (render/onboarding.cjs).
|
|
22
22
|
--check render to memory, compare with disk (both ChatGPT paste files included);
|
|
23
23
|
silent exit 0 when clean; exit 1 and name drift, 2 and name invalid input
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
condition), then the target's binding block.
|
|
28
28
|
--contract-target which target's surface filter, personal policy and binding to use (default claude)
|
|
29
29
|
|
|
30
|
-
Rules render from the
|
|
30
|
+
Rules render from the saved preferences as well as the profile: a rule whose frontmatter says
|
|
31
31
|
`requires: <answer>=<value>` is left out of every render and every contract when the stored
|
|
32
32
|
answer differs (no stored answers = the defaults). The ChatGPT target uses USER.md for its
|
|
33
|
-
profile: unchanged generated profiles keep the compact
|
|
33
|
+
profile: unchanged generated profiles keep the compact profile output, edited generated
|
|
34
34
|
profiles are compacted only while their scaffold matches, and other profiles are kept in full.
|
|
35
35
|
With answers, box 2 carries the contract block plus the inject:true rules; without answers it
|
|
36
36
|
carries every rule for that surface. Over-budget boxes are flagged, never cut.
|
|
@@ -119,6 +119,7 @@ function mustBe(p, kind, where) {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function parseFrontmatter(text, where) {
|
|
122
|
+
text = String(text).replace(/^\ufeff/, '');
|
|
122
123
|
if (!text.startsWith('---\n')) return { meta: {}, body: text };
|
|
123
124
|
const close = text.indexOf('\n---\n', 4);
|
|
124
125
|
if (close === -1) die(`${where}: frontmatter opened with --- but never closed`);
|
|
@@ -157,6 +158,7 @@ function parseFrontmatter(text, where) {
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
function parseSections(body, where) {
|
|
161
|
+
body = String(body).replace(/^\ufeff/, '');
|
|
160
162
|
const sections = {};
|
|
161
163
|
let current = null;
|
|
162
164
|
const lines = body.split('\n');
|
|
@@ -187,7 +189,8 @@ function fenceMap(lines, where) {
|
|
|
187
189
|
const inside = new Array(lines.length).fill(false);
|
|
188
190
|
let open = null; // { ch, len, line }
|
|
189
191
|
lines.forEach((raw, i) => {
|
|
190
|
-
const
|
|
192
|
+
const clean = i === 0 && raw.startsWith('\ufeff') ? raw.slice(1) : raw;
|
|
193
|
+
const line = clean.endsWith('\r') ? clean.slice(0, -1) : clean;
|
|
191
194
|
const m = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
192
195
|
if (open) {
|
|
193
196
|
inside[i] = true;
|
|
@@ -205,6 +208,10 @@ function rejectMarkers(text, where) {
|
|
|
205
208
|
if (text.includes(BEGIN) || text.includes(END)) die(`${where}: contains a render marker token; those are reserved for rendered files`);
|
|
206
209
|
}
|
|
207
210
|
|
|
211
|
+
function hasUtf8Bom(bytes) {
|
|
212
|
+
return bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf;
|
|
213
|
+
}
|
|
214
|
+
|
|
208
215
|
function decodeUtf8(bytes, where) {
|
|
209
216
|
try { return new TextDecoder('utf-8', { fatal: true }).decode(bytes); }
|
|
210
217
|
catch (_) { die(`${where}: not valid UTF-8. Nothing was written`); }
|
|
@@ -241,7 +248,7 @@ function validatePreservedTargets(cfg) {
|
|
|
241
248
|
|
|
242
249
|
function readSource(p, where) {
|
|
243
250
|
mustBe(p, 'file', where);
|
|
244
|
-
const text = decodeUtf8(fs.readFileSync(p), where).replace(/\r\n/g, '\n');
|
|
251
|
+
const text = decodeUtf8(fs.readFileSync(p), where).replace(/^\ufeff/, '').replace(/\r\n/g, '\n');
|
|
245
252
|
rejectMarkers(text, where);
|
|
246
253
|
return text;
|
|
247
254
|
}
|
|
@@ -308,7 +315,7 @@ function renderRule(rule, target) {
|
|
|
308
315
|
}
|
|
309
316
|
|
|
310
317
|
/* the rules that reach one surface: the surfaces filter, then the requires filter against the
|
|
311
|
-
stored answers (defaults when none are stored, so a rule set without
|
|
318
|
+
stored answers (defaults when none are stored, so a rule set without saved answers still renders) */
|
|
312
319
|
function rulesFor(rules, key, answers) {
|
|
313
320
|
const a = answers || onboarding.defaults();
|
|
314
321
|
return rules.filter(r => (!Array.isArray(r.meta.surfaces) || r.meta.surfaces.includes(key))
|
|
@@ -327,17 +334,41 @@ const notesScaffolded = (root, answers) => {
|
|
|
327
334
|
catch (_) { return false; }
|
|
328
335
|
};
|
|
329
336
|
|
|
330
|
-
function
|
|
337
|
+
function readLearned(root) {
|
|
338
|
+
const file = safeTargetPath(root, 'LEARNED.md', 'entries');
|
|
339
|
+
if (!mustBe(file, 'file', 'LEARNED.md')) return { confirmed: [], declined: [], proposed: [], asked: [], hash: 'none' };
|
|
340
|
+
const bytes = fs.readFileSync(file);
|
|
341
|
+
const text = decodeUtf8(bytes, 'LEARNED.md');
|
|
342
|
+
try { return { ...onboarding.parseLearned(text, 'LEARNED.md'), hash: sha256(bytes) }; }
|
|
343
|
+
catch (e) { die(e.message); }
|
|
344
|
+
}
|
|
345
|
+
function pendingDigest(root, entries) {
|
|
346
|
+
const folder = path.join(root, '.agent-personalizer');
|
|
347
|
+
if (!mustBe(folder, 'dir', '.agent-personalizer/')) return false;
|
|
348
|
+
const file = path.join(folder, 'digest.md');
|
|
349
|
+
if (!mustBe(file, 'file', '.agent-personalizer/digest.md')) return false;
|
|
350
|
+
// The id is in the header; the hook never loads or prints old messages.
|
|
351
|
+
let fd;
|
|
352
|
+
try {
|
|
353
|
+
fd = fs.openSync(file, 'r');
|
|
354
|
+
const bytes = Buffer.alloc(4096);
|
|
355
|
+
const n = fs.readSync(fd, bytes, 0, bytes.length, 0);
|
|
356
|
+
const id = bytes.subarray(0, n).toString('utf8').split(/\r?\n/).find(x => /^digest: \S+$/.test(x));
|
|
357
|
+
return !!id && !entries.asked.includes(id);
|
|
358
|
+
} finally { if (fd !== undefined) fs.closeSync(fd); }
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function renderTarget(key, target, profile, rules, cfg, root, learned) {
|
|
331
362
|
if (target.source === 'onboarding') {
|
|
332
|
-
if (!cfg || !cfg.onboarding) die(`target "${key}": no onboarding answers in .agent-personalizer.json. Run the installer
|
|
363
|
+
if (!cfg || !cfg.onboarding) die(`target "${key}": no onboarding answers in .agent-personalizer.json. Run the installer, or pass --answers <file>`);
|
|
333
364
|
return onboarding.renderOnboarding(cfg.onboarding, { notesScaffolded: notesScaffolded(root, cfg.onboarding) });
|
|
334
365
|
}
|
|
335
366
|
const answers = answersOf(cfg);
|
|
336
|
-
const lines = [`## ${target.header}`, '', '_Generated by agent-personalizer from `USER.md`, `rules/` and your
|
|
367
|
+
const lines = [`## ${target.header}`, '', '_Generated by agent-personalizer from `USER.md`, `LEARNED.md`, `rules/` and your saved preferences. Edit those, then re-render. Do not edit between the markers._', ''];
|
|
337
368
|
if (target.boxes) {
|
|
338
369
|
// The profile's own bytes win over stored answers. A generated profile can still be compact,
|
|
339
370
|
// but custom structure or prose stays in full. Box 2 uses the contract and inject:true rules
|
|
340
|
-
// when answers exist, or every rule for this surface without
|
|
371
|
+
// when answers exist, or every rule for this surface without saved answers.
|
|
341
372
|
const picked = rulesFor(rules, key, answers).filter(r => !answers || r.meta.inject === true);
|
|
342
373
|
const ruleText = picked.map(r => {
|
|
343
374
|
const s = r.sections, parts = [s.universal];
|
|
@@ -345,7 +376,14 @@ function renderTarget(key, target, profile, rules, cfg, root) {
|
|
|
345
376
|
if (target.binding && s[`binding:${target.binding}`]) parts.push(s[`binding:${target.binding}`]);
|
|
346
377
|
return parts.join('\n\n');
|
|
347
378
|
}).join('\n\n');
|
|
348
|
-
|
|
379
|
+
let box1 = answers ? (profile ? onboarding.compactProfileFromUser(profile.source, answers, { notesScaffolded: notesScaffolded(root, answers), entries: learned }) : onboarding.compactProfile(answers)) : (profile ? profile.body : '(no USER.md found)');
|
|
380
|
+
if (target.personal) {
|
|
381
|
+
if (learned.confirmed.length) box1 += '\nConfirmed entries:\n' + learned.confirmed.map(x => '- ' + x.entry).join('\n');
|
|
382
|
+
if (learned.declined.length) {
|
|
383
|
+
box1 += '\nNever ask again:\n' + learned.declined.map(x => '- ' + x.entry).join('\n');
|
|
384
|
+
}
|
|
385
|
+
lines.push(`_LEARNED.md source: ${learned.hash}_`, '');
|
|
386
|
+
}
|
|
349
387
|
const box2 = answers ? [onboarding.contractBlock(answers, { files: false, notesScaffolded: notesScaffolded(root, answers) }).split('\n').slice(2).join('\n'), ruleText].filter(Boolean).join('\n\n') : ruleText;
|
|
350
388
|
const over = [];
|
|
351
389
|
const warn = (label, text) => {
|
|
@@ -364,6 +402,10 @@ function renderTarget(key, target, profile, rules, cfg, root) {
|
|
|
364
402
|
return lines.join('\n');
|
|
365
403
|
}
|
|
366
404
|
if (target.profile && profile) lines.push('## Profile', '', profile.body, '');
|
|
405
|
+
if (target.personal && target.profile) {
|
|
406
|
+
lines.push(onboarding.entriesBlock(learned), '', `_LEARNED.md source: ${learned.hash}_`, '');
|
|
407
|
+
if (['claude', 'agents', 'gemini'].includes(key)) lines.push(onboarding.learningProcedure(), '');
|
|
408
|
+
}
|
|
367
409
|
lines.push('## Rules', '');
|
|
368
410
|
for (const r of rulesFor(rules, key, answers)) lines.push(renderRule(r, target), '');
|
|
369
411
|
return lines.join('\n').trimEnd();
|
|
@@ -380,7 +422,7 @@ function markerState(text, where) {
|
|
|
380
422
|
lines.forEach((raw, i) => {
|
|
381
423
|
if (!fenced[i]) {
|
|
382
424
|
const t = (raw.endsWith('\r') ? raw.slice(0, -1) : raw).trim();
|
|
383
|
-
if (t === BEGIN) b.push([pos, pos + raw.length]);
|
|
425
|
+
if (t === BEGIN) b.push([pos + (i === 0 && raw.startsWith('\ufeff') ? 1 : 0), pos + raw.length]);
|
|
384
426
|
else if (t === END) e.push([pos, pos + raw.length]);
|
|
385
427
|
}
|
|
386
428
|
pos += raw.length + 1;
|
|
@@ -430,6 +472,7 @@ function main() {
|
|
|
430
472
|
const contract = !!arg('--contract', false);
|
|
431
473
|
const rules = loadRules(root, arg('--rules', null));
|
|
432
474
|
const profile = loadProfile(root);
|
|
475
|
+
const learned = readLearned(root);
|
|
433
476
|
|
|
434
477
|
if (contract) {
|
|
435
478
|
const key = arg('--contract-target', 'claude');
|
|
@@ -446,6 +489,10 @@ function main() {
|
|
|
446
489
|
if (target.binding && r.sections[`binding:${target.binding}`]) out.push('', r.sections[`binding:${target.binding}`]);
|
|
447
490
|
out.push('');
|
|
448
491
|
}
|
|
492
|
+
if (withPersonal) {
|
|
493
|
+
out.push(onboarding.entriesBlock(learned), '');
|
|
494
|
+
if (['claude', 'agents', 'gemini'].includes(key) && pendingDigest(root, learned)) out.push('[agent-personalizer] New session digest: run /personalize to review up to 5 questions.');
|
|
495
|
+
}
|
|
449
496
|
process.stdout.write(out.join('\n'));
|
|
450
497
|
return;
|
|
451
498
|
}
|
|
@@ -468,31 +515,39 @@ function main() {
|
|
|
468
515
|
const target = TARGETS[key];
|
|
469
516
|
if (!target) die(`unknown target "${key}" (known: ${KNOWN.join(', ')})`);
|
|
470
517
|
const file = safeTargetPath(root, target.file, key);
|
|
471
|
-
const block = renderTarget(key, target, profile, rules, cfg, root);
|
|
472
|
-
let existing = null;
|
|
518
|
+
const block = renderTarget(key, target, profile, rules, cfg, root, learned);
|
|
519
|
+
let existing = null, existingBytes = null, hasBom = false;
|
|
473
520
|
if (fs.existsSync(file)) {
|
|
474
|
-
|
|
521
|
+
existingBytes = fs.readFileSync(file);
|
|
522
|
+
hasBom = hasUtf8Bom(existingBytes);
|
|
523
|
+
existing = decodeUtf8(existingBytes, target.file);
|
|
475
524
|
}
|
|
476
525
|
if (!check) {
|
|
477
526
|
try { fs.accessSync(existing == null ? path.dirname(file) : file, fs.constants.W_OK); }
|
|
478
527
|
catch (_) { die(`${target.file}: not writable. Nothing was written`); }
|
|
479
528
|
}
|
|
480
529
|
const current = existing == null ? null : between(existing, target.file);
|
|
481
|
-
const
|
|
530
|
+
const body = check ? null : splice(existing, block, target.file);
|
|
482
531
|
// the generated file must itself re-parse to exactly one block, or the next render would refuse it
|
|
483
|
-
if (
|
|
532
|
+
if (body != null) { const st = markerState(body, `${target.file} (generated)`); if (st.kind !== 'one' || between(body, `${target.file} (generated)`) !== block) die(`${target.file}: generated content would not re-parse cleanly; a fence in USER.md or a rule is unbalanced. Nothing was written`); }
|
|
533
|
+
const output = body == null ? null : (hasBom ? '\ufeff' + body : body);
|
|
484
534
|
const mode = existing == null ? 0o644 : (fs.statSync(file).mode & 0o777);
|
|
485
|
-
const entry = { key, target, file, block, current, output, mode, report: report(target.file, existing, current, block, false) };
|
|
535
|
+
const entry = { key, target, file, block, current, existing, existingBytes, output, mode, report: report(target.file, existing, current, block, false) };
|
|
486
536
|
if (!target.boxes) return entry;
|
|
487
537
|
// the two plain paste files: whole-file outputs, no markers, compared whole in --check
|
|
488
538
|
const raws = Object.entries(target.boxFiles || {}).map(([which, rel]) => {
|
|
489
539
|
const rfile = safeTargetPath(root, rel, `${key}:${which}`);
|
|
490
540
|
const text = renderTarget.boxes[which];
|
|
491
|
-
let rexisting = null;
|
|
492
|
-
if (fs.existsSync(rfile))
|
|
541
|
+
let rexisting = null, rhasBom = false;
|
|
542
|
+
if (fs.existsSync(rfile)) {
|
|
543
|
+
const rbytes = fs.readFileSync(rfile);
|
|
544
|
+
rhasBom = hasUtf8Bom(rbytes);
|
|
545
|
+
rexisting = decodeUtf8(rbytes, rel);
|
|
546
|
+
}
|
|
493
547
|
if (!check) { try { fs.accessSync(rexisting == null ? path.dirname(rfile) : rfile, fs.constants.W_OK); } catch (_) { die(`${rel}: not writable. Nothing was written`); } }
|
|
494
548
|
const rmode = rexisting == null ? 0o644 : (fs.statSync(rfile).mode & 0o777);
|
|
495
|
-
|
|
549
|
+
const routput = check ? null : (rhasBom ? '\ufeff' + text : text);
|
|
550
|
+
return { key: `${key}:${which}`, target: { file: rel }, file: rfile, block: text, current: rexisting, output: routput, mode: rmode, raw: true, report: report(rel, rexisting, rexisting, text, true) };
|
|
496
551
|
});
|
|
497
552
|
return [entry, ...raws];
|
|
498
553
|
}).flat();
|
|
@@ -501,6 +556,10 @@ function main() {
|
|
|
501
556
|
console.error('render: --strict: a box is over its budget. Nothing was written');
|
|
502
557
|
process.exit(1);
|
|
503
558
|
}
|
|
559
|
+
if (!check) {
|
|
560
|
+
const config = installedConfig(root, plan);
|
|
561
|
+
if (config) plan.push(config);
|
|
562
|
+
}
|
|
504
563
|
|
|
505
564
|
// Every final path must be distinct, and no final path may look like a staging file.
|
|
506
565
|
// Checked in every mode, before any output.
|
|
@@ -572,36 +631,34 @@ function main() {
|
|
|
572
631
|
} catch (e) { undo(`could not commit output (${e.message})`); }
|
|
573
632
|
const leftovers = [];
|
|
574
633
|
for (const c of committed) if (c.bak) tryUnlink(c.bak, leftovers, 'backup not removed');
|
|
575
|
-
for (const s of staged) console.log(s.report);
|
|
634
|
+
for (const s of staged) if (s.report) console.log(s.report);
|
|
576
635
|
for (const o of (renderTarget.overBudget || [])) console.log(`OVER BUDGET ${o} (written in full; trim by hand, bottom up)`);
|
|
577
636
|
if (leftovers.length) {
|
|
578
637
|
console.error('render: every target was written, but CLEANUP INCOMPLETE. Remove these by hand (they hold copies of the previous targets):');
|
|
579
638
|
for (const l of leftovers) console.error(` ${l}`);
|
|
580
639
|
process.exit(2);
|
|
581
640
|
}
|
|
582
|
-
recordInstalled(root, plan);
|
|
583
641
|
}
|
|
584
642
|
|
|
585
|
-
/*
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
block belongs to this tool, so only the block is hashed; the surrounding bytes are the user's
|
|
591
|
-
and are never fingerprinted. Read only; never runs during --check (nothing was written), and
|
|
592
|
-
a config predating this field, or none at all, is left exactly as it is. */
|
|
593
|
-
function recordInstalled(root, plan) {
|
|
643
|
+
/* Plan ownership updates in the same transaction as the targets. A whole-file hash can advance
|
|
644
|
+
only from bytes already recorded as ours; an edited outer file keeps its old hash so uninstall
|
|
645
|
+
retains it. Preserved targets record only the block. User bytes are never adopted on re-render.
|
|
646
|
+
A config predating the installed map stays without it so legacy recipe fallback still applies. */
|
|
647
|
+
function installedConfig(root, plan) {
|
|
594
648
|
const cfgPath = path.join(root, '.agent-personalizer.json');
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
649
|
+
if (!mustBe(cfgPath, 'file', '.agent-personalizer.json')) return null;
|
|
650
|
+
const raw = readJson(cfgPath, 'config');
|
|
651
|
+
try { fs.accessSync(cfgPath, fs.constants.W_OK); }
|
|
652
|
+
catch (_) { die('.agent-personalizer.json: not writable. Nothing was written'); }
|
|
653
|
+
if (!raw.installed || typeof raw.installed !== 'object' || Array.isArray(raw.installed)) return null;
|
|
654
|
+
const installed = { ...raw.installed };
|
|
599
655
|
for (const p of plan) {
|
|
600
656
|
const preserved = !p.raw && Array.isArray(raw.preservedTargets) && raw.preservedTargets.includes(p.key);
|
|
657
|
+
if (!p.raw && !preserved && p.existingBytes !== null && installed[p.target.file] !== sha256(p.existingBytes)) continue;
|
|
601
658
|
installed[p.target.file] = sha256(Buffer.from(preserved ? p.block : p.output));
|
|
602
659
|
}
|
|
603
660
|
raw.installed = installed;
|
|
604
|
-
|
|
661
|
+
return { file: cfgPath, target: { file: '.agent-personalizer.json' }, output: JSON.stringify(raw, null, 2) + '\n', mode: fs.statSync(cfgPath).mode & 0o777 };
|
|
605
662
|
}
|
|
606
663
|
|
|
607
664
|
/* Everything the renderer would refuse about the SOURCES already present in a folder, checked without
|
|
@@ -610,6 +667,7 @@ function recordInstalled(root, plan) {
|
|
|
610
667
|
function preflightSources(root) {
|
|
611
668
|
if (mustBe(path.join(root, 'rules'), 'dir', 'rules/')) loadRules(root, null); // library call: never read argv; a kept local rules/ must parse; package rules are the package's problem
|
|
612
669
|
loadProfile(root);
|
|
670
|
+
readLearned(root);
|
|
613
671
|
}
|
|
614
672
|
|
|
615
673
|
/* Pure output planning for uninstall. Uses this package's renderer, never executable code from
|
|
@@ -617,13 +675,14 @@ function preflightSources(root) {
|
|
|
617
675
|
function renderedContents(root, cfg) {
|
|
618
676
|
const rules = loadRules(root, null);
|
|
619
677
|
const profile = loadProfile(root);
|
|
678
|
+
const learned = readLearned(root);
|
|
620
679
|
renderTarget.boxes = null;
|
|
621
680
|
renderTarget.overBudget = [];
|
|
622
681
|
return cfg.targets.flatMap(key => {
|
|
623
682
|
const target = TARGETS[key];
|
|
624
683
|
if (!target) die(`unknown target "${key}"`);
|
|
625
684
|
safeTargetPath(root, target.file, key);
|
|
626
|
-
const block = renderTarget(key, target, profile, rules, cfg, root);
|
|
685
|
+
const block = renderTarget(key, target, profile, rules, cfg, root, learned);
|
|
627
686
|
const out = [{ key, rel: target.file, block }];
|
|
628
687
|
if (target.boxes) for (const [which, rel] of Object.entries(target.boxFiles || {})) {
|
|
629
688
|
safeTargetPath(root, rel, `${key}:${which}`);
|
|
@@ -636,5 +695,5 @@ function renderedContents(root, cfg) {
|
|
|
636
695
|
/* parseFrontmatter and parseSections are exported so another renderer can read the same rule-file
|
|
637
696
|
format with the same validation (for example one that renders CLAUDE.md sections and session-start
|
|
638
697
|
hook bodies from rules in this format). Set DIE_THROWS to get a Refusal instead of an exit. */
|
|
639
|
-
module.exports = { main, fenceMap, markerState, splice, between, preflightSources, parseFrontmatter, parseSections, readConfig, validatePreservedTargets, renderedContents, Refusal, DIE_THROWS: false };
|
|
698
|
+
module.exports = { readLearned, pendingDigest, main, fenceMap, markerState, splice, between, preflightSources, parseFrontmatter, parseSections, readConfig, validatePreservedTargets, renderedContents, Refusal, DIE_THROWS: false };
|
|
640
699
|
if (require.main === module) main();
|
|
@@ -11,7 +11,7 @@ Before the first substantive reply of a session, read the user's profile (`USER.
|
|
|
11
11
|
In practice: two files, read before you answer anything, every time you start.
|
|
12
12
|
|
|
13
13
|
## personal
|
|
14
|
-
|
|
14
|
+
For learned entries, `LEARNED.md` owns the current status; a summary in the profile may lag until a re-run. For other profile content, if the profile and a rendered instruction file disagree, the profile wins: the rendered file is generated from it and is the one that drifted.
|
|
15
15
|
|
|
16
16
|
## binding:claude
|
|
17
17
|
`USER.md` sits next to `CLAUDE.md`. In Claude Code, `CLAUDE.md` loads automatically; `USER.md` does not, so the first action of a session is to read it.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 65-ask-before-it-repeats
|
|
3
|
+
title: Ask before it repeats
|
|
4
|
+
inject: true
|
|
5
|
+
surfaces: [claude, agents, gemini, chatgpt]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## universal
|
|
9
|
+
On the second same correction, ask once: "Make it a rule?" Name both moments. Yes: said, confirmed. No: said, declined; never ask again.
|
|
10
|
+
|
|
11
|
+
In practice: ask before keeping a pattern.
|
|
12
|
+
|
|
13
|
+
## personal
|
|
14
|
+
Write the answer to `LEARNED.md`, then re-render every selected AI's instructions. Check confirmed and declined entries before asking; neither needs the same question again.
|
|
15
|
+
|
|
16
|
+
## origin
|
|
17
|
+
Written after: a user repeated the same correction in several sessions. The AI obeyed each time, then forgot it, while an unapproved guess in memory became a standing rule.
|
|
18
|
+
Prevents: repeated corrections and guesses kept as the user's rulings.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 70-their-words-point-at-the-thing
|
|
3
|
+
title: Their words point at the thing
|
|
4
|
+
inject: false
|
|
5
|
+
surfaces: [claude, agents, gemini, chatgpt, prompt]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## universal
|
|
9
|
+
The thing is the result, problem or quality the person means: how it should feel, look or work. Their word is the closest handle they had. Trust an example they liked or rejected over the word itself. If uncertainty changes the work, ask one question about the result ("calmer, or just shorter?"). Quote their word as theirs; never turn it into a spec, rule or label.
|
|
10
|
+
|
|
11
|
+
In practice: their word is a pointer. Look where it points and build that.
|
|
12
|
+
|
|
13
|
+
## origin
|
|
14
|
+
Written after: someone called a draft "clickbait-y", meaning it should pull harder, and the AI wrote "clickbait is allowed" into their rules.
|
|
15
|
+
Prevents: a passing word becoming a rule that misfires for months.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 80-symptoms-are-not-causes
|
|
3
|
+
title: Symptoms are not causes
|
|
4
|
+
inject: false
|
|
5
|
+
surfaces: [claude, agents, gemini, chatgpt, prompt]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## universal
|
|
9
|
+
The user describes what they see. On the second unchanged report, measure instead of re-fixing. Find evidence that can distinguish the possible causes before changing the work again.
|
|
10
|
+
|
|
11
|
+
In practice: a repeated symptom calls for a measurement, then a fix.
|
|
12
|
+
|
|
13
|
+
## origin
|
|
14
|
+
Written after: the same "it looks dull" report came three times. Three fixes made it worse; one measurement found the cause.
|
|
15
|
+
Prevents: repeating a fix for a cause that was never checked.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: 90-surface-what-they-cant-see
|
|
3
|
+
title: Surface what they can't see
|
|
4
|
+
inject: false
|
|
5
|
+
surfaces: [claude, agents, gemini, chatgpt, prompt]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## universal
|
|
9
|
+
Give one line on a risk, cost, faster path or stale assumption the user did not ask about, inside the task's scope. Use evidence and make the next step usable.
|
|
10
|
+
|
|
11
|
+
In practice: show the relevant thing the user could not see from their side.
|
|
12
|
+
|
|
13
|
+
## origin
|
|
14
|
+
Written after: an AI completed the requested change while a stale assumption made the result unusable. It had enough evidence to warn the user and stayed silent because nobody asked.
|
|
15
|
+
Prevents: correct execution that misses a visible problem within the task.
|
package/rules/README.md
CHANGED
|
@@ -53,3 +53,7 @@ Files render in filename order. The two-digit prefix is the order; leave gaps.
|
|
|
53
53
|
| `40-sign-every-edit.md` | One signature line, overwritten | no |
|
|
54
54
|
| `50-output-style.md` | Lead with the answer, one item per line, no recap | yes |
|
|
55
55
|
| `60-act-or-ask.md` | Fetch a missing fact; ask for a missing mandate | no |
|
|
56
|
+
| `65-ask-before-it-repeats.md` | Ask once before keeping a repeated correction | yes |
|
|
57
|
+
| `70-their-words-point-at-the-thing.md` | Find the result, problem or quality behind the user's word | no |
|
|
58
|
+
| `80-symptoms-are-not-causes.md` | Measure when the same symptom survives a fix | no |
|
|
59
|
+
| `90-surface-what-they-cant-see.md` | Name one relevant risk, cost, faster path or stale assumption | no |
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# LEARNED.md
|
|
2
|
+
|
|
3
|
+
Entries you approve belong here. Each line names where it came from and whether you approved it. You own this file; re-runs and uninstall keep it.
|
|
4
|
+
|
|
5
|
+
Format: `- [said|inferred, confirmed|proposed|declined] <entry> (evidence: <short evidence>)`. Evidence is optional. Only confirmed entries become instructions. Declined entries stop the question coming back.
|
|
6
|
+
|
|
7
|
+
## Learned
|
|
8
|
+
|
|
9
|
+
## Asked
|
|
10
|
+
|
|
11
|
+
Digest ids already discussed, one per line: `- digest: <ISO timestamp>`.
|