@graphorin/memory 0.6.1 → 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 +71 -0
- package/README.md +1 -1
- 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 +16 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -5
- 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 +1 -1
- package/dist/package.js.map +1 -1
- 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,200 +1,59 @@
|
|
|
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/recall-tools.d.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
9
|
-
dateRange: z.ZodOptional<z.ZodObject<{
|
|
10
|
-
from: z.ZodOptional<z.ZodString>;
|
|
11
|
-
to: z.ZodOptional<z.ZodString>;
|
|
12
|
-
}, "strip", z.ZodTypeAny, {
|
|
13
|
-
from?: string | undefined;
|
|
14
|
-
to?: string | undefined;
|
|
15
|
-
}, {
|
|
16
|
-
from?: string | undefined;
|
|
17
|
-
to?: string | undefined;
|
|
18
|
-
}>>;
|
|
19
|
-
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
/** W-013: explicit interfaces (see fact-tools.ts) - no zod generics in d.ts. */
|
|
6
|
+
interface RecallEpisodesInput {
|
|
20
7
|
query: string;
|
|
21
8
|
topK?: number | undefined;
|
|
22
9
|
dateRange?: {
|
|
23
10
|
from?: string | undefined;
|
|
24
11
|
to?: string | undefined;
|
|
25
12
|
} | undefined;
|
|
26
|
-
}
|
|
13
|
+
}
|
|
14
|
+
interface RecallEpisodeHit {
|
|
15
|
+
episodeId: string;
|
|
16
|
+
summary: string;
|
|
17
|
+
score: number;
|
|
18
|
+
startedAt: string;
|
|
19
|
+
endedAt: string;
|
|
20
|
+
provenance?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
interface RecallEpisodesOutput {
|
|
23
|
+
episodes: RecallEpisodeHit[];
|
|
24
|
+
}
|
|
25
|
+
interface ConversationSearchInput {
|
|
27
26
|
query: string;
|
|
28
27
|
topK?: number | undefined;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} | undefined;
|
|
33
|
-
}>;
|
|
34
|
-
declare const recallEpisodesOutputSchema: z.ZodObject<{
|
|
35
|
-
episodes: z.ZodArray<z.ZodObject<{
|
|
36
|
-
episodeId: z.ZodString;
|
|
37
|
-
summary: z.ZodString;
|
|
38
|
-
score: z.ZodNumber;
|
|
39
|
-
startedAt: z.ZodString;
|
|
40
|
-
endedAt: z.ZodString;
|
|
41
|
-
/** Trust-provenance tag (MST-10) - synthesized episodes say so. */
|
|
42
|
-
provenance: z.ZodOptional<z.ZodString>;
|
|
43
|
-
}, "strip", z.ZodTypeAny, {
|
|
44
|
-
score: number;
|
|
45
|
-
episodeId: string;
|
|
46
|
-
summary: string;
|
|
47
|
-
startedAt: string;
|
|
48
|
-
endedAt: string;
|
|
49
|
-
provenance?: string | undefined;
|
|
50
|
-
}, {
|
|
51
|
-
score: number;
|
|
52
|
-
episodeId: string;
|
|
53
|
-
summary: string;
|
|
54
|
-
startedAt: string;
|
|
55
|
-
endedAt: string;
|
|
56
|
-
provenance?: string | undefined;
|
|
57
|
-
}>, "many">;
|
|
58
|
-
}, "strip", z.ZodTypeAny, {
|
|
59
|
-
episodes: {
|
|
60
|
-
score: number;
|
|
61
|
-
episodeId: string;
|
|
62
|
-
summary: string;
|
|
63
|
-
startedAt: string;
|
|
64
|
-
endedAt: string;
|
|
65
|
-
provenance?: string | undefined;
|
|
66
|
-
}[];
|
|
67
|
-
}, {
|
|
68
|
-
episodes: {
|
|
69
|
-
score: number;
|
|
70
|
-
episodeId: string;
|
|
71
|
-
summary: string;
|
|
72
|
-
startedAt: string;
|
|
73
|
-
endedAt: string;
|
|
74
|
-
provenance?: string | undefined;
|
|
75
|
-
}[];
|
|
76
|
-
}>;
|
|
77
|
-
type RecallEpisodesInput = z.infer<typeof recallEpisodesInputSchema>;
|
|
78
|
-
type RecallEpisodesOutput = z.infer<typeof recallEpisodesOutputSchema>;
|
|
79
|
-
declare const conversationSearchInputSchema: z.ZodObject<{
|
|
80
|
-
query: z.ZodString;
|
|
81
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
82
|
-
}, "strip", z.ZodTypeAny, {
|
|
83
|
-
query: string;
|
|
84
|
-
topK?: number | undefined;
|
|
85
|
-
}, {
|
|
86
|
-
query: string;
|
|
87
|
-
topK?: number | undefined;
|
|
88
|
-
}>;
|
|
89
|
-
declare const conversationSearchOutputSchema: z.ZodObject<{
|
|
90
|
-
matches: z.ZodArray<z.ZodObject<{
|
|
91
|
-
messageId: z.ZodString;
|
|
92
|
-
score: z.ZodNumber;
|
|
93
|
-
}, "strip", z.ZodTypeAny, {
|
|
94
|
-
score: number;
|
|
28
|
+
}
|
|
29
|
+
interface ConversationSearchOutput {
|
|
30
|
+
matches: Array<{
|
|
95
31
|
messageId: string;
|
|
96
|
-
}, {
|
|
97
32
|
score: number;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
matches: {
|
|
102
|
-
score: number;
|
|
103
|
-
messageId: string;
|
|
104
|
-
}[];
|
|
105
|
-
}, {
|
|
106
|
-
matches: {
|
|
107
|
-
score: number;
|
|
108
|
-
messageId: string;
|
|
109
|
-
}[];
|
|
110
|
-
}>;
|
|
111
|
-
type ConversationSearchInput = z.infer<typeof conversationSearchInputSchema>;
|
|
112
|
-
type ConversationSearchOutput = z.infer<typeof conversationSearchOutputSchema>;
|
|
113
|
-
declare const deepRecallInputSchema: z.ZodObject<{
|
|
114
|
-
query: z.ZodString;
|
|
115
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
116
|
-
maxIterations: z.ZodOptional<z.ZodNumber>;
|
|
117
|
-
asOf: z.ZodOptional<z.ZodString>;
|
|
118
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
interface DeepRecallInput {
|
|
119
36
|
query: string;
|
|
120
37
|
topK?: number | undefined;
|
|
121
|
-
asOf?: string | undefined;
|
|
122
38
|
maxIterations?: number | undefined;
|
|
123
|
-
}, {
|
|
124
|
-
query: string;
|
|
125
|
-
topK?: number | undefined;
|
|
126
39
|
asOf?: string | undefined;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/** Id of the fact that superseded this one, when any. */
|
|
140
|
-
supersededBy: z.ZodOptional<z.ZodString>;
|
|
141
|
-
}, "strip", z.ZodTypeAny, {
|
|
142
|
-
text: string;
|
|
143
|
-
score: number;
|
|
144
|
-
sensitivity: "public" | "internal" | "secret";
|
|
145
|
-
factId: string;
|
|
146
|
-
validTo?: string | undefined;
|
|
147
|
-
provenance?: string | undefined;
|
|
148
|
-
supersededBy?: string | undefined;
|
|
149
|
-
}, {
|
|
150
|
-
text: string;
|
|
151
|
-
score: number;
|
|
152
|
-
sensitivity: "public" | "internal" | "secret";
|
|
153
|
-
factId: string;
|
|
154
|
-
validTo?: string | undefined;
|
|
155
|
-
provenance?: string | undefined;
|
|
156
|
-
supersededBy?: string | undefined;
|
|
157
|
-
}>, "many">;
|
|
158
|
-
sufficient: z.ZodBoolean;
|
|
159
|
-
abstained: z.ZodBoolean;
|
|
160
|
-
/**
|
|
161
|
-
* Whether the grader actually judged sufficiency
|
|
162
|
-
* (memory-retrieval-02). When `false`, `sufficient: true` is a
|
|
163
|
-
* default, not a verdict.
|
|
164
|
-
*/
|
|
165
|
-
graded: z.ZodBoolean;
|
|
166
|
-
iterations: z.ZodNumber;
|
|
167
|
-
}, "strip", z.ZodTypeAny, {
|
|
168
|
-
hits: {
|
|
169
|
-
text: string;
|
|
170
|
-
score: number;
|
|
171
|
-
sensitivity: "public" | "internal" | "secret";
|
|
172
|
-
factId: string;
|
|
173
|
-
validTo?: string | undefined;
|
|
174
|
-
provenance?: string | undefined;
|
|
175
|
-
supersededBy?: string | undefined;
|
|
176
|
-
}[];
|
|
177
|
-
sufficient: boolean;
|
|
178
|
-
abstained: boolean;
|
|
179
|
-
graded: boolean;
|
|
180
|
-
iterations: number;
|
|
181
|
-
}, {
|
|
182
|
-
hits: {
|
|
183
|
-
text: string;
|
|
184
|
-
score: number;
|
|
185
|
-
sensitivity: "public" | "internal" | "secret";
|
|
186
|
-
factId: string;
|
|
187
|
-
validTo?: string | undefined;
|
|
188
|
-
provenance?: string | undefined;
|
|
189
|
-
supersededBy?: string | undefined;
|
|
190
|
-
}[];
|
|
40
|
+
}
|
|
41
|
+
interface DeepRecallHit {
|
|
42
|
+
factId: string;
|
|
43
|
+
text: string;
|
|
44
|
+
score: number;
|
|
45
|
+
sensitivity: 'public' | 'internal' | 'secret';
|
|
46
|
+
provenance?: string | undefined;
|
|
47
|
+
validTo?: string | undefined;
|
|
48
|
+
supersededBy?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
interface DeepRecallOutput {
|
|
51
|
+
hits: DeepRecallHit[];
|
|
191
52
|
sufficient: boolean;
|
|
192
53
|
abstained: boolean;
|
|
193
54
|
graded: boolean;
|
|
194
55
|
iterations: number;
|
|
195
|
-
}
|
|
196
|
-
type DeepRecallInput = z.infer<typeof deepRecallInputSchema>;
|
|
197
|
-
type DeepRecallOutput = z.infer<typeof deepRecallOutputSchema>;
|
|
56
|
+
}
|
|
198
57
|
/**
|
|
199
58
|
* `recall_episodes` - triple-signal episode retrieval (recency ×
|
|
200
59
|
* relevance × importance).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recall-tools.d.ts","names":[],"sources":["../../src/tools/recall-tools.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"recall-tools.d.ts","names":[],"sources":["../../src/tools/recall-tools.ts"],"sourcesContent":[],"mappings":";;;;;UAgCiB,mBAAA;EAAA,KAAA,EAAA,MAAA;EAKA,IAAA,CAAA,EAAA,MAAA,GAAA,SAAgB;EAQhB,SAAA,CAAA,EAAA;IAiBA,IAAA,CAAA,EAAA,MAAA,GAAA,SAAuB;IAIvB,EAAA,CAAA,EAAA,MAAA,GAAA,SAAwB;EAqCxB,CAAA,GAAA,SAAA;AAMjB;AASiB,UAjFA,gBAAA,CAiFgB;EAkCjB,SAAA,EAAA,MAAA;EACR,OAAA,EAAA,MAAA;EACA,KAAA,EAAA,MAAA;EAAqB,SAAA,EAAA,MAAA;EAA1B,OAAA,EAAA,MAAA;EAAI,UAAA,CAAA,EAAA,MAAA,GAAA,SAAA;AAqDP;AACQ,UAnKS,oBAAA,CAmKT;EACA,QAAA,EAnKI,gBAmKJ,EAAA;;AAAL,UAnJc,uBAAA,CAmJd;EAAI,KAAA,EAAA,MAAA;EA0CS,IAAA,CAAA,EAAA,MAAA,GAAA,SAAoB;;AAE5B,UA3LS,wBAAA,CA2LT;EAAiB,OAAA,EA1Ld,KA0Lc,CAAA;IAAtB,SAAA,EAAA,MAAA;IAAI,KAAA,EAAA,MAAA;;;UAtJU,eAAA;;;;;;UAMA,aAAA;;;;;;;;;UASA,gBAAA;QACT;;;;;;;;;;;;iBAiCQ,wBAAA,OACR,iBACL,KAAK,qBAAqB;;;;;;;iBAqDb,4BAAA,OACR,iBACL,KAAK,yBAAyB;;;;;;;;;;;;;;;iBA0CjB,oBAAA,OACR,iBACL,KAAK,iBAAiB"}
|
|
@@ -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
|
|
|
@@ -90,10 +91,10 @@ function createRecallEpisodesTool(deps) {
|
|
|
90
91
|
...hit.record.provenance !== void 0 ? { provenance: hit.record.provenance } : {}
|
|
91
92
|
})) };
|
|
92
93
|
const taint = recallTaint(hits.map((h) => h.record));
|
|
93
|
-
return taint === void 0 ? output : {
|
|
94
|
+
return taint === void 0 ? output : toolReturn({
|
|
94
95
|
output,
|
|
95
96
|
taint
|
|
96
|
-
};
|
|
97
|
+
});
|
|
97
98
|
}
|
|
98
99
|
});
|
|
99
100
|
}
|
|
@@ -176,10 +177,10 @@ function createDeepRecallTool(deps) {
|
|
|
176
177
|
iterations: result.iterations
|
|
177
178
|
};
|
|
178
179
|
const taint = recallTaint(result.hits.map((h) => h.record));
|
|
179
|
-
return taint === void 0 ? output : {
|
|
180
|
+
return taint === void 0 ? output : toolReturn({
|
|
180
181
|
output,
|
|
181
182
|
taint
|
|
182
|
-
};
|
|
183
|
+
});
|
|
183
184
|
}
|
|
184
185
|
});
|
|
185
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recall-tools.js","names":[],"sources":["../../src/tools/recall-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 recallEpisodesInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(20).optional(),\n dateRange: z\n .object({\n from: z.string().datetime().optional(),\n to: z.string().datetime().optional(),\n })\n .optional(),\n});\nconst recallEpisodesOutputSchema = z.object({\n episodes: z.array(\n z.object({\n episodeId: z.string(),\n summary: z.string(),\n score: z.number(),\n startedAt: z.string(),\n endedAt: z.string(),\n /** Trust-provenance tag (MST-10) - synthesized episodes say so. */\n provenance: z.string().optional(),\n }),\n ),\n});\n\ntype RecallEpisodesInput = z.infer<typeof recallEpisodesInputSchema>;\ntype RecallEpisodesOutput = z.infer<typeof recallEpisodesOutputSchema>;\n\nconst conversationSearchInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(20).optional(),\n});\nconst conversationSearchOutputSchema = z.object({\n matches: z.array(\n z.object({\n messageId: z.string(),\n score: z.number(),\n }),\n ),\n});\n\ntype ConversationSearchInput = z.infer<typeof conversationSearchInputSchema>;\ntype ConversationSearchOutput = z.infer<typeof conversationSearchOutputSchema>;\n\nconst deepRecallSensitivityEnum = z.enum(['public', 'internal', 'secret']);\nconst deepRecallInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(50).optional(),\n maxIterations: z.number().int().min(1).max(5).optional(),\n asOf: z.string().datetime().optional(),\n});\nconst deepRecallOutputSchema = z.object({\n hits: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n score: z.number(),\n sensitivity: deepRecallSensitivityEnum,\n /** Trust-provenance tag (MST-10) - synthesized facts say so. */\n provenance: z.string().optional(),\n /** Closed validity end (only surfaces on `asOf` reads). */\n validTo: z.string().optional(),\n /** Id of the fact that superseded this one, when any. */\n supersededBy: z.string().optional(),\n }),\n ),\n sufficient: z.boolean(),\n abstained: z.boolean(),\n /**\n * Whether the grader actually judged sufficiency\n * (memory-retrieval-02). When `false`, `sufficient: true` is a\n * default, not a verdict.\n */\n graded: z.boolean(),\n iterations: z.number().int(),\n});\n\ntype DeepRecallInput = z.infer<typeof deepRecallInputSchema>;\ntype DeepRecallOutput = z.infer<typeof deepRecallOutputSchema>;\n\n/**\n * `recall_episodes` - triple-signal episode retrieval (recency ×\n * relevance × importance).\n *\n * @stable\n */\nexport function createRecallEpisodesTool(\n deps: MemoryToolDeps,\n): Tool<RecallEpisodesInput, RecallEpisodesOutput> {\n return tool<RecallEpisodesInput, RecallEpisodesOutput>({\n name: 'recall_episodes',\n description:\n \"Recall summarized episodes (multi-message stretches of past activity) matching a natural-language query. Combines vector relevance, time-decay recency, and the per-episode importance score. Use for long-horizon recall ('the last time we discussed X').\",\n inputSchema: recallEpisodesInputSchema,\n outputSchema: recallEpisodesOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'episodic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const dateRange =\n input.dateRange !== undefined\n ? {\n ...(input.dateRange.from !== undefined ? { from: input.dateRange.from } : {}),\n ...(input.dateRange.to !== undefined ? { to: input.dateRange.to } : {}),\n }\n : undefined;\n const hits = await deps.episodic.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n ...(dateRange !== undefined ? { dateRange } : {}),\n signal: ctx.signal,\n });\n const output = {\n episodes: hits.map((hit) => ({\n episodeId: hit.record.id,\n summary: hit.record.summary,\n score: hit.score,\n startedAt: hit.record.startedAt,\n endedAt: hit.record.endedAt,\n // MST-10: surface origin so a consumer can tell a synthesized\n // (consolidator-extracted) episode from a first-party record -\n // recalled text re-enters the model as trusted tool output.\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n })),\n };\n // C6: recalled foreign-provenance / quarantined episodes re-arm 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 * `conversation_search` - FTS5 search over the active session\n * messages.\n *\n * @stable\n */\nexport function createConversationSearchTool(\n deps: MemoryToolDeps,\n): Tool<ConversationSearchInput, ConversationSearchOutput> {\n return tool<ConversationSearchInput, ConversationSearchOutput>({\n name: 'conversation_search',\n description:\n 'Search the active session message log by natural-language query. Returns up to `topK` matched messages with their stable id and BM25 score.',\n inputSchema: conversationSearchInputSchema,\n outputSchema: conversationSearchOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'session'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const hits = await deps.session.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n signal: ctx.signal,\n });\n return {\n matches: hits.map((hit) => ({\n messageId: hit.record.id,\n score: hit.score,\n })),\n };\n },\n });\n}\n\n/**\n * `deep_recall` - gated, multi-pass (\"deep\") recall over the user's\n * factual memory for HARD questions (P2-4). A local difficulty gate keeps\n * simple lookups single-shot; only queries judged hard trigger a\n * grade-and-reformulate loop (bounded by `maxIterations`, hard-capped at\n * 5), widening to one-hop graph expansion on reformulation passes. The\n * output reports `abstained: true` when memory was insufficient even\n * after reformulating - the agent should then say it lacks the\n * information rather than guess. Registered only when the facade is\n * created with `iterativeRetrieval`; otherwise it degrades to a single\n * pass, so prefer the cheaper `fact_search` for ordinary lookups.\n *\n * @stable\n */\nexport function createDeepRecallTool(\n deps: MemoryToolDeps,\n): Tool<DeepRecallInput, DeepRecallOutput> {\n return tool<DeepRecallInput, DeepRecallOutput>({\n name: 'deep_recall',\n description:\n \"Multi-pass ('deep') recall over the user's long-term factual memory for HARD multi-hop or temporal questions one search can't answer (e.g. 'who recommended the book the person I met in Tbilisi mentioned?'). A difficulty gate keeps simple lookups single-shot; hard questions trigger a bounded grade-and-reformulate loop. If `abstained` is true the memory was insufficient even after reformulating - tell the user you don't have enough stored to answer and DO NOT guess. Prefer the cheaper fact_search for ordinary lookups.\",\n inputSchema: deepRecallInputSchema,\n outputSchema: deepRecallOutputSchema,\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 result = await deps.semantic.searchIterative(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n ...(input.maxIterations !== undefined ? { maxIterations: input.maxIterations } : {}),\n ...(input.asOf !== undefined ? { asOf: input.asOf } : {}),\n // memory-retrieval-02: the model choosing deep_recall over\n // fact_search IS the hardness signal - the local heuristic gate\n // rejected the tool's own documented multi-hop examples\n // (W_MULTI_HOP 0.4 < threshold 0.5) and is English-only. The\n // cap + grader stop conditions still bound cost.\n forceHard: true,\n signal: ctx.signal,\n });\n const output = {\n hits: result.hits.map((hit) => ({\n factId: hit.record.id,\n text: hit.record.text,\n score: hit.score,\n sensitivity: hit.record.sensitivity,\n // MST-10: origin annotation, mirroring fact_search.\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n ...(hit.record.validTo !== undefined ? { validTo: hit.record.validTo } : {}),\n ...(hit.record.supersededBy !== undefined\n ? { supersededBy: hit.record.supersededBy }\n : {}),\n })),\n sufficient: result.sufficient,\n abstained: result.abstained,\n graded: result.graded,\n iterations: result.iterations,\n };\n // C6: mirror fact_search - recalled poisoned content re-arms the ledger.\n const taint = recallTaint(result.hits.map((h) => h.record));\n return taint === undefined ? output : { output, taint };\n },\n });\n}\n"],"mappings":";;;;;AAMA,MAAM,4BAA4B,EAAE,OAAO;CACzC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CAClC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU;CACpD,WAAW,EACR,OAAO;EACN,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU;EACtC,IAAI,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU;EACrC,CAAC,CACD,UAAU;CACd,CAAC;AACF,MAAM,6BAA6B,EAAE,OAAO,EAC1C,UAAU,EAAE,MACV,EAAE,OAAO;CACP,WAAW,EAAE,QAAQ;CACrB,SAAS,EAAE,QAAQ;CACnB,OAAO,EAAE,QAAQ;CACjB,WAAW,EAAE,QAAQ;CACrB,SAAS,EAAE,QAAQ;CAEnB,YAAY,EAAE,QAAQ,CAAC,UAAU;CAClC,CAAC,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QAAQ,OAAO;IACf,YAAY,OAAO;IACpB;GAED,MAAM,QAAQ,YAAY,OAAO,KAAK,KAAK,MAAM,EAAE,OAAO,CAAC;AAC3D,UAAO,UAAU,SAAY,SAAS;IAAE;IAAQ;IAAO;;EAE1D,CAAC"}
|
|
1
|
+
{"version":3,"file":"recall-tools.js","names":[],"sources":["../../src/tools/recall-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 recallEpisodesInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(20).optional(),\n dateRange: z\n .object({\n from: z.string().datetime().optional(),\n to: z.string().datetime().optional(),\n })\n .optional(),\n});\nconst recallEpisodesOutputSchema = z.object({\n episodes: z.array(\n z.object({\n episodeId: z.string(),\n summary: z.string(),\n score: z.number(),\n startedAt: z.string(),\n endedAt: z.string(),\n /** Trust-provenance tag (MST-10) - synthesized episodes say so. */\n provenance: z.string().optional(),\n }),\n ),\n});\n\n/** W-013: explicit interfaces (see fact-tools.ts) - no zod generics in d.ts. */\nexport interface RecallEpisodesInput {\n query: string;\n topK?: number | undefined;\n dateRange?: { from?: string | undefined; to?: string | undefined } | undefined;\n}\nexport interface RecallEpisodeHit {\n episodeId: string;\n summary: string;\n score: number;\n startedAt: string;\n endedAt: string;\n provenance?: string | undefined;\n}\nexport interface RecallEpisodesOutput {\n episodes: RecallEpisodeHit[];\n}\n\nconst conversationSearchInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(20).optional(),\n});\nconst conversationSearchOutputSchema = z.object({\n matches: z.array(\n z.object({\n messageId: z.string(),\n score: z.number(),\n }),\n ),\n});\n\nexport interface ConversationSearchInput {\n query: string;\n topK?: number | undefined;\n}\nexport interface ConversationSearchOutput {\n matches: Array<{ messageId: string; score: number }>;\n}\n\nconst deepRecallSensitivityEnum = z.enum(['public', 'internal', 'secret']);\nconst deepRecallInputSchema = z.object({\n query: z.string().min(1).max(1024),\n topK: z.number().int().positive().max(50).optional(),\n maxIterations: z.number().int().min(1).max(5).optional(),\n asOf: z.string().datetime().optional(),\n});\nconst deepRecallOutputSchema = z.object({\n hits: z.array(\n z.object({\n factId: z.string(),\n text: z.string(),\n score: z.number(),\n sensitivity: deepRecallSensitivityEnum,\n /** Trust-provenance tag (MST-10) - synthesized facts say so. */\n provenance: z.string().optional(),\n /** Closed validity end (only surfaces on `asOf` reads). */\n validTo: z.string().optional(),\n /** Id of the fact that superseded this one, when any. */\n supersededBy: z.string().optional(),\n }),\n ),\n sufficient: z.boolean(),\n abstained: z.boolean(),\n /**\n * Whether the grader actually judged sufficiency\n * (memory-retrieval-02). When `false`, `sufficient: true` is a\n * default, not a verdict.\n */\n graded: z.boolean(),\n iterations: z.number().int(),\n});\n\nexport interface DeepRecallInput {\n query: string;\n topK?: number | undefined;\n maxIterations?: number | undefined;\n asOf?: string | undefined;\n}\nexport interface DeepRecallHit {\n factId: string;\n text: string;\n score: number;\n sensitivity: 'public' | 'internal' | 'secret';\n provenance?: string | undefined;\n validTo?: string | undefined;\n supersededBy?: string | undefined;\n}\nexport interface DeepRecallOutput {\n hits: DeepRecallHit[];\n sufficient: boolean;\n abstained: boolean;\n graded: boolean;\n iterations: number;\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<RecallEpisodesInput, z.infer<typeof recallEpisodesInputSchema>>\n>;\ntype _W013Check2 = W013Assert<\n W013Equals<RecallEpisodesOutput, z.infer<typeof recallEpisodesOutputSchema>>\n>;\ntype _W013Check3 = W013Assert<\n W013Equals<ConversationSearchInput, z.infer<typeof conversationSearchInputSchema>>\n>;\ntype _W013Check4 = W013Assert<\n W013Equals<ConversationSearchOutput, z.infer<typeof conversationSearchOutputSchema>>\n>;\ntype _W013Check5 = W013Assert<W013Equals<DeepRecallInput, z.infer<typeof deepRecallInputSchema>>>;\ntype _W013Check6 = W013Assert<W013Equals<DeepRecallOutput, z.infer<typeof deepRecallOutputSchema>>>;\n\n/**\n * `recall_episodes` - triple-signal episode retrieval (recency ×\n * relevance × importance).\n *\n * @stable\n */\nexport function createRecallEpisodesTool(\n deps: MemoryToolDeps,\n): Tool<RecallEpisodesInput, RecallEpisodesOutput> {\n return tool<RecallEpisodesInput, RecallEpisodesOutput>({\n name: 'recall_episodes',\n description:\n \"Recall summarized episodes (multi-message stretches of past activity) matching a natural-language query. Combines vector relevance, time-decay recency, and the per-episode importance score. Use for long-horizon recall ('the last time we discussed X').\",\n inputSchema: recallEpisodesInputSchema,\n outputSchema: recallEpisodesOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'episodic'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const dateRange =\n input.dateRange !== undefined\n ? {\n ...(input.dateRange.from !== undefined ? { from: input.dateRange.from } : {}),\n ...(input.dateRange.to !== undefined ? { to: input.dateRange.to } : {}),\n }\n : undefined;\n const hits = await deps.episodic.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n ...(dateRange !== undefined ? { dateRange } : {}),\n signal: ctx.signal,\n });\n const output = {\n episodes: hits.map((hit) => ({\n episodeId: hit.record.id,\n summary: hit.record.summary,\n score: hit.score,\n startedAt: hit.record.startedAt,\n endedAt: hit.record.endedAt,\n // MST-10: surface origin so a consumer can tell a synthesized\n // (consolidator-extracted) episode from a first-party record -\n // recalled text re-enters the model as trusted tool output.\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n })),\n };\n // C6: recalled foreign-provenance / quarantined episodes re-arm 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 * `conversation_search` - FTS5 search over the active session\n * messages.\n *\n * @stable\n */\nexport function createConversationSearchTool(\n deps: MemoryToolDeps,\n): Tool<ConversationSearchInput, ConversationSearchOutput> {\n return tool<ConversationSearchInput, ConversationSearchOutput>({\n name: 'conversation_search',\n description:\n 'Search the active session message log by natural-language query. Returns up to `topK` matched messages with their stable id and BM25 score.',\n inputSchema: conversationSearchInputSchema,\n outputSchema: conversationSearchOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'session'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const hits = await deps.session.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n signal: ctx.signal,\n });\n return {\n matches: hits.map((hit) => ({\n messageId: hit.record.id,\n score: hit.score,\n })),\n };\n },\n });\n}\n\n/**\n * `deep_recall` - gated, multi-pass (\"deep\") recall over the user's\n * factual memory for HARD questions (P2-4). A local difficulty gate keeps\n * simple lookups single-shot; only queries judged hard trigger a\n * grade-and-reformulate loop (bounded by `maxIterations`, hard-capped at\n * 5), widening to one-hop graph expansion on reformulation passes. The\n * output reports `abstained: true` when memory was insufficient even\n * after reformulating - the agent should then say it lacks the\n * information rather than guess. Registered only when the facade is\n * created with `iterativeRetrieval`; otherwise it degrades to a single\n * pass, so prefer the cheaper `fact_search` for ordinary lookups.\n *\n * @stable\n */\nexport function createDeepRecallTool(\n deps: MemoryToolDeps,\n): Tool<DeepRecallInput, DeepRecallOutput> {\n return tool<DeepRecallInput, DeepRecallOutput>({\n name: 'deep_recall',\n description:\n \"Multi-pass ('deep') recall over the user's long-term factual memory for HARD multi-hop or temporal questions one search can't answer (e.g. 'who recommended the book the person I met in Tbilisi mentioned?'). A difficulty gate keeps simple lookups single-shot; hard questions trigger a bounded grade-and-reformulate loop. If `abstained` is true the memory was insufficient even after reformulating - tell the user you don't have enough stored to answer and DO NOT guess. Prefer the cheaper fact_search for ordinary lookups.\",\n inputSchema: deepRecallInputSchema,\n outputSchema: deepRecallOutputSchema,\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 result = await deps.semantic.searchIterative(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n ...(input.maxIterations !== undefined ? { maxIterations: input.maxIterations } : {}),\n ...(input.asOf !== undefined ? { asOf: input.asOf } : {}),\n // memory-retrieval-02: the model choosing deep_recall over\n // fact_search IS the hardness signal - the local heuristic gate\n // rejected the tool's own documented multi-hop examples\n // (W_MULTI_HOP 0.4 < threshold 0.5) and is English-only. The\n // cap + grader stop conditions still bound cost.\n forceHard: true,\n signal: ctx.signal,\n });\n const output = {\n hits: result.hits.map((hit) => ({\n factId: hit.record.id,\n text: hit.record.text,\n score: hit.score,\n sensitivity: hit.record.sensitivity,\n // MST-10: origin annotation, mirroring fact_search.\n ...(hit.record.provenance !== undefined ? { provenance: hit.record.provenance } : {}),\n ...(hit.record.validTo !== undefined ? { validTo: hit.record.validTo } : {}),\n ...(hit.record.supersededBy !== undefined\n ? { supersededBy: hit.record.supersededBy }\n : {}),\n })),\n sufficient: result.sufficient,\n abstained: result.abstained,\n graded: result.graded,\n iterations: result.iterations,\n };\n // C6: mirror fact_search - recalled poisoned content re-arms the ledger.\n const taint = recallTaint(result.hits.map((h) => h.record));\n return taint === undefined ? output : toolReturn({ output, taint });\n },\n });\n}\n"],"mappings":";;;;;;AAOA,MAAM,4BAA4B,EAAE,OAAO;CACzC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CAClC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CA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AAC;GACF,MAAM,SAAS;IACb,MAAM,OAAO,KAAK,KAAK,SAAS;KAC9B,QAAQ,IAAI,OAAO;KACnB,MAAM,IAAI,OAAO;KACjB,OAAO,IAAI;KACX,aAAa,IAAI,OAAO;KAExB,GAAI,IAAI,OAAO,eAAe,SAAY,EAAE,YAAY,IAAI,OAAO,YAAY,GAAG,EAAE;KACpF,GAAI,IAAI,OAAO,YAAY,SAAY,EAAE,SAAS,IAAI,OAAO,SAAS,GAAG,EAAE;KAC3E,GAAI,IAAI,OAAO,iBAAiB,SAC5B,EAAE,cAAc,IAAI,OAAO,cAAc,GACzC,EAAE;KACP,EAAE;IACH,YAAY,OAAO;IACnB,WAAW,OAAO;IAClB,QAAQ,OAAO;IACf,YAAY,OAAO;IACpB;GAED,MAAM,QAAQ,YAAY,OAAO,KAAK,KAAK,MAAM,EAAE,OAAO,CAAC;AAC3D,UAAO,UAAU,SAAY,SAAS,WAAW;IAAE;IAAQ;IAAO,CAAC;;EAEtE,CAAC"}
|
|
@@ -1,68 +1,25 @@
|
|
|
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/runbook-tools.d.ts
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
topK: z.ZodOptional<z.ZodNumber>;
|
|
10
|
-
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
/** W-013: explicit interfaces (see fact-tools.ts) - no zod generics in d.ts. */
|
|
7
|
+
interface RunbookSearchInput {
|
|
11
8
|
query: string;
|
|
12
9
|
topK?: number | undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, "strip", z.ZodTypeAny, {
|
|
27
|
-
id: string;
|
|
28
|
-
text: string;
|
|
29
|
-
priority: number;
|
|
30
|
-
score: number;
|
|
31
|
-
steps?: string[] | undefined;
|
|
32
|
-
variables?: string[] | undefined;
|
|
33
|
-
successCriteria?: string[] | undefined;
|
|
34
|
-
}, {
|
|
35
|
-
id: string;
|
|
36
|
-
text: string;
|
|
37
|
-
priority: number;
|
|
38
|
-
score: number;
|
|
39
|
-
steps?: string[] | undefined;
|
|
40
|
-
variables?: string[] | undefined;
|
|
41
|
-
successCriteria?: string[] | undefined;
|
|
42
|
-
}>, "many">;
|
|
43
|
-
}, "strip", z.ZodTypeAny, {
|
|
44
|
-
procedures: {
|
|
45
|
-
id: string;
|
|
46
|
-
text: string;
|
|
47
|
-
priority: number;
|
|
48
|
-
score: number;
|
|
49
|
-
steps?: string[] | undefined;
|
|
50
|
-
variables?: string[] | undefined;
|
|
51
|
-
successCriteria?: string[] | undefined;
|
|
52
|
-
}[];
|
|
53
|
-
}, {
|
|
54
|
-
procedures: {
|
|
55
|
-
id: string;
|
|
56
|
-
text: string;
|
|
57
|
-
priority: number;
|
|
58
|
-
score: number;
|
|
59
|
-
steps?: string[] | undefined;
|
|
60
|
-
variables?: string[] | undefined;
|
|
61
|
-
successCriteria?: string[] | undefined;
|
|
62
|
-
}[];
|
|
63
|
-
}>;
|
|
64
|
-
type RunbookSearchInput = z.infer<typeof runbookSearchInputSchema>;
|
|
65
|
-
type RunbookSearchOutput = z.infer<typeof runbookSearchOutputSchema>;
|
|
10
|
+
}
|
|
11
|
+
interface RunbookProcedureHit {
|
|
12
|
+
id: string;
|
|
13
|
+
text: string;
|
|
14
|
+
steps?: string[] | undefined;
|
|
15
|
+
variables?: string[] | undefined;
|
|
16
|
+
successCriteria?: string[] | undefined;
|
|
17
|
+
priority: number;
|
|
18
|
+
score: number;
|
|
19
|
+
}
|
|
20
|
+
interface RunbookSearchOutput {
|
|
21
|
+
procedures: RunbookProcedureHit[];
|
|
22
|
+
}
|
|
66
23
|
/**
|
|
67
24
|
* `runbook_search` - find validated procedures matching a task
|
|
68
25
|
* description. Quarantined (unvalidated induced) procedures never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runbook-tools.d.ts","names":[],"sources":["../../src/tools/runbook-tools.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"runbook-tools.d.ts","names":[],"sources":["../../src/tools/runbook-tools.ts"],"sourcesContent":[],"mappings":";;;;;;UAoCiB,kBAAA;;;;UAIA,mBAAA;;;;;;;;;UASA,mBAAA;cACH;;;;;;;;;iBAsBE,uBAAA,OACR,iBACL,KAAK,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runbook-tools.js","names":[],"sources":["../../src/tools/runbook-tools.ts"],"sourcesContent":["/**\n * Runbook tool (D3) - gated content recall over procedural memory.\n * `runbook_search` finds validated procedures whose text / steps match\n * a task description and returns them **whole** (title line, numbered\n * steps, variables, success criteria), so the model can follow a known\n * workflow file-style instead of re-deriving it. Registered only when\n * the facade opts in (`createMemory({ runbookSearch: true })`) - the\n * default tool surface is unchanged.\n *\n * @packageDocumentation\n */\n\nimport type { Tool } from '@graphorin/core';\nimport { tool } from '@graphorin/tools';\nimport { z } from 'zod';\nimport type { MemoryToolDeps } from './types.js';\n\nconst runbookSearchInputSchema = z.object({\n query: z.string().min(1).max(512),\n topK: z.number().int().min(1).max(20).optional(),\n});\nconst runbookSearchOutputSchema = z.object({\n procedures: z.array(\n z.object({\n id: z.string(),\n text: z.string(),\n steps: z.array(z.string()).optional(),\n variables: z.array(z.string()).optional(),\n successCriteria: z.array(z.string()).optional(),\n priority: z.number(),\n score: z.number(),\n }),\n ),\n});\n\
|
|
1
|
+
{"version":3,"file":"runbook-tools.js","names":[],"sources":["../../src/tools/runbook-tools.ts"],"sourcesContent":["/**\n * Runbook tool (D3) - gated content recall over procedural memory.\n * `runbook_search` finds validated procedures whose text / steps match\n * a task description and returns them **whole** (title line, numbered\n * steps, variables, success criteria), so the model can follow a known\n * workflow file-style instead of re-deriving it. Registered only when\n * the facade opts in (`createMemory({ runbookSearch: true })`) - the\n * default tool surface is unchanged.\n *\n * @packageDocumentation\n */\n\nimport type { Tool } from '@graphorin/core';\nimport { tool } from '@graphorin/tools';\nimport { z } from 'zod';\nimport type { MemoryToolDeps } from './types.js';\n\nconst runbookSearchInputSchema = z.object({\n query: z.string().min(1).max(512),\n topK: z.number().int().min(1).max(20).optional(),\n});\nconst runbookSearchOutputSchema = z.object({\n procedures: z.array(\n z.object({\n id: z.string(),\n text: z.string(),\n steps: z.array(z.string()).optional(),\n variables: z.array(z.string()).optional(),\n successCriteria: z.array(z.string()).optional(),\n priority: z.number(),\n score: z.number(),\n }),\n ),\n});\n\n/** W-013: explicit interfaces (see fact-tools.ts) - no zod generics in d.ts. */\nexport interface RunbookSearchInput {\n query: string;\n topK?: number | undefined;\n}\nexport interface RunbookProcedureHit {\n id: string;\n text: string;\n steps?: string[] | undefined;\n variables?: string[] | undefined;\n successCriteria?: string[] | undefined;\n priority: number;\n score: number;\n}\nexport interface RunbookSearchOutput {\n procedures: RunbookProcedureHit[];\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<RunbookSearchInput, z.infer<typeof runbookSearchInputSchema>>\n>;\ntype _W013Check2 = W013Assert<\n W013Equals<RunbookSearchOutput, z.infer<typeof runbookSearchOutputSchema>>\n>;\n\n/**\n * `runbook_search` - find validated procedures matching a task\n * description. Quarantined (unvalidated induced) procedures never\n * surface here: they must not drive actions until validated.\n *\n * @stable\n */\nexport function createRunbookSearchTool(\n deps: MemoryToolDeps,\n): Tool<RunbookSearchInput, RunbookSearchOutput> {\n return tool<RunbookSearchInput, RunbookSearchOutput>({\n name: 'runbook_search',\n description:\n 'Find a stored, validated procedure (\"runbook\") matching the task at hand - e.g. \"deploy the docs site\" or \"rotate the API key\". Returns whole procedures with their numbered steps, variables, and success criteria so you can follow a known-good workflow instead of improvising. Use BEFORE attempting a multi-step operational task the user may have done with you previously.',\n inputSchema: runbookSearchInputSchema,\n outputSchema: runbookSearchOutputSchema,\n sideEffectClass: 'read-only',\n sandboxPolicy: 'none',\n sensitivity: 'internal',\n memoryGuardTier: 'pure',\n tags: ['memory', 'procedural'],\n async execute(input, ctx) {\n const scope = await deps.resolveScope(ctx);\n const hits = await deps.procedural.search(scope, input.query, {\n ...(input.topK !== undefined ? { topK: input.topK } : {}),\n });\n return {\n procedures: hits.map((hit) => ({\n id: hit.record.id,\n text: hit.record.text,\n ...(hit.record.steps !== undefined ? { steps: [...hit.record.steps] } : {}),\n ...(hit.record.variables !== undefined ? { variables: [...hit.record.variables] } : {}),\n ...(hit.record.successCriteria !== undefined\n ? { successCriteria: [...hit.record.successCriteria] }\n : {}),\n priority: hit.record.priority,\n score: hit.score,\n })),\n };\n },\n });\n}\n"],"mappings":";;;;AAiBA,MAAM,2BAA2B,EAAE,OAAO;CACxC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;CACjC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,UAAU;CACjD,CAAC;AACF,MAAM,4BAA4B,EAAE,OAAO,EACzC,YAAY,EAAE,MACZ,EAAE,OAAO;CACP,IAAI,EAAE,QAAQ;CACd,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACrC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACzC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CAC/C,UAAU,EAAE,QAAQ;CACpB,OAAO,EAAE,QAAQ;CAClB,CAAC,CACH,EACF,CAAC;;;;;;;;AAuCF,SAAgB,wBACd,MAC+C;AAC/C,QAAO,KAA8C;EACnD,MAAM;EACN,aACE;EACF,aAAa;EACb,cAAc;EACd,iBAAiB;EACjB,eAAe;EACf,aAAa;EACb,iBAAiB;EACjB,MAAM,CAAC,UAAU,aAAa;EAC9B,MAAM,QAAQ,OAAO,KAAK;GACxB,MAAM,QAAQ,MAAM,KAAK,aAAa,IAAI;AAI1C,UAAO,EACL,aAJW,MAAM,KAAK,WAAW,OAAO,OAAO,MAAM,OAAO,EAC5D,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,MAAM,MAAM,GAAG,EAAE,EACzD,CAAC,EAEiB,KAAK,SAAS;IAC7B,IAAI,IAAI,OAAO;IACf,MAAM,IAAI,OAAO;IACjB,GAAI,IAAI,OAAO,UAAU,SAAY,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,MAAM,EAAE,GAAG,EAAE;IAC1E,GAAI,IAAI,OAAO,cAAc,SAAY,EAAE,WAAW,CAAC,GAAG,IAAI,OAAO,UAAU,EAAE,GAAG,EAAE;IACtF,GAAI,IAAI,OAAO,oBAAoB,SAC/B,EAAE,iBAAiB,CAAC,GAAG,IAAI,OAAO,gBAAgB,EAAE,GACpD,EAAE;IACN,UAAU,IAAI,OAAO;IACrB,OAAO,IAAI;IACZ,EAAE,EACJ;;EAEJ,CAAC"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { SessionScope } from "@graphorin/core";
|
|
|
20
20
|
type ScopeResolver = (ctx: _graphorin_core0.ToolExecutionContext<unknown>) => SessionScope | Promise<SessionScope>;
|
|
21
21
|
/**
|
|
22
22
|
* Dependency bundle threaded into every memory tool. Exposed
|
|
23
|
-
* separately from the
|
|
23
|
+
* separately from the `Tool` surface so the executor can scope
|
|
24
24
|
* the dependencies per call without leaking the wider memory facade
|
|
25
25
|
* into the tool author surface.
|
|
26
26
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphorin/memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Six-tier memory system for the Graphorin framework: createMemory() facade with working / session / episodic / semantic / procedural / shared sub-modules, eleven memory tools wired into @graphorin/tools, hybrid vector + FTS5 search composed through Reciprocal Rank Fusion (k=60 default) with a pluggable reranker hook, a multi-stage conflict resolution pipeline (exact dedup → embedding three-zone → heuristic regex → subject/predicate → defer-to-deep) with an English locale pack default + plug-in locales, an embedder migration runner with three coexistence policies (lock-on-first / multi-active / auto-migrate), per-record embedder_id enforcement, multi-agent attribution, append-only writes with soft-delete + supersede semantics, default-on bi-temporal storage, provenance + quarantine safety gate for synthesized memory, AISpan emission for every operation, and tier-aware memory-modification guard wiring.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Oleksiy Stepurenko",
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"multi-agent"
|
|
36
36
|
],
|
|
37
37
|
"type": "module",
|
|
38
|
+
"sideEffects": false,
|
|
38
39
|
"engines": {
|
|
39
|
-
"node": ">=22.
|
|
40
|
+
"node": ">=22.12.0"
|
|
40
41
|
},
|
|
41
42
|
"main": "./dist/index.js",
|
|
42
43
|
"module": "./dist/index.js",
|
|
@@ -44,49 +45,50 @@
|
|
|
44
45
|
"exports": {
|
|
45
46
|
".": {
|
|
46
47
|
"types": "./dist/index.d.ts",
|
|
47
|
-
"
|
|
48
|
+
"default": "./dist/index.js"
|
|
48
49
|
},
|
|
49
50
|
"./facade": {
|
|
50
51
|
"types": "./dist/facade.d.ts",
|
|
51
|
-
"
|
|
52
|
+
"default": "./dist/facade.js"
|
|
52
53
|
},
|
|
53
54
|
"./tiers": {
|
|
54
55
|
"types": "./dist/tiers/index.d.ts",
|
|
55
|
-
"
|
|
56
|
+
"default": "./dist/tiers/index.js"
|
|
56
57
|
},
|
|
57
58
|
"./tools": {
|
|
58
59
|
"types": "./dist/tools/index.d.ts",
|
|
59
|
-
"
|
|
60
|
+
"default": "./dist/tools/index.js"
|
|
60
61
|
},
|
|
61
62
|
"./search": {
|
|
62
63
|
"types": "./dist/search/index.d.ts",
|
|
63
|
-
"
|
|
64
|
+
"default": "./dist/search/index.js"
|
|
64
65
|
},
|
|
65
66
|
"./conflict": {
|
|
66
67
|
"types": "./dist/conflict/index.d.ts",
|
|
67
|
-
"
|
|
68
|
+
"default": "./dist/conflict/index.js"
|
|
68
69
|
},
|
|
69
70
|
"./migration": {
|
|
70
71
|
"types": "./dist/migration/index.d.ts",
|
|
71
|
-
"
|
|
72
|
+
"default": "./dist/migration/index.js"
|
|
72
73
|
},
|
|
73
74
|
"./errors": {
|
|
74
75
|
"types": "./dist/errors/index.d.ts",
|
|
75
|
-
"
|
|
76
|
+
"default": "./dist/errors/index.js"
|
|
76
77
|
},
|
|
77
78
|
"./package.json": "./package.json"
|
|
78
79
|
},
|
|
79
80
|
"files": [
|
|
80
81
|
"dist",
|
|
82
|
+
"src",
|
|
81
83
|
"README.md",
|
|
82
84
|
"CHANGELOG.md",
|
|
83
85
|
"LICENSE"
|
|
84
86
|
],
|
|
85
87
|
"dependencies": {
|
|
86
|
-
"@graphorin/core": "0.
|
|
87
|
-
"@graphorin/observability": "0.
|
|
88
|
-
"@graphorin/security": "0.
|
|
89
|
-
"@graphorin/tools": "0.
|
|
88
|
+
"@graphorin/core": "0.7.0",
|
|
89
|
+
"@graphorin/observability": "0.7.0",
|
|
90
|
+
"@graphorin/security": "0.7.0",
|
|
91
|
+
"@graphorin/tools": "0.7.0"
|
|
90
92
|
},
|
|
91
93
|
"peerDependencies": {
|
|
92
94
|
"zod": "^3.23.0 || ^4.0.0"
|
|
@@ -105,9 +107,8 @@
|
|
|
105
107
|
"better-sqlite3": "^12.9.0",
|
|
106
108
|
"fast-check": "^3.23.0",
|
|
107
109
|
"zod": "^3.25.0",
|
|
108
|
-
"@graphorin/store-sqlite": "0.
|
|
109
|
-
"@graphorin/
|
|
110
|
-
"@graphorin/triggers": "0.6.1"
|
|
110
|
+
"@graphorin/store-sqlite": "0.7.0",
|
|
111
|
+
"@graphorin/triggers": "0.7.0"
|
|
111
112
|
},
|
|
112
113
|
"scripts": {
|
|
113
114
|
"build": "tsdown",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the multi-stage conflict resolution pipeline
|
|
3
|
+
* shipped in `@graphorin/memory` Phase 10b (DEC-117 / ADR-018 ext /
|
|
4
|
+
* RB-02).
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export * from './locale-packs/index.js';
|
|
10
|
+
export {
|
|
11
|
+
_resetBypassWarningForTesting,
|
|
12
|
+
createConflictPipeline,
|
|
13
|
+
runConflictPipeline,
|
|
14
|
+
} from './pipeline.js';
|
|
15
|
+
export {
|
|
16
|
+
type ConflictDecision,
|
|
17
|
+
type ConflictPipeline,
|
|
18
|
+
type ConflictPipelineDeps,
|
|
19
|
+
type ConflictPipelineOptions,
|
|
20
|
+
type ConflictStage,
|
|
21
|
+
type ConflictThresholds,
|
|
22
|
+
DEFAULT_CONFLICT_THRESHOLDS,
|
|
23
|
+
type PipelineStage,
|
|
24
|
+
type ReconcileAction,
|
|
25
|
+
type ReconcileDecision,
|
|
26
|
+
reconcileToConflictDecision,
|
|
27
|
+
type StageContext,
|
|
28
|
+
type StageOutcome,
|
|
29
|
+
} from './types.js';
|