@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.
Files changed (43) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +399 -2
  3. package/dist/src/bm25.d.ts +26 -0
  4. package/dist/src/bm25.js +183 -0
  5. package/dist/src/cache-logs.d.ts +47 -0
  6. package/dist/src/cache-logs.js +433 -0
  7. package/dist/src/cli.d.ts +2 -0
  8. package/dist/src/cli.js +701 -0
  9. package/dist/src/compiler.d.ts +23 -0
  10. package/dist/src/compiler.js +211 -0
  11. package/dist/src/config.d.ts +20 -0
  12. package/dist/src/config.js +134 -0
  13. package/dist/src/doctor.d.ts +23 -0
  14. package/dist/src/doctor.js +447 -0
  15. package/dist/src/frontmatter.d.ts +22 -0
  16. package/dist/src/frontmatter.js +199 -0
  17. package/dist/src/git.d.ts +33 -0
  18. package/dist/src/git.js +251 -0
  19. package/dist/src/hygiene.d.ts +7 -0
  20. package/dist/src/hygiene.js +89 -0
  21. package/dist/src/importer.d.ts +34 -0
  22. package/dist/src/importer.js +261 -0
  23. package/dist/src/index.d.ts +18 -0
  24. package/dist/src/index.js +18 -0
  25. package/dist/src/init.d.ts +43 -0
  26. package/dist/src/init.js +280 -0
  27. package/dist/src/mcp.d.ts +218 -0
  28. package/dist/src/mcp.js +437 -0
  29. package/dist/src/metrics.d.ts +72 -0
  30. package/dist/src/metrics.js +179 -0
  31. package/dist/src/proposals.d.ts +34 -0
  32. package/dist/src/proposals.js +420 -0
  33. package/dist/src/stats.d.ts +165 -0
  34. package/dist/src/stats.js +579 -0
  35. package/dist/src/store.d.ts +23 -0
  36. package/dist/src/store.js +161 -0
  37. package/dist/src/sync.d.ts +15 -0
  38. package/dist/src/sync.js +47 -0
  39. package/dist/src/types.d.ts +100 -0
  40. package/dist/src/types.js +17 -0
  41. package/dist/src/ui.d.ts +19 -0
  42. package/dist/src/ui.js +74 -0
  43. package/package.json +50 -4
