@jungjaehoon/mama-core 1.4.2 → 1.6.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/README.md +48 -10
- package/db/migrations/026-create-canonical-entity-tables.sql +99 -0
- package/db/migrations/027-create-entity-review-support.sql +44 -0
- package/db/migrations/028-create-entity-audit-tables.sql +45 -0
- package/db/migrations/029-extend-entity-observations-observation-type.sql +60 -0
- package/db/migrations/030-case-first-memory-substrate.sql +901 -0
- package/db/migrations/031-wiki-page-index-provenance-columns.sql +2 -0
- package/db/migrations/032-add-memory-provenance-columns.sql +21 -0
- package/db/migrations/033-create-model-runs-and-tool-traces.sql +53 -0
- package/db/migrations/034-add-connector-event-scope-columns.sql +14 -0
- package/db/migrations/035-create-twin-edges.sql +63 -0
- package/db/migrations/036-create-agent-situation-packets.sql +61 -0
- package/dist/agent-graph/alias-write.d.ts +3 -0
- package/dist/agent-graph/alias-write.js +231 -0
- package/dist/agent-graph/entity-resolve.d.ts +3 -0
- package/dist/agent-graph/entity-resolve.js +275 -0
- package/dist/agent-graph/errors.d.ts +4 -0
- package/dist/agent-graph/errors.js +11 -0
- package/dist/agent-graph/graph-query.d.ts +5 -0
- package/dist/agent-graph/graph-query.js +359 -0
- package/dist/agent-graph/index.d.ts +6 -0
- package/dist/agent-graph/index.js +22 -0
- package/dist/agent-graph/types.d.ts +162 -0
- package/dist/agent-graph/types.js +3 -0
- package/dist/agent-situation/builder.d.ts +8 -0
- package/dist/agent-situation/builder.js +239 -0
- package/dist/agent-situation/cache-key.d.ts +4 -0
- package/dist/agent-situation/cache-key.js +64 -0
- package/dist/agent-situation/index.d.ts +7 -0
- package/dist/agent-situation/index.js +28 -0
- package/dist/agent-situation/packet-store.d.ts +27 -0
- package/dist/agent-situation/packet-store.js +228 -0
- package/dist/agent-situation/ranking-policy.d.ts +18 -0
- package/dist/agent-situation/ranking-policy.js +75 -0
- package/dist/agent-situation/source-readers.d.ts +52 -0
- package/dist/agent-situation/source-readers.js +300 -0
- package/dist/agent-situation/types.d.ts +195 -0
- package/dist/agent-situation/types.js +3 -0
- package/dist/canonicalize.d.ts +38 -0
- package/dist/canonicalize.js +106 -0
- package/dist/cases/case-links.d.ts +116 -0
- package/dist/cases/case-links.js +794 -0
- package/dist/cases/composition-overrides.d.ts +90 -0
- package/dist/cases/composition-overrides.js +724 -0
- package/dist/cases/corrections.d.ts +156 -0
- package/dist/cases/corrections.js +1045 -0
- package/dist/cases/freshness.d.ts +57 -0
- package/dist/cases/freshness.js +283 -0
- package/dist/cases/live-state.d.ts +48 -0
- package/dist/cases/live-state.js +256 -0
- package/dist/cases/membership-explain.d.ts +56 -0
- package/dist/cases/membership-explain.js +140 -0
- package/dist/cases/membership-matcher.d.ts +23 -0
- package/dist/cases/membership-matcher.js +193 -0
- package/dist/cases/merge-split.d.ts +61 -0
- package/dist/cases/merge-split.js +368 -0
- package/dist/cases/role-inference.d.ts +10 -0
- package/dist/cases/role-inference.js +85 -0
- package/dist/cases/search-rollup.d.ts +27 -0
- package/dist/cases/search-rollup.js +309 -0
- package/dist/cases/sqlite-transaction.d.ts +10 -0
- package/dist/cases/sqlite-transaction.js +62 -0
- package/dist/cases/store.d.ts +74 -0
- package/dist/cases/store.js +816 -0
- package/dist/cases/target-ref.d.ts +25 -0
- package/dist/cases/target-ref.js +22 -0
- package/dist/cases/timeline-range.d.ts +6 -0
- package/dist/cases/timeline-range.js +322 -0
- package/dist/cases/tombstone-sweeper.d.ts +13 -0
- package/dist/cases/tombstone-sweeper.js +128 -0
- package/dist/cases/types.d.ts +244 -0
- package/dist/cases/types.js +47 -0
- package/dist/cases/wiki-page-index.d.ts +50 -0
- package/dist/cases/wiki-page-index.js +350 -0
- package/dist/connectors/event-index.d.ts +45 -0
- package/dist/connectors/event-index.js +381 -0
- package/dist/connectors/raw-query.d.ts +18 -0
- package/dist/connectors/raw-query.js +305 -0
- package/dist/connectors/types.d.ts +109 -0
- package/dist/connectors/types.js +3 -0
- package/dist/db-adapter/node-sqlite-adapter.d.ts +6 -0
- package/dist/db-adapter/node-sqlite-adapter.js +131 -0
- package/dist/db-manager.d.ts +12 -1
- package/dist/db-manager.js +60 -5
- package/dist/decision-formatter.d.ts +2 -0
- package/dist/decision-formatter.js +11 -8
- package/dist/edges/ref-validation.d.ts +8 -0
- package/dist/edges/ref-validation.js +262 -0
- package/dist/edges/store.d.ts +10 -0
- package/dist/edges/store.js +343 -0
- package/dist/edges/types.d.ts +86 -0
- package/dist/edges/types.js +18 -0
- package/dist/embedding-server/mobile/daemon.d.ts +1 -0
- package/dist/embedding-server/mobile/daemon.js +11 -1
- package/dist/embeddings.js +13 -0
- package/dist/entities/audit-metrics.d.ts +73 -0
- package/dist/entities/audit-metrics.js +128 -0
- package/dist/entities/candidate-generator.d.ts +9 -0
- package/dist/entities/candidate-generator.js +436 -0
- package/dist/entities/entity-impact.d.ts +41 -0
- package/dist/entities/entity-impact.js +140 -0
- package/dist/entities/entity-linked-decision-counts.d.ts +2 -0
- package/dist/entities/entity-linked-decision-counts.js +29 -0
- package/dist/entities/entity-list.d.ts +23 -0
- package/dist/entities/entity-list.js +99 -0
- package/dist/entities/entity-orphan-list.d.ts +26 -0
- package/dist/entities/entity-orphan-list.js +91 -0
- package/dist/entities/entity-search.d.ts +21 -0
- package/dist/entities/entity-search.js +150 -0
- package/dist/entities/errors.d.ts +65 -0
- package/dist/entities/errors.js +124 -0
- package/dist/entities/exact-merge-backfill.d.ts +11 -0
- package/dist/entities/exact-merge-backfill.js +161 -0
- package/dist/entities/lineage-backfill.d.ts +12 -0
- package/dist/entities/lineage-backfill.js +101 -0
- package/dist/entities/lineage-store.d.ts +51 -0
- package/dist/entities/lineage-store.js +308 -0
- package/dist/entities/normalization.d.ts +14 -0
- package/dist/entities/normalization.js +63 -0
- package/dist/entities/policy-store.d.ts +17 -0
- package/dist/entities/policy-store.js +263 -0
- package/dist/entities/policy-types.d.ts +72 -0
- package/dist/entities/policy-types.js +59 -0
- package/dist/entities/projection.d.ts +8 -0
- package/dist/entities/projection.js +82 -0
- package/dist/entities/provenance-query.d.ts +33 -0
- package/dist/entities/provenance-query.js +167 -0
- package/dist/entities/read-identity.d.ts +31 -0
- package/dist/entities/read-identity.js +264 -0
- package/dist/entities/recall-bridge.d.ts +5 -0
- package/dist/entities/recall-bridge.js +171 -0
- package/dist/entities/resolution-engine.d.ts +15 -0
- package/dist/entities/resolution-engine.js +69 -0
- package/dist/entities/rollback-preview.d.ts +39 -0
- package/dist/entities/rollback-preview.js +235 -0
- package/dist/entities/source-locator.d.ts +3 -0
- package/dist/entities/source-locator.js +32 -0
- package/dist/entities/store.d.ts +75 -0
- package/dist/entities/store.js +465 -0
- package/dist/entities/types.d.ts +162 -0
- package/dist/entities/types.js +30 -0
- package/dist/index.d.ts +62 -3
- package/dist/index.js +116 -26
- package/dist/mama-api.d.ts +53 -35
- package/dist/mama-api.js +437 -78
- package/dist/memory/api.d.ts +26 -38
- package/dist/memory/api.js +772 -68
- package/dist/memory/event-store.d.ts +3 -0
- package/dist/memory/event-store.js +21 -2
- package/dist/memory/provenance-audit.d.ts +22 -0
- package/dist/memory/provenance-audit.js +112 -0
- package/dist/memory/provenance-query.d.ts +11 -0
- package/dist/memory/provenance-query.js +193 -0
- package/dist/memory/provenance.d.ts +29 -0
- package/dist/memory/provenance.js +136 -0
- package/dist/memory/scope-backfill.d.ts +17 -0
- package/dist/memory/scope-backfill.js +77 -0
- package/dist/memory/types.d.ts +97 -16
- package/dist/model-runs/store.d.ts +13 -0
- package/dist/model-runs/store.js +457 -0
- package/dist/model-runs/tool-trace-store.d.ts +4 -0
- package/dist/model-runs/tool-trace-store.js +114 -0
- package/dist/model-runs/types.d.ts +69 -0
- package/dist/model-runs/types.js +5 -0
- package/dist/runtime/trusted-provenance.d.ts +3 -0
- package/dist/runtime/trusted-provenance.js +6 -0
- package/dist/search/feedback-store.d.ts +59 -0
- package/dist/search/feedback-store.js +211 -0
- package/dist/search/question-type.d.ts +5 -0
- package/dist/search/question-type.js +41 -0
- package/dist/search/ranker-features.d.ts +23 -0
- package/dist/search/ranker-features.js +104 -0
- package/dist/search/ranker-rescore.d.ts +31 -0
- package/dist/search/ranker-rescore.js +226 -0
- package/dist/search/ranker-trainer.d.ts +94 -0
- package/dist/search/ranker-trainer.js +860 -0
- package/dist/search/search-quality.d.ts +36 -0
- package/dist/search/search-quality.js +29 -0
- package/dist/test-utils.d.ts +14 -0
- package/dist/test-utils.js +52 -0
- package/package.json +28 -3
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type SearchStrictness = 'recall' | 'balanced' | 'strict';
|
|
2
|
+
export interface SearchQualityOptions {
|
|
3
|
+
threshold?: number;
|
|
4
|
+
strict?: boolean;
|
|
5
|
+
strictness?: SearchStrictness;
|
|
6
|
+
disableRecency?: boolean;
|
|
7
|
+
includeRelated?: boolean;
|
|
8
|
+
topicPrefix?: string;
|
|
9
|
+
minLexicalSupport?: boolean;
|
|
10
|
+
diagnostics?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface NormalizedSearchQualityOptions {
|
|
13
|
+
threshold: number;
|
|
14
|
+
strictness: SearchStrictness;
|
|
15
|
+
disableRecency: boolean;
|
|
16
|
+
includeRelated: boolean;
|
|
17
|
+
topicPrefix?: string;
|
|
18
|
+
minLexicalSupport: boolean;
|
|
19
|
+
diagnostics: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface SearchHitDiagnostics {
|
|
22
|
+
retrieval_source: string;
|
|
23
|
+
vector_similarity: number | null;
|
|
24
|
+
lexical_support: boolean;
|
|
25
|
+
entity_support: boolean;
|
|
26
|
+
scope_support: boolean;
|
|
27
|
+
graph_source: 'primary' | 'expanded' | null;
|
|
28
|
+
is_vector_only: boolean;
|
|
29
|
+
/** Relevance confirmations only: never include scope or graph position here. */
|
|
30
|
+
confirmation_signals: string[];
|
|
31
|
+
/** Non-relevance metadata useful for diagnostics and audit output. */
|
|
32
|
+
metadata_signals: string[];
|
|
33
|
+
candidate_threshold_used: number;
|
|
34
|
+
}
|
|
35
|
+
export declare function normalizeSearchQualityOptions(options?: SearchQualityOptions): NormalizedSearchQualityOptions;
|
|
36
|
+
//# sourceMappingURL=search-quality.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeSearchQualityOptions = normalizeSearchQualityOptions;
|
|
4
|
+
function normalizeSearchQualityOptions(options = {}) {
|
|
5
|
+
// Validate strictness at runtime — untyped callers can otherwise pass invalid
|
|
6
|
+
// strings that silently fall through and skew filtering.
|
|
7
|
+
const strictnessCandidate = options.strict === true ? 'strict' : options.strictness;
|
|
8
|
+
const strictness = strictnessCandidate === 'strict' ||
|
|
9
|
+
strictnessCandidate === 'balanced' ||
|
|
10
|
+
strictnessCandidate === 'recall'
|
|
11
|
+
? strictnessCandidate
|
|
12
|
+
: 'recall';
|
|
13
|
+
const defaultThreshold = strictness === 'strict' ? 0.6 : strictness === 'balanced' ? 0.45 : 0.3;
|
|
14
|
+
const rawThreshold = typeof options.threshold === 'number' ? options.threshold : defaultThreshold;
|
|
15
|
+
// Clamp threshold to [0, 1]; fall back to default for non-finite values (NaN, ±Inf).
|
|
16
|
+
const threshold = Number.isFinite(rawThreshold)
|
|
17
|
+
? Math.min(1, Math.max(0, rawThreshold))
|
|
18
|
+
: defaultThreshold;
|
|
19
|
+
return {
|
|
20
|
+
threshold,
|
|
21
|
+
strictness,
|
|
22
|
+
disableRecency: options.disableRecency === true,
|
|
23
|
+
includeRelated: options.includeRelated ?? strictness !== 'strict',
|
|
24
|
+
topicPrefix: options.topicPrefix,
|
|
25
|
+
minLexicalSupport: options.minLexicalSupport ?? strictness !== 'recall',
|
|
26
|
+
diagnostics: options.diagnostics === true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=search-quality.js.map
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -7,6 +7,20 @@
|
|
|
7
7
|
* @module test-utils
|
|
8
8
|
* @version 1.1
|
|
9
9
|
*/
|
|
10
|
+
import type Database from 'better-sqlite3';
|
|
11
|
+
/**
|
|
12
|
+
* Returns migration SQL filenames sorted by their leading three-digit version.
|
|
13
|
+
*/
|
|
14
|
+
export declare function migrationFiles(): string[];
|
|
15
|
+
export declare function migrationVersion(file: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* Apply migrations in order up to `maxVersion` (inclusive), starting from
|
|
18
|
+
* `fromVersion`. Mirrors the production runner's two-part contract:
|
|
19
|
+
* - skip files whose version is already recorded in `schema_version`
|
|
20
|
+
* - tolerate `duplicate column` errors (legacy migrations that add
|
|
21
|
+
* columns idempotently without recording into schema_version)
|
|
22
|
+
*/
|
|
23
|
+
export declare function applyMigrationsThrough(db: Database.Database, maxVersion: number, fromVersion?: number): void;
|
|
10
24
|
/**
|
|
11
25
|
* Preload embedding model (call once in globalSetup)
|
|
12
26
|
*
|
package/dist/test-utils.js
CHANGED
|
@@ -12,6 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.migrationFiles = migrationFiles;
|
|
16
|
+
exports.migrationVersion = migrationVersion;
|
|
17
|
+
exports.applyMigrationsThrough = applyMigrationsThrough;
|
|
15
18
|
exports.preloadEmbeddingModel = preloadEmbeddingModel;
|
|
16
19
|
exports.initTestDB = initTestDB;
|
|
17
20
|
exports.cleanupTestDB = cleanupTestDB;
|
|
@@ -22,8 +25,57 @@ exports.suppressConsole = suppressConsole;
|
|
|
22
25
|
const path_1 = __importDefault(require("path"));
|
|
23
26
|
const fs_1 = __importDefault(require("fs"));
|
|
24
27
|
const os_1 = __importDefault(require("os"));
|
|
28
|
+
const node_fs_1 = require("node:fs");
|
|
29
|
+
const node_path_1 = require("node:path");
|
|
25
30
|
const db_manager_js_1 = require("./db-manager.js");
|
|
26
31
|
const debug_logger_js_1 = require("./debug-logger.js");
|
|
32
|
+
const MIGRATIONS_DIR = (0, node_path_1.join)(__dirname, '..', 'db', 'migrations');
|
|
33
|
+
/**
|
|
34
|
+
* Returns migration SQL filenames sorted by their leading three-digit version.
|
|
35
|
+
*/
|
|
36
|
+
function migrationFiles() {
|
|
37
|
+
return (0, node_fs_1.readdirSync)(MIGRATIONS_DIR)
|
|
38
|
+
.filter((file) => /^\d{3}-.+\.sql$/.test(file))
|
|
39
|
+
.sort((left, right) => left.localeCompare(right));
|
|
40
|
+
}
|
|
41
|
+
function migrationVersion(file) {
|
|
42
|
+
return Number.parseInt(file.slice(0, 3), 10);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Apply migrations in order up to `maxVersion` (inclusive), starting from
|
|
46
|
+
* `fromVersion`. Mirrors the production runner's two-part contract:
|
|
47
|
+
* - skip files whose version is already recorded in `schema_version`
|
|
48
|
+
* - tolerate `duplicate column` errors (legacy migrations that add
|
|
49
|
+
* columns idempotently without recording into schema_version)
|
|
50
|
+
*/
|
|
51
|
+
function applyMigrationsThrough(db, maxVersion, fromVersion = 1) {
|
|
52
|
+
for (const file of migrationFiles()) {
|
|
53
|
+
const version = migrationVersion(file);
|
|
54
|
+
if (version < fromVersion)
|
|
55
|
+
continue;
|
|
56
|
+
if (version > maxVersion)
|
|
57
|
+
break;
|
|
58
|
+
let alreadyApplied = false;
|
|
59
|
+
try {
|
|
60
|
+
alreadyApplied = !!db
|
|
61
|
+
.prepare('SELECT 1 FROM schema_version WHERE version = ?')
|
|
62
|
+
.get(version);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
alreadyApplied = false;
|
|
66
|
+
}
|
|
67
|
+
if (alreadyApplied)
|
|
68
|
+
continue;
|
|
69
|
+
try {
|
|
70
|
+
db.exec((0, node_fs_1.readFileSync)((0, node_path_1.join)(MIGRATIONS_DIR, file), 'utf8'));
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
74
|
+
if (!/duplicate column/i.test(msg))
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
27
79
|
// Track test databases for cleanup
|
|
28
80
|
const testDatabases = [];
|
|
29
81
|
// Embedding model preload state
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungjaehoon/mama-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "MAMA Core - Shared modules for Memory-Augmented MCP Assistant",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,32 @@
|
|
|
26
26
|
"./time-formatter": "./dist/time-formatter.js",
|
|
27
27
|
"./outcome-tracker": "./dist/outcome-tracker.js",
|
|
28
28
|
"./query-intent": "./dist/query-intent.js",
|
|
29
|
-
"./test-utils": "./dist/test-utils.js"
|
|
29
|
+
"./test-utils": "./dist/test-utils.js",
|
|
30
|
+
"./entities/store": "./dist/entities/store.js",
|
|
31
|
+
"./entities/candidate-generator": "./dist/entities/candidate-generator.js",
|
|
32
|
+
"./canonicalize": "./dist/canonicalize.js",
|
|
33
|
+
"./cases/types": "./dist/cases/types.js",
|
|
34
|
+
"./cases/store": "./dist/cases/store.js",
|
|
35
|
+
"./cases/role-inference": "./dist/cases/role-inference.js",
|
|
36
|
+
"./cases/target-ref": "./dist/cases/target-ref.js",
|
|
37
|
+
"./cases/corrections": "./dist/cases/corrections.js",
|
|
38
|
+
"./cases/sqlite-transaction": "./dist/cases/sqlite-transaction.js",
|
|
39
|
+
"./cases/live-state": "./dist/cases/live-state.js",
|
|
40
|
+
"./cases/tombstone-sweeper": "./dist/cases/tombstone-sweeper.js",
|
|
41
|
+
"./cases/merge-split": "./dist/cases/merge-split.js",
|
|
42
|
+
"./cases/membership-matcher": "./dist/cases/membership-matcher.js",
|
|
43
|
+
"./cases/search-rollup": "./dist/cases/search-rollup.js",
|
|
44
|
+
"./cases/timeline-range": "./dist/cases/timeline-range.js",
|
|
45
|
+
"./cases/wiki-page-index": "./dist/cases/wiki-page-index.js",
|
|
46
|
+
"./connectors": "./dist/connectors/event-index.js",
|
|
47
|
+
"./connectors/event-index": "./dist/connectors/event-index.js",
|
|
48
|
+
"./connectors/raw-query": "./dist/connectors/raw-query.js",
|
|
49
|
+
"./connectors/types": "./dist/connectors/types.js",
|
|
50
|
+
"./agent-situation": "./dist/agent-situation/index.js",
|
|
51
|
+
"./agent-graph": "./dist/agent-graph/index.js",
|
|
52
|
+
"./edges/types": "./dist/edges/types.js",
|
|
53
|
+
"./edges/store": "./dist/edges/store.js",
|
|
54
|
+
"./edges/ref-validation": "./dist/edges/ref-validation.js"
|
|
30
55
|
},
|
|
31
56
|
"scripts": {
|
|
32
57
|
"build": "tsc",
|
|
@@ -71,7 +96,7 @@
|
|
|
71
96
|
"@types/better-sqlite3": "^7.6.13",
|
|
72
97
|
"@types/node": "^22.0.0",
|
|
73
98
|
"@types/ws": "^8.18.1",
|
|
74
|
-
"typescript": "^5.
|
|
99
|
+
"typescript": "^5.9.3",
|
|
75
100
|
"vitest": "^1.0.0"
|
|
76
101
|
},
|
|
77
102
|
"files": [
|