@fabersep/memory 0.1.0 → 0.2.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/dist/src/cli.js CHANGED
@@ -4,13 +4,16 @@ import * as path from 'node:path';
4
4
  import * as readline from 'node:readline';
5
5
  import { compileGlobalL0 } from './compiler.js';
6
6
  import { generateUuid, getCompiledL0Path, getDefaultPersonalPath, getHomeDir, loadConfig, saveConfig, } from './config.js';
7
+ import { formatDoctorReport, runDoctor } from './doctor.js';
7
8
  import { getDefaultBranch, getHeadSha, gitCloneTeamRepo, gitInitSoloRepo, isGitRepo, } from './git.js';
8
9
  import { runImport } from './importer.js';
9
- import { formatUnifiedDiff, planOrApplyInit } from './init.js';
10
+ import { formatPlanBeforeAfter, planOrApplyInit } from './init.js';
10
11
  import { FaberMemoryMcpServer } from './mcp.js';
11
12
  import { approveProposalsBatch, findProposalById, reconcileAwaitingCommitProposals, rejectProposal, saveProposal, } from './proposals.js';
13
+ import { buildShareableBenchmark, computeStats, formatShareableMarkdown, formatStatsReport, validateDaysArg, } from './stats.js';
12
14
  import { loadAllScopes, resolveProjectRoot } from './store.js';
13
15
  import { syncAllRoots } from './sync.js';
16
+ import { c, hr, inferErrorAnchor, normalizeTeamUrl, troubleshootingLink, } from './ui.js';
14
17
  function parseFlags(args) {
15
18
  const positional = [];
16
19
  const flags = {};
@@ -39,6 +42,24 @@ function parseFlags(args) {
39
42
  }
40
43
  return { positional, flags };
41
44
  }
