@graphorin/memory 0.6.0 → 0.7.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/CHANGELOG.md +83 -0
- package/README.md +24 -7
- package/dist/conflict/index.js +0 -1
- package/dist/conflict/pipeline.js +0 -1
- package/dist/conflict/pipeline.js.map +1 -1
- package/dist/conflict/stages/stage3-heuristic-regex.js +0 -1
- package/dist/conflict/stages/stage3-heuristic-regex.js.map +1 -1
- package/dist/conflict/types.d.ts +1 -1
- package/dist/conflict/types.js.map +1 -1
- package/dist/consolidator/index.js +2 -0
- package/dist/consolidator/index.js.map +1 -1
- package/dist/consolidator/lock.js +7 -1
- package/dist/consolidator/lock.js.map +1 -1
- package/dist/consolidator/phases/deep.js +19 -12
- package/dist/consolidator/phases/deep.js.map +1 -1
- package/dist/consolidator/phases/induce.d.ts.map +1 -1
- package/dist/consolidator/phases/induce.js +2 -3
- package/dist/consolidator/phases/induce.js.map +1 -1
- package/dist/consolidator/phases/reflect.js +35 -8
- package/dist/consolidator/phases/reflect.js.map +1 -1
- package/dist/consolidator/phases/standard.js +199 -28
- package/dist/consolidator/phases/standard.js.map +1 -1
- package/dist/consolidator/reconcile.js +16 -15
- package/dist/consolidator/reconcile.js.map +1 -1
- package/dist/consolidator/runtime.d.ts.map +1 -1
- package/dist/consolidator/runtime.js +129 -47
- package/dist/consolidator/runtime.js.map +1 -1
- package/dist/consolidator/scheduler.d.ts +17 -3
- package/dist/consolidator/scheduler.d.ts.map +1 -1
- package/dist/consolidator/scheduler.js.map +1 -1
- package/dist/consolidator/types.d.ts +30 -1
- package/dist/consolidator/types.d.ts.map +1 -1
- package/dist/consolidator/types.js +10 -0
- package/dist/consolidator/types.js.map +1 -1
- package/dist/context-engine/compaction/clear-tool-results.d.ts +1 -1
- package/dist/context-engine/compaction/clear-tool-results.js +1 -1
- package/dist/context-engine/compaction/clear-tool-results.js.map +1 -1
- package/dist/context-engine/compaction/compactor.d.ts +1 -0
- package/dist/context-engine/compaction/compactor.d.ts.map +1 -1
- package/dist/context-engine/compaction/compactor.js +32 -8
- package/dist/context-engine/compaction/compactor.js.map +1 -1
- package/dist/context-engine/compaction/hooks/types.d.ts +1 -1
- package/dist/context-engine/compaction/index.d.ts +1 -0
- package/dist/context-engine/compaction/templates/marker.d.ts +33 -0
- package/dist/context-engine/compaction/templates/marker.d.ts.map +1 -0
- package/dist/context-engine/compaction/templates/marker.js +34 -0
- package/dist/context-engine/compaction/templates/marker.js.map +1 -0
- package/dist/context-engine/compaction/templates/summary-9-section.d.ts +1 -1
- package/dist/context-engine/compaction/templates/summary-9-section.d.ts.map +1 -1
- package/dist/context-engine/compaction/templates/summary-9-section.js +4 -3
- package/dist/context-engine/compaction/templates/summary-9-section.js.map +1 -1
- package/dist/context-engine/engine.d.ts +7 -176
- package/dist/context-engine/engine.d.ts.map +1 -1
- package/dist/context-engine/engine.js +0 -2
- package/dist/context-engine/engine.js.map +1 -1
- package/dist/context-engine/index.d.ts +8 -49
- package/dist/context-engine/io-types.d.ts +144 -0
- package/dist/context-engine/io-types.d.ts.map +1 -0
- package/dist/context-engine/locale-packs/types.d.ts +1 -1
- package/dist/context-engine/locale-packs/types.js.map +1 -1
- package/dist/context-engine/privacy-filter.d.ts +1 -2
- package/dist/context-engine/privacy-filter.d.ts.map +1 -1
- package/dist/context-engine/privacy-filter.js +1 -2
- package/dist/context-engine/privacy-filter.js.map +1 -1
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +2 -2
- package/dist/errors/index.js.map +1 -1
- package/dist/facade.d.ts +43 -52
- package/dist/facade.d.ts.map +1 -1
- package/dist/facade.js +5 -3
- package/dist/facade.js.map +1 -1
- package/dist/graph/entity-resolver.js +1 -1
- package/dist/graph/entity-resolver.js.map +1 -1
- package/dist/index.d.ts +17 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/internal/envelope.js +57 -0
- package/dist/internal/envelope.js.map +1 -0
- package/dist/internal/injection-heuristics.js +0 -0
- package/dist/internal/injection-heuristics.js.map +1 -1
- package/dist/internal/llm-json.js +40 -0
- package/dist/internal/llm-json.js.map +1 -0
- package/dist/internal/storage-adapter.d.ts +23 -10
- package/dist/internal/storage-adapter.d.ts.map +1 -1
- package/dist/memory-interface.d.ts +131 -0
- package/dist/memory-interface.d.ts.map +1 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/search/iterative.d.ts.map +1 -1
- package/dist/search/iterative.js +2 -3
- package/dist/search/iterative.js.map +1 -1
- package/dist/search/query-transform.d.ts.map +1 -1
- package/dist/search/query-transform.js +2 -3
- package/dist/search/query-transform.js.map +1 -1
- package/dist/tiers/episodic-memory.js +3 -3
- package/dist/tiers/episodic-memory.js.map +1 -1
- package/dist/tiers/index.d.ts +2 -2
- package/dist/tiers/insight-memory.js +1 -1
- package/dist/tiers/insight-memory.js.map +1 -1
- package/dist/tiers/procedural-memory.d.ts +1 -1
- package/dist/tiers/procedural-memory.js +2 -2
- package/dist/tiers/procedural-memory.js.map +1 -1
- package/dist/tiers/semantic-memory.d.ts +58 -4
- package/dist/tiers/semantic-memory.d.ts.map +1 -1
- package/dist/tiers/semantic-memory.js +103 -20
- package/dist/tiers/semantic-memory.js.map +1 -1
- package/dist/tools/block-tools.d.ts +19 -57
- package/dist/tools/block-tools.d.ts.map +1 -1
- package/dist/tools/block-tools.js.map +1 -1
- package/dist/tools/fact-tools.d.ts +53 -214
- package/dist/tools/fact-tools.d.ts.map +1 -1
- package/dist/tools/fact-tools.js +3 -2
- package/dist/tools/fact-tools.js.map +1 -1
- package/dist/tools/recall-tools.d.ts +34 -175
- package/dist/tools/recall-tools.d.ts.map +1 -1
- package/dist/tools/recall-tools.js +5 -4
- package/dist/tools/recall-tools.js.map +1 -1
- package/dist/tools/runbook-tools.d.ts +15 -58
- package/dist/tools/runbook-tools.d.ts.map +1 -1
- package/dist/tools/runbook-tools.js.map +1 -1
- package/dist/tools/types.d.ts +1 -1
- package/package.json +18 -17
- package/src/conflict/index.ts +29 -0
- package/src/conflict/locale-packs/en.ts +142 -0
- package/src/conflict/locale-packs/index.ts +17 -0
- package/src/conflict/locale-packs/types.ts +138 -0
- package/src/conflict/pipeline.ts +371 -0
- package/src/conflict/stages/helpers.ts +65 -0
- package/src/conflict/stages/stage1-exact-dedup.ts +40 -0
- package/src/conflict/stages/stage2-embedding-three-zone.ts +54 -0
- package/src/conflict/stages/stage3-heuristic-regex.ts +51 -0
- package/src/conflict/stages/stage4-subject-predicate.ts +46 -0
- package/src/conflict/stages/stage5-defer-to-deep.ts +34 -0
- package/src/conflict/types.ts +263 -0
- package/src/consolidator/budget.ts +312 -0
- package/src/consolidator/decay.ts +246 -0
- package/src/consolidator/dlq.ts +61 -0
- package/src/consolidator/errors.ts +87 -0
- package/src/consolidator/idempotency.ts +27 -0
- package/src/consolidator/index.ts +269 -0
- package/src/consolidator/lock.ts +141 -0
- package/src/consolidator/noise-filter.ts +235 -0
- package/src/consolidator/phases/deep.ts +308 -0
- package/src/consolidator/phases/induce.ts +423 -0
- package/src/consolidator/phases/learned-context.ts +233 -0
- package/src/consolidator/phases/light.ts +166 -0
- package/src/consolidator/phases/reflect.ts +504 -0
- package/src/consolidator/phases/standard.ts +1002 -0
- package/src/consolidator/reconcile.ts +273 -0
- package/src/consolidator/runtime.ts +1049 -0
- package/src/consolidator/scheduler.ts +182 -0
- package/src/consolidator/triggers.ts +134 -0
- package/src/consolidator/types.ts +622 -0
- package/src/context-engine/annotations.ts +161 -0
- package/src/context-engine/auto-recall.ts +92 -0
- package/src/context-engine/compaction/clear-tool-results.ts +232 -0
- package/src/context-engine/compaction/compactor.ts +403 -0
- package/src/context-engine/compaction/hooks/reanchor-persona-block.ts +55 -0
- package/src/context-engine/compaction/hooks/reanchor-pinned-facts.ts +66 -0
- package/src/context-engine/compaction/hooks/reanchor-project-rules.ts +57 -0
- package/src/context-engine/compaction/hooks/reanchor-recent-results.ts +116 -0
- package/src/context-engine/compaction/hooks/types.ts +68 -0
- package/src/context-engine/compaction/index.ts +60 -0
- package/src/context-engine/compaction/templates/marker.ts +33 -0
- package/src/context-engine/compaction/templates/summary-9-section.ts +223 -0
- package/src/context-engine/compaction/thresholds.ts +107 -0
- package/src/context-engine/compaction/types.ts +255 -0
- package/src/context-engine/engine.ts +970 -0
- package/src/context-engine/index.ts +118 -0
- package/src/context-engine/io-types.ts +162 -0
- package/src/context-engine/locale-packs/en.ts +107 -0
- package/src/context-engine/locale-packs/index.ts +19 -0
- package/src/context-engine/locale-packs/resolver.ts +197 -0
- package/src/context-engine/locale-packs/types.ts +177 -0
- package/src/context-engine/metadata.ts +114 -0
- package/src/context-engine/preambles/inbound-en.ts +19 -0
- package/src/context-engine/privacy-filter.ts +190 -0
- package/src/context-engine/templates/base-en.ts +19 -0
- package/src/context-engine/templates/composer.ts +91 -0
- package/src/context-engine/token-budget.ts +319 -0
- package/src/context-engine/token-counter.ts +157 -0
- package/src/errors/index.ts +273 -0
- package/src/facade.ts +750 -0
- package/src/graph/entity-resolver.ts +364 -0
- package/src/graph/index.ts +24 -0
- package/src/index.ts +259 -0
- package/src/internal/contextualize.ts +173 -0
- package/src/internal/embedder-binding.ts +53 -0
- package/src/internal/envelope.ts +70 -0
- package/src/internal/id.ts +23 -0
- package/src/internal/injection-heuristics.ts +0 -0
- package/src/internal/llm-json.ts +38 -0
- package/src/internal/spans.ts +35 -0
- package/src/internal/storage-adapter.ts +963 -0
- package/src/memory-interface.ts +158 -0
- package/src/migration/embedder-migration.ts +237 -0
- package/src/migration/index.ts +13 -0
- package/src/search/explain.ts +123 -0
- package/src/search/fit-weights.ts +109 -0
- package/src/search/graph-ppr.ts +38 -0
- package/src/search/index.ts +55 -0
- package/src/search/iterative.ts +658 -0
- package/src/search/query-transform.ts +285 -0
- package/src/search/rrf.ts +225 -0
- package/src/search/trust.ts +55 -0
- package/src/search/types.ts +50 -0
- package/src/tiers/episodic-memory.ts +463 -0
- package/src/tiers/index.ts +50 -0
- package/src/tiers/insight-memory.ts +208 -0
- package/src/tiers/procedural-memory.ts +482 -0
- package/src/tiers/semantic-memory.ts +1729 -0
- package/src/tiers/session-memory.ts +271 -0
- package/src/tiers/shared-memory.ts +62 -0
- package/src/tiers/working-memory.ts +368 -0
- package/src/tools/block-tools.ts +172 -0
- package/src/tools/fact-tools.ts +473 -0
- package/src/tools/index.ts +109 -0
- package/src/tools/recall-tools.ts +303 -0
- package/src/tools/runbook-tools.ts +107 -0
- package/src/tools/taint.ts +39 -0
- package/src/tools/types.ts +37 -0
- package/dist/conflict/locale-packs/index.js +0 -4
- package/dist/context-engine/compaction/index.js +0 -10
- package/dist/context-engine/index.d.ts.map +0 -1
- package/dist/context-engine/index.js +0 -25
- package/dist/context-engine/locale-packs/index.js +0 -4
|
@@ -1,247 +1,86 @@
|
|
|
1
1
|
import { MemoryToolDeps } from "./types.js";
|
|
2
2
|
import { Tool } from "@graphorin/core";
|
|
3
|
-
import { z } from "zod";
|
|
4
3
|
|
|
5
4
|
//#region src/tools/fact-tools.d.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
tags?: string[] | undefined;
|
|
16
|
-
confidence?: number | undefined;
|
|
17
|
-
sensitivity?: "public" | "internal" | "secret" | undefined;
|
|
18
|
-
validFrom?: string | undefined;
|
|
19
|
-
validTo?: string | undefined;
|
|
20
|
-
}, {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* W-013: explicit interfaces instead of `z.infer<typeof schema>` - the
|
|
8
|
+
* inferred aliases baked concrete v3 zod object generics into
|
|
9
|
+
* the published d.ts, which do not typecheck under a zod@4 consumer.
|
|
10
|
+
* Interface<->schema equality is pinned by type tests. Optionals carry
|
|
11
|
+
* `| undefined` to match zod's `.optional()` inference exactly.
|
|
12
|
+
*/
|
|
13
|
+
interface FactRememberInput {
|
|
21
14
|
text: string;
|
|
22
15
|
tags?: string[] | undefined;
|
|
23
16
|
confidence?: number | undefined;
|
|
24
|
-
sensitivity?:
|
|
17
|
+
sensitivity?: 'public' | 'internal' | 'secret' | undefined;
|
|
25
18
|
validFrom?: string | undefined;
|
|
26
19
|
validTo?: string | undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
factId: z.ZodString;
|
|
30
|
-
/**
|
|
31
|
-
* MRET-3: `true` when the write landed in quarantine (hidden from
|
|
32
|
-
* default recall until validated). A synthesized consolidator write or
|
|
33
|
-
* a candidate that tripped the injection heuristics quarantines.
|
|
34
|
-
*/
|
|
35
|
-
quarantined: z.ZodBoolean;
|
|
36
|
-
/** Why it was quarantined, when it was. */
|
|
37
|
-
quarantineReason: z.ZodOptional<z.ZodEnum<["injection", "synthesized"]>>;
|
|
38
|
-
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
}
|
|
21
|
+
interface FactRememberOutput {
|
|
39
22
|
factId: string;
|
|
40
23
|
quarantined: boolean;
|
|
41
|
-
quarantineReason?:
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
quarantined: boolean;
|
|
45
|
-
quarantineReason?: "injection" | "synthesized" | undefined;
|
|
46
|
-
}>;
|
|
47
|
-
type FactRememberInput = z.infer<typeof factRememberInputSchema>;
|
|
48
|
-
type FactRememberOutput = z.infer<typeof factRememberOutputSchema>;
|
|
49
|
-
declare const factSearchInputSchema: z.ZodObject<{
|
|
50
|
-
query: z.ZodString;
|
|
51
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
52
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
53
|
-
asOf: z.ZodOptional<z.ZodString>;
|
|
54
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
quarantineReason?: 'injection' | 'synthesized' | undefined;
|
|
25
|
+
}
|
|
26
|
+
interface FactSearchInput {
|
|
55
27
|
query: string;
|
|
56
|
-
tags?: string[] | undefined;
|
|
57
28
|
topK?: number | undefined;
|
|
58
|
-
asOf?: string | undefined;
|
|
59
|
-
}, {
|
|
60
|
-
query: string;
|
|
61
29
|
tags?: string[] | undefined;
|
|
62
|
-
topK?: number | undefined;
|
|
63
30
|
asOf?: string | undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/** Id of the fact that superseded this one, when any. */
|
|
79
|
-
supersededBy: z.ZodOptional<z.ZodString>;
|
|
80
|
-
}, "strip", z.ZodTypeAny, {
|
|
81
|
-
text: string;
|
|
82
|
-
sensitivity: "public" | "internal" | "secret";
|
|
83
|
-
factId: string;
|
|
84
|
-
score: number;
|
|
85
|
-
validTo?: string | undefined;
|
|
86
|
-
provenance?: "user" | "tool" | "extraction" | "reflection" | "induction" | "imported" | undefined;
|
|
87
|
-
supersededBy?: string | undefined;
|
|
88
|
-
}, {
|
|
89
|
-
text: string;
|
|
90
|
-
sensitivity: "public" | "internal" | "secret";
|
|
91
|
-
factId: string;
|
|
92
|
-
score: number;
|
|
93
|
-
validTo?: string | undefined;
|
|
94
|
-
provenance?: "user" | "tool" | "extraction" | "reflection" | "induction" | "imported" | undefined;
|
|
95
|
-
supersededBy?: string | undefined;
|
|
96
|
-
}>, "many">;
|
|
97
|
-
}, "strip", z.ZodTypeAny, {
|
|
98
|
-
hits: {
|
|
99
|
-
text: string;
|
|
100
|
-
sensitivity: "public" | "internal" | "secret";
|
|
101
|
-
factId: string;
|
|
102
|
-
score: number;
|
|
103
|
-
validTo?: string | undefined;
|
|
104
|
-
provenance?: "user" | "tool" | "extraction" | "reflection" | "induction" | "imported" | undefined;
|
|
105
|
-
supersededBy?: string | undefined;
|
|
106
|
-
}[];
|
|
107
|
-
}, {
|
|
108
|
-
hits: {
|
|
109
|
-
text: string;
|
|
110
|
-
sensitivity: "public" | "internal" | "secret";
|
|
111
|
-
factId: string;
|
|
112
|
-
score: number;
|
|
113
|
-
validTo?: string | undefined;
|
|
114
|
-
provenance?: "user" | "tool" | "extraction" | "reflection" | "induction" | "imported" | undefined;
|
|
115
|
-
supersededBy?: string | undefined;
|
|
116
|
-
}[];
|
|
117
|
-
}>;
|
|
118
|
-
type FactSearchInput = z.infer<typeof factSearchInputSchema>;
|
|
119
|
-
type FactSearchOutput = z.infer<typeof factSearchOutputSchema>;
|
|
120
|
-
declare const factSupersedeInputSchema: z.ZodObject<{
|
|
121
|
-
oldId: z.ZodString;
|
|
122
|
-
newText: z.ZodString;
|
|
123
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
124
|
-
}, "strip", z.ZodTypeAny, {
|
|
125
|
-
newText: string;
|
|
31
|
+
}
|
|
32
|
+
interface FactSearchHit {
|
|
33
|
+
factId: string;
|
|
34
|
+
text: string;
|
|
35
|
+
score: number;
|
|
36
|
+
sensitivity: 'public' | 'internal' | 'secret';
|
|
37
|
+
provenance?: 'user' | 'tool' | 'extraction' | 'reflection' | 'induction' | 'imported' | undefined;
|
|
38
|
+
validTo?: string | undefined;
|
|
39
|
+
supersededBy?: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
interface FactSearchOutput {
|
|
42
|
+
hits: FactSearchHit[];
|
|
43
|
+
}
|
|
44
|
+
interface FactSupersedeInput {
|
|
126
45
|
oldId: string;
|
|
127
|
-
reason?: string | undefined;
|
|
128
|
-
}, {
|
|
129
46
|
newText: string;
|
|
130
|
-
oldId: string;
|
|
131
47
|
reason?: string | undefined;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
oldId: z.ZodString;
|
|
135
|
-
newId: z.ZodString;
|
|
136
|
-
}, "strip", z.ZodTypeAny, {
|
|
137
|
-
oldId: string;
|
|
138
|
-
newId: string;
|
|
139
|
-
}, {
|
|
48
|
+
}
|
|
49
|
+
interface FactSupersedeOutput {
|
|
140
50
|
oldId: string;
|
|
141
51
|
newId: string;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
type FactSupersedeOutput = z.infer<typeof factSupersedeOutputSchema>;
|
|
145
|
-
declare const factForgetInputSchema: z.ZodObject<{
|
|
146
|
-
factId: z.ZodString;
|
|
147
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
148
|
-
}, "strip", z.ZodTypeAny, {
|
|
149
|
-
factId: string;
|
|
150
|
-
reason?: string | undefined;
|
|
151
|
-
}, {
|
|
52
|
+
}
|
|
53
|
+
interface FactForgetInput {
|
|
152
54
|
factId: string;
|
|
153
55
|
reason?: string | undefined;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
factId: z.ZodString;
|
|
157
|
-
forgotten: z.ZodBoolean;
|
|
158
|
-
}, "strip", z.ZodTypeAny, {
|
|
159
|
-
factId: string;
|
|
160
|
-
forgotten: boolean;
|
|
161
|
-
}, {
|
|
56
|
+
}
|
|
57
|
+
interface FactForgetOutput {
|
|
162
58
|
factId: string;
|
|
163
59
|
forgotten: boolean;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
type FactForgetOutput = z.infer<typeof factForgetOutputSchema>;
|
|
167
|
-
declare const factHistoryInputSchema: z.ZodObject<{
|
|
168
|
-
factId: z.ZodString;
|
|
169
|
-
}, "strip", z.ZodTypeAny, {
|
|
170
|
-
factId: string;
|
|
171
|
-
}, {
|
|
60
|
+
}
|
|
61
|
+
interface FactHistoryInput {
|
|
172
62
|
factId: string;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
chain: z.ZodArray<z.ZodObject<{
|
|
176
|
-
factId: z.ZodString;
|
|
177
|
-
text: z.ZodString;
|
|
178
|
-
validFrom: z.ZodOptional<z.ZodString>;
|
|
179
|
-
validTo: z.ZodOptional<z.ZodString>;
|
|
180
|
-
supersedes: z.ZodOptional<z.ZodString>;
|
|
181
|
-
supersededBy: z.ZodOptional<z.ZodString>;
|
|
182
|
-
sensitivity: z.ZodEnum<["public", "internal", "secret"]>;
|
|
183
|
-
}, "strip", z.ZodTypeAny, {
|
|
184
|
-
text: string;
|
|
185
|
-
sensitivity: "public" | "internal" | "secret";
|
|
186
|
-
factId: string;
|
|
187
|
-
validFrom?: string | undefined;
|
|
188
|
-
validTo?: string | undefined;
|
|
189
|
-
supersededBy?: string | undefined;
|
|
190
|
-
supersedes?: string | undefined;
|
|
191
|
-
}, {
|
|
192
|
-
text: string;
|
|
193
|
-
sensitivity: "public" | "internal" | "secret";
|
|
194
|
-
factId: string;
|
|
195
|
-
validFrom?: string | undefined;
|
|
196
|
-
validTo?: string | undefined;
|
|
197
|
-
supersededBy?: string | undefined;
|
|
198
|
-
supersedes?: string | undefined;
|
|
199
|
-
}>, "many">;
|
|
200
|
-
}, "strip", z.ZodTypeAny, {
|
|
201
|
-
chain: {
|
|
202
|
-
text: string;
|
|
203
|
-
sensitivity: "public" | "internal" | "secret";
|
|
204
|
-
factId: string;
|
|
205
|
-
validFrom?: string | undefined;
|
|
206
|
-
validTo?: string | undefined;
|
|
207
|
-
supersededBy?: string | undefined;
|
|
208
|
-
supersedes?: string | undefined;
|
|
209
|
-
}[];
|
|
210
|
-
}, {
|
|
211
|
-
chain: {
|
|
212
|
-
text: string;
|
|
213
|
-
sensitivity: "public" | "internal" | "secret";
|
|
214
|
-
factId: string;
|
|
215
|
-
validFrom?: string | undefined;
|
|
216
|
-
validTo?: string | undefined;
|
|
217
|
-
supersededBy?: string | undefined;
|
|
218
|
-
supersedes?: string | undefined;
|
|
219
|
-
}[];
|
|
220
|
-
}>;
|
|
221
|
-
type FactHistoryInput = z.infer<typeof factHistoryInputSchema>;
|
|
222
|
-
type FactHistoryOutput = z.infer<typeof factHistoryOutputSchema>;
|
|
223
|
-
declare const factValidateInputSchema: z.ZodObject<{
|
|
224
|
-
factId: z.ZodString;
|
|
225
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
226
|
-
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
}
|
|
64
|
+
interface FactHistoryEntry {
|
|
227
65
|
factId: string;
|
|
228
|
-
|
|
229
|
-
|
|
66
|
+
text: string;
|
|
67
|
+
validFrom?: string | undefined;
|
|
68
|
+
validTo?: string | undefined;
|
|
69
|
+
supersedes?: string | undefined;
|
|
70
|
+
supersededBy?: string | undefined;
|
|
71
|
+
sensitivity: 'public' | 'internal' | 'secret';
|
|
72
|
+
}
|
|
73
|
+
interface FactHistoryOutput {
|
|
74
|
+
chain: FactHistoryEntry[];
|
|
75
|
+
}
|
|
76
|
+
interface FactValidateInput {
|
|
230
77
|
factId: string;
|
|
231
78
|
reason?: string | undefined;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
factId: z.ZodString;
|
|
235
|
-
validated: z.ZodBoolean;
|
|
236
|
-
}, "strip", z.ZodTypeAny, {
|
|
237
|
-
factId: string;
|
|
238
|
-
validated: boolean;
|
|
239
|
-
}, {
|
|
79
|
+
}
|
|
80
|
+
interface FactValidateOutput {
|
|
240
81
|
factId: string;
|
|
241
82
|
validated: boolean;
|
|
242
|
-
}
|
|
243
|
-
type FactValidateInput = z.infer<typeof factValidateInputSchema>;
|
|
244
|
-
type FactValidateOutput = z.infer<typeof factValidateOutputSchema>;
|
|
83
|
+
}
|
|
245
84
|
/**
|
|
246
85
|
* `fact_remember` - persist a single semantic fact. The minimum-viable
|
|
247
86
|
* pipeline writes the fact straight through with MD5 deduplication;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fact-tools.d.ts","names":[],"sources":["../../src/tools/fact-tools.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fact-tools.d.ts","names":[],"sources":["../../src/tools/fact-tools.ts"],"sourcesContent":[],"mappings":";;;;;;;AA4CA;AAQA;AAgCA;AAMA;AASA;AAciB,UArEA,iBAAA,CAqEkB;EAKlB,IAAA,EAAA,MAAA;EAcA,IAAA,CAAA,EAAA,MAAA,EAAA,GAAe,SAAA;EAIf,UAAA,CAAA,EAAA,MAAgB,GAAA,SAAA;EAsBh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A,gBAAA;;;;;;;;;UASA,iBAAA;SACR;;UAYQ,iBAAA;;;;UAIA,kBAAA;;;;;;;;;;;iBA4CD,sBAAA,OACR,iBACL,KAAK,mBAAmB;;;;;;;iBAyCX,oBAAA,OACR,iBACL,KAAK,iBAAiB;;;;;;;;;iBAqDT,uBAAA,OACR,iBACL,KAAK,oBAAoB;;;;;;;iBA+BZ,oBAAA,OACR,iBACL,KAAK,iBAAiB;;;;;;;;;iBA4BT,qBAAA,OACR,iBACL,KAAK,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;iBAqDV,sBAAA,OACR,iBACL,KAAK,mBAAmB"}
|
package/dist/tools/fact-tools.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { recallTaint } from "./taint.js";
|
|
2
|
+
import { toolReturn } from "@graphorin/core";
|
|
2
3
|
import { tool } from "@graphorin/tools";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
|
|
@@ -150,10 +151,10 @@ function createFactSearchTool(deps) {
|
|
|
150
151
|
...hit.record.supersededBy !== void 0 ? { supersededBy: hit.record.supersededBy } : {}
|
|
151
152
|
})) };
|
|
152
153
|
const taint = recallTaint(hits.map((h) => h.record));
|
|
153
|
-
return taint === void 0 ? output : {
|
|
154
|
+
return taint === void 0 ? output : toolReturn({
|
|
154
155
|
output,
|
|
155
156
|
taint
|
|
156
|
-
};
|
|
157
|
+
});
|
|
157
158
|
}
|
|
158
159
|
});
|
|
159
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fact-tools.js","names":[],"sources":["../../src/tools/fact-tools.ts"],"sourcesContent":["import type { Tool } from '@graphorin/core';\nimport { tool } from '@graphorin/tools';\nimport { z } from 'zod';\nimport { recallTaint } from './taint.js';\nimport type { MemoryToolDeps } from './types.js';\n\nconst sensitivityEnum = z.enum(['public', 'internal', 'secret']);\nconst provenanceEnum = z.enum([\n 'user',\n 'tool',\n 'extraction',\n 'reflection',\n 'induction',\n 'imported',\n]);\n\nconst factRememberInputSchema = z.object({\n text: z.string().min(1).max(8192),\n tags: z.array(z.string().min(1).max(64)).max(32).optional(),\n confidence: z.number().min(0).max(1).optional(),\n sensitivity: sensitivityEnum.optional(),\n validFrom: z.string().datetime().optional(),\n validTo: z.string().datetime().optional(),\n});\nconst factRememberOutputSchema = z.object({\n factId: z.string(),\n /**\n * MRET-3: `true` when the write landed in quarantine (hidden from\n * default recall until validated). A synthesized consolidator write or\n * a candidate that tripped the injection heuristics quarantines.\n */\n quarantined: z.boolean(),\n /** Why it was quarantined, when it was. */\n quarantineReason: z.enum(['injection', 'synthesized']).optional(),\n});\n\ntype FactRememberInput = z.infer<typeof factRememberInputSchema>;\ntype FactRememberOutput = z.infer<typeof factRememberOutputSchema>;\n\nconst factSearchInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(50).optional(),\n tags: z.array(z.string().min(1)).max(16).optional(),\n asOf: z.string().datetime().optional(),\n});\nconst factSearchOutputSchema = z.object({\n hits: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n score: z.number(),\n sensitivity: sensitivityEnum,\n provenance: provenanceEnum.optional(),\n /**\n * Set when the fact's validity interval was closed (superseded /\n * expired). Only present on `asOf` reads - default reads exclude\n * such facts entirely (memory-retrieval-01).\n */\n validTo: z.string().optional(),\n /** Id of the fact that superseded this one, when any. */\n supersededBy: z.string().optional(),\n }),\n ),\n});\n\ntype FactSearchInput = z.infer<typeof factSearchInputSchema>;\ntype FactSearchOutput = z.infer<typeof factSearchOutputSchema>;\n\nconst factSupersedeInputSchema = z.object({\n oldId: z.string().min(1),\n newText: z.string().min(1).max(8192),\n reason: z.string().max(512).optional(),\n});\nconst factSupersedeOutputSchema = z.object({\n oldId: z.string(),\n newId: z.string(),\n});\n\ntype FactSupersedeInput = z.infer<typeof factSupersedeInputSchema>;\ntype FactSupersedeOutput = z.infer<typeof factSupersedeOutputSchema>;\n\nconst factForgetInputSchema = z.object({\n factId: z.string().min(1),\n reason: z.string().max(512).optional(),\n});\nconst factForgetOutputSchema = z.object({\n factId: z.string(),\n forgotten: z.boolean(),\n});\n\ntype FactForgetInput = z.infer<typeof factForgetInputSchema>;\ntype FactForgetOutput = z.infer<typeof factForgetOutputSchema>;\n\nconst factHistoryInputSchema = z.object({\n factId: z.string().min(1),\n});\nconst factHistoryOutputSchema = z.object({\n chain: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n validFrom: z.string().optional(),\n validTo: z.string().optional(),\n supersedes: z.string().optional(),\n supersededBy: z.string().optional(),\n sensitivity: sensitivityEnum,\n }),\n ),\n});\n\ntype FactHistoryInput = z.infer<typeof factHistoryInputSchema>;\ntype FactHistoryOutput = z.infer<typeof factHistoryOutputSchema>;\n\nconst factValidateInputSchema = z.object({\n factId: z.string().min(1),\n reason: z.string().max(512).optional(),\n});\nconst factValidateOutputSchema = z.object({\n factId: z.string(),\n validated: z.boolean(),\n});\n\ntype FactValidateInput = z.infer<typeof factValidateInputSchema>;\ntype FactValidateOutput = z.infer<typeof factValidateOutputSchema>;\n\n/**\n * `fact_remember` - persist a single semantic fact. The minimum-viable\n * pipeline writes the fact straight through with MD5 deduplication;\n * Phase 10b extends the body with the multi-stage conflict resolution.\n *\n * @stable\n */\nexport function createFactRememberTool(\n deps: MemoryToolDeps,\n): Tool<FactRememberInput, FactRememberOutput> {\n return tool<FactRememberInput, FactRememberOutput>({\n name: 'fact_remember',\n description:\n 'Persist an atomic factual statement about the user, the world, or the current session. Prefer one fact per call; the system applies dedup + conflict resolution downstream. Pass `validFrom` / `validTo` for bi-temporal facts and `sensitivity` to control redaction.',\n inputSchema: factRememberInputSchema,\n outputSchema: factRememberOutputSchema,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const outcome = await deps.semantic.rememberWithDecision(scope, {\n text: input.text,\n ...(input.tags !== undefined ? { tags: input.tags } : {}),\n ...(input.confidence !== undefined ? { confidence: input.confidence } : {}),\n ...(input.sensitivity !== undefined ? { sensitivity: input.sensitivity } : {}),\n ...(input.validFrom !== undefined ? { validFrom: input.validFrom } : {}),\n ...(input.validTo !== undefined ? { validTo: input.validTo } : {}),\n });\n // MRET-3: tell the caller when the write was quarantined so a\n // poisoned fact cannot masquerade as a normally-stored one.\n return {\n factId: outcome.fact.id,\n quarantined: outcome.fact.status === 'quarantined',\n ...(outcome.quarantineReason !== undefined\n ? { quarantineReason: outcome.quarantineReason }\n : {}),\n };\n },\n });\n}\n\n/**\n * `fact_search` - hybrid (vector + FTS5) search over the user's\n * semantic memory. Results merged through the configured reranker.\n *\n * @stable\n */\nexport function createFactSearchTool(\n deps: MemoryToolDeps,\n): Tool<FactSearchInput, FactSearchOutput> {\n return tool<FactSearchInput, FactSearchOutput>({\n name: 'fact_search',\n description:\n \"Search the user's long-term factual memory by natural-language query. Returns up to `topK` matched facts with their score and sensitivity. Use this BEFORE asking the user a question they may have answered earlier. Pass `asOf` (ISO-8601) to read memory as it was at a past instant - point-in-time / 'what was true on date X' - instead of the current state.\",\n inputSchema: factSearchInputSchema,\n outputSchema: factSearchOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const hits = await deps.semantic.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n // MRET-4: forward the tags filter - it was accepted by the\n // schema and silently dropped here.\n ...(input.tags !== undefined && input.tags.length > 0 ? { tags: input.tags } : {}),\n ...(input.asOf !== undefined ? { asOf: input.asOf } : {}),\n signal: ctx.signal,\n });\n const output = {\n hits: hits.map((hit) => ({\n factId: hit.record.id,\n text: hit.record.text,\n score: hit.score,\n sensitivity: hit.record.sensitivity,\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n // memory-retrieval-01: surface validity metadata so the model\n // can tell a historical (asOf) hit from a current one.\n ...(hit.record.validTo !== undefined ? { validTo: hit.record.validTo } : {}),\n ...(hit.record.supersededBy !== undefined\n ? { supersededBy: hit.record.supersededBy }\n : {}),\n })),\n };\n // C6: recalled quarantined / foreign-provenance content re-arms the\n // taint ledger - the cross-session poisoning leg.\n const taint = recallTaint(hits.map((h) => h.record));\n return taint === undefined ? output : { output, taint };\n },\n });\n}\n\n/**\n * `fact_supersede` - soft-supersede an old fact by storing a new one\n * that replaces it. The old fact is kept for replay but no longer\n * surfaced by default reads (they evaluate validity at NOW); it stays\n * reachable via `asOf` / inspector paths.\n *\n * @stable\n */\nexport function createFactSupersedeTool(\n deps: MemoryToolDeps,\n): Tool<FactSupersedeInput, FactSupersedeOutput> {\n return tool<FactSupersedeInput, FactSupersedeOutput>({\n name: 'fact_supersede',\n description:\n \"Mark an old fact superseded by a new one. Use this when the user's situation changed (moved cities, updated a goal, switched a preference) - the old fact is preserved for replay but no longer surfaced as current.\",\n inputSchema: factSupersedeInputSchema,\n outputSchema: factSupersedeOutputSchema,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const result = await deps.semantic.supersede(\n scope,\n input.oldId,\n { text: input.newText },\n input.reason,\n );\n return { oldId: result.old, newId: result.new.id };\n },\n });\n}\n\n/**\n * `fact_forget` - soft-delete a fact (kept for replay; never hard-\n * deleted at this layer).\n *\n * @stable\n */\nexport function createFactForgetTool(\n deps: MemoryToolDeps,\n): Tool<FactForgetInput, FactForgetOutput> {\n return tool<FactForgetInput, FactForgetOutput>({\n name: 'fact_forget',\n description:\n 'Soft-delete a fact. The record is preserved for replay but no longer surfaced by fact_search. Use only for explicit user-driven removal (privacy / user request).',\n inputSchema: factForgetInputSchema,\n outputSchema: factForgetOutputSchema,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n await deps.semantic.forget(scope, input.factId, input.reason);\n return { factId: input.factId, forgotten: true };\n },\n });\n}\n\n/**\n * `fact_history` - trace how a fact changed over time. Returns the\n * full bi-temporal supersede chain the given fact belongs to, oldest →\n * newest, including superseded entries, so the agent can answer \"what\n * did the user say before\" / \"how did this change\". Read-only. P0-2.\n *\n * @stable\n */\nexport function createFactHistoryTool(\n deps: MemoryToolDeps,\n): Tool<FactHistoryInput, FactHistoryOutput> {\n return tool<FactHistoryInput, FactHistoryOutput>({\n name: 'fact_history',\n description:\n \"Trace how a fact changed over time. Given a factId, returns its full bi-temporal supersede chain (oldest → newest), including superseded entries, with each entry's validFrom/validTo. Use this to answer 'how did this change' or 'what was the previous value'.\",\n inputSchema: factHistoryInputSchema,\n outputSchema: factHistoryOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'semantic', 'temporal'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const chain = await deps.semantic.history(scope, input.factId);\n return {\n chain: chain.map((f) => ({\n factId: f.id,\n text: f.text,\n ...(f.validFrom !== undefined ? { validFrom: f.validFrom } : {}),\n ...(f.validTo !== undefined ? { validTo: f.validTo } : {}),\n ...(f.supersedes !== undefined ? { supersedes: f.supersedes } : {}),\n ...(f.supersededBy !== undefined ? { supersededBy: f.supersededBy } : {}),\n sensitivity: f.sensitivity,\n })),\n };\n },\n });\n}\n\n/**\n * `fact_validate` - promote a quarantined fact to active (P1-4). The\n * validation path that admits a synthesized (consolidator / reflection)\n * memory into action-driving recall once it has been reviewed; the\n * promotion is audited in `memory_history`.\n *\n * MRET-3 / MST-1 - two gates close the one-turn memory-poisoning chain\n * (`fact_remember(poison)` → `fact_validate(id)` → active recall):\n *\n * 1. `needsApproval: true` - the run suspends for a human decision\n * before this tool ever executes, so the agent cannot silently\n * promote any quarantined fact.\n * 2. The underlying `SemanticMemory.validate(...)` re-checks the fact's\n * text against the injection heuristics and **refuses** (no `force`\n * is passed here) - an injection-flagged memory cannot be promoted by\n * the agent at all. Only an operator, via the programmatic API with\n * `{ force: true }`, can override after review.\n *\n * Synthesized-but-clean consolidator writes promote normally once\n * approved.\n *\n * @stable\n */\nexport function createFactValidateTool(\n deps: MemoryToolDeps,\n): Tool<FactValidateInput, FactValidateOutput> {\n return tool<FactValidateInput, FactValidateOutput>({\n name: 'fact_validate',\n description:\n 'Promote a quarantined fact to active so it becomes eligible for normal recall. Quarantined facts are memories the system synthesized or flagged as risky; validating one is a deliberate, human-approved admission and never a routine step. This action requires approval, and facts flagged as prompt-injection cannot be promoted here - they are an operator-only decision.',\n inputSchema: factValidateInputSchema,\n outputSchema: factValidateOutputSchema,\n // MRET-3: the only real gate on a model-callable tool - suspend the\n // run for a human decision before promoting anything out of quarantine.\n needsApproval: true,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic', 'safety'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n // No `force`: the agent path can never promote an injection-flagged\n // fact (validate throws QuarantinePromotionRefusedError for those).\n await deps.semantic.validate(scope, input.factId, input.reason);\n return { factId: input.factId, validated: true };\n },\n });\n}\n"],"mappings":";;;;;AAMA,MAAM,kBAAkB,EAAE,KAAK;CAAC;CAAU;CAAY;CAAS,CAAC;AAChE,MAAM,iBAAiB,EAAE,KAAK;CAC5B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,0BAA0B,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CACjC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI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,CAAC;;;;;;;;;;AAWJ,SAAgB,sBACd,MAC2C;AAC3C,QAAO,KAA0C;EAC/C,MAAM;EACN,aACE;EACF,aAAa;EACb,cAAc;EACd,iBAAiB;EACjB,eAAe;EACf,aAAa;EACb,iBAAiB;EACjB,MAAM;GAAC;GAAU;GAAY;GAAW;EACxC,MAAM,QAAQ,OAAO,KAAK;GACxB,MAAM,QAAQ,MAAM,KAAK,aAAa,IAAI;AAE1C,UAAO,EACL,QAFY,MAAM,KAAK,SAAS,QAAQ,OAAO,MAAM,OAAO,EAE/C,KAAK,OAAO;IACvB,QAAQ,EAAE;IACV,MAAM,EAAE;IACR,GAAI,EAAE,cAAc,SAAY,EAAE,WAAW,EAAE,WAAW,GAAG,EAAE;IAC/D,GAAI,EAAE,YAAY,SAAY,EAAE,SAAS,EAAE,SAAS,GAAG,EAAE;IACzD,GAAI,EAAE,eAAe,SAAY,EAAE,YAAY,EAAE,YAAY,GAAG,EAAE;IAClE,GAAI,EAAE,iBAAiB,SAAY,EAAE,cAAc,EAAE,cAAc,GAAG,EAAE;IACxE,aAAa,EAAE;IAChB,EAAE,EACJ;;EAEJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BJ,SAAgB,uBACd,MAC6C;AAC7C,QAAO,KAA4C;EACjD,MAAM;EACN,aACE;EACF,aAAa;EACb,cAAc;EAGd,eAAe;EACf,iBAAiB;EACjB,eAAe;EACf,aAAa;EACb,iBAAiB;EACjB,MAAM;GAAC;GAAU;GAAY;GAAS;EACtC,MAAM,QAAQ,OAAO,KAAK;GACxB,MAAM,QAAQ,MAAM,KAAK,aAAa,IAAI;AAG1C,SAAM,KAAK,SAAS,SAAS,OAAO,MAAM,QAAQ,MAAM,OAAO;AAC/D,UAAO;IAAE,QAAQ,MAAM;IAAQ,WAAW;IAAM;;EAEnD,CAAC"}
|
|
1
|
+
{"version":3,"file":"fact-tools.js","names":[],"sources":["../../src/tools/fact-tools.ts"],"sourcesContent":["import type { Tool } from '@graphorin/core';\nimport { toolReturn } from '@graphorin/core';\nimport { tool } from '@graphorin/tools';\nimport { z } from 'zod';\nimport { recallTaint } from './taint.js';\nimport type { MemoryToolDeps } from './types.js';\n\nconst sensitivityEnum = z.enum(['public', 'internal', 'secret']);\nconst provenanceEnum = z.enum([\n 'user',\n 'tool',\n 'extraction',\n 'reflection',\n 'induction',\n 'imported',\n]);\n\nconst factRememberInputSchema = z.object({\n text: z.string().min(1).max(8192),\n tags: z.array(z.string().min(1).max(64)).max(32).optional(),\n confidence: z.number().min(0).max(1).optional(),\n sensitivity: sensitivityEnum.optional(),\n validFrom: z.string().datetime().optional(),\n validTo: z.string().datetime().optional(),\n});\nconst factRememberOutputSchema = z.object({\n factId: z.string(),\n /**\n * MRET-3: `true` when the write landed in quarantine (hidden from\n * default recall until validated). A synthesized consolidator write or\n * a candidate that tripped the injection heuristics quarantines.\n */\n quarantined: z.boolean(),\n /** Why it was quarantined, when it was. */\n quarantineReason: z.enum(['injection', 'synthesized']).optional(),\n});\n\n/**\n * W-013: explicit interfaces instead of `z.infer<typeof schema>` - the\n * inferred aliases baked concrete v3 zod object generics into\n * the published d.ts, which do not typecheck under a zod@4 consumer.\n * Interface<->schema equality is pinned by type tests. Optionals carry\n * `| undefined` to match zod's `.optional()` inference exactly.\n */\nexport interface FactRememberInput {\n text: string;\n tags?: string[] | undefined;\n confidence?: number | undefined;\n sensitivity?: 'public' | 'internal' | 'secret' | undefined;\n validFrom?: string | undefined;\n validTo?: string | undefined;\n}\nexport interface FactRememberOutput {\n factId: string;\n quarantined: boolean;\n quarantineReason?: 'injection' | 'synthesized' | undefined;\n}\n\nconst factSearchInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(50).optional(),\n tags: z.array(z.string().min(1)).max(16).optional(),\n asOf: z.string().datetime().optional(),\n});\nconst factSearchOutputSchema = z.object({\n hits: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n score: z.number(),\n sensitivity: sensitivityEnum,\n provenance: provenanceEnum.optional(),\n /**\n * Set when the fact's validity interval was closed (superseded /\n * expired). Only present on `asOf` reads - default reads exclude\n * such facts entirely (memory-retrieval-01).\n */\n validTo: z.string().optional(),\n /** Id of the fact that superseded this one, when any. */\n supersededBy: z.string().optional(),\n }),\n ),\n});\n\nexport interface FactSearchInput {\n query: string;\n topK?: number | undefined;\n tags?: string[] | undefined;\n asOf?: string | undefined;\n}\nexport interface FactSearchHit {\n factId: string;\n text: string;\n score: number;\n sensitivity: 'public' | 'internal' | 'secret';\n provenance?: 'user' | 'tool' | 'extraction' | 'reflection' | 'induction' | 'imported' | undefined;\n validTo?: string | undefined;\n supersededBy?: string | undefined;\n}\nexport interface FactSearchOutput {\n hits: FactSearchHit[];\n}\n\nconst factSupersedeInputSchema = z.object({\n oldId: z.string().min(1),\n newText: z.string().min(1).max(8192),\n reason: z.string().max(512).optional(),\n});\nconst factSupersedeOutputSchema = z.object({\n oldId: z.string(),\n newId: z.string(),\n});\n\nexport interface FactSupersedeInput {\n oldId: string;\n newText: string;\n reason?: string | undefined;\n}\nexport interface FactSupersedeOutput {\n oldId: string;\n newId: string;\n}\n\nconst factForgetInputSchema = z.object({\n factId: z.string().min(1),\n reason: z.string().max(512).optional(),\n});\nconst factForgetOutputSchema = z.object({\n factId: z.string(),\n forgotten: z.boolean(),\n});\n\nexport interface FactForgetInput {\n factId: string;\n reason?: string | undefined;\n}\nexport interface FactForgetOutput {\n factId: string;\n forgotten: boolean;\n}\n\nconst factHistoryInputSchema = z.object({\n factId: z.string().min(1),\n});\nconst factHistoryOutputSchema = z.object({\n chain: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n validFrom: z.string().optional(),\n validTo: z.string().optional(),\n supersedes: z.string().optional(),\n supersededBy: z.string().optional(),\n sensitivity: sensitivityEnum,\n }),\n ),\n});\n\nexport interface FactHistoryInput {\n factId: string;\n}\nexport interface FactHistoryEntry {\n factId: string;\n text: string;\n validFrom?: string | undefined;\n validTo?: string | undefined;\n supersedes?: string | undefined;\n supersededBy?: string | undefined;\n sensitivity: 'public' | 'internal' | 'secret';\n}\nexport interface FactHistoryOutput {\n chain: FactHistoryEntry[];\n}\n\nconst factValidateInputSchema = z.object({\n factId: z.string().min(1),\n reason: z.string().max(512).optional(),\n});\nconst factValidateOutputSchema = z.object({\n factId: z.string(),\n validated: z.boolean(),\n});\n\nexport interface FactValidateInput {\n factId: string;\n reason?: string | undefined;\n}\nexport interface FactValidateOutput {\n factId: string;\n validated: boolean;\n}\n\n// W-013 parity gate (compile-time only, erased from the build and the\n// d.ts): each explicit interface must stay MUTUALLY assignable with its\n// schema's inference - a drifted transcription fails `tsc` right here.\ntype W013Equals<A, B> = A extends B ? (B extends A ? true : false) : false;\ntype W013Assert<T extends true> = T;\ntype _W013Check1 = W013Assert<\n W013Equals<FactRememberInput, z.infer<typeof factRememberInputSchema>>\n>;\ntype _W013Check2 = W013Assert<\n W013Equals<FactRememberOutput, z.infer<typeof factRememberOutputSchema>>\n>;\ntype _W013Check3 = W013Assert<W013Equals<FactSearchInput, z.infer<typeof factSearchInputSchema>>>;\ntype _W013Check4 = W013Assert<W013Equals<FactSearchOutput, z.infer<typeof factSearchOutputSchema>>>;\ntype _W013Check5 = W013Assert<\n W013Equals<FactSupersedeInput, z.infer<typeof factSupersedeInputSchema>>\n>;\ntype _W013Check6 = W013Assert<\n W013Equals<FactSupersedeOutput, z.infer<typeof factSupersedeOutputSchema>>\n>;\ntype _W013Check7 = W013Assert<W013Equals<FactForgetInput, z.infer<typeof factForgetInputSchema>>>;\ntype _W013Check8 = W013Assert<W013Equals<FactForgetOutput, z.infer<typeof factForgetOutputSchema>>>;\ntype _W013Check9 = W013Assert<W013Equals<FactHistoryInput, z.infer<typeof factHistoryInputSchema>>>;\ntype _W013Check10 = W013Assert<\n W013Equals<FactHistoryOutput, z.infer<typeof factHistoryOutputSchema>>\n>;\ntype _W013Check11 = W013Assert<\n W013Equals<FactValidateInput, z.infer<typeof factValidateInputSchema>>\n>;\ntype _W013Check12 = W013Assert<\n W013Equals<FactValidateOutput, z.infer<typeof factValidateOutputSchema>>\n>;\n\n/**\n * `fact_remember` - persist a single semantic fact. The minimum-viable\n * pipeline writes the fact straight through with MD5 deduplication;\n * Phase 10b extends the body with the multi-stage conflict resolution.\n *\n * @stable\n */\nexport function createFactRememberTool(\n deps: MemoryToolDeps,\n): Tool<FactRememberInput, FactRememberOutput> {\n return tool<FactRememberInput, FactRememberOutput>({\n name: 'fact_remember',\n description:\n 'Persist an atomic factual statement about the user, the world, or the current session. Prefer one fact per call; the system applies dedup + conflict resolution downstream. Pass `validFrom` / `validTo` for bi-temporal facts and `sensitivity` to control redaction.',\n inputSchema: factRememberInputSchema,\n outputSchema: factRememberOutputSchema,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const outcome = await deps.semantic.rememberWithDecision(scope, {\n text: input.text,\n ...(input.tags !== undefined ? { tags: input.tags } : {}),\n ...(input.confidence !== undefined ? { confidence: input.confidence } : {}),\n ...(input.sensitivity !== undefined ? { sensitivity: input.sensitivity } : {}),\n ...(input.validFrom !== undefined ? { validFrom: input.validFrom } : {}),\n ...(input.validTo !== undefined ? { validTo: input.validTo } : {}),\n });\n // MRET-3: tell the caller when the write was quarantined so a\n // poisoned fact cannot masquerade as a normally-stored one.\n return {\n factId: outcome.fact.id,\n quarantined: outcome.fact.status === 'quarantined',\n ...(outcome.quarantineReason !== undefined\n ? { quarantineReason: outcome.quarantineReason }\n : {}),\n };\n },\n });\n}\n\n/**\n * `fact_search` - hybrid (vector + FTS5) search over the user's\n * semantic memory. Results merged through the configured reranker.\n *\n * @stable\n */\nexport function createFactSearchTool(\n deps: MemoryToolDeps,\n): Tool<FactSearchInput, FactSearchOutput> {\n return tool<FactSearchInput, FactSearchOutput>({\n name: 'fact_search',\n description:\n \"Search the user's long-term factual memory by natural-language query. Returns up to `topK` matched facts with their score and sensitivity. Use this BEFORE asking the user a question they may have answered earlier. Pass `asOf` (ISO-8601) to read memory as it was at a past instant - point-in-time / 'what was true on date X' - instead of the current state.\",\n inputSchema: factSearchInputSchema,\n outputSchema: factSearchOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const hits = await deps.semantic.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n // MRET-4: forward the tags filter - it was accepted by the\n // schema and silently dropped here.\n ...(input.tags !== undefined && input.tags.length > 0 ? { tags: input.tags } : {}),\n ...(input.asOf !== undefined ? { asOf: input.asOf } : {}),\n signal: ctx.signal,\n });\n const output = {\n hits: hits.map((hit) => ({\n factId: hit.record.id,\n text: hit.record.text,\n score: hit.score,\n sensitivity: hit.record.sensitivity,\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n // memory-retrieval-01: surface validity metadata so the model\n // can tell a historical (asOf) hit from a current one.\n ...(hit.record.validTo !== undefined ? { validTo: hit.record.validTo } : {}),\n ...(hit.record.supersededBy !== undefined\n ? { supersededBy: hit.record.supersededBy }\n : {}),\n })),\n };\n // C6: recalled quarantined / foreign-provenance content re-arms the\n // taint ledger - the cross-session poisoning leg.\n const taint = recallTaint(hits.map((h) => h.record));\n return taint === undefined ? output : toolReturn({ output, taint });\n },\n });\n}\n\n/**\n * `fact_supersede` - soft-supersede an old fact by storing a new one\n * that replaces it. The old fact is kept for replay but no longer\n * surfaced by default reads (they evaluate validity at NOW); it stays\n * reachable via `asOf` / inspector paths.\n *\n * @stable\n */\nexport function createFactSupersedeTool(\n deps: MemoryToolDeps,\n): Tool<FactSupersedeInput, FactSupersedeOutput> {\n return tool<FactSupersedeInput, FactSupersedeOutput>({\n name: 'fact_supersede',\n description:\n \"Mark an old fact superseded by a new one. Use this when the user's situation changed (moved cities, updated a goal, switched a preference) - the old fact is preserved for replay but no longer surfaced as current.\",\n inputSchema: factSupersedeInputSchema,\n outputSchema: factSupersedeOutputSchema,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const result = await deps.semantic.supersede(\n scope,\n input.oldId,\n { text: input.newText },\n input.reason,\n );\n return { oldId: result.old, newId: result.new.id };\n },\n });\n}\n\n/**\n * `fact_forget` - soft-delete a fact (kept for replay; never hard-\n * deleted at this layer).\n *\n * @stable\n */\nexport function createFactForgetTool(\n deps: MemoryToolDeps,\n): Tool<FactForgetInput, FactForgetOutput> {\n return tool<FactForgetInput, FactForgetOutput>({\n name: 'fact_forget',\n description:\n 'Soft-delete a fact. The record is preserved for replay but no longer surfaced by fact_search. Use only for explicit user-driven removal (privacy / user request).',\n inputSchema: factForgetInputSchema,\n outputSchema: factForgetOutputSchema,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n await deps.semantic.forget(scope, input.factId, input.reason);\n return { factId: input.factId, forgotten: true };\n },\n });\n}\n\n/**\n * `fact_history` - trace how a fact changed over time. Returns the\n * full bi-temporal supersede chain the given fact belongs to, oldest →\n * newest, including superseded entries, so the agent can answer \"what\n * did the user say before\" / \"how did this change\". Read-only. P0-2.\n *\n * @stable\n */\nexport function createFactHistoryTool(\n deps: MemoryToolDeps,\n): Tool<FactHistoryInput, FactHistoryOutput> {\n return tool<FactHistoryInput, FactHistoryOutput>({\n name: 'fact_history',\n description:\n \"Trace how a fact changed over time. Given a factId, returns its full bi-temporal supersede chain (oldest → newest), including superseded entries, with each entry's validFrom/validTo. Use this to answer 'how did this change' or 'what was the previous value'.\",\n inputSchema: factHistoryInputSchema,\n outputSchema: factHistoryOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'semantic', 'temporal'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const chain = await deps.semantic.history(scope, input.factId);\n return {\n chain: chain.map((f) => ({\n factId: f.id,\n text: f.text,\n ...(f.validFrom !== undefined ? { validFrom: f.validFrom } : {}),\n ...(f.validTo !== undefined ? { validTo: f.validTo } : {}),\n ...(f.supersedes !== undefined ? { supersedes: f.supersedes } : {}),\n ...(f.supersededBy !== undefined ? { supersededBy: f.supersededBy } : {}),\n sensitivity: f.sensitivity,\n })),\n };\n },\n });\n}\n\n/**\n * `fact_validate` - promote a quarantined fact to active (P1-4). The\n * validation path that admits a synthesized (consolidator / reflection)\n * memory into action-driving recall once it has been reviewed; the\n * promotion is audited in `memory_history`.\n *\n * MRET-3 / MST-1 - two gates close the one-turn memory-poisoning chain\n * (`fact_remember(poison)` → `fact_validate(id)` → active recall):\n *\n * 1. `needsApproval: true` - the run suspends for a human decision\n * before this tool ever executes, so the agent cannot silently\n * promote any quarantined fact.\n * 2. The underlying `SemanticMemory.validate(...)` re-checks the fact's\n * text against the injection heuristics and **refuses** (no `force`\n * is passed here) - an injection-flagged memory cannot be promoted by\n * the agent at all. Only an operator, via the programmatic API with\n * `{ force: true }`, can override after review.\n *\n * Synthesized-but-clean consolidator writes promote normally once\n * approved.\n *\n * @stable\n */\nexport function createFactValidateTool(\n deps: MemoryToolDeps,\n): Tool<FactValidateInput, FactValidateOutput> {\n return tool<FactValidateInput, FactValidateOutput>({\n name: 'fact_validate',\n description:\n 'Promote a quarantined fact to active so it becomes eligible for normal recall. Quarantined facts are memories the system synthesized or flagged as risky; validating one is a deliberate, human-approved admission and never a routine step. This action requires approval, and facts flagged as prompt-injection cannot be promoted here - they are an operator-only decision.',\n inputSchema: factValidateInputSchema,\n outputSchema: factValidateOutputSchema,\n // MRET-3: the only real gate on a model-callable tool - suspend the\n // run for a human decision before promoting anything out of quarantine.\n needsApproval: true,\n sideEffectClass: 'side-effecting',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'memory-aware',\n tags: ['memory', 'semantic', 'safety'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n // No `force`: the agent path can never promote an injection-flagged\n // fact (validate throws QuarantinePromotionRefusedError for those).\n await deps.semantic.validate(scope, input.factId, input.reason);\n return { factId: input.factId, validated: true };\n },\n });\n}\n"],"mappings":";;;;;;AAOA,MAAM,kBAAkB,EAAE,KAAK;CAAC;CAAU;CAAY;CAAS,CAAC;AAChE,MAAM,iBAAiB,EAAE,KAAK;CAC5B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,0BAA0B,EAAE,OAAO;CACvC,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CACjC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU;CAC3D,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU;CAC/C,aAAa,gBAAgB,UAAU;CACvC,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU;CAC3C,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU;CAC1C,CAAC;AACF,MAAM,2BAA2B,EAAE,OAAO;CACxC,QAAQ,EAAE,QAAQ;CAMlB,aAAa,EAAE,SAAS;CAExB,kBAAkB,EAAE,KAAK,CAAC,aAAa,cAAc,CAAC,CAAC,UAAU;CAClE,CAAC;AAuBF,MAAM,wBAAwB,EAAE,OAAO;CACrC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CAClC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,CAA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