agent-personalizer 0.4.3 → 0.5.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/README.md +32 -15
- package/bin/agent-personalizer.js +137 -58
- package/docs/companions.md +1 -1
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +2 -2
- package/hooks/README.md +1 -1
- package/package.json +1 -1
- package/render/onboarding.cjs +96 -17
- package/render/render.cjs +32 -10
- package/templates/FOLDER_README.md +2 -2
- package/templates/INBOX_README.md +1 -1
- package/templates/decisions-log.md +2 -2
- package/templates/session-log.md +3 -3
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
Most people set up custom instructions once, in one app, and still get generic output. The instructions decay over a long chat, the AI forgets where things are, every app has its own copy that drifts, and the AI treats its own guesses about you as your rulings.
|
|
8
8
|
|
|
9
|
-
This repo is the fix, in
|
|
9
|
+
This repo is the fix, in three install levels. Stop at the level you need. A level is the only thing the installer asks you to pick.
|
|
10
10
|
|
|
11
|
-
| Level | You have |
|
|
11
|
+
| Level | You have | It writes |
|
|
12
12
|
|---|---|---|
|
|
13
|
-
| **1.
|
|
14
|
-
| **2. Dynamic docs** | a notes folder the AI may edit |
|
|
15
|
-
| **3. Mechanisms** | a coding agent (Claude Code, Codex, Cursor) | the automation: your own copy of `rules/` to edit, one rule source rendered per AI, a session-start contract that puts your rules in context at decision time, a drift check that fails loudly, a forbidden-string gate. |
|
|
16
|
-
|
|
13
|
+
| **1. Profile and home file** | one AI, one app | four files and no folders: a profile of you (`USER.md`), an agent onboarding file written from your answers (`AGENT_ONBOARDING.md`), a home file the AI reads first (`CLAUDE.md` or `AGENTS.md`) with the rules rendered into it, and the installer's own `.agent-personalizer.json`. Nothing else, and the home file names nothing that is not there. |
|
|
14
|
+
| **2. Dynamic docs** | a notes folder the AI may edit | everything in level 1, plus the notes folder itself: a folder index, a weekly session log, a decisions log and an inbox, each with the rules the AI follows when it writes there. Instructions, not automation: the AI does the keeping. |
|
|
15
|
+
| **3. Mechanisms** | a coding agent (Claude Code, Codex, Cursor) | everything above, plus the automation: your own copy of `rules/` to edit, one rule source rendered per AI, a session-start contract that puts your rules in context at decision time, a drift check that fails loudly, a forbidden-string gate. |
|
|
16
|
+
|
|
17
|
+
Level 3 is the top. There is a fourth tier of this system, the hand-off layer, but it ships no files yet and the installer does not offer it: [read what it is](#the-hand-off-layer-not-an-install-level) rather than installing it.
|
|
17
18
|
|
|
18
19
|
Everything here is the generalized shape of a system that runs in production every day. The examples are invented. The failures the rules prevent are real.
|
|
19
20
|
|
|
@@ -29,7 +30,19 @@ Everything here is the generalized shape of a system that runs in production eve
|
|
|
29
30
|
npx agent-personalizer
|
|
30
31
|
```
|
|
31
32
|
|
|
32
|
-
Published on npm with provenance from this repository's own workflow (`npx github:aunysillyme/agent-personalizer` still works and runs the same code straight from the tag). The installer asks which AIs you use and which level you want, then writes only the matching files into the folder you point it at. It never writes secrets. `--help` lists every flag
|
|
33
|
+
Published on npm with provenance from this repository's own workflow (`npx github:aunysillyme/agent-personalizer` still works and runs the same code straight from the tag). The installer asks which AIs you use and which level you want, then writes only the matching files into the folder you point it at. It never writes secrets. `--help` lists every flag.
|
|
34
|
+
|
|
35
|
+
**The interview is short by default.** A bare `npx agent-personalizer` asks the seven questions that change behaviour (name, tone, length, notes tool and path, write policy, always-ask) plus any question the notes tool you pick makes apply, and defaults the rest. `--full` asks all 23.
|
|
36
|
+
|
|
37
|
+
**`--yes` and `--defaults` are not the same flag.**
|
|
38
|
+
|
|
39
|
+
- `--defaults` is the ANSWER SOURCE: accept every default without being asked. Use it with or without `--yes`.
|
|
40
|
+
- `--yes` is NON-INTERACTIVE MODE. It needs `--dir`, `--ai` and `--level`; without those it exits 2. With no `--answers` it falls back to the defaults.
|
|
41
|
+
- `--answers file.json` (or `--answers -` from stdin) is the other answer source, and scripts the whole interview.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx agent-personalizer --dir . --ai claude,agents --level 1 --yes --defaults
|
|
45
|
+
```
|
|
33
46
|
|
|
34
47
|
No Node? Copy `templates/USER.md` and `templates/CLAUDE.md` (or `templates/AGENTS.md`) into your project by hand. That is level 1.
|
|
35
48
|
|
|
@@ -41,9 +54,9 @@ npm_config_cache=./.npm-cache npx agent-personalizer
|
|
|
41
54
|
|
|
42
55
|
---
|
|
43
56
|
|
|
44
|
-
##
|
|
57
|
+
## Why this works: the five places instructions live
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
**These are not the install levels, and there is nothing to pick here.** The levels above are what the installer writes. The five tiers below are where instructions live once they are written, and why each placement exists. Read [docs/tiers.md](docs/tiers.md) before writing a rule of your own.
|
|
47
60
|
|
|
48
61
|
| Tier | What | Prevents |
|
|
49
62
|
|---|---|---|
|
|
@@ -63,20 +76,22 @@ Your instructions live in five places, each with one job and one failure it prev
|
|
|
63
76
|
|
|
64
77
|
The installer asks you how an AI should work with you, then writes the answers to `AGENT_ONBOARDING.md`: how to talk to you, how to shape output, what to read first and in what order, where it may write, how to save a file, and what it must always ask before doing. It is generated from your answers in `.agent-personalizer.json`, so every AI you point at the folder gets the same manual, and re-running the installer changes it everywhere at once.
|
|
65
78
|
|
|
66
|
-
- **Interactive**: run the installer without `--yes` and answer the questions. Enter accepts the default.
|
|
67
|
-
- **Scripted**: `--answers my-answers.json` (see [`test/fixtures/answers.json`](test/fixtures/answers.json) for the shape). Unknown keys, wrong types or unknown choices are refused before anything is written.
|
|
68
|
-
- **Defaults**: `--defaults`
|
|
79
|
+
- **Interactive**: run the installer without `--yes` and answer the questions. Enter accepts the default. The short interview is the default: seven questions, plus any the notes tool you pick makes apply. `--full` asks all 23. A question that applies to one notes tool is never asked about another, so nobody answers the Obsidian question about Notion.
|
|
80
|
+
- **Scripted**: `--answers my-answers.json` (see [`test/fixtures/answers.json`](test/fixtures/answers.json) for the shape), or `--answers -` to read the JSON from stdin. Unknown keys, wrong types or unknown choices are refused before anything is written.
|
|
81
|
+
- **Defaults**: `--defaults`. That is the answer source, and it is not `--yes`, which is non-interactive mode and needs `--dir`, `--ai` and `--level`. A non-interactive run with no answer source falls back to the defaults and says so. The defaults are one working setup: direct, short, one-line corrections, settle facts yourself and ask only when the answer changes what gets built, verdict first, bullets, evidence inline, sign every edit, always ask before delete / publish / send / spend / settings / standing rules. Every one is a question you can answer differently.
|
|
69
82
|
|
|
70
83
|
`USER.md` is generated from the same answers the first time and is then yours to edit. Re-running with changed answers regenerates `AGENT_ONBOARDING.md` and every rendered block; `USER.md` is regenerated only if you never edited it (it still equals the render of the previous answers), otherwise it is kept and the installer names the answers that changed so you can carry them over by hand. Two rules depend on answers: the signature rule renders only when you answered yes, and the output-style rule defers to your stated shape instead of imposing one. The session-start contract carries a short version of the onboarding block, restrictions first, so it is present at the moment of decision, not only in a file.
|
|
71
84
|
|
|
72
85
|
ChatGPT has two custom-instruction boxes with a character budget, so its render is the compact profile plus the onboarding block and only the `inject: true` rules, each box measured against the budget, and written twice: inside `chatgpt-custom-instructions.md` with the counts, and as two plain paste files, `chatgpt-box1.txt` and `chatgpt-box2.txt`. `render.cjs --strict` exits 1 instead of writing when a box is over budget, for people who wire the render into CI. Nothing is cut silently: an over-budget box is written in full and flagged, ordered so the last lines are the cheapest to trim. For the rest of the rules, use a ChatGPT Project and upload `AGENT_ONBOARDING.md` and `rules/` as files.
|
|
73
86
|
|
|
74
|
-
## Level 1: one file
|
|
87
|
+
## Level 1: the profile and one home file
|
|
75
88
|
|
|
76
89
|
1. Fill in [`templates/USER.md`](templates/USER.md), or let the installer generate it from your onboarding answers. Who you are, how to talk to you, how firmly you mean things, how you want output shaped.
|
|
77
90
|
2. Copy [`templates/CLAUDE.md`](templates/CLAUDE.md) for Claude, or [`templates/AGENTS.md`](templates/AGENTS.md) for Codex, Cursor and most other coding agents. Both are pointers: they tell the AI to read `USER.md` first and where everything else lives.
|
|
78
91
|
3. Paste the `USER.md` body into the "custom instructions" box of any chat app that has one.
|
|
79
92
|
|
|
93
|
+
Level 1 creates no notes folder, so none of the files it writes names one. The home file points at `AGENT_ONBOARDING.md` for where the AI may write; `AGENT_ONBOARDING.md` and `USER.md` say outright that the folder is not on disk yet and that the AI is to propose writes rather than create it. Level 2 creates the folder and repoints all three at it in the same run.
|
|
94
|
+
|
|
80
95
|
**The one idea in level 1:** the home file carries pointers, not hand-maintained copies. Text you retype drifts. A pointer does not, and neither does a block the renderer regenerates and `--check` compares (level 3): that block is a generated snapshot, with one owner and a drift check, which is the other acceptable shape.
|
|
81
96
|
|
|
82
97
|
## Level 2: dynamic docs
|
|
@@ -107,10 +122,12 @@ Two companions turn the onboarding answers from advice into enforcement. Neither
|
|
|
107
122
|
- **[obsidian-tc](https://github.com/The-40-Thieves/obsidian-tc)** for Obsidian vaults: governed MCP access. Your **off-limits** answer becomes a folder ACL, your **always-ask** answer becomes its human-in-the-loop list, and destructive tools fail closed until you confirm. `npx obsidian-tc /path/to/vault`.
|
|
108
123
|
- **[The Context Layer](https://sierracatalina.com/context-layer)** by Sierra Catalina: purpose-bound context with receipts. Capture → normalize → vault → decide → bundle → act; memory writes remain proposals. Your **write policy** and **off-limits** answers are its decide and vault stages in miniature. Read the essay first, then run the starter.
|
|
109
124
|
|
|
110
|
-
##
|
|
125
|
+
## The hand-off layer (not an install level)
|
|
111
126
|
|
|
112
127
|
Once you run several AIs, personalization is not the problem any more; routing is. That is a separate layer: which model handles which task, task bundles for every delegation, and CLI runs that only count as success when a deliverable exists. It is being built as its own repo and will link from here when it ships. This repo stays the beginner tier of that stack.
|
|
113
128
|
|
|
129
|
+
Nothing here installs it, so the installer stops at level 3. `--level 4` is still accepted, because it once was offered, and it writes exactly what `--level 3` writes.
|
|
130
|
+
|
|
114
131
|
---
|
|
115
132
|
|
|
116
133
|
## Every rule carries its story
|
|
@@ -133,7 +150,7 @@ examples/ one invented user, end to end
|
|
|
133
150
|
docs/ tiers.md, companions.md, paste-guide.md
|
|
134
151
|
CHANGELOG.md keyed on audit rounds
|
|
135
152
|
.github/ harness.yml: the checks on every push and PR, Ubuntu and macOS x Node 18/20/22, plus a Windows smoke job; publish.yml: npm publish with provenance, dispatched per tag
|
|
136
|
-
test/ run.sh:
|
|
153
|
+
test/ run.sh: 89 checks, exact exit codes, adversarial fixtures (symlinks, traversal, malformed markers, CRLF, partial renders)
|
|
137
154
|
```
|
|
138
155
|
|
|
139
156
|
## Changelog
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
/*
|
|
4
4
|
agent-personalizer installer.
|
|
5
5
|
|
|
6
|
-
npx agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3
|
|
7
|
-
[--answers <file.json>] [--defaults] [--yes]
|
|
6
|
+
npx agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3]
|
|
7
|
+
[--answers <file.json>] [--defaults] [--full] [--yes]
|
|
8
8
|
|
|
9
9
|
Interactive when flags are missing and stdin is a terminal. Non-interactive with flags.
|
|
10
10
|
The ONBOARDING INTERVIEW (how to talk to you, output shape, what to read first, where the AI
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"onboarding" in .agent-personalizer.json and rendered to AGENT_ONBOARDING.md; USER.md is
|
|
14
14
|
generated from the same answers when it does not exist yet.
|
|
15
15
|
Level 1 writes USER.md, AGENT_ONBOARDING.md and the home file(s); the rules render into the home
|
|
16
|
-
file from the package's own rules/ and nothing is copied
|
|
16
|
+
file from the package's own rules/ and nothing is copied, so the home files name no notes folder
|
|
17
|
+
(level 2 creates it, and level 2+ repoints them). Level 3 copies rules/ (yours to edit from
|
|
17
18
|
then on) with the renderer, hook and gate. .agent-personalizer.json stores only the answers that
|
|
18
19
|
differ from the defaults.
|
|
19
20
|
Writes only the files for the chosen AIs and level. Never overwrites a file that exists
|
|
@@ -44,21 +45,26 @@ const AI_LABEL = { claude: 'Claude (Claude Code, Claude apps)', agents: 'Codex /
|
|
|
44
45
|
function die(msg) { console.error(`agent-personalizer: ${msg}`); process.exit(2); }
|
|
45
46
|
|
|
46
47
|
const VALUE_OPTS = ['--dir', '--ai', '--level', '--answers'];
|
|
47
|
-
const FLAG_OPTS = ['--yes', '--defaults', '--quick', '--help', '--version', '-h', '-v'];
|
|
48
|
+
const FLAG_OPTS = ['--yes', '--defaults', '--quick', '--full', '--help', '--version', '-h', '-v'];
|
|
48
49
|
const USAGE = `agent-personalizer ${require(path.join(PKG, 'package.json')).version}
|
|
49
50
|
|
|
50
|
-
npx agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3
|
|
51
|
-
[--answers <file.json> | --answers - | --defaults] [--
|
|
51
|
+
npx agent-personalizer [--dir <folder>] [--ai claude,agents,gemini,chatgpt,prompt] [--level 1|2|3]
|
|
52
|
+
[--answers <file.json> | --answers - | --defaults] [--full] [--yes]
|
|
52
53
|
[--help | -h] [--version | -v]
|
|
53
54
|
|
|
54
55
|
Interactive when flags are missing and stdin is a terminal; the onboarding interview runs then.
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
The interview is SHORT by default: the seven questions that change behaviour (name, tone, length,
|
|
57
|
+
notes tool and path, write policy, always-ask), plus any question the notes tool you pick makes
|
|
58
|
+
apply. Every other answer takes its default.
|
|
59
|
+
--full ask every question instead of the short set. Interactive only.
|
|
60
|
+
--quick the short interview. It is now the default; the flag is kept so older commands still work.
|
|
57
61
|
--answers a JSON file of answers, or "-" to read the JSON from stdin. Unknown keys and values are refused.
|
|
58
|
-
--defaults accept every default without
|
|
59
|
-
--yes
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
--defaults the ANSWER SOURCE: accept every default without being asked. With or without --yes.
|
|
63
|
+
--yes NON-INTERACTIVE MODE, not an answer source. It needs --dir, --ai and --level, and with no
|
|
64
|
+
--answers it falls back to the defaults.
|
|
65
|
+
Levels: 1 profile, onboarding and home file(s); nothing else (the rules render from the package)
|
|
66
|
+
2 + the notes folder: its README, a weekly session log, a decisions log and an inbox
|
|
67
|
+
3 + the renderer, the session-start hook, the gate and a copy of rules/ to edit
|
|
62
68
|
exit codes: 0 ok · 1 unexpected error · 2 refused or invalid input
|
|
63
69
|
`;
|
|
64
70
|
/* Parse argv once, strictly: value options at most once each, flags at most once, nothing unknown. */
|
|
@@ -151,12 +157,15 @@ async function main() {
|
|
|
151
157
|
console.log('\nWhich AIs do you use? Comma-separated from:');
|
|
152
158
|
for (const k of AIS) console.log(` ${k.padEnd(8)} ${AI_LABEL[k]}`);
|
|
153
159
|
ais = ais || await ask('\nAIs', 'claude,agents');
|
|
154
|
-
console.log('\nLevels: 1
|
|
160
|
+
console.log('\nLevels: 1 profile, onboarding and home file(s) · 2 + the notes folder · 3 + renderer, session-start hook, gate and your own rules/');
|
|
155
161
|
level = level || await ask('Level', '1');
|
|
156
162
|
}
|
|
157
163
|
if (!dir || !ais || !level) die('non-interactive run needs --dir, --ai and --level (and --yes)');
|
|
158
|
-
if (!/^[1-4]$/.test(String(level))) die('level must be exactly 1, 2
|
|
164
|
+
if (!/^[1-4]$/.test(String(level))) die('level must be exactly 1, 2 or 3');
|
|
159
165
|
level = Number(level);
|
|
166
|
+
// 4 was once offered as a peer of 1-3 and installed exactly what 3 installs: the hand-off layer is
|
|
167
|
+
// reading material, not files. It is no longer offered, and still accepted so older scripts run.
|
|
168
|
+
if (level === 4) console.log('note: --level 4 installs exactly what --level 3 installs. The hand-off layer (routing, task bundles, verified CLI runs) is reading material until it ships, so 3 is the top install level.');
|
|
160
169
|
const targets = String(ais).split(',').map(s => s.trim()).filter(Boolean);
|
|
161
170
|
const bad = targets.filter(t => !AIS.includes(t));
|
|
162
171
|
if (bad.length) die(`unknown AI: ${bad.join(', ')} (known: ${AIS.join(', ')})`);
|
|
@@ -167,7 +176,9 @@ async function main() {
|
|
|
167
176
|
let answers = null, answersSource = '';
|
|
168
177
|
const answersFile = arg('--answers', null);
|
|
169
178
|
if (answersFile && arg('--defaults', false)) die('--answers and --defaults are exclusive');
|
|
179
|
+
if (arg('--quick', false) && arg('--full', false)) die('--quick and --full are exclusive; the short interview is the default');
|
|
170
180
|
if (arg('--quick', false) && (answersFile || arg('--defaults', false) || !interactive)) die('--quick is the short interview; it needs a terminal and no --answers, --defaults or --yes');
|
|
181
|
+
if (arg('--full', false) && (answersFile || arg('--defaults', false) || !interactive)) die('--full is the long interview; it needs a terminal and no --answers, --defaults or --yes');
|
|
171
182
|
if (answersFile) {
|
|
172
183
|
let raw;
|
|
173
184
|
const label = answersFile === '-' ? 'stdin' : answersFile;
|
|
@@ -179,17 +190,20 @@ async function main() {
|
|
|
179
190
|
if (!arg('--defaults', false) && !process.stdin.isTTY) console.error('agent-personalizer: stdin is not a terminal, so the interview cannot run; using the default answers (pass --answers <file.json>, --answers -, or --defaults to silence this)');
|
|
180
191
|
answersSource = process.stdin.isTTY ? 'defaults (pass --answers <file.json>, or run without --yes, to answer the interview)' : 'defaults (stdin is not a terminal; pass --answers <file.json> or --answers - to script them)';
|
|
181
192
|
} else {
|
|
182
|
-
const
|
|
183
|
-
console.log(
|
|
193
|
+
const full = !!arg('--full', false);
|
|
194
|
+
console.log('\nOnboarding: how should an AI work with you? Enter accepts the default in brackets.');
|
|
195
|
+
console.log(full
|
|
196
|
+
? `Full interview: up to ${onboarding.QUESTIONS.length} questions, some of which apply only to certain notes tools.\n`
|
|
197
|
+
: `Short interview: the ${onboarding.QUICK.length} questions that change behaviour, plus any the notes tool you pick makes apply. Every other answer takes its default; --full asks all ${onboarding.QUESTIONS.length}.\n`);
|
|
184
198
|
const raw = {};
|
|
185
199
|
for (const q of onboarding.QUESTIONS) {
|
|
186
|
-
if (
|
|
200
|
+
if (!onboarding.asks(q, raw, full)) continue;
|
|
187
201
|
if (q.options) for (const [v, l] of q.options) console.log(` ${v.padEnd(30)} ${l}`);
|
|
188
202
|
const dflt = Array.isArray(q.default) ? q.default.join(', ') : q.default;
|
|
189
203
|
raw[q.id] = onboarding.parseAnswer(q, await ask(q.ask, dflt || ''));
|
|
190
204
|
}
|
|
191
205
|
try { answers = onboarding.validate(raw); } catch (e) { die(`onboarding: ${e.message}`); }
|
|
192
|
-
answersSource =
|
|
206
|
+
answersSource = full ? 'your interview answers' : 'your short-interview answers (the rest are defaults)';
|
|
193
207
|
}
|
|
194
208
|
|
|
195
209
|
// The folder you name is followed once (realpath of its deepest EXISTING ancestor); the
|
|
@@ -235,13 +249,32 @@ async function main() {
|
|
|
235
249
|
// signature=no: the signature rule file is not installed (a `requires:` rule that is absent cannot drift back in),
|
|
236
250
|
// and every copied markdown loses its `Last edited by:` template line and its pointer to the rule.
|
|
237
251
|
const noSig = answers.signature === 'no';
|
|
238
|
-
const stripSig = (t) => noSig ? t.split('\n').filter(l => !l.includes('40-sign-every-edit.md') &&
|
|
252
|
+
const stripSig = (t) => noSig ? t.split('\n').filter(l => !l.includes('40-sign-every-edit.md') && !/^`?Last edited by:/.test(l)).join('\n') : t;
|
|
239
253
|
const mdCopy = (rel, src) => plan.push({ rel, text: stripSig(fs.readFileSync(src, 'utf8')) });
|
|
240
254
|
// rules/ is copied at level 3, where it becomes yours to edit; levels 1 and 2 render from the package's rules
|
|
241
255
|
if (level >= 3) for (const f of fs.readdirSync(path.join(PKG, 'rules')).sort()) {
|
|
242
256
|
if (noSig && f === '40-sign-every-edit.md') continue;
|
|
243
257
|
mdCopy(`rules/${f}`, path.join(PKG, 'rules', f));
|
|
244
258
|
}
|
|
259
|
+
// The home templates carry four `notes/...` pointer lines. They collapse to ONE line whenever the
|
|
260
|
+
// folder they name will not be there to read: a cloud notes tool has no local folder at all, and no
|
|
261
|
+
// level below 2 creates one, so a level-1 install used to hand the first session four broken
|
|
262
|
+
// pointers. NOTES_ONE_LINE is also what the level-2 upgrade looks for, byte for byte.
|
|
263
|
+
const NOTES_ONE_LINE = (why) => `- Notes: see \`AGENT_ONBOARDING.md\` § Where you may write (${why})`;
|
|
264
|
+
const NOTES_LATER = `no local notes folder at level 1; level 2 creates \`${base}/\``;
|
|
265
|
+
// Is the folder every notes pointer names going to be there to read? The README is the file the AI
|
|
266
|
+
// is told to read before it writes, and the level-2 scaffold creates it with the folder. The LEVEL
|
|
267
|
+
// alone is a proxy that is wrong in both directions: a level-1 install can land beside a notes
|
|
268
|
+
// folder that already exists, and a re-run at a lower level does not delete what a higher one made
|
|
269
|
+
// (round 1, findings 4 and 5). One boolean drives the home-file collapse and both rendered files,
|
|
270
|
+
// so they can never disagree about the same folder.
|
|
271
|
+
const scaffoldExists = (() => { try { return fs.statSync(path.join(root, base, 'README.md')).isFile(); } catch (_) { return false; } })();
|
|
272
|
+
const willScaffold = level >= 2 && kind !== 'cloud'; // this run's own scaffold, written further down
|
|
273
|
+
const notesScaffolded = kind !== 'cloud' && (scaffoldExists || willScaffold);
|
|
274
|
+
const notesWhy = kind === 'cloud' ? 'reached through its connector, no local files'
|
|
275
|
+
: !notesScaffolded ? NOTES_LATER
|
|
276
|
+
: kind !== 'disk' ? 'local fallback folder `notes/`'
|
|
277
|
+
: null; // disk, scaffold present: the four paths, retargeted at notes_path
|
|
245
278
|
const home = (name) => {
|
|
246
279
|
let t = fs.readFileSync(path.join(PKG, 'templates', name), 'utf8');
|
|
247
280
|
if (level < 3) {
|
|
@@ -249,18 +282,16 @@ async function main() {
|
|
|
249
282
|
t = t.split('\n').filter(l => !/Rules, one file each, the owning copy/.test(l)).join('\n');
|
|
250
283
|
t = t.replace(/`\[owner: rules\/[^\]]+\]`/g, '`[owner: the rendered block below]`');
|
|
251
284
|
}
|
|
252
|
-
if (
|
|
253
|
-
else {
|
|
254
|
-
// cloud, read-only and unknown tools: one line pointing at the onboarding file instead of four local paths
|
|
255
|
-
const tool = onboarding.kindOf(answers) === 'cloud' ? 'reached through its connector, no local files' : 'local fallback folder `notes/`';
|
|
285
|
+
if (notesWhy) {
|
|
256
286
|
let done = false;
|
|
257
287
|
t = t.split('\n').filter(l => { if (!/`notes\//.test(l)) return true; if (done) return false; done = true; return true; })
|
|
258
|
-
.map(l => /`notes\//.test(l) ?
|
|
259
|
-
}
|
|
288
|
+
.map(l => /`notes\//.test(l) ? NOTES_ONE_LINE(notesWhy) : l).join('\n');
|
|
289
|
+
} else if (base !== 'notes') t = t.replace(/\bnotes\//g, `${base}/`);
|
|
260
290
|
return stripSig(t);
|
|
261
291
|
};
|
|
262
|
-
|
|
263
|
-
if (targets.includes('
|
|
292
|
+
const POINTER = 'pointer file; the renderer fills its block below';
|
|
293
|
+
if (targets.includes('claude')) plan.push({ rel: 'CLAUDE.md', text: home('CLAUDE.md'), note: POINTER });
|
|
294
|
+
if (targets.includes('agents')) plan.push({ rel: 'AGENTS.md', text: home('AGENTS.md'), note: POINTER });
|
|
264
295
|
if (level >= 2 && kind !== 'cloud') { // a cloud tool's notes are not local files; no folder named after a workspace
|
|
265
296
|
mdCopy(`${base}/README.md`, path.join(PKG, 'templates', 'FOLDER_README.md'));
|
|
266
297
|
mdCopy(`${base}/sessions/TEMPLATE-week.md`, path.join(PKG, 'templates', 'session-log.md'));
|
|
@@ -301,53 +332,81 @@ async function main() {
|
|
|
301
332
|
// changed answer that the kept file still carries the old value of is named as a conflict.
|
|
302
333
|
const user = probe(root, 'USER.md');
|
|
303
334
|
let userAction = 'create';
|
|
335
|
+
let staleNotesInUser = false;
|
|
304
336
|
const changedKeys = prevAnswers ? Object.keys(answers).filter(k => JSON.stringify(answers[k]) !== JSON.stringify(prevAnswers[k])) : [];
|
|
305
337
|
if (user.exists) {
|
|
306
338
|
if (!fs.lstatSync(user.full).isFile()) die('USER.md exists and is not a regular file');
|
|
339
|
+
const current = fs.readFileSync(user.full, 'utf8');
|
|
340
|
+
// Two candidate renders per answer set, one saying the notes folder is there and one saying it is
|
|
341
|
+
// not (#25). A match against EITHER means the file is still exactly what this installer wrote,
|
|
342
|
+
// so regenerating loses nothing; anything else is yours and is kept.
|
|
343
|
+
const untouched = (ans) => [true, false].some(ns => current === onboarding.renderUser(ans, { notesScaffolded: ns }));
|
|
307
344
|
if (changedKeys.length) {
|
|
308
|
-
|
|
309
|
-
|
|
345
|
+
userAction = untouched(prevAnswers) ? 'regenerate' : 'conflict';
|
|
346
|
+
} else if (notesScaffolded && current === onboarding.renderUser(answers, { notesScaffolded: false })) {
|
|
347
|
+
// Same answers, but the file says the folder is absent and it is not (this run created it, or
|
|
348
|
+
// it was already there). The real paths go back, and only on a byte-for-byte match.
|
|
349
|
+
userAction = 'relevel';
|
|
310
350
|
} else userAction = 'keep';
|
|
351
|
+
// A kept file that does not name the folder README while the folder is there is stale, however it
|
|
352
|
+
// was worded: keying the notice on one sentence let an edit to that sentence silence it (finding 6).
|
|
353
|
+
if (userAction === 'keep' && notesScaffolded && !current.includes(`\`${base}/README.md\``)) staleNotesInUser = true;
|
|
311
354
|
}
|
|
312
355
|
|
|
313
|
-
// Upgrade from
|
|
314
|
-
//
|
|
315
|
-
//
|
|
356
|
+
// Upgrade from a lower level. Two repairs, each matched byte for byte against a line THIS installer
|
|
357
|
+
// wrote, so anything the user edited is left alone:
|
|
358
|
+
// level 3: the pointer lines said "the rendered block below"; now that rules/ arrives they name it.
|
|
359
|
+
// level 2: the one-line notes placeholder a level-1 install wrote becomes the real pointers, now
|
|
360
|
+
// that the folder behind them exists.
|
|
316
361
|
const upgrades = [];
|
|
317
|
-
if (level >=
|
|
362
|
+
if (level >= 2) for (const name of ['CLAUDE.md', 'AGENTS.md']) {
|
|
318
363
|
if (!(name === 'CLAUDE.md' ? targets.includes('claude') : targets.includes('agents'))) continue;
|
|
319
364
|
const { full, exists } = probe(root, name);
|
|
320
365
|
if (!exists || !fs.lstatSync(full).isFile()) continue;
|
|
321
366
|
const tmpl = stripSig(fs.readFileSync(path.join(PKG, 'templates', name), 'utf8')).split('\n');
|
|
322
|
-
const
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
367
|
+
const lines = fs.readFileSync(full, 'utf8').split('\n');
|
|
368
|
+
const why = [];
|
|
369
|
+
if (level >= 3) {
|
|
370
|
+
let repointed = false;
|
|
371
|
+
for (const t of tmpl) {
|
|
372
|
+
if (!/`\[owner: rules\/[^\]]+\]`/.test(t)) continue;
|
|
373
|
+
const placeholder = t.replace(/`\[owner: rules\/[^\]]+\]`/g, '`[owner: the rendered block below]`');
|
|
374
|
+
for (let i = 0; i < lines.length; i++) if (lines[i] === placeholder) { lines[i] = t; repointed = true; }
|
|
375
|
+
}
|
|
376
|
+
const rulesLine = tmpl.find(l => /Rules, one file each, the owning copy/.test(l));
|
|
377
|
+
const anchorIdx = lines.findIndex(l => /AGENT_ONBOARDING\.md`$/.test(l) && /^- /.test(l));
|
|
378
|
+
if (rulesLine && !lines.includes(rulesLine) && anchorIdx !== -1 && repointed) lines.splice(anchorIdx + 1, 0, rulesLine);
|
|
379
|
+
if (repointed) why.push('rule pointers now name rules/, which this level installs');
|
|
380
|
+
}
|
|
381
|
+
if (!notesWhy) { // this run creates the folder the four lines name
|
|
382
|
+
const idx = lines.indexOf(NOTES_ONE_LINE(NOTES_LATER));
|
|
383
|
+
if (idx !== -1) {
|
|
384
|
+
lines.splice(idx, 1, ...tmpl.filter(l => /`notes\//.test(l)).map(l => base === 'notes' ? l : l.replace(/\bnotes\//g, `${base}/`)));
|
|
385
|
+
why.push(`notes pointers now name ${base}/, which this level installs`);
|
|
386
|
+
}
|
|
329
387
|
}
|
|
330
|
-
|
|
331
|
-
const anchorIdx = lines.findIndex(l => /AGENT_ONBOARDING\.md`$/.test(l) && /^- /.test(l));
|
|
332
|
-
if (rulesLine && !lines.includes(rulesLine) && anchorIdx !== -1 && changed) { lines.splice(anchorIdx + 1, 0, rulesLine); }
|
|
333
|
-
if (changed) { try { fs.accessSync(full, fs.constants.W_OK); } catch (_) { die(`${name} is not writable; nothing was written`); } upgrades.push({ name, full, text: lines.join('\n') }); }
|
|
388
|
+
if (why.length) { try { fs.accessSync(full, fs.constants.W_OK); } catch (_) { die(`${name} is not writable; nothing was written`); } upgrades.push({ name, full, text: lines.join('\n'), why }); }
|
|
334
389
|
}
|
|
335
390
|
|
|
336
391
|
// ---- WRITE ----
|
|
337
|
-
for (const u of upgrades) { fs.writeFileSync(u.full, u.text); console.log(`update ${u.name} (
|
|
338
|
-
if (userAction === 'create') { fs.writeFileSync(user.full, onboarding.renderUser(answers), { flag: 'wx' }); console.log('wrote USER.md (from your answers)'); }
|
|
339
|
-
else if (userAction === 'regenerate') { fs.writeFileSync(user.full, onboarding.renderUser(answers)); console.log(`update USER.md (regenerated: it matched your previous answers byte for byte; changed: ${changedKeys.join(', ')})`); }
|
|
392
|
+
for (const u of upgrades) { fs.writeFileSync(u.full, u.text); console.log(`update ${u.name} (${u.why.join('; ')})`); }
|
|
393
|
+
if (userAction === 'create') { fs.writeFileSync(user.full, onboarding.renderUser(answers, { notesScaffolded }), { flag: 'wx' }); console.log('wrote USER.md (from your answers)'); }
|
|
394
|
+
else if (userAction === 'regenerate') { fs.writeFileSync(user.full, onboarding.renderUser(answers, { notesScaffolded })); console.log(`update USER.md (regenerated: it matched your previous answers byte for byte; changed: ${changedKeys.join(', ')})`); }
|
|
395
|
+
else if (userAction === 'relevel') { fs.writeFileSync(user.full, onboarding.renderUser(answers, { notesScaffolded })); console.log(`update USER.md (notes pointers now name ${base}/, which is there; it matched the render that said it was not, byte for byte)`); }
|
|
340
396
|
else if (userAction === 'conflict') {
|
|
341
397
|
console.log(`kept USER.md (you edited it, so it was not regenerated)`);
|
|
342
398
|
console.log(` ANSWERS CHANGED: ${changedKeys.join(', ')}. USER.md still carries the old value(s) and the rendered profile sections come from USER.md.`);
|
|
343
399
|
console.log(` Fix by hand, or delete USER.md and re-run to regenerate it from the new answers. AGENT_ONBOARDING.md already carries the new answers.`);
|
|
344
|
-
} else
|
|
400
|
+
} else {
|
|
401
|
+
console.log('kept USER.md (exists)');
|
|
402
|
+
if (staleNotesInUser) console.log(` NOTE: you edited USER.md while it still said there is no local notes folder. ${base}/ exists now. Fix the two "Where things live" lines by hand, or delete USER.md and re-run.`);
|
|
403
|
+
}
|
|
345
404
|
for (const p of plan) {
|
|
346
405
|
if (p.src) copyIfAbsent(p.src, root, p.rel);
|
|
347
406
|
else {
|
|
348
407
|
const { full, exists } = safeDest(root, p.rel);
|
|
349
408
|
if (exists) console.log(`kept ${p.rel} (exists)`);
|
|
350
|
-
else { fs.writeFileSync(full, p.text, { flag: 'wx' }); console.log(`wrote ${p.rel}`); }
|
|
409
|
+
else { fs.writeFileSync(full, p.text, { flag: 'wx' }); console.log(`wrote ${p.rel}${p.note ? ` (${p.note})` : ''}`); }
|
|
351
410
|
}
|
|
352
411
|
}
|
|
353
412
|
if (level >= 3) {
|
|
@@ -366,15 +425,35 @@ async function main() {
|
|
|
366
425
|
const DOCS = onboarding.DOCS;
|
|
367
426
|
// the rerun command a user can actually type: the npx form when this ran from npm's cache, else the local path that just worked
|
|
368
427
|
const SELF = /[\\/]_npx[\\/]|[\\/]node_modules[\\/]/.test(PKG) ? 'npx agent-personalizer' : `node ${path.relative(process.cwd(), path.join(PKG, 'bin', 'agent-personalizer.js')) || 'bin/agent-personalizer.js'}`;
|
|
428
|
+
// The rerun command names the folder that was just installed, in full. "--dir ." was a command that
|
|
429
|
+
// wrote into whatever directory it was pasted from, which is not where the install went.
|
|
430
|
+
const shq = (x) => /^[A-Za-z0-9._\/@:+,=-]+$/.test(x) ? x : `'${String(x).replace(/'/g, "'\\''")}'`;
|
|
431
|
+
const DIR = shq(root);
|
|
432
|
+
// Which of the files just written an AI picks up on its own, and which a human still has to paste.
|
|
433
|
+
// Claude Code reads CLAUDE.md from the folder; claude.ai reads no files at all, and the success
|
|
434
|
+
// text used to say nothing about that.
|
|
435
|
+
const AUTO = { claude: 'CLAUDE.md (Claude Code)', agents: 'AGENTS.md (Codex, Cursor, anything that reads AGENTS.md)', gemini: 'GEMINI.md (Gemini CLI)' };
|
|
436
|
+
const PASTE = {
|
|
437
|
+
claude: 'claude.ai and the Claude apps read no files: paste the body of USER.md, then AGENT_ONBOARDING.md, into the project or profile instructions',
|
|
438
|
+
chatgpt: 'ChatGPT: paste chatgpt-box1.txt and chatgpt-box2.txt into its two custom-instruction boxes',
|
|
439
|
+
prompt: 'system-prompt.md: paste it wherever you set a system prompt',
|
|
440
|
+
};
|
|
441
|
+
const auto = targets.filter(t => AUTO[t]).map(t => AUTO[t]);
|
|
442
|
+
const paste = targets.filter(t => PASTE[t]).map(t => PASTE[t]);
|
|
443
|
+
const steps = [];
|
|
444
|
+
steps.push('Read AGENT_ONBOARDING.md once: that is what every AI will be told about working with you. Re-run this installer with new answers to change it.\n USER.md is yours to edit freely; the onboarding file is regenerated from .agent-personalizer.json.');
|
|
445
|
+
steps.push(level >= 3
|
|
446
|
+
? `Re-render after editing: node render/render.cjs --dir ${DIR} (drift check: add --check)`
|
|
447
|
+
: `Re-render after editing by running this installer again (it keeps your files and only refreshes the rendered blocks):\n ${SELF} --dir ${DIR} --ai ${targets.join(',')} --level ${level} --yes`);
|
|
448
|
+
steps.push([
|
|
449
|
+
auto.length ? `Read from ${root} automatically, nothing to paste: ${auto.join(', ')}.` : null,
|
|
450
|
+
paste.length ? `Still needs a paste: ${paste.join('; ')}.` : null,
|
|
451
|
+
`Which file each AI reads, and what to re-paste after you change an answer: ${DOCS}/paste-guide.md`,
|
|
452
|
+
].filter(Boolean).join('\n '));
|
|
453
|
+
if (level >= 2 && kind !== 'cloud') steps.push(`Read ${base}/README.md before letting an AI write into ${base}/.`);
|
|
454
|
+
if (level >= 3) steps.push('Register hooks/claude-code/session-start.sh (see hooks/README.md) and copy check/forbidden.example.txt to check/forbidden.local.txt.');
|
|
369
455
|
console.log('\nNext:');
|
|
370
|
-
console.log(
|
|
371
|
-
console.log(' USER.md is yours to edit freely; the onboarding file is regenerated from .agent-personalizer.json.');
|
|
372
|
-
console.log(level >= 3
|
|
373
|
-
? ' 2. Re-render after editing: node render/render.cjs --dir . (drift check: add --check)'
|
|
374
|
-
: ` 2. Re-render after editing by running this installer again (it keeps your files and only refreshes the rendered blocks):\n ${SELF} --dir . --ai ${targets.join(',')} --level ${level} --yes`);
|
|
375
|
-
if (level >= 2 && kind !== 'cloud') console.log(` 3. Read ${base}/README.md before letting an AI write into ${base}/.`);
|
|
376
|
-
if (level >= 3) console.log(' 4. Register hooks/claude-code/session-start.sh (see hooks/README.md) and copy check/forbidden.example.txt to check/forbidden.local.txt.');
|
|
377
|
-
if (level >= 4) console.log(' 5. Level 4 is pointers only for now: routing, task bundles and verified CLI runs live in the multi-agent layer, linked from the README when it ships.');
|
|
456
|
+
steps.forEach((step, i) => console.log(` ${i + 1}. ${step}`));
|
|
378
457
|
if (answers.notes_tool === 'obsidian') console.log(answers.obsidian_tc === 'yes'
|
|
379
458
|
? `\nCompanion: the onboarding file routes the AI through obsidian-tc; configure its folder ACLs from your off-limits answer and its human-in-the-loop list from your always-ask answer. See ${DOCS}/companions.md`
|
|
380
459
|
: `\nCompanion: your notes are an Obsidian vault and the AI will work on the folder directly. obsidian-tc would give it governed access (folder ACLs, human-in-the-loop, audit log): \`npx obsidian-tc /path/to/vault\`, then re-run this installer and answer yes. See ${DOCS}/companions.md`);
|
|
@@ -382,7 +461,7 @@ async function main() {
|
|
|
382
461
|
else if (answers.notes_tool === 'apple-notes') console.log(`\nCompanion: Apple Notes needs a separately installed local Apple Notes MCP; no AI app ships one built in. Until you connect one, the onboarding file already limits the AI to reading and creating new notes. See ${DOCS}/companions.md`);
|
|
383
462
|
else if (answers.notes_tool === 'other') console.log(`\nNote: "${answers.notes_tool_name || 'your notes tool'}" is unknown to this kit; the onboarding file tells the AI to ask before its first write there and to use the local fallback folder notes/ meanwhile.`);
|
|
384
463
|
else if (['onenote', 'evernote'].includes(answers.notes_tool)) console.log(`\nNote: ${answers.notes_tool} has no first-class agent door today; the onboarding file treats it as read-only. See ${DOCS}/companions.md`);
|
|
385
|
-
console.log(
|
|
464
|
+
if (targets.length > 1) console.log(`\nSeveral agents? Read ${DOCS}/companions.md on the Context Layer: purpose-bound bundles and receipts for every delegation.`);
|
|
386
465
|
console.log('\nNothing here read an environment variable or wrote a secret.');
|
|
387
466
|
console.log('\nIf this saved you time, a star helps people find it: https://github.com/aunysillyme/agent-personalizer');
|
|
388
467
|
}
|
package/docs/companions.md
CHANGED
|
@@ -43,7 +43,7 @@ Lexical search and every note tool work immediately; semantic and graph retrieva
|
|
|
43
43
|
- **Write policy** "logs and inbox only" or "ask before every write" is the Layer's rule that memory writes remain proposals until approved.
|
|
44
44
|
- **Off limits** is the Layer's vault stage: originals that never enter a bundle.
|
|
45
45
|
- **Always ask before** is the Layer's decide stage: allow, reduce, approve or deny by action and recipient.
|
|
46
|
-
|
|
46
|
+
Running several agents is where it earns its keep (the hand-off layer, which this repo does not install): each delegation carries a purpose-bound bundle and returns a receipt, so you can answer "who saw what, and why" after the fact. The repo's `AGENT_ONBOARDING.md` is the human-readable policy; the Context Layer is how you make a machine enforce and record it.
|
|
47
47
|
|
|
48
48
|
---
|
|
49
49
|
|
|
@@ -15,7 +15,7 @@ _Generated by agent-personalizer from Mara's own answers (stored in `.agent-pers
|
|
|
15
15
|
- **Directness:** direct answers, no hedging, say what you think.
|
|
16
16
|
- **Length:** short by default, detail on request.
|
|
17
17
|
- **When you are wrong:** state the correction in one line and move on.
|
|
18
|
-
- **When you are unsure:** settle facts
|
|
18
|
+
- **When you are unsure:** settle facts yourself; ask only when the answer changes what gets built.
|
|
19
19
|
- **Never:** em dashes; start a reply with Great question; client names outside their folder.
|
|
20
20
|
|
|
21
21
|
### Output shape
|
|
@@ -37,7 +37,7 @@ _Generated by agent-personalizer from Mara's own answers (stored in `.agent-pers
|
|
|
37
37
|
|
|
38
38
|
### Where you may write
|
|
39
39
|
|
|
40
|
-
- **Notes live in Obsidian:** reach them as the vault at `notes/`, through **obsidian-tc** (governed MCP: folder ACLs, human-in-the-loop confirmation for destructive tools, audit log) rather than raw filesystem access; see https://github.com/aunysillyme/agent-personalizer/blob/v0.
|
|
40
|
+
- **Notes live in Obsidian:** reach them as the vault at `notes/`, through **obsidian-tc** (governed MCP: folder ACLs, human-in-the-loop confirmation for destructive tools, audit log) rather than raw filesystem access; see https://github.com/aunysillyme/agent-personalizer/blob/v0.5.1/docs/companions.md.
|
|
41
41
|
- You may create and edit files anywhere under `notes/`, under that folder's rules. Nowhere else without being asked.
|
|
42
42
|
- **Every folder you write into has a README.** Any write, edit or delete means that README is corrected in the same pass: the file's one-line description, the folder's status, settled decisions, next steps. A stale index is worse than none, because the next agent believes it.
|
|
43
43
|
- **Session log:** append a dated section to this week's note in `notes/sessions/`. **Decisions:** one line each in `notes/decisions.md`. **Inbox:** one file per item in `notes/inbox/`; finished items are deleted, not marked done.
|
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.
|
|
3
|
+
Tier 3 from the tiers doc (https://github.com/aunysillyme/agent-personalizer/blob/v0.5.1/docs/tiers.md): the few rules that must be in context at the moment of decision, injected in full at the start of every session. Injection puts the text in front of the model; whether the model follows it is up to the model and the host. This is the strongest placement available, not a guarantee.
|
|
4
4
|
|
|
5
5
|
Which rules? The ones with `inject: true` in their frontmatter. Keep that set small. Every injected rule costs tokens every session.
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-personalizer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Personalize any AI with dynamic instructions. One profile, one rule source, rendered for Claude, Codex, Cursor, Gemini and ChatGPT.",
|
|
5
5
|
"author": "aunysillyme (https://github.com/aunysillyme)",
|
|
6
6
|
"license": "MIT",
|
package/render/onboarding.cjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
DOCS points at the matching tag on GitHub so an installed copy never links to a file the
|
|
18
18
|
destination does not have.
|
|
19
19
|
*/
|
|
20
|
-
const VERSION = '0.
|
|
20
|
+
const VERSION = '0.5.1';
|
|
21
21
|
const DOCS = `https://github.com/aunysillyme/agent-personalizer/blob/v${VERSION}/docs`;
|
|
22
22
|
|
|
23
23
|
/* THE single source for notes tools. Add a tool here and nowhere else: the interview option, the
|
|
@@ -47,6 +47,29 @@ const kindOf = (a) => TOOL[a.notes_tool].kind;
|
|
|
47
47
|
/* the folder on disk that scaffolds and home-file pointers use: the user's path for a disk tool,
|
|
48
48
|
the fixed fallback for everything else (cloud tools get no folder named after a workspace) */
|
|
49
49
|
const baseFor = (a) => kindOf(a) === 'disk' ? a.notes_path : FALLBACK;
|
|
50
|
+
/* Is the local notes folder the rendered instructions name NOT there? Every non-cloud tool gets one
|
|
51
|
+
(a disk tool's own path, a read-only or unknown tool's fallback) and the level-2 scaffold is what
|
|
52
|
+
creates it, so below level 2 nothing may name a path inside it: the first session would be told to
|
|
53
|
+
read and write into a folder the installer never created. #19 fixed that for the home files, which
|
|
54
|
+
the installer collapses to one line; #25 was the same bug in the two files rendered from here,
|
|
55
|
+
which that one line points AT.
|
|
56
|
+
|
|
57
|
+
The LEVEL is only a proxy, and it is wrong in both directions: a hand-written config carries no
|
|
58
|
+
level, a level-1 install can land in a folder that already has a notes folder, and a re-run at a
|
|
59
|
+
lower level does not remove the folder a higher one created. So `opts.notesScaffolded` (the
|
|
60
|
+
caller's own look at the disk, which is the ground truth) wins whenever the caller passes it, and
|
|
61
|
+
the level is the fallback for a caller that has no root to look in. Round 1, findings 3 to 5.
|
|
62
|
+
|
|
63
|
+
This file is copied into level-3 installs, so the look at the disk stays in the CALLER: these two
|
|
64
|
+
renders are pure functions of the answers plus this one boolean. */
|
|
65
|
+
function notesPending(a, opts) {
|
|
66
|
+
if (kindOf(a) === 'cloud') return false; // no local folder at any level
|
|
67
|
+
if (opts && typeof opts.notesScaffolded === 'boolean') return !opts.notesScaffolded;
|
|
68
|
+
return (opts && Number.isInteger(opts.level) ? opts.level : 2) < 2;
|
|
69
|
+
}
|
|
70
|
+
/* the phrase a pending USER.md carries where the folder rules would be */
|
|
71
|
+
const NOTES_PENDING_MARK = 'no local notes folder yet, so no folder rules yet';
|
|
72
|
+
const notesLater = (base) => `\`--level 2\` creates \`${base}/\``;
|
|
50
73
|
|
|
51
74
|
const QUESTIONS = [
|
|
52
75
|
{ id: 'name', ask: 'What should the AI call you?', type: 'text', default: 'the user' },
|
|
@@ -60,7 +83,7 @@ const QUESTIONS = [
|
|
|
60
83
|
{ id: 'mistakes', ask: 'When the AI is wrong, how should it handle it?', type: 'choice', default: 'one-line',
|
|
61
84
|
options: [['one-line', 'state the correction in one line and move on'], ['brief', 'correction plus one line on the cause'], ['full', 'correction plus the full cause']] },
|
|
62
85
|
{ id: 'unsure', ask: 'When the AI is unsure, what should it do?', type: 'choice', default: 'ask-when-it-changes-the-build',
|
|
63
|
-
options: [['ask-when-it-changes-the-build', 'settle facts itself; ask only when the answer changes what gets built'], ['ask-first', 'ask before doing anything uncertain'], ['assume-and-say', 'proceed on a stated assumption, never ask']] },
|
|
86
|
+
options: [['ask-when-it-changes-the-build', 'settle facts itself; ask only when the answer changes what gets built', 'settle facts yourself; ask only when the answer changes what gets built'], ['ask-first', 'ask before doing anything uncertain'], ['assume-and-say', 'proceed on a stated assumption, never ask']] },
|
|
64
87
|
{ id: 'lead_with', ask: 'What should a reply open with?', type: 'choice', default: 'verdict',
|
|
65
88
|
options: [['verdict', 'the answer or the verdict'], ['summary', 'a one-paragraph summary'], ['context', 'the context, then the answer']] },
|
|
66
89
|
{ id: 'structure', ask: 'How should replies be shaped?', type: 'choice', default: 'bullets',
|
|
@@ -71,9 +94,9 @@ const QUESTIONS = [
|
|
|
71
94
|
{ id: 'read_first', ask: 'Files the AI reads first, in order (comma-separated)', type: 'list', default: ['USER.md', 'AGENT_ONBOARDING.md'] },
|
|
72
95
|
{ id: 'notes_tool', ask: 'Where do your notes live?', type: 'choice', default: 'folder',
|
|
73
96
|
options: Object.entries(TOOL).map(([k, t]) => [k, t.label]) },
|
|
74
|
-
{ id: 'obsidian_tc', ask: '
|
|
97
|
+
{ id: 'obsidian_tc', ask: 'Do you use obsidian-tc, the governed MCP?', type: 'choice', default: 'no', when: (a) => a.notes_tool === 'obsidian',
|
|
75
98
|
options: [['no', 'not installed; the AI works on the vault folder directly'], ['yes', 'installed and connected; the AI reaches the vault through it']] },
|
|
76
|
-
{ id: 'notes_tool_name', ask: '
|
|
99
|
+
{ id: 'notes_tool_name', ask: 'The name of that tool', type: 'text', default: '', when: (a) => a.notes_tool === 'other' },
|
|
77
100
|
{ id: 'notes_path', ask: 'Where inside it: the folder path (Obsidian, Logseq, plain folder), or the workspace / notebook / folder name (Notion, Google Docs, Apple Notes, others)', type: 'text', default: 'notes' },
|
|
78
101
|
{ id: 'tracker', ask: 'Your task tracker, if the AI should read it ("none" to skip)', type: 'text', default: 'none' },
|
|
79
102
|
{ id: 'write_policy', ask: 'How freely may the AI write into your notes?', type: 'choice', default: 'notes-freely',
|
|
@@ -89,8 +112,18 @@ const QUESTIONS = [
|
|
|
89
112
|
];
|
|
90
113
|
|
|
91
114
|
const IDS = new Set(QUESTIONS.map(q => q.id));
|
|
92
|
-
/* the
|
|
115
|
+
/* the short interview, which is what a bare `npx agent-personalizer` runs; every other answer takes
|
|
116
|
+
its default. --full asks the rest as well. */
|
|
93
117
|
const QUICK = ['name', 'tone', 'length', 'notes_tool', 'notes_path', 'write_policy', 'always_ask'];
|
|
118
|
+
/* Does this interview ask question q, given the answers so far? A question with a `when` is
|
|
119
|
+
CONDITIONAL: it is asked exactly when its condition holds, short interview or long, so nobody
|
|
120
|
+
answers the Obsidian question about Notion and nobody picks "other" without being asked to name
|
|
121
|
+
it. Every other question is asked in the long interview and only in the short set otherwise.
|
|
122
|
+
The installer's interview loop calls this, so a test of it is a test of the installer. */
|
|
123
|
+
function asks(q, answersSoFar, full) {
|
|
124
|
+
if (q.when) return !!q.when(answersSoFar || {});
|
|
125
|
+
return !!full || QUICK.includes(q.id);
|
|
126
|
+
}
|
|
94
127
|
/* only the answers that differ from the defaults: what the installer stores, so the config reads as
|
|
95
128
|
"what this person chose" and a future default applies to everyone who never chose otherwise */
|
|
96
129
|
/* PINNED answers are always stored, default or not: they govern what the AI may touch, so a future
|
|
@@ -151,6 +184,11 @@ function parseAnswer(q, raw) {
|
|
|
151
184
|
}
|
|
152
185
|
|
|
153
186
|
const label = (q, v) => { const o = q.options && q.options.find(x => x[0] === v); return o ? o[1] : v; };
|
|
187
|
+
/* The interview asks the HUMAN about the AI, so an option's label is third person ("settle facts
|
|
188
|
+
itself"). USER.md, AGENT_ONBOARDING.md and the session-start contract all address the AI
|
|
189
|
+
directly, so they take the option's third element, its second-person phrasing, where a choice
|
|
190
|
+
carries one. Without it the AI reads "when you are unsure: settle facts itself". */
|
|
191
|
+
const youLabel = (q, v) => { const o = q.options && q.options.find(x => x[0] === v); return o ? (o[2] || o[1]) : v; };
|
|
154
192
|
const Q = Object.fromEntries(QUESTIONS.map(q => [q.id, q]));
|
|
155
193
|
const bullets = (arr, empty) => arr.length ? arr.map(x => `- ${x}`).join('\n') : `- ${empty}`;
|
|
156
194
|
/* md(): for values placed INSIDE an inline-code span; a code span cannot carry structure, so only
|
|
@@ -163,7 +201,8 @@ const esc = (s) => String(s).replace(/`/g, "'");
|
|
|
163
201
|
character as the character itself. */
|
|
164
202
|
const md = (s) => String(s).replace(/[`~<>#*_\[\]|\\]/g, (c) => '\\' + c).replace(/^([-+]|\d+[.)])(?=\s|$)/, (m) => '\\' + m);
|
|
165
203
|
|
|
166
|
-
function renderUser(a) {
|
|
204
|
+
function renderUser(a, opts) {
|
|
205
|
+
const pending = notesPending(a, opts);
|
|
167
206
|
return `# USER.md
|
|
168
207
|
|
|
169
208
|
*Who I am, how to talk to me, how firmly I mean things, how I want output shaped. Every AI reads this first. Generated from my onboarding answers; edit freely, it is mine.*
|
|
@@ -180,7 +219,7 @@ function renderUser(a) {
|
|
|
180
219
|
- **Directness:** ${label(Q.tone, a.tone)}
|
|
181
220
|
- **Length:** ${label(Q.length, a.length)}
|
|
182
221
|
- **When you are wrong:** ${label(Q.mistakes, a.mistakes)}
|
|
183
|
-
- **When you are unsure:** ${
|
|
222
|
+
- **When you are unsure:** ${youLabel(Q.unsure, a.unsure)}
|
|
184
223
|
- **Never:** ${a.never.length ? a.never.map(md).join('; ') : 'nothing declared yet'}
|
|
185
224
|
|
|
186
225
|
## How firmly I mean things
|
|
@@ -206,9 +245,9 @@ Two guards. First: loosen only descriptive claims about me. Never loosen a state
|
|
|
206
245
|
|
|
207
246
|
## Where things live
|
|
208
247
|
|
|
209
|
-
- **My notes:** ${md(toolFor(a).name)}, ${toolFor(a).kind === 'disk' ? `\`${esc(a.notes_path)}/\`` : `"${md(a.notes_path)}"`}${toolFor(a).kind === 'readonly' ? ' (read-only for the AI)' : toolFor(a).kind === 'other' ? ' (the AI asks before its first write there)' : ''}
|
|
248
|
+
- **My notes:** ${md(toolFor(a).name)}, ${toolFor(a).kind === 'disk' ? `\`${esc(a.notes_path)}/\`` : `"${md(a.notes_path)}"`}${toolFor(a).kind === 'readonly' ? ' (read-only for the AI)' : toolFor(a).kind === 'other' ? ' (the AI asks before its first write there)' : ''}${pending && toolFor(a).kind === 'disk' ? ` (not on disk yet; ${notesLater(esc(a.notes_path))})` : ''}
|
|
210
249
|
- **My task tracker:** ${md(a.tracker)}
|
|
211
|
-
- **Rules the AI must read before writing anything to my notes:** ${toolFor(a).kind === 'disk' ? `\`${esc(a.notes_path)}/README.md\`` : toolFor(a).kind === 'cloud' ? `the index ${toolFor(a).unit || 'page'} of "${md(a.notes_path)}", and \`AGENT_ONBOARDING.md\` § Where you may write` : `\`${FALLBACK}/README.md\` (the local fallback folder the AI writes to), and \`AGENT_ONBOARDING.md\` § Where you may write`}
|
|
250
|
+
- **Rules the AI must read before writing anything to my notes:** ${pending ? `\`AGENT_ONBOARDING.md\` § Where you may write (${NOTES_PENDING_MARK}; ${notesLater(esc(baseFor(a)))} and its README)` : toolFor(a).kind === 'disk' ? `\`${esc(a.notes_path)}/README.md\`` : toolFor(a).kind === 'cloud' ? `the index ${toolFor(a).unit || 'page'} of "${md(a.notes_path)}", and \`AGENT_ONBOARDING.md\` § Where you may write` : `\`${FALLBACK}/README.md\` (the local fallback folder the AI writes to), and \`AGENT_ONBOARDING.md\` § Where you may write`}
|
|
212
251
|
`;
|
|
213
252
|
}
|
|
214
253
|
|
|
@@ -217,16 +256,38 @@ Two guards. First: loosen only descriptive claims about me. Never loosen a state
|
|
|
217
256
|
conservative posture. p = location escaped for a code span, q = location escaped for prose. */
|
|
218
257
|
|
|
219
258
|
|
|
220
|
-
function renderOnboarding(a) {
|
|
259
|
+
function renderOnboarding(a, opts) {
|
|
221
260
|
const tool = toolFor(a);
|
|
222
261
|
const disk = tool.kind === 'disk';
|
|
262
|
+
const pending = notesPending(a, opts); // the local folder is intended but level 2 has not created it
|
|
223
263
|
const base = esc(baseFor(a)); // where filesystem writes go, if any
|
|
224
264
|
const unit = tool.unit || 'page';
|
|
225
265
|
const naming = { 'kebab-case': 'kebab-case: `my-note-title.md`', 'snake_case': 'snake_case: `my_note_title.md`', 'any': 'no naming rule; match the folder you are writing into' }[a.file_naming];
|
|
226
266
|
const askList = a.always_ask.map(v => `- **${v}**: ${label(Q.always_ask, v)}`).join('\n') || '- nothing declared; use your judgement and say what you did';
|
|
227
267
|
|
|
228
268
|
let writeSection;
|
|
229
|
-
if (
|
|
269
|
+
if (pending) {
|
|
270
|
+
// Level 1 writes four files and no folders, so every path under base/ is a dead pointer until a
|
|
271
|
+
// level-2 run creates it. Two things stay true regardless: the notes TOOL and its location exist
|
|
272
|
+
// already for a read-only or unknown tool (only the local fallback folder is missing, so do not
|
|
273
|
+
// tell them their own notebook is coming at level 2), and the write policy they chose is not
|
|
274
|
+
// dropped, only deferred to "once it exists".
|
|
275
|
+
const laterLine = {
|
|
276
|
+
'notes-freely': `anywhere under \`${base}/\`, under that folder's rules, and nowhere else unasked`,
|
|
277
|
+
'logs-and-inbox-only': `only the session log (\`${base}/sessions/\`), the decisions log (\`${base}/decisions.md\`) and the inbox (\`${base}/inbox/\`)`,
|
|
278
|
+
'ask-before-every-write': 'ask before every write, every time, showing what you would write and where',
|
|
279
|
+
}[a.write_policy];
|
|
280
|
+
const whereLine = disk
|
|
281
|
+
? `- **Notes will live in ${md(tool.name)}:** ${tool.reach}, once that folder exists.`
|
|
282
|
+
: `- **Notes live in ${md(tool.name)}:** reach them as ${tool.reach}. ${tool.posture}`;
|
|
283
|
+
const absentLine = disk
|
|
284
|
+
? `- **That folder is not on disk yet, so nothing under \`${base}/\` exists to read or write.**`
|
|
285
|
+
: `- **The local fallback folder \`${base}/\` that your writes would go to does not exist yet.**`;
|
|
286
|
+
writeSection = `${whereLine}
|
|
287
|
+
${absentLine} This is a level-1 install: four profile files, no folders. ${notesLater(base)} with its README, session log, decisions log and inbox.
|
|
288
|
+
- **So do not write files there, and do not create that folder yourself.** Propose the write instead: say what would go in it and where it would live, and let them run the level-2 install (or tell you to make the folder).
|
|
289
|
+
- **Once it exists**, the policy they chose applies: you may write ${laterLine}. Every folder you write into has a README, and any write, edit or delete means that README is corrected in the same pass. A stale index is worse than none, because the next agent believes it.`;
|
|
290
|
+
} else if (disk) {
|
|
230
291
|
const writeLine = {
|
|
231
292
|
'notes-freely': `You may create and edit files anywhere under \`${base}/\`, under that folder's rules. Nowhere else without being asked.`,
|
|
232
293
|
'logs-and-inbox-only': `You may write only to the session log (\`${base}/sessions/\`), the decisions log (\`${base}/decisions.md\`) and the inbox (\`${base}/inbox/\`). Anything else: propose it, do not write it.`,
|
|
@@ -274,7 +335,7 @@ ${a.work ? `- **What they do:** ${md(a.work)}\n` : ''}${a.focus ? `- **Current f
|
|
|
274
335
|
- **Directness:** ${label(Q.tone, a.tone)}.
|
|
275
336
|
- **Length:** ${label(Q.length, a.length)}.
|
|
276
337
|
- **When you are wrong:** ${label(Q.mistakes, a.mistakes)}.
|
|
277
|
-
- **When you are unsure:** ${
|
|
338
|
+
- **When you are unsure:** ${youLabel(Q.unsure, a.unsure)}.
|
|
278
339
|
- **Never:** ${a.never.length ? a.never.map(md).join('; ') : 'nothing declared'}.
|
|
279
340
|
|
|
280
341
|
### Output shape
|
|
@@ -287,7 +348,7 @@ ${a.work ? `- **What they do:** ${md(a.work)}\n` : ''}${a.focus ? `- **Current f
|
|
|
287
348
|
### Read this first, in order
|
|
288
349
|
|
|
289
350
|
${bullets(a.read_first.map(md), 'USER.md')}
|
|
290
|
-
- ${tool.kind === 'cloud' ? `The index ${unit} of "${md(a.notes_path)}", before writing there.` : `\`${base}/README.md\`, the rules of the folder you may write into, before writing there.`}
|
|
351
|
+
- ${pending ? `Nothing else yet: there is no notes folder to read, and no folder README (${notesLater(base)} and its README). See § Where you may write below.` : tool.kind === 'cloud' ? `The index ${unit} of "${md(a.notes_path)}", before writing there.` : `\`${base}/README.md\`, the rules of the folder you may write into, before writing there.`}
|
|
291
352
|
${a.tracker !== 'none' ? `- The task tracker (${md(a.tracker)}): what is open and what is already decided, before proposing work.\n` : ''}
|
|
292
353
|
### Where you may write
|
|
293
354
|
|
|
@@ -322,8 +383,26 @@ const WRITE_POLICY = {
|
|
|
322
383
|
'logs-and-inbox-only': 'only the session log, the decisions log and the inbox; propose anything else, do not write it',
|
|
323
384
|
'ask-before-every-write': 'ASK BEFORE EVERY WRITE, every time; show what you would write and where',
|
|
324
385
|
};
|
|
325
|
-
|
|
386
|
+
/* The writes line for a folder that is not there yet. It carries BOTH halves in one clause per
|
|
387
|
+
policy: do not create anything unasked (the operative rule while the folder is absent) and the
|
|
388
|
+
policy that applies once it exists. ask-before-every-write keeps its full text, including "show
|
|
389
|
+
what you would write and where": that clause IS the consent, and someone who pasted the two
|
|
390
|
+
ChatGPT boxes and nothing else has no other copy of it (round 1, finding 1). Every line here is
|
|
391
|
+
shorter than the non-pending line it replaces, because the ChatGPT boxes are plain text on a
|
|
392
|
+
~1500-character budget with about two characters of slack on this repo's own fixture, and the
|
|
393
|
+
harness installs all three policies at level 1 and refuses an over-budget box. */
|
|
394
|
+
const WRITE_POLICY_PENDING = {
|
|
395
|
+
'notes-freely': 'Create nothing unasked; once it exists, anywhere under it, under its rules, nowhere else',
|
|
396
|
+
'logs-and-inbox-only': 'Create nothing unasked; once it exists, only the session log, decisions log and inbox',
|
|
397
|
+
'ask-before-every-write': WRITE_POLICY['ask-before-every-write'],
|
|
398
|
+
};
|
|
399
|
+
function writesLine(a, opts) {
|
|
326
400
|
const t = toolFor(a);
|
|
401
|
+
// No backticks, and the policy in its SHORT form: this line also goes into the ChatGPT boxes, which
|
|
402
|
+
// are plain text on a ~1500-character budget with almost no slack, so the pending line is kept no
|
|
403
|
+
// longer than the line it replaces. The strictest policy has to survive the trim, so the policy is
|
|
404
|
+
// named, not dropped; AGENT_ONBOARDING.md § Where you may write carries all of it in full.
|
|
405
|
+
if (notesPending(a, opts)) return `Writes: no notes folder yet (level 2 creates ${esc(baseFor(a))}/). ${WRITE_POLICY_PENDING[a.write_policy]}.`;
|
|
327
406
|
const where = t.kind === 'cloud' ? `${md(t.name)} "${md(a.notes_path)}" through its connector, no filesystem writes`
|
|
328
407
|
: t.kind === 'readonly' ? `${md(t.name)} is read-only for you; the local fallback folder is ${esc(FALLBACK)}/`
|
|
329
408
|
: t.kind === 'other' ? `${md(t.name)} is unknown here: ask before the first write there; local fallback folder ${esc(FALLBACK)}/ meanwhile`
|
|
@@ -337,9 +416,9 @@ function contractBlock(a, opts) {
|
|
|
337
416
|
'',
|
|
338
417
|
`Always ask before: ${a.always_ask.join(', ') || 'nothing declared'}.`,
|
|
339
418
|
a.off_limits.length ? `Off limits in any output: ${a.off_limits.map(md).join(', ')}.` : null,
|
|
340
|
-
writesLine(a),
|
|
419
|
+
writesLine(a, opts),
|
|
341
420
|
files ? `Read first: ${a.read_first.map(md).join(' → ')}.` : null,
|
|
342
|
-
`Directness: ${label(Q.tone, a.tone)}. Length: ${label(Q.length, a.length)}. When wrong: ${label(Q.mistakes, a.mistakes)}. When unsure: ${
|
|
421
|
+
`Directness: ${label(Q.tone, a.tone)}. Length: ${label(Q.length, a.length)}. When wrong: ${label(Q.mistakes, a.mistakes)}. When unsure: ${youLabel(Q.unsure, a.unsure)}.`,
|
|
343
422
|
`Open with ${label(Q.lead_with, a.lead_with)}; ${label(Q.structure, a.structure)}; evidence ${label(Q.evidence, a.evidence)}.${a.signature === 'yes' ? ' Sign every edit to a note (one `Last edited by:` line, overwritten).' : ''}`,
|
|
344
423
|
a.never.length ? `Never: ${a.never.map(md).join('; ')}.` : null,
|
|
345
424
|
].filter(x => x !== null).join('\n');
|
|
@@ -357,4 +436,4 @@ function compactProfile(a) {
|
|
|
357
436
|
].filter(Boolean).join('\n');
|
|
358
437
|
}
|
|
359
438
|
|
|
360
|
-
module.exports = { QUESTIONS, QUICK, PINNED, TOOL, VERSION, DOCS, FALLBACK, defaults, sparse, validate, parseAnswer, renderUser, renderOnboarding, contractBlock, compactProfile, kindOf, baseFor };
|
|
439
|
+
module.exports = { QUESTIONS, QUICK, PINNED, TOOL, VERSION, DOCS, FALLBACK, NOTES_PENDING_MARK, notesPending, asks, defaults, sparse, validate, parseAnswer, renderUser, renderOnboarding, contractBlock, compactProfile, kindOf, baseFor };
|
package/render/render.cjs
CHANGED
|
@@ -302,11 +302,22 @@ function rulesFor(rules, key, answers) {
|
|
|
302
302
|
&& (!r.meta.requires || a[r.meta.requires.answer] === r.meta.requires.value));
|
|
303
303
|
}
|
|
304
304
|
const answersOf = (cfg) => (cfg && cfg.onboarding) ? cfg.onboarding : null;
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
/* Do the notes pointers in a rendered file name something that is there? The README is the file the
|
|
306
|
+
AI is told to read before it writes, and the level-2 scaffold creates it with the folder, so its
|
|
307
|
+
presence is the sharpest one-stat answer. The LEVEL is not: a hand-written config carries none, a
|
|
308
|
+
level-1 install can land beside an existing notes folder, and a re-run at a lower level does not
|
|
309
|
+
delete what a higher one made (round 1, findings 3 to 5). Cloud answers have no local folder at
|
|
310
|
+
all, and notesPending() short-circuits on that before this is consulted. */
|
|
311
|
+
const notesScaffolded = (root, answers) => {
|
|
312
|
+
if (!answers) return true;
|
|
313
|
+
try { return fs.statSync(path.join(root, onboarding.baseFor(answers), 'README.md')).isFile(); }
|
|
314
|
+
catch (_) { return false; }
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
function renderTarget(key, target, profile, rules, cfg, root) {
|
|
307
318
|
if (target.source === 'onboarding') {
|
|
308
319
|
if (!cfg || !cfg.onboarding) die(`target "${key}": no onboarding answers in .agent-personalizer.json. Run the installer (it asks), or pass --answers <file>`);
|
|
309
|
-
return onboarding.renderOnboarding(cfg.onboarding);
|
|
320
|
+
return onboarding.renderOnboarding(cfg.onboarding, { notesScaffolded: notesScaffolded(root, cfg.onboarding) });
|
|
310
321
|
}
|
|
311
322
|
const answers = answersOf(cfg);
|
|
312
323
|
const lines = [`## ${target.header}`, '', '_Generated by agent-personalizer from `USER.md`, `rules/` and your onboarding answers. Edit those, then re-render. Do not edit between the markers._', ''];
|
|
@@ -322,7 +333,7 @@ function renderTarget(key, target, profile, rules, cfg) {
|
|
|
322
333
|
return parts.join('\n\n');
|
|
323
334
|
}).join('\n\n');
|
|
324
335
|
const box1 = answers ? onboarding.compactProfile(answers) : (profile || '(no USER.md found)');
|
|
325
|
-
const box2 = answers ? [onboarding.contractBlock(answers, { files: false }).split('\n').slice(2).join('\n'), ruleText].filter(Boolean).join('\n\n') : ruleText;
|
|
336
|
+
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;
|
|
326
337
|
const over = [];
|
|
327
338
|
const warn = (label, text) => {
|
|
328
339
|
if (text.length > target.limit) { over.push(label); return `\n> **${label} is OVER BUDGET: ${text.length} characters, the box allows about ${target.limit}.** Nothing was cut for you. Trim from the bottom up: the box is ordered by consequence (restrictions first, style last), so the last lines are the cheapest to lose.`; }
|
|
@@ -383,6 +394,17 @@ function between(existing, file) {
|
|
|
383
394
|
return existing.slice(st.bEnd, st.eStart).replace(/\r\n/g, '\n').replace(/^\n/, '').replace(/\n$/, '');
|
|
384
395
|
}
|
|
385
396
|
|
|
397
|
+
/* One line per file, one verb per line, and the verb is the one that is true of THAT file. The
|
|
398
|
+
installer writes a home file from its template and then calls this renderer to fill the block, so
|
|
399
|
+
a run that printed "wrote" for both steps said the same file was created twice, and a re-run that
|
|
400
|
+
kept the file printed "kept" and then "wrote" it. */
|
|
401
|
+
function report(label, existing, current, block, raw) {
|
|
402
|
+
if (existing == null) return `wrote ${label}`;
|
|
403
|
+
if (current === block) return `ok ${label} (${raw ? 'already current' : 'rendered block already current'})`;
|
|
404
|
+
if (!raw && current === null) return `update ${label} (rendered block added)`;
|
|
405
|
+
return `update ${label} (${raw ? 'rewritten' : 'rendered block'})`;
|
|
406
|
+
}
|
|
407
|
+
|
|
386
408
|
function main() {
|
|
387
409
|
ARGS = parseArgs();
|
|
388
410
|
if (arg('--version', false) || arg('-v', false)) { process.stdout.write(onboarding.VERSION + '\n'); return; }
|
|
@@ -404,7 +426,7 @@ function main() {
|
|
|
404
426
|
const cfgC = readConfig(root);
|
|
405
427
|
const inject = rulesFor(rules, key, answersOf(cfgC)).filter(r => r.meta.inject === true);
|
|
406
428
|
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.`, ''];
|
|
407
|
-
if (cfgC && cfgC.onboarding && withPersonal) out.push(onboarding.contractBlock(cfgC.onboarding), '');
|
|
429
|
+
if (cfgC && cfgC.onboarding && withPersonal) out.push(onboarding.contractBlock(cfgC.onboarding, { notesScaffolded: notesScaffolded(root, cfgC.onboarding) }), '');
|
|
408
430
|
for (const r of inject) {
|
|
409
431
|
out.push(`## ${r.meta.title || r.meta.id || r.file}`, '', r.sections.universal);
|
|
410
432
|
if (withPersonal && r.sections.personal) out.push('', r.sections.personal);
|
|
@@ -433,7 +455,7 @@ function main() {
|
|
|
433
455
|
const target = TARGETS[key];
|
|
434
456
|
if (!target) die(`unknown target "${key}" (known: ${KNOWN.join(', ')})`);
|
|
435
457
|
const file = safeTargetPath(root, target.file, key);
|
|
436
|
-
const block = renderTarget(key, target, profile, rules, cfg);
|
|
458
|
+
const block = renderTarget(key, target, profile, rules, cfg, root);
|
|
437
459
|
let existing = null;
|
|
438
460
|
if (fs.existsSync(file)) {
|
|
439
461
|
existing = decodeUtf8(fs.readFileSync(file), target.file);
|
|
@@ -447,7 +469,7 @@ function main() {
|
|
|
447
469
|
// the generated file must itself re-parse to exactly one block, or the next render would refuse it
|
|
448
470
|
if (output != null) { const st = markerState(output, `${target.file} (generated)`); if (st.kind !== 'one' || between(output, `${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`); }
|
|
449
471
|
const mode = existing == null ? 0o644 : (fs.statSync(file).mode & 0o777);
|
|
450
|
-
const entry = { key, target, file, block, current, output, mode };
|
|
472
|
+
const entry = { key, target, file, block, current, output, mode, report: report(target.file, existing, current, block, false) };
|
|
451
473
|
if (!target.boxes) return entry;
|
|
452
474
|
// the two plain paste files: whole-file outputs, no markers, compared whole in --check
|
|
453
475
|
const raws = Object.entries(target.boxFiles || {}).map(([which, rel]) => {
|
|
@@ -457,7 +479,7 @@ function main() {
|
|
|
457
479
|
if (fs.existsSync(rfile)) rexisting = decodeUtf8(fs.readFileSync(rfile), rel);
|
|
458
480
|
if (!check) { try { fs.accessSync(rexisting == null ? path.dirname(rfile) : rfile, fs.constants.W_OK); } catch (_) { die(`${rel}: not writable. Nothing was written`); } }
|
|
459
481
|
const rmode = rexisting == null ? 0o644 : (fs.statSync(rfile).mode & 0o777);
|
|
460
|
-
return { key: `${key}:${which}`, target: { file: rel }, file: rfile, block: text, current: rexisting, output: check ? null : text, mode: rmode, raw: true };
|
|
482
|
+
return { key: `${key}:${which}`, target: { file: rel }, file: rfile, block: text, current: rexisting, output: check ? null : text, mode: rmode, raw: true, report: report(rel, rexisting, rexisting, text, true) };
|
|
461
483
|
});
|
|
462
484
|
return [entry, ...raws];
|
|
463
485
|
}).flat();
|
|
@@ -516,7 +538,7 @@ function main() {
|
|
|
516
538
|
try {
|
|
517
539
|
for (const p of plan) {
|
|
518
540
|
const tmp = path.join(path.dirname(p.file), `.${path.basename(p.file)}.${run}.agent-personalizer.tmp`);
|
|
519
|
-
staged.push({ tmp, file: p.file, label: p.target.file, mode: p.mode }); // recorded BEFORE the file can exist; cleanup tolerates ENOENT
|
|
541
|
+
staged.push({ tmp, file: p.file, label: p.target.file, mode: p.mode, report: p.report }); // recorded BEFORE the file can exist; cleanup tolerates ENOENT
|
|
520
542
|
fs.writeFileSync(tmp, p.output, { flag: 'wx', mode: p.mode });
|
|
521
543
|
fs.chmodSync(tmp, p.mode);
|
|
522
544
|
}
|
|
@@ -538,7 +560,7 @@ function main() {
|
|
|
538
560
|
} catch (e) { undo(`could not commit output (${e.message})`); }
|
|
539
561
|
const leftovers = [];
|
|
540
562
|
for (const c of committed) if (c.bak) tryUnlink(c.bak, leftovers, 'backup not removed');
|
|
541
|
-
for (const s of staged) console.log(
|
|
563
|
+
for (const s of staged) console.log(s.report);
|
|
542
564
|
for (const o of (renderTarget.overBudget || [])) console.log(`OVER BUDGET ${o} (written in full; trim by hand, bottom up)`);
|
|
543
565
|
if (leftovers.length) {
|
|
544
566
|
console.error('render: every target was written, but CLEANUP INCOMPLETE. Remove these by hand (they hold copies of the previous targets):');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `<Folder name>`
|
|
2
2
|
|
|
3
3
|
*One line: what this folder is for and what does NOT belong here.*
|
|
4
4
|
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
Relevant means a decision, a status flip, a reversal, a new section, a changed scope. Not a typo fix. If nothing became untrue, leave it and say so.
|
|
33
33
|
|
|
34
34
|
---
|
|
35
|
-
Last edited by: <ai> <model> <YYYY-MM-DD> · <ten words on what changed
|
|
35
|
+
`Last edited by: <ai> <model> <YYYY-MM-DD> · <ten words on what changed>`
|
|
@@ -8,9 +8,9 @@ A decision that reverses an earlier one names the earlier line and says "superse
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
-
|
|
11
|
+
- `<YYYY-MM-DD> · <decision> · why: <reason> · where: <session slug>`
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
<!-- synthesis watermark: read through <YYYY-MM-DD> (a sweep that promotes decisions to memory updates this line) -->
|
|
15
15
|
|
|
16
|
-
Last edited by: <ai> <model> <YYYY-MM-DD> · <ten words
|
|
16
|
+
`Last edited by: <ai> <model> <YYYY-MM-DD> · <ten words>`
|
package/templates/session-log.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Session log ·
|
|
1
|
+
# Session log · `<YYYY>-W<ww>`
|
|
2
2
|
|
|
3
3
|
*One note per ISO week. Each session appends a dated section below. Records are grouped by type so a later sweep can promote the durable ones to memory. Nothing here is a rule until it is promoted.*
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ Record types: `decision` · `correction` (the AI was wrong, how, what it should
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## `<YYYY-MM-DD>` - `<three-to-six-word slug>`
|
|
10
10
|
|
|
11
11
|
**What happened:** one or two lines.
|
|
12
12
|
|
|
@@ -19,4 +19,4 @@ Record types: `decision` · `correction` (the AI was wrong, how, what it should
|
|
|
19
19
|
|
|
20
20
|
<!-- next session appends above this line, newest at the top of the week -->
|
|
21
21
|
|
|
22
|
-
Last edited by: <ai> <model> <YYYY-MM-DD> · <ten words
|
|
22
|
+
`Last edited by: <ai> <model> <YYYY-MM-DD> · <ten words>`
|