@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,394 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { claudeRegistry } from "#agents/claude-registry";
|
|
7
|
+
import { codexRegistry } from "#agents/codex-registry";
|
|
8
|
+
import type { AgentRegistry } from "#agents/contracts";
|
|
9
|
+
import { maestroRegistry } from "#agents/maestro-registry";
|
|
10
|
+
import { resolveDefaultModel } from "#agents/model-catalog";
|
|
11
|
+
import { ACTIVE_QUERY_STALE_MS, USERS_LOG_DIR } from "#platform/config";
|
|
12
|
+
import { errMsg } from "#platform/error";
|
|
13
|
+
import { readJsonFile } from "#platform/jsonl";
|
|
14
|
+
import type { AgentKind, QueryState } from "#types";
|
|
15
|
+
import { mcpOk } from "../mcp-helpers";
|
|
16
|
+
|
|
17
|
+
export interface AgentHealthMcpContext {
|
|
18
|
+
userId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface CheckResult {
|
|
22
|
+
agent: string;
|
|
23
|
+
model: string;
|
|
24
|
+
ok: boolean;
|
|
25
|
+
latency: number;
|
|
26
|
+
detail?: string;
|
|
27
|
+
error?: string;
|
|
28
|
+
category?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type CheckerFn = (model: string, timeoutMs: number, signal: AbortSignal) => Promise<CheckResult>;
|
|
32
|
+
|
|
33
|
+
function signalProcessTree(child: ReturnType<typeof spawn>, signal: NodeJS.Signals): void {
|
|
34
|
+
try {
|
|
35
|
+
if (child.pid && process.platform !== "win32") process.kill(-child.pid, signal);
|
|
36
|
+
else child.kill(signal);
|
|
37
|
+
} catch {
|
|
38
|
+
try {
|
|
39
|
+
child.kill(signal);
|
|
40
|
+
} catch {
|
|
41
|
+
// Process already exited.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function spawnCapture(
|
|
47
|
+
cmd: string,
|
|
48
|
+
args: string[],
|
|
49
|
+
timeoutMs: number,
|
|
50
|
+
signal: AbortSignal,
|
|
51
|
+
env?: Record<string, string>,
|
|
52
|
+
): Promise<{ stdout: string; stderr: string }> {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const child = spawn(cmd, args, {
|
|
55
|
+
env: env ?? process.env,
|
|
56
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
57
|
+
detached: process.platform !== "win32",
|
|
58
|
+
// No console window for a health probe. Ignored on POSIX.
|
|
59
|
+
windowsHide: true,
|
|
60
|
+
});
|
|
61
|
+
let settled = false;
|
|
62
|
+
let stdout = "";
|
|
63
|
+
let stderr = "";
|
|
64
|
+
const forceKill = () => signalProcessTree(child, "SIGKILL");
|
|
65
|
+
let killTimer: ReturnType<typeof setTimeout> | undefined;
|
|
66
|
+
const stop = (reason: string) => {
|
|
67
|
+
if (settled) return;
|
|
68
|
+
settled = true;
|
|
69
|
+
signalProcessTree(child, "SIGTERM");
|
|
70
|
+
killTimer = setTimeout(() => {
|
|
71
|
+
forceKill();
|
|
72
|
+
killTimer = undefined;
|
|
73
|
+
}, 1_000);
|
|
74
|
+
killTimer.unref?.();
|
|
75
|
+
reject(new Error(reason));
|
|
76
|
+
};
|
|
77
|
+
const timeout = setTimeout(() => stop("timeout"), timeoutMs);
|
|
78
|
+
const onAbort = () => stop("aborted");
|
|
79
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
80
|
+
const cleanup = () => {
|
|
81
|
+
clearTimeout(timeout);
|
|
82
|
+
signal.removeEventListener("abort", onAbort);
|
|
83
|
+
};
|
|
84
|
+
child.stdout.on("data", (data: Buffer) => {
|
|
85
|
+
stdout += data.toString();
|
|
86
|
+
});
|
|
87
|
+
child.stderr.on("data", (data: Buffer) => {
|
|
88
|
+
stderr += data.toString();
|
|
89
|
+
});
|
|
90
|
+
child.on("error", (err) => {
|
|
91
|
+
if (settled) return;
|
|
92
|
+
settled = true;
|
|
93
|
+
cleanup();
|
|
94
|
+
if (killTimer) clearTimeout(killTimer);
|
|
95
|
+
reject(err);
|
|
96
|
+
});
|
|
97
|
+
child.on("close", (code, exitSignal) => {
|
|
98
|
+
cleanup();
|
|
99
|
+
if (settled) {
|
|
100
|
+
if (killTimer) {
|
|
101
|
+
clearTimeout(killTimer);
|
|
102
|
+
killTimer = undefined;
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
settled = true;
|
|
107
|
+
if (killTimer) clearTimeout(killTimer);
|
|
108
|
+
if (code === 0) resolve({ stdout, stderr });
|
|
109
|
+
else reject(new Error(stderr.trim() || `${cmd} exited with ${code ?? exitSignal}`));
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function resultOk(agent: string, model: string, latency: number, detail: string): CheckResult {
|
|
115
|
+
return { agent, model, ok: true, latency, detail };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function resultFail(agent: string, model: string, latency: number, error: string): CheckResult {
|
|
119
|
+
let category = "unknown";
|
|
120
|
+
const normalized = error.toLowerCase();
|
|
121
|
+
if (
|
|
122
|
+
normalized.includes("auth") ||
|
|
123
|
+
normalized.includes("key") ||
|
|
124
|
+
normalized.includes("credential") ||
|
|
125
|
+
normalized.includes("unauthorized")
|
|
126
|
+
) {
|
|
127
|
+
category = "auth_error";
|
|
128
|
+
} else if (
|
|
129
|
+
normalized.includes("rate") ||
|
|
130
|
+
normalized.includes("limit") ||
|
|
131
|
+
normalized.includes("busy") ||
|
|
132
|
+
normalized.includes("overloaded")
|
|
133
|
+
) {
|
|
134
|
+
category = "rate_limit";
|
|
135
|
+
} else if (
|
|
136
|
+
normalized.includes("network") ||
|
|
137
|
+
normalized.includes("refused") ||
|
|
138
|
+
normalized.includes("dns") ||
|
|
139
|
+
normalized.includes("timeout")
|
|
140
|
+
) {
|
|
141
|
+
category = "network_error";
|
|
142
|
+
}
|
|
143
|
+
return { agent, model, ok: false, latency, error, category };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function checkClaude(
|
|
147
|
+
model: string,
|
|
148
|
+
timeoutMs: number,
|
|
149
|
+
signal: AbortSignal,
|
|
150
|
+
): Promise<CheckResult> {
|
|
151
|
+
const start = performance.now();
|
|
152
|
+
try {
|
|
153
|
+
const args = ["-p", "say OK", "--model", model, "--max-turns", "1", "--output-format", "text"];
|
|
154
|
+
const { stdout, stderr } = await spawnCapture("claude", args, timeoutMs, signal);
|
|
155
|
+
const elapsed = Math.round(performance.now() - start);
|
|
156
|
+
const text = (stdout + stderr).trim().slice(0, 200);
|
|
157
|
+
if (!text) return resultFail("claude", model, elapsed, "empty response");
|
|
158
|
+
return resultOk("claude", model, elapsed, text);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
return resultFail("claude", model, Math.round(performance.now() - start), errMsg(err));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function checkCodex(
|
|
165
|
+
model: string,
|
|
166
|
+
timeoutMs: number,
|
|
167
|
+
signal: AbortSignal,
|
|
168
|
+
): Promise<CheckResult> {
|
|
169
|
+
const start = performance.now();
|
|
170
|
+
try {
|
|
171
|
+
const args = [
|
|
172
|
+
"exec",
|
|
173
|
+
"--model",
|
|
174
|
+
model,
|
|
175
|
+
"--skip-git-repo-check",
|
|
176
|
+
"--sandbox",
|
|
177
|
+
"danger-full-access",
|
|
178
|
+
"say OK",
|
|
179
|
+
];
|
|
180
|
+
const { stdout, stderr } = await spawnCapture("codex", args, timeoutMs, signal, {
|
|
181
|
+
...process.env,
|
|
182
|
+
CODEX_NO_COLOR: "1",
|
|
183
|
+
});
|
|
184
|
+
const elapsed = Math.round(performance.now() - start);
|
|
185
|
+
const combined = (stdout + stderr).trim();
|
|
186
|
+
const match = combined.match(/\ncodex\s*\n(.+?)(?:\n(?:tokens|session|user|$))/);
|
|
187
|
+
return resultOk("codex", model, elapsed, match ? match[1].trim().slice(0, 200) : "OK");
|
|
188
|
+
} catch (err) {
|
|
189
|
+
return resultFail("codex", model, Math.round(performance.now() - start), errMsg(err));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function checkMaestro(
|
|
194
|
+
model: string,
|
|
195
|
+
timeoutMs: number,
|
|
196
|
+
signal: AbortSignal,
|
|
197
|
+
): Promise<CheckResult> {
|
|
198
|
+
const start = performance.now();
|
|
199
|
+
let iterator: AsyncIterator<any> | undefined;
|
|
200
|
+
try {
|
|
201
|
+
const { maestroProvider } = await import("maestro-agent-sdk");
|
|
202
|
+
const generator = (maestroProvider as any)({
|
|
203
|
+
model,
|
|
204
|
+
prompt: "say OK",
|
|
205
|
+
cwd: process.cwd(),
|
|
206
|
+
maxTurns: 1,
|
|
207
|
+
});
|
|
208
|
+
const deadline = Date.now() + timeoutMs;
|
|
209
|
+
const activeIterator = generator[Symbol.asyncIterator]() as AsyncIterator<any>;
|
|
210
|
+
iterator = activeIterator;
|
|
211
|
+
let text = "";
|
|
212
|
+
while (true) {
|
|
213
|
+
const remaining = deadline - Date.now();
|
|
214
|
+
if (remaining <= 0) throw new Error("timeout");
|
|
215
|
+
const eventResult = await new Promise<IteratorResult<any>>((resolve, reject) => {
|
|
216
|
+
const timeout = setTimeout(() => reject(new Error("timeout")), remaining);
|
|
217
|
+
const onAbort = () => reject(new Error("aborted"));
|
|
218
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
219
|
+
void activeIterator
|
|
220
|
+
.next()
|
|
221
|
+
.then(resolve, reject)
|
|
222
|
+
.finally(() => {
|
|
223
|
+
clearTimeout(timeout);
|
|
224
|
+
signal.removeEventListener("abort", onAbort);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
if (eventResult.done) break;
|
|
228
|
+
const event = eventResult.value;
|
|
229
|
+
if (event.type === "text" && event.content) text = event.content.slice(0, 200);
|
|
230
|
+
if (event.type === "error") {
|
|
231
|
+
return resultFail(
|
|
232
|
+
"maestro",
|
|
233
|
+
model,
|
|
234
|
+
Math.round(performance.now() - start),
|
|
235
|
+
event.error || "unknown error",
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return resultOk(
|
|
240
|
+
"maestro",
|
|
241
|
+
model,
|
|
242
|
+
Math.round(performance.now() - start),
|
|
243
|
+
text || "(empty response)",
|
|
244
|
+
);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
return resultFail("maestro", model, Math.round(performance.now() - start), errMsg(err));
|
|
247
|
+
} finally {
|
|
248
|
+
if (iterator?.return) {
|
|
249
|
+
try {
|
|
250
|
+
await iterator.return();
|
|
251
|
+
} catch {
|
|
252
|
+
// The provider may already have closed the iterator.
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function getDefaultModel(registry: AgentRegistry): string {
|
|
259
|
+
return resolveDefaultModel(registry.kind, registry);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const AGENTS: { kind: AgentKind; registry: AgentRegistry; checker: CheckerFn }[] = [
|
|
263
|
+
{ kind: "claude", registry: claudeRegistry, checker: checkClaude },
|
|
264
|
+
{ kind: "codex", registry: codexRegistry, checker: checkCodex },
|
|
265
|
+
{ kind: "maestro", registry: maestroRegistry, checker: checkMaestro },
|
|
266
|
+
];
|
|
267
|
+
|
|
268
|
+
const MAX_CONCURRENT_CHECKS = 2;
|
|
269
|
+
let activeChecks = 0;
|
|
270
|
+
const checkWaiters: Array<() => void> = [];
|
|
271
|
+
const activeCheckAllUsers = new Set<string>();
|
|
272
|
+
|
|
273
|
+
async function withCheckSlot<T>(operation: () => Promise<T>): Promise<T> {
|
|
274
|
+
if (activeChecks >= MAX_CONCURRENT_CHECKS) {
|
|
275
|
+
await new Promise<void>((resolve) => checkWaiters.push(resolve));
|
|
276
|
+
}
|
|
277
|
+
activeChecks += 1;
|
|
278
|
+
try {
|
|
279
|
+
return await operation();
|
|
280
|
+
} finally {
|
|
281
|
+
activeChecks -= 1;
|
|
282
|
+
checkWaiters.shift()?.();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function createAgentHealthMcpServer(context: AgentHealthMcpContext): McpServer {
|
|
287
|
+
const server = new McpServer({ name: "agent-health", version: "1.0.0" });
|
|
288
|
+
const abortController = new AbortController();
|
|
289
|
+
const originalClose = server.close.bind(server);
|
|
290
|
+
server.close = async () => {
|
|
291
|
+
abortController.abort();
|
|
292
|
+
await originalClose();
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
server.tool(
|
|
296
|
+
"check_agent",
|
|
297
|
+
"실제 API 호출로 특정 agent+model 조합이 정상 동작하는지 체크합니다.",
|
|
298
|
+
{
|
|
299
|
+
agent: z.enum(["claude", "codex", "maestro"]).describe("체크할 agent"),
|
|
300
|
+
model: z.string().optional().describe("체크할 모델 (없으면 agent별 default 사용)"),
|
|
301
|
+
timeoutMs: z.number().default(30000).describe("타임아웃 (ms), 기본 30초"),
|
|
302
|
+
},
|
|
303
|
+
async ({ agent, model, timeoutMs }) => {
|
|
304
|
+
const entry = AGENTS.find((candidate) => candidate.kind === agent);
|
|
305
|
+
if (!entry) return mcpOk(`Unknown agent: ${agent}`);
|
|
306
|
+
const resolvedModel = model || getDefaultModel(entry.registry);
|
|
307
|
+
const result = await withCheckSlot(() =>
|
|
308
|
+
entry.checker(resolvedModel, timeoutMs, abortController.signal),
|
|
309
|
+
);
|
|
310
|
+
if (result.ok) {
|
|
311
|
+
return mcpOk(
|
|
312
|
+
`OK ${result.agent} / ${result.model}\n latency: ${result.latency}ms\n detail: ${result.detail}`,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return mcpOk(
|
|
316
|
+
`FAIL ${result.agent} / ${result.model} [${result.category}]\n latency: ${result.latency}ms\n error: ${result.error}`,
|
|
317
|
+
);
|
|
318
|
+
},
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
server.tool(
|
|
322
|
+
"check_all",
|
|
323
|
+
"모든 agent (claude, codex, maestro)를 기본 모델로 동시에 체크합니다.",
|
|
324
|
+
{ timeoutMs: z.number().default(30000).describe("agent별 타임아웃 (ms), 기본 30초") },
|
|
325
|
+
async ({ timeoutMs }) => {
|
|
326
|
+
const userKey = context.userId ?? "unscoped";
|
|
327
|
+
if (activeCheckAllUsers.has(userKey)) {
|
|
328
|
+
return mcpOk("FAIL check_all is already running for this user");
|
|
329
|
+
}
|
|
330
|
+
activeCheckAllUsers.add(userKey);
|
|
331
|
+
try {
|
|
332
|
+
const results = await Promise.all(
|
|
333
|
+
AGENTS.map(async (entry) =>
|
|
334
|
+
withCheckSlot(() =>
|
|
335
|
+
entry.checker(getDefaultModel(entry.registry), timeoutMs, abortController.signal),
|
|
336
|
+
),
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
const lines = results.map((result) =>
|
|
340
|
+
result.ok
|
|
341
|
+
? `OK ${result.agent.padEnd(8)} / ${result.model.padEnd(14)} ${result.latency}ms ${result.detail}`
|
|
342
|
+
: `FAIL ${result.agent.padEnd(8)} / ${result.model.padEnd(14)} ${result.latency}ms [${result.category}] ${result.error}`,
|
|
343
|
+
);
|
|
344
|
+
return mcpOk(
|
|
345
|
+
`Agent/Model Health Check\n${lines.join("\n")}\n\n${results.every((result) => result.ok) ? "All agents healthy" : "Some agents failed"}`,
|
|
346
|
+
);
|
|
347
|
+
} finally {
|
|
348
|
+
activeCheckAllUsers.delete(userKey);
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
server.tool(
|
|
354
|
+
"list_active_queries",
|
|
355
|
+
"현재 사용자 범위에서 실행 중인 토픽 쿼리 목록을 조회합니다.",
|
|
356
|
+
{},
|
|
357
|
+
async () => {
|
|
358
|
+
if (!context.userId) return mcpOk("실행 중인 쿼리 조회 불가 (user context 없음)");
|
|
359
|
+
const stateDir = join(USERS_LOG_DIR, context.userId, "active-queries");
|
|
360
|
+
if (!existsSync(stateDir)) return mcpOk("실행 중인 쿼리 없음");
|
|
361
|
+
|
|
362
|
+
let files: string[];
|
|
363
|
+
try {
|
|
364
|
+
files = readdirSync(stateDir);
|
|
365
|
+
} catch {
|
|
366
|
+
return mcpOk("실행 중인 쿼리 없음");
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const now = Date.now();
|
|
370
|
+
const entries = files.flatMap((file) => {
|
|
371
|
+
if (!file.endsWith(".json")) return [];
|
|
372
|
+
const state = readJsonFile<QueryState>(join(stateDir, file));
|
|
373
|
+
if (!state) return [];
|
|
374
|
+
const sinceMs = new Date(state.since).getTime();
|
|
375
|
+
if (now - sinceMs > ACTIVE_QUERY_STALE_MS) return [];
|
|
376
|
+
return [
|
|
377
|
+
{
|
|
378
|
+
topicName: state.topicName ?? file.slice(0, -5),
|
|
379
|
+
elapsedSec: Math.round((now - sinceMs) / 1000),
|
|
380
|
+
task: state.task,
|
|
381
|
+
},
|
|
382
|
+
];
|
|
383
|
+
});
|
|
384
|
+
if (entries.length === 0) return mcpOk("실행 중인 쿼리 없음");
|
|
385
|
+
const lines = entries.map(
|
|
386
|
+
(entry) =>
|
|
387
|
+
`• ${entry.topicName} | ${entry.elapsedSec}s 경과${entry.task ? ` "${entry.task}"` : ""}`,
|
|
388
|
+
);
|
|
389
|
+
return mcpOk(`실행 중인 쿼리 (${entries.length}개)\n${lines.join("\n")}`);
|
|
390
|
+
},
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
return server;
|
|
394
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { mcpError, mcpOk } from "../mcp-helpers";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_MAX_CALLS = 12;
|
|
7
|
+
const DEFAULT_MAX_TOTAL_BYTES = 512 * 1024;
|
|
8
|
+
const DEFAULT_MAX_CHUNK_BYTES = 64 * 1024;
|
|
9
|
+
const DEFAULT_LINE_LIMIT = 300;
|
|
10
|
+
const MAX_LINE_LIMIT = 500;
|
|
11
|
+
|
|
12
|
+
export interface CompactionLogMcpContext {
|
|
13
|
+
filePath: string;
|
|
14
|
+
maxCalls?: number;
|
|
15
|
+
maxTotalBytes?: number;
|
|
16
|
+
maxChunkBytes?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function positiveInt(value: number | undefined, fallback: number): number {
|
|
20
|
+
return Number.isFinite(value) && value && value > 0 ? Math.floor(value) : fallback;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fitUtf8(text: string, maxBytes: number): string {
|
|
24
|
+
if (Buffer.byteLength(text, "utf8") <= maxBytes) return text;
|
|
25
|
+
const marker = "\n[... oversized line clipped ...]\n";
|
|
26
|
+
const markerBytes = Buffer.byteLength(marker, "utf8");
|
|
27
|
+
const bytes = Buffer.from(text, "utf8");
|
|
28
|
+
if (maxBytes <= markerBytes) {
|
|
29
|
+
return bytes
|
|
30
|
+
.subarray(0, maxBytes)
|
|
31
|
+
.toString("utf8")
|
|
32
|
+
.replace(/\uFFFD+$/u, "");
|
|
33
|
+
}
|
|
34
|
+
const available = Math.max(0, maxBytes - markerBytes);
|
|
35
|
+
const headBudget = Math.ceil(available * 0.6);
|
|
36
|
+
const tailBudget = available - headBudget;
|
|
37
|
+
const head = bytes
|
|
38
|
+
.subarray(0, headBudget)
|
|
39
|
+
.toString("utf8")
|
|
40
|
+
.replace(/\uFFFD+$/u, "");
|
|
41
|
+
const tail = bytes
|
|
42
|
+
.subarray(Math.max(0, bytes.length - tailBudget))
|
|
43
|
+
.toString("utf8")
|
|
44
|
+
.replace(/^\uFFFD+/u, "");
|
|
45
|
+
return `${head}${marker}${tail}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createCompactionLogMcpServer(context: CompactionLogMcpContext): McpServer {
|
|
49
|
+
if (!context.filePath) throw new Error("compaction-log MCP requires filePath");
|
|
50
|
+
const filePath = realpathSync(context.filePath);
|
|
51
|
+
const lines = readFileSync(filePath, "utf8").split("\n");
|
|
52
|
+
const maxCalls = positiveInt(context.maxCalls, DEFAULT_MAX_CALLS);
|
|
53
|
+
const maxTotalBytes = positiveInt(context.maxTotalBytes, DEFAULT_MAX_TOTAL_BYTES);
|
|
54
|
+
const maxChunkBytes = positiveInt(context.maxChunkBytes, DEFAULT_MAX_CHUNK_BYTES);
|
|
55
|
+
let calls = 0;
|
|
56
|
+
let totalBytes = 0;
|
|
57
|
+
|
|
58
|
+
const server = new McpServer({ name: "compaction-log", version: "1.0.0" });
|
|
59
|
+
server.tool(
|
|
60
|
+
"read_compaction_log",
|
|
61
|
+
[
|
|
62
|
+
`Read the immutable conversation snapshot in bounded chunks. It contains ${lines.length} lines.`,
|
|
63
|
+
"Start at offset 1, then inspect the final chunk using total_lines from the response.",
|
|
64
|
+
"Read intermediate chunks only when needed. Return a summary instead of calling after the budget is exhausted.",
|
|
65
|
+
].join(" "),
|
|
66
|
+
{
|
|
67
|
+
offset: z.number().optional().describe("One-based line number. Defaults to 1."),
|
|
68
|
+
limit: z
|
|
69
|
+
.number()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe(`Number of lines. Defaults to ${DEFAULT_LINE_LIMIT}, max ${MAX_LINE_LIMIT}.`),
|
|
72
|
+
},
|
|
73
|
+
async ({ offset: rawOffset, limit: rawLimit }) => {
|
|
74
|
+
calls += 1;
|
|
75
|
+
if (calls > maxCalls || totalBytes >= maxTotalBytes) {
|
|
76
|
+
return mcpError(
|
|
77
|
+
JSON.stringify({
|
|
78
|
+
error: "compaction log read budget exhausted; produce the summary now",
|
|
79
|
+
calls,
|
|
80
|
+
max_calls: maxCalls,
|
|
81
|
+
total_lines: lines.length,
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const offset = positiveInt(rawOffset, 1);
|
|
87
|
+
const limit = Math.min(positiveInt(rawLimit, DEFAULT_LINE_LIMIT), MAX_LINE_LIMIT);
|
|
88
|
+
const start = Math.max(0, offset - 1);
|
|
89
|
+
if (start >= lines.length) {
|
|
90
|
+
return mcpOk(
|
|
91
|
+
JSON.stringify({
|
|
92
|
+
content: "(end of compaction log)",
|
|
93
|
+
offset,
|
|
94
|
+
returned_lines: 0,
|
|
95
|
+
total_lines: lines.length,
|
|
96
|
+
calls,
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const selected: string[] = [];
|
|
102
|
+
let returnedBytes = 0;
|
|
103
|
+
let index = start;
|
|
104
|
+
const callBudget = Math.min(maxChunkBytes, maxTotalBytes - totalBytes);
|
|
105
|
+
while (index < lines.length && selected.length < limit) {
|
|
106
|
+
const line = fitUtf8(lines[index] ?? "", Math.max(1, callBudget));
|
|
107
|
+
const separatorBytes = selected.length > 0 ? 1 : 0;
|
|
108
|
+
const lineBytes = Buffer.byteLength(line, "utf8");
|
|
109
|
+
if (selected.length > 0 && returnedBytes + separatorBytes + lineBytes > callBudget) break;
|
|
110
|
+
selected.push(line);
|
|
111
|
+
returnedBytes += separatorBytes + lineBytes;
|
|
112
|
+
index += 1;
|
|
113
|
+
if (returnedBytes >= callBudget) break;
|
|
114
|
+
}
|
|
115
|
+
totalBytes += returnedBytes;
|
|
116
|
+
|
|
117
|
+
return mcpOk(
|
|
118
|
+
JSON.stringify({
|
|
119
|
+
content: selected.join("\n"),
|
|
120
|
+
offset,
|
|
121
|
+
returned_lines: selected.length,
|
|
122
|
+
returned_bytes: returnedBytes,
|
|
123
|
+
total_lines: lines.length,
|
|
124
|
+
total_read_bytes: totalBytes,
|
|
125
|
+
calls,
|
|
126
|
+
...(index < lines.length ? { next_offset: index + 1 } : {}),
|
|
127
|
+
...(calls >= maxCalls || totalBytes >= maxTotalBytes
|
|
128
|
+
? { note: "Read budget exhausted; produce the summary now." }
|
|
129
|
+
: {}),
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
return server;
|
|
135
|
+
}
|