@mnemoai/core 1.1.0 → 1.1.1
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/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +7 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.d.ts.map +1 -0
- package/{index.ts → dist/index.js} +526 -1333
- package/dist/index.js.map +7 -0
- package/dist/src/access-tracker.d.ts +97 -0
- package/dist/src/access-tracker.d.ts.map +1 -0
- package/dist/src/access-tracker.js +184 -0
- package/dist/src/access-tracker.js.map +7 -0
- package/dist/src/adapters/chroma.d.ts +31 -0
- package/dist/src/adapters/chroma.d.ts.map +1 -0
- package/{src/adapters/chroma.ts → dist/src/adapters/chroma.js} +45 -107
- package/dist/src/adapters/chroma.js.map +7 -0
- package/dist/src/adapters/lancedb.d.ts +29 -0
- package/dist/src/adapters/lancedb.d.ts.map +1 -0
- package/{src/adapters/lancedb.ts → dist/src/adapters/lancedb.js} +41 -109
- package/dist/src/adapters/lancedb.js.map +7 -0
- package/dist/src/adapters/pgvector.d.ts +33 -0
- package/dist/src/adapters/pgvector.d.ts.map +1 -0
- package/{src/adapters/pgvector.ts → dist/src/adapters/pgvector.js} +42 -104
- package/dist/src/adapters/pgvector.js.map +7 -0
- package/dist/src/adapters/qdrant.d.ts +34 -0
- package/dist/src/adapters/qdrant.d.ts.map +1 -0
- package/dist/src/adapters/qdrant.js +132 -0
- package/dist/src/adapters/qdrant.js.map +7 -0
- package/dist/src/adaptive-retrieval.d.ts +14 -0
- package/dist/src/adaptive-retrieval.d.ts.map +1 -0
- package/dist/src/adaptive-retrieval.js +52 -0
- package/dist/src/adaptive-retrieval.js.map +7 -0
- package/dist/src/audit-log.d.ts +56 -0
- package/dist/src/audit-log.d.ts.map +1 -0
- package/dist/src/audit-log.js +139 -0
- package/dist/src/audit-log.js.map +7 -0
- package/dist/src/chunker.d.ts +45 -0
- package/dist/src/chunker.d.ts.map +1 -0
- package/dist/src/chunker.js +157 -0
- package/dist/src/chunker.js.map +7 -0
- package/dist/src/config.d.ts +70 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +142 -0
- package/dist/src/config.js.map +7 -0
- package/dist/src/decay-engine.d.ts +73 -0
- package/dist/src/decay-engine.d.ts.map +1 -0
- package/dist/src/decay-engine.js +119 -0
- package/dist/src/decay-engine.js.map +7 -0
- package/dist/src/embedder.d.ts +94 -0
- package/dist/src/embedder.d.ts.map +1 -0
- package/{src/embedder.ts → dist/src/embedder.js} +119 -317
- package/dist/src/embedder.js.map +7 -0
- package/dist/src/extraction-prompts.d.ts +12 -0
- package/dist/src/extraction-prompts.d.ts.map +1 -0
- package/dist/src/extraction-prompts.js +311 -0
- package/dist/src/extraction-prompts.js.map +7 -0
- package/dist/src/license.d.ts +29 -0
- package/dist/src/license.d.ts.map +1 -0
- package/{src/license.ts → dist/src/license.js} +42 -113
- package/dist/src/license.js.map +7 -0
- package/dist/src/llm-client.d.ts +23 -0
- package/dist/src/llm-client.d.ts.map +1 -0
- package/{src/llm-client.ts → dist/src/llm-client.js} +22 -55
- package/dist/src/llm-client.js.map +7 -0
- package/dist/src/logger.d.ts +33 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +35 -0
- package/dist/src/logger.js.map +7 -0
- package/dist/src/mcp-server.d.ts +16 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/{src/mcp-server.ts → dist/src/mcp-server.js} +81 -181
- package/dist/src/mcp-server.js.map +7 -0
- package/dist/src/memory-categories.d.ts +40 -0
- package/dist/src/memory-categories.d.ts.map +1 -0
- package/dist/src/memory-categories.js +33 -0
- package/dist/src/memory-categories.js.map +7 -0
- package/dist/src/memory-upgrader.d.ts +71 -0
- package/dist/src/memory-upgrader.d.ts.map +1 -0
- package/dist/src/memory-upgrader.js +238 -0
- package/dist/src/memory-upgrader.js.map +7 -0
- package/dist/src/migrate.d.ts +47 -0
- package/dist/src/migrate.d.ts.map +1 -0
- package/{src/migrate.ts → dist/src/migrate.js} +57 -165
- package/dist/src/migrate.js.map +7 -0
- package/dist/src/mnemo.d.ts +67 -0
- package/dist/src/mnemo.d.ts.map +1 -0
- package/dist/src/mnemo.js +66 -0
- package/dist/src/mnemo.js.map +7 -0
- package/dist/src/noise-filter.d.ts +23 -0
- package/dist/src/noise-filter.d.ts.map +1 -0
- package/dist/src/noise-filter.js +62 -0
- package/dist/src/noise-filter.js.map +7 -0
- package/dist/src/noise-prototypes.d.ts +40 -0
- package/dist/src/noise-prototypes.d.ts.map +1 -0
- package/dist/src/noise-prototypes.js +116 -0
- package/dist/src/noise-prototypes.js.map +7 -0
- package/dist/src/observability.d.ts +16 -0
- package/dist/src/observability.d.ts.map +1 -0
- package/dist/src/observability.js +53 -0
- package/dist/src/observability.js.map +7 -0
- package/dist/src/query-tracker.d.ts +27 -0
- package/dist/src/query-tracker.d.ts.map +1 -0
- package/dist/src/query-tracker.js +32 -0
- package/dist/src/query-tracker.js.map +7 -0
- package/dist/src/reflection-event-store.d.ts +44 -0
- package/dist/src/reflection-event-store.d.ts.map +1 -0
- package/dist/src/reflection-event-store.js +50 -0
- package/dist/src/reflection-event-store.js.map +7 -0
- package/dist/src/reflection-item-store.d.ts +58 -0
- package/dist/src/reflection-item-store.d.ts.map +1 -0
- package/dist/src/reflection-item-store.js +69 -0
- package/dist/src/reflection-item-store.js.map +7 -0
- package/dist/src/reflection-mapped-metadata.d.ts +47 -0
- package/dist/src/reflection-mapped-metadata.d.ts.map +1 -0
- package/dist/src/reflection-mapped-metadata.js +40 -0
- package/dist/src/reflection-mapped-metadata.js.map +7 -0
- package/dist/src/reflection-metadata.d.ts +11 -0
- package/dist/src/reflection-metadata.d.ts.map +1 -0
- package/dist/src/reflection-metadata.js +24 -0
- package/dist/src/reflection-metadata.js.map +7 -0
- package/dist/src/reflection-ranking.d.ts +13 -0
- package/dist/src/reflection-ranking.d.ts.map +1 -0
- package/{src/reflection-ranking.ts → dist/src/reflection-ranking.js} +12 -21
- package/dist/src/reflection-ranking.js.map +7 -0
- package/dist/src/reflection-retry.d.ts +30 -0
- package/dist/src/reflection-retry.d.ts.map +1 -0
- package/{src/reflection-retry.ts → dist/src/reflection-retry.js} +24 -64
- package/dist/src/reflection-retry.js.map +7 -0
- package/dist/src/reflection-slices.d.ts +42 -0
- package/dist/src/reflection-slices.d.ts.map +1 -0
- package/{src/reflection-slices.ts → dist/src/reflection-slices.js} +60 -136
- package/dist/src/reflection-slices.js.map +7 -0
- package/dist/src/reflection-store.d.ts +85 -0
- package/dist/src/reflection-store.d.ts.map +1 -0
- package/dist/src/reflection-store.js +407 -0
- package/dist/src/reflection-store.js.map +7 -0
- package/dist/src/resonance-state.d.ts +19 -0
- package/dist/src/resonance-state.d.ts.map +1 -0
- package/{src/resonance-state.ts → dist/src/resonance-state.js} +13 -42
- package/dist/src/resonance-state.js.map +7 -0
- package/dist/src/retriever.d.ts +228 -0
- package/dist/src/retriever.d.ts.map +1 -0
- package/dist/src/retriever.js +1006 -0
- package/dist/src/retriever.js.map +7 -0
- package/dist/src/scopes.d.ts +58 -0
- package/dist/src/scopes.d.ts.map +1 -0
- package/dist/src/scopes.js +252 -0
- package/dist/src/scopes.js.map +7 -0
- package/dist/src/self-improvement-files.d.ts +20 -0
- package/dist/src/self-improvement-files.d.ts.map +1 -0
- package/{src/self-improvement-files.ts → dist/src/self-improvement-files.js} +24 -49
- package/dist/src/self-improvement-files.js.map +7 -0
- package/dist/src/semantic-gate.d.ts +24 -0
- package/dist/src/semantic-gate.d.ts.map +1 -0
- package/dist/src/semantic-gate.js +86 -0
- package/dist/src/semantic-gate.js.map +7 -0
- package/dist/src/session-recovery.d.ts +9 -0
- package/dist/src/session-recovery.d.ts.map +1 -0
- package/{src/session-recovery.ts → dist/src/session-recovery.js} +40 -57
- package/dist/src/session-recovery.js.map +7 -0
- package/dist/src/smart-extractor.d.ts +107 -0
- package/dist/src/smart-extractor.d.ts.map +1 -0
- package/{src/smart-extractor.ts → dist/src/smart-extractor.js} +130 -383
- package/dist/src/smart-extractor.js.map +7 -0
- package/dist/src/smart-metadata.d.ts +103 -0
- package/dist/src/smart-metadata.d.ts.map +1 -0
- package/dist/src/smart-metadata.js +361 -0
- package/dist/src/smart-metadata.js.map +7 -0
- package/dist/src/storage-adapter.d.ts +102 -0
- package/dist/src/storage-adapter.d.ts.map +1 -0
- package/dist/src/storage-adapter.js +22 -0
- package/dist/src/storage-adapter.js.map +7 -0
- package/dist/src/store.d.ts +108 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +939 -0
- package/dist/src/store.js.map +7 -0
- package/dist/src/tier-manager.d.ts +57 -0
- package/dist/src/tier-manager.d.ts.map +1 -0
- package/dist/src/tier-manager.js +80 -0
- package/dist/src/tier-manager.js.map +7 -0
- package/dist/src/tools.d.ts +43 -0
- package/dist/src/tools.d.ts.map +1 -0
- package/dist/src/tools.js +1075 -0
- package/dist/src/tools.js.map +7 -0
- package/dist/src/wal-recovery.d.ts +30 -0
- package/dist/src/wal-recovery.d.ts.map +1 -0
- package/{src/wal-recovery.ts → dist/src/wal-recovery.js} +26 -79
- package/dist/src/wal-recovery.js.map +7 -0
- package/package.json +21 -2
- package/openclaw.plugin.json +0 -815
- package/src/access-tracker.ts +0 -341
- package/src/adapters/README.md +0 -78
- package/src/adapters/qdrant.ts +0 -191
- package/src/adaptive-retrieval.ts +0 -90
- package/src/audit-log.ts +0 -238
- package/src/chunker.ts +0 -254
- package/src/config.ts +0 -271
- package/src/decay-engine.ts +0 -238
- package/src/extraction-prompts.ts +0 -339
- package/src/memory-categories.ts +0 -71
- package/src/memory-upgrader.ts +0 -388
- package/src/mnemo.ts +0 -142
- package/src/noise-filter.ts +0 -97
- package/src/noise-prototypes.ts +0 -164
- package/src/observability.ts +0 -81
- package/src/query-tracker.ts +0 -57
- package/src/reflection-event-store.ts +0 -98
- package/src/reflection-item-store.ts +0 -112
- package/src/reflection-mapped-metadata.ts +0 -84
- package/src/reflection-metadata.ts +0 -23
- package/src/reflection-store.ts +0 -602
- package/src/retriever.ts +0 -1510
- package/src/scopes.ts +0 -375
- package/src/semantic-gate.ts +0 -121
- package/src/smart-metadata.ts +0 -561
- package/src/storage-adapter.ts +0 -153
- package/src/store.ts +0 -1330
- package/src/tier-manager.ts +0 -189
- package/src/tools.ts +0 -1292
- package/test/core.test.mjs +0 -301
|
@@ -1,45 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ReflectionSlices {
|
|
3
|
-
invariants: string[];
|
|
4
|
-
derived: string[];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface ReflectionMappedMemory {
|
|
8
|
-
text: string;
|
|
9
|
-
category: "preference" | "fact" | "decision";
|
|
10
|
-
heading: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type ReflectionMappedKind = "user-model" | "agent-model" | "lesson" | "decision";
|
|
14
|
-
|
|
15
|
-
export interface ReflectionMappedMemoryItem extends ReflectionMappedMemory {
|
|
16
|
-
mappedKind: ReflectionMappedKind;
|
|
17
|
-
ordinal: number;
|
|
18
|
-
groupSize: number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ReflectionSliceItem {
|
|
22
|
-
text: string;
|
|
23
|
-
itemKind: "invariant" | "derived";
|
|
24
|
-
section: "Invariants" | "Derived";
|
|
25
|
-
ordinal: number;
|
|
26
|
-
groupSize: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface ReflectionGovernanceEntry {
|
|
30
|
-
priority?: string;
|
|
31
|
-
status?: string;
|
|
32
|
-
area?: string;
|
|
33
|
-
summary: string;
|
|
34
|
-
details?: string;
|
|
35
|
-
suggestedAction?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function extractSectionMarkdown(markdown: string, heading: string): string {
|
|
1
|
+
function extractSectionMarkdown(markdown, heading) {
|
|
39
2
|
const lines = markdown.split(/\r?\n/);
|
|
40
3
|
const headingNeedle = `## ${heading}`.toLowerCase();
|
|
41
4
|
let inSection = false;
|
|
42
|
-
const collected
|
|
5
|
+
const collected = [];
|
|
43
6
|
for (const raw of lines) {
|
|
44
7
|
const line = raw.trim();
|
|
45
8
|
const lower = line.toLowerCase();
|
|
@@ -53,10 +16,9 @@ export function extractSectionMarkdown(markdown: string, heading: string): strin
|
|
|
53
16
|
}
|
|
54
17
|
return collected.join("\n").trim();
|
|
55
18
|
}
|
|
56
|
-
|
|
57
|
-
export function parseSectionBullets(markdown: string, heading: string): string[] {
|
|
19
|
+
function parseSectionBullets(markdown, heading) {
|
|
58
20
|
const lines = extractSectionMarkdown(markdown, heading).split(/\r?\n/);
|
|
59
|
-
const collected
|
|
21
|
+
const collected = [];
|
|
60
22
|
for (const raw of lines) {
|
|
61
23
|
const line = raw.trim();
|
|
62
24
|
if (line.startsWith("- ") || line.startsWith("* ")) {
|
|
@@ -66,8 +28,7 @@ export function parseSectionBullets(markdown: string, heading: string): string[]
|
|
|
66
28
|
}
|
|
67
29
|
return collected;
|
|
68
30
|
}
|
|
69
|
-
|
|
70
|
-
export function isPlaceholderReflectionSliceLine(line: string): boolean {
|
|
31
|
+
function isPlaceholderReflectionSliceLine(line) {
|
|
71
32
|
const normalized = line.replace(/\*\*/g, "").trim();
|
|
72
33
|
if (!normalized) return true;
|
|
73
34
|
if (/^\(none( captured)?\)$/i.test(normalized)) return true;
|
|
@@ -77,189 +38,152 @@ export function isPlaceholderReflectionSliceLine(line: string): boolean {
|
|
|
77
38
|
if (/investigate why embedded reflection generation failed/i.test(normalized)) return true;
|
|
78
39
|
return false;
|
|
79
40
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return line
|
|
83
|
-
.replace(/\*\*/g, "")
|
|
84
|
-
.replace(/^(invariants?|reflections?|derived)[::]\s*/i, "")
|
|
85
|
-
.trim();
|
|
41
|
+
function normalizeReflectionSliceLine(line) {
|
|
42
|
+
return line.replace(/\*\*/g, "").replace(/^(invariants?|reflections?|derived)[::]\s*/i, "").trim();
|
|
86
43
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return lines
|
|
90
|
-
.map(normalizeReflectionSliceLine)
|
|
91
|
-
.filter((line) => !isPlaceholderReflectionSliceLine(line));
|
|
44
|
+
function sanitizeReflectionSliceLines(lines) {
|
|
45
|
+
return lines.map(normalizeReflectionSliceLine).filter((line) => !isPlaceholderReflectionSliceLine(line));
|
|
92
46
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return /^(always|never|when\b|if\b|before\b|after\b|prefer\b|avoid\b|require\b|only\b|do not\b|must\b|should\b)/i.test(line) ||
|
|
96
|
-
/\b(must|should|never|always|prefer|avoid|required?)\b/i.test(line);
|
|
47
|
+
function isInvariantRuleLike(line) {
|
|
48
|
+
return /^(always|never|when\b|if\b|before\b|after\b|prefer\b|avoid\b|require\b|only\b|do not\b|must\b|should\b)/i.test(line) || /\b(must|should|never|always|prefer|avoid|required?)\b/i.test(line);
|
|
97
49
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return /^(this run|next run|going forward|follow-up|re-check|retest|verify|confirm|avoid repeating|adjust|change|update|retry|keep|watch)\b/i.test(line) ||
|
|
101
|
-
/\b(this run|next run|delta|change|adjust|retry|re-check|retest|verify|confirm|avoid repeating|follow-up)\b/i.test(line);
|
|
50
|
+
function isDerivedDeltaLike(line) {
|
|
51
|
+
return /^(this run|next run|going forward|follow-up|re-check|retest|verify|confirm|avoid repeating|adjust|change|update|retry|keep|watch)\b/i.test(line) || /\b(this run|next run|delta|change|adjust|retry|re-check|retest|verify|confirm|avoid repeating|follow-up)\b/i.test(line);
|
|
102
52
|
}
|
|
103
|
-
|
|
104
|
-
function isOpenLoopAction(line: string): boolean {
|
|
53
|
+
function isOpenLoopAction(line) {
|
|
105
54
|
return /^(investigate|verify|confirm|re-check|retest|update|add|remove|fix|avoid|keep|watch|document)\b/i.test(line);
|
|
106
55
|
}
|
|
107
|
-
|
|
108
|
-
export function extractReflectionLessons(reflectionText: string): string[] {
|
|
56
|
+
function extractReflectionLessons(reflectionText) {
|
|
109
57
|
return sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, "Lessons & pitfalls (symptom / cause / fix / prevention)"));
|
|
110
58
|
}
|
|
111
|
-
|
|
112
|
-
export function extractReflectionLearningGovernanceCandidates(reflectionText: string): ReflectionGovernanceEntry[] {
|
|
59
|
+
function extractReflectionLearningGovernanceCandidates(reflectionText) {
|
|
113
60
|
const section = extractSectionMarkdown(reflectionText, "Learning governance candidates (.learnings / promotion / skill extraction)");
|
|
114
61
|
if (!section) return [];
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
.split(/(?=^###\s+Entry\b)/gim)
|
|
118
|
-
.map((block) => block.trim())
|
|
119
|
-
.filter(Boolean);
|
|
120
|
-
|
|
121
|
-
const parsed = entryBlocks
|
|
122
|
-
.map(parseReflectionGovernanceEntry)
|
|
123
|
-
.filter((entry): entry is ReflectionGovernanceEntry => entry !== null);
|
|
124
|
-
|
|
62
|
+
const entryBlocks = section.split(/(?=^###\s+Entry\b)/gim).map((block) => block.trim()).filter(Boolean);
|
|
63
|
+
const parsed = entryBlocks.map(parseReflectionGovernanceEntry).filter((entry) => entry !== null);
|
|
125
64
|
if (parsed.length > 0) return parsed;
|
|
126
|
-
|
|
127
65
|
const fallbackBullets = sanitizeReflectionSliceLines(
|
|
128
66
|
parseSectionBullets(reflectionText, "Learning governance candidates (.learnings / promotion / skill extraction)")
|
|
129
67
|
);
|
|
130
68
|
if (fallbackBullets.length === 0) return [];
|
|
131
|
-
|
|
132
69
|
return [{
|
|
133
70
|
priority: "medium",
|
|
134
71
|
status: "pending",
|
|
135
72
|
area: "config",
|
|
136
73
|
summary: "Reflection learning governance candidates",
|
|
137
74
|
details: fallbackBullets.map((line) => `- ${line}`).join("\n"),
|
|
138
|
-
suggestedAction: "Review the governance candidates, promote durable rules to AGENTS.md / SOUL.md / TOOLS.md when stable, and extract a skill if the pattern becomes reusable."
|
|
75
|
+
suggestedAction: "Review the governance candidates, promote durable rules to AGENTS.md / SOUL.md / TOOLS.md when stable, and extract a skill if the pattern becomes reusable."
|
|
139
76
|
}];
|
|
140
77
|
}
|
|
141
|
-
|
|
142
|
-
function parseReflectionGovernanceEntry(block: string): ReflectionGovernanceEntry | null {
|
|
78
|
+
function parseReflectionGovernanceEntry(block) {
|
|
143
79
|
const body = block.replace(/^###\s+Entry\b[^\n]*\n?/i, "").trim();
|
|
144
80
|
if (!body) return null;
|
|
145
|
-
|
|
146
|
-
const readField = (label: string): string | undefined => {
|
|
81
|
+
const readField = (label) => {
|
|
147
82
|
const match = body.match(new RegExp(`^\\*\\*${label}\\*\\*:\\s*(.+)$`, "im"));
|
|
148
83
|
const value = match?.[1]?.trim();
|
|
149
|
-
return value ? value :
|
|
84
|
+
return value ? value : void 0;
|
|
150
85
|
};
|
|
151
|
-
|
|
152
|
-
const readSection = (label: string): string | undefined => {
|
|
86
|
+
const readSection = (label) => {
|
|
153
87
|
const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
154
88
|
const match = body.match(new RegExp(`^###\\s+${escaped}\\s*\\n([\\s\\S]*?)(?=^###\\s+|$)`, "im"));
|
|
155
89
|
const value = match?.[1]?.trim();
|
|
156
|
-
return value ? value :
|
|
90
|
+
return value ? value : void 0;
|
|
157
91
|
};
|
|
158
|
-
|
|
159
92
|
const summary = readSection("Summary");
|
|
160
93
|
if (!summary) return null;
|
|
161
|
-
|
|
162
94
|
return {
|
|
163
95
|
priority: readField("Priority"),
|
|
164
96
|
status: readField("Status"),
|
|
165
97
|
area: readField("Area"),
|
|
166
98
|
summary,
|
|
167
99
|
details: readSection("Details"),
|
|
168
|
-
suggestedAction: readSection("Suggested Action")
|
|
100
|
+
suggestedAction: readSection("Suggested Action")
|
|
169
101
|
};
|
|
170
102
|
}
|
|
171
|
-
|
|
172
|
-
export function extractReflectionMappedMemories(reflectionText: string): ReflectionMappedMemory[] {
|
|
103
|
+
function extractReflectionMappedMemories(reflectionText) {
|
|
173
104
|
return extractReflectionMappedMemoryItems(reflectionText).map(({ text, category, heading }) => ({ text, category, heading }));
|
|
174
105
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const mappedSections: Array<{
|
|
178
|
-
heading: string;
|
|
179
|
-
category: "preference" | "fact" | "decision";
|
|
180
|
-
mappedKind: ReflectionMappedKind;
|
|
181
|
-
}> = [
|
|
106
|
+
function extractReflectionMappedMemoryItems(reflectionText) {
|
|
107
|
+
const mappedSections = [
|
|
182
108
|
{
|
|
183
109
|
heading: "User model deltas (about the human)",
|
|
184
110
|
category: "preference",
|
|
185
|
-
mappedKind: "user-model"
|
|
111
|
+
mappedKind: "user-model"
|
|
186
112
|
},
|
|
187
113
|
{
|
|
188
114
|
heading: "Agent model deltas (about the assistant/system)",
|
|
189
115
|
category: "preference",
|
|
190
|
-
mappedKind: "agent-model"
|
|
116
|
+
mappedKind: "agent-model"
|
|
191
117
|
},
|
|
192
118
|
{
|
|
193
119
|
heading: "Lessons & pitfalls (symptom / cause / fix / prevention)",
|
|
194
120
|
category: "fact",
|
|
195
|
-
mappedKind: "lesson"
|
|
121
|
+
mappedKind: "lesson"
|
|
196
122
|
},
|
|
197
123
|
{
|
|
198
124
|
heading: "Decisions (durable)",
|
|
199
125
|
category: "decision",
|
|
200
|
-
mappedKind: "decision"
|
|
201
|
-
}
|
|
126
|
+
mappedKind: "decision"
|
|
127
|
+
}
|
|
202
128
|
];
|
|
203
|
-
|
|
204
129
|
return mappedSections.flatMap(({ heading, category, mappedKind }) => {
|
|
205
130
|
const lines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, heading));
|
|
206
131
|
const groupSize = lines.length;
|
|
207
132
|
return lines.map((text, ordinal) => ({ text, category, heading, mappedKind, ordinal, groupSize }));
|
|
208
133
|
});
|
|
209
134
|
}
|
|
210
|
-
|
|
211
|
-
export function extractReflectionSlices(reflectionText: string): ReflectionSlices {
|
|
135
|
+
function extractReflectionSlices(reflectionText) {
|
|
212
136
|
const invariantSection = parseSectionBullets(reflectionText, "Invariants");
|
|
213
137
|
const derivedSection = parseSectionBullets(reflectionText, "Derived");
|
|
214
138
|
const mergedSection = parseSectionBullets(reflectionText, "Invariants & Reflections");
|
|
215
|
-
|
|
216
139
|
const invariantsPrimary = sanitizeReflectionSliceLines(invariantSection).filter(isInvariantRuleLike);
|
|
217
140
|
const derivedPrimary = sanitizeReflectionSliceLines(derivedSection).filter(isDerivedDeltaLike);
|
|
218
|
-
|
|
219
141
|
const invariantLinesLegacy = sanitizeReflectionSliceLines(
|
|
220
142
|
mergedSection.filter((line) => /invariant|stable|policy|rule/i.test(line))
|
|
221
143
|
).filter(isInvariantRuleLike);
|
|
222
144
|
const reflectionLinesLegacy = sanitizeReflectionSliceLines(
|
|
223
145
|
mergedSection.filter((line) => /reflect|inherit|derive|change|apply/i.test(line))
|
|
224
146
|
).filter(isDerivedDeltaLike);
|
|
225
|
-
const openLoopLines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, "Open loops / next actions"))
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
.filter(isInvariantRuleLike);
|
|
230
|
-
|
|
231
|
-
const invariants = invariantsPrimary.length > 0
|
|
232
|
-
? invariantsPrimary
|
|
233
|
-
: (invariantLinesLegacy.length > 0 ? invariantLinesLegacy : durableDecisionLines);
|
|
234
|
-
const derived = derivedPrimary.length > 0
|
|
235
|
-
? derivedPrimary
|
|
236
|
-
: [...reflectionLinesLegacy, ...openLoopLines];
|
|
237
|
-
|
|
147
|
+
const openLoopLines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, "Open loops / next actions")).filter(isOpenLoopAction).filter(isDerivedDeltaLike);
|
|
148
|
+
const durableDecisionLines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, "Decisions (durable)")).filter(isInvariantRuleLike);
|
|
149
|
+
const invariants = invariantsPrimary.length > 0 ? invariantsPrimary : invariantLinesLegacy.length > 0 ? invariantLinesLegacy : durableDecisionLines;
|
|
150
|
+
const derived = derivedPrimary.length > 0 ? derivedPrimary : [...reflectionLinesLegacy, ...openLoopLines];
|
|
238
151
|
return {
|
|
239
152
|
invariants: invariants.slice(0, 8),
|
|
240
|
-
derived: derived.slice(0, 10)
|
|
153
|
+
derived: derived.slice(0, 10)
|
|
241
154
|
};
|
|
242
155
|
}
|
|
243
|
-
|
|
244
|
-
export function extractReflectionSliceItems(reflectionText: string): ReflectionSliceItem[] {
|
|
156
|
+
function extractReflectionSliceItems(reflectionText) {
|
|
245
157
|
const slices = extractReflectionSlices(reflectionText);
|
|
246
158
|
const invariantGroupSize = slices.invariants.length;
|
|
247
159
|
const derivedGroupSize = slices.derived.length;
|
|
248
|
-
|
|
249
160
|
const invariantItems = slices.invariants.map((text, ordinal) => ({
|
|
250
161
|
text,
|
|
251
|
-
itemKind: "invariant"
|
|
252
|
-
section: "Invariants"
|
|
162
|
+
itemKind: "invariant",
|
|
163
|
+
section: "Invariants",
|
|
253
164
|
ordinal,
|
|
254
|
-
groupSize: invariantGroupSize
|
|
165
|
+
groupSize: invariantGroupSize
|
|
255
166
|
}));
|
|
256
167
|
const derivedItems = slices.derived.map((text, ordinal) => ({
|
|
257
168
|
text,
|
|
258
|
-
itemKind: "derived"
|
|
259
|
-
section: "Derived"
|
|
169
|
+
itemKind: "derived",
|
|
170
|
+
section: "Derived",
|
|
260
171
|
ordinal,
|
|
261
|
-
groupSize: derivedGroupSize
|
|
172
|
+
groupSize: derivedGroupSize
|
|
262
173
|
}));
|
|
263
|
-
|
|
264
174
|
return [...invariantItems, ...derivedItems];
|
|
265
175
|
}
|
|
176
|
+
export {
|
|
177
|
+
extractReflectionLearningGovernanceCandidates,
|
|
178
|
+
extractReflectionLessons,
|
|
179
|
+
extractReflectionMappedMemories,
|
|
180
|
+
extractReflectionMappedMemoryItems,
|
|
181
|
+
extractReflectionSliceItems,
|
|
182
|
+
extractReflectionSlices,
|
|
183
|
+
extractSectionMarkdown,
|
|
184
|
+
isPlaceholderReflectionSliceLine,
|
|
185
|
+
normalizeReflectionSliceLine,
|
|
186
|
+
parseSectionBullets,
|
|
187
|
+
sanitizeReflectionSliceLines
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=reflection-slices.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/reflection-slices.ts"],
|
|
4
|
+
"sourcesContent": ["// SPDX-License-Identifier: LicenseRef-Mnemo-Pro\nexport interface ReflectionSlices {\n invariants: string[];\n derived: string[];\n}\n\nexport interface ReflectionMappedMemory {\n text: string;\n category: \"preference\" | \"fact\" | \"decision\";\n heading: string;\n}\n\nexport type ReflectionMappedKind = \"user-model\" | \"agent-model\" | \"lesson\" | \"decision\";\n\nexport interface ReflectionMappedMemoryItem extends ReflectionMappedMemory {\n mappedKind: ReflectionMappedKind;\n ordinal: number;\n groupSize: number;\n}\n\nexport interface ReflectionSliceItem {\n text: string;\n itemKind: \"invariant\" | \"derived\";\n section: \"Invariants\" | \"Derived\";\n ordinal: number;\n groupSize: number;\n}\n\nexport interface ReflectionGovernanceEntry {\n priority?: string;\n status?: string;\n area?: string;\n summary: string;\n details?: string;\n suggestedAction?: string;\n}\n\nexport function extractSectionMarkdown(markdown: string, heading: string): string {\n const lines = markdown.split(/\\r?\\n/);\n const headingNeedle = `## ${heading}`.toLowerCase();\n let inSection = false;\n const collected: string[] = [];\n for (const raw of lines) {\n const line = raw.trim();\n const lower = line.toLowerCase();\n if (lower.startsWith(\"## \")) {\n if (inSection && lower !== headingNeedle) break;\n inSection = lower === headingNeedle;\n continue;\n }\n if (!inSection) continue;\n collected.push(raw);\n }\n return collected.join(\"\\n\").trim();\n}\n\nexport function parseSectionBullets(markdown: string, heading: string): string[] {\n const lines = extractSectionMarkdown(markdown, heading).split(/\\r?\\n/);\n const collected: string[] = [];\n for (const raw of lines) {\n const line = raw.trim();\n if (line.startsWith(\"- \") || line.startsWith(\"* \")) {\n const normalized = line.slice(2).trim();\n if (normalized) collected.push(normalized);\n }\n }\n return collected;\n}\n\nexport function isPlaceholderReflectionSliceLine(line: string): boolean {\n const normalized = line.replace(/\\*\\*/g, \"\").trim();\n if (!normalized) return true;\n if (/^\\(none( captured)?\\)$/i.test(normalized)) return true;\n if (/^(invariants?|reflections?|derived)[:\uFF1A]$/i.test(normalized)) return true;\n if (/apply this session'?s deltas next run/i.test(normalized)) return true;\n if (/apply this session'?s distilled changes next run/i.test(normalized)) return true;\n if (/investigate why embedded reflection generation failed/i.test(normalized)) return true;\n return false;\n}\n\nexport function normalizeReflectionSliceLine(line: string): string {\n return line\n .replace(/\\*\\*/g, \"\")\n .replace(/^(invariants?|reflections?|derived)[:\uFF1A]\\s*/i, \"\")\n .trim();\n}\n\nexport function sanitizeReflectionSliceLines(lines: string[]): string[] {\n return lines\n .map(normalizeReflectionSliceLine)\n .filter((line) => !isPlaceholderReflectionSliceLine(line));\n}\n\nfunction isInvariantRuleLike(line: string): boolean {\n return /^(always|never|when\\b|if\\b|before\\b|after\\b|prefer\\b|avoid\\b|require\\b|only\\b|do not\\b|must\\b|should\\b)/i.test(line) ||\n /\\b(must|should|never|always|prefer|avoid|required?)\\b/i.test(line);\n}\n\nfunction isDerivedDeltaLike(line: string): boolean {\n return /^(this run|next run|going forward|follow-up|re-check|retest|verify|confirm|avoid repeating|adjust|change|update|retry|keep|watch)\\b/i.test(line) ||\n /\\b(this run|next run|delta|change|adjust|retry|re-check|retest|verify|confirm|avoid repeating|follow-up)\\b/i.test(line);\n}\n\nfunction isOpenLoopAction(line: string): boolean {\n return /^(investigate|verify|confirm|re-check|retest|update|add|remove|fix|avoid|keep|watch|document)\\b/i.test(line);\n}\n\nexport function extractReflectionLessons(reflectionText: string): string[] {\n return sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, \"Lessons & pitfalls (symptom / cause / fix / prevention)\"));\n}\n\nexport function extractReflectionLearningGovernanceCandidates(reflectionText: string): ReflectionGovernanceEntry[] {\n const section = extractSectionMarkdown(reflectionText, \"Learning governance candidates (.learnings / promotion / skill extraction)\");\n if (!section) return [];\n\n const entryBlocks = section\n .split(/(?=^###\\s+Entry\\b)/gim)\n .map((block) => block.trim())\n .filter(Boolean);\n\n const parsed = entryBlocks\n .map(parseReflectionGovernanceEntry)\n .filter((entry): entry is ReflectionGovernanceEntry => entry !== null);\n\n if (parsed.length > 0) return parsed;\n\n const fallbackBullets = sanitizeReflectionSliceLines(\n parseSectionBullets(reflectionText, \"Learning governance candidates (.learnings / promotion / skill extraction)\")\n );\n if (fallbackBullets.length === 0) return [];\n\n return [{\n priority: \"medium\",\n status: \"pending\",\n area: \"config\",\n summary: \"Reflection learning governance candidates\",\n details: fallbackBullets.map((line) => `- ${line}`).join(\"\\n\"),\n suggestedAction: \"Review the governance candidates, promote durable rules to AGENTS.md / SOUL.md / TOOLS.md when stable, and extract a skill if the pattern becomes reusable.\",\n }];\n}\n\nfunction parseReflectionGovernanceEntry(block: string): ReflectionGovernanceEntry | null {\n const body = block.replace(/^###\\s+Entry\\b[^\\n]*\\n?/i, \"\").trim();\n if (!body) return null;\n\n const readField = (label: string): string | undefined => {\n const match = body.match(new RegExp(`^\\\\*\\\\*${label}\\\\*\\\\*:\\\\s*(.+)$`, \"im\"));\n const value = match?.[1]?.trim();\n return value ? value : undefined;\n };\n\n const readSection = (label: string): string | undefined => {\n const escaped = label.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n const match = body.match(new RegExp(`^###\\\\s+${escaped}\\\\s*\\\\n([\\\\s\\\\S]*?)(?=^###\\\\s+|$)`, \"im\"));\n const value = match?.[1]?.trim();\n return value ? value : undefined;\n };\n\n const summary = readSection(\"Summary\");\n if (!summary) return null;\n\n return {\n priority: readField(\"Priority\"),\n status: readField(\"Status\"),\n area: readField(\"Area\"),\n summary,\n details: readSection(\"Details\"),\n suggestedAction: readSection(\"Suggested Action\"),\n };\n}\n\nexport function extractReflectionMappedMemories(reflectionText: string): ReflectionMappedMemory[] {\n return extractReflectionMappedMemoryItems(reflectionText).map(({ text, category, heading }) => ({ text, category, heading }));\n}\n\nexport function extractReflectionMappedMemoryItems(reflectionText: string): ReflectionMappedMemoryItem[] {\n const mappedSections: Array<{\n heading: string;\n category: \"preference\" | \"fact\" | \"decision\";\n mappedKind: ReflectionMappedKind;\n }> = [\n {\n heading: \"User model deltas (about the human)\",\n category: \"preference\",\n mappedKind: \"user-model\",\n },\n {\n heading: \"Agent model deltas (about the assistant/system)\",\n category: \"preference\",\n mappedKind: \"agent-model\",\n },\n {\n heading: \"Lessons & pitfalls (symptom / cause / fix / prevention)\",\n category: \"fact\",\n mappedKind: \"lesson\",\n },\n {\n heading: \"Decisions (durable)\",\n category: \"decision\",\n mappedKind: \"decision\",\n },\n ];\n\n return mappedSections.flatMap(({ heading, category, mappedKind }) => {\n const lines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, heading));\n const groupSize = lines.length;\n return lines.map((text, ordinal) => ({ text, category, heading, mappedKind, ordinal, groupSize }));\n });\n}\n\nexport function extractReflectionSlices(reflectionText: string): ReflectionSlices {\n const invariantSection = parseSectionBullets(reflectionText, \"Invariants\");\n const derivedSection = parseSectionBullets(reflectionText, \"Derived\");\n const mergedSection = parseSectionBullets(reflectionText, \"Invariants & Reflections\");\n\n const invariantsPrimary = sanitizeReflectionSliceLines(invariantSection).filter(isInvariantRuleLike);\n const derivedPrimary = sanitizeReflectionSliceLines(derivedSection).filter(isDerivedDeltaLike);\n\n const invariantLinesLegacy = sanitizeReflectionSliceLines(\n mergedSection.filter((line) => /invariant|stable|policy|rule/i.test(line))\n ).filter(isInvariantRuleLike);\n const reflectionLinesLegacy = sanitizeReflectionSliceLines(\n mergedSection.filter((line) => /reflect|inherit|derive|change|apply/i.test(line))\n ).filter(isDerivedDeltaLike);\n const openLoopLines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, \"Open loops / next actions\"))\n .filter(isOpenLoopAction)\n .filter(isDerivedDeltaLike);\n const durableDecisionLines = sanitizeReflectionSliceLines(parseSectionBullets(reflectionText, \"Decisions (durable)\"))\n .filter(isInvariantRuleLike);\n\n const invariants = invariantsPrimary.length > 0\n ? invariantsPrimary\n : (invariantLinesLegacy.length > 0 ? invariantLinesLegacy : durableDecisionLines);\n const derived = derivedPrimary.length > 0\n ? derivedPrimary\n : [...reflectionLinesLegacy, ...openLoopLines];\n\n return {\n invariants: invariants.slice(0, 8),\n derived: derived.slice(0, 10),\n };\n}\n\nexport function extractReflectionSliceItems(reflectionText: string): ReflectionSliceItem[] {\n const slices = extractReflectionSlices(reflectionText);\n const invariantGroupSize = slices.invariants.length;\n const derivedGroupSize = slices.derived.length;\n\n const invariantItems = slices.invariants.map((text, ordinal) => ({\n text,\n itemKind: \"invariant\" as const,\n section: \"Invariants\" as const,\n ordinal,\n groupSize: invariantGroupSize,\n }));\n const derivedItems = slices.derived.map((text, ordinal) => ({\n text,\n itemKind: \"derived\" as const,\n section: \"Derived\" as const,\n ordinal,\n groupSize: derivedGroupSize,\n }));\n\n return [...invariantItems, ...derivedItems];\n}\n"],
|
|
5
|
+
"mappings": "AAqCO,SAAS,uBAAuB,UAAkB,SAAyB;AAChF,QAAM,QAAQ,SAAS,MAAM,OAAO;AACpC,QAAM,gBAAgB,MAAM,OAAO,GAAG,YAAY;AAClD,MAAI,YAAY;AAChB,QAAM,YAAsB,CAAC;AAC7B,aAAW,OAAO,OAAO;AACvB,UAAM,OAAO,IAAI,KAAK;AACtB,UAAM,QAAQ,KAAK,YAAY;AAC/B,QAAI,MAAM,WAAW,KAAK,GAAG;AAC3B,UAAI,aAAa,UAAU,cAAe;AAC1C,kBAAY,UAAU;AACtB;AAAA,IACF;AACA,QAAI,CAAC,UAAW;AAChB,cAAU,KAAK,GAAG;AAAA,EACpB;AACA,SAAO,UAAU,KAAK,IAAI,EAAE,KAAK;AACnC;AAEO,SAAS,oBAAoB,UAAkB,SAA2B;AAC/E,QAAM,QAAQ,uBAAuB,UAAU,OA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ryEntry, MemorySearchResult } from "./store.js";
|
|
2
|
+
import { type ReflectionSlices } from "./reflection-slices.js";
|
|
3
|
+
export declare const REFLECTION_DERIVE_LOGISTIC_MIDPOINT_DAYS = 3;
|
|
4
|
+
export declare const REFLECTION_DERIVE_LOGISTIC_K = 1.2;
|
|
5
|
+
export declare const REFLECTION_DERIVE_FALLBACK_BASE_WEIGHT = 0.35;
|
|
6
|
+
export declare const DEFAULT_REFLECTION_DERIVED_MAX_AGE_MS: number;
|
|
7
|
+
export declare const DEFAULT_REFLECTION_MAPPED_MAX_AGE_MS: number;
|
|
8
|
+
type ReflectionStoreKind = "event" | "item-invariant" | "item-derived" | "combined-legacy";
|
|
9
|
+
type ReflectionErrorSignalLike = {
|
|
10
|
+
signatureHash: string;
|
|
11
|
+
};
|
|
12
|
+
interface ReflectionStorePayload {
|
|
13
|
+
text: string;
|
|
14
|
+
metadata: Record<string, unknown>;
|
|
15
|
+
kind: ReflectionStoreKind;
|
|
16
|
+
}
|
|
17
|
+
interface BuildReflectionStorePayloadsParams {
|
|
18
|
+
reflectionText: string;
|
|
19
|
+
sessionKey: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
agentId: string;
|
|
22
|
+
command: string;
|
|
23
|
+
scope: string;
|
|
24
|
+
toolErrorSignals: ReflectionErrorSignalLike[];
|
|
25
|
+
runAt: number;
|
|
26
|
+
usedFallback: boolean;
|
|
27
|
+
eventId?: string;
|
|
28
|
+
sourceReflectionPath?: string;
|
|
29
|
+
writeLegacyCombined?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function buildReflectionStorePayloads(params: BuildReflectionStorePayloadsParams): {
|
|
32
|
+
eventId: string;
|
|
33
|
+
slices: ReflectionSlices;
|
|
34
|
+
payloads: ReflectionStorePayload[];
|
|
35
|
+
};
|
|
36
|
+
interface ReflectionStoreDeps {
|
|
37
|
+
embedPassage: (text: string) => Promise<number[]>;
|
|
38
|
+
vectorSearch: (vector: number[], limit?: number, minScore?: number, scopeFilter?: string[]) => Promise<MemorySearchResult[]>;
|
|
39
|
+
store: (entry: Omit<MemoryEntry, "id" | "timestamp">) => Promise<MemoryEntry>;
|
|
40
|
+
}
|
|
41
|
+
interface StoreReflectionToLanceDBParams extends BuildReflectionStorePayloadsParams, ReflectionStoreDeps {
|
|
42
|
+
dedupeThreshold?: number;
|
|
43
|
+
}
|
|
44
|
+
export declare function storeReflectionToLanceDB(params: StoreReflectionToLanceDBParams): Promise<{
|
|
45
|
+
stored: boolean;
|
|
46
|
+
eventId: string;
|
|
47
|
+
slices: ReflectionSlices;
|
|
48
|
+
storedKinds: ReflectionStoreKind[];
|
|
49
|
+
}>;
|
|
50
|
+
export interface LoadReflectionSlicesParams {
|
|
51
|
+
entries: MemoryEntry[];
|
|
52
|
+
agentId: string;
|
|
53
|
+
now?: number;
|
|
54
|
+
deriveMaxAgeMs?: number;
|
|
55
|
+
invariantMaxAgeMs?: number;
|
|
56
|
+
}
|
|
57
|
+
export declare function loadAgentReflectionSlicesFromEntries(params: LoadReflectionSlicesParams): {
|
|
58
|
+
invariants: string[];
|
|
59
|
+
derived: string[];
|
|
60
|
+
};
|
|
61
|
+
export declare function computeDerivedLineQuality(nonPlaceholderLineCount: number): number;
|
|
62
|
+
export interface LoadReflectionMappedRowsParams {
|
|
63
|
+
entries: MemoryEntry[];
|
|
64
|
+
agentId: string;
|
|
65
|
+
now?: number;
|
|
66
|
+
maxAgeMs?: number;
|
|
67
|
+
maxPerKind?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface ReflectionMappedSlices {
|
|
70
|
+
userModel: string[];
|
|
71
|
+
agentModel: string[];
|
|
72
|
+
lesson: string[];
|
|
73
|
+
decision: string[];
|
|
74
|
+
}
|
|
75
|
+
export declare function loadReflectionMappedRowsFromEntries(params: LoadReflectionMappedRowsParams): ReflectionMappedSlices;
|
|
76
|
+
export declare function getReflectionDerivedDecayDefaults(): {
|
|
77
|
+
midpointDays: number;
|
|
78
|
+
k: number;
|
|
79
|
+
};
|
|
80
|
+
export declare function getReflectionInvariantDecayDefaults(): {
|
|
81
|
+
midpointDays: number;
|
|
82
|
+
k: number;
|
|
83
|
+
};
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=reflection-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflection-store.d.ts","sourceRoot":"","sources":["../../src/reflection-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAchC,eAAO,MAAM,wCAAwC,IAAI,CAAC;AAC1D,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,sCAAsC,OAAO,CAAC;AAE3D,eAAO,MAAM,qCAAqC,QAA2B,CAAC;AAC9E,eAAO,MAAM,oCAAoC,QAA2B,CAAC;AAE7E,KAAK,mBAAmB,GAAG,OAAO,GAAG,gBAAgB,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAE3F,KAAK,yBAAyB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,UAAU,sBAAsB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAED,UAAU,kCAAkC;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,yBAAyB,EAAE,CAAC;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB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