@otium-team/negotium 0.0.0-stage → 0.23.13
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/LICENSE +202 -0
- package/README.md +329 -2
- package/bin/codex-sdk-window-hide.mjs +40 -0
- package/bin/negotium.mjs +22 -0
- package/dist/agent-helpers.js +23090 -0
- package/dist/agent-helpers.js.map +171 -0
- package/dist/background-bash.js +535 -0
- package/dist/background-bash.js.map +16 -0
- package/dist/browser-runtime.js +2334 -0
- package/dist/browser-runtime.js.map +35 -0
- package/dist/canonical-mcp-bridge.js +13 -0
- package/dist/canonical-mcp-bridge.js.map +9 -0
- package/dist/chunk-22kg3fsw.js +79 -0
- package/dist/chunk-22kg3fsw.js.map +9 -0
- package/dist/chunk-d4j77adx.js +336 -0
- package/dist/chunk-d4j77adx.js.map +13 -0
- package/dist/chunk-mk9x18jn.js +172 -0
- package/dist/chunk-mk9x18jn.js.map +12 -0
- package/dist/chunk-qd0vtfm2.js +3923 -0
- package/dist/chunk-qd0vtfm2.js.map +47 -0
- package/dist/chunk-wf7ny8eq.js +206 -0
- package/dist/chunk-wf7ny8eq.js.map +10 -0
- package/dist/chunk-ww8a4ej4.js +54 -0
- package/dist/chunk-ww8a4ej4.js.map +10 -0
- package/dist/cron.js +1 -0
- package/dist/hosted-agent.js +5982 -0
- package/dist/hosted-agent.js.map +62 -0
- package/dist/main.js +60229 -0
- package/dist/main.js.map +340 -0
- package/dist/mcp-catalog.js +39 -0
- package/dist/mcp-catalog.js.map +10 -0
- package/dist/mcp-factories.js +25767 -0
- package/dist/mcp-factories.js.map +181 -0
- package/dist/mcp-servers.js +50 -0
- package/dist/mcp-servers.js.map +10 -0
- package/dist/media.js +570 -0
- package/dist/media.js.map +15 -0
- package/dist/outbox.js +354 -0
- package/dist/outbox.js.map +15 -0
- package/dist/platform-runtime.js +73 -0
- package/dist/platform-runtime.js.map +12 -0
- package/dist/prompts.js +892 -0
- package/dist/prompts.js.map +15 -0
- package/dist/query-runtime.js +1071 -0
- package/dist/query-runtime.js.map +26 -0
- package/dist/registry.js +335 -0
- package/dist/registry.js.map +14 -0
- package/dist/rollout.js +57 -0
- package/dist/rollout.js.map +10 -0
- package/dist/runtime/cron/background-sessions.ts +119 -0
- package/dist/runtime/cron/context.ts +123 -0
- package/dist/runtime/cron/host.ts +67 -0
- package/dist/runtime/cron/index.ts +95 -0
- package/dist/runtime/cron/mcp-server.ts +556 -0
- package/dist/runtime/cron/module.ts +174 -0
- package/dist/runtime/cron/package.json +6 -0
- package/dist/runtime/cron/schedule.ts +211 -0
- package/dist/runtime/cron/scheduler.ts +444 -0
- package/dist/runtime/cron/scripts.ts +203 -0
- package/dist/runtime/cron/store.ts +1163 -0
- package/dist/runtime/cron/summarize.ts +115 -0
- package/dist/runtime/package.json +6 -0
- package/dist/runtime/scripts/faster-whisper-wrapper.py +87 -0
- package/dist/runtime/src/agents/api-topic-agent-switch.ts +179 -0
- package/dist/runtime/src/agents/archiver.ts +677 -0
- package/dist/runtime/src/agents/auth-check.ts +156 -0
- package/dist/runtime/src/agents/claude-notices.ts +130 -0
- package/dist/runtime/src/agents/claude-provider.ts +941 -0
- package/dist/runtime/src/agents/claude-registry.ts +117 -0
- package/dist/runtime/src/agents/claude-runtime-inspection.ts +43 -0
- package/dist/runtime/src/agents/codex-app-server.ts +138 -0
- package/dist/runtime/src/agents/codex-native-multi-agent.ts +360 -0
- package/dist/runtime/src/agents/codex-provider.ts +1193 -0
- package/dist/runtime/src/agents/codex-registry.ts +116 -0
- package/dist/runtime/src/agents/codex-tier-resolver.ts +74 -0
- package/dist/runtime/src/agents/codex-tree-kill.ts +54 -0
- package/dist/runtime/src/agents/codex-tree-manager.ts +230 -0
- package/dist/runtime/src/agents/codex-vault-hook-bridge.ts +240 -0
- package/dist/runtime/src/agents/codex-vault-hook.mjs +50 -0
- package/dist/runtime/src/agents/codex-windows-wrapper.ts +174 -0
- package/dist/runtime/src/agents/compaction-support.ts +75 -0
- package/dist/runtime/src/agents/compaction-tool-projection.ts +125 -0
- package/dist/runtime/src/agents/contracts.ts +75 -0
- package/dist/runtime/src/agents/deep-map.ts +13 -0
- package/dist/runtime/src/agents/execution-host.ts +118 -0
- package/dist/runtime/src/agents/explicit-agent-switch.ts +106 -0
- package/dist/runtime/src/agents/fixtures/claude-attachments.jsonl +2 -0
- package/dist/runtime/src/agents/fixtures/codex-shell.jsonl +5 -0
- package/dist/runtime/src/agents/fork.ts +100 -0
- package/dist/runtime/src/agents/hosted-agent.ts +78 -0
- package/dist/runtime/src/agents/idle-archiver.ts +225 -0
- package/dist/runtime/src/agents/idle-compact.ts +225 -0
- package/dist/runtime/src/agents/index.ts +225 -0
- package/dist/runtime/src/agents/maestro-provider.ts +246 -0
- package/dist/runtime/src/agents/maestro-registry.ts +189 -0
- package/dist/runtime/src/agents/mcp-tools/ask-user.ts +653 -0
- package/dist/runtime/src/agents/mcp-tools/common.ts +23 -0
- package/dist/runtime/src/agents/mcp-tools/inline-assets.ts +203 -0
- package/dist/runtime/src/agents/mcp-tools/publish-html.ts +183 -0
- package/dist/runtime/src/agents/mcp-tools/request-vault.ts +684 -0
- package/dist/runtime/src/agents/mcp-tools/self-config.ts +353 -0
- package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +1349 -0
- package/dist/runtime/src/agents/mcp-tools/visual-compat.ts +18 -0
- package/dist/runtime/src/agents/mcp-tools/visuals.ts +60 -0
- package/dist/runtime/src/agents/memory-archive-policy.ts +54 -0
- package/dist/runtime/src/agents/model-catalog.ts +439 -0
- package/dist/runtime/src/agents/public-helpers.ts +149 -0
- package/dist/runtime/src/agents/registry.ts +35 -0
- package/dist/runtime/src/agents/rollout/claude.ts +336 -0
- package/dist/runtime/src/agents/rollout/codex.ts +910 -0
- package/dist/runtime/src/agents/rollout/index.ts +26 -0
- package/dist/runtime/src/agents/rollout/shared.ts +293 -0
- package/dist/runtime/src/agents/self-config-core.ts +704 -0
- package/dist/runtime/src/agents/task-events.ts +59 -0
- package/dist/runtime/src/agents/tool-format.ts +613 -0
- package/dist/runtime/src/agents/topic-agent-switch.ts +189 -0
- package/dist/runtime/src/agents/topic-cleanup.ts +285 -0
- package/dist/runtime/src/agents/vault-tool-policy.ts +36 -0
- package/dist/runtime/src/application/execute-external-user-turn.ts +23 -0
- package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +484 -0
- package/dist/runtime/src/application/submit-user-message.ts +60 -0
- package/dist/runtime/src/application/switch-topic-effort.ts +48 -0
- package/dist/runtime/src/application/switch-topic-model.ts +79 -0
- package/dist/runtime/src/application/topic-service.ts +190 -0
- package/dist/runtime/src/application/turn-follow-ups.ts +291 -0
- package/dist/runtime/src/application/vault-command.ts +170 -0
- package/dist/runtime/src/bus.ts +409 -0
- package/dist/runtime/src/config-public.ts +2 -0
- package/dist/runtime/src/cron-host.ts +33 -0
- package/dist/runtime/src/cron-mcp-host.ts +5 -0
- package/dist/runtime/src/identifiers.ts +49 -0
- package/dist/runtime/src/index.ts +573 -0
- package/dist/runtime/src/mcp/agent-health-server.ts +8 -0
- package/dist/runtime/src/mcp/canonical-bridge-config.ts +84 -0
- package/dist/runtime/src/mcp/canonical-proxy-server.ts +308 -0
- package/dist/runtime/src/mcp/compaction-log-server.ts +25 -0
- package/dist/runtime/src/mcp/decision-server.ts +21 -0
- package/dist/runtime/src/mcp/dm-ipc.ts +60 -0
- package/dist/runtime/src/mcp/factories/agent-health.ts +394 -0
- package/dist/runtime/src/mcp/factories/compaction-log.ts +135 -0
- package/dist/runtime/src/mcp/factories/decision.ts +186 -0
- package/dist/runtime/src/mcp/factories/index.ts +73 -0
- package/dist/runtime/src/mcp/factories/session-comm.ts +184 -0
- package/dist/runtime/src/mcp/factories/session-history.ts +103 -0
- package/dist/runtime/src/mcp/factories/stdio-protection.ts +24 -0
- package/dist/runtime/src/mcp/factories/system-health.ts +259 -0
- package/dist/runtime/src/mcp/factories/task.ts +185 -0
- package/dist/runtime/src/mcp/factories/token-stats.ts +145 -0
- package/dist/runtime/src/mcp/factories/vault.ts +32 -0
- package/dist/runtime/src/mcp/mcp-helpers.ts +40 -0
- package/dist/runtime/src/mcp/peer-bridge.ts +119 -0
- package/dist/runtime/src/mcp/runtime-spec.ts +473 -0
- package/dist/runtime/src/mcp/session-comm/actor-policy.ts +160 -0
- package/dist/runtime/src/mcp/session-comm/bridge-ipc-config.ts +27 -0
- package/dist/runtime/src/mcp/session-comm/context.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/default-host.ts +723 -0
- package/dist/runtime/src/mcp/session-comm/history-target.ts +89 -0
- package/dist/runtime/src/mcp/session-comm/history-tools.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/hub-remote-session.ts +553 -0
- package/dist/runtime/src/mcp/session-comm/limits.ts +8 -0
- package/dist/runtime/src/mcp/session-comm/peer-forward.ts +251 -0
- package/dist/runtime/src/mcp/session-comm/runtime.ts +128 -0
- package/dist/runtime/src/mcp/session-comm/server.ts +1036 -0
- package/dist/runtime/src/mcp/session-comm/tell-permissions.ts +79 -0
- package/dist/runtime/src/mcp/session-comm/topic-catalog.ts +155 -0
- package/dist/runtime/src/mcp/session-comm/topic-config.ts +137 -0
- package/dist/runtime/src/mcp/session-comm/topics.ts +313 -0
- package/dist/runtime/src/mcp/session-history-limits.ts +36 -0
- package/dist/runtime/src/mcp/session-history-reader.ts +359 -0
- package/dist/runtime/src/mcp/session-history-server.ts +19 -0
- package/dist/runtime/src/mcp/stdio-protect.ts +7 -0
- package/dist/runtime/src/mcp/system-health-server.ts +5 -0
- package/dist/runtime/src/mcp/task-server.ts +17 -0
- package/dist/runtime/src/mcp/token-stats-server.ts +10 -0
- package/dist/runtime/src/mcp/vault-server.ts +12 -0
- package/dist/runtime/src/mcp/wiki-search-index.ts +359 -0
- package/dist/runtime/src/mcp/wiki-server.ts +2386 -0
- package/dist/runtime/src/mcp-runtime-host.ts +81 -0
- package/dist/runtime/src/media/file-events.ts +33 -0
- package/dist/runtime/src/media/text-extractor.ts +334 -0
- package/dist/runtime/src/media/video.ts +92 -0
- package/dist/runtime/src/node-host.ts +211 -0
- package/dist/runtime/src/outbox/coalescing-runner.ts +157 -0
- package/dist/runtime/src/outbox/file-ops.ts +267 -0
- package/dist/runtime/src/outbox/index.ts +26 -0
- package/dist/runtime/src/outbox/utils.ts +74 -0
- package/dist/runtime/src/platform/background-bash/context.ts +9 -0
- package/dist/runtime/src/platform/background-bash/manager.ts +292 -0
- package/dist/runtime/src/platform/background-bash/output-buffer.ts +323 -0
- package/dist/runtime/src/platform/config-helpers.ts +47 -0
- package/dist/runtime/src/platform/config.ts +618 -0
- package/dist/runtime/src/platform/constants.ts +30 -0
- package/dist/runtime/src/platform/debug-users.ts +14 -0
- package/dist/runtime/src/platform/delay.ts +1 -0
- package/dist/runtime/src/platform/error.ts +9 -0
- package/dist/runtime/src/platform/file-utils.ts +35 -0
- package/dist/runtime/src/platform/ipc.ts +55 -0
- package/dist/runtime/src/platform/jsonl.ts +277 -0
- package/dist/runtime/src/platform/lifecycle.ts +176 -0
- package/dist/runtime/src/platform/log-rotation.ts +45 -0
- package/dist/runtime/src/platform/logger.ts +42 -0
- package/dist/runtime/src/platform/maestro-bootstrap-env.ts +3 -0
- package/dist/runtime/src/platform/mcp-catalog-policy.ts +63 -0
- package/dist/runtime/src/platform/mcp-config.ts +1329 -0
- package/dist/runtime/src/platform/memoize-import.ts +26 -0
- package/dist/runtime/src/platform/modules.ts +145 -0
- package/dist/runtime/src/platform/node-plugins.ts +46 -0
- package/dist/runtime/src/platform/paths.ts +62 -0
- package/dist/runtime/src/platform/playwright/browser-processes.ts +300 -0
- package/dist/runtime/src/platform/playwright/capability.ts +5 -0
- package/dist/runtime/src/platform/playwright/headed-launch.ts +61 -0
- package/dist/runtime/src/platform/playwright/manager-utils.ts +128 -0
- package/dist/runtime/src/platform/playwright/manager.ts +1502 -0
- package/dist/runtime/src/platform/playwright/mcp-transport.ts +35 -0
- package/dist/runtime/src/platform/playwright/profile-management.ts +33 -0
- package/dist/runtime/src/platform/playwright/public-runtime.ts +52 -0
- package/dist/runtime/src/platform/playwright/transport-probe.ts +89 -0
- package/dist/runtime/src/platform/playwright/vault-broker.ts +261 -0
- package/dist/runtime/src/platform/public-runtime.ts +18 -0
- package/dist/runtime/src/prompts/agents/wiki-archiver.md +194 -0
- package/dist/runtime/src/prompts/builders.ts +696 -0
- package/dist/runtime/src/prompts/sessions/_shared-tools.md +38 -0
- package/dist/runtime/src/prompts/sessions/channel-system.md +13 -0
- package/dist/runtime/src/prompts/sessions/manager-system.md +34 -0
- package/dist/runtime/src/prompts/sessions/surfaces/cli.md +6 -0
- package/dist/runtime/src/prompts/sessions/surfaces/otium-manager.md +18 -0
- package/dist/runtime/src/prompts/sessions/surfaces/otium.md +6 -0
- package/dist/runtime/src/prompts/sessions/surfaces/telegram.md +5 -0
- package/dist/runtime/src/prompts/sessions/surfaces/terminal.md +6 -0
- package/dist/runtime/src/prompts/sessions/topic-system.md +9 -0
- package/dist/runtime/src/prompts/sessions/visual-design.md +38 -0
- package/dist/runtime/src/query/active-rooms.ts +514 -0
- package/dist/runtime/src/query/index.ts +23 -0
- package/dist/runtime/src/query/public-runtime.ts +28 -0
- package/dist/runtime/src/query/room-query-registry.ts +217 -0
- package/dist/runtime/src/query/session-inbox-cleanup.ts +45 -0
- package/dist/runtime/src/query/session-inbox-path.ts +42 -0
- package/dist/runtime/src/query/state.ts +116 -0
- package/dist/runtime/src/query/types.ts +8 -0
- package/dist/runtime/src/runtime/actor-topic-reach.ts +123 -0
- package/dist/runtime/src/runtime/actor-topic-scope.ts +255 -0
- package/dist/runtime/src/runtime/ask-callbacks.ts +217 -0
- package/dist/runtime/src/runtime/attachments.ts +149 -0
- package/dist/runtime/src/runtime/background-session-policy.ts +1 -0
- package/dist/runtime/src/runtime/background-sessions.ts +288 -0
- package/dist/runtime/src/runtime/bashrs-completions.ts +350 -0
- package/dist/runtime/src/runtime/channel-context.ts +115 -0
- package/dist/runtime/src/runtime/context-warning.ts +131 -0
- package/dist/runtime/src/runtime/cron-sessions.ts +35 -0
- package/dist/runtime/src/runtime/delivery-ack.ts +112 -0
- package/dist/runtime/src/runtime/errors.ts +70 -0
- package/dist/runtime/src/runtime/event-heartbeat.ts +77 -0
- package/dist/runtime/src/runtime/file-hooks.ts +81 -0
- package/dist/runtime/src/runtime/footer.ts +23 -0
- package/dist/runtime/src/runtime/gateway-capabilities.ts +22 -0
- package/dist/runtime/src/runtime/inbox.ts +1307 -0
- package/dist/runtime/src/runtime/playwright-turn-abort.ts +59 -0
- package/dist/runtime/src/runtime/public-helpers.ts +78 -0
- package/dist/runtime/src/runtime/remote-session-grant.ts +221 -0
- package/dist/runtime/src/runtime/remote-session-inbox.ts +943 -0
- package/dist/runtime/src/runtime/remote-session-reply-outbox.ts +168 -0
- package/dist/runtime/src/runtime/task-format.ts +18 -0
- package/dist/runtime/src/runtime/tasks.ts +53 -0
- package/dist/runtime/src/runtime/thread-context.ts +123 -0
- package/dist/runtime/src/runtime/thread-read.ts +67 -0
- package/dist/runtime/src/runtime/topic-config.ts +29 -0
- package/dist/runtime/src/runtime/turn-event-stream.ts +1051 -0
- package/dist/runtime/src/runtime/turn-runner.ts +2311 -0
- package/dist/runtime/src/runtime/turn-session.ts +116 -0
- package/dist/runtime/src/runtime/usage-alert.ts +51 -0
- package/dist/runtime/src/runtime/user-turn-envelope.ts +94 -0
- package/dist/runtime/src/runtime/visual-html.ts +175 -0
- package/dist/runtime/src/runtime/visual-store.ts +480 -0
- package/dist/runtime/src/runtime/visuals.ts +209 -0
- package/dist/runtime/src/runtime-gateway.ts +1045 -0
- package/dist/runtime/src/security/sanitize.ts +27 -0
- package/dist/runtime/src/security/sensitive-path.ts +41 -0
- package/dist/runtime/src/storage/activity-log.ts +167 -0
- package/dist/runtime/src/storage/api-messages.ts +766 -0
- package/dist/runtime/src/storage/api-topic-brief.ts +134 -0
- package/dist/runtime/src/storage/api-topic-config.ts +197 -0
- package/dist/runtime/src/storage/api-topics.ts +1647 -0
- package/dist/runtime/src/storage/app-settings.ts +50 -0
- package/dist/runtime/src/storage/ask-user-gates.ts +359 -0
- package/dist/runtime/src/storage/browser-profiles.ts +186 -0
- package/dist/runtime/src/storage/conversation-migration.ts +180 -0
- package/dist/runtime/src/storage/conversations.ts +377 -0
- package/dist/runtime/src/storage/decisions.ts +231 -0
- package/dist/runtime/src/storage/forum/agent-settings.ts +20 -0
- package/dist/runtime/src/storage/forum/index.ts +4 -0
- package/dist/runtime/src/storage/forum/repository.ts +283 -0
- package/dist/runtime/src/storage/forum/schema.ts +314 -0
- package/dist/runtime/src/storage/forum-db.ts +4 -0
- package/dist/runtime/src/storage/remote-session.ts +1028 -0
- package/dist/runtime/src/storage/runtime-events.ts +209 -0
- package/dist/runtime/src/storage/runtime-follow-ups.ts +212 -0
- package/dist/runtime/src/storage/runtime-gateway-submissions.ts +132 -0
- package/dist/runtime/src/storage/runtime-leases.ts +190 -0
- package/dist/runtime/src/storage/runtime-process-leases.ts +288 -0
- package/dist/runtime/src/storage/runtime-topic-state.ts +181 -0
- package/dist/runtime/src/storage/runtime-turn-requests.ts +846 -0
- package/dist/runtime/src/storage/self-schedules.ts +306 -0
- package/dist/runtime/src/storage/session-asks.ts +468 -0
- package/dist/runtime/src/storage/session-inbox-signal.ts +76 -0
- package/dist/runtime/src/storage/session-inbox.ts +161 -0
- package/dist/runtime/src/storage/sqlite.ts +154 -0
- package/dist/runtime/src/storage/storage-contract.ts +54 -0
- package/dist/runtime/src/storage/storage-host.ts +336 -0
- package/dist/runtime/src/storage/storage-public-host.ts +16 -0
- package/dist/runtime/src/storage/storage-public.ts +66 -0
- package/dist/runtime/src/storage/tasks.ts +172 -0
- package/dist/runtime/src/storage/token-stats.ts +432 -0
- package/dist/runtime/src/storage/topic-archive-state.ts +226 -0
- package/dist/runtime/src/storage/topic-archive.ts +169 -0
- package/dist/runtime/src/storage/topic-host-mcp-grants.ts +54 -0
- package/dist/runtime/src/storage/topic-link-records.ts +1085 -0
- package/dist/runtime/src/storage/topic-settings.ts +67 -0
- package/dist/runtime/src/storage/topic-tool-capabilities.ts +89 -0
- package/dist/runtime/src/storage/topic-transcript.ts +98 -0
- package/dist/runtime/src/storage/vault-crypto-core.ts +65 -0
- package/dist/runtime/src/storage/vault-crypto.ts +31 -0
- package/dist/runtime/src/storage/vault-public.ts +27 -0
- package/dist/runtime/src/storage/vault-request-gates.ts +359 -0
- package/dist/runtime/src/storage/vault.ts +388 -0
- package/dist/runtime/src/storage/wiki-summary-names.ts +52 -0
- package/dist/runtime/src/storage/wiki.ts +90 -0
- package/dist/runtime/src/topics/claim-abort.ts +190 -0
- package/dist/runtime/src/topics/create.ts +192 -0
- package/dist/runtime/src/topics/derive.ts +600 -0
- package/dist/runtime/src/topics/lifecycle.ts +425 -0
- package/dist/runtime/src/topics/links.ts +7 -0
- package/dist/runtime/src/topics/personal-general.ts +91 -0
- package/dist/runtime/src/topics/session.ts +1041 -0
- package/dist/runtime/src/topics/update.ts +287 -0
- package/dist/runtime/src/types/api.ts +591 -0
- package/dist/runtime/src/types.ts +418 -0
- package/dist/runtime/src/version.ts +1 -0
- package/dist/runtime/tsconfig.json +13 -0
- package/dist/runtime-gateway.js +514 -0
- package/dist/runtime-gateway.js.map +10 -0
- package/dist/runtime-helpers.js +1792 -0
- package/dist/runtime-helpers.js.map +40 -0
- package/dist/sqlite.js +66 -0
- package/dist/sqlite.js.map +10 -0
- package/dist/storage.js +5223 -0
- package/dist/storage.js.map +47 -0
- package/dist/types/apps/negotium/src/mcp-servers.d.ts +20 -0
- package/dist/types/packages/core/src/agents/api-topic-agent-switch.d.ts +38 -0
- package/dist/types/packages/core/src/agents/archiver.d.ts +87 -0
- package/dist/types/packages/core/src/agents/auth-check.d.ts +19 -0
- package/dist/types/packages/core/src/agents/claude-notices.d.ts +15 -0
- package/dist/types/packages/core/src/agents/claude-provider.d.ts +25 -0
- package/dist/types/packages/core/src/agents/claude-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/claude-runtime-inspection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/codex-app-server.d.ts +13 -0
- package/dist/types/packages/core/src/agents/codex-native-multi-agent.d.ts +20 -0
- package/dist/types/packages/core/src/agents/codex-provider.d.ts +64 -0
- package/dist/types/packages/core/src/agents/codex-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/codex-tier-resolver.d.ts +10 -0
- package/dist/types/packages/core/src/agents/codex-tree-kill.d.ts +13 -0
- package/dist/types/packages/core/src/agents/codex-tree-manager.d.ts +28 -0
- package/dist/types/packages/core/src/agents/codex-vault-hook-bridge.d.ts +28 -0
- package/dist/types/packages/core/src/agents/codex-windows-wrapper.d.ts +30 -0
- package/dist/types/packages/core/src/agents/compaction-support.d.ts +5 -0
- package/dist/types/packages/core/src/agents/compaction-tool-projection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/contracts.d.ts +68 -0
- package/dist/types/packages/core/src/agents/deep-map.d.ts +2 -0
- package/dist/types/packages/core/src/agents/execution-host.d.ts +33 -0
- package/dist/types/packages/core/src/agents/explicit-agent-switch.d.ts +26 -0
- package/dist/types/packages/core/src/agents/fork.d.ts +50 -0
- package/dist/types/packages/core/src/agents/hosted-agent.d.ts +15 -0
- package/dist/types/packages/core/src/agents/idle-archiver.d.ts +35 -0
- package/dist/types/packages/core/src/agents/idle-compact.d.ts +37 -0
- package/dist/types/packages/core/src/agents/index.d.ts +8 -0
- package/dist/types/packages/core/src/agents/maestro-provider.d.ts +75 -0
- package/dist/types/packages/core/src/agents/maestro-registry.d.ts +3 -0
- package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +147 -0
- package/dist/types/packages/core/src/agents/mcp-tools/common.d.ts +14 -0
- package/dist/types/packages/core/src/agents/mcp-tools/inline-assets.d.ts +24 -0
- package/dist/types/packages/core/src/agents/mcp-tools/publish-html.d.ts +18 -0
- package/dist/types/packages/core/src/agents/mcp-tools/request-vault.d.ts +124 -0
- package/dist/types/packages/core/src/agents/mcp-tools/self-config.d.ts +45 -0
- package/dist/types/packages/core/src/agents/mcp-tools/spawn-subagent.d.ts +148 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visual-compat.d.ts +55 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visuals.d.ts +70 -0
- package/dist/types/packages/core/src/agents/memory-archive-policy.d.ts +24 -0
- package/dist/types/packages/core/src/agents/model-catalog.d.ts +132 -0
- package/dist/types/packages/core/src/agents/public-helpers.d.ts +17 -0
- package/dist/types/packages/core/src/agents/registry.d.ts +5 -0
- package/dist/types/packages/core/src/agents/rollout/claude.d.ts +77 -0
- package/dist/types/packages/core/src/agents/rollout/codex.d.ts +119 -0
- package/dist/types/packages/core/src/agents/rollout/index.d.ts +6 -0
- package/dist/types/packages/core/src/agents/rollout/shared.d.ts +56 -0
- package/dist/types/packages/core/src/agents/self-config-core.d.ts +199 -0
- package/dist/types/packages/core/src/agents/task-events.d.ts +19 -0
- package/dist/types/packages/core/src/agents/tool-format.d.ts +25 -0
- package/dist/types/packages/core/src/agents/topic-cleanup.d.ts +83 -0
- package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +2 -0
- package/dist/types/packages/core/src/bus.d.ts +141 -0
- package/dist/types/packages/core/src/identifiers.d.ts +27 -0
- package/dist/types/packages/core/src/mcp/canonical-bridge-config.d.ts +21 -0
- package/dist/types/packages/core/src/mcp/factories/agent-health.d.ts +5 -0
- package/dist/types/packages/core/src/mcp/factories/compaction-log.d.ts +8 -0
- package/dist/types/packages/core/src/mcp/factories/decision.d.ts +18 -0
- package/dist/types/packages/core/src/mcp/factories/index.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +38 -0
- package/dist/types/packages/core/src/mcp/factories/session-history.d.ts +11 -0
- package/dist/types/packages/core/src/mcp/factories/stdio-protection.d.ts +10 -0
- package/dist/types/packages/core/src/mcp/factories/system-health.d.ts +37 -0
- package/dist/types/packages/core/src/mcp/factories/task.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/factories/vault.d.ts +9 -0
- package/dist/types/packages/core/src/mcp/mcp-helpers.d.ts +26 -0
- package/dist/types/packages/core/src/mcp/peer-bridge.d.ts +92 -0
- package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +147 -0
- package/dist/types/packages/core/src/mcp/session-comm/actor-policy.d.ts +120 -0
- package/dist/types/packages/core/src/mcp/session-comm/bridge-ipc-config.d.ts +6 -0
- package/dist/types/packages/core/src/mcp/session-comm/context.d.ts +44 -0
- package/dist/types/packages/core/src/mcp/session-comm/history-tools.d.ts +31 -0
- package/dist/types/packages/core/src/mcp/session-comm/hub-remote-session.d.ts +149 -0
- package/dist/types/packages/core/src/mcp/session-comm/limits.d.ts +8 -0
- package/dist/types/packages/core/src/mcp/session-comm/peer-forward.d.ts +85 -0
- package/dist/types/packages/core/src/mcp/session-comm/tell-permissions.d.ts +29 -0
- package/dist/types/packages/core/src/mcp/session-comm/topic-catalog.d.ts +59 -0
- package/dist/types/packages/core/src/mcp/session-history-limits.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/session-history-reader.d.ts +35 -0
- package/dist/types/packages/core/src/mcp/wiki-search-index.d.ts +59 -0
- package/dist/types/packages/core/src/mcp/wiki-server.d.ts +53 -0
- package/dist/types/packages/core/src/media/file-events.d.ts +14 -0
- package/dist/types/packages/core/src/media/text-extractor.d.ts +34 -0
- package/dist/types/packages/core/src/outbox/coalescing-runner.d.ts +68 -0
- package/dist/types/packages/core/src/outbox/file-ops.d.ts +79 -0
- package/dist/types/packages/core/src/outbox/index.d.ts +3 -0
- package/dist/types/packages/core/src/outbox/utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/background-bash/context.d.ts +1 -0
- package/dist/types/packages/core/src/platform/background-bash/manager.d.ts +34 -0
- package/dist/types/packages/core/src/platform/config-helpers.d.ts +20 -0
- package/dist/types/packages/core/src/platform/config.d.ts +178 -0
- package/dist/types/packages/core/src/platform/constants.d.ts +20 -0
- package/dist/types/packages/core/src/platform/delay.d.ts +1 -0
- package/dist/types/packages/core/src/platform/error.d.ts +6 -0
- package/dist/types/packages/core/src/platform/file-utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/ipc.d.ts +32 -0
- package/dist/types/packages/core/src/platform/jsonl.d.ts +46 -0
- package/dist/types/packages/core/src/platform/lifecycle.d.ts +40 -0
- package/dist/types/packages/core/src/platform/logger.d.ts +20 -0
- package/dist/types/packages/core/src/platform/maestro-bootstrap-env.d.ts +0 -0
- package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +73 -0
- package/dist/types/packages/core/src/platform/mcp-config.d.ts +286 -0
- package/dist/types/packages/core/src/platform/memoize-import.d.ts +15 -0
- package/dist/types/packages/core/src/platform/paths.d.ts +18 -0
- package/dist/types/packages/core/src/platform/playwright/browser-processes.d.ts +60 -0
- package/dist/types/packages/core/src/platform/playwright/capability.d.ts +1 -0
- package/dist/types/packages/core/src/platform/playwright/headed-launch.d.ts +13 -0
- package/dist/types/packages/core/src/platform/playwright/manager-utils.d.ts +34 -0
- package/dist/types/packages/core/src/platform/playwright/manager.d.ts +194 -0
- package/dist/types/packages/core/src/platform/playwright/mcp-transport.d.ts +4 -0
- package/dist/types/packages/core/src/platform/playwright/profile-management.d.ts +8 -0
- package/dist/types/packages/core/src/platform/playwright/public-runtime.d.ts +6 -0
- package/dist/types/packages/core/src/platform/playwright/transport-probe.d.ts +13 -0
- package/dist/types/packages/core/src/platform/playwright/vault-broker.d.ts +6 -0
- package/dist/types/packages/core/src/platform/public-runtime.d.ts +3 -0
- package/dist/types/packages/core/src/prompts/builders.d.ts +78 -0
- package/dist/types/packages/core/src/query/active-rooms.d.ts +240 -0
- package/dist/types/packages/core/src/query/public-runtime.d.ts +4 -0
- package/dist/types/packages/core/src/query/room-query-registry.d.ts +71 -0
- package/dist/types/packages/core/src/query/session-inbox-cleanup.d.ts +5 -0
- package/dist/types/packages/core/src/query/session-inbox-path.d.ts +8 -0
- package/dist/types/packages/core/src/query/state.d.ts +25 -0
- package/dist/types/packages/core/src/query/types.d.ts +6 -0
- package/dist/types/packages/core/src/runtime/actor-topic-reach.d.ts +63 -0
- package/dist/types/packages/core/src/runtime/actor-topic-scope.d.ts +127 -0
- package/dist/types/packages/core/src/runtime/ask-callbacks.d.ts +53 -0
- package/dist/types/packages/core/src/runtime/attachments.d.ts +36 -0
- package/dist/types/packages/core/src/runtime/background-session-policy.d.ts +1 -0
- package/dist/types/packages/core/src/runtime/background-sessions.d.ts +27 -0
- package/dist/types/packages/core/src/runtime/bashrs-completions.d.ts +50 -0
- package/dist/types/packages/core/src/runtime/channel-context.d.ts +13 -0
- package/dist/types/packages/core/src/runtime/context-warning.d.ts +46 -0
- package/dist/types/packages/core/src/runtime/cron-sessions.d.ts +9 -0
- package/dist/types/packages/core/src/runtime/errors.d.ts +6 -0
- package/dist/types/packages/core/src/runtime/event-heartbeat.d.ts +17 -0
- package/dist/types/packages/core/src/runtime/file-hooks.d.ts +38 -0
- package/dist/types/packages/core/src/runtime/playwright-turn-abort.d.ts +12 -0
- package/dist/types/packages/core/src/runtime/public-helpers.d.ts +17 -0
- package/dist/types/packages/core/src/runtime/remote-session-grant.d.ts +91 -0
- package/dist/types/packages/core/src/runtime/remote-session-inbox.d.ts +206 -0
- package/dist/types/packages/core/src/runtime/remote-session-reply-outbox.d.ts +37 -0
- package/dist/types/packages/core/src/runtime/task-format.d.ts +4 -0
- package/dist/types/packages/core/src/runtime/tasks.d.ts +3 -0
- package/dist/types/packages/core/src/runtime/thread-context.d.ts +62 -0
- package/dist/types/packages/core/src/runtime/topic-config.d.ts +24 -0
- package/dist/types/packages/core/src/runtime/turn-event-stream.d.ts +47 -0
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +284 -0
- package/dist/types/packages/core/src/runtime/turn-session.d.ts +49 -0
- package/dist/types/packages/core/src/runtime/usage-alert.d.ts +11 -0
- package/dist/types/packages/core/src/runtime/user-turn-envelope.d.ts +37 -0
- package/dist/types/packages/core/src/runtime/visual-html.d.ts +13 -0
- package/dist/types/packages/core/src/runtime/visual-store.d.ts +71 -0
- package/dist/types/packages/core/src/runtime/visuals.d.ts +33 -0
- package/dist/types/packages/core/src/runtime-gateway.d.ts +282 -0
- package/dist/types/packages/core/src/security/sanitize.d.ts +16 -0
- package/dist/types/packages/core/src/security/sensitive-path.d.ts +1 -0
- package/dist/types/packages/core/src/storage/activity-log.d.ts +25 -0
- package/dist/types/packages/core/src/storage/api-messages.d.ts +156 -0
- package/dist/types/packages/core/src/storage/api-topic-brief.d.ts +39 -0
- package/dist/types/packages/core/src/storage/api-topic-config.d.ts +23 -0
- package/dist/types/packages/core/src/storage/api-topics.d.ts +274 -0
- package/dist/types/packages/core/src/storage/app-settings.d.ts +4 -0
- package/dist/types/packages/core/src/storage/ask-user-gates.d.ts +65 -0
- package/dist/types/packages/core/src/storage/browser-profiles.d.ts +31 -0
- package/dist/types/packages/core/src/storage/conversations.d.ts +149 -0
- package/dist/types/packages/core/src/storage/decisions.d.ts +45 -0
- package/dist/types/packages/core/src/storage/forum/agent-settings.d.ts +3 -0
- package/dist/types/packages/core/src/storage/forum/index.d.ts +4 -0
- package/dist/types/packages/core/src/storage/forum/repository.d.ts +42 -0
- package/dist/types/packages/core/src/storage/forum/schema.d.ts +38 -0
- package/dist/types/packages/core/src/storage/forum-db.d.ts +2 -0
- package/dist/types/packages/core/src/storage/remote-session.d.ts +318 -0
- package/dist/types/packages/core/src/storage/runtime-events.d.ts +33 -0
- package/dist/types/packages/core/src/storage/runtime-leases.d.ts +27 -0
- package/dist/types/packages/core/src/storage/runtime-process-leases.d.ts +47 -0
- package/dist/types/packages/core/src/storage/runtime-topic-state.d.ts +39 -0
- package/dist/types/packages/core/src/storage/runtime-turn-requests.d.ts +163 -0
- package/dist/types/packages/core/src/storage/self-schedules.d.ts +54 -0
- package/dist/types/packages/core/src/storage/session-asks.d.ts +78 -0
- package/dist/types/packages/core/src/storage/session-inbox-signal.d.ts +35 -0
- package/dist/types/packages/core/src/storage/session-inbox.d.ts +36 -0
- package/dist/types/packages/core/src/storage/sqlite.d.ts +20 -0
- package/dist/types/packages/core/src/storage/storage-contract.d.ts +46 -0
- package/dist/types/packages/core/src/storage/storage-host.d.ts +41 -0
- package/dist/types/packages/core/src/storage/storage-public-host.d.ts +7 -0
- package/dist/types/packages/core/src/storage/storage-public.d.ts +45 -0
- package/dist/types/packages/core/src/storage/tasks.d.ts +49 -0
- package/dist/types/packages/core/src/storage/token-stats.d.ts +69 -0
- package/dist/types/packages/core/src/storage/topic-archive-state.d.ts +33 -0
- package/dist/types/packages/core/src/storage/topic-archive.d.ts +42 -0
- package/dist/types/packages/core/src/storage/topic-host-mcp-grants.d.ts +5 -0
- package/dist/types/packages/core/src/storage/topic-link-records.d.ts +281 -0
- package/dist/types/packages/core/src/storage/topic-settings.d.ts +19 -0
- package/dist/types/packages/core/src/storage/topic-tool-capabilities.d.ts +37 -0
- package/dist/types/packages/core/src/storage/topic-transcript.d.ts +38 -0
- package/dist/types/packages/core/src/storage/vault-crypto-core.d.ts +6 -0
- package/dist/types/packages/core/src/storage/vault-crypto.d.ts +12 -0
- package/dist/types/packages/core/src/storage/vault-public.d.ts +3 -0
- package/dist/types/packages/core/src/storage/vault-request-gates.d.ts +69 -0
- package/dist/types/packages/core/src/storage/vault.d.ts +49 -0
- package/dist/types/packages/core/src/storage/wiki-summary-names.d.ts +13 -0
- package/dist/types/packages/core/src/storage/wiki.d.ts +15 -0
- package/dist/types/packages/core/src/topics/derive.d.ts +83 -0
- package/dist/types/packages/core/src/topics/lifecycle.d.ts +75 -0
- package/dist/types/packages/core/src/topics/links.d.ts +2 -0
- package/dist/types/packages/core/src/topics/personal-general.d.ts +15 -0
- package/dist/types/packages/core/src/topics/session.d.ts +70 -0
- package/dist/types/packages/core/src/types/api.d.ts +551 -0
- package/dist/types/packages/core/src/types.d.ts +405 -0
- package/dist/types/packages/core/src/version.d.ts +1 -0
- package/dist/types/packages/module-cron/src/background-sessions.d.ts +2 -0
- package/dist/types/packages/module-cron/src/context.d.ts +15 -0
- package/dist/types/packages/module-cron/src/host.d.ts +23 -0
- package/dist/types/packages/module-cron/src/index.d.ts +14 -0
- package/dist/types/packages/module-cron/src/module.d.ts +13 -0
- package/dist/types/packages/module-cron/src/schedule.d.ts +23 -0
- package/dist/types/packages/module-cron/src/scheduler.d.ts +46 -0
- package/dist/types/packages/module-cron/src/scripts.d.ts +29 -0
- package/dist/types/packages/module-cron/src/store.d.ts +152 -0
- package/dist/types/packages/module-cron/src/summarize.d.ts +4 -0
- package/dist/vault.js +848 -0
- package/dist/vault.js.map +18 -0
- package/install-bash-rs.mjs +90 -0
- package/install-browser-rs.mjs +83 -0
- package/package.json +171 -4
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/** Stable, daemon-focused core surface. Keep this free of the root barrel. */
|
|
2
|
+
export { killOwnedCodexTreesForShutdown } from "#agents/codex-tree-kill";
|
|
3
|
+
export {
|
|
4
|
+
reconcilePendingAskUserQuestionGates,
|
|
5
|
+
startAskUserQuestionGateOwner,
|
|
6
|
+
stopAskUserQuestionGateOwner,
|
|
7
|
+
} from "#agents/mcp-tools/ask-user";
|
|
8
|
+
export {
|
|
9
|
+
reconcilePendingRequestVaultGates,
|
|
10
|
+
startRequestVaultGateOwner,
|
|
11
|
+
stopRequestVaultGateOwner,
|
|
12
|
+
} from "#agents/mcp-tools/request-vault";
|
|
13
|
+
export { sweepStaleSubagentCards } from "#agents/mcp-tools/spawn-subagent";
|
|
14
|
+
export {
|
|
15
|
+
RuntimeGatewayIdempotencyConflictError,
|
|
16
|
+
RuntimeGatewayTopicUnavailableError,
|
|
17
|
+
submitRuntimeGatewayTurn,
|
|
18
|
+
} from "#application/submit-runtime-gateway-turn";
|
|
19
|
+
export { submitUserMessage } from "#application/submit-user-message";
|
|
20
|
+
export { switchTopicEffort } from "#application/switch-topic-effort";
|
|
21
|
+
export { switchTopicModel } from "#application/switch-topic-model";
|
|
22
|
+
export { TopicServiceError, topicService } from "#application/topic-service";
|
|
23
|
+
export {
|
|
24
|
+
deleteFollowUp,
|
|
25
|
+
editFollowUp,
|
|
26
|
+
FollowUpNotFoundError,
|
|
27
|
+
followUpLine,
|
|
28
|
+
holdFollowUpsAfterStop,
|
|
29
|
+
holdOrSubmitRuntimeGatewayTurn,
|
|
30
|
+
moveFollowUp,
|
|
31
|
+
sendFollowUpNow,
|
|
32
|
+
startFollowUpDispatcher,
|
|
33
|
+
} from "#application/turn-follow-ups";
|
|
34
|
+
export {
|
|
35
|
+
deleteVaultEntry,
|
|
36
|
+
executeVaultCommand,
|
|
37
|
+
listVaultEntries,
|
|
38
|
+
saveVaultEntry,
|
|
39
|
+
} from "#application/vault-command";
|
|
40
|
+
export type { RuntimeBusEvent, TopicDeletedMeta } from "#bus";
|
|
41
|
+
export { runtimeBus, WsHub } from "#bus";
|
|
42
|
+
export {
|
|
43
|
+
asClientMessageId,
|
|
44
|
+
asMessageId,
|
|
45
|
+
asRequestId,
|
|
46
|
+
asTopicId,
|
|
47
|
+
asUserId,
|
|
48
|
+
} from "#identifiers";
|
|
49
|
+
export { setRuntimeMcpPort } from "#mcp/runtime-spec";
|
|
50
|
+
export { MAX_PEER_MESSAGE_LENGTH } from "#mcp/session-comm/limits";
|
|
51
|
+
export { killAllBgBash } from "#platform/background-bash/manager";
|
|
52
|
+
export {
|
|
53
|
+
DATA_DIR,
|
|
54
|
+
FALLBACK_AGENT,
|
|
55
|
+
NEGOTIUM_PORT,
|
|
56
|
+
NODE_CONTROL_TOKEN,
|
|
57
|
+
NODE_ID,
|
|
58
|
+
RUN_DIR,
|
|
59
|
+
STATE_DIR,
|
|
60
|
+
WORKSPACE_DIR,
|
|
61
|
+
} from "#platform/config";
|
|
62
|
+
export { onShutdown, runShutdown } from "#platform/lifecycle";
|
|
63
|
+
export { logger } from "#platform/logger";
|
|
64
|
+
export type { NodeMcpEntry } from "#platform/mcp-config";
|
|
65
|
+
export {
|
|
66
|
+
getNodeMcpServers,
|
|
67
|
+
hostMcpGrantRefusal,
|
|
68
|
+
isReservedRuntimeMcpServerName,
|
|
69
|
+
resolveCuaRsBinary,
|
|
70
|
+
setCuaRsMcpPort,
|
|
71
|
+
setNodeMcpServers,
|
|
72
|
+
} from "#platform/mcp-config";
|
|
73
|
+
export type {
|
|
74
|
+
NegotiumNodeModule,
|
|
75
|
+
StartedNegotiumNodeModules,
|
|
76
|
+
} from "#platform/modules";
|
|
77
|
+
export { startNegotiumNodeModules } from "#platform/modules";
|
|
78
|
+
export {
|
|
79
|
+
nodeRequestHandlerNames,
|
|
80
|
+
runNodeRequestHandlers,
|
|
81
|
+
} from "#platform/node-plugins";
|
|
82
|
+
export {
|
|
83
|
+
killAllPlaywright,
|
|
84
|
+
reapPlaywrightOrphans as reapOrphanBrowsers,
|
|
85
|
+
} from "#platform/playwright/manager";
|
|
86
|
+
export { abortAllRooms, listRunningTopicQueries } from "#query/active-rooms";
|
|
87
|
+
export { parseActorTopicScope, validateActorTopicScope } from "#runtime/actor-topic-scope";
|
|
88
|
+
export { failInterruptedRemoteAskCallbacks } from "#runtime/ask-callbacks";
|
|
89
|
+
export { listBackgroundSessionsForUser } from "#runtime/background-sessions";
|
|
90
|
+
export type {
|
|
91
|
+
BashrsCompletion,
|
|
92
|
+
BashrsCompletionSink,
|
|
93
|
+
} from "#runtime/bashrs-completions";
|
|
94
|
+
export {
|
|
95
|
+
flushBashrsCompletions,
|
|
96
|
+
setBashrsCompletionSink,
|
|
97
|
+
startBashrsCompletionsWorker,
|
|
98
|
+
} from "#runtime/bashrs-completions";
|
|
99
|
+
export type { FileHooks, UploadAccess } from "#runtime/file-hooks";
|
|
100
|
+
export { setFileHooks } from "#runtime/file-hooks";
|
|
101
|
+
export {
|
|
102
|
+
listRuntimeGatewayCapabilities,
|
|
103
|
+
registerRuntimeGatewayCapability,
|
|
104
|
+
} from "#runtime/gateway-capabilities";
|
|
105
|
+
export { startSessionInboxWorker } from "#runtime/inbox";
|
|
106
|
+
export { validateRemoteSessionGrant } from "#runtime/remote-session-grant";
|
|
107
|
+
export {
|
|
108
|
+
deliverRemoteSessionInbox,
|
|
109
|
+
parseRemoteSessionInboxDelivery,
|
|
110
|
+
RemoteSessionInboxError,
|
|
111
|
+
recoverRemoteSessionInbox,
|
|
112
|
+
resolveRemoteSessionInboxPrincipal,
|
|
113
|
+
} from "#runtime/remote-session-inbox";
|
|
114
|
+
export {
|
|
115
|
+
runRemoteSessionMaintenance,
|
|
116
|
+
startRemoteSessionReplyOutboxWorker,
|
|
117
|
+
} from "#runtime/remote-session-reply-outbox";
|
|
118
|
+
export { startAiTurn, startDurableTurnRequestWorker } from "#runtime/turn-runner";
|
|
119
|
+
export type { PortableTopicVisual } from "#runtime/visual-store";
|
|
120
|
+
export { getPortableTopicVisual } from "#runtime/visual-store";
|
|
121
|
+
export {
|
|
122
|
+
appendApiMessage,
|
|
123
|
+
getApiMessage,
|
|
124
|
+
getLastMessagePreviews,
|
|
125
|
+
listApiMessages,
|
|
126
|
+
listThreadMessages,
|
|
127
|
+
setApiMessageReactions,
|
|
128
|
+
softDeleteApiMessage,
|
|
129
|
+
updateApiMessageText,
|
|
130
|
+
} from "#storage/api-messages";
|
|
131
|
+
export {
|
|
132
|
+
getApiTopicConfig,
|
|
133
|
+
setApiTopicConfig,
|
|
134
|
+
type TopicConfig,
|
|
135
|
+
} from "#storage/api-topic-config";
|
|
136
|
+
export {
|
|
137
|
+
getTopic,
|
|
138
|
+
type LocalSurfaceScopeStatus,
|
|
139
|
+
localSurfaceScopeStatus,
|
|
140
|
+
type SurfaceScopeStampStatus,
|
|
141
|
+
surfaceScopeStampStatus,
|
|
142
|
+
upsertTopic,
|
|
143
|
+
} from "#storage/api-topics";
|
|
144
|
+
export { getGlobalAiName, setGlobalAiName } from "#storage/app-settings";
|
|
145
|
+
export { readDecisions, writeDecisionGraphSvg } from "#storage/decisions";
|
|
146
|
+
export {
|
|
147
|
+
claimRemoteSessionInbox,
|
|
148
|
+
purgeRemoteSessionInboxClaims,
|
|
149
|
+
purgeStaleRemoteSessionAsks,
|
|
150
|
+
releaseRemoteSessionInboxClaim,
|
|
151
|
+
remoteSessionPayloadHash,
|
|
152
|
+
takeRemoteSessionAsk,
|
|
153
|
+
} from "#storage/remote-session";
|
|
154
|
+
export type { StoredRuntimeEvent } from "#storage/runtime-events";
|
|
155
|
+
export {
|
|
156
|
+
earliestRuntimeEventSeq,
|
|
157
|
+
latestRuntimeEventSeq,
|
|
158
|
+
listRecentRuntimeEventsForTopic,
|
|
159
|
+
listRuntimeEventsAfter,
|
|
160
|
+
pruneRuntimeEvents,
|
|
161
|
+
} from "#storage/runtime-events";
|
|
162
|
+
export { acquireRuntimeProcessLease } from "#storage/runtime-process-leases";
|
|
163
|
+
export { getTopicStats } from "#storage/token-stats";
|
|
164
|
+
export {
|
|
165
|
+
type AdminRepairOtiumTopicScopeInput,
|
|
166
|
+
type AdminRepairOtiumTopicScopeRefusal,
|
|
167
|
+
type AdminRepairOtiumTopicScopeResult,
|
|
168
|
+
adminRepairOtiumTopicScope,
|
|
169
|
+
committedClaimsByTopic,
|
|
170
|
+
getTopicCreateClaim,
|
|
171
|
+
getTopicTombstone,
|
|
172
|
+
insertCommittedTopicCreateClaim,
|
|
173
|
+
isTopicClaimAbortFenced,
|
|
174
|
+
latestTopicScopeMove,
|
|
175
|
+
listTopicTombstonesAfter,
|
|
176
|
+
markTopicCreateClaimAborted,
|
|
177
|
+
OTIUM_TOPIC_SCOPE_IMMUTABLE_ERROR,
|
|
178
|
+
pruneTopicCreateClaims,
|
|
179
|
+
recordTopicLinkNodeIdentity,
|
|
180
|
+
TOPIC_CREATE_CLAIM_PRUNE_BATCH,
|
|
181
|
+
type TopicCreateClaim,
|
|
182
|
+
type TopicTombstone,
|
|
183
|
+
topicHasMessagesAfterClaim,
|
|
184
|
+
topicLinkDbEpoch,
|
|
185
|
+
topicLinkNodeIdentity,
|
|
186
|
+
topicLinkPayloadHash,
|
|
187
|
+
topicTombstoneHighWater,
|
|
188
|
+
} from "#storage/topic-link-records";
|
|
189
|
+
export {
|
|
190
|
+
type AbortTopicCreateClaimOptions,
|
|
191
|
+
abortTopicCreateClaim,
|
|
192
|
+
type TopicCreateClaimAbortResult,
|
|
193
|
+
} from "#topics/claim-abort";
|
|
194
|
+
export { TopicValidationError } from "#topics/create";
|
|
195
|
+
export {
|
|
196
|
+
getVisibleTopics,
|
|
197
|
+
isParticipant,
|
|
198
|
+
TopicDeriveBusyError,
|
|
199
|
+
TopicForkCompactionError,
|
|
200
|
+
TopicTitleConflictError,
|
|
201
|
+
} from "#topics/derive";
|
|
202
|
+
export { ensurePersonalGeneral } from "#topics/personal-general";
|
|
203
|
+
export { compactTopicSession } from "#topics/session";
|
|
204
|
+
export {
|
|
205
|
+
TopicUpdateConflictError,
|
|
206
|
+
updateManagerTopicRuntimeConfig,
|
|
207
|
+
updateTopicSettings,
|
|
208
|
+
} from "#topics/update";
|
|
209
|
+
export type { AgentKind, EffortLevel } from "#types";
|
|
210
|
+
export type { AiMode, AttachmentDto, TopicDto, TopicSurface } from "#types/api";
|
|
211
|
+
export { NEGOTIUM_VERSION } from "#version";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starvation-free trigger coalescing for workers driven by *both* an irregular
|
|
3
|
+
* event source (fs.watch, in-process signals) and a periodic safety net poll.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists instead of `debouncedFlush`
|
|
6
|
+
* -------------------------------------------
|
|
7
|
+
* A trailing-edge debounce re-arms its timer on every trigger. When any trigger
|
|
8
|
+
* source fires faster than the debounce delay the quiet window never arrives
|
|
9
|
+
* and the work is postponed forever — the exact self-starving regression that a
|
|
10
|
+
* 100ms fallback poll feeding a 200ms debounce produced (b919a2e).
|
|
11
|
+
*
|
|
12
|
+
* The invariant here is the opposite one:
|
|
13
|
+
*
|
|
14
|
+
* Once a run is armed, nothing can push it further out.
|
|
15
|
+
*
|
|
16
|
+
* A trigger only ever *creates* a timer; it never clears or reschedules one.
|
|
17
|
+
* Extra triggers arriving before that timer fires are absorbed for free, so a
|
|
18
|
+
* high trigger rate makes the run happen sooner, never later.
|
|
19
|
+
*
|
|
20
|
+
* trigger() ──► running? ── yes ─► pending = true (run again after)
|
|
21
|
+
* │ no
|
|
22
|
+
* ▼
|
|
23
|
+
* armed? ── yes ─► drop (already guaranteed to run)
|
|
24
|
+
* │ no
|
|
25
|
+
* ▼
|
|
26
|
+
* wait = max(0, lastStart + minIntervalMs - now)
|
|
27
|
+
* wait === 0 ─► run immediately (leading edge: ~0 latency)
|
|
28
|
+
* wait > 0 ─► setTimeout(run, wait) (bounded: ≤ minIntervalMs)
|
|
29
|
+
*
|
|
30
|
+
* Consequences:
|
|
31
|
+
* - Latency: an idle worker runs on the *leading* edge, so a single message is
|
|
32
|
+
* picked up immediately. Inside a burst the worst case is `minIntervalMs`.
|
|
33
|
+
* - Throughput cap: runs start at most once per `minIntervalMs`, so a chatty
|
|
34
|
+
* watcher (including events caused by the run's own writes) cannot spin.
|
|
35
|
+
* - Coalescing: triggers landing while a run is in flight collapse into a
|
|
36
|
+
* single follow-up run scheduled once the current one settles.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
import { logger as defaultLogger } from "#platform/logger";
|
|
40
|
+
|
|
41
|
+
export interface CoalescingRunnerLogger {
|
|
42
|
+
error(fields: Record<string, unknown>, message: string): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface CoalescingRunnerOptions {
|
|
46
|
+
/** The work to coalesce. Rejections are logged, never propagated. */
|
|
47
|
+
run: () => Promise<void> | void;
|
|
48
|
+
/** Log label. */
|
|
49
|
+
label: string;
|
|
50
|
+
/**
|
|
51
|
+
* Minimum gap between the *starts* of two consecutive runs, and therefore the
|
|
52
|
+
* upper bound on how long a trigger can wait for one. `0` runs on every
|
|
53
|
+
* trigger.
|
|
54
|
+
*/
|
|
55
|
+
minIntervalMs: number;
|
|
56
|
+
logger?: CoalescingRunnerLogger;
|
|
57
|
+
/** Injectable clock, for deterministic tests. */
|
|
58
|
+
now?: () => number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface CoalescingRunner {
|
|
62
|
+
/** Request a run "as soon as the rate limit allows". Never delays a pending one. */
|
|
63
|
+
trigger(): void;
|
|
64
|
+
/** Run now, ignoring the rate limit (boot drain). Resolves when that run settles. */
|
|
65
|
+
runNow(): Promise<void>;
|
|
66
|
+
/** Release timers. Further triggers are ignored; an in-flight run is not cancelled. */
|
|
67
|
+
stop(): void;
|
|
68
|
+
/** Completed + in-flight run count. Test/diagnostics only. */
|
|
69
|
+
readonly runCount: number;
|
|
70
|
+
/** True while a run is in flight. Test/diagnostics only. */
|
|
71
|
+
readonly isRunning: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createCoalescingRunner(options: CoalescingRunnerOptions): CoalescingRunner {
|
|
75
|
+
const { run, label, minIntervalMs } = options;
|
|
76
|
+
const log = options.logger ?? defaultLogger;
|
|
77
|
+
const now = options.now ?? Date.now;
|
|
78
|
+
|
|
79
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
80
|
+
let running = false;
|
|
81
|
+
let pending = false;
|
|
82
|
+
let stopped = false;
|
|
83
|
+
let lastStart: number | null = null;
|
|
84
|
+
let runCount = 0;
|
|
85
|
+
|
|
86
|
+
function arm(): void {
|
|
87
|
+
if (stopped || running || timer) return;
|
|
88
|
+
const wait = lastStart === null ? 0 : Math.max(0, lastStart + minIntervalMs - now());
|
|
89
|
+
if (wait <= 0) {
|
|
90
|
+
void execute();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
timer = setTimeout(() => {
|
|
94
|
+
timer = null;
|
|
95
|
+
void execute();
|
|
96
|
+
}, wait);
|
|
97
|
+
timer.unref?.();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function execute(): Promise<void> {
|
|
101
|
+
if (stopped || running) return;
|
|
102
|
+
running = true;
|
|
103
|
+
pending = false;
|
|
104
|
+
lastStart = now();
|
|
105
|
+
runCount++;
|
|
106
|
+
try {
|
|
107
|
+
await run();
|
|
108
|
+
} catch (err) {
|
|
109
|
+
log.error({ err, label }, `${label}: Unhandled error`);
|
|
110
|
+
} finally {
|
|
111
|
+
running = false;
|
|
112
|
+
if (pending && !stopped) {
|
|
113
|
+
pending = false;
|
|
114
|
+
// Re-arm through the normal path so the rate limit still applies. A run
|
|
115
|
+
// that outlasted `minIntervalMs` re-runs immediately.
|
|
116
|
+
arm();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
trigger(): void {
|
|
123
|
+
if (stopped) return;
|
|
124
|
+
if (running) {
|
|
125
|
+
pending = true;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
arm();
|
|
129
|
+
},
|
|
130
|
+
async runNow(): Promise<void> {
|
|
131
|
+
if (stopped) return;
|
|
132
|
+
if (running) {
|
|
133
|
+
pending = true;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (timer) {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
timer = null;
|
|
139
|
+
}
|
|
140
|
+
await execute();
|
|
141
|
+
},
|
|
142
|
+
stop(): void {
|
|
143
|
+
stopped = true;
|
|
144
|
+
pending = false;
|
|
145
|
+
if (timer) {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
timer = null;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
get runCount(): number {
|
|
151
|
+
return runCount;
|
|
152
|
+
},
|
|
153
|
+
get isRunning(): boolean {
|
|
154
|
+
return running;
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { appendFileSync, existsSync, readFileSync, renameSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { readJsonlLines } from "#platform/jsonl";
|
|
4
|
+
import { logger } from "#platform/logger";
|
|
5
|
+
|
|
6
|
+
const PROCESSING_SUFFIX = ".processing";
|
|
7
|
+
|
|
8
|
+
export interface OutboxLogger {
|
|
9
|
+
debug(fields: Record<string, unknown>, message: string): void;
|
|
10
|
+
info(fields: Record<string, unknown>, message: string): void;
|
|
11
|
+
warn(fields: Record<string, unknown>, message: string): void;
|
|
12
|
+
error(fields: Record<string, unknown>, message: string): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface OutboxFileHost {
|
|
16
|
+
logger: OutboxLogger;
|
|
17
|
+
readJsonlLines(path: string): string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface OutboxFileOps {
|
|
21
|
+
isProcessingFile(name: string): boolean;
|
|
22
|
+
drainOutboxFile(
|
|
23
|
+
filePath: string,
|
|
24
|
+
label: string,
|
|
25
|
+
): { lines: string[]; processingPath: string } | null;
|
|
26
|
+
deleteProcessingFile(processingPath: string, label: string, consumedLines?: number): void;
|
|
27
|
+
parseOutboxLine<T>(line: string, label: string): T | null;
|
|
28
|
+
processOutboxFile<T extends Record<string, unknown>>(
|
|
29
|
+
filePath: string,
|
|
30
|
+
label: string,
|
|
31
|
+
handler: (entry: T) => Promise<void>,
|
|
32
|
+
opts?: { maxRetries?: number },
|
|
33
|
+
): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const defaultHost: OutboxFileHost = { logger, readJsonlLines };
|
|
37
|
+
const hostContext = new AsyncLocalStorage<OutboxFileHost>();
|
|
38
|
+
|
|
39
|
+
function host(): OutboxFileHost {
|
|
40
|
+
return hostContext.getStore() ?? defaultHost;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** True if `name` is an in-flight `.processing` claim file written by drainOutboxFile. */
|
|
44
|
+
export function isProcessingFile(name: string): boolean {
|
|
45
|
+
return name.endsWith(PROCESSING_SUFFIX);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function tryUnlink(path: string, label: string, reason: string) {
|
|
49
|
+
try {
|
|
50
|
+
unlinkSync(path);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
// ENOENT means another path already cleaned this up (e.g. concurrent
|
|
53
|
+
// drain, double-delete in a retry loop). Not worth warning about.
|
|
54
|
+
if ((e as NodeJS.ErrnoException)?.code === "ENOENT") {
|
|
55
|
+
host().logger.debug({ path }, `${label}: ${reason} (already gone)`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
host().logger.warn({ err: e, path }, `${label}: ${reason}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Atomically claim a .jsonl outbox file for processing.
|
|
64
|
+
* Recovers leftover .processing files from crashes, renames the pending file
|
|
65
|
+
* to .processing to prevent race conditions, and returns the parsed lines.
|
|
66
|
+
* Returns null if the file doesn't exist or can't be claimed.
|
|
67
|
+
*
|
|
68
|
+
* Partial-failure edge case: when a crash leftover is merged back into pending,
|
|
69
|
+
* `readFileSync` → `appendFileSync` → `unlinkSync` runs sequentially. If
|
|
70
|
+
* `appendFileSync` throws mid-write (e.g. ENOSPC), the pending file receives a
|
|
71
|
+
* partial copy of the leftover and the catch branch still unlinks the leftover
|
|
72
|
+
* to avoid an infinite retry loop — so the tail of the leftover can be lost.
|
|
73
|
+
* In practice the next drain parses the partial line as invalid JSON and drops
|
|
74
|
+
* it via `parseOutboxLine`. This is a deliberate trade-off: we accept the rare
|
|
75
|
+
* partial loss instead of stalling the outbox when the disk is full.
|
|
76
|
+
*/
|
|
77
|
+
export function drainOutboxFile(
|
|
78
|
+
filePath: string,
|
|
79
|
+
label: string,
|
|
80
|
+
): { lines: string[]; processingPath: string } | null {
|
|
81
|
+
const processingPath = filePath + PROCESSING_SUFFIX;
|
|
82
|
+
const hasPending = existsSync(filePath);
|
|
83
|
+
const hasLeftover = existsSync(processingPath);
|
|
84
|
+
|
|
85
|
+
// Merge leftover into pending before claim.
|
|
86
|
+
// hasPending=false: normal crash recovery — leftover is all we have.
|
|
87
|
+
// hasPending=true: crash + writer race — without merge, the rename below
|
|
88
|
+
// would overwrite leftover and drop its lines.
|
|
89
|
+
if (hasLeftover) {
|
|
90
|
+
// warn on crash+race (rare), info on plain recovery (expected after crash)
|
|
91
|
+
const logMsg = `${label}: merging leftover .processing before claim`;
|
|
92
|
+
const logCtx = { filePath, processingPath, hadPending: hasPending };
|
|
93
|
+
if (hasPending) host().logger.warn(logCtx, logMsg);
|
|
94
|
+
else host().logger.info(logCtx, logMsg);
|
|
95
|
+
try {
|
|
96
|
+
const leftover = readFileSync(processingPath, "utf-8");
|
|
97
|
+
if (leftover) appendFileSync(filePath, leftover.endsWith("\n") ? leftover : `${leftover}\n`);
|
|
98
|
+
unlinkSync(processingPath);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
host().logger.error(
|
|
101
|
+
{ err: e, processingPath },
|
|
102
|
+
`${label}: failed to merge leftover — data may be lost`,
|
|
103
|
+
);
|
|
104
|
+
tryUnlink(processingPath, label, "failed to clean up leftover after merge error");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!existsSync(filePath)) return null;
|
|
109
|
+
|
|
110
|
+
// Atomically rename to prevent race condition with writer
|
|
111
|
+
try {
|
|
112
|
+
renameSync(filePath, processingPath);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
host().logger.warn({ err: e, filePath }, `${label}: failed to rename for processing`);
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const lines = host().readJsonlLines(processingPath);
|
|
120
|
+
return { lines, processingPath };
|
|
121
|
+
} catch (e) {
|
|
122
|
+
host().logger.warn({ err: e, processingPath }, `${label}: failed to read processing file`);
|
|
123
|
+
tryUnlink(processingPath, label, "failed to delete corrupt processing file");
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Delete the .processing file after all entries are consumed.
|
|
130
|
+
*
|
|
131
|
+
* Writer-race salvage: `appendFileSync` racing `drainOutboxFile`'s rename can
|
|
132
|
+
* land a line on the claimed inode AFTER the drainer already read it. Without
|
|
133
|
+
* a recheck, unlinking here would silently destroy that entry. When
|
|
134
|
+
* `consumedLines` is provided, any lines beyond it are appended back to the
|
|
135
|
+
* original pending file before the claim is deleted (at-least-once preserved).
|
|
136
|
+
*/
|
|
137
|
+
export function deleteProcessingFile(
|
|
138
|
+
processingPath: string,
|
|
139
|
+
label: string,
|
|
140
|
+
consumedLines?: number,
|
|
141
|
+
) {
|
|
142
|
+
if (consumedLines !== undefined && processingPath.endsWith(PROCESSING_SUFFIX)) {
|
|
143
|
+
try {
|
|
144
|
+
const current = host().readJsonlLines(processingPath);
|
|
145
|
+
if (current.length > consumedLines) {
|
|
146
|
+
const pendingPath = processingPath.slice(0, -PROCESSING_SUFFIX.length);
|
|
147
|
+
const tail = current.slice(consumedLines).join("\n");
|
|
148
|
+
appendFileSync(pendingPath, `${tail}\n`);
|
|
149
|
+
host().logger.warn(
|
|
150
|
+
{ processingPath, salvaged: current.length - consumedLines },
|
|
151
|
+
`${label}: writer raced the drain — salvaged late lines back to pending`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
host().logger.warn({ err: e, processingPath }, `${label}: writer-race recheck failed`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
tryUnlink(processingPath, label, "failed to delete processing file");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Parse a single JSONL line. Returns null (and logs an error) on invalid JSON.
|
|
163
|
+
* Keeps the parse + error-log pattern in one place instead of repeating it in
|
|
164
|
+
* every flush function.
|
|
165
|
+
*/
|
|
166
|
+
export function parseOutboxLine<T>(line: string, label: string): T | null {
|
|
167
|
+
try {
|
|
168
|
+
return JSON.parse(line) as T;
|
|
169
|
+
} catch {
|
|
170
|
+
host().logger.error({ label, line: line.slice(0, 120) }, `${label}: Invalid JSON, dropping`);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Drain an outbox file and invoke `handler` for each parsed entry.
|
|
177
|
+
* Handles drain → parse → process → delete-processing → write-back-failures in one call.
|
|
178
|
+
*
|
|
179
|
+
* `handler` should throw to signal a retryable failure.
|
|
180
|
+
* Failed entries are written back to `filePath` for the next flush cycle.
|
|
181
|
+
* Pass `maxRetries` to drop entries that have exceeded the retry budget.
|
|
182
|
+
*
|
|
183
|
+
* Delivery: at-least-once. The `.processing` claim is deleted only AFTER all
|
|
184
|
+
* entries were handled — a crash mid-processing leaves the claim on disk and
|
|
185
|
+
* the next drain's leftover-merge redelivers the whole batch (including
|
|
186
|
+
* already-handled entries). Handlers must therefore be idempotent or accept
|
|
187
|
+
* duplicates; deleting the claim up-front would instead silently lose every
|
|
188
|
+
* unprocessed entry on crash, which is worse for every queue using this path.
|
|
189
|
+
*/
|
|
190
|
+
export async function processOutboxFile<T extends Record<string, unknown>>(
|
|
191
|
+
filePath: string,
|
|
192
|
+
label: string,
|
|
193
|
+
handler: (entry: T) => Promise<void>,
|
|
194
|
+
opts: { maxRetries?: number } = {},
|
|
195
|
+
): Promise<void> {
|
|
196
|
+
const drained = drainOutboxFile(filePath, label);
|
|
197
|
+
if (!drained) return;
|
|
198
|
+
const { lines, processingPath } = drained;
|
|
199
|
+
|
|
200
|
+
if (lines.length === 0) {
|
|
201
|
+
deleteProcessingFile(processingPath, label, 0);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const MAX_RETRIES = opts.maxRetries ?? 0;
|
|
206
|
+
const failedLines: string[] = [];
|
|
207
|
+
|
|
208
|
+
for (const line of lines) {
|
|
209
|
+
const entry = parseOutboxLine<T>(line, label);
|
|
210
|
+
if (!entry) continue;
|
|
211
|
+
|
|
212
|
+
const retryCount = (entry.retryCount as number | undefined) ?? 0;
|
|
213
|
+
try {
|
|
214
|
+
await handler(entry);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
if (MAX_RETRIES > 0) {
|
|
217
|
+
const next = retryCount + 1;
|
|
218
|
+
if (next >= MAX_RETRIES) {
|
|
219
|
+
host().logger.error(
|
|
220
|
+
{ err, label, retryCount: next },
|
|
221
|
+
`${label}: Max retries reached, dropping`,
|
|
222
|
+
);
|
|
223
|
+
} else {
|
|
224
|
+
host().logger.warn({ err, label, retryCount: next }, `${label}: Failed, will retry`);
|
|
225
|
+
failedLines.push(JSON.stringify({ ...entry, retryCount: next }));
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
host().logger.error({ err, label }, `${label}: Failed to process entry`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Drop the claim before writing failures back (same order as dm-queue):
|
|
234
|
+
// a crash between the two redelivers nothing extra, while the reverse
|
|
235
|
+
// order could double the failed entries (write-back + leftover merge).
|
|
236
|
+
deleteProcessingFile(processingPath, label, lines.length);
|
|
237
|
+
|
|
238
|
+
if (failedLines.length > 0) {
|
|
239
|
+
try {
|
|
240
|
+
appendFileSync(filePath, `${failedLines.join("\n")}\n`);
|
|
241
|
+
} catch (e) {
|
|
242
|
+
host().logger.error(
|
|
243
|
+
{ err: e, label, count: failedLines.length },
|
|
244
|
+
`${label}: Failed to write back entries`,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Bind outbox processing to caller-owned logging and JSONL parsing dependencies. */
|
|
251
|
+
export function createOutboxFileOps(boundHost: OutboxFileHost): OutboxFileOps {
|
|
252
|
+
return {
|
|
253
|
+
isProcessingFile,
|
|
254
|
+
drainOutboxFile: (filePath, label) =>
|
|
255
|
+
hostContext.run(boundHost, () => drainOutboxFile(filePath, label)),
|
|
256
|
+
deleteProcessingFile: (processingPath, label, consumedLines) =>
|
|
257
|
+
hostContext.run(boundHost, () => deleteProcessingFile(processingPath, label, consumedLines)),
|
|
258
|
+
parseOutboxLine: <T>(line: string, label: string) =>
|
|
259
|
+
hostContext.run(boundHost, () => parseOutboxLine<T>(line, label)),
|
|
260
|
+
processOutboxFile: <T extends Record<string, unknown>>(
|
|
261
|
+
filePath: string,
|
|
262
|
+
label: string,
|
|
263
|
+
handler: (entry: T) => Promise<void>,
|
|
264
|
+
opts: { maxRetries?: number } = {},
|
|
265
|
+
) => hostContext.run(boundHost, () => processOutboxFile(filePath, label, handler, opts)),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export {
|
|
2
|
+
type CoalescingRunner,
|
|
3
|
+
type CoalescingRunnerLogger,
|
|
4
|
+
type CoalescingRunnerOptions,
|
|
5
|
+
createCoalescingRunner,
|
|
6
|
+
} from "./coalescing-runner";
|
|
7
|
+
export {
|
|
8
|
+
createOutboxFileOps,
|
|
9
|
+
deleteProcessingFile,
|
|
10
|
+
drainOutboxFile,
|
|
11
|
+
isProcessingFile,
|
|
12
|
+
type OutboxFileHost,
|
|
13
|
+
type OutboxFileOps,
|
|
14
|
+
type OutboxLogger,
|
|
15
|
+
parseOutboxLine,
|
|
16
|
+
processOutboxFile,
|
|
17
|
+
} from "./file-ops";
|
|
18
|
+
export {
|
|
19
|
+
createOutboxWatchOps,
|
|
20
|
+
debouncedFlush,
|
|
21
|
+
FALLBACK_INTERVAL_MS,
|
|
22
|
+
type OutboxWatchHost,
|
|
23
|
+
type OutboxWatchLogger,
|
|
24
|
+
type OutboxWatchOps,
|
|
25
|
+
watchDir,
|
|
26
|
+
} from "./utils";
|