@ouro.bot/cli 0.1.0-alpha.47 → 0.1.0-alpha.471
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 +132 -19
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +2 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
- package/changelog.json +2998 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +140 -0
- package/dist/arc/episodes.js +117 -0
- package/dist/arc/intentions.js +133 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +237 -0
- package/dist/arc/packets.js +193 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +65 -0
- package/dist/heart/active-work.js +832 -0
- package/dist/heart/agent-entry.js +58 -3
- package/dist/heart/attachments/image-normalize.js +194 -0
- package/dist/heart/attachments/materialize.js +97 -0
- package/dist/heart/attachments/originals.js +88 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/sources/adapter.js +2 -0
- package/dist/heart/attachments/sources/bluebubbles.js +156 -0
- package/dist/heart/attachments/sources/cli-local-file.js +78 -0
- package/dist/heart/attachments/sources/index.js +16 -0
- package/dist/heart/attachments/store.js +103 -0
- package/dist/heart/attachments/types.js +93 -0
- package/dist/heart/auth/auth-flow.js +426 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/commitments.js +111 -0
- package/dist/heart/config-registry.js +304 -0
- package/dist/heart/config.js +110 -128
- package/dist/heart/core.js +745 -227
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +490 -0
- package/dist/heart/daemon/agent-discovery.js +79 -3
- package/dist/heart/daemon/agent-service.js +360 -0
- package/dist/heart/daemon/agentic-repair.js +216 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +631 -0
- package/dist/heart/daemon/cli-exec.js +6635 -0
- package/dist/heart/daemon/cli-help.js +482 -0
- package/dist/heart/daemon/cli-parse.js +1490 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +561 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/connect-bay.js +323 -0
- package/dist/heart/daemon/daemon-cli.js +29 -1616
- package/dist/heart/daemon/daemon-entry.js +345 -3
- package/dist/heart/daemon/daemon-health.js +141 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +190 -12
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +677 -58
- package/dist/heart/daemon/dns-workflow.js +365 -0
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +486 -0
- package/dist/heart/daemon/health-monitor.js +92 -1
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
- package/dist/heart/daemon/http-health-probe.js +80 -0
- package/dist/heart/daemon/human-command-screens.js +234 -0
- package/dist/heart/daemon/human-readiness.js +114 -0
- package/dist/heart/daemon/inner-status.js +89 -0
- package/dist/heart/daemon/interactive-repair.js +394 -0
- package/dist/heart/daemon/launchd.js +25 -5
- package/dist/heart/daemon/log-tailer.js +82 -12
- package/dist/heart/daemon/logs-prune.js +110 -0
- package/dist/heart/daemon/message-router.js +2 -2
- package/dist/heart/daemon/os-cron-deps.js +134 -0
- package/dist/heart/daemon/ouro-bot-entry.js +4 -2
- package/dist/heart/daemon/ouro-entry.js +3 -1
- package/dist/heart/daemon/process-manager.js +214 -0
- package/dist/heart/daemon/provider-discovery.js +137 -0
- package/dist/heart/daemon/provider-ping-progress.js +83 -0
- package/dist/heart/daemon/pulse.js +475 -0
- package/dist/heart/daemon/readiness-repair.js +365 -0
- package/dist/heart/daemon/run-hooks.js +2 -0
- package/dist/heart/daemon/runtime-logging.js +67 -16
- package/dist/heart/daemon/runtime-metadata.js +73 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +178 -37
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +109 -4
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +264 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/terminal-ui.js +499 -0
- package/dist/heart/daemon/thoughts.js +149 -10
- package/dist/heart/daemon/up-progress.js +366 -0
- package/dist/heart/daemon/vault-items.js +56 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/habits/habit-migration.js +189 -0
- package/dist/heart/habits/habit-parser.js +140 -0
- package/dist/heart/habits/habit-runtime-state.js +100 -0
- package/dist/heart/habits/habit-scheduler.js +372 -0
- package/dist/heart/{daemon → hatch}/hatch-flow.js +52 -117
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
- package/dist/heart/{daemon → hatch}/specialist-prompt.js +12 -9
- package/dist/heart/{daemon → hatch}/specialist-tools.js +35 -12
- package/dist/heart/identity.js +201 -66
- package/dist/heart/kept-notes.js +357 -0
- package/dist/heart/kicks.js +1 -1
- package/dist/heart/machine-identity.js +161 -0
- package/dist/heart/mcp/mcp-server.js +653 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +59 -0
- package/dist/heart/outlook/outlook-http-hooks.js +66 -0
- package/dist/heart/outlook/outlook-http-response.js +7 -0
- package/dist/heart/outlook/outlook-http-routes.js +244 -0
- package/dist/heart/outlook/outlook-http-static.js +99 -0
- package/dist/heart/outlook/outlook-http-transport.js +116 -0
- package/dist/heart/outlook/outlook-http.js +99 -0
- package/dist/heart/outlook/outlook-read.js +31 -0
- package/dist/heart/outlook/outlook-types.js +27 -0
- package/dist/heart/outlook/outlook-view.js +195 -0
- package/dist/heart/outlook/readers/agent-machine.js +359 -0
- package/dist/heart/outlook/readers/continuity-readers.js +332 -0
- package/dist/heart/outlook/readers/mail.js +340 -0
- package/dist/heart/outlook/readers/runtime-readers.js +644 -0
- package/dist/heart/outlook/readers/sessions.js +232 -0
- package/dist/heart/outlook/readers/shared.js +111 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +255 -0
- package/dist/heart/provider-credentials.js +424 -0
- package/dist/heart/provider-failover.js +266 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +262 -0
- package/dist/heart/provider-state.js +216 -0
- package/dist/heart/provider-visibility.js +188 -0
- package/dist/heart/providers/anthropic-token.js +131 -0
- package/dist/heart/providers/anthropic.js +193 -55
- package/dist/heart/providers/azure.js +103 -12
- package/dist/heart/providers/error-classification.js +63 -0
- package/dist/heart/providers/github-copilot.js +145 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +29 -7
- package/dist/heart/providers/openai-codex.js +62 -38
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +260 -0
- package/dist/heart/sense-truth.js +11 -4
- package/dist/heart/session-activity.js +190 -0
- package/dist/heart/session-events.js +855 -0
- package/dist/heart/session-transcript.js +167 -0
- package/dist/heart/start-of-turn-packet.js +345 -0
- package/dist/heart/streaming.js +36 -27
- package/dist/heart/sync.js +332 -0
- package/dist/heart/target-resolution.js +127 -0
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/tool-activity-callbacks.js +36 -0
- package/dist/heart/tool-description.js +135 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +361 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +1 -1
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/versioning/ouro-path-installer.js +425 -0
- package/dist/heart/versioning/ouro-version-manager.js +295 -0
- package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
- package/dist/heart/{daemon → versioning}/update-checker.js +5 -1
- package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
- package/dist/mailroom/attention.js +167 -0
- package/dist/mailroom/autonomy.js +209 -0
- package/dist/mailroom/blob-store.js +302 -0
- package/dist/mailroom/core.js +658 -0
- package/dist/mailroom/entry.js +160 -0
- package/dist/mailroom/file-store.js +393 -0
- package/dist/mailroom/mbox-import.js +136 -0
- package/dist/mailroom/outbound.js +360 -0
- package/dist/mailroom/policy.js +263 -0
- package/dist/mailroom/reader.js +170 -0
- package/dist/mailroom/smtp-ingress.js +176 -0
- package/dist/mailroom/source-state.js +176 -0
- package/dist/mailroom/travel-extract.js +89 -0
- package/dist/mind/bundle-manifest.js +7 -1
- package/dist/mind/context.js +132 -93
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +74 -93
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/friends/channel.js +30 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +38 -1
- package/dist/mind/friends/store-file.js +39 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +2 -2
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +66 -7
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +978 -169
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/scrutiny.js +173 -0
- package/dist/nerves/cli-logging.js +7 -1
- package/dist/nerves/coverage/audit-rules.js +15 -6
- package/dist/nerves/coverage/audit.js +28 -2
- package/dist/nerves/coverage/cli.js +1 -1
- package/dist/nerves/coverage/contract.js +5 -5
- package/dist/nerves/coverage/file-completeness.js +84 -5
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +224 -4
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/redact.js +79 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/outlook-ui/assets/index-BPr5vNuM.css +1 -0
- package/dist/outlook-ui/assets/index-BbOjyIms.js +61 -0
- package/dist/outlook-ui/index.html +15 -0
- package/dist/repertoire/ado-client.js +15 -56
- package/dist/repertoire/ado-semantic.js +11 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +774 -0
- package/dist/repertoire/bundle-templates.js +72 -0
- package/dist/repertoire/bw-installer.js +180 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +330 -0
- package/dist/repertoire/coding/feedback.js +197 -30
- package/dist/repertoire/coding/manager.js +158 -9
- package/dist/repertoire/coding/spawner.js +55 -9
- package/dist/repertoire/coding/tools.js +170 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +111 -0
- package/dist/repertoire/duffel-client.js +185 -0
- package/dist/repertoire/github-client.js +14 -55
- package/dist/repertoire/graph-client.js +11 -52
- package/dist/repertoire/guardrails.js +396 -0
- package/dist/repertoire/mcp-client.js +255 -0
- package/dist/repertoire/mcp-manager.js +305 -0
- package/dist/repertoire/mcp-tools.js +63 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +15 -24
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tasks/board.js +43 -5
- package/dist/repertoire/tasks/fix.js +182 -0
- package/dist/repertoire/tasks/index.js +37 -4
- package/dist/repertoire/tasks/lifecycle.js +2 -2
- package/dist/repertoire/tasks/parser.js +3 -2
- package/dist/repertoire/tasks/scanner.js +194 -37
- package/dist/repertoire/tasks/transitions.js +16 -78
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-base.js +44 -740
- package/dist/repertoire/tools-bluebubbles.js +1 -0
- package/dist/repertoire/tools-bridge.js +141 -0
- package/dist/repertoire/tools-bundle.js +984 -0
- package/dist/repertoire/tools-config.js +185 -0
- package/dist/repertoire/tools-continuity.js +248 -0
- package/dist/repertoire/tools-credential.js +381 -0
- package/dist/repertoire/tools-files.js +342 -0
- package/dist/repertoire/tools-flight.js +224 -0
- package/dist/repertoire/tools-flow.js +105 -0
- package/dist/repertoire/tools-github.js +1 -7
- package/dist/repertoire/tools-mail.js +795 -0
- package/dist/repertoire/tools-notes.js +376 -0
- package/dist/repertoire/tools-session.js +739 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +180 -0
- package/dist/repertoire/tools-surface.js +243 -0
- package/dist/repertoire/tools-teams.js +9 -39
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools.js +144 -113
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +131 -0
- package/dist/repertoire/vault-setup.js +246 -0
- package/dist/repertoire/vault-unlock.js +561 -0
- package/dist/scripts/claude-code-hook.js +41 -0
- package/dist/scripts/claude-code-stop-hook.js +47 -0
- package/dist/senses/attention-queue.js +116 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/bluebubbles/attachment-download.js +137 -0
- package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +219 -18
- package/dist/senses/bluebubbles/entry.js +73 -0
- package/dist/senses/{bluebubbles-inbound-log.js → bluebubbles/inbound-log.js} +7 -3
- package/dist/senses/bluebubbles/index.js +1620 -0
- package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +33 -12
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +3 -3
- package/dist/senses/bluebubbles/replay.js +129 -0
- package/dist/senses/{bluebubbles-runtime-state.js → bluebubbles/runtime-state.js} +2 -2
- package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
- package/dist/senses/cli/bracketed-paste.js +82 -0
- package/dist/senses/cli/image-paste.js +287 -0
- package/dist/senses/cli/image-ref-navigation.js +75 -0
- package/dist/senses/cli/ink-app.js +156 -0
- package/dist/senses/cli/inline-diff.js +64 -0
- package/dist/senses/cli/input-keys.js +174 -0
- package/dist/senses/cli/kill-ring.js +86 -0
- package/dist/senses/cli/message-list.js +51 -0
- package/dist/senses/cli/ouro-tui.js +605 -0
- package/dist/senses/cli/spinner-imperative.js +135 -0
- package/dist/senses/cli/spinner.js +101 -0
- package/dist/senses/cli/status-line.js +60 -0
- package/dist/senses/cli/streaming-markdown.js +526 -0
- package/dist/senses/cli/tool-display.js +83 -0
- package/dist/senses/cli/tool-render.js +85 -0
- package/dist/senses/cli/tui-store.js +240 -0
- package/dist/senses/cli/virtual-list.js +35 -0
- package/dist/senses/cli-entry.js +60 -8
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +516 -211
- package/dist/senses/commands.js +66 -3
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +97 -17
- package/dist/senses/inner-dialog.js +404 -14
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +232 -0
- package/dist/senses/pipeline.js +533 -72
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +205 -0
- package/dist/senses/surface-tool.js +68 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +413 -163
- package/dist/senses/trust-gate.js +5 -5
- package/package.json +37 -7
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +117 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +101 -0
- package/skills/travel-planning.md +138 -0
- package/dist/heart/daemon/ouro-path-installer.js +0 -178
- package/dist/heart/daemon/subagent-installer.js +0 -166
- package/dist/mind/associative-recall.js +0 -209
- package/dist/senses/bluebubbles-entry.js +0 -13
- package/dist/senses/bluebubbles.js +0 -1028
- package/dist/senses/debug-activity.js +0 -127
- package/subagents/README.md +0 -86
- package/subagents/work-doer.md +0 -237
- package/subagents/work-merger.md +0 -618
- package/subagents/work-planner.md +0 -390
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
- /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
- /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
- /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
- /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.parseMailroomEntryArgs = parseMailroomEntryArgs;
|
|
37
|
+
exports.runMailroomEntry = runMailroomEntry;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const storage_blob_1 = require("@azure/storage-blob");
|
|
40
|
+
const identity_1 = require("@azure/identity");
|
|
41
|
+
const runtime_1 = require("../nerves/runtime");
|
|
42
|
+
const blob_store_1 = require("./blob-store");
|
|
43
|
+
const file_store_1 = require("./file-store");
|
|
44
|
+
const smtp_ingress_1 = require("./smtp-ingress");
|
|
45
|
+
const KEY_VALUE_ARGS = new Map([
|
|
46
|
+
["registry", "--registry"],
|
|
47
|
+
["registry-base64", "--registry-base64"],
|
|
48
|
+
["store", "--store"],
|
|
49
|
+
["azure-account-url", "--azure-account-url"],
|
|
50
|
+
["azure-container", "--azure-container"],
|
|
51
|
+
["azure-managed-identity-client-id", "--azure-managed-identity-client-id"],
|
|
52
|
+
["smtp-port", "--smtp-port"],
|
|
53
|
+
["http-port", "--http-port"],
|
|
54
|
+
["host", "--host"],
|
|
55
|
+
]);
|
|
56
|
+
function expandKeyValueArgs(args) {
|
|
57
|
+
const expanded = [];
|
|
58
|
+
for (const arg of args) {
|
|
59
|
+
const equalsIndex = arg.indexOf("=");
|
|
60
|
+
if (!arg.startsWith("--") && equalsIndex > 0) {
|
|
61
|
+
const key = arg.slice(0, equalsIndex).trim();
|
|
62
|
+
const flag = KEY_VALUE_ARGS.get(key);
|
|
63
|
+
if (flag) {
|
|
64
|
+
expanded.push(flag, arg.slice(equalsIndex + 1));
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
expanded.push(arg);
|
|
69
|
+
}
|
|
70
|
+
return expanded;
|
|
71
|
+
}
|
|
72
|
+
function optionalValue(args, flag) {
|
|
73
|
+
const index = args.indexOf(flag);
|
|
74
|
+
return index === -1 ? undefined : args[index + 1];
|
|
75
|
+
}
|
|
76
|
+
function optionalNumber(args, flag, fallback) {
|
|
77
|
+
const index = args.indexOf(flag);
|
|
78
|
+
if (index === -1)
|
|
79
|
+
return fallback;
|
|
80
|
+
const value = Number.parseInt(args[index + 1] ?? "", 10);
|
|
81
|
+
if (!Number.isInteger(value) || value < 0 || value > 65535) {
|
|
82
|
+
throw new Error(`${flag} must be a TCP port`);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function optionalString(args, flag, fallback) {
|
|
87
|
+
return optionalValue(args, flag) ?? fallback;
|
|
88
|
+
}
|
|
89
|
+
function parseMailroomEntryArgs(args) {
|
|
90
|
+
const expanded = expandKeyValueArgs(args);
|
|
91
|
+
const storePath = optionalValue(expanded, "--store");
|
|
92
|
+
const azureAccountUrl = optionalValue(expanded, "--azure-account-url");
|
|
93
|
+
if (!storePath && !azureAccountUrl) {
|
|
94
|
+
throw new Error("Missing --store or --azure-account-url");
|
|
95
|
+
}
|
|
96
|
+
const registryPath = optionalValue(expanded, "--registry");
|
|
97
|
+
const registryBase64 = optionalValue(expanded, "--registry-base64");
|
|
98
|
+
if (!registryPath && !registryBase64) {
|
|
99
|
+
throw new Error("Missing --registry or --registry-base64");
|
|
100
|
+
}
|
|
101
|
+
const parsed = {
|
|
102
|
+
...(registryPath ? { registryPath } : {}),
|
|
103
|
+
...(registryBase64 ? { registryBase64 } : {}),
|
|
104
|
+
...(storePath ? { storePath } : {}),
|
|
105
|
+
...(azureAccountUrl ? { azureAccountUrl } : {}),
|
|
106
|
+
azureContainer: optionalString(expanded, "--azure-container", "mailroom"),
|
|
107
|
+
...(optionalValue(expanded, "--azure-managed-identity-client-id") ? { azureManagedIdentityClientId: optionalValue(expanded, "--azure-managed-identity-client-id") } : {}),
|
|
108
|
+
smtpPort: optionalNumber(expanded, "--smtp-port", 2525),
|
|
109
|
+
httpPort: optionalNumber(expanded, "--http-port", 8080),
|
|
110
|
+
host: optionalString(expanded, "--host", "0.0.0.0"),
|
|
111
|
+
};
|
|
112
|
+
(0, runtime_1.emitNervesEvent)({
|
|
113
|
+
component: "senses",
|
|
114
|
+
event: "senses.mail_entry_args_parsed",
|
|
115
|
+
message: "mailroom entry args parsed",
|
|
116
|
+
meta: { registryPath: parsed.registryPath ?? null, registryBase64: parsed.registryBase64 ? "present" : null, storePath: parsed.storePath ?? null, azureAccountUrl: parsed.azureAccountUrl ?? null, azureContainer: parsed.azureContainer, azureManagedIdentityClientId: parsed.azureManagedIdentityClientId ? "present" : null, smtpPort: parsed.smtpPort, httpPort: parsed.httpPort },
|
|
117
|
+
});
|
|
118
|
+
return parsed;
|
|
119
|
+
}
|
|
120
|
+
function createStore(parsed) {
|
|
121
|
+
if (parsed.azureAccountUrl) {
|
|
122
|
+
const credential = parsed.azureManagedIdentityClientId
|
|
123
|
+
? new identity_1.DefaultAzureCredential({ managedIdentityClientId: parsed.azureManagedIdentityClientId })
|
|
124
|
+
: new identity_1.DefaultAzureCredential();
|
|
125
|
+
return new blob_store_1.AzureBlobMailroomStore({
|
|
126
|
+
serviceClient: new storage_blob_1.BlobServiceClient(parsed.azureAccountUrl, credential),
|
|
127
|
+
containerName: parsed.azureContainer,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return new file_store_1.FileMailroomStore({ rootDir: parsed.storePath });
|
|
131
|
+
}
|
|
132
|
+
function readRegistry(parsed) {
|
|
133
|
+
if (parsed.registryBase64) {
|
|
134
|
+
return JSON.parse(Buffer.from(parsed.registryBase64, "base64").toString("utf-8"));
|
|
135
|
+
}
|
|
136
|
+
return JSON.parse(fs.readFileSync(parsed.registryPath, "utf-8"));
|
|
137
|
+
}
|
|
138
|
+
function runMailroomEntry(args = process.argv.slice(2)) {
|
|
139
|
+
const parsed = parseMailroomEntryArgs(args);
|
|
140
|
+
const registry = readRegistry(parsed);
|
|
141
|
+
const servers = (0, smtp_ingress_1.startMailroomIngress)({
|
|
142
|
+
registry,
|
|
143
|
+
store: createStore(parsed),
|
|
144
|
+
smtpPort: parsed.smtpPort,
|
|
145
|
+
httpPort: parsed.httpPort,
|
|
146
|
+
host: parsed.host,
|
|
147
|
+
});
|
|
148
|
+
(0, runtime_1.emitNervesEvent)({
|
|
149
|
+
component: "senses",
|
|
150
|
+
event: "senses.mail_entry_started",
|
|
151
|
+
message: "mailroom entry started",
|
|
152
|
+
meta: { domain: registry.domain, smtpPort: parsed.smtpPort, httpPort: parsed.httpPort },
|
|
153
|
+
});
|
|
154
|
+
return servers;
|
|
155
|
+
}
|
|
156
|
+
/* v8 ignore start -- exercised by packaged/container entrypoint smoke rather than in-process unit tests. @preserve */
|
|
157
|
+
if (require.main === module) {
|
|
158
|
+
runMailroomEntry();
|
|
159
|
+
}
|
|
160
|
+
/* v8 ignore stop */
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FileMailroomStore = void 0;
|
|
37
|
+
exports.ingestRawMailToStore = ingestRawMailToStore;
|
|
38
|
+
exports.decryptMessages = decryptMessages;
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
const runtime_1 = require("../nerves/runtime");
|
|
42
|
+
const core_1 = require("./core");
|
|
43
|
+
function ensureDir(dir) {
|
|
44
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
function readJson(filePath) {
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function writeJson(filePath, value) {
|
|
55
|
+
ensureDir(path.dirname(filePath));
|
|
56
|
+
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf-8");
|
|
57
|
+
}
|
|
58
|
+
function compareNewestFirst(left, right) {
|
|
59
|
+
return Date.parse(right.receivedAt) - Date.parse(left.receivedAt);
|
|
60
|
+
}
|
|
61
|
+
function compareCandidatesNewestFirst(left, right) {
|
|
62
|
+
return Date.parse(right.lastSeenAt) - Date.parse(left.lastSeenAt);
|
|
63
|
+
}
|
|
64
|
+
class FileMailroomStore {
|
|
65
|
+
rootDir;
|
|
66
|
+
constructor(options) {
|
|
67
|
+
this.rootDir = options.rootDir;
|
|
68
|
+
ensureDir(this.messagesDir);
|
|
69
|
+
ensureDir(this.rawDir);
|
|
70
|
+
ensureDir(this.logsDir);
|
|
71
|
+
ensureDir(this.candidatesDir);
|
|
72
|
+
ensureDir(this.decisionsDir);
|
|
73
|
+
ensureDir(this.outboundDir);
|
|
74
|
+
(0, runtime_1.emitNervesEvent)({
|
|
75
|
+
component: "senses",
|
|
76
|
+
event: "senses.mail_file_store_init",
|
|
77
|
+
message: "file mailroom store initialized",
|
|
78
|
+
meta: { rootDir: this.rootDir },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
get messagesDir() {
|
|
82
|
+
return path.join(this.rootDir, "messages");
|
|
83
|
+
}
|
|
84
|
+
get rawDir() {
|
|
85
|
+
return path.join(this.rootDir, "raw");
|
|
86
|
+
}
|
|
87
|
+
get logsDir() {
|
|
88
|
+
return path.join(this.rootDir, "access-log");
|
|
89
|
+
}
|
|
90
|
+
get candidatesDir() {
|
|
91
|
+
return path.join(this.rootDir, "candidates");
|
|
92
|
+
}
|
|
93
|
+
get decisionsDir() {
|
|
94
|
+
return path.join(this.rootDir, "decisions");
|
|
95
|
+
}
|
|
96
|
+
get outboundDir() {
|
|
97
|
+
return path.join(this.rootDir, "outbound");
|
|
98
|
+
}
|
|
99
|
+
messagePath(id) {
|
|
100
|
+
return path.join(this.messagesDir, `${id}.json`);
|
|
101
|
+
}
|
|
102
|
+
candidatePath(id) {
|
|
103
|
+
return path.join(this.candidatesDir, `${id}.json`);
|
|
104
|
+
}
|
|
105
|
+
rawPath(objectName) {
|
|
106
|
+
return path.join(this.rootDir, objectName);
|
|
107
|
+
}
|
|
108
|
+
decisionLogPath(agentId) {
|
|
109
|
+
return path.join(this.decisionsDir, `${agentId}.jsonl`);
|
|
110
|
+
}
|
|
111
|
+
outboundPath(id) {
|
|
112
|
+
return path.join(this.outboundDir, `${id}.json`);
|
|
113
|
+
}
|
|
114
|
+
accessLogPath(agentId) {
|
|
115
|
+
return path.join(this.logsDir, `${agentId}.jsonl`);
|
|
116
|
+
}
|
|
117
|
+
async putRawMessage(input) {
|
|
118
|
+
const { message, rawPayload, candidate } = await (0, core_1.buildStoredMailMessage)(input);
|
|
119
|
+
const existing = readJson(this.messagePath(message.id));
|
|
120
|
+
if (existing) {
|
|
121
|
+
(0, runtime_1.emitNervesEvent)({
|
|
122
|
+
component: "senses",
|
|
123
|
+
event: "senses.mail_store_dedupe",
|
|
124
|
+
message: "mailroom store deduped existing message",
|
|
125
|
+
meta: { id: message.id, agentId: message.agentId },
|
|
126
|
+
});
|
|
127
|
+
return { created: false, message: existing };
|
|
128
|
+
}
|
|
129
|
+
writeJson(this.rawPath(message.rawObject), rawPayload);
|
|
130
|
+
writeJson(this.messagePath(message.id), message);
|
|
131
|
+
if (candidate) {
|
|
132
|
+
writeJson(this.candidatePath(candidate.id), candidate);
|
|
133
|
+
}
|
|
134
|
+
(0, runtime_1.emitNervesEvent)({
|
|
135
|
+
component: "senses",
|
|
136
|
+
event: "senses.mail_store_message_written",
|
|
137
|
+
message: "mailroom store wrote message",
|
|
138
|
+
meta: { id: message.id, agentId: message.agentId, candidate: candidate !== undefined },
|
|
139
|
+
});
|
|
140
|
+
return { created: true, message };
|
|
141
|
+
}
|
|
142
|
+
async getMessage(id) {
|
|
143
|
+
const message = readJson(this.messagePath(id));
|
|
144
|
+
(0, runtime_1.emitNervesEvent)({
|
|
145
|
+
component: "senses",
|
|
146
|
+
event: "senses.mail_store_message_read",
|
|
147
|
+
message: "mailroom store read message",
|
|
148
|
+
meta: { id, found: message !== null },
|
|
149
|
+
});
|
|
150
|
+
return message;
|
|
151
|
+
}
|
|
152
|
+
async listMessages(filters) {
|
|
153
|
+
const messages = fs.readdirSync(this.messagesDir)
|
|
154
|
+
.filter((name) => name.endsWith(".json"))
|
|
155
|
+
.map((name) => readJson(path.join(this.messagesDir, name)))
|
|
156
|
+
.filter((message) => message !== null)
|
|
157
|
+
.filter((message) => message.agentId === filters.agentId)
|
|
158
|
+
.filter((message) => filters.placement ? message.placement === filters.placement : true)
|
|
159
|
+
.filter((message) => filters.compartmentKind ? message.compartmentKind === filters.compartmentKind : true)
|
|
160
|
+
.filter((message) => filters.source ? message.source === filters.source : true)
|
|
161
|
+
.sort(compareNewestFirst)
|
|
162
|
+
.slice(0, filters.limit ?? 20);
|
|
163
|
+
(0, runtime_1.emitNervesEvent)({
|
|
164
|
+
component: "senses",
|
|
165
|
+
event: "senses.mail_store_messages_listed",
|
|
166
|
+
message: "mailroom store listed messages",
|
|
167
|
+
meta: { agentId: filters.agentId, count: messages.length },
|
|
168
|
+
});
|
|
169
|
+
return messages;
|
|
170
|
+
}
|
|
171
|
+
async updateMessagePlacement(id, placement) {
|
|
172
|
+
const message = readJson(this.messagePath(id));
|
|
173
|
+
if (!message) {
|
|
174
|
+
(0, runtime_1.emitNervesEvent)({
|
|
175
|
+
component: "senses",
|
|
176
|
+
event: "senses.mail_store_message_placement_updated",
|
|
177
|
+
message: "mailroom store message placement update missed",
|
|
178
|
+
meta: { id, placement, found: false },
|
|
179
|
+
});
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const updated = { ...message, placement };
|
|
183
|
+
writeJson(this.messagePath(id), updated);
|
|
184
|
+
(0, runtime_1.emitNervesEvent)({
|
|
185
|
+
component: "senses",
|
|
186
|
+
event: "senses.mail_store_message_placement_updated",
|
|
187
|
+
message: "mailroom store updated message placement",
|
|
188
|
+
meta: { id, placement, found: true },
|
|
189
|
+
});
|
|
190
|
+
return updated;
|
|
191
|
+
}
|
|
192
|
+
async readRawPayload(objectName) {
|
|
193
|
+
const payload = readJson(this.rawPath(objectName));
|
|
194
|
+
(0, runtime_1.emitNervesEvent)({
|
|
195
|
+
component: "senses",
|
|
196
|
+
event: "senses.mail_store_raw_read",
|
|
197
|
+
message: "mailroom store read raw payload",
|
|
198
|
+
meta: { objectName, found: payload !== null },
|
|
199
|
+
});
|
|
200
|
+
return payload;
|
|
201
|
+
}
|
|
202
|
+
async putScreenerCandidate(candidate) {
|
|
203
|
+
writeJson(this.candidatePath(candidate.id), candidate);
|
|
204
|
+
(0, runtime_1.emitNervesEvent)({
|
|
205
|
+
component: "senses",
|
|
206
|
+
event: "senses.mail_screener_candidate_written",
|
|
207
|
+
message: "mail screener candidate written",
|
|
208
|
+
meta: { id: candidate.id, agentId: candidate.agentId, status: candidate.status },
|
|
209
|
+
});
|
|
210
|
+
return candidate;
|
|
211
|
+
}
|
|
212
|
+
async updateScreenerCandidate(candidate) {
|
|
213
|
+
return this.putScreenerCandidate(candidate);
|
|
214
|
+
}
|
|
215
|
+
async listScreenerCandidates(filters) {
|
|
216
|
+
const candidates = fs.readdirSync(this.candidatesDir)
|
|
217
|
+
.filter((name) => name.endsWith(".json"))
|
|
218
|
+
.map((name) => readJson(path.join(this.candidatesDir, name)))
|
|
219
|
+
.filter((candidate) => candidate !== null)
|
|
220
|
+
.filter((candidate) => candidate.agentId === filters.agentId)
|
|
221
|
+
.filter((candidate) => filters.status ? candidate.status === filters.status : true)
|
|
222
|
+
.filter((candidate) => filters.placement ? candidate.placement === filters.placement : true)
|
|
223
|
+
.sort(compareCandidatesNewestFirst)
|
|
224
|
+
.slice(0, filters.limit ?? 50);
|
|
225
|
+
(0, runtime_1.emitNervesEvent)({
|
|
226
|
+
component: "senses",
|
|
227
|
+
event: "senses.mail_screener_candidates_listed",
|
|
228
|
+
message: "mail screener candidates listed",
|
|
229
|
+
meta: { agentId: filters.agentId, count: candidates.length },
|
|
230
|
+
});
|
|
231
|
+
return candidates;
|
|
232
|
+
}
|
|
233
|
+
async recordMailDecision(entry) {
|
|
234
|
+
const complete = {
|
|
235
|
+
schemaVersion: 1,
|
|
236
|
+
...entry,
|
|
237
|
+
id: entry.id ?? `decision_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
238
|
+
createdAt: entry.createdAt ?? new Date().toISOString(),
|
|
239
|
+
};
|
|
240
|
+
ensureDir(this.decisionsDir);
|
|
241
|
+
fs.appendFileSync(this.decisionLogPath(entry.agentId), `${JSON.stringify(complete)}\n`, "utf-8");
|
|
242
|
+
(0, runtime_1.emitNervesEvent)({
|
|
243
|
+
component: "senses",
|
|
244
|
+
event: "senses.mail_decision_recorded",
|
|
245
|
+
message: "mail decision recorded",
|
|
246
|
+
meta: { agentId: entry.agentId, messageId: entry.messageId, action: entry.action },
|
|
247
|
+
});
|
|
248
|
+
return complete;
|
|
249
|
+
}
|
|
250
|
+
async listMailDecisions(agentId) {
|
|
251
|
+
const filePath = this.decisionLogPath(agentId);
|
|
252
|
+
if (!fs.existsSync(filePath)) {
|
|
253
|
+
(0, runtime_1.emitNervesEvent)({
|
|
254
|
+
component: "senses",
|
|
255
|
+
event: "senses.mail_decisions_listed",
|
|
256
|
+
message: "mail decisions listed",
|
|
257
|
+
meta: { agentId, count: 0 },
|
|
258
|
+
});
|
|
259
|
+
return [];
|
|
260
|
+
}
|
|
261
|
+
const entries = fs.readFileSync(filePath, "utf-8")
|
|
262
|
+
.split(/\r?\n/)
|
|
263
|
+
.filter(Boolean)
|
|
264
|
+
.map((line) => JSON.parse(line));
|
|
265
|
+
(0, runtime_1.emitNervesEvent)({
|
|
266
|
+
component: "senses",
|
|
267
|
+
event: "senses.mail_decisions_listed",
|
|
268
|
+
message: "mail decisions listed",
|
|
269
|
+
meta: { agentId, count: entries.length },
|
|
270
|
+
});
|
|
271
|
+
return entries;
|
|
272
|
+
}
|
|
273
|
+
async upsertMailOutbound(record) {
|
|
274
|
+
writeJson(this.outboundPath(record.id), record);
|
|
275
|
+
(0, runtime_1.emitNervesEvent)({
|
|
276
|
+
component: "senses",
|
|
277
|
+
event: "senses.mail_outbound_record_written",
|
|
278
|
+
message: "mail outbound record written",
|
|
279
|
+
meta: { agentId: record.agentId, id: record.id, status: record.status },
|
|
280
|
+
});
|
|
281
|
+
return record;
|
|
282
|
+
}
|
|
283
|
+
async getMailOutbound(id) {
|
|
284
|
+
const record = readJson(this.outboundPath(id));
|
|
285
|
+
(0, runtime_1.emitNervesEvent)({
|
|
286
|
+
component: "senses",
|
|
287
|
+
event: "senses.mail_outbound_record_read",
|
|
288
|
+
message: "mail outbound record read",
|
|
289
|
+
meta: { id, found: record !== null },
|
|
290
|
+
});
|
|
291
|
+
return record;
|
|
292
|
+
}
|
|
293
|
+
async listMailOutbound(agentId) {
|
|
294
|
+
const records = fs.readdirSync(this.outboundDir)
|
|
295
|
+
.filter((name) => name.endsWith(".json"))
|
|
296
|
+
.map((name) => readJson(path.join(this.outboundDir, name)))
|
|
297
|
+
.filter((record) => record !== null)
|
|
298
|
+
.filter((record) => record.agentId === agentId)
|
|
299
|
+
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
300
|
+
(0, runtime_1.emitNervesEvent)({
|
|
301
|
+
component: "senses",
|
|
302
|
+
event: "senses.mail_outbound_records_listed",
|
|
303
|
+
message: "mail outbound records listed",
|
|
304
|
+
meta: { agentId, count: records.length },
|
|
305
|
+
});
|
|
306
|
+
return records;
|
|
307
|
+
}
|
|
308
|
+
async recordAccess(entry) {
|
|
309
|
+
const complete = {
|
|
310
|
+
...entry,
|
|
311
|
+
id: `access_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
312
|
+
accessedAt: new Date().toISOString(),
|
|
313
|
+
};
|
|
314
|
+
ensureDir(this.logsDir);
|
|
315
|
+
fs.appendFileSync(this.accessLogPath(entry.agentId), `${JSON.stringify(complete)}\n`, "utf-8");
|
|
316
|
+
(0, runtime_1.emitNervesEvent)({
|
|
317
|
+
component: "senses",
|
|
318
|
+
event: "senses.mail_access_recorded",
|
|
319
|
+
message: "mail access recorded",
|
|
320
|
+
meta: { agentId: entry.agentId, messageId: entry.messageId ?? null, tool: entry.tool },
|
|
321
|
+
});
|
|
322
|
+
return complete;
|
|
323
|
+
}
|
|
324
|
+
async listAccessLog(agentId) {
|
|
325
|
+
const filePath = this.accessLogPath(agentId);
|
|
326
|
+
if (!fs.existsSync(filePath)) {
|
|
327
|
+
(0, runtime_1.emitNervesEvent)({
|
|
328
|
+
component: "senses",
|
|
329
|
+
event: "senses.mail_access_log_listed",
|
|
330
|
+
message: "mail access log listed",
|
|
331
|
+
meta: { agentId, count: 0 },
|
|
332
|
+
});
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
const entries = fs.readFileSync(filePath, "utf-8")
|
|
336
|
+
.split(/\r?\n/)
|
|
337
|
+
.filter(Boolean)
|
|
338
|
+
.map((line) => JSON.parse(line));
|
|
339
|
+
(0, runtime_1.emitNervesEvent)({
|
|
340
|
+
component: "senses",
|
|
341
|
+
event: "senses.mail_access_log_listed",
|
|
342
|
+
message: "mail access log listed",
|
|
343
|
+
meta: { agentId, count: entries.length },
|
|
344
|
+
});
|
|
345
|
+
return entries;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.FileMailroomStore = FileMailroomStore;
|
|
349
|
+
async function ingestRawMailToStore(input) {
|
|
350
|
+
const { resolveMailAddress } = await Promise.resolve().then(() => __importStar(require("./core")));
|
|
351
|
+
const { classifyResolvedMailPlacement } = await Promise.resolve().then(() => __importStar(require("./policy")));
|
|
352
|
+
const accepted = [];
|
|
353
|
+
const rejectedRecipients = [];
|
|
354
|
+
for (const recipient of input.envelope.rcptTo) {
|
|
355
|
+
const resolved = resolveMailAddress(input.registry, recipient);
|
|
356
|
+
if (!resolved) {
|
|
357
|
+
rejectedRecipients.push(recipient);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const classification = classifyResolvedMailPlacement({
|
|
361
|
+
registry: input.registry,
|
|
362
|
+
resolved,
|
|
363
|
+
sender: input.envelope.mailFrom,
|
|
364
|
+
...(input.authentication ? { authentication: input.authentication } : {}),
|
|
365
|
+
});
|
|
366
|
+
const result = await input.store.putRawMessage({
|
|
367
|
+
resolved,
|
|
368
|
+
envelope: input.envelope,
|
|
369
|
+
rawMime: input.rawMime,
|
|
370
|
+
receivedAt: input.receivedAt,
|
|
371
|
+
...(input.ingest ? { ingest: input.ingest } : {}),
|
|
372
|
+
classification,
|
|
373
|
+
});
|
|
374
|
+
accepted.push(result.message);
|
|
375
|
+
}
|
|
376
|
+
(0, runtime_1.emitNervesEvent)({
|
|
377
|
+
component: "senses",
|
|
378
|
+
event: "senses.mail_ingest_complete",
|
|
379
|
+
message: "mail ingest completed",
|
|
380
|
+
meta: { accepted: accepted.length, rejected: rejectedRecipients.length },
|
|
381
|
+
});
|
|
382
|
+
return { accepted, rejectedRecipients };
|
|
383
|
+
}
|
|
384
|
+
function decryptMessages(messages, privateKeys) {
|
|
385
|
+
const decrypted = messages.map((message) => (0, core_1.decryptStoredMailMessage)(message, privateKeys));
|
|
386
|
+
(0, runtime_1.emitNervesEvent)({
|
|
387
|
+
component: "senses",
|
|
388
|
+
event: "senses.mail_messages_decrypted",
|
|
389
|
+
message: "mail messages decrypted",
|
|
390
|
+
meta: { count: decrypted.length },
|
|
391
|
+
});
|
|
392
|
+
return decrypted;
|
|
393
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitMboxMessages = splitMboxMessages;
|
|
4
|
+
exports.importMboxToStore = importMboxToStore;
|
|
5
|
+
const mailparser_1 = require("mailparser");
|
|
6
|
+
const runtime_1 = require("../nerves/runtime");
|
|
7
|
+
const core_1 = require("./core");
|
|
8
|
+
function splitMboxMessages(rawMbox) {
|
|
9
|
+
const text = rawMbox.toString("utf-8");
|
|
10
|
+
const separators = [...text.matchAll(/^From [^\r\n]*(?:\r?\n)/gm)];
|
|
11
|
+
if (separators.length === 0) {
|
|
12
|
+
const trimmed = text.trim();
|
|
13
|
+
return trimmed ? [Buffer.from(text, "utf-8")] : [];
|
|
14
|
+
}
|
|
15
|
+
const messages = separators
|
|
16
|
+
.map((match, index) => {
|
|
17
|
+
const start = match.index + match[0].length;
|
|
18
|
+
const end = index + 1 < separators.length ? separators[index + 1].index : text.length;
|
|
19
|
+
return text.slice(start, end).replace(/\r?\n$/, "");
|
|
20
|
+
})
|
|
21
|
+
.filter((message) => message.trim().length > 0)
|
|
22
|
+
.map((message) => Buffer.from(message, "utf-8"));
|
|
23
|
+
(0, runtime_1.emitNervesEvent)({
|
|
24
|
+
component: "senses",
|
|
25
|
+
event: "senses.mail_mbox_split",
|
|
26
|
+
message: "mbox payload split into messages",
|
|
27
|
+
meta: { messages: messages.length },
|
|
28
|
+
});
|
|
29
|
+
return messages;
|
|
30
|
+
}
|
|
31
|
+
function findSourceGrant(input) {
|
|
32
|
+
const ownerEmail = input.ownerEmail ? (0, core_1.normalizeMailAddress)(input.ownerEmail) : undefined;
|
|
33
|
+
const source = input.source?.trim().toLowerCase();
|
|
34
|
+
const grants = input.registry.sourceGrants.filter((grant) => {
|
|
35
|
+
if (!grant.enabled || grant.agentId !== input.agentId)
|
|
36
|
+
return false;
|
|
37
|
+
if (ownerEmail && (0, core_1.normalizeMailAddress)(grant.ownerEmail) !== ownerEmail)
|
|
38
|
+
return false;
|
|
39
|
+
if (source && grant.source.toLowerCase() !== source)
|
|
40
|
+
return false;
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
if (grants.length === 0) {
|
|
44
|
+
throw new Error(`No enabled Mailroom source grant found for ${input.agentId}${ownerEmail ? ` owner ${ownerEmail}` : ""}${source ? ` source ${source}` : ""}`);
|
|
45
|
+
}
|
|
46
|
+
if (grants.length > 1 && !ownerEmail && !source) {
|
|
47
|
+
throw new Error(`Multiple source grants found for ${input.agentId}; pass --owner-email or --source to choose one`);
|
|
48
|
+
}
|
|
49
|
+
return grants[0];
|
|
50
|
+
}
|
|
51
|
+
async function parseMboxMessage(rawMessage, grant) {
|
|
52
|
+
const parsed = await (0, mailparser_1.simpleParser)(rawMessage);
|
|
53
|
+
const mailFrom = parsed.from?.value?.[0]?.address;
|
|
54
|
+
return {
|
|
55
|
+
rawMessage,
|
|
56
|
+
envelope: {
|
|
57
|
+
mailFrom: mailFrom ? (0, core_1.normalizeMailAddress)(mailFrom) : "",
|
|
58
|
+
rcptTo: [(0, core_1.normalizeMailAddress)(grant.aliasAddress)],
|
|
59
|
+
remoteAddress: "mbox-import",
|
|
60
|
+
},
|
|
61
|
+
...(parsed.date ? { messageDate: parsed.date } : {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function latestMessageDate(messages) {
|
|
65
|
+
const timestamps = messages
|
|
66
|
+
.map((message) => message.messageDate?.getTime())
|
|
67
|
+
.filter((timestamp) => typeof timestamp === "number" && Number.isFinite(timestamp));
|
|
68
|
+
if (timestamps.length === 0)
|
|
69
|
+
return null;
|
|
70
|
+
return new Date(Math.max(...timestamps)).toISOString();
|
|
71
|
+
}
|
|
72
|
+
function historicalImportClassification(resolvedPlacement, sourceGrant) {
|
|
73
|
+
return {
|
|
74
|
+
placement: resolvedPlacement,
|
|
75
|
+
candidate: false,
|
|
76
|
+
trustReason: `delegated source grant ${sourceGrant.source} historical mbox import`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function importMboxToStore(input) {
|
|
80
|
+
const agentId = input.agentId.toLowerCase();
|
|
81
|
+
const sourceGrant = findSourceGrant({
|
|
82
|
+
registry: input.registry,
|
|
83
|
+
agentId,
|
|
84
|
+
ownerEmail: input.ownerEmail,
|
|
85
|
+
source: input.source,
|
|
86
|
+
});
|
|
87
|
+
const resolved = (0, core_1.resolveMailAddress)(input.registry, sourceGrant.aliasAddress);
|
|
88
|
+
/* v8 ignore start -- findSourceGrant and resolveMailAddress share the same registry; this is a corruption guard. @preserve */
|
|
89
|
+
if (!resolved) {
|
|
90
|
+
throw new Error(`Source grant alias ${sourceGrant.aliasAddress} is not resolvable`);
|
|
91
|
+
}
|
|
92
|
+
/* v8 ignore stop */
|
|
93
|
+
let imported = 0;
|
|
94
|
+
let duplicates = 0;
|
|
95
|
+
const messages = [];
|
|
96
|
+
const rawMessages = splitMboxMessages(input.rawMbox);
|
|
97
|
+
const parsedMessages = await Promise.all(rawMessages.map((rawMessage) => parseMboxMessage(rawMessage, sourceGrant)));
|
|
98
|
+
const importedAt = (input.importedAt ?? new Date()).toISOString();
|
|
99
|
+
const sourceFreshThrough = latestMessageDate(parsedMessages);
|
|
100
|
+
for (const parsedMessage of parsedMessages) {
|
|
101
|
+
const result = await input.store.putRawMessage({
|
|
102
|
+
resolved,
|
|
103
|
+
envelope: parsedMessage.envelope,
|
|
104
|
+
rawMime: parsedMessage.rawMessage,
|
|
105
|
+
receivedAt: parsedMessage.messageDate ?? input.importedAt,
|
|
106
|
+
ingest: {
|
|
107
|
+
schemaVersion: 1,
|
|
108
|
+
kind: "mbox-import",
|
|
109
|
+
importedAt,
|
|
110
|
+
sourceFreshThrough,
|
|
111
|
+
attentionSuppressed: true,
|
|
112
|
+
},
|
|
113
|
+
classification: historicalImportClassification(resolved.defaultPlacement, sourceGrant),
|
|
114
|
+
});
|
|
115
|
+
messages.push(result.message);
|
|
116
|
+
if (result.created)
|
|
117
|
+
imported += 1;
|
|
118
|
+
else
|
|
119
|
+
duplicates += 1;
|
|
120
|
+
}
|
|
121
|
+
(0, runtime_1.emitNervesEvent)({
|
|
122
|
+
component: "senses",
|
|
123
|
+
event: "senses.mail_mbox_imported",
|
|
124
|
+
message: "mbox mail imported",
|
|
125
|
+
meta: { agentId, scanned: rawMessages.length, imported, duplicates, grantId: sourceGrant.grantId },
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
agentId,
|
|
129
|
+
sourceGrant,
|
|
130
|
+
scanned: rawMessages.length,
|
|
131
|
+
imported,
|
|
132
|
+
duplicates,
|
|
133
|
+
sourceFreshThrough,
|
|
134
|
+
messages,
|
|
135
|
+
};
|
|
136
|
+
}
|