agent-personalizer 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +155 -0
  3. package/bin/agent-personalizer.js +388 -0
  4. package/check/forbidden.example.txt +31 -0
  5. package/check/gate.cjs +349 -0
  6. package/docs/companions.md +62 -0
  7. package/docs/paste-guide.md +66 -0
  8. package/docs/tiers.md +89 -0
  9. package/examples/freelance-illustrator/.agent-personalizer.json +52 -0
  10. package/examples/freelance-illustrator/AGENTS.md +180 -0
  11. package/examples/freelance-illustrator/AGENT_ONBOARDING.md +70 -0
  12. package/examples/freelance-illustrator/CLAUDE.md +184 -0
  13. package/examples/freelance-illustrator/USER.md +49 -0
  14. package/examples/freelance-illustrator/notes/README.md +39 -0
  15. package/examples/freelance-illustrator/notes/decisions.md +18 -0
  16. package/examples/freelance-illustrator/notes/inbox/2026-09-03-shot-list-for-six-prints.md +14 -0
  17. package/examples/freelance-illustrator/notes/inbox/README.md +19 -0
  18. package/examples/freelance-illustrator/notes/sessions/2026-W36.md +41 -0
  19. package/examples/freelance-illustrator/rules/00-read-the-profile-first.md +24 -0
  20. package/examples/freelance-illustrator/rules/10-evidence-before-assertion.md +24 -0
  21. package/examples/freelance-illustrator/rules/20-one-owner-per-rule.md +24 -0
  22. package/examples/freelance-illustrator/rules/30-folder-index-is-part-of-the-change.md +26 -0
  23. package/examples/freelance-illustrator/rules/40-sign-every-edit.md +25 -0
  24. package/examples/freelance-illustrator/rules/50-output-style.md +21 -0
  25. package/examples/freelance-illustrator/rules/60-act-or-ask.md +30 -0
  26. package/hooks/README.md +39 -0
  27. package/hooks/claude-code/session-start.sh +14 -0
  28. package/package.json +49 -0
  29. package/render/onboarding.cjs +360 -0
  30. package/render/render.cjs +559 -0
  31. package/render/targets.json +57 -0
  32. package/rules/00-read-the-profile-first.md +24 -0
  33. package/rules/10-evidence-before-assertion.md +24 -0
  34. package/rules/20-one-owner-per-rule.md +24 -0
  35. package/rules/30-folder-index-is-part-of-the-change.md +26 -0
  36. package/rules/40-sign-every-edit.md +25 -0
  37. package/rules/50-output-style.md +21 -0
  38. package/rules/60-act-or-ask.md +30 -0
  39. package/rules/README.md +55 -0
  40. package/templates/AGENTS.md +30 -0
  41. package/templates/CLAUDE.md +30 -0
  42. package/templates/FOLDER_README.md +35 -0
  43. package/templates/INBOX_README.md +19 -0
  44. package/templates/USER.md +52 -0
  45. package/templates/decisions-log.md +16 -0
  46. package/templates/session-log.md +22 -0
