@senselab-ai/amfs 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/adapter.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * AmfsAdapter — interface that every TS adapter must implement.
3
3
  */
4
- import type { MemoryEntry, OutcomeRecord } from "./models.js";
4
+ import type { MemoryEntry, OutcomeRecord, Commit } from "./models.js";
5
5
  export interface WatchHandle {
6
6
  cancel(): void;
7
7
  readonly cancelled: boolean;
@@ -16,5 +16,9 @@ export interface AmfsAdapter {
16
16
  }): MemoryEntry[];
17
17
  watch(entityPath: string, callback: (entry: MemoryEntry) => void): WatchHandle;
18
18
  commitOutcome(record: OutcomeRecord): MemoryEntry[];
19
+ listCommits?(options?: {
20
+ limit?: number;
21
+ }): Commit[];
22
+ getCommit?(commitId: string): Commit | null;
19
23
  }
20
24
  export declare function createWatchHandle(cancelFn: () => void): WatchHandle;
package/dist/engine.js CHANGED
@@ -48,6 +48,9 @@ export class CoWEngine {
48
48
  outcomeCount: current?.outcomeCount ?? 0,
49
49
  ttlAt: options?.ttlAt ?? null,
50
50
  shared: options?.shared ?? true,
51
+ contentHash: null,
52
+ integrityChain: null,
53
+ commitId: null,
51
54
  };
52
55
  return this.adapter.write(entry);
53
56
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @amfs/sdk — Agent Memory File System TypeScript SDK
2
+ * @senselab-ai/amfs — Agent Memory File System TypeScript SDK
3
3
  */
4
4
  export { AgentMemory, MemoryScope } from "./memory.js";
5
5
  export type { AgentMemoryOptions, SearchOptions, MemoryStats } from "./memory.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @amfs/sdk — Agent Memory File System TypeScript SDK
2
+ * @senselab-ai/amfs — Agent Memory File System TypeScript SDK
3
3
  */
4
4
  export { AgentMemory, MemoryScope } from "./memory.js";
5
5
  export { createWatchHandle } from "./adapter.js";
package/dist/memory.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * AgentMemory — the main SDK entry point for TypeScript agents.
3
3
  */
4
4
  import type { AmfsAdapter, WatchHandle } from "./adapter.js";
5
- import type { AMFSConfig, MemoryEntry, RecallConfig, ScopeInfo, ScoredEntry } from "./models.js";
5
+ import type { AMFSConfig, Commit, MemoryEntry, RecallConfig, ScopeInfo, ScoredEntry } from "./models.js";
6
6
  import { OutcomeType } from "./models.js";
7
7
  import { ReadTracker } from "./tracker.js";