45
+ async function promptLine(question) {
46
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
47
+ try {
48
+ return await new Promise((resolve) => {
49
+ rl.question(question, (ans) => resolve(ans.trim()));
50
+ });
51
+ }
52
+ finally {
53
+ rl.close();
54
+ }
55
+ }
56
+ function printErrorWithHelp(errMsg) {
57
+ console.error(c.red(`Error: ${errMsg}`));
58
+ const anchor = inferErrorAnchor(errMsg);
59
+ if (anchor) {
60
+ console.error(c.dim(` Details: ${troubleshootingLink(anchor)}`));
61
+ }
62
+ }
42
63
  async function main() {
43
64
  const argv = process.argv.slice(2);
44
65
  const cmd = argv[0];
@@ -56,7 +77,11 @@ async function main() {
56
77
  if (cmd === 'setup') {
57
78
  const config = loadConfig(homeDir);
58
79
  if (flags.team) {
59
- const url = String(flags.team);
80
+ const rawUrl = String(flags.team);
81
+ const { url, normalized } = normalizeTeamUrl(rawUrl);
82
+ if (normalized) {
83
+ console.log(c.dim(`Normalized team URL: ${rawUrl} -> ${url}`));
84
+ }
60
85
  const dest = typeof flags.path === 'string'
61
86
  ? path.resolve(flags.path)
62
87
  : path.join(homeDir, 'clones', 'team');
@@ -73,7 +98,7 @@ async function main() {
73
98
  submitMode,
74
99
  };
75
100
  saveConfig(config, homeDir);
76
- console.log(`Configured team root at ${dest} (branch: ${defaultBranch}, uuid: ${config.roots.team.uuid})`);
101
+ console.log(c.green(`Configured team root at ${dest} (branch: ${defaultBranch}, uuid: ${config.roots.team.uuid})`));
77
102
  return 0;
78
103
  }
79
104
  const personalPath = typeof flags.path === 'string'
@@ -89,7 +114,7 @@ async function main() {
89
114
  defaultBranch: 'main',
90
115
  };
91
116
  saveConfig(config, homeDir);
92
- console.log(`Initialized personal memory root at ${personalPath} (uuid: ${config.roots.personal.uuid})`);
117
+ console.log(c.green(`Initialized personal memory root at ${personalPath} (uuid: ${config.roots.personal.uuid})`));
93
118
  return 0;
94
119
  }
95
120
  if (cmd === 'config') {
@@ -109,7 +134,7 @@ async function main() {
109
134
  }
110
135
  root.path = path.resolve(newPath);
111
136
  saveConfig(config, homeDir);
112
- console.log(`Updated ${scope} root path to ${root.path} (uuid preserved: ${root.uuid})`);
137
+ console.log(c.green(`Updated ${scope} root path to ${root.path} (uuid preserved: ${root.uuid})`));
113
138
  return 0;
114
139
  }
115
140
  if (sub === 'set-submit-mode') {
@@ -120,7 +145,23 @@ async function main() {
120
145
  }
121
146
  config.roots.team.submitMode = mode;
122
147
  saveConfig(config, homeDir);
123
- console.log(`Updated team submit mode to ${mode}`);
148
+ console.log(c.green(`Updated team submit mode to ${mode}`));
149
+ return 0;
150
+ }
151
+ if (sub === 'unset') {
152
+ const scope = positional[1];
153
+ if (!scope || !['personal', 'team'].includes(scope)) {
154
+ console.error('Usage: faber-memory config unset <personal|team>');
155
+ return 1;
156
+ }
157
+ const existing = config.roots[scope];
158
+ if (!existing) {
159
+ console.log(`Root "${scope}" is not configured.`);
160
+ return 0;
161
+ }
162
+ delete config.roots[scope];
163
+ saveConfig(config, homeDir);
164
+ console.log(c.green(`Disconnected ${scope} root from config (files on disk at ${existing.path} were kept intact).`));
124
165
  return 0;
125
166
  }
126
167
  console.log(JSON.stringify(config, null, 2));
@@ -138,17 +179,17 @@ async function main() {
138
179
  standaloneRepoDir,
139
180
  });
140
181
  for (const w of res.warnings)
141
- console.warn(`Warning: ${w}`);
182
+ console.warn(c.yellow(`Warning: ${w}`));
142
183
  if (!res.ok) {
143
184
  for (const e of res.errors)
144
- console.error(`Error: ${e}`);
185
+ printErrorWithHelp(e);
145
186
  return 1;
146
187
  }
147
188
  if (checkOnly) {
148
- console.log(`OK: compile --check passed (${res.estimatedTokens}/${res.budget} estimated tokens).`);
189
+ console.log(c.green(`OK: compile --check passed (${res.estimatedTokens}/${res.budget} estimated tokens).`));
149
190
  }
150
191
  else {
151
- console.log(`Compiled L0 to ${res.outputPath} (${res.estimatedTokens}/${res.budget} estimated tokens).`);
192
+ console.log(c.green(`Compiled L0 to ${res.outputPath} (${res.estimatedTokens}/${res.budget} estimated tokens).`));
152
193
  }
153
194
  return 0;
154
195
  }
@@ -157,15 +198,15 @@ async function main() {
157
198
  const timeoutMs = typeof flags.timeout === 'string' ? Number(flags.timeout) : 5000;
158
199
  const res = await syncAllRoots(config, { homeDir, timeoutMs, recompile: true });
159
200
  for (const w of res.warnings)
160
- console.warn(`Warning: ${w}`);
201
+ console.warn(c.yellow(`Warning: ${w}`));
161
202
  if (!res.ok) {
162
203
  for (const e of res.errors)
163
- console.error(`Error: ${e}`);
204
+ printErrorWithHelp(e);
164
205
  return 1;
165
206
  }
166
- console.log(res.advanced
207
+ console.log(c.green(res.advanced
167
208
  ? 'Synced remote updates and recompiled L0.'
168
- : 'Already up to date; L0 compiled.');
209
+ : 'Already up to date; L0 compiled.'));
169
210
  return 0;
170
211
  }
