@remnic/core 9.3.572 → 9.3.574

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.
@@ -1,135 +0,0 @@
1
- import {
2
- StorageManager
3
- } from "./chunk-IRFF6LSF.js";
4
-
5
- // src/semantic-rule-promotion.ts
6
- function normalizeRuleWhitespace(value) {
7
- return value.replace(/\s+/g, " ").trim();
8
- }
9
- function stripTrailingClausePunctuation(value) {
10
- return value.replace(/[,:;]+$/g, "").trim();
11
- }
12
- function canonicalizeRuleContent(value) {
13
- return extractExplicitIfThenRule(value) ?? normalizeRuleWhitespace(value);
14
- }
15
- function canonicalizeRuleKey(value) {
16
- return canonicalizeRuleContent(value).toLowerCase();
17
- }
18
- function extractExplicitIfThenRule(content) {
19
- const match = content.match(/\bif\b([\s\S]+?)\bthen\b([\s\S]+?)(?:[.!?](?:\s|$)|$)/i);
20
- if (!match) return null;
21
- const condition = stripTrailingClausePunctuation(normalizeRuleWhitespace(match[1] ?? ""));
22
- const outcome = stripTrailingClausePunctuation(normalizeRuleWhitespace(match[2] ?? ""));
23
- if (condition.length === 0 || outcome.length === 0) return null;
24
- return `IF ${condition} THEN ${outcome}.`;
25
- }
26
- function promotionConfidence(memory) {
27
- const base = Number.isFinite(memory.frontmatter.confidence) ? memory.frontmatter.confidence : 0.8;
28
- return Math.max(0.6, Math.min(0.98, base));
29
- }
30
- function promotionTags(memory) {
31
- return Array.from(/* @__PURE__ */ new Set([...memory.frontmatter.tags ?? [], "semantic-rule", "promoted-rule"]));
32
- }
33
- function buildSupportLinks(sourceMemoryId, confidence) {
34
- return [
35
- {
36
- targetId: sourceMemoryId,
37
- linkType: "supports",
38
- strength: confidence,
39
- reason: "Promoted from verified episodic memory"
40
- }
41
- ];
42
- }
43
- async function promoteSemanticRuleFromMemory(options) {
44
- const report = {
45
- enabled: options.enabled,
46
- dryRun: options.dryRun === true,
47
- promoted: [],
48
- skipped: []
49
- };
50
- if (!options.enabled) {
51
- report.skipped.push({
52
- sourceMemoryId: options.sourceMemoryId,
53
- reason: "disabled"
54
- });
55
- return report;
56
- }
57
- const storage = new StorageManager(options.memoryDir);
58
- const sourceMemory = await storage.getMemoryById(options.sourceMemoryId);
59
- if (!sourceMemory) {
60
- report.skipped.push({
61
- sourceMemoryId: options.sourceMemoryId,
62
- reason: "source-memory-missing"
63
- });
64
- return report;
65
- }
66
- if (sourceMemory.frontmatter.status === "forgotten") {
67
- report.skipped.push({
68
- sourceMemoryId: options.sourceMemoryId,
69
- reason: "source-memory-forgotten"
70
- });
71
- return report;
72
- }
73
- if (sourceMemory.frontmatter.status === "archived" || sourceMemory.frontmatter.memoryKind !== "episode") {
74
- report.skipped.push({
75
- sourceMemoryId: options.sourceMemoryId,
76
- reason: "source-memory-not-episode"
77
- });
78
- return report;
79
- }
80
- const content = extractExplicitIfThenRule(sourceMemory.content);
81
- if (!content) {
82
- report.skipped.push({
83
- sourceMemoryId: options.sourceMemoryId,
84
- reason: "no-explicit-rule"
85
- });
86
- return report;
87
- }
88
- const ruleKey = canonicalizeRuleKey(content);
89
- const existingRule = (await storage.readAllMemories()).find(
90
- (memory) => memory.frontmatter.category === "rule" && memory.frontmatter.status !== "archived" && memory.frontmatter.status !== "forgotten" && canonicalizeRuleKey(memory.content) === ruleKey
91
- );
92
- if (existingRule) {
93
- report.skipped.push({
94
- sourceMemoryId: options.sourceMemoryId,
95
- reason: "duplicate-rule",
96
- existingRuleId: existingRule.frontmatter.id
97
- });
98
- return report;
99
- }
100
- const confidence = promotionConfidence(sourceMemory);
101
- const candidateBase = {
102
- sourceMemoryId: options.sourceMemoryId,
103
- content,
104
- confidence,
105
- tags: promotionTags(sourceMemory),
106
- memoryKind: "note",
107
- lineage: [options.sourceMemoryId]
108
- };
109
- if (options.dryRun === true) {
110
- report.promoted.push({
111
- id: `dry-run:${options.sourceMemoryId}`,
112
- ...candidateBase
113
- });
114
- return report;
115
- }
116
- const id = await storage.writeMemory("rule", content, {
117
- confidence,
118
- tags: candidateBase.tags,
119
- source: "semantic-rule-promotion",
120
- lineage: candidateBase.lineage,
121
- sourceMemoryId: options.sourceMemoryId,
122
- memoryKind: "note",
123
- links: buildSupportLinks(options.sourceMemoryId, confidence)
124
- });
125
- report.promoted.push({
126
- id,
127
- ...candidateBase
128
- });
129
- return report;
130
- }
131
-
132
- export {
133
- promoteSemanticRuleFromMemory
134
- };
135
- //# sourceMappingURL=chunk-74VA26CT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/semantic-rule-promotion.ts"],"sourcesContent":["import { StorageManager } from \"./storage.js\";\nimport type { MemoryFile, MemoryLink } from \"./types.js\";\n\nexport interface SemanticRulePromotionCandidate {\n id: string;\n sourceMemoryId: string;\n content: string;\n confidence: number;\n tags: string[];\n memoryKind: \"note\";\n lineage: string[];\n}\n\nexport interface SemanticRulePromotionSkip {\n sourceMemoryId: string;\n reason:\n | \"disabled\"\n | \"source-memory-missing\"\n | \"source-memory-forgotten\"\n | \"source-memory-not-episode\"\n | \"no-explicit-rule\"\n | \"duplicate-rule\";\n existingRuleId?: string;\n}\n\nexport interface SemanticRulePromotionReport {\n enabled: boolean;\n dryRun: boolean;\n promoted: SemanticRulePromotionCandidate[];\n skipped: SemanticRulePromotionSkip[];\n}\n\nfunction normalizeRuleWhitespace(value: string): string {\n return value.replace(/\\s+/g, \" \").trim();\n}\n\nfunction stripTrailingClausePunctuation(value: string): string {\n return value.replace(/[,:;]+$/g, \"\").trim();\n}\n\nfunction canonicalizeRuleContent(value: string): string {\n return extractExplicitIfThenRule(value) ?? normalizeRuleWhitespace(value);\n}\n\nfunction canonicalizeRuleKey(value: string): string {\n return canonicalizeRuleContent(value).toLowerCase();\n}\n\nfunction extractExplicitIfThenRule(content: string): string | null {\n const match = content.match(/\\bif\\b([\\s\\S]+?)\\bthen\\b([\\s\\S]+?)(?:[.!?](?:\\s|$)|$)/i);\n if (!match) return null;\n const condition = stripTrailingClausePunctuation(normalizeRuleWhitespace(match[1] ?? \"\"));\n const outcome = stripTrailingClausePunctuation(normalizeRuleWhitespace(match[2] ?? \"\"));\n if (condition.length === 0 || outcome.length === 0) return null;\n return `IF ${condition} THEN ${outcome}.`;\n}\n\nfunction promotionConfidence(memory: MemoryFile): number {\n const base = Number.isFinite(memory.frontmatter.confidence) ? memory.frontmatter.confidence : 0.8;\n return Math.max(0.6, Math.min(0.98, base));\n}\n\nfunction promotionTags(memory: MemoryFile): string[] {\n return Array.from(new Set([...(memory.frontmatter.tags ?? []), \"semantic-rule\", \"promoted-rule\"]));\n}\n\nfunction buildSupportLinks(sourceMemoryId: string, confidence: number): MemoryLink[] {\n return [\n {\n targetId: sourceMemoryId,\n linkType: \"supports\",\n strength: confidence,\n reason: \"Promoted from verified episodic memory\",\n },\n ];\n}\n\nexport async function promoteSemanticRuleFromMemory(options: {\n memoryDir: string;\n enabled: boolean;\n sourceMemoryId: string;\n dryRun?: boolean;\n}): Promise<SemanticRulePromotionReport> {\n const report: SemanticRulePromotionReport = {\n enabled: options.enabled,\n dryRun: options.dryRun === true,\n promoted: [],\n skipped: [],\n };\n if (!options.enabled) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"disabled\",\n });\n return report;\n }\n\n const storage = new StorageManager(options.memoryDir);\n const sourceMemory = await storage.getMemoryById(options.sourceMemoryId);\n if (!sourceMemory) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"source-memory-missing\",\n });\n return report;\n }\n if (sourceMemory.frontmatter.status === \"forgotten\") {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"source-memory-forgotten\",\n });\n return report;\n }\n if (\n sourceMemory.frontmatter.status === \"archived\" ||\n sourceMemory.frontmatter.memoryKind !== \"episode\"\n ) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"source-memory-not-episode\",\n });\n return report;\n }\n\n const content = extractExplicitIfThenRule(sourceMemory.content);\n if (!content) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"no-explicit-rule\",\n });\n return report;\n }\n\n const ruleKey = canonicalizeRuleKey(content);\n const existingRule = (await storage.readAllMemories()).find(\n (memory) =>\n memory.frontmatter.category === \"rule\" &&\n memory.frontmatter.status !== \"archived\" &&\n memory.frontmatter.status !== \"forgotten\" &&\n canonicalizeRuleKey(memory.content) === ruleKey,\n );\n if (existingRule) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"duplicate-rule\",\n existingRuleId: existingRule.frontmatter.id,\n });\n return report;\n }\n\n const confidence = promotionConfidence(sourceMemory);\n const candidateBase = {\n sourceMemoryId: options.sourceMemoryId,\n content,\n confidence,\n tags: promotionTags(sourceMemory),\n memoryKind: \"note\" as const,\n lineage: [options.sourceMemoryId],\n };\n\n if (options.dryRun === true) {\n report.promoted.push({\n id: `dry-run:${options.sourceMemoryId}`,\n ...candidateBase,\n });\n return report;\n }\n\n const id = await storage.writeMemory(\"rule\", content, {\n confidence,\n tags: candidateBase.tags,\n source: \"semantic-rule-promotion\",\n lineage: candidateBase.lineage,\n sourceMemoryId: options.sourceMemoryId,\n memoryKind: \"note\",\n links: buildSupportLinks(options.sourceMemoryId, confidence),\n });\n report.promoted.push({\n id,\n ...candidateBase,\n });\n return report;\n}\n"],"mappings":";;;;;AAgCA,SAAS,wBAAwB,OAAuB;AACtD,SAAO,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACzC;AAEA,SAAS,+BAA+B,OAAuB;AAC7D,SAAO,MAAM,QAAQ,YAAY,EAAE,EAAE,KAAK;AAC5C;AAEA,SAAS,wBAAwB,OAAuB;AACtD,SAAO,0BAA0B,KAAK,KAAK,wBAAwB,KAAK;AAC1E;AAEA,SAAS,oBAAoB,OAAuB;AAClD,SAAO,wBAAwB,KAAK,EAAE,YAAY;AACpD;AAEA,SAAS,0BAA0B,SAAgC;AACjE,QAAM,QAAQ,QAAQ,MAAM,wDAAwD;AACpF,MAAI,CAAC,MAAO,QAAO;AACnB,QAA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