@oscharko-dev/keiko-memory-consolidation 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.
@@ -0,0 +1,60 @@
1
+ import type { MemoryEdge, MemoryEdgeId, MemoryId } from "@oscharko-dev/keiko-contracts/memory";
2
+ import type { MemoryUpdate } from "@oscharko-dev/keiko-contracts/memory";
3
+ export type ConsolidationJobState = "queued" | "running" | "completed" | "failed" | "canceled" | "skipped";
4
+ export interface ConsolidationJob {
5
+ readonly id: string;
6
+ readonly state: ConsolidationJobState;
7
+ readonly startedAt?: number;
8
+ readonly completedAt?: number;
9
+ readonly result?: ConsolidationResult;
10
+ readonly error?: string;
11
+ }
12
+ export type StaleReason = "expired" | "low-confidence" | "aged-out";
13
+ export interface StaleFlag {
14
+ readonly memoryId: MemoryId;
15
+ readonly reason: StaleReason;
16
+ readonly detectedAt: number;
17
+ }
18
+ export type ReviewReason = "multi-way-duplicate" | "potential-conflict";
19
+ export type ProposedAction = {
20
+ readonly kind: "merge";
21
+ readonly winner: MemoryId;
22
+ readonly losers: readonly MemoryId[];
23
+ } | {
24
+ readonly kind: "supersede";
25
+ readonly newer: MemoryId;
26
+ readonly older: MemoryId;
27
+ };
28
+ export interface ReviewItem {
29
+ readonly id: string;
30
+ readonly reason: ReviewReason;
31
+ readonly relatedMemoryIds: readonly MemoryId[];
32
+ readonly proposedAction?: ProposedAction;
33
+ readonly proposedEdges?: readonly MemoryEdge[];
34
+ readonly detectedAt: number;
35
+ }
36
+ export interface ConsolidationOptions {
37
+ readonly nowMs: number;
38
+ readonly newEdgeId: () => MemoryEdgeId;
39
+ readonly newReviewItemId: () => string;
40
+ readonly jaccardThreshold?: number;
41
+ readonly staleConfidenceThreshold?: number;
42
+ readonly maxAgeMs?: number;
43
+ readonly maxClustersPerRun?: number;
44
+ readonly maxRecordsPerRun?: number;
45
+ readonly cancellationSignal?: () => boolean;
46
+ readonly summaryGenerator?: (text: string) => Promise<string>;
47
+ }
48
+ export interface ConsolidationResult {
49
+ readonly state: "completed" | "canceled" | "skipped" | "failed";
50
+ readonly edgesProposed: readonly MemoryEdge[];
51
+ readonly updatesProposed: readonly MemoryUpdate[];
52
+ readonly staleFlags: readonly StaleFlag[];
53
+ readonly reviewItems: readonly ReviewItem[];
54
+ readonly clustersInspected: number;
55
+ readonly conflictPairsDetected: number;
56
+ readonly recordsInspected: number;
57
+ readonly truncated: boolean;
58
+ readonly elapsedMs: number;
59
+ }
60
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAQzE,MAAM,MAAM,qBAAqB,GAC7B,QAAQ,GACR,SAAS,GACT,WAAW,GACX,QAAQ,GACR,UAAU,GACV,SAAS,CAAC;AAEd,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEpE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAG7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAQD,MAAM,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CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/D;AAOD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;IAChE,QAAQ,CAAC,aAAa,EAAE,SAAS,UAAU,EAAE,CAAC;IAC9C,QAAQ,CAAC,eAAe,EAAE,SAAS,YAAY,EAAE,CAAC;IAClD,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAInC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAI5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B"}
package/dist/types.js ADDED
@@ -0,0 +1,19 @@
1
+ // Public surface for keiko-memory-consolidation (Epic #204 child #208).
2
+ //
3
+ // Consolidation is a PURE-FUNCTION engine. The caller pre-fetches MemoryRecords from the vault
4
+ // (#206), invokes `runConsolidation`, and applies the proposed edges, supersessions, and
5
+ // review-item resolutions back to the vault and audit ledger (#214). The engine itself never
6
+ // touches storage, never reads the clock, and never generates random ids — everything that would
7
+ // be impure is injected through `ConsolidationOptions` (`nowMs`, `newEdgeId`, `newReviewItemId`,
8
+ // `cancellationSignal`). This keeps the layer trivially reproducible: same input + same options
9
+ // => byte-identical result.
10
+ //
11
+ // Design choice (preserved across review and pinned here so future contributors do not "fix" it):
12
+ // `updatesProposed` is reserved for a future model-assisted body-summarisation pass. v1 NEVER
13
+ // emits `MemoryUpdate` envelopes: every merge / supersession is routed through a `ReviewItem`
14
+ // carrying a `ProposedAction`, so the caller (#211 MemoriaViva UI or a workflow) materialises
15
+ // the actual `MemorySupersession` envelope after explicit review. This preserves the Epic #204
16
+ // invariant: "consolidation never mutates accepted memories without preserving provenance and
17
+ // audit history" — the caller's supersession is the audited transition, not a silent in-place
18
+ // patch.
19
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const KEIKO_MEMORY_CONSOLIDATION_VERSION: "0.1.0";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kCAAkC,EAAG,OAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ export const KEIKO_MEMORY_CONSOLIDATION_VERSION = "0.1.0";
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@oscharko-dev/keiko-memory-consolidation",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "description": "MemoriaViva — Internal memory-consolidation package: pure-function engine that takes a bounded set of accepted MemoryRecords and returns proposed relationship edges, stale flags, and review items (multi-way duplicates and potential conflicts). The engine NEVER mutates accepted memories: every merge/supersession is routed through a ReviewItem so the caller (#211 MemoriaViva UI or a workflow) materializes the actual MemorySupersession envelope after explicit review. No IO, no clock, no randomness (caller supplies nowMs and id factories via ConsolidationOptions). ADR-0019 direction rule 3h (consolidation may depend only on keiko-contracts and keiko-security). Not published independently.",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc -b tsconfig.json",
17
+ "typecheck": "tsc -b tsconfig.json",
18
+ "test": "vitest run"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "sideEffects": false,
24
+ "engines": {
25
+ "node": ">=22"
26
+ },
27
+ "dependencies": {
28
+ "@oscharko-dev/keiko-contracts": "0.2.0",
29
+ "@oscharko-dev/keiko-security": "0.2.0"
30
+ }
31
+ }