bilmem 0.1.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.
@@ -0,0 +1,390 @@
1
+ /**
2
+ * Core type definitions for bilmem:
3
+ * A lightweight, language-independent knowledge and learning runtime for AI agents.
4
+ */
5
+ type Scope = 'global' | 'user' | 'organization' | 'project' | string;
6
+ type KnowledgeType = 'lesson' | 'fact' | 'decision' | 'convention' | 'rule' | 'architecture' | 'question' | 'failure' | 'heuristic';
7
+ type KnowledgeStatus = 'active' | 'candidate' | 'probation' | 'needs_revalidation' | 'stale' | 'contradicted' | 'superseded' | 'invalid' | 'invalidated';
8
+ type KnowledgeStage = 'candidate' | 'probation' | 'active';
9
+ type ConfidenceTier = 'low' | 'medium' | 'high';
10
+ interface Provenance {
11
+ type: 'code' | 'doc' | 'git' | 'user' | 'agent' | 'test' | 'file';
12
+ path?: string;
13
+ line?: number;
14
+ commit?: string;
15
+ author?: string;
16
+ timestamp: string;
17
+ contentHash?: string;
18
+ uri?: string;
19
+ }
20
+ /**
21
+ * An observation made from a source file, commit, agent attempt, or user correction.
22
+ */
23
+ interface Observation {
24
+ id: string;
25
+ source: string;
26
+ claim: string;
27
+ provenance: Provenance;
28
+ confidence: number;
29
+ positive?: string[];
30
+ negative?: string[];
31
+ details?: Record<string, unknown>;
32
+ recordedAt: string;
33
+ }
34
+ /**
35
+ * Evidence node supporting or contradicting claims.
36
+ * Underlying source identity ensures multiple agents reading the same source
37
+ * do NOT count as independent evidence.
38
+ */
39
+ interface Evidence {
40
+ id: string;
41
+ source: string;
42
+ sourceHash: string;
43
+ observationIds: string[];
44
+ type: 'supports' | 'contradicts' | 'observes';
45
+ claim: string;
46
+ provenance: Provenance;
47
+ weight: number;
48
+ firstObservedAt: string;
49
+ lastObservedAt: string;
50
+ }
51
+ type RelationType = 'IMPORTS' | 'DEFINES' | 'REFERENCES' | 'CALLS' | 'TESTS' | 'DOCUMENTS' | 'SUPPORTS' | 'CONTRADICTS' | 'SPECIALIZES' | 'SUPERSEDES' | 'DEPENDS_ON' | 'CO_CHANGED' | 'MOVED';
52
+ interface EvidenceRelation {
53
+ from: string;
54
+ to: string;
55
+ type: RelationType;
56
+ weight?: number;
57
+ metadata?: Record<string, unknown>;
58
+ }
59
+ interface TemporalMetadata {
60
+ revision: number;
61
+ valid_from?: {
62
+ commit?: string;
63
+ timestamp?: string;
64
+ };
65
+ valid_until?: {
66
+ commit?: string;
67
+ timestamp?: string;
68
+ };
69
+ supersedes?: string[];
70
+ }
71
+ interface KnowledgeMetrics {
72
+ reuse_count: number;
73
+ last_used?: string;
74
+ support_count: number;
75
+ contradiction_count: number;
76
+ successful_outcomes: number;
77
+ failed_outcomes: number;
78
+ }
79
+ interface KnowledgeHistoryEntry {
80
+ timestamp: string;
81
+ stage?: KnowledgeStage;
82
+ status: KnowledgeStatus;
83
+ action?: string;
84
+ reason?: string;
85
+ evidenceId?: string;
86
+ source?: string;
87
+ }
88
+ interface KnowledgeOutcomesSummary {
89
+ applied: number;
90
+ successful: number;
91
+ misleading: number;
92
+ neutral: number;
93
+ }
94
+ /**
95
+ * Reusable conclusion supported by evidence.
96
+ */
97
+ interface Knowledge {
98
+ id: string;
99
+ type: KnowledgeType;
100
+ status: KnowledgeStatus;
101
+ stage?: KnowledgeStage;
102
+ statement: string;
103
+ positive: string[];
104
+ negative: string[];
105
+ relations: string[];
106
+ confidence: number;
107
+ confidenceTier?: ConfidenceTier;
108
+ evidence: string[];
109
+ depends_on?: string[];
110
+ resolves?: string[];
111
+ question?: string;
112
+ scope: Scope;
113
+ tags?: string[];
114
+ temporal?: TemporalMetadata;
115
+ metrics: KnowledgeMetrics;
116
+ outcomesSummary?: KnowledgeOutcomesSummary;
117
+ history?: KnowledgeHistoryEntry[];
118
+ value?: number;
119
+ createdAt: string;
120
+ updatedAt: string;
121
+ }
122
+ /**
123
+ * Epistemic Resolution Types.
124
+ */
125
+ type ResolutionState = 'KNOWN' | 'PARTIALLY_KNOWN' | 'UNKNOWN' | 'CONFLICTED' | 'STALE';
126
+ type ResolutionReason = 'NOT_OBSERVED' | 'INSUFFICIENT_EVIDENCE' | 'CONFLICTING_EVIDENCE' | 'STALE_EVIDENCE' | 'UNRESOLVABLE_LOCALLY' | 'CONTEXT_MISMATCH';
127
+ type ActionType = 'USE_KNOWLEDGE' | 'INSPECT_FILE' | 'INSPECT_SYMBOL' | 'INSPECT_TEST' | 'SEARCH_REPOSITORY' | 'CHECK_GIT' | 'CHECK_DOCUMENTATION' | 'ASK_USER' | 'STOP';
128
+ interface NextEvidenceAction {
129
+ type: ActionType;
130
+ target?: string;
131
+ reason: string;
132
+ relativeCost?: number;
133
+ expectedInfoGain?: number;
134
+ }
135
+ interface InvestigationReceipt {
136
+ id: string;
137
+ question: string;
138
+ checked: string[];
139
+ findings: string[];
140
+ rejected: Array<{
141
+ target: string;
142
+ reason: string;
143
+ }>;
144
+ missing: string[];
145
+ next?: NextEvidenceAction;
146
+ status: 'resolved' | 'unresolved';
147
+ timestamp: string;
148
+ gitCommit?: string;
149
+ positive?: string[];
150
+ negative?: string[];
151
+ }
152
+ interface ResolveOptions {
153
+ question: string;
154
+ positive?: string[];
155
+ negative?: string[];
156
+ scope?: Scope;
157
+ limit?: number;
158
+ maxDepth?: number;
159
+ }
160
+ interface ResolutionResult {
161
+ state: ResolutionState;
162
+ reason?: ResolutionReason;
163
+ known: Array<{
164
+ id: string;
165
+ statement: string;
166
+ confidence: number | string;
167
+ confidenceTier?: ConfidenceTier;
168
+ stage?: KnowledgeStage;
169
+ }>;
170
+ applicable: string[];
171
+ rejected: Array<{
172
+ id: string;
173
+ reason: string;
174
+ }>;
175
+ missing: string[];
176
+ checked: string[];
177
+ next?: NextEvidenceAction;
178
+ fallback?: {
179
+ type: 'ask' | 'inspect';
180
+ question?: string;
181
+ target?: string;
182
+ };
183
+ receiptId?: string;
184
+ }
185
+ /**
186
+ * First-class Unknown representation.
187
+ */
188
+ type UnknownState = 'KNOWN' | 'PARTIALLY_KNOWN' | 'UNKNOWN' | 'STALE' | 'CONFLICTED';
189
+ type UnknownReason = 'NOT_OBSERVED' | 'INSUFFICIENT_EVIDENCE' | 'CONFLICTING_EVIDENCE' | 'STALE' | 'UNRESOLVABLE_LOCALLY';
190
+ interface UnknownNextAction {
191
+ type: 'ask' | 'inspect' | 'verify' | 'test';
192
+ question?: string;
193
+ suggestedAction?: string;
194
+ }
195
+ interface UnknownRecord {
196
+ id: string;
197
+ state: UnknownState;
198
+ reason?: UnknownReason;
199
+ statement?: string;
200
+ checked: string[];
201
+ next?: UnknownNextAction;
202
+ scope: Scope;
203
+ createdAt: string;
204
+ updatedAt: string;
205
+ }
206
+ /**
207
+ * Outcome recording whether knowledge application helped or failed.
208
+ */
209
+ type OutcomeType = 'success' | 'failure' | 'reverted' | 'neutral';
210
+ interface OutcomeRecord {
211
+ id: string;
212
+ knowledgeId?: string;
213
+ taskId?: string;
214
+ result: OutcomeType;
215
+ context?: {
216
+ positive?: string[];
217
+ negative?: string[];
218
+ };
219
+ feedback?: string;
220
+ timestamp: string;
221
+ }
222
+ /**
223
+ * Smart knowledge growth classification actions.
224
+ */
225
+ type ReconciliationAction = 'NEW' | 'MERGE' | 'UPDATE' | 'SUPPORT' | 'CONTRADICT' | 'SPECIALIZE' | 'GENERALIZE' | 'IGNORE';
226
+ interface ReconciliationResult {
227
+ action: ReconciliationAction;
228
+ targetId?: string;
229
+ knowledge?: Knowledge;
230
+ reason: string;
231
+ score?: number;
232
+ }
233
+ /**
234
+ * Agent task trajectory event.
235
+ */
236
+ type TrajectoryEventType = 'search' | 'read' | 'hypothesis' | 'attempt' | 'edit' | 'test' | 'failure' | 'revert' | 'success' | 'ask_user' | 'user_correction';
237
+ interface TrajectoryEvent {
238
+ type: TrajectoryEventType;
239
+ description: string;
240
+ path?: string;
241
+ data?: Record<string, unknown>;
242
+ timestamp?: string;
243
+ }
244
+ interface TaskTrajectory {
245
+ taskId: string;
246
+ goal: string;
247
+ events: TrajectoryEvent[];
248
+ startedAt: string;
249
+ completedAt?: string;
250
+ finalOutcome?: OutcomeType;
251
+ }
252
+ /**
253
+ * JEV Matching Result.
254
+ */
255
+ type JevMatchStatus = 'MATCH' | 'POSSIBLE' | 'REJECT';
256
+ interface JevExplanation {
257
+ positiveMatches: string[];
258
+ negativeConflicts: string[];
259
+ score: number;
260
+ confidence: number;
261
+ status: JevMatchStatus;
262
+ reasons: string[];
263
+ }
264
+ interface JevResult {
265
+ knowledge: Knowledge;
266
+ status: JevMatchStatus;
267
+ score: number;
268
+ explanation: JevExplanation;
269
+ }
270
+ interface KnowledgeBudgetConfig {
271
+ active?: number;
272
+ maxCandidates?: number;
273
+ }
274
+ /**
275
+ * Global Bilmem Configuration.
276
+ */
277
+ interface BilmemConfig {
278
+ schemaVersion: number;
279
+ projectName: string;
280
+ defaultScope: Scope;
281
+ lastScanCommit?: string;
282
+ lastScanTimestamp?: string;
283
+ dataDir: string;
284
+ knowledge?: {
285
+ budget?: KnowledgeBudgetConfig;
286
+ };
287
+ }
288
+ /**
289
+ * Aggregated metrics tracked by bilmem.
290
+ */
291
+ interface BilmemMetrics {
292
+ knowledgeHits: number;
293
+ knowledgeMisses: number;
294
+ knowledgeReused: number;
295
+ unknownsResolved: number;
296
+ repeatedInvestigationsPrevented: number;
297
+ candidateKnowledgeMerged: number;
298
+ staleKnowledgeDetected: number;
299
+ contradictionsDetected: number;
300
+ knowledgePromoted: number;
301
+ knowledgeSuperseded: number;
302
+ }
303
+ /**
304
+ * Conditions evaluated by the rule engine during scanning.
305
+ */
306
+ interface RuleCondition {
307
+ has_file?: string | string[];
308
+ missing_file?: string | string[];
309
+ any_file?: string[];
310
+ file_pattern?: string;
311
+ content_match?: {
312
+ files?: string;
313
+ pattern: string;
314
+ };
315
+ }
316
+ /**
317
+ * Definition of a single rule in a RuleSet.
318
+ */
319
+ interface RuleDefinition {
320
+ id: string;
321
+ name?: string;
322
+ statement: string;
323
+ type?: KnowledgeType;
324
+ confidence?: number;
325
+ scope?: Scope;
326
+ positive?: string[];
327
+ negative?: string[];
328
+ when?: RuleCondition;
329
+ details?: Record<string, unknown>;
330
+ tags?: string[];
331
+ }
332
+ /**
333
+ * A bundle of rules defined in a YAML file.
334
+ */
335
+ interface RuleSet {
336
+ name?: string;
337
+ version?: number | string;
338
+ scope?: Scope;
339
+ description?: string;
340
+ rules: RuleDefinition[];
341
+ }
342
+ /**
343
+ * Result of evaluating a rule against repository context.
344
+ */
345
+ interface EvaluatedRule {
346
+ rule: RuleDefinition;
347
+ matched: boolean;
348
+ reason?: string;
349
+ matchedFiles?: string[];
350
+ }
351
+ /**
352
+ * Summary diff representing incremental learning changes.
353
+ */
354
+ interface KnowledgeDiff {
355
+ sinceRef?: string;
356
+ observationsAdded: number;
357
+ candidatesAdded: number;
358
+ strengthenedCount: number;
359
+ revisedCount: number;
360
+ contradictionCount: number;
361
+ unknownsCount?: number;
362
+ needsRevalidationCount?: number;
363
+ invalidatedCount: number;
364
+ details?: {
365
+ strengthened?: string[];
366
+ revised?: string[];
367
+ contradictions?: string[];
368
+ unknowns?: string[];
369
+ needsRevalidation?: string[];
370
+ invalidated?: string[];
371
+ };
372
+ }
373
+ /**
374
+ * Point-in-time snapshot of repository knowledge state.
375
+ */
376
+ interface RevisionSnapshot {
377
+ id: string;
378
+ commit?: string;
379
+ timestamp: string;
380
+ action: 'scan' | 'learn' | 'compact' | 'init' | string;
381
+ observationCount: number;
382
+ evidenceCount: number;
383
+ knowledgeCount: number;
384
+ activeCount: number;
385
+ contradictedCount: number;
386
+ staleCount: number;
387
+ changesSummary?: string;
388
+ }
389
+
390
+ export type { ActionType as A, BilmemConfig as B, ConfidenceTier as C, TrajectoryEvent as D, EvaluatedRule as E, TrajectoryEventType as F, UnknownNextAction as G, UnknownReason as H, InvestigationReceipt as I, JevResult as J, Knowledge as K, UnknownState as L, NextEvidenceAction as N, OutcomeType as O, Provenance as P, ResolveOptions as R, Scope as S, TaskTrajectory as T, UnknownRecord as U, ResolutionResult as a, BilmemMetrics as b, Evidence as c, EvidenceRelation as d, JevExplanation as e, JevMatchStatus as f, KnowledgeBudgetConfig as g, KnowledgeDiff as h, KnowledgeHistoryEntry as i, KnowledgeMetrics as j, KnowledgeOutcomesSummary as k, KnowledgeStage as l, KnowledgeStatus as m, KnowledgeType as n, Observation as o, OutcomeRecord as p, ReconciliationAction as q, ReconciliationResult as r, RelationType as s, ResolutionReason as t, ResolutionState as u, RevisionSnapshot as v, RuleCondition as w, RuleDefinition as x, RuleSet as y, TemporalMetadata as z };
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "bilmem",
3
+ "version": "0.1.0",
4
+ "description": "Lightweight, language-independent knowledge and learning runtime for AI agents and developer tooling",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "bilmem": "./dist/cli/index.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./core": {
17
+ "types": "./dist/core/index.d.ts",
18
+ "import": "./dist/core/index.js"
19
+ },
20
+ "./jev": {
21
+ "types": "./dist/jev/index.d.ts",
22
+ "import": "./dist/jev/index.js"
23
+ },
24
+ "./search": {
25
+ "types": "./dist/search/index.d.ts",
26
+ "import": "./dist/search/index.js"
27
+ },
28
+ "./storage": {
29
+ "types": "./dist/storage/index.d.ts",
30
+ "import": "./dist/storage/index.js"
31
+ },
32
+ "./scanner": {
33
+ "types": "./dist/scanner/index.d.ts",
34
+ "import": "./dist/scanner/index.js"
35
+ },
36
+ "./mcp": {
37
+ "types": "./dist/mcp/index.d.ts",
38
+ "import": "./dist/mcp/index.js"
39
+ },
40
+ "./install": {
41
+ "types": "./dist/install/index.d.ts",
42
+ "import": "./dist/install/index.js"
43
+ },
44
+ "./stats": {
45
+ "types": "./dist/stats/index.d.ts",
46
+ "import": "./dist/stats/index.js"
47
+ }
48
+ },
49
+ "scripts": {
50
+ "prebuild": "npm run typecheck",
51
+ "build": "tsup",
52
+ "dev": "tsup --watch",
53
+ "test": "vitest run",
54
+ "test:watch": "vitest",
55
+ "typecheck": "tsc --noEmit"
56
+ },
57
+ "dependencies": {
58
+ "@orama/orama": "^3.1.18",
59
+ "commander": "^13.1.0",
60
+ "mcponce": "^0.2.3",
61
+ "tree-sitter-wasms": "^0.1.13",
62
+ "web-tree-sitter": "^0.22.6",
63
+ "yaml": "^2.7.0"
64
+ },
65
+ "devDependencies": {
66
+ "@types/node": "^20.17.19",
67
+ "tsup": "^8.3.6",
68
+ "typescript": "^5.7.3",
69
+ "vitest": "^2.1.8"
70
+ }
71
+ }