@fabersep/memory 0.0.0-stage → 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/LICENSE +202 -0
- package/README.md +399 -2
- package/dist/src/bm25.d.ts +26 -0
- package/dist/src/bm25.js +183 -0
- package/dist/src/cache-logs.d.ts +47 -0
- package/dist/src/cache-logs.js +433 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +701 -0
- package/dist/src/compiler.d.ts +23 -0
- package/dist/src/compiler.js +211 -0
- package/dist/src/config.d.ts +20 -0
- package/dist/src/config.js +134 -0
- package/dist/src/doctor.d.ts +23 -0
- package/dist/src/doctor.js +447 -0
- package/dist/src/frontmatter.d.ts +22 -0
- package/dist/src/frontmatter.js +199 -0
- package/dist/src/git.d.ts +33 -0
- package/dist/src/git.js +251 -0
- package/dist/src/hygiene.d.ts +7 -0
- package/dist/src/hygiene.js +89 -0
- package/dist/src/importer.d.ts +34 -0
- package/dist/src/importer.js +261 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +18 -0
- package/dist/src/init.d.ts +43 -0
- package/dist/src/init.js +280 -0
- package/dist/src/mcp.d.ts +218 -0
- package/dist/src/mcp.js +437 -0
- package/dist/src/metrics.d.ts +72 -0
- package/dist/src/metrics.js +179 -0
- package/dist/src/proposals.d.ts +34 -0
- package/dist/src/proposals.js +420 -0
- package/dist/src/stats.d.ts +165 -0
- package/dist/src/stats.js +579 -0
- package/dist/src/store.d.ts +23 -0
- package/dist/src/store.js +161 -0
- package/dist/src/sync.d.ts +15 -0
- package/dist/src/sync.js +47 -0
- package/dist/src/types.d.ts +100 -0
- package/dist/src/types.js +17 -0
- package/dist/src/ui.d.ts +19 -0
- package/dist/src/ui.js +74 -0
- package/package.json +50 -4
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import * as readline from 'node:readline';
|
|
5
|
+
import { compileGlobalL0 } from './compiler.js';
|
|
6
|
+
import { generateUuid, getCompiledL0Path, getDefaultPersonalPath, getHomeDir, loadConfig, saveConfig, } from './config.js';
|
|
7
|
+
import { formatDoctorReport, runDoctor } from './doctor.js';
|
|
8
|
+
import { getDefaultBranch, getHeadSha, gitCloneTeamRepo, gitInitSoloRepo, isGitRepo, } from './git.js';
|
|
9
|
+
import { runImport } from './importer.js';
|
|
10
|
+
import { formatPlanBeforeAfter, planOrApplyInit } from './init.js';
|
|
11
|
+
import { FaberMemoryMcpServer } from './mcp.js';
|
|
12
|
+
import { approveProposalsBatch, findProposalById, reconcileAwaitingCommitProposals, rejectProposal, saveProposal, } from './proposals.js';
|
|
13
|
+
import { buildShareableBenchmark, computeStats, formatShareableMarkdown, formatStatsReport, validateDaysArg, } from './stats.js';
|
|
14
|
+
import { loadAllScopes, resolveProjectRoot } from './store.js';
|
|
15
|
+
import { syncAllRoots } from './sync.js';
|
|
16
|
+
import { c, hr, inferErrorAnchor, normalizeTeamUrl, troubleshootingLink, } from './ui.js';
|
|
17
|
+
function parseFlags(args) {
|
|
18
|
+
const positional = [];
|
|
19
|
+
const flags = {};
|
|
20
|
+
for (let i = 0; i < args.length; i++) {
|
|
21
|
+
const arg = args[i];
|
|
22
|
+
if (arg.startsWith('--')) {
|
|
23
|
+
const eqIdx = arg.indexOf('=');
|
|
24
|
+
if (eqIdx !== -1) {
|
|
25
|
+
flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const key = arg.slice(2);
|
|
29
|
+
const next = args[i + 1];
|
|
30
|
+
if (next && !next.startsWith('--')) {
|
|
31
|
+
flags[key] = next;
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
flags[key] = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
positional.push(arg);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { positional, flags };
|
|
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
|
+
}
|
|
63
|
+
async function main() {
|
|
64
|
+
const argv = process.argv.slice(2);
|
|
65
|
+
const cmd = argv[0];
|
|
66
|
+
const { positional, flags } = parseFlags(argv.slice(1));
|
|
67
|
+
const homeDir = getHomeDir();
|
|
68
|
+
if (!cmd || cmd === '--help' || cmd === '-h') {
|
|
69
|
+
printHelp();
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
if (cmd === 'serve') {
|
|
73
|
+
const server = new FaberMemoryMcpServer({ homeDir, cwd: process.cwd() });
|
|
74
|
+
server.serveStdio();
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
if (cmd === 'setup') {
|
|
78
|
+
const config = loadConfig(homeDir);
|
|
79
|
+
if (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
|
+
}
|
|
85
|
+
const dest = typeof flags.path === 'string'
|
|
86
|
+
? path.resolve(flags.path)
|
|
87
|
+
: path.join(homeDir, 'clones', 'team');
|
|
88
|
+
const submitMode = flags['submit-mode'] === 'pr' ? 'pr' : 'auto';
|
|
89
|
+
const defaultBranch = isGitRepo(dest)
|
|
90
|
+
? getDefaultBranch(dest)
|
|
91
|
+
: gitCloneTeamRepo(url, dest);
|
|
92
|
+
config.roots.team = {
|
|
93
|
+
uuid: config.roots.team?.uuid || generateUuid(),
|
|
94
|
+
path: dest,
|
|
95
|
+
scope: 'team',
|
|
96
|
+
remote: url,
|
|
97
|
+
defaultBranch,
|
|
98
|
+
submitMode,
|
|
99
|
+
};
|
|
100
|
+
saveConfig(config, homeDir);
|
|
101
|
+
console.log(c.green(`Configured team root at ${dest} (branch: ${defaultBranch}, uuid: ${config.roots.team.uuid})`));
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
const personalPath = typeof flags.path === 'string'
|
|
105
|
+
? path.resolve(flags.path)
|
|
106
|
+
: positional[0]
|
|
107
|
+
? path.resolve(positional[0])
|
|
108
|
+
: getDefaultPersonalPath();
|
|
109
|
+
gitInitSoloRepo(personalPath, 'main');
|
|
110
|
+
config.roots.personal = {
|
|
111
|
+
uuid: config.roots.personal?.uuid || generateUuid(),
|
|
112
|
+
path: personalPath,
|
|
113
|
+
scope: 'personal',
|
|
114
|
+
defaultBranch: 'main',
|
|
115
|
+
};
|
|
116
|
+
saveConfig(config, homeDir);
|
|
117
|
+
console.log(c.green(`Initialized personal memory root at ${personalPath} (uuid: ${config.roots.personal.uuid})`));
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
if (cmd === 'config') {
|
|
121
|
+
const sub = positional[0];
|
|
122
|
+
const config = loadConfig(homeDir);
|
|
123
|
+
if (sub === 'set-path') {
|
|
124
|
+
const scope = positional[1];
|
|
125
|
+
const newPath = positional[2];
|
|
126
|
+
if (!scope || !newPath || !['personal', 'team'].includes(scope)) {
|
|
127
|
+
console.error('Usage: faber-memory config set-path <personal|team> <new-path>');
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
const root = config.roots[scope];
|
|
131
|
+
if (!root) {
|
|
132
|
+
console.error(`Root "${scope}" is not configured yet.`);
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
root.path = path.resolve(newPath);
|
|
136
|
+
saveConfig(config, homeDir);
|
|
137
|
+
console.log(c.green(`Updated ${scope} root path to ${root.path} (uuid preserved: ${root.uuid})`));
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
if (sub === 'set-submit-mode') {
|
|
141
|
+
const mode = positional[1];
|
|
142
|
+
if (!['auto', 'pr'].includes(mode) || !config.roots.team) {
|
|
143
|
+
console.error('Usage: faber-memory config set-submit-mode <auto|pr>');
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
config.roots.team.submitMode = mode;
|
|
147
|
+
saveConfig(config, homeDir);
|
|
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).`));
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
console.log(JSON.stringify(config, null, 2));
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
if (cmd === 'compile') {
|
|
171
|
+
const config = loadConfig(homeDir);
|
|
172
|
+
const checkOnly = Boolean(flags.check);
|
|
173
|
+
const standaloneRepoDir = typeof flags.repo === 'string' ? path.resolve(flags.repo) : undefined;
|
|
174
|
+
const res = compileGlobalL0(config, {
|
|
175
|
+
homeDir,
|
|
176
|
+
checkOnly,
|
|
177
|
+
includeProjectCheck: checkOnly,
|
|
178
|
+
cwd: process.cwd(),
|
|
179
|
+
standaloneRepoDir,
|
|
180
|
+
});
|
|
181
|
+
for (const w of res.warnings)
|
|
182
|
+
console.warn(c.yellow(`Warning: ${w}`));
|
|
183
|
+
if (!res.ok) {
|
|
184
|
+
for (const e of res.errors)
|
|
185
|
+
printErrorWithHelp(e);
|
|
186
|
+
return 1;
|
|
187
|
+
}
|
|
188
|
+
if (checkOnly) {
|
|
189
|
+
console.log(c.green(`OK: compile --check passed (${res.estimatedTokens}/${res.budget} estimated tokens).`));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
console.log(c.green(`Compiled L0 to ${res.outputPath} (${res.estimatedTokens}/${res.budget} estimated tokens).`));
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
if (cmd === 'sync') {
|
|
197
|
+
const config = loadConfig(homeDir);
|
|
198
|
+
const timeoutMs = typeof flags.timeout === 'string' ? Number(flags.timeout) : 5000;
|
|
199
|
+
const res = await syncAllRoots(config, { homeDir, timeoutMs, recompile: true });
|
|
200
|
+
for (const w of res.warnings)
|
|
201
|
+
console.warn(c.yellow(`Warning: ${w}`));
|
|
202
|
+
if (!res.ok) {
|
|
203
|
+
for (const e of res.errors)
|
|
204
|
+
printErrorWithHelp(e);
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
console.log(c.green(res.advanced
|
|
208
|
+
? 'Synced remote updates and recompiled L0.'
|
|
209
|
+
: 'Already up to date; L0 compiled.'));
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
if (cmd === 'approve') {
|
|
213
|
+
const config = loadConfig(homeDir);
|
|
214
|
+
const ids = positional;
|
|
215
|
+
if (ids.length === 0) {
|
|
216
|
+
console.error('Usage: faber-memory approve <proposal-id> [...]');
|
|
217
|
+
return 1;
|
|
218
|
+
}
|
|
219
|
+
const proposals = [];
|
|
220
|
+
for (const id of ids) {
|
|
221
|
+
const p = findProposalById(id, homeDir);
|
|
222
|
+
if (!p) {
|
|
223
|
+
console.error(c.red(`Error: Proposal "${id}" not found.`));
|
|
224
|
+
return 1;
|
|
225
|
+
}
|
|
226
|
+
proposals.push(p);
|
|
227
|
+
}
|
|
228
|
+
const modeOverride = flags.mode === 'pr' || flags.mode === 'auto' ? flags.mode : undefined;
|
|
229
|
+
const outcome = await approveProposalsBatch(config, proposals, {
|
|
230
|
+
homeDir,
|
|
231
|
+
teamSubmitModeOverride: modeOverride,
|
|
232
|
+
});
|
|
233
|
+
for (const m of outcome.messages)
|
|
234
|
+
console.log(m);
|
|
235
|
+
if (!outcome.ok) {
|
|
236
|
+
for (const e of outcome.errors)
|
|
237
|
+
printErrorWithHelp(e);
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
return 0;
|
|
241
|
+
}
|
|
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
|
+
}
|
|
262
|
+
const id = positional[0];
|
|
263
|
+
if (!id) {
|
|
264
|
+
console.error('Usage: faber-memory reject <proposal-id> | faber-memory reject --all [--yes]');
|
|
265
|
+
return 1;
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const removed = rejectProposal(id, homeDir);
|
|
269
|
+
console.log(c.green(`Rejected and removed proposal ${removed.id}.`));
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
printErrorWithHelp(err instanceof Error ? err.message : String(err));
|
|
274
|
+
return 1;
|
|
275
|
+
}
|
|
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
|
+
}
|
|
313
|
+
if (cmd === 'review') {
|
|
314
|
+
const config = loadConfig(homeDir);
|
|
315
|
+
const proposals = reconcileAwaitingCommitProposals(homeDir).filter((p) => p.status !== 'awaiting_commit');
|
|
316
|
+
if (proposals.length === 0) {
|
|
317
|
+
console.log('No pending proposals to review.');
|
|
318
|
+
return 0;
|
|
319
|
+
}
|
|
320
|
+
const decisions = new Map();
|
|
321
|
+
if (flags['approve-all']) {
|
|
322
|
+
for (const p of proposals)
|
|
323
|
+
decisions.set(p.id, 'approve');
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
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
|
+
});
|
|
333
|
+
const lineIter = rl[Symbol.asyncIterator]();
|
|
334
|
+
const ask = async (q) => {
|
|
335
|
+
process.stdout.write(q);
|
|
336
|
+
const next = await lineIter.next();
|
|
337
|
+
if (next.done)
|
|
338
|
+
return null;
|
|
339
|
+
return String(next.value);
|
|
340
|
+
};
|
|
341
|
+
const MAX_PREVIEW_LINES = 12;
|
|
342
|
+
try {
|
|
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}`);
|
|
364
|
+
if (p.forceNew && 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)`));
|
|
372
|
+
}
|
|
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;
|
|
408
|
+
if (answer === 'a' || answer === 'approve') {
|
|
409
|
+
decisions.set(p.id, 'approve');
|
|
410
|
+
idx++;
|
|
411
|
+
}
|
|
412
|
+
else if (answer === 'e' || answer === 'edit') {
|
|
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();
|
|
417
|
+
if (newBody) {
|
|
418
|
+
p.body = newBody;
|
|
419
|
+
saveProposal(p, homeDir);
|
|
420
|
+
}
|
|
421
|
+
const confirmRaw = await ask('Approve edited proposal? [y/N]: ');
|
|
422
|
+
if (confirmRaw === null)
|
|
423
|
+
break;
|
|
424
|
+
const confirm = confirmRaw.trim().toLowerCase();
|
|
425
|
+
if (confirm === 'y' || confirm === 'yes') {
|
|
426
|
+
decisions.set(p.id, 'approve');
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
decisions.set(p.id, 'skip');
|
|
430
|
+
}
|
|
431
|
+
idx++;
|
|
432
|
+
}
|
|
433
|
+
else if (answer === 'r' || answer === 'reject') {
|
|
434
|
+
decisions.set(p.id, 'reject');
|
|
435
|
+
idx++;
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
decisions.set(p.id, 'skip');
|
|
439
|
+
idx++;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
rl.close();
|
|
445
|
+
}
|
|
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;
|
|
460
|
+
if (toApprove.length > 0) {
|
|
461
|
+
const outcome = await approveProposalsBatch(config, toApprove, { homeDir });
|
|
462
|
+
for (const m of outcome.messages)
|
|
463
|
+
console.log(m);
|
|
464
|
+
if (!outcome.ok) {
|
|
465
|
+
for (const e of outcome.errors)
|
|
466
|
+
printErrorWithHelp(e);
|
|
467
|
+
exitCode = 1;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
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;
|
|
476
|
+
}
|
|
477
|
+
if (cmd === 'status') {
|
|
478
|
+
const config = loadConfig(homeDir);
|
|
479
|
+
const projectRes = resolveProjectRoot(undefined, process.cwd());
|
|
480
|
+
const loaded = loadAllScopes(config, projectRes);
|
|
481
|
+
const proposals = reconcileAwaitingCommitProposals(homeDir);
|
|
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')})`);
|
|
486
|
+
if (config.roots.team) {
|
|
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'})`);
|
|
488
|
+
}
|
|
489
|
+
if (config.roots.personal) {
|
|
490
|
+
console.log(` Personal root: ${config.roots.personal.path} (HEAD: ${getHeadSha(config.roots.personal.path)?.slice(0, 8) || 'none'})`);
|
|
491
|
+
}
|
|
492
|
+
console.log(` Project root: ${projectRes.projectRoot || 'none'} (source: ${projectRes.source})`);
|
|
493
|
+
if (loaded.uncommittedWarnings.length > 0) {
|
|
494
|
+
console.log(c.yellow('Warnings:'));
|
|
495
|
+
for (const w of loaded.uncommittedWarnings)
|
|
496
|
+
console.log(` - ${w}`);
|
|
497
|
+
}
|
|
498
|
+
const nowMs = Date.now();
|
|
499
|
+
const staleMs = config.staleDays * 24 * 60 * 60 * 1000;
|
|
500
|
+
console.log(`Pending proposals: ${proposals.length}`);
|
|
501
|
+
for (const p of proposals) {
|
|
502
|
+
const ageDays = Math.floor((nowMs - Date.parse(p.createdAt)) / (24 * 60 * 60 * 1000));
|
|
503
|
+
const isStale = nowMs - Date.parse(p.createdAt) > staleMs;
|
|
504
|
+
const flagsList = [p.status];
|
|
505
|
+
if (isStale)
|
|
506
|
+
flagsList.push(`STALE (${ageDays}d > ${config.staleDays}d)`);
|
|
507
|
+
console.log(` - ${p.id} [${p.scope}/${p.action}] (${flagsList.join(', ')}): ${p.summary}`);
|
|
508
|
+
if (p.status === 'awaiting_commit' && p.targetFilePath) {
|
|
509
|
+
console.log(` file: ${p.targetFilePath} — run "git add ${p.targetFilePath} && git commit" to activate`);
|
|
510
|
+
}
|
|
511
|
+
if (p.status === 'push_failed' && p.error) {
|
|
512
|
+
console.log(c.red(` push error: ${p.error}`));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return 0;
|
|
516
|
+
}
|
|
517
|
+
if (cmd === 'import') {
|
|
518
|
+
const config = loadConfig(homeDir);
|
|
519
|
+
const from = flags.from;
|
|
520
|
+
const sourcePath = positional[0];
|
|
521
|
+
if (!from || !sourcePath) {
|
|
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]');
|
|
523
|
+
return 1;
|
|
524
|
+
}
|
|
525
|
+
try {
|
|
526
|
+
const res = await runImport(config, {
|
|
527
|
+
from,
|
|
528
|
+
sourcePath: path.resolve(sourcePath),
|
|
529
|
+
scope: typeof flags.scope === 'string' ? flags.scope : 'personal',
|
|
530
|
+
splitHeadings: Boolean(flags['split-headings']),
|
|
531
|
+
normalizePaths: Boolean(flags['normalize-paths']),
|
|
532
|
+
approve: Boolean(flags.approve),
|
|
533
|
+
homeDir,
|
|
534
|
+
cwd: process.cwd(),
|
|
535
|
+
});
|
|
536
|
+
console.log(c.green(`Staged ${res.staged.length} proposal(s) in pre-memory.`));
|
|
537
|
+
if (res.approvedIds.length > 0) {
|
|
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')}`));
|
|
552
|
+
}
|
|
553
|
+
if (res.duplicates.length > 0) {
|
|
554
|
+
console.log(c.yellow(`Duplicates skipped (${res.duplicates.length}):`));
|
|
555
|
+
for (const d of res.duplicates) {
|
|
556
|
+
console.log(` - ${d.source} matches "${d.matchedId}" (${d.summary})`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (res.skippedHygiene.length > 0) {
|
|
560
|
+
console.log(c.yellow(`Hygiene skipped (${res.skippedHygiene.length}):`));
|
|
561
|
+
for (const s of res.skippedHygiene) {
|
|
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)}`));
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
for (const n of res.notes)
|
|
576
|
+
console.log(n);
|
|
577
|
+
return 0;
|
|
578
|
+
}
|
|
579
|
+
catch (err) {
|
|
580
|
+
printErrorWithHelp(err instanceof Error ? err.message : String(err));
|
|
581
|
+
return 1;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (cmd === 'init') {
|
|
585
|
+
const config = loadConfig(homeDir);
|
|
586
|
+
const apply = Boolean(flags.apply);
|
|
587
|
+
const undo = Boolean(flags.undo);
|
|
588
|
+
const projectHint = Boolean(flags['project-hint']);
|
|
589
|
+
const engines = typeof flags.engine === 'string'
|
|
590
|
+
? flags.engine.split(',').map((e) => e.trim())
|
|
591
|
+
: undefined;
|
|
592
|
+
try {
|
|
593
|
+
const res = planOrApplyInit(config, {
|
|
594
|
+
apply,
|
|
595
|
+
undo,
|
|
596
|
+
engines,
|
|
597
|
+
projectHint,
|
|
598
|
+
homeDir,
|
|
599
|
+
});
|
|
600
|
+
for (const n of res.notes)
|
|
601
|
+
console.log(c.yellow(n));
|
|
602
|
+
for (const p of res.plans) {
|
|
603
|
+
console.log(formatPlanBeforeAfter(p));
|
|
604
|
+
}
|
|
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
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (res.projectHint) {
|
|
612
|
+
console.log(`Project hint: ${res.projectHint}`);
|
|
613
|
+
}
|
|
614
|
+
if (!apply && !undo) {
|
|
615
|
+
console.log(c.yellow('\nDry-run only. Re-run with --apply to write changes.'));
|
|
616
|
+
}
|
|
617
|
+
return 0;
|
|
618
|
+
}
|
|
619
|
+
catch (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);
|
|
628
|
+
return 1;
|
|
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;
|
|
668
|
+
}
|
|
669
|
+
console.error(`Unknown command: ${cmd}`);
|
|
670
|
+
printHelp();
|
|
671
|
+
return 1;
|
|
672
|
+
}
|
|
673
|
+
function printHelp() {
|
|
674
|
+
console.log(`@fabersep/memory (faber-memory)
|
|
675
|
+
|
|
676
|
+
Commands:
|
|
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]
|
|
680
|
+
compile [--check] [--repo <dir>]
|
|
681
|
+
sync [--timeout <ms>]
|
|
682
|
+
status
|
|
683
|
+
stats [--days 1..90] [--json] [--cache] [--engine claude-code|antigravity|all] [--log-dir <path>] [--share]
|
|
684
|
+
doctor [--json] [--strict]
|
|
685
|
+
review [--approve-all]
|
|
686
|
+
approve <proposal-id> [...] [--mode auto|pr]
|
|
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]
|
|
690
|
+
serve
|
|
691
|
+
`);
|
|
692
|
+
}
|
|
693
|
+
main()
|
|
694
|
+
.then((code) => {
|
|
695
|
+
if (code !== 0)
|
|
696
|
+
process.exit(code);
|
|
697
|
+
})
|
|
698
|
+
.catch((err) => {
|
|
699
|
+
printErrorWithHelp(err instanceof Error ? err.message : String(err));
|
|
700
|
+
process.exit(1);
|
|
701
|
+
});
|