@jungjaehoon/mama-os 0.28.5 → 0.29.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/dist/agent/agent-loop.d.ts +0 -4
- package/dist/agent/agent-loop.d.ts.map +1 -1
- package/dist/agent/agent-loop.js +44 -12
- package/dist/agent/agent-loop.js.map +1 -1
- package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
- package/dist/agent/code-act/host-bridge.js +53 -3
- package/dist/agent/code-act/host-bridge.js.map +1 -1
- package/dist/agent/code-act/tool-policy.d.ts.map +1 -1
- package/dist/agent/code-act/tool-policy.js +5 -0
- package/dist/agent/code-act/tool-policy.js.map +1 -1
- package/dist/agent/codex-auth.d.ts +0 -1
- package/dist/agent/codex-auth.d.ts.map +1 -1
- package/dist/agent/codex-auth.js +0 -4
- package/dist/agent/codex-auth.js.map +1 -1
- package/dist/agent/codex-home.d.ts +0 -2
- package/dist/agent/codex-home.d.ts.map +1 -1
- package/dist/agent/codex-home.js +0 -66
- package/dist/agent/codex-home.js.map +1 -1
- package/dist/agent/context-compile-service.d.ts +9 -0
- package/dist/agent/context-compile-service.d.ts.map +1 -1
- package/dist/agent/context-compile-service.js +6 -0
- package/dist/agent/context-compile-service.js.map +1 -1
- package/dist/agent/context-prompt-builder.d.ts +0 -6
- package/dist/agent/context-prompt-builder.d.ts.map +1 -1
- package/dist/agent/context-prompt-builder.js +0 -131
- package/dist/agent/context-prompt-builder.js.map +1 -1
- package/dist/agent/contract-extractor.d.ts +0 -4
- package/dist/agent/contract-extractor.d.ts.map +1 -1
- package/dist/agent/contract-extractor.js +0 -68
- package/dist/agent/contract-extractor.js.map +1 -1
- package/dist/agent/gateway-tool-executor.d.ts +20 -15
- package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
- package/dist/agent/gateway-tool-executor.js +236 -90
- package/dist/agent/gateway-tool-executor.js.map +1 -1
- package/dist/agent/gateway-tools.md +7 -4
- package/dist/agent/skill-loader.d.ts +0 -7
- package/dist/agent/skill-loader.d.ts.map +1 -1
- package/dist/agent/skill-loader.js +0 -86
- package/dist/agent/skill-loader.js.map +1 -1
- package/dist/agent/token-estimator.d.ts +0 -8
- package/dist/agent/token-estimator.d.ts.map +1 -1
- package/dist/agent/token-estimator.js +0 -14
- package/dist/agent/token-estimator.js.map +1 -1
- package/dist/agent/tool-registry.d.ts.map +1 -1
- package/dist/agent/tool-registry.js +23 -5
- package/dist/agent/tool-registry.js.map +1 -1
- package/dist/agent/types.d.ts +27 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/api/agent-graph-handler.d.ts +9 -0
- package/dist/api/agent-graph-handler.d.ts.map +1 -1
- package/dist/api/agent-graph-handler.js +27 -1
- package/dist/api/agent-graph-handler.js.map +1 -1
- package/dist/api/entity-audit-handler.d.ts +1 -2
- package/dist/api/entity-audit-handler.d.ts.map +1 -1
- package/dist/api/entity-audit-handler.js +0 -5
- package/dist/api/entity-audit-handler.js.map +1 -1
- package/dist/api/index.d.ts +1 -9
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +4 -17
- package/dist/api/index.js.map +1 -1
- package/dist/api/intelligence-handler.d.ts +0 -5
- package/dist/api/intelligence-handler.d.ts.map +1 -1
- package/dist/api/intelligence-handler.js +0 -15
- package/dist/api/intelligence-handler.js.map +1 -1
- package/dist/api/types.d.ts +1 -5
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js +0 -14
- package/dist/api/types.js.map +1 -1
- package/dist/cli/commands/start.d.ts +117 -3
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +223 -62
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/config/config-manager.d.ts +0 -5
- package/dist/cli/config/config-manager.d.ts.map +1 -1
- package/dist/cli/config/config-manager.js +0 -29
- package/dist/cli/config/config-manager.js.map +1 -1
- package/dist/cli/config/types.d.ts.map +1 -1
- package/dist/cli/config/types.js +3 -0
- package/dist/cli/config/types.js.map +1 -1
- package/dist/cli/runtime/agent-loop-init.d.ts.map +1 -1
- package/dist/cli/runtime/agent-loop-init.js +9 -1
- package/dist/cli/runtime/agent-loop-init.js.map +1 -1
- package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
- package/dist/cli/runtime/api-routes-init.js +32 -5
- package/dist/cli/runtime/api-routes-init.js.map +1 -1
- package/dist/cli/runtime/api-server-init.d.ts.map +1 -1
- package/dist/cli/runtime/api-server-init.js +2 -0
- package/dist/cli/runtime/api-server-init.js.map +1 -1
- package/dist/cli/runtime/gateway-init.d.ts +1 -1
- package/dist/cli/runtime/gateway-init.d.ts.map +1 -1
- package/dist/cli/runtime/gateway-init.js +11 -38
- package/dist/cli/runtime/gateway-init.js.map +1 -1
- package/dist/cli/runtime/gateway-wiring.d.ts.map +1 -1
- package/dist/cli/runtime/gateway-wiring.js +6 -120
- package/dist/cli/runtime/gateway-wiring.js.map +1 -1
- package/dist/cli/utils/pid-manager.d.ts +0 -10
- package/dist/cli/utils/pid-manager.d.ts.map +1 -1
- package/dist/cli/utils/pid-manager.js +0 -26
- package/dist/cli/utils/pid-manager.js.map +1 -1
- package/dist/connectors/framework/polling-scheduler.d.ts +33 -1
- package/dist/connectors/framework/polling-scheduler.d.ts.map +1 -1
- package/dist/connectors/framework/polling-scheduler.js +46 -40
- package/dist/connectors/framework/polling-scheduler.js.map +1 -1
- package/dist/connectors/trello/query-tools.d.ts +32 -5
- package/dist/connectors/trello/query-tools.d.ts.map +1 -1
- package/dist/connectors/trello/query-tools.js +56 -17
- package/dist/connectors/trello/query-tools.js.map +1 -1
- package/dist/db/agent-store.d.ts +0 -4
- package/dist/db/agent-store.d.ts.map +1 -1
- package/dist/db/agent-store.js +0 -65
- package/dist/db/agent-store.js.map +1 -1
- package/dist/envelope/enforcer.d.ts.map +1 -1
- package/dist/envelope/enforcer.js +10 -1
- package/dist/envelope/enforcer.js.map +1 -1
- package/dist/envelope/index.d.ts +0 -1
- package/dist/envelope/index.d.ts.map +1 -1
- package/dist/envelope/index.js +0 -1
- package/dist/envelope/index.js.map +1 -1
- package/dist/envelope/signature.d.ts +0 -1
- package/dist/envelope/signature.d.ts.map +1 -1
- package/dist/envelope/signature.js +0 -7
- package/dist/envelope/signature.js.map +1 -1
- package/dist/envelope/tool-connector-scope.d.ts +35 -0
- package/dist/envelope/tool-connector-scope.d.ts.map +1 -0
- package/dist/envelope/tool-connector-scope.js +57 -0
- package/dist/envelope/tool-connector-scope.js.map +1 -0
- package/dist/evidence/effects.d.ts +107 -0
- package/dist/evidence/effects.d.ts.map +1 -0
- package/dist/evidence/effects.js +281 -0
- package/dist/evidence/effects.js.map +1 -0
- package/dist/evidence/read.d.ts +75 -0
- package/dist/evidence/read.d.ts.map +1 -0
- package/dist/evidence/read.js +105 -0
- package/dist/evidence/read.js.map +1 -0
- package/dist/gateways/base-gateway.d.ts +23 -3
- package/dist/gateways/base-gateway.d.ts.map +1 -1
- package/dist/gateways/base-gateway.js +15 -2
- package/dist/gateways/base-gateway.js.map +1 -1
- package/dist/gateways/discord.d.ts +4 -16
- package/dist/gateways/discord.d.ts.map +1 -1
- package/dist/gateways/discord.js +22 -189
- package/dist/gateways/discord.js.map +1 -1
- package/dist/gateways/index.d.ts +2 -1
- package/dist/gateways/index.d.ts.map +1 -1
- package/dist/gateways/message-router.d.ts +13 -20
- package/dist/gateways/message-router.d.ts.map +1 -1
- package/dist/gateways/message-router.js +32 -3
- package/dist/gateways/message-router.js.map +1 -1
- package/dist/gateways/slack.d.ts +2 -12
- package/dist/gateways/slack.d.ts.map +1 -1
- package/dist/gateways/slack.js +6 -220
- package/dist/gateways/slack.js.map +1 -1
- package/dist/gateways/telegram.d.ts +2 -2
- package/dist/gateways/telegram.d.ts.map +1 -1
- package/dist/gateways/telegram.js +3 -2
- package/dist/gateways/telegram.js.map +1 -1
- package/dist/gateways/turn-contract.d.ts +104 -0
- package/dist/gateways/turn-contract.d.ts.map +1 -0
- package/dist/{memory/consult-contract.js → gateways/turn-contract.js} +1 -1
- package/dist/gateways/turn-contract.js.map +1 -0
- package/dist/memory/provenance-live.d.ts +111 -0
- package/dist/memory/provenance-live.d.ts.map +1 -0
- package/dist/memory/provenance-live.js +381 -0
- package/dist/memory/provenance-live.js.map +1 -0
- package/dist/memory/provenance-resolver.d.ts +184 -0
- package/dist/memory/provenance-resolver.d.ts.map +1 -0
- package/dist/memory/provenance-resolver.js +152 -0
- package/dist/memory/provenance-resolver.js.map +1 -0
- package/dist/multi-agent/agent-event-bus.d.ts +1 -0
- package/dist/multi-agent/agent-event-bus.d.ts.map +1 -1
- package/dist/multi-agent/bmad-templates.d.ts +0 -18
- package/dist/multi-agent/bmad-templates.d.ts.map +1 -1
- package/dist/multi-agent/bmad-templates.js +0 -127
- package/dist/multi-agent/bmad-templates.js.map +1 -1
- package/dist/multi-agent/dashboard-agent-persona.js +3 -3
- package/dist/operator/board-reconcile.d.ts +2 -3
- package/dist/operator/board-reconcile.d.ts.map +1 -1
- package/dist/operator/board-reconcile.js +18 -32
- package/dist/operator/board-reconcile.js.map +1 -1
- package/dist/operator/changes-projection.d.ts +70 -0
- package/dist/operator/changes-projection.d.ts.map +1 -0
- package/dist/operator/changes-projection.js +109 -0
- package/dist/operator/changes-projection.js.map +1 -0
- package/dist/operator/external-correlation.d.ts +94 -0
- package/dist/operator/external-correlation.d.ts.map +1 -0
- package/dist/operator/external-correlation.js +177 -0
- package/dist/operator/external-correlation.js.map +1 -0
- package/dist/operator/operator-trigger-loop.d.ts +9 -1
- package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
- package/dist/operator/operator-trigger-loop.js +8 -4
- package/dist/operator/operator-trigger-loop.js.map +1 -1
- package/dist/operator/provenance-lookup.d.ts +18 -0
- package/dist/operator/provenance-lookup.d.ts.map +1 -0
- package/dist/operator/provenance-lookup.js +54 -0
- package/dist/operator/provenance-lookup.js.map +1 -0
- package/dist/operator/report-carry.d.ts +18 -1
- package/dist/operator/report-carry.d.ts.map +1 -1
- package/dist/operator/report-carry.js +22 -3
- package/dist/operator/report-carry.js.map +1 -1
- package/dist/operator/report-run.d.ts +35 -0
- package/dist/operator/report-run.d.ts.map +1 -1
- package/dist/operator/report-run.js +184 -24
- package/dist/operator/report-run.js.map +1 -1
- package/dist/operator/situation-report.d.ts.map +1 -1
- package/dist/operator/situation-report.js +9 -2
- package/dist/operator/situation-report.js.map +1 -1
- package/dist/operator/task-ledger.d.ts +84 -2
- package/dist/operator/task-ledger.d.ts.map +1 -1
- package/dist/operator/task-ledger.js +274 -31
- package/dist/operator/task-ledger.js.map +1 -1
- package/dist/operator/worker-run.js +1 -1
- package/dist/operator/worker-run.js.map +1 -1
- package/dist/operator/workorder-hooks.d.ts +79 -4
- package/dist/operator/workorder-hooks.d.ts.map +1 -1
- package/dist/operator/workorder-hooks.js +152 -20
- package/dist/operator/workorder-hooks.js.map +1 -1
- package/dist/operator/workorder-publishers.d.ts +2 -0
- package/dist/operator/workorder-publishers.d.ts.map +1 -1
- package/dist/operator/workorder-publishers.js +8 -1
- package/dist/operator/workorder-publishers.js.map +1 -1
- package/dist/utils/untrusted-content.d.ts +11 -0
- package/dist/utils/untrusted-content.d.ts.map +1 -1
- package/dist/utils/untrusted-content.js +20 -0
- package/dist/utils/untrusted-content.js.map +1 -1
- package/package.json +4 -3
- package/scripts/backfill-channel-keys.ts +451 -0
- package/dist/agent/auto-recall.d.ts +0 -48
- package/dist/agent/auto-recall.d.ts.map +0 -1
- package/dist/agent/auto-recall.js +0 -192
- package/dist/agent/auto-recall.js.map +0 -1
- package/dist/agent/claude-client.d.ts +0 -50
- package/dist/agent/claude-client.d.ts.map +0 -1
- package/dist/agent/claude-client.js +0 -219
- package/dist/agent/claude-client.js.map +0 -1
- package/dist/agent/delegation-executor.d.ts +0 -49
- package/dist/agent/delegation-executor.d.ts.map +0 -1
- package/dist/agent/delegation-executor.js +0 -692
- package/dist/agent/delegation-executor.js.map +0 -1
- package/dist/agent/mcp-executor.d.ts +0 -60
- package/dist/agent/mcp-executor.d.ts.map +0 -1
- package/dist/agent/mcp-executor.js +0 -190
- package/dist/agent/mcp-executor.js.map +0 -1
- package/dist/agent/process-tree.d.ts +0 -6
- package/dist/agent/process-tree.d.ts.map +0 -1
- package/dist/agent/process-tree.js +0 -21
- package/dist/agent/process-tree.js.map +0 -1
- package/dist/agent/streaming-callback-manager.d.ts +0 -85
- package/dist/agent/streaming-callback-manager.d.ts.map +0 -1
- package/dist/agent/streaming-callback-manager.js +0 -103
- package/dist/agent/streaming-callback-manager.js.map +0 -1
- package/dist/agent/token-budget.d.ts +0 -49
- package/dist/agent/token-budget.d.ts.map +0 -1
- package/dist/agent/token-budget.js +0 -92
- package/dist/agent/token-budget.js.map +0 -1
- package/dist/connectors/kagemusha/history-compiler.d.ts +0 -18
- package/dist/connectors/kagemusha/history-compiler.d.ts.map +0 -1
- package/dist/connectors/kagemusha/history-compiler.js +0 -35
- package/dist/connectors/kagemusha/history-compiler.js.map +0 -1
- package/dist/db/migrations/wiki-artifacts.d.ts +0 -3
- package/dist/db/migrations/wiki-artifacts.d.ts.map +0 -1
- package/dist/db/migrations/wiki-artifacts.js +0 -24
- package/dist/db/migrations/wiki-artifacts.js.map +0 -1
- package/dist/envelope/subset.d.ts +0 -9
- package/dist/envelope/subset.d.ts.map +0 -1
- package/dist/envelope/subset.js +0 -67
- package/dist/envelope/subset.js.map +0 -1
- package/dist/memory/consult-contract.d.ts +0 -8
- package/dist/memory/consult-contract.d.ts.map +0 -1
- package/dist/memory/consult-contract.js.map +0 -1
- package/dist/multi-agent/agent-message-queue.d.ts +0 -104
- package/dist/multi-agent/agent-message-queue.d.ts.map +0 -1
- package/dist/multi-agent/agent-message-queue.js +0 -227
- package/dist/multi-agent/agent-message-queue.js.map +0 -1
- package/dist/multi-agent/background-task-manager.d.ts +0 -248
- package/dist/multi-agent/background-task-manager.d.ts.map +0 -1
- package/dist/multi-agent/background-task-manager.js +0 -415
- package/dist/multi-agent/background-task-manager.js.map +0 -1
- package/dist/multi-agent/category-router.d.ts +0 -56
- package/dist/multi-agent/category-router.d.ts.map +0 -1
- package/dist/multi-agent/category-router.js +0 -99
- package/dist/multi-agent/category-router.js.map +0 -1
- package/dist/multi-agent/council-engine.d.ts +0 -60
- package/dist/multi-agent/council-engine.d.ts.map +0 -1
- package/dist/multi-agent/council-engine.js +0 -284
- package/dist/multi-agent/council-engine.js.map +0 -1
- package/dist/multi-agent/delegation-format-validator.d.ts +0 -22
- package/dist/multi-agent/delegation-format-validator.d.ts.map +0 -1
- package/dist/multi-agent/delegation-format-validator.js +0 -31
- package/dist/multi-agent/delegation-format-validator.js.map +0 -1
- package/dist/multi-agent/delegation-manager.d.ts +0 -128
- package/dist/multi-agent/delegation-manager.d.ts.map +0 -1
- package/dist/multi-agent/delegation-manager.js +0 -276
- package/dist/multi-agent/delegation-manager.js.map +0 -1
- package/dist/multi-agent/i18n-messages.d.ts +0 -35
- package/dist/multi-agent/i18n-messages.d.ts.map +0 -1
- package/dist/multi-agent/i18n-messages.js +0 -54
- package/dist/multi-agent/i18n-messages.js.map +0 -1
- package/dist/multi-agent/index.d.ts +0 -31
- package/dist/multi-agent/index.d.ts.map +0 -1
- package/dist/multi-agent/index.js +0 -46
- package/dist/multi-agent/index.js.map +0 -1
- package/dist/multi-agent/multi-agent-base.d.ts +0 -223
- package/dist/multi-agent/multi-agent-base.d.ts.map +0 -1
- package/dist/multi-agent/multi-agent-base.js +0 -592
- package/dist/multi-agent/multi-agent-base.js.map +0 -1
- package/dist/multi-agent/multi-agent-discord.d.ts +0 -142
- package/dist/multi-agent/multi-agent-discord.d.ts.map +0 -1
- package/dist/multi-agent/multi-agent-discord.js +0 -1235
- package/dist/multi-agent/multi-agent-discord.js.map +0 -1
- package/dist/multi-agent/multi-agent-slack.d.ts +0 -146
- package/dist/multi-agent/multi-agent-slack.d.ts.map +0 -1
- package/dist/multi-agent/multi-agent-slack.js +0 -953
- package/dist/multi-agent/multi-agent-slack.js.map +0 -1
- package/dist/multi-agent/multi-bot-manager.d.ts +0 -119
- package/dist/multi-agent/multi-bot-manager.d.ts.map +0 -1
- package/dist/multi-agent/multi-bot-manager.js +0 -449
- package/dist/multi-agent/multi-bot-manager.js.map +0 -1
- package/dist/multi-agent/orchestrator.d.ts +0 -110
- package/dist/multi-agent/orchestrator.d.ts.map +0 -1
- package/dist/multi-agent/orchestrator.js +0 -436
- package/dist/multi-agent/orchestrator.js.map +0 -1
- package/dist/multi-agent/rate-limiter.d.ts +0 -76
- package/dist/multi-agent/rate-limiter.d.ts.map +0 -1
- package/dist/multi-agent/rate-limiter.js +0 -128
- package/dist/multi-agent/rate-limiter.js.map +0 -1
- package/dist/multi-agent/shared-context.d.ts +0 -127
- package/dist/multi-agent/shared-context.d.ts.map +0 -1
- package/dist/multi-agent/shared-context.js +0 -239
- package/dist/multi-agent/shared-context.js.map +0 -1
- package/dist/multi-agent/slack-config-validator.d.ts +0 -42
- package/dist/multi-agent/slack-config-validator.d.ts.map +0 -1
- package/dist/multi-agent/slack-config-validator.js +0 -194
- package/dist/multi-agent/slack-config-validator.js.map +0 -1
- package/dist/multi-agent/slack-multi-bot-manager.d.ts +0 -143
- package/dist/multi-agent/slack-multi-bot-manager.d.ts.map +0 -1
- package/dist/multi-agent/slack-multi-bot-manager.js +0 -413
- package/dist/multi-agent/slack-multi-bot-manager.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-anti-pattern-detector.d.ts +0 -98
- package/dist/multi-agent/swarm/swarm-anti-pattern-detector.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-anti-pattern-detector.js +0 -225
- package/dist/multi-agent/swarm/swarm-anti-pattern-detector.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-db.d.ts +0 -175
- package/dist/multi-agent/swarm/swarm-db.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-db.js +0 -313
- package/dist/multi-agent/swarm/swarm-db.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-event-reporter.d.ts +0 -116
- package/dist/multi-agent/swarm/swarm-event-reporter.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-event-reporter.js +0 -243
- package/dist/multi-agent/swarm/swarm-event-reporter.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-mama-adapter.d.ts +0 -57
- package/dist/multi-agent/swarm/swarm-mama-adapter.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-mama-adapter.js +0 -87
- package/dist/multi-agent/swarm/swarm-mama-adapter.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-manager.d.ts +0 -122
- package/dist/multi-agent/swarm/swarm-manager.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-manager.js +0 -199
- package/dist/multi-agent/swarm/swarm-manager.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-task-learner.d.ts +0 -104
- package/dist/multi-agent/swarm/swarm-task-learner.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-task-learner.js +0 -211
- package/dist/multi-agent/swarm/swarm-task-learner.js.map +0 -1
- package/dist/multi-agent/swarm/swarm-task-runner.d.ts +0 -155
- package/dist/multi-agent/swarm/swarm-task-runner.d.ts.map +0 -1
- package/dist/multi-agent/swarm/swarm-task-runner.js +0 -615
- package/dist/multi-agent/swarm/swarm-task-runner.js.map +0 -1
- package/dist/multi-agent/swarm/wave-engine.d.ts +0 -96
- package/dist/multi-agent/swarm/wave-engine.d.ts.map +0 -1
- package/dist/multi-agent/swarm/wave-engine.js +0 -123
- package/dist/multi-agent/swarm/wave-engine.js.map +0 -1
- package/dist/multi-agent/system-reminder.d.ts +0 -206
- package/dist/multi-agent/system-reminder.d.ts.map +0 -1
- package/dist/multi-agent/system-reminder.js +0 -455
- package/dist/multi-agent/system-reminder.js.map +0 -1
- package/dist/multi-agent/task-continuation.d.ts +0 -74
- package/dist/multi-agent/task-continuation.d.ts.map +0 -1
- package/dist/multi-agent/task-continuation.js +0 -172
- package/dist/multi-agent/task-continuation.js.map +0 -1
- package/dist/multi-agent/ultrawork-state.d.ts +0 -57
- package/dist/multi-agent/ultrawork-state.d.ts.map +0 -1
- package/dist/multi-agent/ultrawork-state.js +0 -191
- package/dist/multi-agent/ultrawork-state.js.map +0 -1
- package/dist/multi-agent/ultrawork.d.ts +0 -152
- package/dist/multi-agent/ultrawork.d.ts.map +0 -1
- package/dist/multi-agent/ultrawork.js +0 -879
- package/dist/multi-agent/ultrawork.js.map +0 -1
- package/dist/multi-agent/work-tracker.d.ts +0 -22
- package/dist/multi-agent/work-tracker.d.ts.map +0 -1
- package/dist/multi-agent/work-tracker.js +0 -45
- package/dist/multi-agent/work-tracker.js.map +0 -1
- package/dist/multi-agent/workflow-engine.d.ts +0 -87
- package/dist/multi-agent/workflow-engine.d.ts.map +0 -1
- package/dist/multi-agent/workflow-engine.js +0 -604
- package/dist/multi-agent/workflow-engine.js.map +0 -1
- package/dist/onboarding/all-tools.d.ts +0 -18
- package/dist/onboarding/all-tools.d.ts.map +0 -1
- package/dist/onboarding/all-tools.js +0 -149
- package/dist/onboarding/all-tools.js.map +0 -1
- package/dist/onboarding/autonomous-discovery-tools.d.ts +0 -23
- package/dist/onboarding/autonomous-discovery-tools.d.ts.map +0 -1
- package/dist/onboarding/autonomous-discovery-tools.js +0 -268
- package/dist/onboarding/autonomous-discovery-tools.js.map +0 -1
- package/dist/onboarding/onboarding-state.d.ts +0 -70
- package/dist/onboarding/onboarding-state.d.ts.map +0 -1
- package/dist/onboarding/onboarding-state.js +0 -183
- package/dist/onboarding/onboarding-state.js.map +0 -1
- package/dist/onboarding/personality-quiz.d.ts +0 -35
- package/dist/onboarding/personality-quiz.d.ts.map +0 -1
- package/dist/onboarding/personality-quiz.js +0 -219
- package/dist/onboarding/personality-quiz.js.map +0 -1
- package/dist/onboarding/phase-5-summary.d.ts +0 -26
- package/dist/onboarding/phase-5-summary.d.ts.map +0 -1
- package/dist/onboarding/phase-5-summary.js +0 -153
- package/dist/onboarding/phase-5-summary.js.map +0 -1
- package/dist/onboarding/phase-6-security.d.ts +0 -33
- package/dist/onboarding/phase-6-security.d.ts.map +0 -1
- package/dist/onboarding/phase-6-security.js +0 -473
- package/dist/onboarding/phase-6-security.js.map +0 -1
- package/dist/onboarding/phase-7-integrations.d.ts +0 -91
- package/dist/onboarding/phase-7-integrations.d.ts.map +0 -1
- package/dist/onboarding/phase-7-integrations.js +0 -725
- package/dist/onboarding/phase-7-integrations.js.map +0 -1
- package/dist/onboarding/phase-8-demo.d.ts +0 -43
- package/dist/onboarding/phase-8-demo.d.ts.map +0 -1
- package/dist/onboarding/phase-8-demo.js +0 -346
- package/dist/onboarding/phase-8-demo.js.map +0 -1
- package/dist/onboarding/phase-9-finalization.d.ts +0 -27
- package/dist/onboarding/phase-9-finalization.d.ts.map +0 -1
- package/dist/onboarding/phase-9-finalization.js +0 -417
- package/dist/onboarding/phase-9-finalization.js.map +0 -1
- package/dist/onboarding/ritual-prompt.d.ts +0 -2
- package/dist/onboarding/ritual-prompt.d.ts.map +0 -1
- package/dist/onboarding/ritual-prompt.js +0 -285
- package/dist/onboarding/ritual-prompt.js.map +0 -1
- package/dist/onboarding/ritual-tools.d.ts +0 -17
- package/dist/onboarding/ritual-tools.d.ts.map +0 -1
- package/dist/onboarding/ritual-tools.js +0 -93
- package/dist/onboarding/ritual-tools.js.map +0 -1
- package/dist/setup/setup-tools.d.ts +0 -13
- package/dist/setup/setup-tools.d.ts.map +0 -1
- package/dist/setup/setup-tools.js +0 -106
- package/dist/setup/setup-tools.js.map +0 -1
- package/dist/utils/slack-input-validator.d.ts +0 -74
- package/dist/utils/slack-input-validator.d.ts.map +0 -1
- package/dist/utils/slack-input-validator.js +0 -275
- package/dist/utils/slack-input-validator.js.map +0 -1
- package/dist/utils/slack-rate-limiter.d.ts +0 -139
- package/dist/utils/slack-rate-limiter.d.ts.map +0 -1
- package/dist/utils/slack-rate-limiter.js +0 -324
- package/dist/utils/slack-rate-limiter.js.map +0 -1
- package/dist/wiki/wiki-compiler.d.ts +0 -13
- package/dist/wiki/wiki-compiler.d.ts.map +0 -1
- package/dist/wiki/wiki-compiler.js +0 -82
- package/dist/wiki/wiki-compiler.js.map +0 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** What kind of durable change happened. Closed on purpose - see the module note. */
|
|
2
|
+
export type EffectKind = 'task_create' | 'task_update' | 'report_update' | 'report_publish' | 'memory_write' | 'wiki_write';
|
|
3
|
+
/** What it happened to. */
|
|
4
|
+
export type EffectTarget = 'task' | 'report_slot' | 'memory' | 'wiki_page';
|
|
5
|
+
/** Whether the change could name what caused it. */
|
|
6
|
+
export type CauseState = 'attributed' | 'unattributed';
|
|
7
|
+
/** Fields every durable change carries, whether or not it can name a cause. */
|
|
8
|
+
export interface ChangeInput {
|
|
9
|
+
/**
|
|
10
|
+
* The model run that produced the change, so it is traceable to a transcript.
|
|
11
|
+
* Null when no model run did - a host-internal write is not made more honest by
|
|
12
|
+
* inventing a run id for it.
|
|
13
|
+
*/
|
|
14
|
+
runId?: string | null;
|
|
15
|
+
/** Evidence channel this change concerns, when it concerns one. */
|
|
16
|
+
channelId?: string | null;
|
|
17
|
+
kind: EffectKind;
|
|
18
|
+
targetType: EffectTarget;
|
|
19
|
+
targetId: string;
|
|
20
|
+
/** The written payload; hashed, never stored, so the ledger cannot leak content. */
|
|
21
|
+
payload: unknown;
|
|
22
|
+
atMs: number;
|
|
23
|
+
}
|
|
24
|
+
export interface EffectInput extends ChangeInput {
|
|
25
|
+
/** Events that caused it. Must not be empty. */
|
|
26
|
+
sourceEventIds: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
export interface EffectRecord {
|
|
29
|
+
id: number;
|
|
30
|
+
runId: string | null;
|
|
31
|
+
channelId: string | null;
|
|
32
|
+
causeState: CauseState;
|
|
33
|
+
sourceEventIds: string[];
|
|
34
|
+
kind: EffectKind;
|
|
35
|
+
targetType: EffectTarget;
|
|
36
|
+
targetId: string;
|
|
37
|
+
payloadHash: string;
|
|
38
|
+
atMs: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether a value can serve as a cause at all.
|
|
42
|
+
*
|
|
43
|
+
* Callers ask before writing rather than discovering it as a constraint violation,
|
|
44
|
+
* because the answer changes what they record, not whether they may proceed: a malformed
|
|
45
|
+
* cause makes a change unattributed, it does not make the change illegitimate. Legacy
|
|
46
|
+
* rows really do carry 400-character source identifiers, and refusing to let the operator
|
|
47
|
+
* update a work item because its upstream id is the wrong shape would be enforcement
|
|
48
|
+
* bought with the owner's work.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isUsableCause(value: string | null | undefined): value is string;
|
|
51
|
+
export declare const EVIDENCE_EFFECTS_DDL: string;
|
|
52
|
+
interface EffectAdapter {
|
|
53
|
+
prepare(sql: string): {
|
|
54
|
+
run(...params: unknown[]): {
|
|
55
|
+
lastInsertRowid?: number | bigint;
|
|
56
|
+
};
|
|
57
|
+
all(...params: unknown[]): unknown[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export declare function ensureEffectLedger(adapter: EffectAdapter): void;
|
|
61
|
+
export declare class EffectWithoutCauseError extends Error {
|
|
62
|
+
constructor(kind: EffectKind, targetId: string);
|
|
63
|
+
}
|
|
64
|
+
/** Stable hash of what was written. The ledger proves a change happened, not what it said. */
|
|
65
|
+
export declare function payloadHash(payload: unknown): string;
|
|
66
|
+
/**
|
|
67
|
+
* Record a durable change.
|
|
68
|
+
*
|
|
69
|
+
* Throws rather than returning a failure when the cause is missing. A caller that wrote
|
|
70
|
+
* something and then could not say why must not proceed as if the write were accounted
|
|
71
|
+
* for - silently skipping the ledger row is how 1,169 runs closed as `done` while five
|
|
72
|
+
* receipts existed.
|
|
73
|
+
*/
|
|
74
|
+
export declare function recordEffect(adapter: EffectAdapter, input: EffectInput): number;
|
|
75
|
+
/**
|
|
76
|
+
* Record a durable change that could not name what caused it.
|
|
77
|
+
*
|
|
78
|
+
* Deliberately a separate function with an uncomfortable name. Every call is an admission
|
|
79
|
+
* that the system changed something it cannot explain, and the point is that the count of
|
|
80
|
+
* these is visible next to the count of real effects rather than absent from both.
|
|
81
|
+
*/
|
|
82
|
+
export declare function recordUnattributedChange(adapter: EffectAdapter, input: ChangeInput): number;
|
|
83
|
+
export interface EffectQuery {
|
|
84
|
+
runId?: string;
|
|
85
|
+
targetType?: EffectTarget;
|
|
86
|
+
targetId?: string;
|
|
87
|
+
causeState?: CauseState;
|
|
88
|
+
sinceMs?: number;
|
|
89
|
+
limit?: number;
|
|
90
|
+
}
|
|
91
|
+
/** Read effects back, newest first - the substrate a report projects from. */
|
|
92
|
+
export declare function listEffects(adapter: EffectAdapter, query?: EffectQuery): EffectRecord[];
|
|
93
|
+
export interface ChangeCoverage {
|
|
94
|
+
/** Changes that named the events behind them. */
|
|
95
|
+
attributed: number;
|
|
96
|
+
/** Changes the system made and could not explain. */
|
|
97
|
+
unattributed: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* How much of what the system changed rests on evidence.
|
|
101
|
+
*
|
|
102
|
+
* The single number this ledger exists to make answerable, and the one the previous shape
|
|
103
|
+
* of the system could not produce at all.
|
|
104
|
+
*/
|
|
105
|
+
export declare function changeCoverage(adapter: EffectAdapter, sinceMs?: number, targetType?: EffectTarget): ChangeCoverage;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/evidence/effects.ts"],"names":[],"mappings":"AAqDA,qFAAqF;AACrF,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,aAAa,GACb,eAAe,GACf,gBAAgB,GAChB,cAAc,GACd,YAAY,CAAC;AAEjB,2BAA2B;AAC3B,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE3E,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;AAEvD,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;I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ED,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM;CAM/C;AAED,8FAA8F;AAC9F,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAKpD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAQ/E;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAE3F;AA6BD,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,GAAE,WAAgB,GAAG,YAAY,EAAE,CA8C3F;AAED,MAAM,WAAW,cAAc;IAC7B,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,YAAY,GACxB,cAAc,CA0BhB"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EffectWithoutCauseError = exports.EVIDENCE_EFFECTS_DDL = void 0;
|
|
4
|
+
exports.isUsableCause = isUsableCause;
|
|
5
|
+
exports.ensureEffectLedger = ensureEffectLedger;
|
|
6
|
+
exports.payloadHash = payloadHash;
|
|
7
|
+
exports.recordEffect = recordEffect;
|
|
8
|
+
exports.recordUnattributedChange = recordUnattributedChange;
|
|
9
|
+
exports.listEffects = listEffects;
|
|
10
|
+
exports.changeCoverage = changeCoverage;
|
|
11
|
+
/**
|
|
12
|
+
* Every durable change, and what caused it.
|
|
13
|
+
*
|
|
14
|
+
* This is the half the system never had. Measured over ten days: 1,471 workorders ran,
|
|
15
|
+
* 1,169 of them closed as `done`, and FIVE durable effect receipts exist - all five inside
|
|
16
|
+
* one eleven-minute window a week earlier. `done` meant "the run finished", not "something
|
|
17
|
+
* changed", and nothing downstream could tell the difference. The peer system recorded
|
|
18
|
+
* 1,080 effects over the same kind of window, every one of them naming the events that
|
|
19
|
+
* caused it, and its reports are projections of that table rather than prose assembled
|
|
20
|
+
* from whatever a model happened to read.
|
|
21
|
+
*
|
|
22
|
+
* So the rule here is narrow and total:
|
|
23
|
+
*
|
|
24
|
+
* A CHANGE THAT CANNOT NAME ITS CAUSE IS NOT RECORDED AS ONE. `source_event_ids` is NOT
|
|
25
|
+
* NULL and must be non-empty, enforced by the schema rather than by callers remembering.
|
|
26
|
+
* The tempting softening - allow an empty array "for now" - is exactly how the effect
|
|
27
|
+
* table becomes a second log: it would fill with rows that prove nothing, and the first
|
|
28
|
+
* question anyone asks of it ("what made this happen?") would have no answer for most of
|
|
29
|
+
* them. If a write genuinely has no observed cause, that is worth discovering, not
|
|
30
|
+
* papering over.
|
|
31
|
+
*
|
|
32
|
+
* The kinds are a closed set for the same reason the peer's are: an open `effect_kind`
|
|
33
|
+
* column drifts into free text within a month, and then counting what the system actually
|
|
34
|
+
* did requires reading strings. Adding a kind should be a deliberate edit here.
|
|
35
|
+
*
|
|
36
|
+
* ONE TABLE, BOTH NUMBERS. A change that could not name a cause is still recorded here,
|
|
37
|
+
* marked `unattributed` and holding an empty cause list that the schema forces to stay
|
|
38
|
+
* empty. This is not the softening warned about above - `recordEffect` still refuses a
|
|
39
|
+
* causeless effect, and a writer has to call `recordUnattributedChange` by name to admit
|
|
40
|
+
* one. It is here because the failure this whole redesign keeps finding is a numerator
|
|
41
|
+
* with no denominator. Split across two tables, "every effect names its cause" is true by
|
|
42
|
+
* construction and means nothing; in one table the ratio is a single GROUP BY.
|
|
43
|
+
*
|
|
44
|
+
* WHAT THIS TABLE DOES NOT YET ANSWER, stated plainly so nobody reads more into the
|
|
45
|
+
* number than it holds: the "1,169 done, five receipts" comparison needs RUNS beside
|
|
46
|
+
* CHANGES, and runs still live in `operator_tasks`. `changeCoverage` answers "of the
|
|
47
|
+
* changes recorded, how many rest on evidence" - not "how many runs changed anything".
|
|
48
|
+
* The join that answers the second question needs the run id on both sides, and only one
|
|
49
|
+
* side carries it today.
|
|
50
|
+
*
|
|
51
|
+
* Recording the unattributed change rather than refusing the write follows the operating
|
|
52
|
+
* rule this system runs under: enforce only what is irreversible or externally visible,
|
|
53
|
+
* and make everything else loud. A task row is neither, so the ledger observes it.
|
|
54
|
+
*
|
|
55
|
+
* A CAUSE IS AN EVENT ID, and the schema checks the shape rather than trusting the helper
|
|
56
|
+
* to have filtered - `[""]`, `[null]`, `[0]` and a 200 KB string are all "non-empty
|
|
57
|
+
* arrays" and all lies. What the schema still cannot check is whether the id names an
|
|
58
|
+
* event that exists and is readable: the event index lives in a different database. A
|
|
59
|
+
* cited cause that resolves to nothing is a fabricated citation, and catching those is the
|
|
60
|
+
* next thing this needs.
|
|
61
|
+
*/
|
|
62
|
+
const node_crypto_1 = require("node:crypto");
|
|
63
|
+
const EFFECT_KINDS = [
|
|
64
|
+
'task_create',
|
|
65
|
+
'task_update',
|
|
66
|
+
'report_update',
|
|
67
|
+
'report_publish',
|
|
68
|
+
'memory_write',
|
|
69
|
+
'wiki_write',
|
|
70
|
+
];
|
|
71
|
+
const EFFECT_TARGETS = ['task', 'report_slot', 'memory', 'wiki_page'];
|
|
72
|
+
/** Long enough for any upstream id, short enough that the column cannot carry content. */
|
|
73
|
+
const MAX_EVENT_ID_LENGTH = 200;
|
|
74
|
+
const PAYLOAD_HASH_LENGTH = 32;
|
|
75
|
+
/**
|
|
76
|
+
* Whether a value can serve as a cause at all.
|
|
77
|
+
*
|
|
78
|
+
* Callers ask before writing rather than discovering it as a constraint violation,
|
|
79
|
+
* because the answer changes what they record, not whether they may proceed: a malformed
|
|
80
|
+
* cause makes a change unattributed, it does not make the change illegitimate. Legacy
|
|
81
|
+
* rows really do carry 400-character source identifiers, and refusing to let the operator
|
|
82
|
+
* update a work item because its upstream id is the wrong shape would be enforcement
|
|
83
|
+
* bought with the owner's work.
|
|
84
|
+
*/
|
|
85
|
+
function isUsableCause(value) {
|
|
86
|
+
if (typeof value !== 'string')
|
|
87
|
+
return false;
|
|
88
|
+
const trimmed = value.trim();
|
|
89
|
+
return trimmed.length > 0 && trimmed.length <= MAX_EVENT_ID_LENGTH;
|
|
90
|
+
}
|
|
91
|
+
const quoted = (values) => values.map((v) => `'${v}'`).join(', ');
|
|
92
|
+
exports.EVIDENCE_EFFECTS_DDL = `
|
|
93
|
+
CREATE TABLE IF NOT EXISTS evidence_effects (
|
|
94
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
95
|
+
run_id TEXT,
|
|
96
|
+
channel_id TEXT,
|
|
97
|
+
cause_state TEXT NOT NULL CHECK (cause_state IN ('attributed', 'unattributed')),
|
|
98
|
+
source_event_ids_json TEXT NOT NULL
|
|
99
|
+
CHECK (
|
|
100
|
+
json_valid(source_event_ids_json)
|
|
101
|
+
AND (
|
|
102
|
+
(cause_state = 'attributed' AND json_array_length(source_event_ids_json) >= 1)
|
|
103
|
+
OR (cause_state = 'unattributed' AND json_array_length(source_event_ids_json) = 0)
|
|
104
|
+
)
|
|
105
|
+
),
|
|
106
|
+
effect_kind TEXT NOT NULL CHECK (effect_kind IN (${quoted(EFFECT_KINDS)})),
|
|
107
|
+
target_type TEXT NOT NULL CHECK (target_type IN (${quoted(EFFECT_TARGETS)})),
|
|
108
|
+
target_id TEXT NOT NULL CHECK (length(trim(target_id)) > 0),
|
|
109
|
+
payload_hash TEXT NOT NULL CHECK (length(payload_hash) = ${PAYLOAD_HASH_LENGTH}),
|
|
110
|
+
created_at INTEGER NOT NULL CHECK (typeof(created_at) = 'integer' AND created_at >= 0)
|
|
111
|
+
)
|
|
112
|
+
`;
|
|
113
|
+
/**
|
|
114
|
+
* Per-element shape of the cause list.
|
|
115
|
+
*
|
|
116
|
+
* A trigger rather than a CHECK because SQLite forbids subqueries in CHECK, and checking
|
|
117
|
+
* each element needs `json_each`. Without this the column enforces only "non-empty array",
|
|
118
|
+
* which `[""]` and `[null]` and `[0]` all satisfy while naming nothing.
|
|
119
|
+
*
|
|
120
|
+
* The length bound is not cosmetic: an unbounded cause id turns an audit ledger into a
|
|
121
|
+
* content channel, which is the one thing the payload is hashed to avoid.
|
|
122
|
+
*/
|
|
123
|
+
const EVIDENCE_EFFECTS_CAUSE_TRIGGER = `
|
|
124
|
+
CREATE TRIGGER IF NOT EXISTS evidence_effects_cause_shape
|
|
125
|
+
BEFORE INSERT ON evidence_effects
|
|
126
|
+
WHEN EXISTS (
|
|
127
|
+
SELECT 1 FROM json_each(NEW.source_event_ids_json)
|
|
128
|
+
WHERE json_each.type <> 'text'
|
|
129
|
+
OR trim(json_each.value) = ''
|
|
130
|
+
OR length(json_each.value) > ${MAX_EVENT_ID_LENGTH}
|
|
131
|
+
)
|
|
132
|
+
BEGIN
|
|
133
|
+
SELECT RAISE(ABORT, 'evidence_effects: a cause must be a non-empty event id');
|
|
134
|
+
END
|
|
135
|
+
`;
|
|
136
|
+
const INDEXES = [
|
|
137
|
+
`CREATE INDEX IF NOT EXISTS idx_evidence_effects_run
|
|
138
|
+
ON evidence_effects(run_id, created_at DESC)`,
|
|
139
|
+
`CREATE INDEX IF NOT EXISTS idx_evidence_effects_target
|
|
140
|
+
ON evidence_effects(target_type, target_id, created_at DESC)`,
|
|
141
|
+
`CREATE INDEX IF NOT EXISTS idx_evidence_effects_channel
|
|
142
|
+
ON evidence_effects(channel_id, created_at DESC)`,
|
|
143
|
+
// Coverage is meant to be cheap enough that nobody has an excuse not to look.
|
|
144
|
+
`CREATE INDEX IF NOT EXISTS idx_evidence_effects_coverage
|
|
145
|
+
ON evidence_effects(created_at DESC, cause_state)`,
|
|
146
|
+
];
|
|
147
|
+
function ensureEffectLedger(adapter) {
|
|
148
|
+
adapter.prepare(exports.EVIDENCE_EFFECTS_DDL).run();
|
|
149
|
+
adapter.prepare(EVIDENCE_EFFECTS_CAUSE_TRIGGER).run();
|
|
150
|
+
for (const sql of INDEXES) {
|
|
151
|
+
adapter.prepare(sql).run();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
class EffectWithoutCauseError extends Error {
|
|
155
|
+
constructor(kind, targetId) {
|
|
156
|
+
super(`Refusing to record ${kind} on ${targetId} with no source events: a change that cannot name its cause is not an effect.`);
|
|
157
|
+
this.name = 'EffectWithoutCauseError';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.EffectWithoutCauseError = EffectWithoutCauseError;
|
|
161
|
+
/** Stable hash of what was written. The ledger proves a change happened, not what it said. */
|
|
162
|
+
function payloadHash(payload) {
|
|
163
|
+
return (0, node_crypto_1.createHash)('sha256')
|
|
164
|
+
.update(JSON.stringify(payload ?? null))
|
|
165
|
+
.digest('hex')
|
|
166
|
+
.slice(0, PAYLOAD_HASH_LENGTH);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Record a durable change.
|
|
170
|
+
*
|
|
171
|
+
* Throws rather than returning a failure when the cause is missing. A caller that wrote
|
|
172
|
+
* something and then could not say why must not proceed as if the write were accounted
|
|
173
|
+
* for - silently skipping the ledger row is how 1,169 runs closed as `done` while five
|
|
174
|
+
* receipts existed.
|
|
175
|
+
*/
|
|
176
|
+
function recordEffect(adapter, input) {
|
|
177
|
+
const sourceEventIds = [
|
|
178
|
+
...new Set(input.sourceEventIds.filter(isUsableCause).map((id) => id.trim())),
|
|
179
|
+
];
|
|
180
|
+
if (sourceEventIds.length === 0) {
|
|
181
|
+
throw new EffectWithoutCauseError(input.kind, input.targetId);
|
|
182
|
+
}
|
|
183
|
+
return insertChange(adapter, input, 'attributed', sourceEventIds);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Record a durable change that could not name what caused it.
|
|
187
|
+
*
|
|
188
|
+
* Deliberately a separate function with an uncomfortable name. Every call is an admission
|
|
189
|
+
* that the system changed something it cannot explain, and the point is that the count of
|
|
190
|
+
* these is visible next to the count of real effects rather than absent from both.
|
|
191
|
+
*/
|
|
192
|
+
function recordUnattributedChange(adapter, input) {
|
|
193
|
+
return insertChange(adapter, input, 'unattributed', []);
|
|
194
|
+
}
|
|
195
|
+
function insertChange(adapter, input, causeState, sourceEventIds) {
|
|
196
|
+
const result = adapter
|
|
197
|
+
.prepare(`INSERT INTO evidence_effects
|
|
198
|
+
(run_id, channel_id, cause_state, source_event_ids_json,
|
|
199
|
+
effect_kind, target_type, target_id, payload_hash, created_at)
|
|
200
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
201
|
+
.run(input.runId ?? null, input.channelId ?? null, causeState, JSON.stringify(sourceEventIds), input.kind, input.targetType, input.targetId, payloadHash(input.payload), input.atMs);
|
|
202
|
+
return Number(result.lastInsertRowid ?? 0);
|
|
203
|
+
}
|
|
204
|
+
/** Read effects back, newest first - the substrate a report projects from. */
|
|
205
|
+
function listEffects(adapter, query = {}) {
|
|
206
|
+
const clauses = [];
|
|
207
|
+
const params = [];
|
|
208
|
+
if (query.runId !== undefined) {
|
|
209
|
+
clauses.push('run_id = ?');
|
|
210
|
+
params.push(query.runId);
|
|
211
|
+
}
|
|
212
|
+
if (query.targetType !== undefined) {
|
|
213
|
+
clauses.push('target_type = ?');
|
|
214
|
+
params.push(query.targetType);
|
|
215
|
+
}
|
|
216
|
+
if (query.targetId !== undefined) {
|
|
217
|
+
clauses.push('target_id = ?');
|
|
218
|
+
params.push(query.targetId);
|
|
219
|
+
}
|
|
220
|
+
if (query.causeState !== undefined) {
|
|
221
|
+
clauses.push('cause_state = ?');
|
|
222
|
+
params.push(query.causeState);
|
|
223
|
+
}
|
|
224
|
+
if (query.sinceMs !== undefined) {
|
|
225
|
+
clauses.push('created_at >= ?');
|
|
226
|
+
params.push(query.sinceMs);
|
|
227
|
+
}
|
|
228
|
+
params.push(Math.min(Math.max(query.limit ?? 200, 1), 1000));
|
|
229
|
+
const rows = adapter
|
|
230
|
+
.prepare(`SELECT * FROM evidence_effects
|
|
231
|
+
${clauses.length > 0 ? `WHERE ${clauses.join(' AND ')}` : ''}
|
|
232
|
+
ORDER BY created_at DESC, id DESC
|
|
233
|
+
LIMIT ?`)
|
|
234
|
+
.all(...params);
|
|
235
|
+
return rows.map((row) => ({
|
|
236
|
+
id: Number(row.id),
|
|
237
|
+
runId: typeof row.run_id === 'string' ? row.run_id : null,
|
|
238
|
+
channelId: typeof row.channel_id === 'string' ? row.channel_id : null,
|
|
239
|
+
causeState: String(row.cause_state),
|
|
240
|
+
sourceEventIds: JSON.parse(String(row.source_event_ids_json)),
|
|
241
|
+
kind: String(row.effect_kind),
|
|
242
|
+
targetType: String(row.target_type),
|
|
243
|
+
targetId: String(row.target_id),
|
|
244
|
+
payloadHash: String(row.payload_hash),
|
|
245
|
+
atMs: Number(row.created_at),
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* How much of what the system changed rests on evidence.
|
|
250
|
+
*
|
|
251
|
+
* The single number this ledger exists to make answerable, and the one the previous shape
|
|
252
|
+
* of the system could not produce at all.
|
|
253
|
+
*/
|
|
254
|
+
function changeCoverage(adapter, sinceMs, targetType) {
|
|
255
|
+
// Coverage must describe the same population as the rows a caller is looking at, or the
|
|
256
|
+
// two halves of one answer disagree and the reader cannot tell which is wrong.
|
|
257
|
+
const clauses = [];
|
|
258
|
+
const params = [];
|
|
259
|
+
if (sinceMs !== undefined) {
|
|
260
|
+
clauses.push('created_at >= ?');
|
|
261
|
+
params.push(sinceMs);
|
|
262
|
+
}
|
|
263
|
+
if (targetType !== undefined) {
|
|
264
|
+
clauses.push('target_type = ?');
|
|
265
|
+
params.push(targetType);
|
|
266
|
+
}
|
|
267
|
+
const rows = adapter
|
|
268
|
+
.prepare(`SELECT cause_state, COUNT(*) AS n FROM evidence_effects
|
|
269
|
+
${clauses.length > 0 ? `WHERE ${clauses.join(' AND ')}` : ''}
|
|
270
|
+
GROUP BY cause_state`)
|
|
271
|
+
.all(...params);
|
|
272
|
+
const coverage = { attributed: 0, unattributed: 0 };
|
|
273
|
+
for (const row of rows) {
|
|
274
|
+
if (row.cause_state === 'attributed')
|
|
275
|
+
coverage.attributed = Number(row.n);
|
|
276
|
+
if (row.cause_state === 'unattributed')
|
|
277
|
+
coverage.unattributed = Number(row.n);
|
|
278
|
+
}
|
|
279
|
+
return coverage;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","sourceRoot":"","sources":["../../src/evidence/effects.ts"],"names":[],"mappings":";;;AAiIA,sCAIC;AAqED,gDAMC;AAYD,kCAKC;AAUD,oCAQC;AASD,4DAEC;AAuCD,kCA8CC;AAeD,wCA8BC;AAhYD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,6CAAyC;AAqDzC,MAAM,YAAY,GAA0B;IAC1C,aAAa;IACb,aAAa;IACb,eAAe;IACf,gBAAgB;IAChB,cAAc;IACd,YAAY;CACb,CAAC;AAEF,MAAM,cAAc,GAA4B,CAAC,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAE/F,0FAA0F;AAC1F,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;;;;;;;;;GASG;AACH,SAAgB,aAAa,CAAC,KAAgC;IAC5D,IAAI,OAAO,KAAK,KAAK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;IACxF,+EAA+E;IAC/E,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1B,CAAC;IACD,MAAM,IAAI,GAAG,OAAO;SACjB,OAAO,CACN;UACI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;6BACvC,CACxB;SACA,GAAG,CAAC,GAAG,MAAM,CAAmC,CAAC;IACpD,MAAM,QAAQ,GAAmB,EAAE,UAAU,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;IACpE,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,CAAC,WAAW,KAAK,YAAY;YAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1E,IAAI,GAAG,CAAC,WAAW,KAAK,cAAc;YAAE,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live grant: which connectors and channels this system was told to look at.
|
|
3
|
+
*
|
|
4
|
+
* This file used to also carry a boolean visibility predicate and a SQL reader of its own -
|
|
5
|
+
* a third and fourth compiled copy of a rule whose whole point was that there be one. Both
|
|
6
|
+
* had zero callers, which is worse than a live copy rather than better: nothing exercises
|
|
7
|
+
* them, so nothing notices when they drift, and they sit there looking authoritative until
|
|
8
|
+
* someone reads one and believes it. They are deleted. The rule lives in mama-core's
|
|
9
|
+
* channel-grant.ts, where its two used forms sit adjacent with a differential between them.
|
|
10
|
+
*
|
|
11
|
+
* What remains here is the part that is genuinely local: turning the owner's connector
|
|
12
|
+
* config into a grant, and narrowing that grant to what one envelope may read.
|
|
13
|
+
*
|
|
14
|
+
* WHY A GRANT AT ALL. The path it replaced returned ZERO rows out of 30,671 in production,
|
|
15
|
+
* blocked four separate ways at once: a project window whose column was null on every row,
|
|
16
|
+
* a tenant partition with exactly one value, a scope-id namespace that shared nothing with
|
|
17
|
+
* the one callers hold, and a legacy escape hatch gated shut whenever any specific scope
|
|
18
|
+
* was present - which is always. Each was individually fatal, so this is a replacement and
|
|
19
|
+
* not a repair.
|
|
20
|
+
*
|
|
21
|
+
* An event is visible when the caller was granted its connector and its channel. Both come
|
|
22
|
+
* from `(source_connector, channel)`, which every indexed row carries with no nulls, and
|
|
23
|
+
* which is the SAME key the connector config declares its channels under. The old path
|
|
24
|
+
* invented a third naming layer on top of that key, populated it 37% of the time, and then
|
|
25
|
+
* filtered on it.
|
|
26
|
+
*/
|
|
27
|
+
import type { ChannelGrant } from '@jungjaehoon/mama-core/context-compile';
|
|
28
|
+
/**
|
|
29
|
+
* Build a grant from the connector config, which already names every channel.
|
|
30
|
+
*
|
|
31
|
+
* A connector present with an EMPTY channel list is denied rather than granted everything -
|
|
32
|
+
* that rule is stated and enforced in `isChannelGranted`, which is the only place it lives.
|
|
33
|
+
*/
|
|
34
|
+
export declare function grantFromConnectorConfig(config: unknown): ChannelGrant;
|
|
35
|
+
/**
|
|
36
|
+
* The live grant, read fresh on every call.
|
|
37
|
+
*
|
|
38
|
+
* Not cached at boot: the owner adds and removes channels while the daemon runs, and a
|
|
39
|
+
* grant captured once would keep reading a channel after it was removed - the failure
|
|
40
|
+
* mode where turning something off does not turn it off.
|
|
41
|
+
*/
|
|
42
|
+
export declare function liveBoundaryChannels(): ChannelGrant;
|
|
43
|
+
/**
|
|
44
|
+
* Narrow the configured grant to what THIS envelope may read.
|
|
45
|
+
*
|
|
46
|
+
* Two independent narrowings, and the second is the whole reason this exists rather than a
|
|
47
|
+
* one-line filter:
|
|
48
|
+
*
|
|
49
|
+
* 1. Connector - the envelope's `raw_connectors` is the standing permission.
|
|
50
|
+
*
|
|
51
|
+
* 2. CHANNEL - when the envelope names channel scopes, only those channels are readable.
|
|
52
|
+
* Raw visibility used to be decided by the scope columns, so a per-message envelope
|
|
53
|
+
* scoped to one channel could not reach another. Deciding it by connector alone silently
|
|
54
|
+
* dropped that isolation: reactive envelopes for two channels of the same connector
|
|
55
|
+
* carry identical `raw_connectors`, so every such run could have compiled 500-character
|
|
56
|
+
* excerpts out of every other configured channel of that connector. The scope columns
|
|
57
|
+
* were the wrong mechanism - populated on 37% of rows in three namespaces - but the
|
|
58
|
+
* isolation they attempted is real, and it belongs here, where the envelope's own
|
|
59
|
+
* channel scopes state it exactly.
|
|
60
|
+
*
|
|
61
|
+
* An envelope with no channel scope is a run that was never bound to one (a report, a
|
|
62
|
+
* scheduled worker), and it keeps the connector-level ceiling.
|
|
63
|
+
*
|
|
64
|
+
* CALLERS MUST PASS THE ENVELOPE'S OWN SCOPES, never a caller-requested subset. A request
|
|
65
|
+
* may narrow what it asks for; it must not be able to widen its grant by asking for less.
|
|
66
|
+
* Two surfaces got that wrong before it was written down here.
|
|
67
|
+
*/
|
|
68
|
+
export declare function narrowGrantToEnvelope(configured: ChannelGrant, visibility: {
|
|
69
|
+
connectors: readonly string[];
|
|
70
|
+
scopes: readonly {
|
|
71
|
+
kind: string;
|
|
72
|
+
id: string;
|
|
73
|
+
}[];
|
|
74
|
+
}): ChannelGrant;
|
|
75
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/evidence/read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAG3E;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAqBtE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAMnD;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,YAAY,EACxB,UAAU,EAAE;IACV,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,MAAM,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACjD,GACA,YAAY,CA0Bd"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grantFromConnectorConfig = grantFromConnectorConfig;
|
|
4
|
+
exports.liveBoundaryChannels = liveBoundaryChannels;
|
|
5
|
+
exports.narrowGrantToEnvelope = narrowGrantToEnvelope;
|
|
6
|
+
const config_loader_js_1 = require("../connectors/config-loader.js");
|
|
7
|
+
/**
|
|
8
|
+
* Build a grant from the connector config, which already names every channel.
|
|
9
|
+
*
|
|
10
|
+
* A connector present with an EMPTY channel list is denied rather than granted everything -
|
|
11
|
+
* that rule is stated and enforced in `isChannelGranted`, which is the only place it lives.
|
|
12
|
+
*/
|
|
13
|
+
function grantFromConnectorConfig(config) {
|
|
14
|
+
const grant = {};
|
|
15
|
+
if (config === null || typeof config !== 'object') {
|
|
16
|
+
return grant;
|
|
17
|
+
}
|
|
18
|
+
for (const [connector, raw] of Object.entries(config)) {
|
|
19
|
+
if (raw === null || typeof raw !== 'object') {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const entry = raw;
|
|
23
|
+
// A disabled connector is not a grant. Reading its history because rows survive
|
|
24
|
+
// disabling would make "off" mean "off for new data only".
|
|
25
|
+
if (entry.enabled === false) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (entry.channels === null || typeof entry.channels !== 'object') {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
grant[connector] = Object.keys(entry.channels);
|
|
32
|
+
}
|
|
33
|
+
return grant;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The live grant, read fresh on every call.
|
|
37
|
+
*
|
|
38
|
+
* Not cached at boot: the owner adds and removes channels while the daemon runs, and a
|
|
39
|
+
* grant captured once would keep reading a channel after it was removed - the failure
|
|
40
|
+
* mode where turning something off does not turn it off.
|
|
41
|
+
*/
|
|
42
|
+
function liveBoundaryChannels() {
|
|
43
|
+
const loaded = (0, config_loader_js_1.loadConnectorConfig)();
|
|
44
|
+
// A config that cannot be read is not a grant. Falling back to "everything" on a parse
|
|
45
|
+
// error is how a read path ends up wider precisely when the configuration is broken.
|
|
46
|
+
if (!loaded.ok)
|
|
47
|
+
return {};
|
|
48
|
+
return grantFromConnectorConfig(loaded.config);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Narrow the configured grant to what THIS envelope may read.
|
|
52
|
+
*
|
|
53
|
+
* Two independent narrowings, and the second is the whole reason this exists rather than a
|
|
54
|
+
* one-line filter:
|
|
55
|
+
*
|
|
56
|
+
* 1. Connector - the envelope's `raw_connectors` is the standing permission.
|
|
57
|
+
*
|
|
58
|
+
* 2. CHANNEL - when the envelope names channel scopes, only those channels are readable.
|
|
59
|
+
* Raw visibility used to be decided by the scope columns, so a per-message envelope
|
|
60
|
+
* scoped to one channel could not reach another. Deciding it by connector alone silently
|
|
61
|
+
* dropped that isolation: reactive envelopes for two channels of the same connector
|
|
62
|
+
* carry identical `raw_connectors`, so every such run could have compiled 500-character
|
|
63
|
+
* excerpts out of every other configured channel of that connector. The scope columns
|
|
64
|
+
* were the wrong mechanism - populated on 37% of rows in three namespaces - but the
|
|
65
|
+
* isolation they attempted is real, and it belongs here, where the envelope's own
|
|
66
|
+
* channel scopes state it exactly.
|
|
67
|
+
*
|
|
68
|
+
* An envelope with no channel scope is a run that was never bound to one (a report, a
|
|
69
|
+
* scheduled worker), and it keeps the connector-level ceiling.
|
|
70
|
+
*
|
|
71
|
+
* CALLERS MUST PASS THE ENVELOPE'S OWN SCOPES, never a caller-requested subset. A request
|
|
72
|
+
* may narrow what it asks for; it must not be able to widen its grant by asking for less.
|
|
73
|
+
* Two surfaces got that wrong before it was written down here.
|
|
74
|
+
*/
|
|
75
|
+
function narrowGrantToEnvelope(configured, visibility) {
|
|
76
|
+
// Channel scope ids are `<connector>:<channelId>` (deriveMemoryScopes). Split on the
|
|
77
|
+
// FIRST separator only: channel ids contain colons of their own.
|
|
78
|
+
const scopedChannels = new Map();
|
|
79
|
+
for (const scope of visibility.scopes) {
|
|
80
|
+
if (scope.kind !== 'channel')
|
|
81
|
+
continue;
|
|
82
|
+
const separator = scope.id.indexOf(':');
|
|
83
|
+
if (separator <= 0)
|
|
84
|
+
continue;
|
|
85
|
+
const connector = scope.id.slice(0, separator);
|
|
86
|
+
const channelId = scope.id.slice(separator + 1);
|
|
87
|
+
if (channelId.length === 0)
|
|
88
|
+
continue;
|
|
89
|
+
const existing = scopedChannels.get(connector) ?? new Set();
|
|
90
|
+
existing.add(channelId);
|
|
91
|
+
scopedChannels.set(connector, existing);
|
|
92
|
+
}
|
|
93
|
+
const narrowed = {};
|
|
94
|
+
for (const [connector, channels] of Object.entries(configured)) {
|
|
95
|
+
if (!visibility.connectors.includes(connector))
|
|
96
|
+
continue;
|
|
97
|
+
const bound = scopedChannels.get(connector);
|
|
98
|
+
// A channel scope naming no configured channel leaves the connector with an empty
|
|
99
|
+
// grant, which reads nothing. That is the correct answer: the run is bound to a channel
|
|
100
|
+
// this system was not told to look at.
|
|
101
|
+
narrowed[connector] = bound ? channels.filter((channel) => bound.has(channel)) : channels;
|
|
102
|
+
}
|
|
103
|
+
return narrowed;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/evidence/read.ts"],"names":[],"mappings":";;AAmCA,4DAqBC;AASD,oDAMC;AA2BD,sDAgCC;AAvGD,qEAAqE;AAErE;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,MAAe;IACtD,MAAM,KAAK,GAAiB,EAAE,CAAC;IAC/B,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAiC,CAAC,EAAE,CAAC;QACjF,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5C,SAAS;QACX,CAAC;QACD,MAAM,KAAK,GAAG,GAAgD,CAAC;QAC/D,gFAAgF;QAChF,2DAA2D;QAC3D,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC5B,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAClE,SAAS;QACX,CAAC;QACD,KAAK,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAkB,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB;IAClC,MAAM,MAAM,GAAG,IAAA,sCAAmB,GAAE,CAAC;IACrC,uFAAuF;IACvF,qFAAqF;IACrF,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,O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FAAkF;QAClF,wFAAwF;QACxF,uCAAuC;QACvC,QAAQ,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC5F,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -5,14 +5,34 @@
|
|
|
5
5
|
* Platform-specific behavior is implemented via abstract methods and properties.
|
|
6
6
|
*/
|
|
7
7
|
import type { Gateway, GatewayEvent, GatewayEventHandler, GatewayConfig, MessageSource } from './types.js';
|
|
8
|
-
import {
|
|
8
|
+
import type { SessionDirectory, TurnProcessor } from './turn-contract.js';
|
|
9
9
|
export interface BaseGatewayOptions {
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* How a turn is processed. Required, because this is what a user-facing surface
|
|
12
|
+
* actually needs; the concrete router is an extra capability, not the dependency.
|
|
13
|
+
*/
|
|
14
|
+
turnProcessor: TurnProcessor;
|
|
15
|
+
/**
|
|
16
|
+
* Optional, and narrow. Only surfaces that read session data for their own display
|
|
17
|
+
* concerns - naming a channel, listing what is active - ask for this. It is not a
|
|
18
|
+
* router: a surface that serves turns cannot reach past the contract through it.
|
|
19
|
+
*/
|
|
20
|
+
sessionDirectory?: SessionDirectory;
|
|
11
21
|
config?: Partial<GatewayConfig>;
|
|
12
22
|
}
|
|
13
23
|
export declare abstract class BaseGateway implements Gateway {
|
|
14
24
|
abstract readonly source: MessageSource;
|
|
15
|
-
protected
|
|
25
|
+
protected sessionDirectory?: SessionDirectory;
|
|
26
|
+
/**
|
|
27
|
+
* The turn seam, shared by every user-facing surface.
|
|
28
|
+
*
|
|
29
|
+
* Telegram, Discord and Slack are ONE role - the place a person reaches the agent - so
|
|
30
|
+
* the boundary belongs here rather than to any one of them. Connectors are not turn
|
|
31
|
+
* sources at all; they are data the agent reads, and they never pass through here.
|
|
32
|
+
*
|
|
33
|
+
* Required: a surface that serves turns needs this and nothing else.
|
|
34
|
+
*/
|
|
35
|
+
protected turnProcessor: TurnProcessor;
|
|
16
36
|
protected eventHandlers: GatewayEventHandler[];
|
|
17
37
|
protected connected: boolean;
|
|
18
38
|
constructor(options: BaseGatewayOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-gateway.d.ts","sourceRoot":"","sources":["../../src/gateways/base-gateway.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,aAAa,EACd,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"base-gateway.d.ts","sourceRoot":"","sources":["../../src/gateways/base-gateway.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,aAAa,EAAE,aAAa,CAAC;IAC7B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACjC;AAED,8BAAsB,WAAY,YAAW,OAAO;IAClD,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAExC,SAAS,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAC9C;;;;;;;;OAQG;IACH,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,SAAS,CAAC,aAAa,EAAE,mBAAmB,EAAE,CAAM;IACpD,SAAS,CAAC,SAAS,UAAS;gBAEhB,OAAO,EAAE,kBAAkB;IASvC,QAAQ,CAAC,K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