@graphorin/memory 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -1
- package/README.md +31 -31
- package/dist/conflict/index.d.ts +3 -1
- package/dist/conflict/index.js +1 -1
- package/dist/conflict/locale-packs/en.d.ts +13 -0
- package/dist/conflict/locale-packs/en.d.ts.map +1 -0
- package/dist/conflict/locale-packs/en.js +1 -1
- package/dist/conflict/locale-packs/en.js.map +1 -1
- package/dist/conflict/pipeline.d.ts +2 -2
- package/dist/conflict/pipeline.js +3 -3
- package/dist/conflict/pipeline.js.map +1 -1
- package/dist/conflict/stages/helpers.js +1 -1
- package/dist/conflict/stages/helpers.js.map +1 -1
- package/dist/conflict/stages/stage1-exact-dedup.js.map +1 -1
- package/dist/conflict/stages/stage2-embedding-three-zone.js.map +1 -1
- package/dist/conflict/stages/stage3-heuristic-regex.js +1 -1
- package/dist/conflict/stages/stage3-heuristic-regex.js.map +1 -1
- package/dist/conflict/stages/stage4-subject-predicate.js.map +1 -1
- package/dist/conflict/stages/stage5-defer-to-deep.js.map +1 -1
- package/dist/conflict/types.d.ts +7 -7
- package/dist/conflict/types.js +1 -1
- package/dist/conflict/types.js.map +1 -1
- package/dist/consolidator/budget.js +16 -3
- package/dist/consolidator/budget.js.map +1 -1
- package/dist/consolidator/decay.d.ts +13 -2
- package/dist/consolidator/decay.js +17 -5
- package/dist/consolidator/decay.js.map +1 -1
- package/dist/consolidator/dlq.js +1 -1
- package/dist/consolidator/dlq.js.map +1 -1
- package/dist/consolidator/errors.js +2 -2
- package/dist/consolidator/errors.js.map +1 -1
- package/dist/consolidator/index.js +8 -6
- package/dist/consolidator/index.js.map +1 -1
- package/dist/consolidator/lock.js +1 -1
- package/dist/consolidator/lock.js.map +1 -1
- package/dist/consolidator/noise-filter.js.map +1 -1
- package/dist/consolidator/phases/deep.js +6 -2
- package/dist/consolidator/phases/deep.js.map +1 -1
- package/dist/consolidator/phases/induce.d.ts +10 -10
- package/dist/consolidator/phases/induce.js +6 -6
- package/dist/consolidator/phases/induce.js.map +1 -1
- package/dist/consolidator/phases/learned-context.js +129 -0
- package/dist/consolidator/phases/learned-context.js.map +1 -0
- package/dist/consolidator/phases/light.js +2 -1
- package/dist/consolidator/phases/light.js.map +1 -1
- package/dist/consolidator/phases/reflect.js +5 -4
- package/dist/consolidator/phases/reflect.js.map +1 -1
- package/dist/consolidator/phases/standard.js +37 -8
- package/dist/consolidator/phases/standard.js.map +1 -1
- package/dist/consolidator/reconcile.js +1 -1
- package/dist/consolidator/reconcile.js.map +1 -1
- package/dist/consolidator/runtime.d.ts +4 -4
- package/dist/consolidator/runtime.d.ts.map +1 -1
- package/dist/consolidator/runtime.js +73 -16
- package/dist/consolidator/runtime.js.map +1 -1
- package/dist/consolidator/scheduler.d.ts +5 -5
- package/dist/consolidator/scheduler.js +1 -1
- package/dist/consolidator/scheduler.js.map +1 -1
- package/dist/consolidator/triggers.js +7 -7
- package/dist/consolidator/triggers.js.map +1 -1
- package/dist/consolidator/types.d.ts +68 -20
- package/dist/consolidator/types.d.ts.map +1 -1
- package/dist/consolidator/types.js +16 -6
- package/dist/consolidator/types.js.map +1 -1
- package/dist/context-engine/annotations.d.ts +9 -9
- package/dist/context-engine/annotations.js +3 -3
- package/dist/context-engine/annotations.js.map +1 -1
- package/dist/context-engine/auto-recall.js.map +1 -1
- package/dist/context-engine/compaction/clear-tool-results.d.ts +18 -3
- package/dist/context-engine/compaction/clear-tool-results.d.ts.map +1 -1
- package/dist/context-engine/compaction/clear-tool-results.js +26 -5
- package/dist/context-engine/compaction/clear-tool-results.js.map +1 -1
- package/dist/context-engine/compaction/compactor.js +19 -6
- package/dist/context-engine/compaction/compactor.js.map +1 -1
- package/dist/context-engine/compaction/hooks/reanchor-persona-block.js +4 -0
- package/dist/context-engine/compaction/hooks/reanchor-persona-block.js.map +1 -1
- package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js.map +1 -1
- package/dist/context-engine/compaction/hooks/reanchor-project-rules.js +2 -1
- package/dist/context-engine/compaction/hooks/reanchor-project-rules.js.map +1 -1
- package/dist/context-engine/compaction/hooks/reanchor-recent-results.d.ts +28 -0
- package/dist/context-engine/compaction/hooks/reanchor-recent-results.d.ts.map +1 -0
- package/dist/context-engine/compaction/hooks/reanchor-recent-results.js +71 -0
- package/dist/context-engine/compaction/hooks/reanchor-recent-results.js.map +1 -0
- package/dist/context-engine/compaction/hooks/types.d.ts +15 -3
- package/dist/context-engine/compaction/hooks/types.d.ts.map +1 -1
- package/dist/context-engine/compaction/index.d.ts +1 -0
- package/dist/context-engine/compaction/index.js +2 -1
- package/dist/context-engine/compaction/templates/summary-9-section.d.ts +10 -3
- package/dist/context-engine/compaction/templates/summary-9-section.d.ts.map +1 -1
- package/dist/context-engine/compaction/templates/summary-9-section.js +42 -5
- package/dist/context-engine/compaction/templates/summary-9-section.js.map +1 -1
- package/dist/context-engine/compaction/thresholds.js.map +1 -1
- package/dist/context-engine/compaction/types.d.ts +47 -7
- package/dist/context-engine/compaction/types.d.ts.map +1 -1
- package/dist/context-engine/engine.d.ts +23 -4
- package/dist/context-engine/engine.d.ts.map +1 -1
- package/dist/context-engine/engine.js +69 -15
- package/dist/context-engine/engine.js.map +1 -1
- package/dist/context-engine/index.d.ts +1 -0
- package/dist/context-engine/index.d.ts.map +1 -1
- package/dist/context-engine/index.js +2 -1
- package/dist/context-engine/locale-packs/en.js +14 -13
- package/dist/context-engine/locale-packs/en.js.map +1 -1
- package/dist/context-engine/locale-packs/types.d.ts +10 -10
- package/dist/context-engine/locale-packs/types.d.ts.map +1 -1
- package/dist/context-engine/locale-packs/types.js.map +1 -1
- package/dist/context-engine/metadata.d.ts +1 -1
- package/dist/context-engine/metadata.js +2 -2
- package/dist/context-engine/metadata.js.map +1 -1
- package/dist/context-engine/preambles/inbound-en.d.ts +1 -1
- package/dist/context-engine/preambles/inbound-en.js +1 -1
- package/dist/context-engine/preambles/inbound-en.js.map +1 -1
- package/dist/context-engine/privacy-filter.d.ts +2 -2
- package/dist/context-engine/privacy-filter.js +1 -1
- package/dist/context-engine/privacy-filter.js.map +1 -1
- package/dist/context-engine/templates/base-en.d.ts +1 -1
- package/dist/context-engine/templates/base-en.js +1 -1
- package/dist/context-engine/templates/base-en.js.map +1 -1
- package/dist/context-engine/templates/composer.d.ts +1 -1
- package/dist/context-engine/templates/composer.js.map +1 -1
- package/dist/context-engine/token-budget.d.ts +1 -1
- package/dist/context-engine/token-budget.js +1 -1
- package/dist/context-engine/token-budget.js.map +1 -1
- package/dist/context-engine/token-counter.d.ts +16 -7
- package/dist/context-engine/token-counter.d.ts.map +1 -1
- package/dist/context-engine/token-counter.js +31 -9
- package/dist/context-engine/token-counter.js.map +1 -1
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +4 -4
- package/dist/errors/index.js.map +1 -1
- package/dist/facade.d.ts +44 -15
- package/dist/facade.d.ts.map +1 -1
- package/dist/facade.js +16 -8
- package/dist/facade.js.map +1 -1
- package/dist/graph/entity-resolver.d.ts +2 -2
- package/dist/graph/entity-resolver.js +2 -2
- package/dist/graph/entity-resolver.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/contextualize.js +2 -2
- package/dist/internal/contextualize.js.map +1 -1
- package/dist/internal/embedder-binding.js +1 -1
- package/dist/internal/embedder-binding.js.map +1 -1
- package/dist/internal/id.js +1 -1
- package/dist/internal/id.js.map +1 -1
- package/dist/internal/injection-heuristics.js +25 -2
- package/dist/internal/injection-heuristics.js.map +1 -1
- package/dist/internal/spans.js +1 -1
- package/dist/internal/spans.js.map +1 -1
- package/dist/internal/storage-adapter.d.ts +71 -22
- package/dist/internal/storage-adapter.d.ts.map +1 -1
- package/dist/migration/embedder-migration.d.ts +7 -7
- package/dist/migration/embedder-migration.js.map +1 -1
- package/dist/search/explain.d.ts +7 -4
- package/dist/search/explain.d.ts.map +1 -1
- package/dist/search/explain.js +1 -1
- package/dist/search/explain.js.map +1 -1
- package/dist/search/fit-weights.d.ts +48 -0
- package/dist/search/fit-weights.d.ts.map +1 -0
- package/dist/search/fit-weights.js +70 -0
- package/dist/search/fit-weights.js.map +1 -0
- package/dist/search/graph-ppr.d.ts +36 -0
- package/dist/search/graph-ppr.d.ts.map +1 -0
- package/dist/search/graph-ppr.js +38 -0
- package/dist/search/graph-ppr.js.map +1 -0
- package/dist/search/index.d.ts +4 -1
- package/dist/search/index.js +4 -1
- package/dist/search/iterative.d.ts +15 -8
- package/dist/search/iterative.d.ts.map +1 -1
- package/dist/search/iterative.js +10 -9
- package/dist/search/iterative.js.map +1 -1
- package/dist/search/query-transform.d.ts +6 -6
- package/dist/search/query-transform.js +6 -6
- package/dist/search/query-transform.js.map +1 -1
- package/dist/search/rrf.d.ts +4 -4
- package/dist/search/rrf.js +4 -4
- package/dist/search/rrf.js.map +1 -1
- package/dist/search/trust.d.ts +30 -0
- package/dist/search/trust.d.ts.map +1 -0
- package/dist/search/trust.js +50 -0
- package/dist/search/trust.js.map +1 -0
- package/dist/search/types.d.ts +1 -1
- package/dist/tiers/episodic-memory.d.ts +6 -4
- package/dist/tiers/episodic-memory.d.ts.map +1 -1
- package/dist/tiers/episodic-memory.js +3 -2
- package/dist/tiers/episodic-memory.js.map +1 -1
- package/dist/tiers/index.d.ts +1 -1
- package/dist/tiers/index.js +1 -1
- package/dist/tiers/insight-memory.d.ts +4 -4
- package/dist/tiers/insight-memory.js +3 -3
- package/dist/tiers/insight-memory.js.map +1 -1
- package/dist/tiers/procedural-memory.d.ts +29 -7
- package/dist/tiers/procedural-memory.d.ts.map +1 -1
- package/dist/tiers/procedural-memory.js +66 -6
- package/dist/tiers/procedural-memory.js.map +1 -1
- package/dist/tiers/semantic-memory.d.ts +111 -30
- package/dist/tiers/semantic-memory.d.ts.map +1 -1
- package/dist/tiers/semantic-memory.js +120 -27
- package/dist/tiers/semantic-memory.js.map +1 -1
- package/dist/tiers/session-memory.d.ts +7 -7
- package/dist/tiers/session-memory.js +7 -7
- package/dist/tiers/session-memory.js.map +1 -1
- package/dist/tiers/shared-memory.d.ts +1 -1
- package/dist/tiers/shared-memory.js +1 -1
- package/dist/tiers/shared-memory.js.map +1 -1
- package/dist/tiers/working-memory.d.ts +3 -3
- package/dist/tiers/working-memory.js +2 -2
- package/dist/tiers/working-memory.js.map +1 -1
- package/dist/tools/block-tools.d.ts +9 -9
- package/dist/tools/block-tools.d.ts.map +1 -1
- package/dist/tools/block-tools.js +3 -3
- package/dist/tools/block-tools.js.map +1 -1
- package/dist/tools/fact-tools.d.ts +48 -31
- package/dist/tools/fact-tools.d.ts.map +1 -1
- package/dist/tools/fact-tools.js +30 -18
- package/dist/tools/fact-tools.js.map +1 -1
- package/dist/tools/index.d.ts +9 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/recall-tools.d.ts +40 -20
- package/dist/tools/recall-tools.d.ts.map +1 -1
- package/dist/tools/recall-tools.js +29 -10
- package/dist/tools/recall-tools.js.map +1 -1
- package/dist/tools/runbook-tools.d.ts +76 -0
- package/dist/tools/runbook-tools.d.ts.map +1 -0
- package/dist/tools/runbook-tools.js +53 -0
- package/dist/tools/runbook-tools.js.map +1 -0
- package/dist/tools/taint.js +33 -0
- package/dist/tools/taint.js.map +1 -0
- package/dist/tools/types.d.ts +1 -1
- package/package.json +8 -8
|
@@ -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 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 }),\n ),\n sufficient: z.boolean(),\n abstained: 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 return {\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 },\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 signal: ctx.signal,\n });\n return {\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 })),\n sufficient: result.sufficient,\n abstained: result.abstained,\n iterations: result.iterations,\n };\n },\n });\n}\n"],"mappings":";;;;AAKA,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,CACH,EACF,CAAC;AAKF,MAAM,gCAAgC,EAAE,OAAO;CAC7C,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CAClC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU;CACrD,CAAC;AACF,MAAM,iCAAiC,EAAE,OAAO,EAC9C,SAAS,EAAE,MACT,EAAE,OAAO;CACP,WAAW,EAAE,QAAQ;CACrB,OAAO,EAAE,QAAQ;CAClB,CAAC,CACH,EACF,CAAC;AAKF,MAAM,4BAA4B,EAAE,KAAK;CAAC;CAAU;CAAY;CAAS,CAAC;AAC1E,MAAM,wBAAwB,EAAE,OAAO;CACrC,OAAO,EAAE,QAA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MAAM,SAAS,SAAY,EAAE,MAAM,MAAM,MAAM,GAAG,EAAE;IACxD,QAAQ,IAAI;IACb,CAAC;AACF,UAAO;IACL,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;KACrF,EAAE;IACH,YAAY,OAAO;IACnB,WAAW,OAAO;IAClB,YAAY,OAAO;IACpB;;EAEJ,CAAC"}
|
|
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,CACH,EACF,CAAC;AAKF,MAAM,gCAAgC,EAAE,OAAO;CAC7C,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK;CAClC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU;CACrD,CAAC;AACF,MAAM,iCAAiC,EAAE,OAAO,EAC9C,SAAS,EAAE,MACT,EAAE,OAAO;CACP,WAAW,EAAE,QAAQ;CACrB,OAAO,EAAE,QAAQ;CAClB,CAAC,CACH,EACF,CAAC;AAKF,MAAM,4BAA4B,EAAE,KAAK;CAAC;C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ACjB,MAAM,CAAC,UAAU,WAAW;EAC5B,MAAM,QAAQ,OAAO,KAAK;GACxB,MAAM,QAAQ,MAAM,KAAK,aAAa,IAAI;GAC1C,MAAM,SAAS,MAAM,KAAK,SAAS,gBAAgB,OAAO,MAAM,OAAO;IACrE,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,MAAM,MAAM,GAAG,EAAE;IACxD,GAAI,MAAM,kBAAkB,SAAY,EAAE,eAAe,MAAM,eAAe,GAAG,EAAE;IACnF,GAAI,MAAM,SAAS,SAAY,EAAE,MAAM,MAAM,MAAM,GAAG,EAAE;IAMxD,WAAW;IACX,QAAQ,IAAI;IACb,CAAC;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;IAAE;IAAQ;IAAO;;EAE1D,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { MemoryToolDeps } from "./types.js";
|
|
2
|
+
import { Tool } from "@graphorin/core";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/tools/runbook-tools.d.ts
|
|
6
|
+
|
|
7
|
+
declare const runbookSearchInputSchema: z.ZodObject<{
|
|
8
|
+
query: z.ZodString;
|
|
9
|
+
topK: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
query: string;
|
|
12
|
+
topK?: number | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
query: string;
|
|
15
|
+
topK?: number | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
declare const runbookSearchOutputSchema: z.ZodObject<{
|
|
18
|
+
procedures: z.ZodArray<z.ZodObject<{
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
text: z.ZodString;
|
|
21
|
+
steps: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
22
|
+
variables: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
23
|
+
successCriteria: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
24
|
+
priority: z.ZodNumber;
|
|
25
|
+
score: z.ZodNumber;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
text: string;
|
|
28
|
+
score: number;
|
|
29
|
+
id: string;
|
|
30
|
+
priority: number;
|
|
31
|
+
steps?: string[] | undefined;
|
|
32
|
+
variables?: string[] | undefined;
|
|
33
|
+
successCriteria?: string[] | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
text: string;
|
|
36
|
+
score: number;
|
|
37
|
+
id: string;
|
|
38
|
+
priority: number;
|
|
39
|
+
steps?: string[] | undefined;
|
|
40
|
+
variables?: string[] | undefined;
|
|
41
|
+
successCriteria?: string[] | undefined;
|
|
42
|
+
}>, "many">;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
procedures: {
|
|
45
|
+
text: string;
|
|
46
|
+
score: number;
|
|
47
|
+
id: string;
|
|
48
|
+
priority: number;
|
|
49
|
+
steps?: string[] | undefined;
|
|
50
|
+
variables?: string[] | undefined;
|
|
51
|
+
successCriteria?: string[] | undefined;
|
|
52
|
+
}[];
|
|
53
|
+
}, {
|
|
54
|
+
procedures: {
|
|
55
|
+
text: string;
|
|
56
|
+
score: number;
|
|
57
|
+
id: string;
|
|
58
|
+
priority: 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>;
|
|
66
|
+
/**
|
|
67
|
+
* `runbook_search` - find validated procedures matching a task
|
|
68
|
+
* description. Quarantined (unvalidated induced) procedures never
|
|
69
|
+
* surface here: they must not drive actions until validated.
|
|
70
|
+
*
|
|
71
|
+
* @stable
|
|
72
|
+
*/
|
|
73
|
+
declare function createRunbookSearchTool(deps: MemoryToolDeps): Tool<RunbookSearchInput, RunbookSearchOutput>;
|
|
74
|
+
//#endregion
|
|
75
|
+
export { createRunbookSearchTool };
|
|
76
|
+
//# sourceMappingURL=runbook-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runbook-tools.d.ts","names":[],"sources":["../../src/tools/runbook-tools.ts"],"sourcesContent":[],"mappings":";;;;;;cAiBM,0BAAwB,CAAA,CAAA;;;;;;;;;;cAIxB,2BAAyB,CAAA,CAAA;;;;;;IAAA,eAAA,eAAA,WAAA,YAAA,EAAA,MAAA,CAAA,CAAA;IAAA,QAAA,aAAA;IAc1B,KAAA,aAAkB;EAClB,CAAA,EAAA,OAAA,cAAmB,EAAA;IASR,IAAA,EAAA,MAAA;IACR,KAAA,EAAA,MAAA;IACA,EAAA,EAAA,MAAA;IAAoB,QAAA,EAAA,MAAA;IAAzB,KAAA,CAAA,EAAA,MAAA,EAAA,GAAA,SAAA;IAAI,SAAA,CAAA,EAAA,MAAA,EAAA,GAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAZF,kBAAA,GAAqB,CAAA,CAAE,aAAa;KACpC,mBAAA,GAAsB,CAAA,CAAE,aAAa;;;;;;;;iBAS1B,uBAAA,OACR,iBACL,KAAK,oBAAoB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { tool } from "@graphorin/tools";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/tools/runbook-tools.ts
|
|
5
|
+
const runbookSearchInputSchema = z.object({
|
|
6
|
+
query: z.string().min(1).max(512),
|
|
7
|
+
topK: z.number().int().min(1).max(20).optional()
|
|
8
|
+
});
|
|
9
|
+
const runbookSearchOutputSchema = z.object({ procedures: z.array(z.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
text: z.string(),
|
|
12
|
+
steps: z.array(z.string()).optional(),
|
|
13
|
+
variables: z.array(z.string()).optional(),
|
|
14
|
+
successCriteria: z.array(z.string()).optional(),
|
|
15
|
+
priority: z.number(),
|
|
16
|
+
score: z.number()
|
|
17
|
+
})) });
|
|
18
|
+
/**
|
|
19
|
+
* `runbook_search` - find validated procedures matching a task
|
|
20
|
+
* description. Quarantined (unvalidated induced) procedures never
|
|
21
|
+
* surface here: they must not drive actions until validated.
|
|
22
|
+
*
|
|
23
|
+
* @stable
|
|
24
|
+
*/
|
|
25
|
+
function createRunbookSearchTool(deps) {
|
|
26
|
+
return tool({
|
|
27
|
+
name: "runbook_search",
|
|
28
|
+
description: "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.",
|
|
29
|
+
inputSchema: runbookSearchInputSchema,
|
|
30
|
+
outputSchema: runbookSearchOutputSchema,
|
|
31
|
+
sideEffectClass: "read-only",
|
|
32
|
+
sandboxPolicy: "none",
|
|
33
|
+
sensitivity: "internal",
|
|
34
|
+
memoryGuardTier: "pure",
|
|
35
|
+
tags: ["memory", "procedural"],
|
|
36
|
+
async execute(input, ctx) {
|
|
37
|
+
const scope = await deps.resolveScope(ctx);
|
|
38
|
+
return { procedures: (await deps.procedural.search(scope, input.query, { ...input.topK !== void 0 ? { topK: input.topK } : {} })).map((hit) => ({
|
|
39
|
+
id: hit.record.id,
|
|
40
|
+
text: hit.record.text,
|
|
41
|
+
...hit.record.steps !== void 0 ? { steps: [...hit.record.steps] } : {},
|
|
42
|
+
...hit.record.variables !== void 0 ? { variables: [...hit.record.variables] } : {},
|
|
43
|
+
...hit.record.successCriteria !== void 0 ? { successCriteria: [...hit.record.successCriteria] } : {},
|
|
44
|
+
priority: hit.record.priority,
|
|
45
|
+
score: hit.score
|
|
46
|
+
})) };
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { createRunbookSearchTool };
|
|
53
|
+
//# sourceMappingURL=runbook-tools.js.map
|
|
@@ -0,0 +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\ntype RunbookSearchInput = z.infer<typeof runbookSearchInputSchema>;\ntype RunbookSearchOutput = z.infer<typeof runbookSearchOutputSchema>;\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,Q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|
+
/**
|
|
5
|
+
* C6: taint override for memory-recall tool results. The recall tools are
|
|
6
|
+
* first-party (`sideEffectClass: 'read-only'`), so the data-flow ledger
|
|
7
|
+
* would derive their outputs as trusted - but the CONTENT they return can
|
|
8
|
+
* be quarantined or foreign-provenance memory written in an earlier
|
|
9
|
+
* session (the cross-session poisoning leg). This helper computes the
|
|
10
|
+
* `ToolReturn.taint` override that re-arms the ledger at recall: recalled
|
|
11
|
+
* poisoned content is recorded as untrusted spans, so the verbatim probe
|
|
12
|
+
* and the trifecta/derived gates see it exactly like fresh untrusted
|
|
13
|
+
* input.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Compute the taint override for a recalled item set: untrusted when ANY
|
|
19
|
+
* item is quarantined or foreign-provenance; `undefined` when all items
|
|
20
|
+
* are first-party active (the common case - zero overhead, no override).
|
|
21
|
+
*
|
|
22
|
+
* @stable
|
|
23
|
+
*/
|
|
24
|
+
function recallTaint(items) {
|
|
25
|
+
for (const item of items) if (item.status === "quarantined" || isForeignProvenance(item.provenance)) return {
|
|
26
|
+
untrusted: true,
|
|
27
|
+
sourceKind: "memory-recall"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { recallTaint };
|
|
33
|
+
//# sourceMappingURL=taint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taint.js","names":[],"sources":["../../src/tools/taint.ts"],"sourcesContent":["/**\n * C6: taint override for memory-recall tool results. The recall tools are\n * first-party (`sideEffectClass: 'read-only'`), so the data-flow ledger\n * would derive their outputs as trusted - but the CONTENT they return can\n * be quarantined or foreign-provenance memory written in an earlier\n * session (the cross-session poisoning leg). This helper computes the\n * `ToolReturn.taint` override that re-arms the ledger at recall: recalled\n * poisoned content is recorded as untrusted spans, so the verbatim probe\n * and the trifecta/derived gates see it exactly like fresh untrusted\n * input.\n *\n * @packageDocumentation\n */\n\nimport { isForeignProvenance } from '../search/trust.js';\n\n/** Minimal record surface the helper inspects. */\nexport interface RecalledItemLike {\n readonly provenance?: string | null;\n readonly status?: string;\n}\n\n/**\n * Compute the taint override for a recalled item set: untrusted when ANY\n * item is quarantined or foreign-provenance; `undefined` when all items\n * are first-party active (the common case - zero overhead, no override).\n *\n * @stable\n */\nexport function recallTaint(\n items: ReadonlyArray<RecalledItemLike>,\n): { readonly untrusted: true; readonly sourceKind: 'memory-recall' } | undefined {\n for (const item of items) {\n if (item.status === 'quarantined' || isForeignProvenance(item.provenance)) {\n return { untrusted: true, sourceKind: 'memory-recall' };\n }\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,YACd,OACgF;AAChF,MAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,WAAW,iBAAiB,oBAAoB,KAAK,WAAW,CACvE,QAAO;EAAE,WAAW;EAAM,YAAY;EAAiB"}
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EpisodicMemory } from "../tiers/episodic-memory.js";
|
|
2
2
|
import { SemanticMemory } from "../tiers/semantic-memory.js";
|
|
3
|
+
import { WorkingMemory } from "../tiers/working-memory.js";
|
|
3
4
|
import { ProceduralMemory } from "../tiers/procedural-memory.js";
|
|
4
5
|
import { SessionMemory } from "../tiers/session-memory.js";
|
|
5
6
|
import { SharedMemory } from "../tiers/shared-memory.js";
|
|
6
|
-
import { WorkingMemory } from "../tiers/working-memory.js";
|
|
7
7
|
import * as _graphorin_core0 from "@graphorin/core";
|
|
8
8
|
import { SessionScope } from "@graphorin/core";
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphorin/memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"LICENSE"
|
|
84
84
|
],
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@graphorin/core": "0.
|
|
87
|
-
"@graphorin/observability": "0.
|
|
88
|
-
"@graphorin/security": "0.
|
|
89
|
-
"@graphorin/tools": "0.
|
|
86
|
+
"@graphorin/core": "0.6.0",
|
|
87
|
+
"@graphorin/observability": "0.6.0",
|
|
88
|
+
"@graphorin/security": "0.6.0",
|
|
89
|
+
"@graphorin/tools": "0.6.0"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"zod": "^3.23.0 || ^4.0.0"
|
|
@@ -105,9 +105,9 @@
|
|
|
105
105
|
"better-sqlite3": "^12.9.0",
|
|
106
106
|
"fast-check": "^3.23.0",
|
|
107
107
|
"zod": "^3.25.0",
|
|
108
|
-
"@graphorin/store-sqlite": "0.
|
|
109
|
-
"@graphorin/embedder-transformersjs": "0.
|
|
110
|
-
"@graphorin/triggers": "0.
|
|
108
|
+
"@graphorin/store-sqlite": "0.6.0",
|
|
109
|
+
"@graphorin/embedder-transformersjs": "0.6.0",
|
|
110
|
+
"@graphorin/triggers": "0.6.0"
|
|
111
111
|
},
|
|
112
112
|
"scripts": {
|
|
113
113
|
"build": "tsdown",
|