@jungjaehoon/mama-core 2.4.1 → 4.1.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/README.md +76 -239
- package/db/migrations/030-case-first-memory-substrate.sql +13 -98
- package/db/migrations/034-add-connector-event-scope-columns.sql +9 -13
- package/db/migrations/039-add-connector-event-operator-ingest-seq.sql +9 -95
- package/db/migrations/062-refresh-connector-event-sequences.sql +9 -113
- package/db/migrations/063-refresh-legacy-connector-event-updates.sql +9 -32
- package/db/migrations/067-add-connector-event-source-entity-id.sql +9 -13
- package/db/migrations/069-create-registry-nodes.sql +52 -0
- package/db/migrations/070-record-identity.sql +35 -0
- package/db/migrations/071-service-operation-origins.sql +187 -0
- package/db/migrations/072-observation-versions.sql +29 -0
- package/db/migrations/073-registry-corrections.sql +45 -0
- package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
- package/db/migrations/075-agent-judgments.sql +58 -0
- package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
- package/db/migrations/077-legacy-record-kind.sql +6 -0
- package/db/migrations/078-source-ingest-commands.sql +18 -0
- package/db/migrations/079-twin-edge-relations.sql +43 -0
- package/db/migrations/080-restore-duration-days.sql +7 -0
- package/db/migrations/081-mailbox.sql +61 -0
- package/db/migrations/082-commitments-row-id.sql +12 -0
- package/db/migrations/083-observation-is-the-evidence.sql +49 -0
- package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
- package/db/migrations/085-a-migration-has-a-source.sql +37 -0
- package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
- package/db/migrations/087-mailbox-payload.sql +5 -0
- package/db/migrations/088-native-input-journal.sql +14 -0
- package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
- package/db/migrations/090-model-run-native-inputs.sql +29 -0
- package/db/migrations/091-native-turn-results.sql +11 -0
- package/db/migrations/092-restore-decision-fts.sql +34 -0
- package/db/migrations/093-native-turn-primary-kind.sql +14 -0
- package/db/migrations/094-commitment-run-provenance.sql +9 -0
- package/db/migrations/095-model-run-native-input-identity.sql +39 -0
- package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
- package/db/migrations/097-native-input-json-validity.sql +37 -0
- package/db/migrations/098-workflow-memory-kind.sql +105 -0
- package/db/migrations/099-commitment-revision-graph.sql +2 -0
- package/dist/action-contracts.d.ts +212 -0
- package/dist/action-contracts.js +10 -0
- package/dist/api/catalog.d.ts +118 -0
- package/dist/api/catalog.js +1756 -0
- package/dist/api/dispatch.d.ts +76 -0
- package/dist/api/dispatch.js +372 -0
- package/dist/canonicalize.d.ts +2 -2
- package/dist/canonicalize.js +3 -3
- package/dist/client/client.d.ts +33 -0
- package/dist/client/client.js +123 -0
- package/dist/client/ipc.d.ts +81 -0
- package/dist/client/ipc.js +314 -0
- package/dist/db-adapter/base-adapter.d.ts +6 -66
- package/dist/db-adapter/base-adapter.js +6 -6
- package/dist/db-adapter/index.d.ts +5 -5
- package/dist/db-adapter/index.js +2 -5
- package/dist/db-adapter/node-sqlite-adapter.d.ts +85 -15
- package/dist/db-adapter/node-sqlite-adapter.js +1985 -570
- package/dist/db-manager.d.ts +53 -97
- package/dist/db-manager.js +121 -603
- package/dist/embedding/embedder.d.ts +132 -0
- package/dist/embedding/embedder.js +299 -0
- package/dist/identity/principal-repository.d.ts +2 -2
- package/dist/index.d.ts +43 -58
- package/dist/index.js +97 -145
- package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
- package/dist/knowledge/access.js +663 -0
- package/dist/knowledge/case-errors.d.ts +31 -0
- package/dist/knowledge/case-errors.js +40 -0
- package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
- package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
- package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
- package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
- package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
- package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
- package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
- package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
- package/dist/knowledge/commitment-revision-migration.d.ts +4 -0
- package/dist/knowledge/commitment-revision-migration.js +50 -0
- package/dist/knowledge/commitments.d.ts +192 -0
- package/dist/knowledge/commitments.js +386 -0
- package/dist/knowledge/decision-edges.d.ts +70 -0
- package/dist/knowledge/decision-edges.js +123 -0
- package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
- package/dist/knowledge/graph-query.js +1585 -0
- package/dist/knowledge/identity.d.ts +16 -0
- package/dist/knowledge/identity.js +22 -0
- package/dist/knowledge/index.d.ts +47 -0
- package/dist/knowledge/index.js +90 -0
- package/dist/knowledge/judgment-edge.d.ts +6 -0
- package/dist/knowledge/judgment-edge.js +22 -0
- package/dist/knowledge/judgments.d.ts +118 -0
- package/dist/knowledge/judgments.js +802 -0
- package/dist/knowledge/observations.d.ts +160 -0
- package/dist/knowledge/observations.js +449 -0
- package/dist/knowledge/question-type.d.ts +34 -0
- package/dist/knowledge/question-type.js +70 -0
- package/dist/{search → knowledge}/ranker-features.js +1 -1
- package/dist/{search → knowledge}/search-quality.d.ts +0 -1
- package/dist/knowledge/search.d.ts +38 -0
- package/dist/knowledge/search.js +91 -0
- package/dist/knowledge/source-ingest.d.ts +65 -0
- package/dist/knowledge/source-ingest.js +174 -0
- package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
- package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
- package/dist/knowledge/work-dates.d.ts +49 -0
- package/dist/knowledge/work-dates.js +120 -0
- package/dist/mama-api.d.ts +114 -778
- package/dist/mama-api.js +313 -2461
- package/dist/memory/api.d.ts +264 -24
- package/dist/memory/api.js +1633 -843
- package/dist/memory/bootstrap-builder.d.ts +2 -1
- package/dist/memory/bootstrap-builder.js +5 -5
- package/dist/memory/channel-summary-state-store.d.ts +3 -2
- package/dist/memory/channel-summary-state-store.js +53 -51
- package/dist/memory/channel-summary-store.d.ts +5 -3
- package/dist/memory/channel-summary-store.js +3 -8
- package/dist/memory/dashboard-read.d.ts +46 -0
- package/dist/memory/dashboard-read.js +94 -0
- package/dist/memory/event-store.d.ts +3 -3
- package/dist/memory/event-store.js +3 -10
- package/dist/memory/finding-store.d.ts +3 -2
- package/dist/memory/finding-store.js +2 -7
- package/dist/memory/graph-read.d.ts +52 -0
- package/dist/memory/graph-read.js +130 -0
- package/dist/memory/judgment-types.d.ts +394 -0
- package/dist/memory/judgment-types.js +16 -0
- package/dist/memory/provenance-audit.d.ts +5 -2
- package/dist/memory/provenance-audit.js +8 -14
- package/dist/memory/provenance-live.d.ts +141 -0
- package/dist/memory/provenance-live.js +409 -0
- package/dist/memory/provenance-query.d.ts +5 -4
- package/dist/memory/provenance-query.js +21 -29
- package/dist/memory/provenance-resolver.d.ts +191 -0
- package/dist/memory/provenance-resolver.js +155 -0
- package/dist/memory/provenance.d.ts +1 -11
- package/dist/memory/provenance.js +2 -33
- package/dist/memory/recall-sanitize.d.ts +55 -0
- package/dist/memory/recall-sanitize.js +144 -0
- package/dist/memory/secret-filter.d.ts +32 -0
- package/dist/memory/secret-filter.js +126 -0
- package/dist/memory/truth-store.d.ts +2 -1
- package/dist/memory/truth-store.js +1 -4
- package/dist/memory/types.d.ts +74 -24
- package/dist/memory/types.js +75 -5
- package/dist/memory/write-adapters.d.ts +98 -0
- package/dist/memory/write-adapters.js +242 -0
- package/dist/operations/owner-action-effects.d.ts +53 -0
- package/dist/operations/owner-action-effects.js +96 -0
- package/dist/provenance/source-ref.d.ts +1 -1
- package/dist/provenance/source-ref.js +0 -2
- package/dist/registry/corrections.d.ts +31 -0
- package/dist/registry/corrections.js +332 -0
- package/dist/registry/record-identity.d.ts +49 -0
- package/dist/registry/record-identity.js +133 -0
- package/dist/registry/store.d.ts +101 -0
- package/dist/registry/store.js +395 -0
- package/dist/registry/types.d.ts +28 -0
- package/dist/registry/types.js +5 -0
- package/dist/relevance-scorer.js +2 -2
- package/dist/runtime/agent-event-bus.d.ts +50 -0
- package/dist/runtime/agent-event-bus.js +101 -0
- package/dist/runtime/drivers/claude-cli-wrapper.d.ts +152 -0
- package/dist/runtime/drivers/claude-cli-wrapper.js +375 -0
- package/dist/runtime/drivers/claude-effort.d.ts +4 -0
- package/dist/runtime/drivers/claude-effort.js +16 -0
- package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
- package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
- package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
- package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
- package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
- package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
- package/dist/runtime/drivers/codex-home.d.ts +20 -0
- package/dist/runtime/drivers/codex-home.js +674 -0
- package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
- package/dist/runtime/drivers/codex-thread-registry.js +433 -0
- package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
- package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
- package/dist/runtime/drivers/persistent-cli-process.d.ts +425 -0
- package/dist/runtime/drivers/persistent-cli-process.js +1529 -0
- package/dist/runtime/drivers/types.d.ts +456 -0
- package/dist/runtime/drivers/types.js +110 -0
- package/dist/runtime/mailbox.d.ts +223 -0
- package/dist/runtime/mailbox.js +582 -0
- package/dist/runtime/model-run-store.d.ts +28 -0
- package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
- package/dist/{model-runs/types.d.ts → runtime/model-run-types.d.ts} +33 -4
- package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
- package/dist/runtime/native-effect-observer.d.ts +22 -0
- package/dist/runtime/native-effect-observer.js +103 -0
- package/dist/runtime/native-input-journal.d.ts +46 -0
- package/dist/runtime/native-input-journal.js +308 -0
- package/dist/runtime/native-prompt.d.ts +118 -0
- package/dist/runtime/native-prompt.js +496 -0
- package/dist/runtime/native-session.d.ts +10 -0
- package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
- package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
- package/dist/runtime/native-tool-trace-observer.js +65 -0
- package/dist/runtime/native-turn.d.ts +272 -0
- package/dist/runtime/native-turn.js +1041 -0
- package/dist/runtime/operations.d.ts +236 -0
- package/dist/runtime/operations.js +565 -0
- package/dist/runtime/post-tool-handler.d.ts +74 -0
- package/dist/runtime/post-tool-handler.js +137 -0
- package/dist/runtime/prompt-layers.d.ts +126 -0
- package/dist/runtime/prompt-layers.js +239 -0
- package/dist/runtime/runtime-process.d.ts +102 -0
- package/dist/runtime/runtime-process.js +206 -0
- package/dist/runtime/runtime.d.ts +278 -0
- package/dist/runtime/runtime.js +563 -0
- package/dist/runtime/session-pool.d.ts +176 -0
- package/dist/runtime/session-pool.js +369 -0
- package/dist/runtime/stimulus-payload.d.ts +5 -0
- package/dist/runtime/stimulus-payload.js +50 -0
- package/dist/runtime/subagent-bridge.d.ts +24 -0
- package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
- package/dist/runtime/text-completion.d.ts +22 -0
- package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
- package/dist/runtime/token-estimator.d.ts +25 -0
- package/dist/runtime/token-estimator.js +75 -0
- package/dist/runtime/tool-trace-store.d.ts +22 -0
- package/dist/{model-runs → runtime}/tool-trace-store.js +46 -27
- package/dist/runtime/trace-summary.d.ts +5 -0
- package/dist/runtime/trace-summary.js +74 -0
- package/dist/runtime/turn-text.d.ts +23 -0
- package/dist/runtime/turn-text.js +41 -0
- package/dist/storage/database.d.ts +67 -0
- package/dist/storage/database.js +158 -0
- package/package.json +20 -34
- package/dist/agent-graph/alias-write.d.ts +0 -3
- package/dist/agent-graph/alias-write.js +0 -234
- package/dist/agent-graph/entity-resolve.d.ts +0 -3
- package/dist/agent-graph/entity-resolve.js +0 -271
- package/dist/agent-graph/errors.d.ts +0 -4
- package/dist/agent-graph/errors.js +0 -11
- package/dist/agent-graph/graph-query.d.ts +0 -5
- package/dist/agent-graph/graph-query.js +0 -360
- package/dist/agent-graph/index.d.ts +0 -6
- package/dist/agent-situation/builder.d.ts +0 -8
- package/dist/agent-situation/builder.js +0 -239
- package/dist/agent-situation/cache-key.d.ts +0 -4
- package/dist/agent-situation/cache-key.js +0 -64
- package/dist/agent-situation/index.d.ts +0 -7
- package/dist/agent-situation/index.js +0 -28
- package/dist/agent-situation/packet-store.d.ts +0 -27
- package/dist/agent-situation/packet-store.js +0 -228
- package/dist/agent-situation/ranking-policy.d.ts +0 -18
- package/dist/agent-situation/ranking-policy.js +0 -75
- package/dist/agent-situation/source-readers.d.ts +0 -52
- package/dist/agent-situation/source-readers.js +0 -300
- package/dist/agent-situation/types.d.ts +0 -195
- package/dist/cases/wiki-page-index.d.ts +0 -37
- package/dist/cases/wiki-page-index.js +0 -201
- package/dist/config-loader.d.ts +0 -68
- package/dist/config-loader.js +0 -239
- package/dist/connectors/event-index.d.ts +0 -24
- package/dist/connectors/event-index.js +0 -245
- package/dist/connectors/raw-query.d.ts +0 -40
- package/dist/connectors/raw-query.js +0 -412
- package/dist/connectors/types.d.ts +0 -117
- package/dist/connectors/types.js +0 -3
- package/dist/context-compile/boundary-defaults.d.ts +0 -12
- package/dist/context-compile/boundary-defaults.js +0 -105
- package/dist/context-compile/channel-grant.js +0 -66
- package/dist/context-compile/compiler-policy.d.ts +0 -39
- package/dist/context-compile/compiler-policy.js +0 -147
- package/dist/context-compile/compiler.d.ts +0 -18
- package/dist/context-compile/compiler.js +0 -404
- package/dist/context-compile/index.d.ts +0 -10
- package/dist/context-compile/index.js +0 -26
- package/dist/context-compile/packet-store.d.ts +0 -8
- package/dist/context-compile/packet-store.js +0 -239
- package/dist/context-compile/ref.d.ts +0 -7
- package/dist/context-compile/ref.js +0 -102
- package/dist/context-compile/source-readers.d.ts +0 -70
- package/dist/context-compile/source-readers.js +0 -840
- package/dist/context-compile/types.d.ts +0 -155
- package/dist/context-compile/types.js +0 -11
- package/dist/context-compile/visibility.d.ts +0 -21
- package/dist/context-compile/visibility.js +0 -224
- package/dist/decision-tracker.d.ts +0 -206
- package/dist/decision-tracker.js +0 -481
- package/dist/edges/ref-validation.d.ts +0 -7
- package/dist/edges/ref-validation.js +0 -321
- package/dist/edges/store.d.ts +0 -8
- package/dist/edges/store.js +0 -129
- package/dist/embedding-client.d.ts +0 -28
- package/dist/embedding-client.js +0 -53
- package/dist/embedding-server/index.d.ts +0 -67
- package/dist/embedding-server/index.js +0 -405
- package/dist/embedding-server/mobile/auth.d.ts +0 -44
- package/dist/embedding-server/mobile/auth.js +0 -150
- package/dist/embedding-server/mobile/daemon.d.ts +0 -129
- package/dist/embedding-server/mobile/daemon.js +0 -313
- package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
- package/dist/embedding-server/mobile/output-parser.js +0 -241
- package/dist/embedding-server/mobile/session-api.d.ts +0 -57
- package/dist/embedding-server/mobile/session-api.js +0 -261
- package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
- package/dist/embedding-server/mobile/session-manager.js +0 -378
- package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
- package/dist/embedding-server/mobile/websocket-handler.js +0 -486
- package/dist/embeddings.d.ts +0 -68
- package/dist/embeddings.js +0 -244
- package/dist/entities/audit-metrics.d.ts +0 -68
- package/dist/entities/audit-metrics.js +0 -124
- package/dist/entities/candidate-generator.d.ts +0 -8
- package/dist/entities/candidate-generator.js +0 -24
- package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
- package/dist/entities/entity-linked-decision-counts.js +0 -29
- package/dist/entities/entity-list.d.ts +0 -22
- package/dist/entities/entity-list.js +0 -3
- package/dist/entities/entity-orphan-list.d.ts +0 -17
- package/dist/entities/entity-orphan-list.js +0 -3
- package/dist/entities/entity-search.d.ts +0 -20
- package/dist/entities/entity-search.js +0 -3
- package/dist/entities/errors.d.ts +0 -55
- package/dist/entities/errors.js +0 -100
- package/dist/entities/lineage-store.d.ts +0 -28
- package/dist/entities/lineage-store.js +0 -204
- package/dist/entities/normalization.d.ts +0 -14
- package/dist/entities/normalization.js +0 -63
- package/dist/entities/policy-store.d.ts +0 -8
- package/dist/entities/policy-store.js +0 -75
- package/dist/entities/policy-types.d.ts +0 -72
- package/dist/entities/policy-types.js +0 -59
- package/dist/entities/projection.d.ts +0 -8
- package/dist/entities/projection.js +0 -82
- package/dist/entities/provenance-query.d.ts +0 -32
- package/dist/entities/provenance-query.js +0 -3
- package/dist/entities/read-identity.d.ts +0 -31
- package/dist/entities/read-identity.js +0 -264
- package/dist/entities/recall-bridge.d.ts +0 -5
- package/dist/entities/recall-bridge.js +0 -171
- package/dist/entities/resolution-engine.d.ts +0 -8
- package/dist/entities/resolution-engine.js +0 -3
- package/dist/entities/rollback-preview.d.ts +0 -35
- package/dist/entities/rollback-preview.js +0 -3
- package/dist/entities/source-locator.d.ts +0 -3
- package/dist/entities/source-locator.js +0 -32
- package/dist/entities/store.d.ts +0 -69
- package/dist/entities/store.js +0 -544
- package/dist/entities/types.d.ts +0 -166
- package/dist/entities/types.js +0 -30
- package/dist/memory/extraction-prompt.d.ts +0 -4
- package/dist/memory/extraction-prompt.js +0 -89
- package/dist/memory/scope-backfill.d.ts +0 -14
- package/dist/memory/scope-backfill.js +0 -3
- package/dist/memory/scope-store.d.ts +0 -4
- package/dist/memory/scope-store.js +0 -9
- package/dist/memory-store.d.ts +0 -87
- package/dist/memory-store.js +0 -78
- package/dist/model-runs/store.d.ts +0 -13
- package/dist/model-runs/tool-trace-store.d.ts +0 -8
- package/dist/notification-manager.d.ts +0 -7
- package/dist/notification-manager.js +0 -12
- package/dist/outcome-tracker.d.ts +0 -151
- package/dist/outcome-tracker.js +0 -271
- package/dist/query-intent.d.ts +0 -23
- package/dist/query-intent.js +0 -114
- package/dist/runtime/trusted-provenance.d.ts +0 -3
- package/dist/runtime/trusted-provenance.js +0 -6
- package/dist/search/question-type.d.ts +0 -5
- package/dist/search/question-type.js +0 -41
- package/dist/test-utils.d.ts +0 -80
- package/dist/test-utils.js +0 -218
- package/dist/tier-validator.d.ts +0 -43
- package/dist/tier-validator.js +0 -159
- package/dist/time-formatter.d.ts +0 -25
- package/dist/time-formatter.js +0 -93
- /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
- /package/dist/{search → knowledge}/feedback-store.js +0 -0
- /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
- /package/dist/{search → knowledge}/search-quality.js +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a claim's support back to the events it came from.
|
|
3
|
+
*
|
|
4
|
+
* This is the capability the whole "traceable judgment" idea rests on, and until now it
|
|
5
|
+
* did not exist in any form the agent could reach. Memory records carried model run,
|
|
6
|
+
* envelope, gateway call and source refs; recall stripped every one of them, so an agent
|
|
7
|
+
* could read a memory and then had no way to say which memory a statement rested on. A
|
|
8
|
+
* handle was added upstream; this turns the handle into an answer.
|
|
9
|
+
*
|
|
10
|
+
* Two rules shape everything here.
|
|
11
|
+
*
|
|
12
|
+
* POSSESSION IS NOT AUTHORIZATION. Holding a memory id proves only that recall returned
|
|
13
|
+
* it once, under some scope, at some time. Every event is re-checked against the scope
|
|
14
|
+
* active NOW, and content is withheld when that check fails. A resolver that trusted the
|
|
15
|
+
* handle would turn recall into a capability leak: read once, cite forever.
|
|
16
|
+
*
|
|
17
|
+
* ABSENCE GETS A REASON. Silence is what made the original problem invisible - a report
|
|
18
|
+
* asserted things with nothing behind them and looked identical to one that was
|
|
19
|
+
* grounded. Every failure here names itself, so "I cannot support this" is a statement
|
|
20
|
+
* the agent can make instead of a gap it cannot see.
|
|
21
|
+
*/
|
|
22
|
+
/** Why a claim, or one of its supports, could not be resolved. */
|
|
23
|
+
export type ResolutionFailure =
|
|
24
|
+
/** The memory carries no source refs at all. */
|
|
25
|
+
'missing_ref'
|
|
26
|
+
/** Provenance exists but predates scoped writes - nothing to re-check against. */
|
|
27
|
+
| 'legacy_unscoped'
|
|
28
|
+
/** The referenced event is no longer in the index. */
|
|
29
|
+
| 'event_deleted'
|
|
30
|
+
/** The event exists but is not visible under the scope active now. */
|
|
31
|
+
| 'outside_scope'
|
|
32
|
+
/** The ref shape is not one this resolver knows how to dereference. */
|
|
33
|
+
| 'unsupported_ref'
|
|
34
|
+
/**
|
|
35
|
+
* The claim records provenance, but none of it points at an observed event.
|
|
36
|
+
* Measured, not hypothetical: of the source refs stored on this machine, 13,403 are
|
|
37
|
+
* `memory:`, 1,748 are `envelope:`, 9 are `message:` and ZERO are `raw:`. Folding this
|
|
38
|
+
* into `unsupported_ref` would have reported a parser limitation where the real answer
|
|
39
|
+
* is that the claim rests on other claims rather than on anything observed.
|
|
40
|
+
*/
|
|
41
|
+
| 'no_event_refs'
|
|
42
|
+
/** No memory with that id. */
|
|
43
|
+
| 'unknown_memory';
|
|
44
|
+
export interface ResolvedEvent {
|
|
45
|
+
connector: string;
|
|
46
|
+
eventIndexId: string;
|
|
47
|
+
sourceId: string;
|
|
48
|
+
channel: string | null;
|
|
49
|
+
observedAt: string | null;
|
|
50
|
+
/** Bounded excerpt. Never the whole record: this answers "where from", not "give me". */
|
|
51
|
+
excerpt: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One support that could not be dereferenced, and why.
|
|
55
|
+
*
|
|
56
|
+
* `kind` exists because the other two fields collapse three different situations into
|
|
57
|
+
* one shape: an unparseable ref, a withheld observation, and a withheld claim all render
|
|
58
|
+
* as roughly `{null, reason}`. "A supporting observation was withheld" and "a supporting
|
|
59
|
+
* claim was withheld" are different statements about grounding, and an agent that cannot
|
|
60
|
+
* tell them apart cannot make either one.
|
|
61
|
+
*/
|
|
62
|
+
export interface UnresolvedSupport {
|
|
63
|
+
kind: 'event' | 'memory' | 'message' | 'unknown';
|
|
64
|
+
/** Present only for events. A memory id is withheld deliberately - see below. */
|
|
65
|
+
eventIndexId: string | null;
|
|
66
|
+
reason: ResolutionFailure;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Provenance that was recorded but does not point at an observed event: the memory a
|
|
70
|
+
* claim was built from, the envelope that authorized the write, the message that
|
|
71
|
+
* prompted it. Reported rather than discarded - "this rests on three earlier memories
|
|
72
|
+
* and no observation" is a true and useful answer, and it is the answer for almost
|
|
73
|
+
* every memory that exists today.
|
|
74
|
+
*/
|
|
75
|
+
export interface RecordedSupport {
|
|
76
|
+
kind: 'memory' | 'envelope' | 'message';
|
|
77
|
+
id: string;
|
|
78
|
+
}
|
|
79
|
+
/** A source ref or canonical graph link that can name an observed event. */
|
|
80
|
+
export type ParsedSourceRef = {
|
|
81
|
+
kind: 'raw';
|
|
82
|
+
connector: string;
|
|
83
|
+
eventIndexId: string;
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'observation';
|
|
86
|
+
observationId: string;
|
|
87
|
+
} | RecordedSupport | {
|
|
88
|
+
kind: 'unsupported';
|
|
89
|
+
};
|
|
90
|
+
export interface ProvenanceResolution {
|
|
91
|
+
memoryId: string;
|
|
92
|
+
/**
|
|
93
|
+
* The stored record's own status, and whether the system has retired it.
|
|
94
|
+
*
|
|
95
|
+
* Carried because every read path filters these out and this one did not: 65% of the
|
|
96
|
+
* live corpus is `superseded`, and without this the tool would report `resolved` for a
|
|
97
|
+
* retired claim in output identical to a current one. Grounding a statement in a record
|
|
98
|
+
* the system has explicitly replaced, confidently and invisibly, is the failure this
|
|
99
|
+
* whole tool exists to prevent.
|
|
100
|
+
*/
|
|
101
|
+
memoryStatus: string | null;
|
|
102
|
+
retired: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* `resolved` - every support dereferenced and visible.
|
|
105
|
+
* `partial` - at least one resolved, at least one not.
|
|
106
|
+
* `unresolved` - nothing could be shown, and `reason` says why.
|
|
107
|
+
*/
|
|
108
|
+
status: 'resolved' | 'partial' | 'unresolved';
|
|
109
|
+
modelRunId: string | null;
|
|
110
|
+
contextPacketId: string | null;
|
|
111
|
+
events: ResolvedEvent[];
|
|
112
|
+
unresolved: UnresolvedSupport[];
|
|
113
|
+
/** Recorded provenance that is not an observed event. Never a failure. */
|
|
114
|
+
supports: RecordedSupport[];
|
|
115
|
+
/** Present only when nothing resolved, so a caller never has to infer the cause. */
|
|
116
|
+
reason?: ResolutionFailure;
|
|
117
|
+
}
|
|
118
|
+
/** A memory's recorded provenance, reduced to what resolution needs. */
|
|
119
|
+
export interface ProvenanceSubjectRecord {
|
|
120
|
+
/** Raw status column, e.g. `active`, `superseded`. */
|
|
121
|
+
status?: string | null;
|
|
122
|
+
/** True when the reader's status filter, or a supersede link, would exclude it. */
|
|
123
|
+
retired?: boolean;
|
|
124
|
+
modelRunId: string | null;
|
|
125
|
+
contextPacketId: string | null;
|
|
126
|
+
/** Canonical source refs; empty when the write was not evidence-backed. */
|
|
127
|
+
sourceRefs: ReadonlyArray<ParsedSourceRef>;
|
|
128
|
+
/** True when the record predates scoped provenance and cannot be re-checked. */
|
|
129
|
+
legacyUnscoped?: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface IndexedEvent {
|
|
132
|
+
connector: string;
|
|
133
|
+
eventIndexId: string;
|
|
134
|
+
sourceId: string;
|
|
135
|
+
channel: string | null;
|
|
136
|
+
observedAt: string | null;
|
|
137
|
+
/** Source/event occurrence time, separate from host capture time. */
|
|
138
|
+
sourceAt?: string | null;
|
|
139
|
+
content: string;
|
|
140
|
+
/**
|
|
141
|
+
* The scope recorded on the event, or null when it was indexed before scoped
|
|
142
|
+
* indexing existed. Carried on the event so visibility is a pure function of it -
|
|
143
|
+
* a caller cannot re-check what it was not given.
|
|
144
|
+
*/
|
|
145
|
+
memoryScope?: {
|
|
146
|
+
kind: string;
|
|
147
|
+
id: string;
|
|
148
|
+
} | null;
|
|
149
|
+
/** Project and tenant the event was indexed under; null when it carries neither. */
|
|
150
|
+
projectId?: string | null;
|
|
151
|
+
tenantId?: string | null;
|
|
152
|
+
}
|
|
153
|
+
export interface ProvenanceResolverDeps {
|
|
154
|
+
lookupMemoryProvenance(memoryId: string): ProvenanceSubjectRecord | null;
|
|
155
|
+
lookupEvent(connector: string, eventIndexId: string): IndexedEvent | null;
|
|
156
|
+
/** Resolve an exact canonical observation edge without trusting a claimed connector. */
|
|
157
|
+
lookupObservation?(observationId: string): IndexedEvent | null;
|
|
158
|
+
/**
|
|
159
|
+
* Whether this event is visible under the scope active NOW - not the scope that was
|
|
160
|
+
* active when the memory was written. This is the check that keeps a handle from
|
|
161
|
+
* becoming a standing capability.
|
|
162
|
+
*/
|
|
163
|
+
isVisible(event: IndexedEvent): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Whether a recorded support may be named under the authority active now.
|
|
166
|
+
*
|
|
167
|
+
* Applies to every non-event support, not just memories. The first version checked
|
|
168
|
+
* nothing here and the second checked only `memory:`, which left `message:` refs -
|
|
169
|
+
* built as `source:channelId:turnId` - handing a channel identifier to any caller that
|
|
170
|
+
* could read the memory. Naming a support is disclosure whatever its kind.
|
|
171
|
+
*
|
|
172
|
+
* Optional so the pure module stays usable without a store; when absent, supports are
|
|
173
|
+
* withheld rather than assumed visible. A check that fails open is not a check.
|
|
174
|
+
*/
|
|
175
|
+
isSupportVisible?(support: RecordedSupport): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Redaction applied to an excerpt before it leaves. Recall runs its text through a
|
|
178
|
+
* pattern list (URLs, emails, tokens, key shapes, raw refs); an excerpt path that
|
|
179
|
+
* skipped it would send connector content out through a surface whose sibling scrubs
|
|
180
|
+
* it. Optional, and identity when absent - the pure module holds no pattern list.
|
|
181
|
+
*/
|
|
182
|
+
redact?(text: string): string;
|
|
183
|
+
/** Excerpt bound in characters. */
|
|
184
|
+
excerptChars?: number;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resolve one memory's support. Never throws for missing or invisible evidence - those
|
|
188
|
+
* are answers, not errors, and an agent needs to be able to report them.
|
|
189
|
+
*/
|
|
190
|
+
export declare function resolveMemoryProvenance(memoryId: string, deps: ProvenanceResolverDeps): ProvenanceResolution;
|
|
191
|
+
//# sourceMappingURL=provenance-resolver.d.ts.map
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a claim's support back to the events it came from.
|
|
4
|
+
*
|
|
5
|
+
* This is the capability the whole "traceable judgment" idea rests on, and until now it
|
|
6
|
+
* did not exist in any form the agent could reach. Memory records carried model run,
|
|
7
|
+
* envelope, gateway call and source refs; recall stripped every one of them, so an agent
|
|
8
|
+
* could read a memory and then had no way to say which memory a statement rested on. A
|
|
9
|
+
* handle was added upstream; this turns the handle into an answer.
|
|
10
|
+
*
|
|
11
|
+
* Two rules shape everything here.
|
|
12
|
+
*
|
|
13
|
+
* POSSESSION IS NOT AUTHORIZATION. Holding a memory id proves only that recall returned
|
|
14
|
+
* it once, under some scope, at some time. Every event is re-checked against the scope
|
|
15
|
+
* active NOW, and content is withheld when that check fails. A resolver that trusted the
|
|
16
|
+
* handle would turn recall into a capability leak: read once, cite forever.
|
|
17
|
+
*
|
|
18
|
+
* ABSENCE GETS A REASON. Silence is what made the original problem invisible - a report
|
|
19
|
+
* asserted things with nothing behind them and looked identical to one that was
|
|
20
|
+
* grounded. Every failure here names itself, so "I cannot support this" is a statement
|
|
21
|
+
* the agent can make instead of a gap it cannot see.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.resolveMemoryProvenance = resolveMemoryProvenance;
|
|
25
|
+
const DEFAULT_EXCERPT_CHARS = 280;
|
|
26
|
+
function excerptOf(content, limit) {
|
|
27
|
+
const collapsed = content.replace(/\s+/g, ' ').trim();
|
|
28
|
+
return collapsed.length <= limit ? collapsed : `${collapsed.slice(0, limit)}…`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolve one memory's support. Never throws for missing or invisible evidence - those
|
|
32
|
+
* are answers, not errors, and an agent needs to be able to report them.
|
|
33
|
+
*/
|
|
34
|
+
function resolveMemoryProvenance(memoryId, deps) {
|
|
35
|
+
const limit = deps.excerptChars ?? DEFAULT_EXCERPT_CHARS;
|
|
36
|
+
const record = deps.lookupMemoryProvenance(memoryId);
|
|
37
|
+
if (!record) {
|
|
38
|
+
return {
|
|
39
|
+
memoryId,
|
|
40
|
+
status: 'unresolved',
|
|
41
|
+
modelRunId: null,
|
|
42
|
+
contextPacketId: null,
|
|
43
|
+
events: [],
|
|
44
|
+
unresolved: [],
|
|
45
|
+
supports: [],
|
|
46
|
+
memoryStatus: null,
|
|
47
|
+
retired: false,
|
|
48
|
+
reason: 'unknown_memory',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const base = {
|
|
52
|
+
memoryId,
|
|
53
|
+
modelRunId: record.modelRunId,
|
|
54
|
+
contextPacketId: record.contextPacketId,
|
|
55
|
+
memoryStatus: record.status ?? null,
|
|
56
|
+
retired: record.retired ?? false,
|
|
57
|
+
};
|
|
58
|
+
if (record.legacyUnscoped) {
|
|
59
|
+
return {
|
|
60
|
+
...base,
|
|
61
|
+
status: 'unresolved',
|
|
62
|
+
events: [],
|
|
63
|
+
unresolved: [],
|
|
64
|
+
supports: [],
|
|
65
|
+
reason: 'legacy_unscoped',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (record.sourceRefs.length === 0) {
|
|
69
|
+
// A durable claim with no evidence behind it. Accepted at write time on purpose -
|
|
70
|
+
// requiring a compiled packet before an agent may record an observation would gate
|
|
71
|
+
// judgment on paperwork - but it must be visible here rather than look like support.
|
|
72
|
+
return {
|
|
73
|
+
...base,
|
|
74
|
+
status: 'unresolved',
|
|
75
|
+
events: [],
|
|
76
|
+
unresolved: [],
|
|
77
|
+
supports: [],
|
|
78
|
+
reason: 'missing_ref',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const events = [];
|
|
82
|
+
const unresolved = [];
|
|
83
|
+
const supports = [];
|
|
84
|
+
let eventRefCount = 0;
|
|
85
|
+
for (const ref of record.sourceRefs) {
|
|
86
|
+
// Recorded provenance that is not an observation. Kept out of `unresolved` on
|
|
87
|
+
// purpose: counting it as a failure would put a permanent entry at the front of the
|
|
88
|
+
// failure list, which then decides the reported reason for every memory and buries
|
|
89
|
+
// the ones that actually explain something.
|
|
90
|
+
if (ref.kind !== 'raw' && ref.kind !== 'observation') {
|
|
91
|
+
if (ref.kind === 'unsupported') {
|
|
92
|
+
unresolved.push({ kind: 'unknown', eventIndexId: null, reason: 'unsupported_ref' });
|
|
93
|
+
}
|
|
94
|
+
else if (!(deps.isSupportVisible?.(ref) ?? false)) {
|
|
95
|
+
// Named as absent, with the id withheld. Disclosing it would confirm that a
|
|
96
|
+
// specific memory exists just outside the caller's scope - the thing the
|
|
97
|
+
// top-level `unknown_memory` answer is careful not to do - or hand over the
|
|
98
|
+
// channel identifier buried in a message ref.
|
|
99
|
+
unresolved.push({
|
|
100
|
+
kind: ref.kind === 'memory' ? 'memory' : 'message',
|
|
101
|
+
eventIndexId: null,
|
|
102
|
+
reason: 'outside_scope',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
supports.push({ kind: ref.kind, id: ref.id });
|
|
107
|
+
}
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
eventRefCount += 1;
|
|
111
|
+
const eventIndexId = ref.kind === 'observation' ? ref.observationId : ref.eventIndexId;
|
|
112
|
+
const event = ref.kind === 'observation'
|
|
113
|
+
? (deps.lookupObservation?.(ref.observationId) ?? null)
|
|
114
|
+
: deps.lookupEvent(ref.connector, ref.eventIndexId);
|
|
115
|
+
if (!event) {
|
|
116
|
+
unresolved.push({ kind: 'event', eventIndexId, reason: 'event_deleted' });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (!deps.isVisible(event)) {
|
|
120
|
+
// Named, but nothing about it disclosed - not the channel, not a word of content.
|
|
121
|
+
unresolved.push({ kind: 'event', eventIndexId, reason: 'outside_scope' });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
events.push({
|
|
125
|
+
connector: event.connector,
|
|
126
|
+
eventIndexId: event.eventIndexId,
|
|
127
|
+
sourceId: event.sourceId,
|
|
128
|
+
channel: event.channel,
|
|
129
|
+
observedAt: event.observedAt,
|
|
130
|
+
excerpt: excerptOf(deps.redact ? deps.redact(event.content) : event.content, limit),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (events.length === 0) {
|
|
134
|
+
return {
|
|
135
|
+
...base,
|
|
136
|
+
status: 'unresolved',
|
|
137
|
+
events,
|
|
138
|
+
unresolved,
|
|
139
|
+
supports,
|
|
140
|
+
// A claim whose provenance points only at other claims is a different fact from a
|
|
141
|
+
// claim whose evidence went missing, and the agent needs to be able to say which.
|
|
142
|
+
reason: eventRefCount === 0 && unresolved.length === 0
|
|
143
|
+
? 'no_event_refs'
|
|
144
|
+
: (unresolved[0]?.reason ?? 'missing_ref'),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
...base,
|
|
149
|
+
status: unresolved.length === 0 ? 'resolved' : 'partial',
|
|
150
|
+
events,
|
|
151
|
+
unresolved,
|
|
152
|
+
supports,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=provenance-resolver.js.map
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import type { MemoryEventRecord, MemoryWriteProvenance, PublicIngestConversationInput, PublicIngestMemoryInput, PublicSaveMemoryInput } from './types.js';
|
|
2
|
-
export interface TrustedProvenanceCapability {
|
|
3
|
-
readonly __trustedProvenanceCapability: 'mama-core';
|
|
4
|
-
}
|
|
5
|
-
export interface TrustedMemoryWriteOptions {
|
|
6
|
-
provenance: MemoryWriteProvenance;
|
|
7
|
-
capability: TrustedProvenanceCapability;
|
|
8
|
-
}
|
|
9
2
|
export interface NormalizedMemoryProvenance {
|
|
10
3
|
actor: MemoryEventRecord['actor'];
|
|
11
4
|
agent_id: string | null;
|
|
@@ -18,12 +11,9 @@ export interface NormalizedMemoryProvenance {
|
|
|
18
11
|
source_refs: string[];
|
|
19
12
|
provenance: Record<string, unknown>;
|
|
20
13
|
}
|
|
21
|
-
export declare function createTrustedProvenanceCapability(): TrustedProvenanceCapability;
|
|
22
|
-
export declare function assertTrustedProvenanceCapability(capability: TrustedProvenanceCapability | undefined): asserts capability is TrustedProvenanceCapability;
|
|
23
14
|
export declare function stripCallerProvenance<T extends Record<string, unknown>>(input: T): T;
|
|
24
15
|
export declare function sanitizePublicSaveMemoryInput(input: PublicSaveMemoryInput): PublicSaveMemoryInput;
|
|
25
16
|
export declare function sanitizePublicIngestMemoryInput(input: PublicIngestMemoryInput): PublicIngestMemoryInput;
|
|
26
17
|
export declare function sanitizePublicIngestConversationInput(input: PublicIngestConversationInput): PublicIngestConversationInput;
|
|
27
|
-
export declare function normalizeMemoryWriteProvenance(
|
|
28
|
-
export declare function appendProvenanceSourceRefs(options: TrustedMemoryWriteOptions | undefined, refs: string[]): TrustedMemoryWriteOptions | undefined;
|
|
18
|
+
export declare function normalizeMemoryWriteProvenance(provenance?: MemoryWriteProvenance): NormalizedMemoryProvenance;
|
|
29
19
|
//# sourceMappingURL=provenance.d.ts.map
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTrustedProvenanceCapability = createTrustedProvenanceCapability;
|
|
4
|
-
exports.assertTrustedProvenanceCapability = assertTrustedProvenanceCapability;
|
|
5
3
|
exports.stripCallerProvenance = stripCallerProvenance;
|
|
6
4
|
exports.sanitizePublicSaveMemoryInput = sanitizePublicSaveMemoryInput;
|
|
7
5
|
exports.sanitizePublicIngestMemoryInput = sanitizePublicIngestMemoryInput;
|
|
8
6
|
exports.sanitizePublicIngestConversationInput = sanitizePublicIngestConversationInput;
|
|
9
7
|
exports.normalizeMemoryWriteProvenance = normalizeMemoryWriteProvenance;
|
|
10
|
-
exports.appendProvenanceSourceRefs = appendProvenanceSourceRefs;
|
|
11
|
-
const issuedCapabilities = new WeakSet();
|
|
12
8
|
const ALLOWED_PROVENANCE_FIELDS = new Set([
|
|
13
9
|
'actor',
|
|
14
10
|
'agent_id',
|
|
@@ -21,18 +17,6 @@ const ALLOWED_PROVENANCE_FIELDS = new Set([
|
|
|
21
17
|
'source_message_ref',
|
|
22
18
|
'source_refs',
|
|
23
19
|
]);
|
|
24
|
-
function createTrustedProvenanceCapability() {
|
|
25
|
-
const capability = Object.freeze({
|
|
26
|
-
__trustedProvenanceCapability: 'mama-core',
|
|
27
|
-
});
|
|
28
|
-
issuedCapabilities.add(capability);
|
|
29
|
-
return capability;
|
|
30
|
-
}
|
|
31
|
-
function assertTrustedProvenanceCapability(capability) {
|
|
32
|
-
if (!capability || typeof capability !== 'object' || !issuedCapabilities.has(capability)) {
|
|
33
|
-
throw new Error('Invalid trusted provenance capability');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
20
|
function stripCallerProvenance(input) {
|
|
37
21
|
if (!Object.prototype.hasOwnProperty.call(input, 'provenance')) {
|
|
38
22
|
return input;
|
|
@@ -49,12 +33,10 @@ function sanitizePublicIngestMemoryInput(input) {
|
|
|
49
33
|
function sanitizePublicIngestConversationInput(input) {
|
|
50
34
|
return stripCallerProvenance(input);
|
|
51
35
|
}
|
|
52
|
-
function normalizeMemoryWriteProvenance(
|
|
53
|
-
if (!
|
|
36
|
+
function normalizeMemoryWriteProvenance(provenance) {
|
|
37
|
+
if (!provenance) {
|
|
54
38
|
return buildFallbackProvenance();
|
|
55
39
|
}
|
|
56
|
-
assertTrustedProvenanceCapability(options.capability);
|
|
57
|
-
const provenance = options.provenance ?? {};
|
|
58
40
|
const actor = provenance.actor ?? 'main_agent';
|
|
59
41
|
const sourceRefs = normalizeStringArray(provenance.source_refs);
|
|
60
42
|
const compact = {
|
|
@@ -85,19 +67,6 @@ function normalizeMemoryWriteProvenance(options) {
|
|
|
85
67
|
provenance: compact,
|
|
86
68
|
};
|
|
87
69
|
}
|
|
88
|
-
function appendProvenanceSourceRefs(options, refs) {
|
|
89
|
-
if (!options) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
assertTrustedProvenanceCapability(options.capability);
|
|
93
|
-
return {
|
|
94
|
-
capability: options.capability,
|
|
95
|
-
provenance: {
|
|
96
|
-
...options.provenance,
|
|
97
|
-
source_refs: [...(options.provenance.source_refs ?? []), ...refs],
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
70
|
function buildFallbackProvenance() {
|
|
102
71
|
const actor = 'actor:direct_client';
|
|
103
72
|
return {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare function sanitizeRecallText(value: string | undefined): string | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* The shape a recall answers in.
|
|
4
|
+
*
|
|
5
|
+
* memory.read:topic returned recallMemory's records verbatim; the scrub and this
|
|
6
|
+
* narrowing lived in a host tool case that wrapped the action, so a caller
|
|
7
|
+
* naming the action got unredacted full records. Provenance already scrubbed its
|
|
8
|
+
* excerpts - topic simply did not - and the two read surfaces have to answer the
|
|
9
|
+
* same way.
|
|
10
|
+
*/
|
|
11
|
+
export interface SafeRecallMemory {
|
|
12
|
+
/**
|
|
13
|
+
* Handle for the recalled record.
|
|
14
|
+
*
|
|
15
|
+
* Without this the agent receives prose it cannot point at: it can read a
|
|
16
|
+
* memory and then has no way to say WHICH memory a statement rests on, so a
|
|
17
|
+
* claim can never be traced back to its evidence and a correction has no
|
|
18
|
+
* address. The id is an opaque identifier, not content, so returning it
|
|
19
|
+
* discloses nothing the summary does not.
|
|
20
|
+
*/
|
|
21
|
+
memoryId?: string;
|
|
22
|
+
topic?: string;
|
|
23
|
+
kind?: string;
|
|
24
|
+
summary?: string;
|
|
25
|
+
confidence?: number;
|
|
26
|
+
status?: string;
|
|
27
|
+
/**
|
|
28
|
+
* SUCCESS / FAILED / PARTIAL, or null.
|
|
29
|
+
*
|
|
30
|
+
* Not free text, so it discloses nothing the summary does not - and a reader
|
|
31
|
+
* that cannot see it presents a failed decision as if it still held. The
|
|
32
|
+
* projection was tuned to one consumer before it became the action's answer
|
|
33
|
+
* for all of them, and dropping this is what that cost.
|
|
34
|
+
*/
|
|
35
|
+
outcome?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SafeRecallProfileEvidence {
|
|
38
|
+
topic?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface SafeRecallBundle {
|
|
41
|
+
profile: {
|
|
42
|
+
static: SafeRecallMemory[];
|
|
43
|
+
dynamic: SafeRecallMemory[];
|
|
44
|
+
evidence: SafeRecallProfileEvidence[];
|
|
45
|
+
};
|
|
46
|
+
memories: SafeRecallMemory[];
|
|
47
|
+
graph_context: {
|
|
48
|
+
primary: SafeRecallMemory[];
|
|
49
|
+
expanded: SafeRecallMemory[];
|
|
50
|
+
edge_count: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Scrub a recall bundle and narrow it to the fields a read may answer with. */
|
|
54
|
+
export declare function sanitizeRecallBundle(bundle: unknown): SafeRecallBundle;
|
|
55
|
+
//# sourceMappingURL=recall-sanitize.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeRecallText = sanitizeRecallText;
|
|
4
|
+
exports.sanitizeRecallBundle = sanitizeRecallBundle;
|
|
5
|
+
/**
|
|
6
|
+
* Recall-surface text redaction, owned by the core so every read surface scrubs
|
|
7
|
+
* the same way. The provenance action passes this as its `redact` - a caller
|
|
8
|
+
* never supplies the scrub, because a citation that lets the caller choose the
|
|
9
|
+
* redaction would let them choose none.
|
|
10
|
+
*/
|
|
11
|
+
const RECALL_TEXT_REDACTION_PATTERNS = [
|
|
12
|
+
/MAMA_SYNTHETIC_[A-Z0-9_]+_DO_NOT_LEAK/g,
|
|
13
|
+
/synthetic:\/\/raw[^\s"']*/g,
|
|
14
|
+
/raw:[^\s"']*/g,
|
|
15
|
+
/\bhttps?:\/\/[^\s"'<>()]+/gi,
|
|
16
|
+
/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi,
|
|
17
|
+
/\b(?:Bearer|Token|Authorization)\s*[:=]?\s*[A-Za-z0-9._~+/=-]{8,}/gi,
|
|
18
|
+
/\b(?:api[_-]?key|token|secret|password)\s*[:=]\s*[^\s"']{8,}/gi,
|
|
19
|
+
/(?:ghp|gho|ghu|ghs|ghr|github_pat)_[A-Za-z0-9_]{8,}\b/g,
|
|
20
|
+
/xox[baprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
21
|
+
/sk-[A-Za-z0-9_-]{20,}\b/g,
|
|
22
|
+
/\b[CU][A-Z0-9]{8,}\b/g,
|
|
23
|
+
/\b[0-9]{17,20}\b/g,
|
|
24
|
+
/(?:\/Users|\/home|\/tmp)\/[^\s"']*/g,
|
|
25
|
+
/[A-Za-z]:\\Users\\[^\s"']*/g,
|
|
26
|
+
];
|
|
27
|
+
const MAX_RECALL_TEXT_LENGTH = 280;
|
|
28
|
+
const RECALL_TEXT_REDACTION_SCAN_LIMIT = MAX_RECALL_TEXT_LENGTH + 2048;
|
|
29
|
+
function sanitizeRecallText(value) {
|
|
30
|
+
if (!value) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
let sanitized = value.length > RECALL_TEXT_REDACTION_SCAN_LIMIT
|
|
34
|
+
? value.slice(0, RECALL_TEXT_REDACTION_SCAN_LIMIT)
|
|
35
|
+
: value;
|
|
36
|
+
for (const pattern of RECALL_TEXT_REDACTION_PATTERNS) {
|
|
37
|
+
sanitized = sanitized.replace(pattern, '[redacted]');
|
|
38
|
+
}
|
|
39
|
+
const wasTruncated = value.length > MAX_RECALL_TEXT_LENGTH || sanitized.length > MAX_RECALL_TEXT_LENGTH;
|
|
40
|
+
if (sanitized.length > MAX_RECALL_TEXT_LENGTH) {
|
|
41
|
+
sanitized = sanitized.slice(0, MAX_RECALL_TEXT_LENGTH);
|
|
42
|
+
}
|
|
43
|
+
if (wasTruncated) {
|
|
44
|
+
sanitized = `${sanitized} [truncated]`;
|
|
45
|
+
}
|
|
46
|
+
return sanitized;
|
|
47
|
+
}
|
|
48
|
+
function asRecord(value) {
|
|
49
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
50
|
+
? value
|
|
51
|
+
: null;
|
|
52
|
+
}
|
|
53
|
+
function stringField(record, field) {
|
|
54
|
+
const value = record[field];
|
|
55
|
+
return typeof value === 'string' ? value : undefined;
|
|
56
|
+
}
|
|
57
|
+
function numberField(record, field) {
|
|
58
|
+
const value = record[field];
|
|
59
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
function sanitizeRecallMemory(value) {
|
|
62
|
+
const record = asRecord(value);
|
|
63
|
+
if (!record) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const safe = {};
|
|
67
|
+
const memoryId = stringField(record, 'id');
|
|
68
|
+
if (memoryId) {
|
|
69
|
+
safe.memoryId = memoryId;
|
|
70
|
+
}
|
|
71
|
+
const topic = sanitizeRecallText(stringField(record, 'topic'));
|
|
72
|
+
const kind = sanitizeRecallText(stringField(record, 'kind'));
|
|
73
|
+
const summary = sanitizeRecallText(stringField(record, 'summary'));
|
|
74
|
+
const status = sanitizeRecallText(stringField(record, 'status'));
|
|
75
|
+
const outcome = sanitizeRecallText(stringField(record, 'outcome'));
|
|
76
|
+
const confidence = numberField(record, 'confidence');
|
|
77
|
+
if (topic) {
|
|
78
|
+
safe.topic = topic;
|
|
79
|
+
}
|
|
80
|
+
if (kind) {
|
|
81
|
+
safe.kind = kind;
|
|
82
|
+
}
|
|
83
|
+
if (summary) {
|
|
84
|
+
safe.summary = summary;
|
|
85
|
+
}
|
|
86
|
+
if (status) {
|
|
87
|
+
safe.status = status;
|
|
88
|
+
}
|
|
89
|
+
if (outcome) {
|
|
90
|
+
safe.outcome = outcome;
|
|
91
|
+
}
|
|
92
|
+
if (confidence !== undefined) {
|
|
93
|
+
safe.confidence = confidence;
|
|
94
|
+
}
|
|
95
|
+
return Object.keys(safe).length > 0 ? safe : null;
|
|
96
|
+
}
|
|
97
|
+
function sanitizeRecallMemories(value) {
|
|
98
|
+
if (!Array.isArray(value)) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
return value
|
|
102
|
+
.map((memory) => sanitizeRecallMemory(memory))
|
|
103
|
+
.filter((memory) => memory !== null);
|
|
104
|
+
}
|
|
105
|
+
function sanitizeProfileEvidence(value) {
|
|
106
|
+
if (!Array.isArray(value)) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
return value
|
|
110
|
+
.map((item) => {
|
|
111
|
+
const record = asRecord(item);
|
|
112
|
+
if (!record) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const evidence = {};
|
|
116
|
+
const topic = sanitizeRecallText(stringField(record, 'topic'));
|
|
117
|
+
if (topic) {
|
|
118
|
+
evidence.topic = topic;
|
|
119
|
+
}
|
|
120
|
+
return Object.keys(evidence).length > 0 ? evidence : null;
|
|
121
|
+
})
|
|
122
|
+
.filter((evidence) => evidence !== null);
|
|
123
|
+
}
|
|
124
|
+
/** Scrub a recall bundle and narrow it to the fields a read may answer with. */
|
|
125
|
+
function sanitizeRecallBundle(bundle) {
|
|
126
|
+
const record = asRecord(bundle) ?? {};
|
|
127
|
+
const profile = asRecord(record.profile) ?? {};
|
|
128
|
+
const graphContext = asRecord(record.graph_context) ?? {};
|
|
129
|
+
const edges = Array.isArray(graphContext.edges) ? graphContext.edges : [];
|
|
130
|
+
return {
|
|
131
|
+
profile: {
|
|
132
|
+
static: sanitizeRecallMemories(profile.static),
|
|
133
|
+
dynamic: sanitizeRecallMemories(profile.dynamic),
|
|
134
|
+
evidence: sanitizeProfileEvidence(profile.evidence),
|
|
135
|
+
},
|
|
136
|
+
memories: sanitizeRecallMemories(record.memories),
|
|
137
|
+
graph_context: {
|
|
138
|
+
primary: sanitizeRecallMemories(graphContext.primary),
|
|
139
|
+
expanded: sanitizeRecallMemories(graphContext.expanded),
|
|
140
|
+
edge_count: edges.length,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=recall-sanitize.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret-pattern filter for recallable writes.
|
|
3
|
+
*
|
|
4
|
+
* The one real leak path a chat-reachable caller has is memory: a secret saved
|
|
5
|
+
* as a "decision" resurfaces later through search or recall. This filter
|
|
6
|
+
* refuses the write at the choke point, which is the action contract — every
|
|
7
|
+
* write that recall can return passes through here. Minimal gitleaks-style
|
|
8
|
+
* set: shapes, not entropy heuristics, so false positives stay near zero.
|
|
9
|
+
*
|
|
10
|
+
* It lives in core because the contract does. The patterns name provider key
|
|
11
|
+
* shapes and prompt-injection phrasing; nothing here knows a product.
|
|
12
|
+
*/
|
|
13
|
+
export interface SecretScanResult {
|
|
14
|
+
clean: boolean;
|
|
15
|
+
matches: string[];
|
|
16
|
+
warnings: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare class SecretMaterialRefusedError extends Error {
|
|
19
|
+
constructor(matches: readonly string[]);
|
|
20
|
+
}
|
|
21
|
+
/** Scan text for secret-shaped material. */
|
|
22
|
+
export declare function scanForSecrets(text: string): SecretScanResult;
|
|
23
|
+
/**
|
|
24
|
+
* Scan every string reachable in a memory-write input (nested objects and
|
|
25
|
+
* arrays included, container-depth-capped): open_files arrays, scope ids, and source
|
|
26
|
+
* objects are persisted too and must not smuggle secrets past a top-level
|
|
27
|
+
* scan (review m1).
|
|
28
|
+
*/
|
|
29
|
+
export declare function scanMemoryWriteInput(input: Record<string, unknown>): SecretScanResult;
|
|
30
|
+
/** Mask the same credential shapes in observations without treating hashes as tokens. */
|
|
31
|
+
export declare function redactSecretPatterns(text: string): string;
|
|
32
|
+
//# sourceMappingURL=secret-filter.d.ts.map
|