@@ -0,0 +1,34 @@
1
+ import { EntryType, L0Mode, Proposal, ProposalAction, Scope, TeamSubmitMode, UserConfig } from './types.js';
2
+ export declare const CACHE_GUIDANCE_NOTE = "Note: Updated L0 applies to new sessions; batching reviews at session end maximizes prompt-cache reuse.";
3
+ export declare function saveProposal(proposal: Proposal, homeDir?: string): string;
4
+ export declare function deleteProposal(proposal: Proposal, homeDir?: string): void;
5
+ export declare function listAllProposals(homeDir?: string): Proposal[];
6
+ export declare function reconcileAwaitingCommitProposals(homeDir?: string): Proposal[];
7
+ export declare function findProposalById(id: string, homeDir?: string): Proposal | null;
8
+ export declare function createProposal(config: UserConfig, input: {
9
+ scope: Scope;
10
+ action: ProposalAction;
11
+ entryId?: string;
12
+ targetId?: string;
13
+ summary: string;
14
+ type: EntryType;
15
+ tags?: string[];
16
+ l0?: L0Mode;
17
+ body: string;
18
+ forceNew?: boolean;
19
+ reason?: string;
20
+ projectRootPath?: string;
21
+ }, homeDir?: string): Proposal;
22
+ export declare function rejectProposal(id: string, homeDir?: string): Proposal;
23
+ export interface ApproveOutcome {
24
+ ok: boolean;
25
+ approvedIds: string[];
26
+ messages: string[];
27
+ errors: string[];
28
+ compareUrl?: string;
29
+ recompiledL0?: boolean;
30
+ }
31
+ export declare function approveProposalsBatch(config: UserConfig, proposals: Proposal[], options?: {
32
+ homeDir?: string;
33
+ teamSubmitModeOverride?: TeamSubmitMode;
34
+ }): Promise<ApproveOutcome>;
@@ -0,0 +1,420 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { generateProposalId, getAllPreMemoryBaseDir, getHomeDir, getPreMemoryRootDir, getProjectRootUuid, withStateLock, } from './config.js';
4
+ import { compileGlobalL0 } from './compiler.js';
5
+ import { parseMarkdownWithFrontmatter, serializeEntryMarkdown, slugify, } from './frontmatter.js';
6
+ import { buildCompareUrl, createThrowawayWorktree, getDefaultBranch, getRemoteUrl, gitCommitFiles, gitPullFfOnly, gitSync, isBranchProtectionRejection, readHeadFile, removeThrowawayWorktree, } from './git.js';
7
+ import { formatHygieneErrors, scanHygiene } from './hygiene.js';
8
+ import { appendMetric } from './metrics.js';
9
+ import { PROJECT_MEMORY_REL_DIR } from './store.js';
10
+ export const CACHE_GUIDANCE_NOTE = 'Note: Updated L0 applies to new sessions; batching reviews at session end maximizes prompt-cache reuse.';
11
+ export function saveProposal(proposal, homeDir = getHomeDir()) {
12
+ const dir = getPreMemoryRootDir(proposal.rootUuid, homeDir);
13
+ fs.mkdirSync(dir, { recursive: true });
14
+ const filePath = path.join(dir, `${proposal.id}.json`);
15
+ fs.writeFileSync(filePath, JSON.stringify(proposal, null, 2) + '\n', 'utf8');
16
+ return filePath;
17
+ }
18
+ export function deleteProposal(proposal, homeDir = getHomeDir()) {
19
+ const filePath = path.join(getPreMemoryRootDir(proposal.rootUuid, homeDir), `${proposal.id}.json`);
20
+ if (fs.existsSync(filePath)) {
21
+ fs.unlinkSync(filePath);
22
+ }
23
+ }
24
+ export function listAllProposals(homeDir = getHomeDir()) {
25
+ const baseDir = getAllPreMemoryBaseDir(homeDir);
26
+ if (!fs.existsSync(baseDir))
27
+ return [];
28
+ const proposals = [];
29
+ for (const rootUuid of fs.readdirSync(baseDir)) {
30
+ const rootDir = path.join(baseDir, rootUuid);
31
+ if (!fs.statSync(rootDir).isDirectory())
32
+ continue;
33
+ for (const file of fs.readdirSync(rootDir)) {
34
+ if (!file.endsWith('.json'))
35
+ continue;
36
+ try {
37
+ const raw = JSON.parse(fs.readFileSync(path.join(rootDir, file), 'utf8'));
38
+ proposals.push(raw);
39
+ }
40
+ catch {
41
+ // Skip malformed file
42
+ }
43
+ }
44
+ }
45
+ proposals.sort((a, b) => (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0));
46
+ return proposals;
47
+ }
48
+ export function reconcileAwaitingCommitProposals(homeDir = getHomeDir()) {
49
+ const all = listAllProposals(homeDir);
50
+ const remaining = [];
51
+ for (const p of all) {
52
+ if (p.status === 'awaiting_commit' && p.projectRootPath && p.targetFilePath) {
53
+ const committed = readHeadFile(p.projectRootPath, p.targetFilePath);
54
+ if (committed !== null) {
55
+ deleteProposal(p, homeDir);
56
+ continue;
57
+ }
58
+ }
59
+ remaining.push(p);
60
+ }
61
+ return remaining;
62
+ }
63
+ export function findProposalById(id, homeDir = getHomeDir()) {
64
+ const all = reconcileAwaitingCommitProposals(homeDir);
65
+ return all.find((p) => p.id === id) || null;
66
+ }
67
+ export function createProposal(config, input, homeDir = getHomeDir()) {
68
+ let rootUuid;
69
+ if (input.scope === 'personal') {
70
+ if (!config.roots.personal) {
71
+ throw new Error('Personal memory root is not configured.');
72
+ }
73
+ rootUuid = config.roots.personal.uuid;
74
+ }
75
+ else if (input.scope === 'team') {
76
+ if (!config.roots.team) {
77
+ throw new Error('Team memory root is not configured.');
78
+ }
79
+ rootUuid = config.roots.team.uuid;
80
+ }
81
+ else {
82
+ if (!input.projectRootPath) {
83
+ throw new Error('Project scope requires an active project root.');
84
+ }
85
+ rootUuid = getProjectRootUuid(input.projectRootPath);
86
+ }
87
+ const entryId = input.action === 'update' && input.targetId
88
+ ? input.targetId
89
+ : input.entryId
90
+ ? slugify(input.entryId)
91
+ : slugify(input.summary);
92
+ const proposal = {
93
+ id: generateProposalId(config.userTag),
94
+ rootUuid,
95
+ scope: input.scope,
96
+ action: input.action,
97
+ entryId,
98
+ targetId: input.targetId,
99
+ summary: input.summary.replace(/\s+/g, ' ').trim(),
100
+ type: input.type,
101
+ tags: input.tags || [],
102
+ l0: input.l0,
103
+ body: input.body.trim(),
104
+ forceNew: input.forceNew,
105
+ reason: input.reason,
106
+ status: 'pending',
107
+ createdAt: new Date().toISOString(),
108
+ projectRootPath: input.projectRootPath,
109
+ };
110
+ saveProposal(proposal, homeDir);
111
+ return proposal;
112
+ }
113
+ export function rejectProposal(id, homeDir = getHomeDir()) {
114
+ const proposal = findProposalById(id, homeDir);
115
+ if (!proposal) {
116
+ throw new Error(`Proposal "${id}" not found in pre-memory.`);
117
+ }
118
+ deleteProposal(proposal, homeDir);
119
+ appendMetric({
120
+ type: 'review_outcome',
121
+ ts: new Date().toISOString(),
122
+ scope: proposal.scope,
123
+ outcome: 'rejected',
124
+ }, homeDir);
125
+ return proposal;
126
+ }
127
+ function applyProposalFilesToDir(repoDir, subDir, proposal) {
128
+ const touched = [];
129
+ const targetDir = subDir ? path.join(repoDir, subDir) : repoDir;
130
+ fs.mkdirSync(targetDir, { recursive: true });
131
+ const relEntryPath = subDir
132
+ ? path.posix.join(subDir, `${proposal.entryId}.md`)
133
+ : `${proposal.entryId}.md`;
134
+ const absEntryPath = path.join(repoDir, relEntryPath);
135
+ const markdown = serializeEntryMarkdown({
136
+ summary: proposal.summary,
137
+ type: proposal.type,
138
+ tags: proposal.tags,
139
+ status: 'active',
140
+ l0: proposal.l0 || (proposal.scope === 'project' ? 'none' : 'line'),
141
+ }, proposal.body);
142
+ fs.writeFileSync(absEntryPath, markdown, 'utf8');
143
+ touched.push(relEntryPath);
144
+ if (proposal.action === 'supersede' && proposal.targetId && proposal.targetId !== proposal.entryId) {
145
+ const targetRel = subDir
146
+ ? path.posix.join(subDir, `${proposal.targetId}.md`)
147
+ : `${proposal.targetId}.md`;
148
+ const targetAbs = path.join(repoDir, targetRel);
149
+ if (fs.existsSync(targetAbs)) {
150
+ const existingRaw = fs.readFileSync(targetAbs, 'utf8');
151
+ const parsed = parseMarkdownWithFrontmatter(existingRaw);
152
+ const oldSummary = typeof parsed.rawFrontmatter.summary === 'string'
153
+ ? parsed.rawFrontmatter.summary
154
+ : proposal.targetId;
155
+ const oldType = typeof parsed.rawFrontmatter.type === 'string'
156
+ ? parsed.rawFrontmatter.type
157
+ : 'rule';
158
+ const oldTags = Array.isArray(parsed.rawFrontmatter.tags)
159
+ ? parsed.rawFrontmatter.tags.map(String)
160
+ : [];
161
+ const updatedOld = serializeEntryMarkdown({
162
+ summary: oldSummary,
163
+ type: oldType,
164
+ tags: oldTags,
165
+ status: 'superseded',
166
+ superseded_by: proposal.entryId,
167
+ l0: 'none',
168
+ }, parsed.body);
169
+ fs.writeFileSync(targetAbs, updatedOld, 'utf8');
170
+ touched.push(targetRel);
171
+ }
172
+ }
173
+ return touched;
174
+ }
175
+ export async function approveProposalsBatch(config, proposals, options = {}) {
176
+ const homeDir = options.homeDir || getHomeDir();
177
+ const messages = [];
178
+ const errors = [];
179
+ const approvedIds = [];
180
+ let compareUrl;
181
+ let recompiledL0 = false;
182
+ if (proposals.length === 0) {
183
+ return { ok: true, approvedIds: [], messages: ['No proposals to approve.'], errors: [] };
184
+ }
185
+ // Hygiene check every proposal first (AC-20b1)
186
+ for (const p of proposals) {
187
+ const findings = scanHygiene(`${p.summary}\n${p.body}`);
188
+ if (findings.length > 0) {
189
+ errors.push(formatHygieneErrors(findings, `proposal ${p.id}`));
190
+ }
191
+ }
192
+ if (errors.length > 0) {
193
+ return { ok: false, approvedIds: [], messages: [], errors };
194
+ }
195
+ // Group by scope
196
+ const byScope = new Map();
197
+ for (const p of proposals) {
198
+ const list = byScope.get(p.scope) || [];
199
+ list.push(p);
200
+ byScope.set(p.scope, list);
201
+ }
202
+ // 1. Personal scope: single commit + single L0 recompile
203
+ const personalProps = byScope.get('personal') || [];
204
+ if (personalProps.length > 0) {
205
+ const root = config.roots.personal;
206
+ if (!root) {
207
+ errors.push('Personal memory root is not configured.');
208
+ return { ok: false, approvedIds, messages, errors };
209
+ }
210
+ const touched = [];
211
+ for (const p of personalProps) {
212
+ touched.push(...applyProposalFilesToDir(root.path, '', p));
213
+ }
214
+ const commitMsg = personalProps.length === 1
215
+ ? `memory(${personalProps[0].action}): ${personalProps[0].entryId} [${personalProps[0].id}]`
216
+ : `memory(batch): approve ${personalProps.length} proposals (${personalProps.map((p) => p.id).join(', ')})`;
217
+ gitCommitFiles(root.path, touched, commitMsg);
218
+ for (const p of personalProps) {
219
+ deleteProposal(p, homeDir);
220
+ approvedIds.push(p.id);
221
+ appendMetric({
222
+ type: 'review_outcome',
223
+ ts: new Date().toISOString(),
224
+ scope: 'personal',
225
+ outcome: 'approved_committed',
226
+ }, homeDir);
227
+ }
228
+ const comp = compileGlobalL0(config, { homeDir, trigger: 'approve' });
229
+ if (!comp.ok) {
230
+ errors.push(...comp.errors);
231
+ return { ok: false, approvedIds, messages, errors };
232
+ }
233
+ recompiledL0 = true;
234
+ messages.push(`Approved ${personalProps.length} personal proposal(s) in 1 commit and recompiled L0 (${comp.estimatedTokens}/${comp.budget} tokens).`);
235
+ }
236
+ // 2. Project scope: write uncommitted file(s) and mark awaiting_commit
237
+ const projectProps = byScope.get('project') || [];
238
+ if (projectProps.length > 0) {
239
+ for (const p of projectProps) {
240
+ if (!p.projectRootPath) {
241
+ errors.push(`Project proposal ${p.id} is missing projectRootPath.`);
242
+ continue;
243
+ }
244
+ const touched = applyProposalFilesToDir(p.projectRootPath, PROJECT_MEMORY_REL_DIR, p);
245
+ p.status = 'awaiting_commit';
246
+ p.targetFilePath = touched[0];
247
+ saveProposal(p, homeDir);
248
+ approvedIds.push(p.id);
249
+ appendMetric({
250
+ type: 'review_outcome',
251
+ ts: new Date().toISOString(),
252
+ scope: 'project',
253
+ outcome: 'awaiting_commit',
254
+ }, homeDir);
255
+ messages.push(`Staged project memory file ${touched[0]} (uncommitted). Run: git add ${touched.join(' ')} && git commit -m "memory: ${p.entryId}"`);
256
+ }
257
+ if (errors.length > 0) {
258
+ return { ok: false, approvedIds, messages, errors };
259
+ }
260
+ }
261
+ // 3. Team scope: throwaway git worktree from origin/<defaultBranch>
262
+ const teamProps = byScope.get('team') || [];
263
+ if (teamProps.length > 0) {
264
+ const root = config.roots.team;
265
+ if (!root) {
266
+ errors.push('Team memory root is not configured.');
267
+ return { ok: false, approvedIds, messages, errors };
268
+ }
269
+ const res = await approveTeamBatch(config, root, teamProps, homeDir, options.teamSubmitModeOverride);
270
+ if (!res.ok) {
271
+ errors.push(...res.errors);
272
+ return { ok: false, approvedIds, messages, errors };
273
+ }
274
+ approvedIds.push(...res.approvedIds);
275
+ messages.push(...res.messages);
276
+ if (res.compareUrl)
277
+ compareUrl = res.compareUrl;
278
+ if (res.recompiledL0)
279
+ recompiledL0 = true;
280
+ }
281
+ if (recompiledL0) {
282
+ messages.push(CACHE_GUIDANCE_NOTE);
283
+ }
284
+ return {
285
+ ok: true,
286
+ approvedIds,
287
+ messages,
288
+ errors: [],
289
+ compareUrl,
290
+ recompiledL0,
291
+ };
292
+ }
293
+ async function approveTeamBatch(config, root, teamProps, homeDir, overrideMode) {
294
+ const defaultBranch = root.defaultBranch || getDefaultBranch(root.path);
295
+ const submitMode = overrideMode || root.submitMode || 'auto';
296
+ const branchName = teamProps.length === 1
297
+ ? `memory/proposal-${teamProps[0].id}`
298
+ : `memory/proposal-${teamProps[0].id}-batch`;
299
+ let worktreeDir = null;
300
+ try {
301
+ worktreeDir = createThrowawayWorktree(root.path, defaultBranch);
302
+ const touched = [];
303
+ for (const p of teamProps) {
304
+ touched.push(...applyProposalFilesToDir(worktreeDir, '', p));
305
+ }
306
+ const commitMsg = teamProps.length === 1
307
+ ? `memory(${teamProps[0].action}): ${teamProps[0].entryId} [${teamProps[0].id}]`
308
+ : `memory(batch): approve ${teamProps.length} proposals (${teamProps.map((p) => p.id).join(', ')})`;
309
+ gitCommitFiles(worktreeDir, touched, commitMsg);
310
+ const remoteUrl = root.remote || getRemoteUrl(root.path);
311
+ if (submitMode === 'auto') {
312
+ const directPush = gitSync(['-C', worktreeDir, 'push', 'origin', `HEAD:${defaultBranch}`]);
313
+ if (directPush.ok) {
314
+ for (const p of teamProps) {
315
+ deleteProposal(p, homeDir);
316
+ appendMetric({
317
+ type: 'review_outcome',
318
+ ts: new Date().toISOString(),
319
+ scope: 'team',
320
+ outcome: 'approved_pushed',
321
+ }, homeDir);
322
+ }
323
+ // Sync serving clone & recompile L0
324
+ const pull = await gitPullFfOnly(root.path, 5000);
325
+ let recompiledL0 = false;
326
+ if (pull.ok) {
327
+ const comp = compileGlobalL0(config, { homeDir, trigger: 'approve' });
328
+ if (comp.ok)
329
+ recompiledL0 = true;
330
+ }
331
+ return {
332
+ ok: true,
333
+ approvedIds: teamProps.map((p) => p.id),
334
+ messages: [
335
+ `Pushed ${teamProps.length} team proposal(s) directly to origin/${defaultBranch} and synced local L0.`,
336
+ ],
337
+ errors: [],
338
+ recompiledL0,
339
+ };
340
+ }
341
+ if (!isBranchProtectionRejection(directPush.stderr)) {
342
+ markPushFailed(teamProps, directPush.stderr.trim() || 'git push failed', homeDir);
343
+ return {
344
+ ok: false,
345
+ approvedIds: [],
346
+ messages: [],
347
+ errors: [`Team push failed: ${directPush.stderr.trim() || 'unknown remote error'}`],
348
+ };
349
+ }
350
+ // Fall through to PR branch push on branch protection rejection
351
+ }
352
+ const prPush = gitSync([
353
+ '-C',
354
+ worktreeDir,
355
+ 'push',
356
+ 'origin',
357
+ `HEAD:refs/heads/${branchName}`,
358
+ ]);
359
+ if (!prPush.ok) {
360
+ markPushFailed(teamProps, prPush.stderr.trim() || 'git push branch failed', homeDir);
361
+ return {
362
+ ok: false,
363
+ approvedIds: [],
364
+ messages: [],
365
+ errors: [`Team PR branch push failed: ${prPush.stderr.trim() || 'unknown remote error'}`],
366
+ };
367
+ }
368
+ const compareUrl = buildCompareUrl(remoteUrl, defaultBranch, branchName);
369
+ for (const p of teamProps) {
370
+ deleteProposal(p, homeDir);
371
+ appendMetric({
372
+ type: 'review_outcome',
373
+ ts: new Date().toISOString(),
374
+ scope: 'team',
375
+ outcome: 'approved_pr',
376
+ }, homeDir);
377
+ }
378
+ return {
379
+ ok: true,
380
+ approvedIds: teamProps.map((p) => p.id),
381
+ messages: [
382
+ `Pushed branch ${branchName} to remote.`,
383
+ `Create PR: ${compareUrl}`,
384
+ ],
385
+ errors: [],
386
+ compareUrl,
387
+ recompiledL0: false,
388
+ };
389
+ }
390
+ catch (err) {
391
+ const msg = err instanceof Error ? err.message : String(err);
392
+ markPushFailed(teamProps, msg, homeDir);
393
+ return {
394
+ ok: false,
395
+ approvedIds: [],
396
+ messages: [],
397
+ errors: [`Team approval failed: ${msg}`],
398
+ };
399
+ }
400
+ finally {
401
+ if (worktreeDir) {
402
+ removeThrowawayWorktree(root.path, worktreeDir);
403
+ }
404
+ }
405
+ }
406
+ function markPushFailed(proposals, error, homeDir) {
407
+ withStateLock(() => {
408
+ for (const p of proposals) {
409
+ p.status = 'push_failed';
410
+ p.error = error;
411
+ saveProposal(p, homeDir);
412
+ appendMetric({
413
+ type: 'review_outcome',
414
+ ts: new Date().toISOString(),
415
+ scope: p.scope,
416
+ outcome: 'push_failed',
417
+ }, homeDir);
418
+ }
419
+ }, homeDir);
420
+ }
@@ -0,0 +1,165 @@
1
+ import { CacheAnalysisResult, CacheEngineOption } from './cache-logs.js';
2
+ export declare const STATS_SCHEMA_VERSION = 1;
3
+ export declare const MCP_SCHEMA_TOKEN_TARGET = 500;
4
+ export declare const STALE_VERIFIED_DAYS = 90;
5
+ export declare const L0_CHURN_WARN_THRESHOLD = 5;
6
+ export declare function getPackageVersion(): string;
7
+ export declare function validateDaysArg(raw: unknown): {
8
+ ok: true;
9
+ days: number;
10
+ } | {
11
+ ok: false;
12
+ error: string;
13
+ };
14
+ export interface StatsReport {
15
+ schemaVersion: number;
16
+ packageVersion: string;
17
+ configured: boolean;
18
+ windowDays: number;
19
+ ledger: {
20
+ exists: boolean;
21
+ coverageDays: number;
22
+ totalEvents: number;
23
+ windowEvents: number;
24
+ skippedLines: number;
25
+ };
26
+ corpus: {
27
+ activeEntries: number;
28
+ l0Entries: number;
29
+ corpusTokens: number;
30
+ l0Tokens: number;
31
+ tokenBudget: number;
32
+ reductionPct: number;
33
+ budgetUtilizationPct: number;
34
+ projectActiveEntries?: number;
35
+ projectTokens?: number;
36
+ };
37
+ mcpSchema: {
38
+ tokens: number;
39
+ target: number;
40
+ toolCount: number;
41
+ };
42
+ l0Stability: {
43
+ changesLast7Days: number;
44
+ changesInWindow: number;
45
+ churnWarning: boolean;
46
+ };
47
+ retrieval: {
48
+ nonEmptySearches: number;
49
+ emptySearches: number;
50
+ getCalls: number;
51
+ getCallsPerSearch: number;
52
+ zeroResultCount: number;
53
+ zeroResultPct: number;
54
+ medianBm25LatencyMs: number | null;
55
+ };
56
+ entryTemperature: {
57
+ hotEntries: {
58
+ id: string;
59
+ hits: number;
60
+ }[];
61
+ coldWithheld: boolean;
62
+ coldWithheldReason?: string;
63
+ coldL0Entries: string[];
64
+ staleL0Entries: {
65
+ id: string;
66
+ lastVerified: string;
67
+ ageDays: number;
68
+ }[];
69
+ unverifiedL0Entries: string[];
70
+ };
71
+ funnel: {
72
+ bySource: {
73
+ mcp: {
74
+ staged: number;
75
+ duplicateBlocked: number;
76
+ hygieneBlockedSecret: number;
77
+ hygieneBlockedMachinePath: number;
78
+ validationError: number;
79
+ };
80
+ import: {
81
+ staged: number;
82
+ duplicateBlocked: number;
83
+ hygieneBlockedSecret: number;
84
+ hygieneBlockedMachinePath: number;
85
+ validationError: number;
86
+ };
87
+ };
88
+ reviewOutcomes: {
89
+ approvedCommitted: number;
90
+ approvedPushed: number;
91
+ approvedPr: number;
92
+ pushFailed: number;
93
+ awaitingCommit: number;
94
+ rejected: number;
95
+ };
96
+ };
97
+ cache?: CacheAnalysisResult;
98
+ }
99
+ export interface ShareableBenchmarkJson {
100
+ schemaVersion: number;
101
+ packageVersion: string;
102
+ windowDays: number;
103
+ corpus: {
104
+ activeEntries: number;
105
+ l0Entries: number;
106
+ corpusTokens: number;
107
+ l0Tokens: number;
108
+ tokenBudget: number;
109
+ reductionPct: number;
110
+ budgetUtilizationPct: number;
111
+ };
112
+ mcpSchemaTokens: number;
113
+ l0Stability: {
114
+ changesLast7Days: number;
115
+ changesInWindow: number;
116
+ };
117
+ retrieval: {
118
+ nonEmptySearches: number;
119
+ getCalls: number;
120
+ getCallsPerSearch: number;
121
+ zeroResultCount: number;
122
+ zeroResultPct: number;
123
+ medianBm25LatencyMs: number | null;
124
+ };
125
+ funnel: {
126
+ proposedMcp: number;
127
+ proposedImport: number;
128
+ staged: number;
129
+ duplicateBlocked: number;
130
+ hygieneBlockedSecret: number;
131
+ hygieneBlockedMachinePath: number;
132
+ validationError: number;
133
+ approvedCommitted: number;
134
+ approvedPushed: number;
135
+ approvedPr: number;
136
+ pushFailed: number;
137
+ awaitingCommit: number;
138
+ rejected: number;
139
+ };
140
+ cache?: Partial<Record<'claude-code' | 'antigravity', {
141
+ sessions: number;
142
+ steps: number;
143
+ firstStepHitPct: number;
144
+ warmStepHitPct: number;
145
+ eligibleSessions?: number;
146
+ correlatedBreaks?: number;
147
+ }>>;
148
+ }
149
+ export declare function computeStats(options?: {
150
+ days?: number;
151
+ includeCache?: boolean;
152
+ engine?: CacheEngineOption;
153
+ logDir?: string;
154
+ homeDir?: string;
155
+ userHome?: string;
156
+ cwd?: string;
157
+ nowMs?: number;
158
+ }): StatsReport;
159
+ /**
160
+ * Closed allowlist serializer for `faber-memory stats --share`.
161
+ * Never includes paths, repo names, entry IDs, proposal IDs, model names, or summaries.
162
+ */
163
+ export declare function buildShareableBenchmark(report: StatsReport): ShareableBenchmarkJson;
164
+ export declare function formatShareableMarkdown(card: ShareableBenchmarkJson): string;
165
+ export declare function formatStatsReport(report: StatsReport): string;