agent-personalizer 0.7.2 → 0.8.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.
- package/CHANGELOG.md +20 -1
- package/README.md +23 -14
- package/SECURITY.md +3 -1
- package/bin/agent-personalizer.js +79 -105
- package/bin/install-plan.cjs +3 -0
- package/bin/known-hashes.json +54 -0
- package/bin/learn.cjs +185 -0
- package/bin/sessions.cjs +392 -0
- package/bin/uninstall.cjs +30 -4
- package/check/gate.cjs +4 -3
- package/docs/README.md +2 -1
- package/docs/companions.md +2 -2
- package/docs/guarantees.md +13 -3
- package/docs/install.md +28 -18
- package/docs/learning.md +99 -0
- package/docs/paste-guide.md +4 -4
- package/docs/tiers.md +4 -4
- package/examples/freelance-illustrator/.agent-personalizer.json +3 -3
- package/examples/freelance-illustrator/AGENTS.md +67 -3
- package/examples/freelance-illustrator/AGENT_ONBOARDING.md +4 -7
- package/examples/freelance-illustrator/CLAUDE.md +67 -3
- package/examples/freelance-illustrator/LEARNED.md +14 -0
- package/examples/freelance-illustrator/USER.md +6 -1
- package/examples/freelance-illustrator/rules/00-read-the-profile-first.md +1 -1
- package/examples/freelance-illustrator/rules/65-ask-before-it-repeats.md +18 -0
- package/examples/freelance-illustrator/rules/70-their-words-point-at-the-thing.md +15 -0
- package/examples/freelance-illustrator/rules/80-symptoms-are-not-causes.md +15 -0
- package/examples/freelance-illustrator/rules/90-surface-what-they-cant-see.md +15 -0
- package/examples/freelance-illustrator/rules/README.md +59 -0
- package/examples/lab-technician/.agent-personalizer.json +38 -0
- package/examples/lab-technician/AGENTS.md +243 -0
- package/examples/lab-technician/AGENT_ONBOARDING.md +64 -0
- package/examples/lab-technician/CLAUDE.md +247 -0
- package/examples/lab-technician/LEARNED.md +14 -0
- package/examples/lab-technician/USER.md +53 -0
- package/examples/lab-technician/notes/README.md +26 -0
- package/examples/lab-technician/notes/decisions.md +4 -0
- package/examples/lab-technician/notes/inbox/2026-10-06-observation-table.md +3 -0
- package/examples/lab-technician/notes/inbox/README.md +7 -0
- package/examples/lab-technician/notes/sessions/2026-W41.md +7 -0
- package/examples/lab-technician/rules/00-read-the-profile-first.md +24 -0
- package/examples/lab-technician/rules/10-evidence-before-assertion.md +24 -0
- package/examples/lab-technician/rules/20-one-owner-per-rule.md +24 -0
- package/examples/lab-technician/rules/30-folder-index-is-part-of-the-change.md +26 -0
- package/examples/lab-technician/rules/40-sign-every-edit.md +25 -0
- package/examples/lab-technician/rules/50-output-style.md +21 -0
- package/examples/lab-technician/rules/60-act-or-ask.md +30 -0
- package/examples/lab-technician/rules/65-ask-before-it-repeats.md +18 -0
- package/examples/lab-technician/rules/70-their-words-point-at-the-thing.md +15 -0
- package/examples/lab-technician/rules/80-symptoms-are-not-causes.md +15 -0
- package/examples/lab-technician/rules/90-surface-what-they-cant-see.md +15 -0
- package/examples/lab-technician/rules/README.md +59 -0
- package/examples/product-designer/.agent-personalizer.json +38 -0
- package/examples/product-designer/AGENTS.md +243 -0
- package/examples/product-designer/AGENT_ONBOARDING.md +63 -0
- package/examples/product-designer/CLAUDE.md +247 -0
- package/examples/product-designer/LEARNED.md +14 -0
- package/examples/product-designer/USER.md +53 -0
- package/examples/product-designer/notes/README.md +26 -0
- package/examples/product-designer/notes/decisions.md +4 -0
- package/examples/product-designer/notes/inbox/2026-10-06-cancellation-wording.md +8 -0
- package/examples/product-designer/notes/inbox/README.md +7 -0
- package/examples/product-designer/notes/sessions/2026-W41.md +7 -0
- package/examples/product-designer/rules/00-read-the-profile-first.md +24 -0
- package/examples/product-designer/rules/10-evidence-before-assertion.md +24 -0
- package/examples/product-designer/rules/20-one-owner-per-rule.md +24 -0
- package/examples/product-designer/rules/30-folder-index-is-part-of-the-change.md +26 -0
- package/examples/product-designer/rules/40-sign-every-edit.md +25 -0
- package/examples/product-designer/rules/50-output-style.md +21 -0
- package/examples/product-designer/rules/60-act-or-ask.md +30 -0
- package/examples/product-designer/rules/65-ask-before-it-repeats.md +18 -0
- package/examples/product-designer/rules/70-their-words-point-at-the-thing.md +15 -0
- package/examples/product-designer/rules/80-symptoms-are-not-causes.md +15 -0
- package/examples/product-designer/rules/90-surface-what-they-cant-see.md +15 -0
- package/examples/product-designer/rules/README.md +59 -0
- package/hooks/README.md +1 -1
- package/llms.txt +6 -2
- package/package.json +2 -2
- package/render/onboarding.cjs +111 -45
- package/render/render.cjs +60 -12
- package/rules/00-read-the-profile-first.md +1 -1
- package/rules/65-ask-before-it-repeats.md +18 -0
- package/rules/70-their-words-point-at-the-thing.md +15 -0
- package/rules/80-symptoms-are-not-causes.md +15 -0
- package/rules/90-surface-what-they-cant-see.md +15 -0
- package/rules/README.md +4 -0
- package/templates/LEARNED.md +11 -0
package/bin/sessions.cjs
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
|
|
7
|
+
const MAX_LINE = 8 * 1024 * 1024;
|
|
8
|
+
const MAX_FILE = 64 * 1024 * 1024;
|
|
9
|
+
const SOURCES = new Set(['claude-code', 'codex', 'gemini-cli']);
|
|
10
|
+
const CONTEXT_HEADERS = ['# AGENTS.md instructions', '# Files mentioned by the user', '# Response annotations', '# Browser comments'];
|
|
11
|
+
|
|
12
|
+
function bump(state, reason) {
|
|
13
|
+
state.skipped[reason] = (state.skipped[reason] || 0) + 1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Both sides are compared in NFC and lower case: macOS often stores accents decomposed (NFD),
|
|
17
|
+
which would otherwise let a listed name through. Audit 0.8.0 F2. */
|
|
18
|
+
const fold = (text) => String(text).normalize('NFC').toLowerCase();
|
|
19
|
+
function privateMatch(text, terms) {
|
|
20
|
+
const lower = fold(text);
|
|
21
|
+
return terms.some(term => lower.includes(term));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function cutContextBlocks(text) {
|
|
25
|
+
const tags = /<(\/?)(system-reminder|pasted_content)\b[^>]*>/gi;
|
|
26
|
+
const stack = [];
|
|
27
|
+
let output = '', position = 0, match;
|
|
28
|
+
while ((match = tags.exec(text))) {
|
|
29
|
+
if (!stack.length) output += text.slice(position, match.index);
|
|
30
|
+
const name = match[2].toLowerCase();
|
|
31
|
+
if (match[1]) {
|
|
32
|
+
if (stack[stack.length - 1] === name) stack.pop();
|
|
33
|
+
} else if (!/\/\s*>$/.test(match[0])) stack.push(name);
|
|
34
|
+
position = tags.lastIndex;
|
|
35
|
+
}
|
|
36
|
+
// An unfinished block stays excluded rather than exposing a partial paste.
|
|
37
|
+
if (!stack.length) output += text.slice(position);
|
|
38
|
+
return output;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function typedText(items, state) {
|
|
42
|
+
if (!items.length) { bump(state, 'non_typed'); return null; }
|
|
43
|
+
// A private match drops the whole message, including its other text items.
|
|
44
|
+
if (privateMatch(items.join('\n'), state.privateTerms) || privateMatch(items.join(''), state.privateTerms)) { bump(state, 'private_match'); return null; }
|
|
45
|
+
const kept = [];
|
|
46
|
+
for (const item of items) {
|
|
47
|
+
let text = item.trim();
|
|
48
|
+
if (/^<[A-Za-z][A-Za-z0-9_:-]*/.test(text) || CONTEXT_HEADERS.some(prefix => text.startsWith(prefix))) {
|
|
49
|
+
bump(state, 'automation_text');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
text = cutContextBlocks(text).trim();
|
|
53
|
+
if (text) kept.push(text);
|
|
54
|
+
}
|
|
55
|
+
const text = kept.join('\n');
|
|
56
|
+
if (!text) { bump(state, 'empty_message'); return null; }
|
|
57
|
+
if (text.length > 2000) { bump(state, 'long_message'); return null; }
|
|
58
|
+
return text;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function textItems(content, type) {
|
|
62
|
+
if (typeof content === 'string') return [content];
|
|
63
|
+
if (!Array.isArray(content)) return [];
|
|
64
|
+
return content.filter(item => item && typeof item === 'object' && item.type === type && typeof item.text === 'string').map(item => item.text);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function statPath(file, kind, state, count = false) {
|
|
68
|
+
if (count) state.filesChecked += 1;
|
|
69
|
+
try {
|
|
70
|
+
const stat = await fs.promises.lstat(file);
|
|
71
|
+
if (stat.isSymbolicLink()) { bump(state, 'symlink'); return null; }
|
|
72
|
+
if ((kind === 'directory' && !stat.isDirectory()) || (kind === 'file' && !stat.isFile())) {
|
|
73
|
+
bump(state, 'non_regular');
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return stat;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error.code !== 'ENOENT') bump(state, 'unreadable');
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function children(dir, state) {
|
|
84
|
+
if (!await statPath(dir, 'directory', state)) return [];
|
|
85
|
+
try { return (await fs.promises.readdir(dir)).sort(); }
|
|
86
|
+
catch { bump(state, 'unreadable'); return []; }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function candidate(file, source, project, format, state) {
|
|
90
|
+
const stat = await statPath(file, 'file', state, true);
|
|
91
|
+
if (stat) state.candidates.push({ file, source, project, format, mtimeMs: stat.mtimeMs });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function discover(home, sources, state) {
|
|
95
|
+
if (!await statPath(home, 'directory', state)) return;
|
|
96
|
+
if (sources.has('claude-code')) {
|
|
97
|
+
const app = path.join(home, '.claude');
|
|
98
|
+
if (await statPath(app, 'directory', state)) {
|
|
99
|
+
const projects = path.join(app, 'projects');
|
|
100
|
+
for (const project of await children(projects, state)) {
|
|
101
|
+
const dir = path.join(projects, project);
|
|
102
|
+
for (const name of await children(dir, state)) {
|
|
103
|
+
if (name.endsWith('.jsonl')) await candidate(path.join(dir, name), 'claude-code', project, 'claude', state);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (sources.has('codex')) {
|
|
109
|
+
const app = path.join(home, '.codex');
|
|
110
|
+
if (await statPath(app, 'directory', state)) {
|
|
111
|
+
async function walk(dir) {
|
|
112
|
+
for (const name of await children(dir, state)) {
|
|
113
|
+
const file = path.join(dir, name);
|
|
114
|
+
const stat = await statPath(file, null, state);
|
|
115
|
+
if (!stat) continue;
|
|
116
|
+
if (stat.isDirectory()) await walk(file);
|
|
117
|
+
else if (name.startsWith('rollout-') && name.endsWith('.jsonl')) await candidate(file, 'codex', path.basename(dir), 'codex', state);
|
|
118
|
+
else if (!stat.isFile()) bump(state, 'non_regular');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
await walk(path.join(app, 'sessions'));
|
|
122
|
+
const memories = path.join(app, 'memories');
|
|
123
|
+
for (const name of await children(memories, state)) {
|
|
124
|
+
if (!name.endsWith('.md')) continue;
|
|
125
|
+
const file = path.join(memories, name);
|
|
126
|
+
const stat = await statPath(file, 'file', state, true);
|
|
127
|
+
if (stat) state.memoryFiles.push({ file, mtimeMs: stat.mtimeMs });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (sources.has('gemini-cli')) {
|
|
132
|
+
const app = path.join(home, '.gemini');
|
|
133
|
+
if (await statPath(app, 'directory', state)) {
|
|
134
|
+
const tmp = path.join(app, 'tmp');
|
|
135
|
+
for (const project of await children(tmp, state)) {
|
|
136
|
+
const dir = path.join(tmp, project);
|
|
137
|
+
if (!await statPath(dir, 'directory', state)) continue;
|
|
138
|
+
for (const name of await children(path.join(dir, 'chats'), state)) {
|
|
139
|
+
if (name.startsWith('session-') && name.endsWith('.jsonl')) await candidate(path.join(dir, 'chats', name), 'gemini-cli', project, 'gemini', state);
|
|
140
|
+
}
|
|
141
|
+
const logs = path.join(dir, 'logs.json');
|
|
142
|
+
try {
|
|
143
|
+
await fs.promises.lstat(logs);
|
|
144
|
+
await candidate(logs, 'gemini-cli', project, 'gemini-logs', state);
|
|
145
|
+
} catch (error) { if (error.code !== 'ENOENT') bump(state, 'unreadable'); }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function safeOpen(file, state) {
|
|
152
|
+
// Recheck each path within HOME immediately before opening to catch replaced links.
|
|
153
|
+
const relative = path.relative(state.home, file);
|
|
154
|
+
if (relative.startsWith(`..${path.sep}`) || relative === '..' || path.isAbsolute(relative)) return null;
|
|
155
|
+
let current = state.home;
|
|
156
|
+
if (!await statPath(current, 'directory', state)) return null;
|
|
157
|
+
const parts = relative.split(path.sep);
|
|
158
|
+
for (const name of parts.slice(0, -1)) {
|
|
159
|
+
current = path.join(current, name);
|
|
160
|
+
if (!await statPath(current, 'directory', state)) return null;
|
|
161
|
+
}
|
|
162
|
+
const before = await statPath(file, 'file', state);
|
|
163
|
+
if (!before) return null;
|
|
164
|
+
try {
|
|
165
|
+
const handle = await fs.promises.open(file, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW || 0));
|
|
166
|
+
const after = await handle.stat();
|
|
167
|
+
if (!after.isFile() || before.ino !== after.ino || before.dev !== after.dev) {
|
|
168
|
+
await handle.close();
|
|
169
|
+
bump(state, 'non_regular');
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
state.filesRead.push(file);
|
|
173
|
+
if (after.size > MAX_FILE) bump(state, 'file_limit');
|
|
174
|
+
return handle;
|
|
175
|
+
} catch { bump(state, 'unreadable'); return null; }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function scanLines(file, state, onLine) {
|
|
179
|
+
const handle = await safeOpen(file, state);
|
|
180
|
+
if (!handle) return false;
|
|
181
|
+
let fragments = [], length = 0, oversize = false;
|
|
182
|
+
function line() {
|
|
183
|
+
if (!oversize && length) onLine(Buffer.concat(fragments, length).toString('utf8'));
|
|
184
|
+
fragments = []; length = 0; oversize = false;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const stream = handle.createReadStream({ autoClose: false, highWaterMark: 64 * 1024, start: 0, end: MAX_FILE - 1 });
|
|
188
|
+
for await (const chunk of stream) {
|
|
189
|
+
let start = 0;
|
|
190
|
+
for (let end = chunk.indexOf(10); ; end = chunk.indexOf(10, start)) {
|
|
191
|
+
const stop = end === -1 ? chunk.length : end;
|
|
192
|
+
if (!oversize && stop > start) {
|
|
193
|
+
length += stop - start;
|
|
194
|
+
if (length > MAX_LINE) { oversize = true; fragments = []; bump(state, 'oversize_line'); }
|
|
195
|
+
else fragments.push(chunk.subarray(start, stop));
|
|
196
|
+
}
|
|
197
|
+
if (end === -1) break;
|
|
198
|
+
line();
|
|
199
|
+
start = end + 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// A capped file's partial final record is not a complete JSON line.
|
|
203
|
+
const stat = await handle.stat();
|
|
204
|
+
if (stat.size <= MAX_FILE) line();
|
|
205
|
+
return true;
|
|
206
|
+
} catch { bump(state, 'unreadable'); return false; }
|
|
207
|
+
finally { await handle.close(); }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function parsedLine(line, state) {
|
|
211
|
+
try {
|
|
212
|
+
const record = JSON.parse(line);
|
|
213
|
+
if (!record || Array.isArray(record) || typeof record !== 'object') { bump(state, 'unknown_format'); return null; }
|
|
214
|
+
return record;
|
|
215
|
+
} catch { bump(state, 'malformed_line'); return null; }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function baseSession(file) {
|
|
219
|
+
return { source: file.source, date: new Date(file.mtimeMs).toISOString(), project: file.project, sessionId: path.basename(file.file), file: file.file, mtimeMs: file.mtimeMs, messages: [] };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async function readClaude(file, state) {
|
|
223
|
+
const session = baseSession(file);
|
|
224
|
+
let known = false, automation = false;
|
|
225
|
+
const ok = await scanLines(file.file, state, line => {
|
|
226
|
+
const record = parsedLine(line, state);
|
|
227
|
+
if (!record) return;
|
|
228
|
+
if (typeof record.entrypoint === 'string' && record.entrypoint.startsWith('sdk')) automation = true;
|
|
229
|
+
if (record.type !== 'user') return;
|
|
230
|
+
known = true;
|
|
231
|
+
if (record.isMeta || record.isSidechain || record.isCompactSummary || record.isVisibleInTranscriptOnly) { bump(state, 'non_typed'); return; }
|
|
232
|
+
if (typeof record.sessionId === 'string') session.sessionId = record.sessionId;
|
|
233
|
+
const text = typedText(textItems(record.message && record.message.content, 'text'), state);
|
|
234
|
+
if (text) session.messages.push(text);
|
|
235
|
+
});
|
|
236
|
+
if (!ok) return [];
|
|
237
|
+
if (automation) { bump(state, 'automation_session'); return []; }
|
|
238
|
+
if (!known) bump(state, 'unknown_format');
|
|
239
|
+
return session.messages.length ? [session] : [];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function readCodex(file, state) {
|
|
243
|
+
const session = baseSession(file);
|
|
244
|
+
let known = false, automation = false;
|
|
245
|
+
const ok = await scanLines(file.file, state, line => {
|
|
246
|
+
const record = parsedLine(line, state);
|
|
247
|
+
if (!record) return;
|
|
248
|
+
if (record.type === 'session_meta' && record.payload && typeof record.payload === 'object') {
|
|
249
|
+
known = true;
|
|
250
|
+
const meta = record.payload;
|
|
251
|
+
if (meta.source === 'exec' || (meta.source && typeof meta.source === 'object' && Object.prototype.hasOwnProperty.call(meta.source, 'subagent'))) automation = true;
|
|
252
|
+
if (typeof meta.id === 'string') session.sessionId = meta.id;
|
|
253
|
+
if (typeof meta.cwd === 'string') session.project = path.basename(meta.cwd);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (record.type !== 'response_item' || !record.payload || record.payload.type !== 'message' || record.payload.role !== 'user') return;
|
|
257
|
+
known = true;
|
|
258
|
+
const text = typedText(textItems(record.payload.content, 'input_text'), state);
|
|
259
|
+
if (text) session.messages.push(text);
|
|
260
|
+
});
|
|
261
|
+
if (!ok) return [];
|
|
262
|
+
if (automation) { bump(state, 'automation_session'); return []; }
|
|
263
|
+
if (!known) bump(state, 'unknown_format');
|
|
264
|
+
return session.messages.length ? [session] : [];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function readGemini(file, state) {
|
|
268
|
+
const session = baseSession(file);
|
|
269
|
+
let known = false, messages = [];
|
|
270
|
+
const ok = await scanLines(file.file, state, line => {
|
|
271
|
+
const record = parsedLine(line, state);
|
|
272
|
+
if (!record) return;
|
|
273
|
+
if (typeof record.sessionId === 'string') { session.sessionId = record.sessionId; known = true; }
|
|
274
|
+
if (record.$set && Object.prototype.hasOwnProperty.call(record.$set, 'messages')) {
|
|
275
|
+
if (Array.isArray(record.$set.messages)) { messages = record.$set.messages; known = true; }
|
|
276
|
+
else bump(state, 'unknown_format');
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
if (!ok) return [];
|
|
280
|
+
for (const message of messages) {
|
|
281
|
+
if (!message || message.type !== 'user') continue;
|
|
282
|
+
const items = Array.isArray(message.content) ? message.content.filter(item => item && typeof item.text === 'string' && (!item.type || item.type === 'text')).map(item => item.text) : [];
|
|
283
|
+
const text = typedText(items, state);
|
|
284
|
+
if (text) session.messages.push(text);
|
|
285
|
+
}
|
|
286
|
+
if (!known) bump(state, 'unknown_format');
|
|
287
|
+
return session.messages.length ? [session] : [];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function readGeminiLogs(file, state) {
|
|
291
|
+
const grouped = new Map();
|
|
292
|
+
// Old logs are JSON arrays. Frame one entry at a time instead of buffering the array.
|
|
293
|
+
let entry = '', entryBytes = 0, depth = 0, quoted = false, escaped = false, oversize = false, started = false, finished = false, invalid = false;
|
|
294
|
+
function accept() {
|
|
295
|
+
if (oversize) { bump(state, 'oversize_line'); return; }
|
|
296
|
+
const record = parsedLine(entry, state);
|
|
297
|
+
if (!record || record.type !== 'user') return;
|
|
298
|
+
if (typeof record.sessionId !== 'string' || typeof record.message !== 'string') { bump(state, 'unknown_format'); return; }
|
|
299
|
+
const text = typedText([record.message], state);
|
|
300
|
+
if (!text) return;
|
|
301
|
+
if (!grouped.has(record.sessionId)) {
|
|
302
|
+
const session = baseSession(file);
|
|
303
|
+
session.sessionId = record.sessionId;
|
|
304
|
+
grouped.set(record.sessionId, session);
|
|
305
|
+
}
|
|
306
|
+
grouped.get(record.sessionId).messages.push(text);
|
|
307
|
+
}
|
|
308
|
+
const ok = await scanLines(file.file, state, line => {
|
|
309
|
+
for (const character of `${line}\n`) {
|
|
310
|
+
if (!started) {
|
|
311
|
+
if (/\s/.test(character)) continue;
|
|
312
|
+
if (character !== '[') { invalid = true; return; }
|
|
313
|
+
started = true;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (invalid) return;
|
|
317
|
+
if (!depth) {
|
|
318
|
+
if (/\s/.test(character) || character === ',') continue;
|
|
319
|
+
if (character === ']') { finished = true; continue; }
|
|
320
|
+
if (finished || character !== '{') { invalid = true; return; }
|
|
321
|
+
depth = 1; entry = '{'; entryBytes = 1; quoted = false; escaped = false; oversize = false;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (!oversize) {
|
|
325
|
+
entryBytes += Buffer.byteLength(character, 'utf8');
|
|
326
|
+
entry += character;
|
|
327
|
+
if (entryBytes > MAX_LINE) { oversize = true; entry = ''; }
|
|
328
|
+
}
|
|
329
|
+
if (quoted) {
|
|
330
|
+
if (escaped) escaped = false;
|
|
331
|
+
else if (character === '\\') escaped = true;
|
|
332
|
+
else if (character === '"') quoted = false;
|
|
333
|
+
} else if (character === '"') quoted = true;
|
|
334
|
+
else if (character === '{' || character === '[') depth += 1;
|
|
335
|
+
else if (character === '}' || character === ']') {
|
|
336
|
+
depth -= 1;
|
|
337
|
+
if (!depth) accept();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
if (!ok) return [];
|
|
342
|
+
if (!started || invalid) { bump(state, 'unknown_format'); return []; }
|
|
343
|
+
if (!finished || depth) bump(state, 'malformed_line');
|
|
344
|
+
return [...grouped.values()];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function readMemory(file, state) {
|
|
348
|
+
const lines = [];
|
|
349
|
+
if (!await scanLines(file.file, state, line => lines.push(line))) return null;
|
|
350
|
+
const text = lines.join('\n').trim();
|
|
351
|
+
if (!text) return null;
|
|
352
|
+
if (privateMatch(text, state.privateTerms)) { bump(state, 'private_match'); return null; }
|
|
353
|
+
return { file: file.file, text, date: new Date(file.mtimeMs).toISOString() };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async function readSessions({ home = os.homedir(), sources = [], limit = 20, privateTerms = [] } = {}) {
|
|
357
|
+
const selectedSources = new Set(Array.isArray(sources) ? sources.filter(source => SOURCES.has(source)) : []);
|
|
358
|
+
const maximum = Number.isInteger(limit) && limit >= 0 ? Math.min(limit, 20) : 20;
|
|
359
|
+
const state = {
|
|
360
|
+
home: path.resolve(home), candidates: [], memoryFiles: [], filesRead: [], filesChecked: 0, skipped: {},
|
|
361
|
+
privateTerms: Array.isArray(privateTerms) ? privateTerms.filter(term => typeof term === 'string' && term).map(fold) : []
|
|
362
|
+
};
|
|
363
|
+
await discover(state.home, selectedSources, state);
|
|
364
|
+
state.candidates.sort((a, b) => b.mtimeMs - a.mtimeMs || a.file.localeCompare(b.file));
|
|
365
|
+
const sessions = [], geminiSessions = new Map();
|
|
366
|
+
const readers = { claude: readClaude, codex: readCodex, gemini: readGemini, 'gemini-logs': readGeminiLogs };
|
|
367
|
+
for (const file of state.candidates) {
|
|
368
|
+
if (sessions.length >= maximum) break;
|
|
369
|
+
const found = await readers[file.format](file, state);
|
|
370
|
+
for (const session of found) {
|
|
371
|
+
if (session.source === 'gemini-cli' && geminiSessions.has(session.sessionId)) {
|
|
372
|
+
const existing = geminiSessions.get(session.sessionId);
|
|
373
|
+
for (const text of session.messages) {
|
|
374
|
+
if (existing.messages.includes(text)) bump(state, 'duplicate_message');
|
|
375
|
+
else existing.messages.push(text);
|
|
376
|
+
}
|
|
377
|
+
} else if (sessions.length < maximum) {
|
|
378
|
+
if (session.source === 'gemini-cli') geminiSessions.set(session.sessionId, session);
|
|
379
|
+
sessions.push(session);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const memories = [];
|
|
384
|
+
state.memoryFiles.sort((a, b) => b.mtimeMs - a.mtimeMs || a.file.localeCompare(b.file));
|
|
385
|
+
for (const file of state.memoryFiles) {
|
|
386
|
+
const memory = await readMemory(file, state);
|
|
387
|
+
if (memory) memories.push(memory);
|
|
388
|
+
}
|
|
389
|
+
return { sessions, memories, filesRead: state.filesRead, filesChecked: state.filesChecked, skipped: state.skipped };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
module.exports = { readSessions };
|
package/bin/uninstall.cjs
CHANGED
|
@@ -84,12 +84,34 @@ function run(dir, dry) {
|
|
|
84
84
|
const homeNames = new Set(['CLAUDE.md', 'AGENTS.md']);
|
|
85
85
|
const expected = new Map();
|
|
86
86
|
for (const p of recipe) {
|
|
87
|
-
if (homeNames.has(p.rel)) continue; //
|
|
87
|
+
if (homeNames.has(p.rel) || p.rel === 'LEARNED.md') continue; // entries always belong to the user
|
|
88
88
|
const bytes = p.src ? fs.readFileSync(p.src) : Buffer.from(p.text);
|
|
89
89
|
if (expected.has(p.rel) && !expected.get(p.rel).equals(bytes)) refuse(`${p.rel}: conflicting install paths; nothing was removed`);
|
|
90
90
|
expected.set(p.rel, bytes);
|
|
91
91
|
}
|
|
92
92
|
const tracked = new Set(modern ? [CONFIG, ...Object.keys(cfg.installed)] : [CONFIG, 'USER.md', ...recipe.map(p => p.rel)]);
|
|
93
|
+
tracked.delete('LEARNED.md');
|
|
94
|
+
// The digest is disposable private material, independent of installed-file hashes.
|
|
95
|
+
const digestFolder = '.agent-personalizer';
|
|
96
|
+
const digestFiles = [];
|
|
97
|
+
function collectDigest(rel) {
|
|
98
|
+
const full = probe(rel, 'dir');
|
|
99
|
+
if (!full) return;
|
|
100
|
+
const names = fs.readdirSync(full).sort();
|
|
101
|
+
observations.get(rel).children = names;
|
|
102
|
+
dirs.add(rel);
|
|
103
|
+
for (const name of names) {
|
|
104
|
+
const child = `${rel}/${name}`;
|
|
105
|
+
const info = fs.lstatSync(path.join(root, child));
|
|
106
|
+
if (info.isDirectory() && !info.isSymbolicLink()) collectDigest(child);
|
|
107
|
+
else { read(child); digestFiles.push(child); }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// The whole private folder is removed by uninstall. Validate even unexpected descendants
|
|
111
|
+
// before planning any deletion, so a symlink cannot turn this into a wider removal.
|
|
112
|
+
collectDigest(digestFolder);
|
|
113
|
+
for (const rel of digestFiles) tracked.add(rel);
|
|
114
|
+
const learned = read('LEARNED.md');
|
|
93
115
|
if (!modern) for (const key of cfg.targets) {
|
|
94
116
|
const target = TARGETS[key];
|
|
95
117
|
tracked.add(target.file);
|
|
@@ -115,6 +137,7 @@ function run(dir, dry) {
|
|
|
115
137
|
: renderer.renderedContents(root, cfg);
|
|
116
138
|
const plan = [];
|
|
117
139
|
const add = (rel, action, output, reason) => plan.push({ rel, action, output, reason });
|
|
140
|
+
for (const rel of digestFiles) if (read(rel)) add(rel, 'remove', null, 'private digest data');
|
|
118
141
|
for (const entry of rendered) {
|
|
119
142
|
const { rel, key, block, raw } = entry;
|
|
120
143
|
if (!tracked.has(rel)) continue;
|
|
@@ -171,7 +194,7 @@ function run(dir, dry) {
|
|
|
171
194
|
add('USER.md', userUnedited ? 'remove' : 'keep', null, 'edited');
|
|
172
195
|
}
|
|
173
196
|
for (const [rel, bytes] of expected) {
|
|
174
|
-
if (!tracked.has(rel)) continue;
|
|
197
|
+
if (!tracked.has(rel) || digestFiles.includes(rel)) continue;
|
|
175
198
|
const existing = read(rel);
|
|
176
199
|
if (!existing) continue;
|
|
177
200
|
const recorded = recordedHash(cfg, rel);
|
|
@@ -186,7 +209,7 @@ function run(dir, dry) {
|
|
|
186
209
|
// Current answers cannot erase history, and an unrecorded file is never adopted here.
|
|
187
210
|
const planned = new Set(plan.map(p => p.rel));
|
|
188
211
|
if (modern) for (const rel of Object.keys(cfg.installed)) {
|
|
189
|
-
if (planned.has(rel)) continue;
|
|
212
|
+
if (planned.has(rel) || rel === 'LEARNED.md') continue;
|
|
190
213
|
const bytes = read(rel);
|
|
191
214
|
if (bytes) add(rel, sha256(bytes) === recordedHash(cfg, rel) ? 'remove' : 'keep', null, 'edited');
|
|
192
215
|
}
|
|
@@ -207,7 +230,8 @@ function run(dir, dry) {
|
|
|
207
230
|
const full = probe(rel, saved.kind);
|
|
208
231
|
if (!full) refuse(`${rel} changed during preflight; nothing was removed`);
|
|
209
232
|
const now = fs.lstatSync(full);
|
|
210
|
-
if (now.dev !== saved.info.dev || now.ino !== saved.info.ino || now.mode !== saved.info.mode || (saved.bytes && !fs.readFileSync(full).equals(saved.bytes))
|
|
233
|
+
if (now.dev !== saved.info.dev || now.ino !== saved.info.ino || now.mode !== saved.info.mode || (saved.bytes && !fs.readFileSync(full).equals(saved.bytes))
|
|
234
|
+
|| (saved.children && JSON.stringify(fs.readdirSync(full).sort()) !== JSON.stringify(saved.children)))
|
|
211
235
|
refuse(`${rel} changed during preflight; nothing was removed`);
|
|
212
236
|
}
|
|
213
237
|
for (const rel of [...plan.filter(p => p.action !== 'keep').map(p => p.rel), ...emptyDirs, ...(removeConfig ? [CONFIG] : [])]) {
|
|
@@ -216,6 +240,7 @@ function run(dir, dry) {
|
|
|
216
240
|
}
|
|
217
241
|
const label = dry ? 'would ' : '';
|
|
218
242
|
if (dry) console.log('Dry run: preview only; no files changed.');
|
|
243
|
+
if (learned) console.log('kept LEARNED.md (your entries, edited or untouched)');
|
|
219
244
|
for (const p of plan) {
|
|
220
245
|
if (p.action === 'keep') { console.log(`kept ${p.rel} (${p.reason})`); continue; }
|
|
221
246
|
if (!dry) {
|
|
@@ -243,6 +268,7 @@ function run(dir, dry) {
|
|
|
243
268
|
}
|
|
244
269
|
console.log(`${label}remove ${rel}/ (empty)`);
|
|
245
270
|
}
|
|
271
|
+
if (!dry && probe(digestFolder, 'dir')) refuse(`${digestFolder}/ changed during removal; ${CONFIG} kept, review its remaining contents`);
|
|
246
272
|
// Config is always the final removal. A kept tracked path keeps the record for review.
|
|
247
273
|
if (removeConfig) {
|
|
248
274
|
if (!dry) {
|
package/check/gate.cjs
CHANGED
|
@@ -97,7 +97,7 @@ function refuseTrackedList(file) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function loadList(file) {
|
|
100
|
+
function loadList(file, { allowEmpty = false } = {}) {
|
|
101
101
|
let st = null;
|
|
102
102
|
try { st = fs.lstatSync(file); } catch (_) { st = null; }
|
|
103
103
|
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.`);
|
|
@@ -117,7 +117,7 @@ function loadList(file) {
|
|
|
117
117
|
allow.push(a);
|
|
118
118
|
} else terms.push(line);
|
|
119
119
|
});
|
|
120
|
-
if (!terms.length) die('forbidden list has no terms.');
|
|
120
|
+
if (!terms.length && !allowEmpty) die('forbidden list has no terms.');
|
|
121
121
|
return { terms, allow, real };
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -354,4 +354,5 @@ function main() {
|
|
|
354
354
|
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)`);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
|
|
357
|
+
module.exports = { loadList };
|
|
358
|
+
if (require.main === module) main();
|
package/docs/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# Documentation
|
|
2
2
|
|
|
3
|
-
agent-personalizer
|
|
3
|
+
agent-personalizer writes shared AI instructions and, with your consent, helps your AI learn from your recent sessions. Start with installation, then choose the guides for your setup.
|
|
4
4
|
|
|
5
5
|
| Guide | What it gives you |
|
|
6
6
|
|---|---|
|
|
7
7
|
| [Install and use](install.md) | Interactive setup, scripted answers, flags, updates and uninstall. |
|
|
8
|
+
| [Learning and privacy](learning.md) | Consent, session sources, evidence-backed questions, shared entries and forgetting the digest. |
|
|
8
9
|
| [Instruction tiers](tiers.md) | Where style, home files, session contracts, rule owners and memory belong. |
|
|
9
10
|
| [Paste guide](paste-guide.md) | Which file each AI reads and how to refresh pasted instructions. |
|
|
10
11
|
| [Companion tools](companions.md) | Notes connectors, access controls and approval mechanisms. |
|
package/docs/companions.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
| Your
|
|
5
|
+
| Your saved setting | What enforces it without a companion | With a companion |
|
|
6
6
|
|---|---|---|
|
|
7
7
|
| **Always ask before** delete / publish / send / spend | the AI remembering | obsidian-tc: destructive tools fail closed until a human confirms |
|
|
8
8
|
| **Off limits** folders | the AI remembering | obsidian-tc: folder ACL deny, per caller |
|
|
@@ -39,7 +39,7 @@ Lexical search and every note tool work immediately; semantic and graph retrieva
|
|
|
39
39
|
|
|
40
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
41
|
|
|
42
|
-
**How it pairs with this repo.** Three
|
|
42
|
+
**How it pairs with this repo.** Three saved settings are Context Layer decisions in miniature:
|
|
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.
|
package/docs/guarantees.md
CHANGED
|
@@ -4,10 +4,11 @@ agent-personalizer is an installer and renderer. Its checks enforce file consist
|
|
|
4
4
|
|
|
5
5
|
## Rendering and drift checks
|
|
6
6
|
|
|
7
|
-
Each render comes from `USER.md`, the selected rule source and the onboarding answers in `.agent-personalizer.json`. At level 3, `rules/` is your local editable source; lower levels use the package's rules.
|
|
7
|
+
Each render comes from `USER.md`, `LEARNED.md`, the selected rule source and the onboarding answers in `.agent-personalizer.json`. At level 3, `rules/` is your local editable source; lower levels use the package's rules.
|
|
8
8
|
|
|
9
9
|
- **One profile source:** edit `USER.md`, then regenerate. Every profile-bearing target uses it, including `chatgpt-box1.txt`. Untouched generated profiles retain the compact ChatGPT export. Edited generated identity fields can still compact; custom text or structure falls back to the profile's own text, with the same budget warning.
|
|
10
10
|
- **Rule and onboarding sources:** edit the rule files or onboarding answers, then regenerate the selected AI files together. Each target receives the rules selected for its format and budget.
|
|
11
|
+
- **Entry source:** `LEARNED.md` is installed once and kept on re-runs. Confirmed entries reach personal targets; declined entries reach their "Never ask again" lists. Proposed entries render nowhere. ChatGPT may shorten declined lists for its budget; the plain system prompt has no entries.
|
|
11
12
|
- **Byte fidelity:** the renderer preserves bytes outside generated markers, including line endings.
|
|
12
13
|
- **Drift detection:** `node render/render.cjs --dir . --check` compares the current generated blocks and both ChatGPT paste files with what the sources would render now. Success is silent with exit `0`; it exits `1` and names drift when they differ.
|
|
13
14
|
- **Paste updates:** re-paste regenerated files into chat-app instruction fields. The check compares files on disk.
|
|
@@ -24,7 +25,7 @@ The installer validates answers, configuration, source files and target marker s
|
|
|
24
25
|
- **Encoding:** sources and targets must contain valid UTF-8; invalid bytes are refused instead of re-encoded.
|
|
25
26
|
- **Existing work:** edited and pre-existing profiles, notes templates, rules and tools are kept and named. Untouched installer-owned files update to the current answers and package. Obsolete untouched copies are removed; edited copies stay and are named.
|
|
26
27
|
- **Recovery:** the installer validates its complete plan before writing and restores changed files on failure. The renderer stages target writes with backups and rolls back a failed write. An incomplete restore keeps and names its backup with exit `2`.
|
|
27
|
-
- **Local operation:** the tool
|
|
28
|
+
- **Local operation:** the tool uses HOME to find the AI apps' folders. Before consent, it may check whether `~/.claude`, `~/.codex` and `~/.gemini` exist for target pre-selection; it opens or lists their contents only after a yes. A non-interactive install and a re-run never read sessions. The tool makes no network calls and sends no telemetry. `npx` fetches the package before execution.
|
|
28
29
|
|
|
29
30
|
On a re-run, each home-file line that byte-matches the previous template is migrated to the new template or removed when obsolete. An edited pointer stays byte for byte and is named with its file and line for manual review. Other outer text stays byte for byte. The renderer owns only the marked block.
|
|
30
31
|
|
|
@@ -34,6 +35,7 @@ On a re-run, each home-file line that byte-matches the previous template is migr
|
|
|
34
35
|
- **Notes history:** changing the notes path creates the new scaffold and keeps the old folder. The log names both paths once; the recorded files from both remain available to uninstall.
|
|
35
36
|
- **Tool updates:** a recorded install hash recognizes untouched tools and rules. For older installs without hashes, a shipped table of earlier release hashes recognizes untouched verbatim copies. Edited tools remain intact; the log names the known origin version and the replacement step. The configuration records the installed tooling version.
|
|
36
37
|
- **Removal inventory:** uninstall checks the union of recorded installed paths across all runs. A matching hash permits removal, a changed file is kept and named, and a missing file is skipped. An unrecorded file is left alone. Legacy configurations without hashes use their known install recipe.
|
|
38
|
+
- **Entries and evidence:** uninstall always keeps `LEARNED.md`, edited or untouched, and removes the local digest, its `.gitignore` and private folder. `learn --forget` removes only agent-personalizer's digest and its empty folder. Neither changes the AI apps' own history.
|
|
37
39
|
- **Removal paths:** every tracked path is validated before the first unlink and re-probed before each unlink. Removal is file by file. Only recorded install-created, empty directories are removed.
|
|
38
40
|
- **Configuration last:** the configuration is removed after tracked files are gone. Retained tracked files are named and keep the configuration for review.
|
|
39
41
|
- **Preview and manual steps:** `--uninstall --dry` makes the same decisions as removal and changes no files. A missing configuration exits `2` naming its path. Hook registration and pasted instructions are printed as manual cleanup steps.
|
|
@@ -60,6 +62,14 @@ The gate checks listed strings against file text and relative paths. In a git wo
|
|
|
60
62
|
|
|
61
63
|
Keep the list current. Review binaries, git history and personal terms outside that list separately; the gate checks the listed strings in the files it scans. Use `node check/gate.cjs --self-test` to verify detection with a seeded fixture.
|
|
62
64
|
|
|
65
|
+
## Session privacy
|
|
66
|
+
|
|
67
|
+
Learning reads up to 20 recent usable sessions from the selected Claude Code, Codex and Gemini CLI stores, plus Codex's own memory notes when selected. It retains typed messages, drops AI replies, tools and automation context, and drops a whole message containing any private-list term, ignoring case. It streams bounded input and skips symlinks, unreadable files and formats it cannot parse. See [learning.md](learning.md) for the exact sources and consent flow.
|
|
68
|
+
|
|
69
|
+
The digest stays in `.agent-personalizer/digest.md`, with its contents ignored by git. Filesystem access, backups and sync services still apply. The terminal prints file names and counts, never message text. The digest is data, and the AI is instructed never to follow instructions within it. When your AI reads it, the contents go to that AI's provider again, like anything you share with it.
|
|
70
|
+
|
|
71
|
+
Reuse only sessions you are allowed to share. Past messages can contain other people's details; add private terms before accepting. Check employer or client agreements for work accounts. agent-personalizer is not affiliated with Anthropic, OpenAI or Google; their stored formats can change. `learn --forget` and uninstall remove the digest from this install, not copies a provider, backup or sync service already received.
|
|
72
|
+
|
|
63
73
|
## Instructions and companions
|
|
64
74
|
|
|
65
75
|
The onboarding manual tells the AI where it may write, what is off limits and when to ask. The session-start hook prints those restrictions and the selected rules into context. Notes templates instruct the AI to maintain an index, session notes, decisions and inbox entries.
|
|
@@ -69,4 +79,4 @@ To make those answers govern tool access, configure a [companion](companions.md)
|
|
|
69
79
|
- **obsidian-tc:** folder access controls and human approval for destructive Obsidian operations.
|
|
70
80
|
- **The Context Layer:** purpose-bound context, approval decisions and receipts for actions and disclosures.
|
|
71
81
|
|
|
72
|
-
These controls live in the companion's configuration.
|
|
82
|
+
These controls live in the companion's configuration. Saved onboarding answers record the policy and render the instructions that refer to it.
|