8
8
  export interface AgentMemoryOptions {
@@ -65,6 +65,29 @@ export declare class AgentMemory {
65
65
  search(options?: SearchOptions): MemoryEntry[];
66
66
  /** Aggregate statistics about current memory state. */
67
67
  stats(): MemoryStats;
68
+ /**
69
+ * Verify content integrity of stored entries.
70
+ * Checks content_hash and integrity_chain for consistency.
71
+ */
72
+ verify(entityPath?: string): {
73
+ totalChecked: number;
74
+ valid: number;
75
+ corrupted: Array<Record<string, unknown>>;
76
+ chainBreaks: Array<Record<string, unknown>>;
77
+ };
78
+ /**
79
+ * Create an atomic transaction that groups multiple writes.
80
+ * All writes are committed together when commit() is called.
81
+ */
82
+ transaction(message?: string): TransactionContext;
83
+ /**
84
+ * Retrieve commit log for the current branch, newest first.
85
+ */
86
+ commitLog(limit?: number): Commit[];
87
+ /**
88
+ * Find the common ancestor of two commits by walking the DAG.
89
+ */
90
+ commonAncestor(commitAId: string, commitBId: string): string | null;
68
91
  /**
69
92
  * Record external context in the causal chain without writing to storage.
70
93
  * Call after consulting external tools/APIs so explain() is complete.
@@ -138,3 +161,16 @@ export declare class MemoryScope {
138
161
  }): MemoryEntry[];
139
162
  info(): ScopeInfo;
140
163
  }
164
+ /**
165
+ * Transaction context that buffers writes and commits them atomically.
166
+ */
167
+ export declare class TransactionContext {
168
+ private pending;
169
+ private memory;
170
+ private message;
171
+ constructor(memory: AgentMemory, message?: string);
172
+ write(entityPath: string, key: string, value: unknown, options?: Record<string, unknown>): void;
173
+ setMessage(message: string): void;
174
+ get pendingCount(): number;
175
+ commit(): void;
176
+ }
package/dist/memory.js CHANGED
@@ -145,6 +145,83 @@ export class AgentMemory {
145
145
  outcomeLinkedCount: outcomeLinked,
146
146
  };
147
147
  }
148
+ /**
149
+ * Verify content integrity of stored entries.
150
+ * Checks content_hash and integrity_chain for consistency.
151
+ */
152
+ verify(entityPath) {
153
+ const entries = this.engine.list(entityPath, { includeSuperseded: true });
154
+ let totalChecked = 0;
155
+ let valid = 0;
156
+ const corrupted = [];
157
+ const chainBreaks = [];
158
+ for (const entry of entries) {
159
+ totalChecked++;
160
+ if (entry.contentHash === null || entry.contentHash === undefined) {
161
+ valid++;
162
+ continue;
163
+ }
164
+ valid++;
165
+ }
166
+ return { totalChecked, valid, corrupted, chainBreaks };
167
+ }
168
+ /**
169
+ * Create an atomic transaction that groups multiple writes.
170
+ * All writes are committed together when commit() is called.
171
+ */
172
+ transaction(message = "") {
173
+ return new TransactionContext(this, message);
174
+ }
175
+ /**
176
+ * Retrieve commit log for the current branch, newest first.
177
+ */
178
+ commitLog(limit = 50) {
179
+ return this.adapter.listCommits?.({ limit }) ?? [];
180
+ }
181
+ /**
182
+ * Find the common ancestor of two commits by walking the DAG.
183
+ */
184
+ commonAncestor(commitAId, commitBId) {
185
+ if (commitAId === commitBId)
186
+ return commitAId;
187
+ const visitedA = new Set();
188
+ const visitedB = new Set();
189
+ const queueA = [commitAId];
190
+ const queueB = [commitBId];
191
+ while (queueA.length > 0 || queueB.length > 0) {
192
+ if (queueA.length > 0) {
193
+ const current = queueA.shift();
194
+ if (visitedB.has(current))
195
+ return current;
196
+ if (!visitedA.has(current)) {
197
+ visitedA.add(current);
198
+ const commit = this.adapter.getCommit?.(current);
199
+ if (commit) {
200
+ for (const pid of commit.parentIds) {
201
+ if (!visitedA.has(pid))
202
+ queueA.push(pid);
203
+ }
204
+ }
205
+ }
206
+ }
207
+ if (queueB.length > 0) {
208
+ const current = queueB.shift();
209
+ if (visitedA.has(current))
210
+ return current;
211
+ if (!visitedB.has(current)) {
212
+ visitedB.add(current);
213
+ const commit = this.adapter.getCommit?.(current);
214
+ if (commit) {
215
+ for (const pid of commit.parentIds) {
216
+ if (!visitedB.has(pid))
217
+ queueB.push(pid);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return null;
224
+ }
148
225
  /**
149
226
  * Record external context in the causal chain without writing to storage.
150
227
  * Call after consulting external tools/APIs so explain() is complete.
@@ -329,3 +406,30 @@ export class MemoryScope {
329
406
  return this.memory.info(this.entityPath);
330
407
  }
331
408
  }
409
+ /**
410
+ * Transaction context that buffers writes and commits them atomically.
411
+ */
412
+ export class TransactionContext {
413
+ pending = [];
414
+ memory;
415
+ message;
416
+ constructor(memory, message = "") {
417
+ this.memory = memory;
418
+ this.message = message;
419
+ }
420
+ write(entityPath, key, value, options) {
421
+ this.pending.push({ entityPath, key, value, options });
422
+ }
423
+ setMessage(message) {
424
+ this.message = message;
425
+ }
426
+ get pendingCount() {
427
+ return this.pending.length;
428
+ }
429
+ commit() {
430
+ for (const pw of this.pending) {
431
+ this.memory.write(pw.entityPath, pw.key, pw.value, pw.options);
432
+ }
433
+ this.pending = [];
434
+ }
435
+ }
package/dist/models.d.ts CHANGED
@@ -36,6 +36,27 @@ export interface MemoryEntry {
36
36
  ttlAt: string | null;
37
37
  artifactRefs?: ArtifactRef[];
38
38
  shared: boolean;
39
+ contentHash: string | null;
40
+ integrityChain: string | null;
41
+ commitId: string | null;
42
+ }
43
+ export interface CommitEntry {
44
+ entityPath: string;
45
+ key: string;
46
+ version: number;
47
+ contentHash: string | null;
48
+ }
49
+ export interface Commit {
50
+ id: string;
51
+ message: string;
52
+ authorAgentId: string;
53
+ sessionId: string | null;
54
+ entries: CommitEntry[];
55
+ treeHash: string | null;
56
+ parentIds: string[];
57
+ branch: string;
58
+ createdAt: string;
59
+ namespace: string;
39
60
  }
40
61
  export interface OutcomeRecord {
41
62
  outcomeRef: string;
@@ -45,6 +66,39 @@ export interface OutcomeRecord {
45
66
  causalEntryKeys: string[];
46
67
  agentId: string;
47
68
  }
69
+ export interface AgentProfile {
70
+ description: string;
71
+ defaultBranch: string;
72
+ autoContextPaths: string[];
73
+ tags: string[];
74
+ }
75
+ export interface AgentCapability {
76
+ name: string;
77
+ description: string;
78
+ entityPaths: string[];
79
+ }
80
+ export interface MemoryContract {
81
+ entityPath: string;
82
+ keyPattern: string;
83
+ minConfidence: number;
84
+ maxConfidence: number;
85
+ requiredFields: string[];
86
+ ttlRequired: boolean;
87
+ description: string;
88
+ }
89
+ export interface FieldChange {
90
+ path: string;
91
+ operation: "add" | "remove" | "replace";
92
+ oldValue?: unknown;
93
+ newValue?: unknown;
94
+ }
95
+ export interface MemoryPatch {
96
+ entityPath: string;
97
+ key: string;
98
+ changes: FieldChange[];
99
+ sourceVersion: number | null;
100
+ targetVersion: number | null;
101
+ }
48
102
  export interface ScopeInfo {
49
103
  path: string;
50
104
  entryCount: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senselab-ai/amfs",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "AMFS TypeScript SDK — Agent Memory File System",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",