171
212
  if (cmd === 'approve') {
@@ -179,7 +220,7 @@ async function main() {
179
220
  for (const id of ids) {
180
221
  const p = findProposalById(id, homeDir);
181
222
  if (!p) {
182
- console.error(`Error: Proposal "${id}" not found.`);
223
+ console.error(c.red(`Error: Proposal "${id}" not found.`));
183
224
  return 1;
184
225
  }
185
226
  proposals.push(p);
@@ -193,27 +234,82 @@ async function main() {
193
234
  console.log(m);
194
235
  if (!outcome.ok) {
195
236
  for (const e of outcome.errors)
196
- console.error(`Error: ${e}`);
237
+ printErrorWithHelp(e);
197
238
  return 1;
198
239
  }
199
240
  return 0;
200
241
  }
201
242
  if (cmd === 'reject') {
243
+ if (flags.all) {
244
+ const proposals = reconcileAwaitingCommitProposals(homeDir);
245
+ if (proposals.length === 0) {
246
+ console.log('No pending proposals to reject.');
247
+ return 0;
248
+ }
249
+ if (!flags.yes) {
250
+ const ans = (await promptLine(c.yellow(`Reject and delete all ${proposals.length} pending proposal(s)? [y/N]: `))).toLowerCase();
251
+ if (ans !== 'y' && ans !== 'yes') {
252
+ console.log('Cancelled. No proposals were removed.');
253
+ return 0;
254
+ }
255
+ }
256
+ for (const p of proposals) {
257
+ rejectProposal(p.id, homeDir);
258
+ }
259
+ console.log(c.green(`Rejected and removed ${proposals.length} pending proposal(s).`));
260
+ return 0;
261
+ }
202
262
  const id = positional[0];
203
263
  if (!id) {
204
- console.error('Usage: faber-memory reject <proposal-id>');
264
+ console.error('Usage: faber-memory reject <proposal-id> | faber-memory reject --all [--yes]');
205
265
  return 1;
206
266
  }
207
267
  try {
208
268
  const removed = rejectProposal(id, homeDir);
209
- console.log(`Rejected and removed proposal ${removed.id}.`);
269
+ console.log(c.green(`Rejected and removed proposal ${removed.id}.`));
210
270
  return 0;
211
271
  }
212
272
  catch (err) {
213
- console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
273
+ printErrorWithHelp(err instanceof Error ? err.message : String(err));
214
274
  return 1;
215
275
  }
216
276
  }
277
+ if (cmd === 'reset') {
278
+ const config = loadConfig(homeDir);
279
+ const includePersonal = Boolean(flags['include-personal-repo']);
280
+ const personalPath = config.roots.personal?.path;
281
+ console.log(c.bold(c.yellow('FaberSEP Memory Reset')));
282
+ console.log('This will:');
283
+ console.log(' 1. Undo agent wiring (remove faber-memory blocks & MCP entries).');
284
+ console.log(` 2. Delete local state directory: ${homeDir} (config, compiled L0, pre-memory, metrics.jsonl, team clone).`);
285
+ if (includePersonal && personalPath) {
286
+ console.log(c.red(` 3. Delete personal memory Git repository: ${personalPath}`));
287
+ }
288
+ else if (personalPath) {
289
+ console.log(c.dim(` (Personal Git repo at ${personalPath} will be kept. Pass --include-personal-repo to delete it too.)`));
290
+ }
291
+ if (!flags.yes) {
292
+ const ans = (await promptLine(c.yellow('Continue with reset? [y/N]: '))).toLowerCase();
293
+ if (ans !== 'y' && ans !== 'yes') {
294
+ console.log('Reset cancelled.');
295
+ return 0;
296
+ }
297
+ }
298
+ try {
299
+ planOrApplyInit(config, { undo: true, homeDir });
300
+ }
301
+ catch {
302
+ // Best-effort undo even if config is partial
303
+ }
304
+ if (fs.existsSync(homeDir)) {
305
+ fs.rmSync(homeDir, { recursive: true, force: true });
306
+ }
307
+ if (includePersonal && personalPath && fs.existsSync(personalPath)) {
308
+ fs.rmSync(personalPath, { recursive: true, force: true });
309
+ }
310
+ console.log(c.green('Reset complete.'));
311
+ return 0;
312
+ }
217
313
  if (cmd === 'review') {
218
314
  const config = loadConfig(homeDir);
219
315
  const proposals = reconcileAwaitingCommitProposals(homeDir).filter((p) => p.status !== 'awaiting_commit');
@@ -221,50 +317,126 @@ async function main() {
221
317
  console.log('No pending proposals to review.');
222
318
  return 0;
223
319
  }
224
- const toApprove = [];
320
+ const decisions = new Map();
225
321
  if (flags['approve-all']) {
226
- toApprove.push(...proposals);
322
+ for (const p of proposals)
323
+ decisions.set(p.id, 'approve');
227
324
  }
228
325
  else {
229
326
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
327
+ let interrupted = false;
328
+ rl.on('SIGINT', () => {
329
+ interrupted = true;
330
+ console.log(c.yellow('\nInterrupted — saving decisions made so far...'));
331
+ rl.close();
332
+ });
230
333
  const lineIter = rl[Symbol.asyncIterator]();
231
334
  const ask = async (q) => {
232
335
  process.stdout.write(q);
233
336
  const next = await lineIter.next();
234
- return next.done ? '' : String(next.value);
337
+ if (next.done)
338
+ return null;
339
+ return String(next.value);
235
340
  };
341
+ const MAX_PREVIEW_LINES = 12;
236
342
  try {
237
- for (const p of proposals) {
238
- console.log(`\n=== Proposal ${p.id} [${p.scope} / ${p.action}] ===`);
239
- console.log(`Entry ID: ${p.entryId}${p.targetId ? ` (target: ${p.targetId})` : ''}`);
240
- console.log(`Type: ${p.type} | Summary: ${p.summary}`);
343
+ let idx = 0;
344
+ let showFull = false;
345
+ while (idx < proposals.length && !interrupted) {
346
+ const p = proposals[idx];
347
+ const approvedCount = [...decisions.values()].filter((d) => d === 'approve').length;
348
+ const rejectedCount = [...decisions.values()].filter((d) => d === 'reject').length;
349
+ const skippedCount = [...decisions.values()].filter((d) => d === 'skip').length;
350
+ const prevDecision = decisions.get(p.id);
351
+ console.log(`\n${c.dim(hr('═', 68))}`);
352
+ console.log(`${c.bold(c.cyan(`[ ${idx + 1} / ${proposals.length} ]`))} ` +
353
+ `${c.green(`Approved: ${approvedCount}`)} | ` +
354
+ `${c.red(`Rejected: ${rejectedCount}`)} | ` +
355
+ `${c.yellow(`Skipped: ${skippedCount}`)}` +
356
+ (prevDecision ? c.dim(` (current: ${prevDecision})`) : ''));
357
+ console.log(c.dim(hr('─', 68)));
358
+ console.log(`${c.bold('ID:')} ${c.cyan(p.entryId)} ` +
359
+ `${c.bold('Scope:')} ${c.magenta(p.scope)} ` +
360
+ `${c.bold('Type:')} ${p.type} ` +
361
+ `${c.bold('Action:')} ${p.action}` +
362
+ (p.targetId ? ` (target: ${p.targetId})` : ''));
363
+ console.log(`${c.bold('Summary:')} ${p.summary}`);
241
364
  if (p.forceNew && p.reason) {
242
- console.log(`force_new reason: ${p.reason}`);
365
+ console.log(`${c.yellow('force_new reason:')} ${p.reason}`);
366
+ }
367
+ console.log(c.dim(hr('─', 68)));
368
+ const bodyLines = p.body.split('\n');
369
+ if (!showFull && bodyLines.length > MAX_PREVIEW_LINES) {
370
+ console.log(bodyLines.slice(0, MAX_PREVIEW_LINES).join('\n'));
371
+ console.log(c.dim(`... (+${bodyLines.length - MAX_PREVIEW_LINES} more lines — press [v] to view full body)`));
243
372
  }
244
- console.log(`Body:\n${p.body}\n`);
245
- const answer = (await ask('Action? [a]pprove / [e]dit / [r]eject / [s]kip: '))
246
- .trim()
247
- .toLowerCase();
373
+ else {
374
+ console.log(p.body);
375
+ }
376
+ console.log(c.dim(hr('─', 68)));
377
+ const navHints = [
378
+ c.green('[a]pprove'),
379
+ c.cyan('[e]dit'),
380
+ c.red('[r]eject'),
381
+ c.yellow('[s]kip'),
382
+ ...(!showFull && bodyLines.length > MAX_PREVIEW_LINES ? ['[v]iew full'] : []),
383
+ ...(idx > 0 ? ['[b]ack'] : []),
384
+ c.dim('[q]uit & save'),
385
+ ].join(' ');
386
+ const rawAns = await ask(`${navHints}\n> `);
387
+ if (rawAns === null)
388
+ break;
389
+ const answer = rawAns.trim().toLowerCase();
390
+ if (answer === 'v' || answer === 'view') {
391
+ showFull = true;
392
+ continue;
393
+ }
394
+ if (answer === 'b' || answer === 'back') {
395
+ if (idx > 0) {
396
+ idx--;
397
+ showFull = false;
398
+ }
399
+ else {
400
+ console.log(c.dim('Already at the first proposal.'));
401
+ }
402
+ continue;
403
+ }
404
+ if (answer === 'q' || answer === 'quit') {
405
+ break;
406
+ }
407
+ showFull = false;
248
408
  if (answer === 'a' || answer === 'approve') {
249
- toApprove.push(p);
409
+ decisions.set(p.id, 'approve');
410
+ idx++;
250
411
  }
251
412
  else if (answer === 'e' || answer === 'edit') {
252
- const newBody = (await ask('New body (single line or leave empty to keep): ')).trim();
413
+ const newBodyRaw = await ask('New body (single line or leave empty to keep): ');
414
+ if (newBodyRaw === null)
415
+ break;
416
+ const newBody = newBodyRaw.trim();
253
417
  if (newBody) {
254
418
  p.body = newBody;
255
419
  saveProposal(p, homeDir);
256
420
  }
257
- const confirm = (await ask('Approve edited proposal? [y/N]: ')).trim().toLowerCase();
421
+ const confirmRaw = await ask('Approve edited proposal? [y/N]: ');
422
+ if (confirmRaw === null)
423
+ break;
424
+ const confirm = confirmRaw.trim().toLowerCase();
258
425
  if (confirm === 'y' || confirm === 'yes') {
259
- toApprove.push(p);
426
+ decisions.set(p.id, 'approve');
427
+ }
428
+ else {
429
+ decisions.set(p.id, 'skip');
260
430
  }
431
+ idx++;
261
432
  }
262
433
  else if (answer === 'r' || answer === 'reject') {
263
- rejectProposal(p.id, homeDir);
264
- console.log(`Rejected ${p.id}.`);
434
+ decisions.set(p.id, 'reject');
435
+ idx++;
265
436
  }
266
437
  else {
267
- console.log(`Skipped ${p.id}.`);
438
+ decisions.set(p.id, 'skip');
439
+ idx++;
268
440
  }
269
441
  }
270
442
  }
@@ -272,25 +444,45 @@ async function main() {
272
444
  rl.close();
273
445
  }
274
446
  }
447
+ const toApprove = [];
448
+ const toReject = [];
449
+ for (const p of proposals) {
450
+ const d = decisions.get(p.id);
451
+ if (d === 'approve')
452
+ toApprove.push(p);
453
+ else if (d === 'reject')
454
+ toReject.push(p);
455
+ }
456
+ for (const p of toReject) {
457
+ rejectProposal(p.id, homeDir);
458
+ }
459
+ let exitCode = 0;
275
460
  if (toApprove.length > 0) {
276
461
  const outcome = await approveProposalsBatch(config, toApprove, { homeDir });
277
462
  for (const m of outcome.messages)
278
463
  console.log(m);
279
464
  if (!outcome.ok) {
280
465
  for (const e of outcome.errors)
281
- console.error(`Error: ${e}`);
282
- return 1;
466
+ printErrorWithHelp(e);
467
+ exitCode = 1;
283
468
  }
284
469
  }
285
- return 0;
470
+ const remainingCount = proposals.length - toApprove.length - toReject.length;
471
+ console.log(`\n${c.bold('Review summary:')} ` +
472
+ `${c.green(`${toApprove.length} approved`)} | ` +
473
+ `${c.red(`${toReject.length} rejected`)} | ` +
474
+ `${c.yellow(`${remainingCount} remaining in pre-memory`)}`);
475
+ return exitCode;
286
476
  }
287
477
  if (cmd === 'status') {
288
478
  const config = loadConfig(homeDir);
289
479
  const projectRes = resolveProjectRoot(undefined, process.cwd());
290
480
  const loaded = loadAllScopes(config, projectRes);
291
481
  const proposals = reconcileAwaitingCommitProposals(homeDir);
292
- console.log('FaberSEP Memory Status');
293
- console.log(` Compiled L0: ${getCompiledL0Path(homeDir)} (${fs.existsSync(getCompiledL0Path(homeDir)) ? 'present' : 'missing'})`);
482
+ console.log(c.bold('FaberSEP Memory Status'));
483
+ const l0Path = getCompiledL0Path(homeDir);
484
+ const l0Present = fs.existsSync(l0Path);
485
+ console.log(` Compiled L0: ${l0Path} (${l0Present ? c.green('present') : c.yellow('missing')})`);
294
486
  if (config.roots.team) {
295
487
  console.log(` Team root: ${config.roots.team.path} (HEAD: ${getHeadSha(config.roots.team.path)?.slice(0, 8) || 'none'}, mode: ${config.roots.team.submitMode || 'auto'})`);
296
488
  }
@@ -299,7 +491,7 @@ async function main() {
299
491
  }
300
492
  console.log(` Project root: ${projectRes.projectRoot || 'none'} (source: ${projectRes.source})`);
301
493
  if (loaded.uncommittedWarnings.length > 0) {
302
- console.log('Warnings:');
494
+ console.log(c.yellow('Warnings:'));
303
495
  for (const w of loaded.uncommittedWarnings)
304
496
  console.log(` - ${w}`);
305
497
  }
@@ -317,7 +509,7 @@ async function main() {
317
509
  console.log(` file: ${p.targetFilePath} — run "git add ${p.targetFilePath} && git commit" to activate`);
318
510
  }
319
511
  if (p.status === 'push_failed' && p.error) {
320
- console.log(` push error: ${p.error}`);
512
+ console.log(c.red(` push error: ${p.error}`));
321
513
  }
322
514
  }
323
515
  return 0;
@@ -327,7 +519,7 @@ async function main() {
327
519
  const from = flags.from;
328
520
  const sourcePath = positional[0];
329
521
  if (!from || !sourcePath) {
330
- console.error('Usage: faber-memory import --from <markdown-dir|claude-memory|agents-md|cursor-rules> <path> [--split-headings] [--approve]');
522
+ console.error('Usage: faber-memory import --from <markdown-dir|claude-memory|agents-md|cursor-rules> <path> [--scope personal|team|project] [--split-headings] [--normalize-paths] [--approve]');
331
523
  return 1;
332
524
  }
333
525
  try {
@@ -336,24 +528,48 @@ async function main() {
336
528
  sourcePath: path.resolve(sourcePath),
337
529
  scope: typeof flags.scope === 'string' ? flags.scope : 'personal',
338
530
  splitHeadings: Boolean(flags['split-headings']),
531
+ normalizePaths: Boolean(flags['normalize-paths']),
339
532
  approve: Boolean(flags.approve),
340
533
  homeDir,
341
534
  cwd: process.cwd(),
342
535
  });
343
- console.log(`Staged ${res.staged.length} proposal(s) in pre-memory.`);
536
+ console.log(c.green(`Staged ${res.staged.length} proposal(s) in pre-memory.`));
344
537
  if (res.approvedIds.length > 0) {
345
- console.log(`Approved ${res.approvedIds.length} proposal(s) in solo mode.`);
538
+ console.log(c.green(`Approved ${res.approvedIds.length} proposal(s) in solo mode.`));
539
+ }
540
+ if (res.normalizedPaths.length > 0) {
541
+ console.log(c.cyan(`Normalized machine paths to ~/ in ${res.normalizedPaths.length} file(s):`));
542
+ for (const n of res.normalizedPaths) {
543
+ console.log(` - ${n.source} (${n.replacements} replacement(s))`);
544
+ }
545
+ }
546
+ if (res.skippedIndex.length > 0) {
547
+ console.log(c.dim(`Index files skipped (${res.skippedIndex.length}) — faber-memory compiles its own L0 MEMORY.md index:`));
548
+ for (const f of res.skippedIndex) {
549
+ console.log(c.dim(` - ${f}`));
550
+ }
551
+ console.log(c.dim(` Details: ${troubleshootingLink('index-files')}`));
346
552
  }
347
553
  if (res.duplicates.length > 0) {
348
- console.log(`Duplicates skipped (${res.duplicates.length}):`);
554
+ console.log(c.yellow(`Duplicates skipped (${res.duplicates.length}):`));
349
555
  for (const d of res.duplicates) {
350
556
  console.log(` - ${d.source} matches "${d.matchedId}" (${d.summary})`);
351
557
  }
352
558
  }
353
559
  if (res.skippedHygiene.length > 0) {
354
- console.log(`Hygiene skipped (${res.skippedHygiene.length}):`);
560
+ console.log(c.yellow(`Hygiene skipped (${res.skippedHygiene.length}):`));
355
561
  for (const s of res.skippedHygiene) {
356
562
  console.log(` - ${s.source}: ${s.reason}`);
563
+ if (s.snippet) {
564
+ console.log(c.dim(` snippet: ${s.snippet}`));
565
+ }
566
+ if (s.anchor === 'machine-specific-paths') {
567
+ console.log(c.cyan(' hint: Replace /Users/<name>/ or /home/<name>/ with ~/, or re-run with --normalize-paths.'));
568
+ }
569
+ else {
570
+ console.log(c.cyan(' hint: Remove the secret/token and reference an env var name instead.'));
571
+ }
572
+ console.log(c.dim(` details: ${troubleshootingLink(s.anchor)}`));
357
573
  }
358
574
  }
359
575
  for (const n of res.notes)
@@ -361,7 +577,7 @@ async function main() {
361
577
  return 0;
362
578
  }
363
579
  catch (err) {
364
- console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
580
+ printErrorWithHelp(err instanceof Error ? err.message : String(err));
365
581
  return 1;
366
582
  }
367
583
  }
@@ -382,25 +598,73 @@ async function main() {
382
598
  homeDir,
383
599
  });
384
600
  for (const n of res.notes)
385
- console.log(n);
601
+ console.log(c.yellow(n));
386
602
  for (const p of res.plans) {
387
- console.log(formatUnifiedDiff(p));
603
+ console.log(formatPlanBeforeAfter(p));
388
604
  }
389
- if (undo && res.backups.length > 0) {
390
- console.log(`Backup files preserved (not auto-restored): ${res.backups.join(', ')}`);
605
+ if (undo) {
606
+ console.log(c.cyan('\nRemoved agent wiring only. Your memory repos and pending pre-memory proposals were kept intact. (Use "faber-memory reset" to wipe local state.)'));
607
+ if (res.backups.length > 0) {
608
+ console.log(c.dim(`Backup files preserved (not auto-restored): ${res.backups.join(', ')}`));
609
+ }
391
610
  }
392
611
  if (res.projectHint) {
393
612
  console.log(`Project hint: ${res.projectHint}`);
394
613
  }
395
614
  if (!apply && !undo) {
396
- console.log('\nDry-run only. Re-run with --apply to write changes.');
615
+ console.log(c.yellow('\nDry-run only. Re-run with --apply to write changes.'));
397
616
  }
398
617
  return 0;
399
618
  }
400
619
  catch (err) {
401
- console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
620
+ printErrorWithHelp(err instanceof Error ? err.message : String(err));
621
+ return 1;
622
+ }
623
+ }
624
+ if (cmd === 'stats') {
625
+ const daysCheck = validateDaysArg(flags.days);
626
+ if (!daysCheck.ok) {
627
+ printErrorWithHelp(daysCheck.error);
402
628
  return 1;
403
629
  }
630
+ const report = computeStats({
631
+ days: daysCheck.days,
632
+ includeCache: Boolean(flags.cache),
633
+ engine: typeof flags.engine === 'string' ? flags.engine : undefined,
634
+ logDir: typeof flags['log-dir'] === 'string' ? path.resolve(flags['log-dir']) : undefined,
635
+ homeDir,
636
+ cwd: process.cwd(),
637
+ });
638
+ if (flags.share) {
639
+ const card = buildShareableBenchmark(report);
640
+ if (flags.json) {
641
+ console.log(JSON.stringify(card, null, 2));
642
+ }
643
+ else {
644
+ console.log(formatShareableMarkdown(card));
645
+ }
646
+ return 0;
647
+ }
648
+ if (flags.json) {
649
+ console.log(JSON.stringify(report, null, 2));
650
+ return 0;
651
+ }
652
+ console.log(formatStatsReport(report));
653
+ return 0;
654
+ }
655
+ if (cmd === 'doctor') {
656
+ const report = runDoctor({
657
+ strict: Boolean(flags.strict),
658
+ homeDir,
659
+ cwd: process.cwd(),
660
+ });
661
+ if (flags.json) {
662
+ console.log(JSON.stringify(report, null, 2));
663
+ }
664
+ else {
665
+ console.log(formatDoctorReport(report));
666
+ }
667
+ return report.exitCode;
404
668
  }
405
669
  console.error(`Unknown command: ${cmd}`);
406
670
  printHelp();
@@ -410,16 +674,19 @@ function printHelp() {
410
674
  console.log(`@fabersep/memory (faber-memory)
411
675
 
412
676
  Commands:
413
- setup [path] [--team <git-url> --path <dir> --submit-mode auto|pr]
414
- config [set-path <personal|team> <new-path> | set-submit-mode <auto|pr>]
415
- init [--apply | --undo] [--engine claude-code,antigravity,cursor,codex] [--project-hint]
677
+ setup [path] [--team <git-url|org/repo> --path <dir> --submit-mode auto|pr]
678
+ config [set-path <personal|team> <new-path> | set-submit-mode <auto|pr> | unset <personal|team>]
679
+ init [--apply | --undo] [--engine claude-code,antigravity,claude-desktop,cursor,codex] [--project-hint]
416
680
  compile [--check] [--repo <dir>]
417
681
  sync [--timeout <ms>]
418
682
  status
683
+ stats [--days 1..90] [--json] [--cache] [--engine claude-code|antigravity|all] [--log-dir <path>] [--share]
684
+ doctor [--json] [--strict]
419
685
  review [--approve-all]
420
686
  approve <proposal-id> [...] [--mode auto|pr]
421
- reject <proposal-id>
422
- import --from <markdown-dir|claude-memory|agents-md|cursor-rules> <path> [--split-headings] [--approve]
687
+ reject <proposal-id> | reject --all [--yes]
688
+ reset [--include-personal-repo] [--yes]
689
+ import --from <markdown-dir|claude-memory|agents-md|cursor-rules> <path> [--scope personal|team|project] [--split-headings] [--normalize-paths] [--approve]
423
690
  serve
424
691
  `);
425
692
  }
@@ -429,6 +696,6 @@ main()
429
696
  process.exit(code);
430
697
  })
