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/CHANGELOG.md +22 -1
- package/README.md +17 -7
- package/RELEASING.md +1 -1
- package/SECURITY.md +3 -1
- package/bin/agent-personalizer.js +130 -81
- package/bin/global.cjs +201 -0
- package/bin/home.cjs +15 -0
- package/bin/install-plan.cjs +7 -2
- package/bin/known-hashes.json +78 -0
- package/bin/learn.cjs +2 -2
- package/bin/sessions.cjs +48 -15
- package/bin/uninstall.cjs +2 -1
- package/docs/guarantees.md +2 -2
- package/docs/install.md +27 -5
- package/docs/learning.md +1 -1
- package/docs/paste-guide.md +5 -3
- package/examples/freelance-illustrator/.agent-personalizer.json +1 -1
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +1 -1
- package/examples/freelance-illustrator/rules/README.md +2 -0
- package/examples/lab-technician/rules/README.md +2 -0
- package/examples/product-designer/rules/README.md +2 -0
- package/hooks/README.md +1 -1
- package/package.json +1 -1
- package/render/onboarding.cjs +1 -1
- package/render/render.cjs +14 -6
- package/rules/README.md +2 -0
package/render/render.cjs
CHANGED
|
@@ -83,6 +83,7 @@ const BINDINGS = new Set(Object.values(TARGETS).map(t => t.binding).filter(Boole
|
|
|
83
83
|
const SECTION_RE = /^(universal|personal|origin|binding:[a-z]+)$/;
|
|
84
84
|
const META_KEYS = new Set(['id', 'title', 'inject', 'surfaces', 'requires']);
|
|
85
85
|
const RULE_FILE_RE = /^\d{2}-[A-Za-z0-9._-]+\.md$/;
|
|
86
|
+
const CORE_RULE_FILES = new Set(['00-read-the-profile-first.md', '10-evidence-before-assertion.md', '50-output-style.md', '60-act-or-ask.md', '65-ask-before-it-repeats.md']);
|
|
86
87
|
|
|
87
88
|
|
|
88
89
|
const VALUE_OPTS = ['--dir', '--targets', '--contract-target', '--rules'];
|
|
@@ -283,7 +284,12 @@ function loadRules(root, explicit) {
|
|
|
283
284
|
function loadProfile(root) {
|
|
284
285
|
const p = path.join(root, 'USER.md');
|
|
285
286
|
if (!fs.existsSync(p) && !(() => { try { fs.lstatSync(p); return true; } catch (_) { return false; } })()) return null;
|
|
286
|
-
|
|
287
|
+
return profileFromSource(readSource(p, 'USER.md'));
|
|
288
|
+
}
|
|
289
|
+
function profileFromSource(source) {
|
|
290
|
+
if (typeof source !== 'string') die('USER.md: profile source must be text');
|
|
291
|
+
const text = source.replace(/^\ufeff/, '').replace(/\r\n/g, '\n');
|
|
292
|
+
rejectMarkers(text, 'USER.md');
|
|
287
293
|
fenceMap(text.split('\n'), 'USER.md'); // an unterminated fence in the profile is an error, not a surprise later
|
|
288
294
|
return { source: text, body: text.replace(/^#\s+USER\.md\s*\n/, '').replace(/\n---\n\*Template from agent-personalizer[^\n]*\n?$/, '').trim() };
|
|
289
295
|
}
|
|
@@ -321,6 +327,7 @@ function rulesFor(rules, key, answers) {
|
|
|
321
327
|
return rules.filter(r => (!Array.isArray(r.meta.surfaces) || r.meta.surfaces.includes(key))
|
|
322
328
|
&& (!r.meta.requires || a[r.meta.requires.answer] === r.meta.requires.value));
|
|
323
329
|
}
|
|
330
|
+
const rulesAtLevel = (rules, cfg) => cfg && (cfg.level === 1 || cfg.level === 2) ? rules.filter(r => CORE_RULE_FILES.has(r.file)) : rules;
|
|
324
331
|
const answersOf = (cfg) => (cfg && cfg.onboarding) ? cfg.onboarding : null;
|
|
325
332
|
/* Do the notes pointers in a rendered file name something that is there? The README is the file the
|
|
326
333
|
AI is told to read before it writes, and the level-2 scaffold creates it with the folder, so its
|
|
@@ -363,6 +370,7 @@ function renderTarget(key, target, profile, rules, cfg, root, learned) {
|
|
|
363
370
|
if (!cfg || !cfg.onboarding) die(`target "${key}": no onboarding answers in .agent-personalizer.json. Run the installer, or pass --answers <file>`);
|
|
364
371
|
return onboarding.renderOnboarding(cfg.onboarding, { notesScaffolded: notesScaffolded(root, cfg.onboarding) });
|
|
365
372
|
}
|
|
373
|
+
rules = rulesAtLevel(rules, cfg);
|
|
366
374
|
const answers = answersOf(cfg);
|
|
367
375
|
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._', ''];
|
|
368
376
|
if (target.boxes) {
|
|
@@ -480,7 +488,7 @@ function main() {
|
|
|
480
488
|
const target = TARGETS[key];
|
|
481
489
|
const withPersonal = target.personal && !arg('--no-personal', false);
|
|
482
490
|
const cfgC = readConfig(root);
|
|
483
|
-
const inject = rulesFor(rules, key, answersOf(cfgC)).filter(r => r.meta.inject === true);
|
|
491
|
+
const inject = rulesFor(rulesAtLevel(rules, cfgC), key, answersOf(cfgC)).filter(r => r.meta.inject === true);
|
|
484
492
|
const out = [`[agent-personalizer] Session-start contract for ${key}. Injected in full at the start of every session so these rules are in context at the moment of decision.`, ''];
|
|
485
493
|
if (cfgC && cfgC.onboarding && withPersonal) out.push(onboarding.contractBlock(cfgC.onboarding, { notesScaffolded: notesScaffolded(root, cfgC.onboarding) }), '');
|
|
486
494
|
for (const r of inject) {
|
|
@@ -672,10 +680,10 @@ function preflightSources(root) {
|
|
|
672
680
|
|
|
673
681
|
/* Pure output planning for uninstall. Uses this package's renderer, never executable code from
|
|
674
682
|
the installed folder. The caller preflights all paths before asking for these bytes. */
|
|
675
|
-
function renderedContents(root, cfg) {
|
|
683
|
+
function renderedContents(root, cfg, options = {}) {
|
|
676
684
|
const rules = loadRules(root, null);
|
|
677
|
-
const profile = loadProfile(root);
|
|
678
|
-
const learned = readLearned(root);
|
|
685
|
+
const profile = Object.hasOwn(options, 'profileSource') ? profileFromSource(options.profileSource) : loadProfile(root);
|
|
686
|
+
const learned = options.learned || readLearned(root);
|
|
679
687
|
renderTarget.boxes = null;
|
|
680
688
|
renderTarget.overBudget = [];
|
|
681
689
|
return cfg.targets.flatMap(key => {
|
|
@@ -695,5 +703,5 @@ function renderedContents(root, cfg) {
|
|
|
695
703
|
/* parseFrontmatter and parseSections are exported so another renderer can read the same rule-file
|
|
696
704
|
format with the same validation (for example one that renders CLAUDE.md sections and session-start
|
|
697
705
|
hook bodies from rules in this format). Set DIE_THROWS to get a Refusal instead of an exit. */
|
|
698
|
-
module.exports = { readLearned, pendingDigest, main, fenceMap, markerState, splice, between, preflightSources, parseFrontmatter, parseSections, readConfig, validatePreservedTargets, renderedContents, Refusal, DIE_THROWS: false };
|
|
706
|
+
module.exports = { CORE_RULE_FILES, readLearned, pendingDigest, main, fenceMap, markerState, splice, between, preflightSources, parseFrontmatter, parseSections, readConfig, validatePreservedTargets, renderedContents, Refusal, DIE_THROWS: false };
|
|
699
707
|
if (require.main === module) main();
|
package/rules/README.md
CHANGED
|
@@ -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
|