package/check/gate.cjs ADDED
@@ -0,0 +1,349 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /*
4
+ gate.cjs: the zero-personal-data gate.
5
+
6
+ Scans every regular, non-binary file under a directory for terms listed in
7
+ check/forbidden.local.txt and fails loudly on any hit. The list itself is gitignored:
8
+ a list of your own identifiers must never ship in a public repo.
9
+
10
+ usage:
11
+ node check/gate.cjs [--dir <root>] [--list <file>] scan; exit 0 clean, 1 on hits, 2 on setup error
12
+ node check/gate.cjs --self-test prove the gate can go red on a seeded hit
13
+
14
+ Fail-closed: a missing or empty list is exit 2, never a pass; a list that git tracks is exit 2.
15
+ The list file may never be tracked by git; every repository enclosing its REAL path is
16
+ asked, with a literal pathspec, before anything is scanned, whatever --dir or --all say.
17
+ The list must be a regular file, not a symlink.
18
+ Coverage: anywhere inside a git work tree (a subfolder included), exactly what git would
19
+ ship from --dir down: for every cached path the INDEX blob (what a commit publishes) plus
20
+ the working-tree copy when it differs (what the next `git add` publishes); for every
21
+ untracked, not-ignored path the working-tree copy. A gitignored scratch file cannot fail
22
+ the gate, a forgotten new file cannot dodge it, and a leak staged then cleaned on disk is
23
+ still caught. A symlink is never followed, but its target text is scanned (git ships it).
24
+ --all walks every regular file under --dir, node_modules included; only .git is skipped. Git enumeration failing inside a
25
+ repo is a setup error (exit 2), never a silent fallback. Outside a repo, or with --all,
26
+ every regular file under --dir. Any extension. Binary files (a NUL
27
+ byte in the first 8 KB) are skipped. Symlinks are never followed.
28
+ Matching: case-insensitive substring, over each file's TEXT and over its relative PATH (a
29
+ private name in a published filename is still a disclosure; a path hit is labelled "(path)").
30
+ Lines "allow:<exact text>" whitelist that exact string (attribution you keep on purpose); a
31
+ forbidden term inside an allowed string does not count. Unicode lookalikes are not detected.
32
+ A working-tree path whose parent directory is a symlink is NOT read (the file would be outside
33
+ the scan root); the index blob for that path is still scanned, and the skip is counted and
34
+ printed. What this gate is: a check for the exact strings you listed. What it is not: a proof
35
+ that no personal data ships. Unknown terms, history and binary files are outside it.
36
+ */
37
+ const fs = require('fs');
38
+ const path = require('path');
39
+ const os = require('os');
40
+ const { execFileSync } = require('child_process');
41
+
42
+ const SKIP_DIRS = new Set(['.git']); // --all means every file; git mode lets .gitignore decide about node_modules
43
+
44
+ function die(msg) { console.error(`GATE SETUP ERROR: ${msg}`); process.exit(2); }
45
+
46
+ const VALUE_OPTS = ['--dir', '--list'];
47
+ const FLAG_OPTS = ['--self-test', '--all'];
48
+ /* Parse argv once, strictly: value options at most once each, flags at most once, nothing unknown. */
49
+ function parseArgs() {
50
+ const out = {};
51
+ const argv = process.argv.slice(2);
52
+ for (let i = 0; i < argv.length; i++) {
53
+ const a = argv[i];
54
+ if (VALUE_OPTS.includes(a)) {
55
+ if (a in out) die(`${a} given more than once`);
56
+ const v = argv[i + 1];
57
+ if (v === undefined || v === '' || v.startsWith('--')) die(`${a} needs a non-empty value`);
58
+ out[a] = v; i++;
59
+ } else if (FLAG_OPTS.includes(a)) {
60
+ if (a in out) die(`${a} given more than once`);
61
+ out[a] = true;
62
+ } else die(`unknown option "${a}" (known: ${[...VALUE_OPTS, ...FLAG_OPTS].join(', ')})`);
63
+ }
64
+ return out;
65
+ }
66
+ let ARGS = null;
67
+ function arg(name, dflt) { if (!ARGS) ARGS = parseArgs(); return name in ARGS ? ARGS[name] : dflt; }
68
+
69
+ /* If ANY enclosing git repository tracks the list file, it would ship. Every ancestor
70
+ directory that carries .git metadata is asked, with a literal pathspec (so a name with
71
+ `*`, `?`, `[` or a leading `:` cannot be misread), for an index entry at the list's
72
+ repo-relative path. Independent of --dir and --all. Git failing while metadata exists is
73
+ a setup error; a "not a repository" answer is trusted only when no metadata exists. */
74
+ function hasDotGit(dir) {
75
+ // lstat, not existsSync: a dangling .git symlink or any odd entry is still metadata
76
+ try { fs.lstatSync(path.join(dir, '.git')); return true; } catch (e) { return e.code !== 'ENOENT'; }
77
+ }
78
+
79
+ function refuseTrackedList(file) {
80
+ let dir = path.dirname(file);
81
+ for (;;) {
82
+ if (hasDotGit(dir)) {
83
+ const rel = path.relative(dir, file);
84
+ let out;
85
+ try {
86
+ out = execFileSync('git', ['-C', dir, 'ls-files', '-z', '--cached', '--full-name', '--', `:(literal)${rel}`], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
87
+ } catch (e) {
88
+ const err = String(e.stderr || e.message || '');
89
+ die(`${dir} carries .git metadata but git could not answer whether it tracks ${rel} (${err.trim().split('\n')[0] || e.code || 'unknown error'}). Fix git first.`);
90
+ }
91
+ if (out.split('\0').filter(Boolean).length) die(`the forbidden list itself is tracked by git (${file}, repository ${dir}). It must never ship: run \`git rm --cached -- ":(literal)${rel}"\` in ${dir} and add it to .gitignore.`);
92
+ }
93
+ const parent = path.dirname(dir);
94
+ if (parent === dir) return;
95
+ dir = parent;
96
+ }
97
+ }
98
+
99
+ function loadList(file) {
100
+ let st = null;
101
+ try { st = fs.lstatSync(file); } catch (_) { st = null; }
102
+ if (!st) die(`${file} not found.\nCopy check/forbidden.example.txt to that path and fill it in. The gate does not pass without it.`);
103
+ if (st.isSymbolicLink()) die(`${file} is a symlink; the list must be a regular file (a link can point at a tracked copy)`);
104
+ if (!st.isFile()) die(`${file} is not a regular file`);
105
+ const real = fs.realpathSync(file); // the REAL path: an alias through a symlinked directory must not hide the repository that tracks it
106
+ refuseTrackedList(real);
107
+ let text;
108
+ try { text = fs.readFileSync(file, 'utf8'); } catch (e) { die(`cannot read ${file} (${e.code || e.message})`); }
109
+ const terms = [], allow = [];
110
+ text.split('\n').forEach((raw, n) => {
111
+ const line = raw.trim();
112
+ if (!line || line.startsWith('#')) return;
113
+ if (line.startsWith('allow:')) {
114
+ const a = line.slice(6).trim();
115
+ if (!a) die(`${file}:${n + 1}: empty allow entry`);
116
+ allow.push(a);
117
+ } else terms.push(line);
118
+ });
119
+ if (!terms.length) die('forbidden list has no terms.');
120
+ return { terms, allow, real };
121
+ }
122
+
123
+ function isBinary(bytes) { return bytes.subarray(0, 8192).includes(0); }
124
+
125
+ function* walk(root) {
126
+ for (const name of fs.readdirSync(root).sort()) {
127
+ if (SKIP_DIRS.has(name)) continue;
128
+ const p = path.join(root, name);
129
+ const st = fs.lstatSync(p);
130
+ if (st.isSymbolicLink()) { yield p; continue; } // yielded so its TARGET TEXT gets scanned; never followed
131
+ if (st.isDirectory()) yield* walk(p);
132
+ else if (st.isFile()) yield p;
133
+ }
134
+ }
135
+
136
+ function allowedSpans(lineLower, allow) {
137
+ const spans = [];
138
+ for (const a of allow) {
139
+ const al = a.toLowerCase();
140
+ if (!al.length) continue;
141
+ let i = lineLower.indexOf(al);
142
+ while (i !== -1) { spans.push([i, i + al.length]); i = lineLower.indexOf(al, i + al.length); }
143
+ }
144
+ return spans;
145
+ }
146
+
147
+ /* What git would ship, as {label, bytes} items:
148
+ - every cached path: the INDEX blob (that is what a commit publishes), and the working-tree
149
+ copy as well when it differs from the index (that is what `git add` would publish next);
150
+ - every untracked, not-ignored path: the working-tree copy.
151
+ A tracked submodule (gitlink, mode 160000) is refused: its files are not in this index. */
152
+ function git(root, args, input) {
153
+ return execFileSync('git', ['-C', root, ...args], { input, maxBuffer: 1 << 28 });
154
+ }
155
+
156
+ function* gitItems(root) {
157
+ const stage = git(root, ['ls-files', '-z', '--stage']).toString('utf8');
158
+ const cached = [];
159
+ for (const rec of stage.split('\0')) {
160
+ if (!rec) continue;
161
+ const m = rec.match(/^(\d{6}) ([0-9a-f]{40,64}) (\d)\t([\s\S]*)$/);
162
+ if (!m) die(`unreadable index record: ${rec.slice(0, 80)}`);
163
+ const [, mode, oid, , rel] = m;
164
+ if (mode === '160000') die(`tracked submodule at ${rel}: the gate does not descend into submodules. Run it inside the submodule, or pass --all to walk every file under --dir.`);
165
+ cached.push({ oid, rel, link: mode === '120000' }); // a symlink entry ships its TARGET TEXT as the blob; scanned, never followed
166
+ }
167
+ // index blobs, in one batch
168
+ if (cached.length) {
169
+ const out = git(root, ['cat-file', '--batch'], cached.map(c => c.oid).join('\n') + '\n');
170
+ let pos = 0;
171
+ for (const c of cached) {
172
+ const nl = out.indexOf(0x0a, pos);
173
+ if (nl === -1) die(`git cat-file: short output for ${c.rel}`);
174
+ const header = out.subarray(pos, nl).toString('utf8');
175
+ const hm = header.match(/^([0-9a-f]+) (\w+) (\d+)$/);
176
+ if (!hm) die(`git cat-file: unexpected header for ${c.rel}: ${header}`);
177
+ const size = Number(hm[3]);
178
+ const body = out.subarray(nl + 1, nl + 1 + size);
179
+ pos = nl + 1 + size + 1;
180
+ yield { rel: c.rel, label: c.link ? `${c.rel} (index, symlink target)` : `${c.rel} (index)`, bytes: body };
181
+ }
182
+ }
183
+ // working-tree copies that differ from the index
184
+ // --relative: paths relative to --dir, the same coordinate system ls-files uses from there
185
+ const changed = new Set(git(root, ['diff', '--name-only', '-z', '--relative']).toString('utf8').split('\0').filter(Boolean));
186
+ for (const c of cached) {
187
+ if (!changed.has(c.rel)) continue;
188
+ const item = treeItem(root, c.rel, ' (working tree)');
189
+ if (item) yield item;
190
+ }
191
+ // untracked, not ignored
192
+ const others = git(root, ['ls-files', '-z', '--others', '--exclude-standard']).toString('utf8').split('\0').filter(Boolean);
193
+ for (const rel of others) {
194
+ const item = treeItem(root, rel, '');
195
+ if (item) yield item;
196
+ }
197
+ }
198
+
199
+ /* A working-tree entry as scan bytes: a regular file's content, or a symlink's TARGET TEXT
200
+ (readlink, never followed). Anything else is skipped. */
201
+ function treeItem(root, rel, suffix) {
202
+ const p = path.join(root, rel);
203
+ // every ancestor of the path must be a real directory inside root: a symlinked parent would
204
+ // make this read a file OUTSIDE the scan root (git itself would not ship that content)
205
+ const parts = rel.split('/'); let cur = root;
206
+ for (let i = 0; i < parts.length - 1; i++) {
207
+ cur = path.join(cur, parts[i]);
208
+ let ds; try { ds = fs.lstatSync(cur); } catch (_) { return null; }
209
+ if (ds.isSymbolicLink() || !ds.isDirectory()) { treeItem.skipped.push(`${rel}${suffix || ' (working tree)'}: parent ${path.relative(root, cur)} is ${ds.isSymbolicLink() ? 'a symlink' : 'not a directory'}`); return null; }
210
+ }
211
+ let st; try { st = fs.lstatSync(p); } catch (_) { return null; }
212
+ if (st.isSymbolicLink()) return { rel, label: `${rel}${suffix || ' (working tree)'} symlink target`, bytes: Buffer.from(fs.readlinkSync(p), 'utf8') };
213
+ if (st.isFile()) return { rel, label: `${rel}${suffix}`, bytes: fs.readFileSync(p) };
214
+ return null;
215
+ }
216
+
217
+ treeItem.skipped = [];
218
+
219
+ function* walkItems(root) {
220
+ for (const p of walk(root)) {
221
+ const st = fs.lstatSync(p);
222
+ const rel = path.relative(root, p);
223
+ if (st.isSymbolicLink()) yield { rel, label: `${rel} (symlink target)`, bytes: Buffer.from(fs.readlinkSync(p), 'utf8') };
224
+ else yield { rel, label: rel, bytes: fs.readFileSync(p) };
225
+ }
226
+ }
227
+
228
+ /* Does any ancestor (root included) carry .git metadata? Checked without git. */
229
+ function hasGitMetadata(root) {
230
+ let dir = root;
231
+ for (;;) {
232
+ if (hasDotGit(dir)) return true;
233
+ const parent = path.dirname(dir);
234
+ if (parent === dir) return false;
235
+ dir = parent;
236
+ }
237
+ }
238
+
239
+ /* true = inside a git work tree; false = git confirmed "not a repository", or git could
240
+ not run AND no .git metadata exists anywhere above. Git failing while .git metadata is
241
+ present is a setup error: a walk over a repo can miss tracked files under skipped
242
+ directories, so the gate refuses rather than degrades. */
243
+ function insideGitRepo(root) {
244
+ try {
245
+ const bare = execFileSync('git', ['-C', root, 'rev-parse', '--is-bare-repository'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
246
+ if (bare === 'true') die(`${root} is a bare repository: there is no working tree to ship and this gate does not read packed objects. Run it in a checkout.`);
247
+ return execFileSync('git', ['-C', root, 'rev-parse', '--is-inside-work-tree'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim() === 'true';
248
+ } catch (e) {
249
+ if (e && e.message && /is a bare repository/.test(e.message)) throw e;
250
+ const err = String(e.stderr || e.message || '');
251
+ if (!hasGitMetadata(root)) return false;
252
+ if (e.status === 128 && /not a git repository/i.test(err)) die(`${root} carries .git metadata that git rejects as not a repository (${err.trim().split('\n')[0]}). Repair it, or pass --all to scan every file under --dir.`);
253
+ die(`${root} carries git metadata but git could not run (${err.trim().split('\n')[0] || e.code || 'unknown error'}). Fix git, or pass --all to scan every file under --dir.`);
254
+ }
255
+ }
256
+
257
+ function fileSet(root, all) {
258
+ if (all) return { items: walkItems(root), mode: 'walk' };
259
+ if (insideGitRepo(root)) {
260
+ let items;
261
+ try { items = [...gitItems(root)]; } catch (e) { if (e && e.message && /^(tracked submodule|unreadable index|git cat-file)/.test(e.message)) throw e; die(`git enumeration failed inside a repository: ${e.message}`); }
262
+ return { items, mode: 'git' };
263
+ }
264
+ return { items: walkItems(root), mode: 'walk' };
265
+ }
266
+
267
+ function scan(root, list, listFile, all) {
268
+ root = fs.realpathSync(root); // every caller, self-test included, compares real paths
269
+ const hits = [];
270
+ const scannedPaths = new Set();
271
+ treeItem.skipped = [];
272
+ let files = 0;
273
+ const skipPath = list.real || (listFile ? path.resolve(listFile) : null);
274
+ const set = fileSet(root, all);
275
+ scan.mode = set.mode;
276
+ // The list file is excluded by its exact resolved path, never by its display label, and
277
+ // only as a working-tree copy: if git has it in the INDEX it would ship, so that is exit 2.
278
+ for (const item of set.items) {
279
+ if (skipPath && path.resolve(root, item.rel) === skipPath) {
280
+ if (/\(index/.test(item.label)) die(`the forbidden list itself is tracked by git (${item.rel}). It must never ship: run \`git rm --cached ${item.rel}\` and add it to .gitignore.`);
281
+ continue;
282
+ }
283
+ files++;
284
+ // the PATH first: one scan per item, labelled "(path)", never covered by allow spans of the text
285
+ if (!scannedPaths.has(item.rel)) {
286
+ scannedPaths.add(item.rel);
287
+ const lower = item.rel.toLowerCase(), spans = allowedSpans(lower, list.allow);
288
+ for (const term of list.terms) {
289
+ const t = term.toLowerCase(); let i = lower.indexOf(t);
290
+ while (i !== -1) { if (!spans.some(([x, y]) => i >= x && i + t.length <= y)) hits.push({ file: `${item.rel} (path)`, line: 0, term }); i = lower.indexOf(t, i + 1); }
291
+ }
292
+ }
293
+ if (isBinary(item.bytes)) continue;
294
+ const lines = item.bytes.toString('utf8').split('\n');
295
+ lines.forEach((line, n) => {
296
+ const lower = line.toLowerCase();
297
+ const spans = allowedSpans(lower, list.allow);
298
+ for (const term of list.terms) {
299
+ const t = term.toLowerCase();
300
+ let i = lower.indexOf(t);
301
+ while (i !== -1) {
302
+ const inside = spans.some(([a, b]) => i >= a && i + t.length <= b);
303
+ if (!inside) hits.push({ file: item.label, line: n + 1, term });
304
+ i = lower.indexOf(t, i + 1);
305
+ }
306
+ }
307
+ });
308
+ }
309
+ return { hits, files, skipped: treeItem.skipped.slice() };
310
+ }
311
+
312
+ function selfTest() {
313
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gate-selftest-'));
314
+ let ok = false;
315
+ try {
316
+ const listFile = path.join(tmp, 'forbidden.txt');
317
+ fs.writeFileSync(listFile, 'Seeded Secret Name\nallow:Copyright Seeded Secret Name Ltd\n');
318
+ fs.writeFileSync(path.join(tmp, 'clean.md'), 'Nothing to see. Copyright Seeded Secret Name Ltd is allowed.\n');
319
+ fs.writeFileSync(path.join(tmp, 'dirty.md'), 'This mentions seeded secret name in prose.\n');
320
+ fs.writeFileSync(path.join(tmp, 'Dockerfile'), 'RUN echo seeded secret name\n');
321
+ fs.writeFileSync(path.join(tmp, 'blob.bin'), Buffer.from([0x73, 0x65, 0x00, 0x65, 0x64]));
322
+ const { hits } = scan(tmp, loadList(listFile), listFile, true);
323
+ const files = hits.map(h => h.file).sort().join(',');
324
+ ok = hits.length === 2 && files === 'Dockerfile,dirty.md';
325
+ console.log(ok ? 'self-test: gate went red on the seeded hits (dirty.md, Dockerfile), green on the allowed string, skipped the binary' : `self-test FAILED: expected hits in Dockerfile and dirty.md only, got ${JSON.stringify(hits)}`);
326
+ } finally {
327
+ fs.rmSync(tmp, { recursive: true, force: true });
328
+ }
329
+ process.exitCode = ok ? 0 : 1;
330
+ }
331
+
332
+ function main() {
333
+ if (!!arg('--self-test', false)) return selfTest();
334
+ let root = path.resolve(arg('--dir', path.join(__dirname, '..')));
335
+ if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) die(`--dir ${root} is not a directory`);
336
+ root = fs.realpathSync(root); // same canonical form as the list path, so the exclusion compares like with like
337
+ const listFile = path.resolve(arg('--list', path.join(__dirname, 'forbidden.local.txt')));
338
+ const all = !!arg('--all', false);
339
+ const { hits, files, skipped } = scan(root, loadList(listFile), listFile, all);
340
+ for (const k of skipped) console.log(`skipped ${k} (outside the scan root; not read)`);
341
+ if (hits.length) {
342
+ console.log(`GATE FAILED: ${hits.length} hit(s)`);
343
+ for (const h of hits) console.log(` ${h.file}${h.line ? ':' + h.line : ''} "${h.term}"`);
344
+ process.exit(1);
345
+ }
346
+ console.log(`gate clean: 0 hits across ${files} files, text and paths (${scan.mode === 'git' ? 'files git would ship, index blobs included' : 'every file under --dir'}; ${skipped.length} skipped)`);
347
+ }
348
+
349
+ main();
@@ -0,0 +1,62 @@
1
+ # Companion tools
2
+
3
+ This repo tells an AI *how to behave with you*. Two companions govern *what it can touch* and *what it is allowed to carry*. Neither is required; both make the onboarding answers enforceable instead of advisory.
4
+
5
+ | Your answer in the interview | What enforces it without a companion | With a companion |
6
+ |---|---|---|
7
+ | **Always ask before** delete / publish / send / spend | the AI remembering | obsidian-tc: destructive tools fail closed until a human confirms |
8
+ | **Off limits** folders | the AI remembering | obsidian-tc: folder ACL deny, per caller |
9
+ | **Write policy** (freely / logs and inbox only / ask first) | the AI remembering | obsidian-tc: per-folder read / write / delete scopes; Context Layer: memory writes stay proposals until approved |
10
+ | **Evidence inline** | the AI citing what it read | Context Layer: every disclosure and action leaves a receipt |
11
+
12
+ ---
13
+
14
+ ## obsidian-tc (for Obsidian vaults)
15
+
16
+ **What it is.** A governed MCP server over Obsidian vaults: https://github.com/The-40-Thieves/obsidian-tc (AGPL-3.0). Its own README states the problem it exists for: an agent with raw filesystem access to a vault "can do real damage", and most Obsidian MCP servers hand that access over with an API key between the agent and everything you have written.
17
+
18
+ **What it adds** (its words, condensed):
19
+ - **Governed writes**: every call runs through auth → scopes → folder ACL → read-only kill switch → idempotency → throttle → human-in-the-loop confirmation → audit log. You decide which folders an agent may read, write or delete, per vault and per caller; destructive operations fail closed until a human approves.
20
+ - **Fused retrieval**: BM25 + vector + graph, fused and reranked, so "where did I say X" works across a large vault.
21
+ - **Memory that lives in the vault**: episodes, activation decay, explicit forgetting, under the same ACL as every other write.
22
+ - **Three meta-tools by default** (`find_capability`, `describe_capability`, `call_capability`) in front of ~163 capabilities, so the agent's context stays small.
23
+
24
+ **Try it**:
25
+ ```bash
26
+ npx obsidian-tc /path/to/vault
27
+ ```
28
+ Lexical search and every note tool work immediately; semantic and graph retrieval need an embeddings backend (Ollama by default). Also ships as a Docker image, an `.mcpb` bundle, and standalone binaries.
29
+
30
+ **How it pairs with this repo.** Answer `notes_tool: obsidian` and `obsidian_tc: yes` and the rendered `AGENT_ONBOARDING.md` tells the AI to reach the vault through obsidian-tc rather than the filesystem; your **off-limits** and **always-ask** answers become the folder ACL and the human-in-the-loop list you configure there. Same intent, now enforced. Answer `obsidian_tc: no` (the default) and the AI works on the vault folder directly, with the onboarding file naming what obsidian-tc would add.
31
+
32
+ ---
33
+
34
+ ## The Context Layer (Sierra Catalina)
35
+
36
+ **What it is.** A specification and starter for purpose-bound context between you, your vault, and any agent: https://sierracatalina.com/context-layer. It is an architecture you adopt, with tested v0.2 contracts and a local proof profile you can run, not a package you install once.
37
+
38
+ **The shape** (from the page, condensed). Six stages: **capture** (record source, time, identity and a payload digest before interpretation) → **normalize** (derive structured claims with provenance and confidence) → **vault** (encrypted originals and policy state stay inside user-controlled authority; raw data never enters a bundle or a receipt) → **decide** (allow, reduce, approve or deny, by purpose, recipient, selectors, actions and expiry) → **bundle** (recipient-bound, expiring, single-use context with restrictions and provenance) → **act** (verify capabilities, execute the permitted action, append a minimized receipt; **memory writes remain proposals**). The receipt rail: request → decision → disclosure → action → writeback.
39
+
40
+ **Read in this order**: the [essay](https://sierracatalina.com/signal/the-context-layer) (the argument in plain language) → [architecture](https://sierracatalina.com/context-layer/architecture) → [specification](https://sierracatalina.com/context-layer/specification) → [implementation](https://sierracatalina.com/context-layer/implementation) → [code](https://sierracatalina.com/context-layer/code) (v0.2 contracts, encrypted local vault, four-state policy, scoped bundles, anchored receipts, a files adapter, a local-agent consumer) → [demo](https://sierracatalina.com/context-layer/demo). Its stated boundary: it does not claim production key custody or a portable signing suite.
41
+
42
+ **How it pairs with this repo.** Three of the interview's answers are Context Layer decisions in miniature:
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
+ - **Off limits** is the Layer's vault stage: originals that never enter a bundle.
45
+ - **Always ask before** is the Layer's decide stage: allow, reduce, approve or deny by action and recipient.
46
+ Level 4 (several agents) is where it earns its keep: 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
+
48
+ ---
49
+
50
+ ## Reaching the other note tools
51
+
52
+ | `notes_tool` answer | How an AI reaches it | Write posture rendered into the onboarding file |
53
+ |---|---|---|
54
+ | `obsidian` | obsidian-tc (above) when `obsidian_tc: yes`, else the vault folder on disk | your write policy, enforced by obsidian-tc's ACL when configured |
55
+ | `logseq` / `folder` | the folder on disk | your write policy, under each folder's README |
56
+ | `notion` | Notion's own MCP connector | writes only into the pages or databases you name; the AI proposes new top-level pages, never creates them unasked |
57
+ | `google-docs` | the Google Drive / Docs connector | the AI drafts into a doc named for the topic and never edits a shared doc's existing text without being asked |
58
+ | `apple-notes` | a separately installed local Apple Notes MCP (no AI app ships one built in) | read, and create new notes; never edit or delete existing notes |
59
+ | `onenote` / `evernote` | no first-class agent door today | treated as a read-only source; the AI writes to a local fallback folder (`notes/`) and tells you what to paste back |
60
+ | `other` | you name the tool and the location | the AI asks before its first write there and uses the local fallback folder (`notes/`) until then |
61
+
62
+ None of these connectors ship in this repo. The onboarding file names the door; you connect it in your AI's own settings, where the app offers one. For cloud tools the onboarding file also says, explicitly, that none of these notes are local files, so the AI does not invent a folder named after your workspace.
@@ -0,0 +1,66 @@
1
+ # Where each rendered file goes
2
+
3
+ The renderer writes one file per AI. This page says where each AI reads it, and what to do when you change an answer. Product menus move; the file names and the mechanism do not. Where a menu path is given it is as of this writing; if it has moved, search the product's settings for "custom instructions" or "project instructions".
4
+
5
+ | Rendered file | Who reads it | How it is read |
6
+ |---|---|---|
7
+ | `CLAUDE.md` | Claude Code | Automatically, from the folder you run it in (and from `~/.claude/CLAUDE.md` for every folder). Nothing to paste. |
8
+ | `AGENT_ONBOARDING.md` | any AI | Named as the second thing to read in `CLAUDE.md` and `AGENTS.md`. Paste it wherever the AI has no file access (below). |
9
+ | `AGENTS.md` | Codex CLI, Cursor, and other agents that adopted the AGENTS.md convention | Automatically, from the repository root. Nothing to paste. |
10
+ | `GEMINI.md` | Gemini CLI | Automatically, from the folder. Nothing to paste. |
11
+ | `chatgpt-custom-instructions.md` | ChatGPT | Two boxes to paste, below. |
12
+ | `system-prompt.md` | anything with a system-prompt field, shared bots, API calls | Paste as the system prompt. Universal rules only, no profile, safe to share. |
13
+
14
+ ---
15
+
16
+ ## Claude Code
17
+
18
+ 1. Run the installer in the project folder. `CLAUDE.md` and `AGENT_ONBOARDING.md` land there and Claude Code reads `CLAUDE.md` on every session.
19
+ 2. For rules that must win at the moment of decision, register the session-start hook: see [`hooks/README.md`](../hooks/README.md). It prints the inject-marked rules and your onboarding block into context before your first message.
20
+ 3. For your output style specifically, Claude Code has a custom output-style slot that lives in the system prompt every turn (`/output-style`). Put the "How to talk" and "Output shape" lines from `AGENT_ONBOARDING.md` there; a style in the system prompt is re-sent every turn, so it does not fade the way a file read once does. Tier 1 in [tiers.md](tiers.md).
21
+
22
+ ## claude.ai (web and desktop apps), Claude Projects
23
+
24
+ The apps do not read files from your disk. Paste:
25
+ 1. The body of `USER.md` into the Project's instructions field (Projects → your project → Set project instructions), followed by the body of `AGENT_ONBOARDING.md`.
26
+ 2. For a chat outside any Project, the account-level custom instructions field (Settings → Profile) takes the same text.
27
+
28
+ Re-paste after every re-render. `--check` verifies the files on disk; it cannot see the pasted copy.
29
+
30
+ ## ChatGPT
31
+
32
+ Settings → Personalization → Custom instructions. Two boxes. The renderer writes them three ways: `chatgpt-box1.txt` and `chatgpt-box2.txt` are the plain paste files (open, select all, paste), and `chatgpt-custom-instructions.md` carries the same two texts inside fences with their character counts:
33
+ 1. "What would you like ChatGPT to know about you?" ← Box 1 (your profile).
34
+ 2. "How would you like ChatGPT to respond?" ← Box 2 (universal rules and the ChatGPT binding).
35
+
36
+ Each box has a character limit (about 1,500 at the time of writing; the number lives in `render/targets.json`, not verified against the live product). With onboarding answers the render is built for that budget: Box 1 is the compact profile, Box 2 is the onboarding block (always-ask, off-limits, write policy, then style) followed by the `inject: true` rules only. Each box prints its count. If a box is still over, nothing is cut for you: it is written in full and flagged OVER BUDGET, and the lines are in order of consequence, so trim from the bottom. The rules that are not `inject: true` do not fit here by design; for those, make a ChatGPT Project and upload `AGENT_ONBOARDING.md` and `rules/` as project files.
37
+
38
+ ## Codex CLI
39
+
40
+ Reads `AGENTS.md` from the repository root automatically (and from parent folders and `~/.codex/AGENTS.md`, nearest wins). Run the installer at the repo root and there is nothing to paste. For an adversarial read of your own repo, the same file tells Codex how to talk to you.
41
+
42
+ ## Cursor
43
+
44
+ Reads `AGENTS.md` at the project root. Older setups use `.cursor/rules/`; if yours does, point one rule file at `AGENTS.md` rather than copying its text, so there is one owner.
45
+
46
+ ## Gemini CLI
47
+
48
+ Reads `GEMINI.md` from the folder (and parent folders). Run the installer with `--ai gemini` and there is nothing to paste.
49
+
50
+ ## Anything else
51
+
52
+ Use `system-prompt.md`. It carries only the universal blocks: no profile, no personal blocks, no off-limits names. That is deliberate: a system prompt is often shared, logged, or sent to a vendor, and the profile is not for that.
53
+
54
+ ---
55
+
56
+ ## When you change an answer
57
+
58
+ 1. Re-run the installer with the new answers (`--answers` or the interview). It regenerates `AGENT_ONBOARDING.md` and every rendered block. `USER.md` is regenerated only if you never edited it; otherwise it is kept and the installer names the changed answers for you to carry over by hand (or delete `USER.md` and re-run). Editing `USER.md` or a rule by hand: `node render/render.cjs --dir .` at level 3.
59
+ 2. Files that are read automatically (`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`) are done.
60
+ 3. Files that were pasted (claude.ai, ChatGPT, any system prompt) must be pasted again. Nothing can detect a stale paste for you; put "re-paste after re-render" in your own checklist.
61
+
62
+ ## What not to do
63
+
64
+ - Do not edit inside the marker block of a rendered file; edit `USER.md`, `rules/`, or your answers, and re-render. The next render overwrites the block.
65
+ - Do not paste `AGENT_ONBOARDING.md` into a shared bot. It names your off-limits topics and your working habits. `system-prompt.md` is the shareable one.
66
+ - Do not keep a hand-edited copy of a rule in two places. One owner, everything else points to it. [tiers.md](tiers.md), tier 4.
package/docs/tiers.md ADDED
@@ -0,0 +1,89 @@
1
+ # The five tiers
2
+
3
+ Instructions to an AI live in five places. Each has one job and prevents one failure. Put a rule in the wrong tier and it either decays, drifts, or gets ignored. Put it in the right one and it holds.
4
+
5
+ Read bottom-up. Tier 1 is the most present, tier 5 the most durable.
6
+
7
+ A word on the stories below: each is one setup's experience of what held and what did not. They explain why the tiers are shaped this way. They are not measurements, and placing a rule in a tier puts it in front of the model; it does not make the model obey. Instruction precedence differs by host and model.
8
+
9
+ ---
10
+
11
+ ## Tier 1: style in the system prompt
12
+
13
+ **What.** How the AI writes back to you: length, structure, punctuation, what to lead with. Not what it knows. Not what it does.
14
+
15
+ **Where.** The one slot your AI keeps in front of it every single turn. Claude Code calls it an output style. Chat apps call it custom instructions or a system prompt. If the app has no slot, the top of the home file is the next best place.
16
+
17
+ **Prevents.** Decay. A style stated once in a message fades after twenty turns. A style in the system prompt is re-sent on turn two hundred exactly as on turn one, so it cannot fade for lack of presence (it can still be ignored).
18
+
19
+ **Story.** A user corrected the same formatting habit, in words, more than thirty times across two months. Every correction held for a session and vanished. Moving the same sentence into the system-prompt slot ended it in a day. The rule had not changed. Its tier had.
20
+
21
+ ---
22
+
23
+ ## Tier 2: one always-loaded home file
24
+
25
+ **What.** `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, whatever your AI reads first. It says who you are (by pointing at `USER.md`), where your notes live, and which document owns which rule.
26
+
27
+ **Where.** The root of the project or folder the AI works in. Some AIs also read a global one in your home directory.
28
+
29
+ **Prevents.** The AI not knowing where anything is. Without a home file it re-derives your setup every session, wrongly.
30
+
31
+ **Story.** A home file grew to 40 KB of rules, restated from documents that lived elsewhere. Three of those restatements went stale within a month and the AI followed the stale copies with full confidence, because the home file is the first thing it reads. The fix was not a shorter file. It was a file of pointers: one line per rule, naming the document that owns it.
32
+
33
+ **Rule inside the tier.** The home file carries pointers, or a generated block, never a hand-maintained copy. A `[hook: name]` or `[owner: path]` tag on a one-line rule tells the AI where the full text lives. The block between the render markers is the one exception: it is a generated snapshot of `USER.md` and `rules/`, regenerated by `render/render.cjs` and compared by `--check`, so it has one owner and a drift detector. What this tier forbids is a second copy you maintain by hand.
34
+
35
+ ---
36
+
37
+ ## Tier 3: session-start injection
38
+
39
+ **What.** The handful of rules that must win at the moment of decision, injected in full at the start of every session. Not pointers. Full text.
40
+
41
+ **Where.** A session-start hook (Claude Code has these). For AIs without hooks, a block you paste at the top of the first message, or a saved prompt that starts every session.
42
+
43
+ **Prevents.** A tool's own instructions beating yours by default. Installed skills, plugins and tool descriptions each say "use me." A rule that says "use the other one first" loses that argument if it is only stated in a document the AI may or may not have opened. Injection makes sure your rule is at least in the room; it does not settle the argument on every host.
44
+
45
+ **Story.** Thirty-two installed skill packages for one crawling service each instructed the AI to use that service. The user's rule said a different, free tool was the default. The rule lived in the home file as a pointer. The AI picked the paid service every time, because at the moment of choice thirty-two voices said one thing and one pointer said another. Injecting the full routing rule at session start fixed it. Prose in a document does not win that argument; a contract present in context does.
46
+
47
+ **Rule inside the tier.** Injected contracts are few, and each carries its story. Ten is a lot. Every one costs tokens every session.
48
+
49
+ ---
50
+
51
+ ## Tier 4: one owning document per rule
52
+
53
+ **What.** Every rule has exactly one document that owns it. Everything else points there. Canon is read on demand, when the task needs it.
54
+
55
+ **Where.** Your notes folder. A `protocols/` or `rules/` directory. Each file names what it owns.
56
+
57
+ **Prevents.** Drift. A rule hand-stated in five places drifts in five places, and the five copies disagree silently until one of them is quoted back at you as your own ruling.
58
+
59
+ **Story.** A routing rule was corrected in its owning document. Four days later, four other surfaces still carried the old version, and the AI quoted one of them to the user as if her own decision had been the reverse. A drift detector had been green the whole time, because it checked that each surface matched the rule as last recorded, not that each surface matched the owner. Restating canon is how it drifts. Link down instead.
60
+
61
+ **Rule inside the tier.** If you find yourself pasting a rule's text into a second file by hand, stop and write a pointer, or let the renderer generate the copy and check it. Pasted copies you cannot check (a chat app's instruction box) are re-pasted after every change; nothing can detect a stale paste for you.
62
+
63
+ ---
64
+
65
+ ## Tier 5: memory with a status on every fact
66
+
67
+ **What.** What the AI remembers about you across sessions: preferences, corrections, project facts. Each fact carries a status: `asserted` if you said it, `derived` if the AI inferred it.
68
+
69
+ **Where.** A memory directory the AI writes to, one fact per file, with a small always-loaded index of standing rules and a larger on-demand index of everything else.
70
+
71
+ **Prevents.** The AI treating its own guess as your ruling. An inference written down without a status reads, next session, like something you decided.
72
+
73
+ **Story.** A memory file said the user preferred a certain tool. The user had never said so; an earlier session had inferred it from one choice. Three sessions built on it. The status field exists so the next session can tell the difference between "she said" and "I guessed," and so a contradicted fact gets marked `superseded` with a pointer rather than silently overwritten.
74
+
75
+ **Rule inside the tier.** The always-loaded index stays small: standing rules only. A project detail or a tool gotcha lives in the on-demand index. The core file was 18 KB once, and every line loaded whether or not it mattered.
76
+
77
+ ---
78
+
79
+ ## How the tiers relate
80
+
81
+ ```
82
+ tier 1 style every turn system prompt slot
83
+ tier 2 home file every session pointers to owners
84
+ tier 3 contracts every session full text, few, with stories
85
+ tier 4 canon on demand one owner per rule
86
+ tier 5 memory across sessions facts with a status
87
+ ```
88
+
89
+ A rule moves DOWN the tiers as it proves durable: a correction becomes a memory fact, a memory fact that keeps mattering becomes a rule in canon, a canon rule that keeps losing arguments becomes an injected contract. Nothing starts at tier 3.
@@ -0,0 +1,52 @@
1
+ {
2
+ "targets": [
3
+ "claude",
4
+ "agents",
5
+ "onboarding"
6
+ ],
7
+ "level": 3,
8
+ "onboarding": {
9
+ "name": "Mara",
10
+ "pronouns": "she/her",
11
+ "work": "freelance illustrator: book covers and editorial work",
12
+ "focus": "a 12-cover fantasy series due in November, and a print shop",
13
+ "tone": "direct",
14
+ "length": "short",
15
+ "mistakes": "one-line",
16
+ "unsure": "ask-when-it-changes-the-build",
17
+ "lead_with": "verdict",
18
+ "structure": "tables-when-comparing",
19
+ "evidence": "inline",
20
+ "never": [
21
+ "em dashes",
22
+ "start a reply with Great question",
23
+ "client names outside their folder"
24
+ ],
25
+ "read_first": [
26
+ "USER.md",
27
+ "AGENT_ONBOARDING.md",
28
+ "notes/README.md",
29
+ "rules/",
30
+ "notes/decisions.md"
31
+ ],
32
+ "notes_path": "notes",
33
+ "tracker": "a kanban board the AI reads and I move",
34
+ "write_policy": "notes-freely",
35
+ "file_naming": "kebab-case",
36
+ "signature": "yes",
37
+ "off_limits": [
38
+ "health notes",
39
+ "the journal folder",
40
+ "signed contracts"
41
+ ],
42
+ "always_ask": [
43
+ "delete",
44
+ "publish",
45
+ "send",
46
+ "spend",
47
+ "standing-rules"
48
+ ],
49
+ "notes_tool": "obsidian",
50
+ "obsidian_tc": "yes"
51
+ }
52
+ }