431
698
  .catch((err) => {
432
- console.error(err instanceof Error ? err.message : String(err));
699
+ printErrorWithHelp(err instanceof Error ? err.message : String(err));
433
700
  process.exit(1);
434
701
  });
@@ -1,3 +1,4 @@
1
+ import { CompileTrigger } from './metrics.js';
1
2
  import { MemoryEntry, UserConfig } from './types.js';
2
3
  export declare function estimateTokens(text: string): number;
3
4
  export interface CompileResult {
@@ -9,6 +10,8 @@ export interface CompileResult {
9
10
  errors: string[];
10
11
  warnings: string[];
11
12
  }
13
+ export declare function renderEntryFullBody(entry: MemoryEntry): string;
14
+ export declare function estimateCorpusTokens(entries: MemoryEntry[]): number;
12
15
  export declare function renderGlobalL0(teamEntries: MemoryEntry[], personalEntries: MemoryEntry[]): string;
13
16
  export declare function compileGlobalL0(config: UserConfig, options?: {
14
17
  homeDir?: string;
@@ -16,4 +19,5 @@ export declare function compileGlobalL0(config: UserConfig, options?: {
16
19
  includeProjectCheck?: boolean;
17
20
  cwd?: string;
18
21
  standaloneRepoDir?: string;
22
+ trigger?: CompileTrigger;
19
23
  }): CompileResult;