@otium-team/negotium 0.0.0-stage → 0.23.11
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 +23903 -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 +2336 -0
- package/dist/browser-runtime.js.map +35 -0
- package/dist/canonical-mcp-bridge.js +14 -0
- package/dist/canonical-mcp-bridge.js.map +9 -0
- package/dist/chunk-0fenxbe6.js +173 -0
- package/dist/chunk-0fenxbe6.js.map +12 -0
- package/dist/chunk-2mx7fq49.js +6 -0
- package/dist/chunk-2mx7fq49.js.map +9 -0
- package/dist/chunk-ad7kxsaq.js +202 -0
- package/dist/chunk-ad7kxsaq.js.map +9 -0
- package/dist/chunk-da9ad838.js +3927 -0
- package/dist/chunk-da9ad838.js.map +47 -0
- package/dist/chunk-f7p0h1gs.js +54 -0
- package/dist/chunk-f7p0h1gs.js.map +10 -0
- package/dist/chunk-jtv8yzy1.js +206 -0
- package/dist/chunk-jtv8yzy1.js.map +10 -0
- package/dist/chunk-mxxwx5mg.js +375 -0
- package/dist/chunk-mxxwx5mg.js.map +13 -0
- package/dist/cron.js +1 -0
- package/dist/hosted-agent.js +5919 -0
- package/dist/hosted-agent.js.map +62 -0
- package/dist/main.js +60536 -0
- package/dist/main.js.map +338 -0
- package/dist/mcp-catalog.js +39 -0
- package/dist/mcp-catalog.js.map +10 -0
- package/dist/mcp-factories.js +26572 -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 +1073 -0
- package/dist/query-runtime.js.map +26 -0
- package/dist/registry.js +336 -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 +866 -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 +420 -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 +186 -0
- package/dist/runtime/src/application/vault-command.ts +170 -0
- package/dist/runtime/src/bus.ts +403 -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 +200 -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 +508 -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 +2284 -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 +848 -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-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 +805 -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 +582 -0
- package/dist/runtime/src/types.ts +395 -0
- package/dist/runtime/src/version.ts +1 -0
- package/dist/runtime/tsconfig.json +13 -0
- package/dist/runtime-gateway.js +453 -0
- package/dist/runtime-gateway.js.map +10 -0
- package/dist/runtime-helpers.js +1794 -0
- package/dist/runtime-helpers.js.map +40 -0
- package/dist/sqlite.js +68 -0
- package/dist/sqlite.js.map +10 -0
- package/dist/storage.js +5194 -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 +138 -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 +234 -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 +224 -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 +138 -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 +546 -0
- package/dist/types/packages/core/src/types.d.ts +384 -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 +850 -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,1036 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { ACTIVE_QUERY_STALE_MS, USERS_LOG_DIR } from "#platform/config";
|
|
6
|
+
import { errMsg } from "#platform/error";
|
|
7
|
+
import { readJsonFile } from "#platform/jsonl";
|
|
8
|
+
import {
|
|
9
|
+
formatMcpStatus,
|
|
10
|
+
OPTIONAL_FORUM_MCP_SERVERS,
|
|
11
|
+
REQUIRED_FORUM_MCP_SERVERS,
|
|
12
|
+
} from "#platform/mcp-config";
|
|
13
|
+
import { closeBrowserOwnerTabs } from "#platform/playwright/manager";
|
|
14
|
+
import { deleteManagedBrowserProfile } from "#platform/playwright/profile-management";
|
|
15
|
+
import { sanitizeId } from "#security/sanitize";
|
|
16
|
+
import { getTopic } from "#storage/api-topics";
|
|
17
|
+
import {
|
|
18
|
+
assignTopicBrowserProfile,
|
|
19
|
+
getBrowserProfileOwner,
|
|
20
|
+
getTopicBrowserProfile,
|
|
21
|
+
isTopicBrowserProfileOwner,
|
|
22
|
+
listBrowserProfiles,
|
|
23
|
+
} from "#storage/browser-profiles";
|
|
24
|
+
import {
|
|
25
|
+
abandonRemoteSessionAsk,
|
|
26
|
+
beginRemoteSessionAsk,
|
|
27
|
+
markRemoteSessionAskSent,
|
|
28
|
+
} from "#storage/remote-session";
|
|
29
|
+
import {
|
|
30
|
+
clearPendingAsk,
|
|
31
|
+
createPendingAsk,
|
|
32
|
+
describePendingAskState,
|
|
33
|
+
listPendingAsksForCaller,
|
|
34
|
+
releasePendingAsk,
|
|
35
|
+
} from "#storage/session-asks";
|
|
36
|
+
import { enqueueSessionInbox } from "#storage/session-inbox";
|
|
37
|
+
import { connectStdio, mcpError, mcpOk } from "../mcp-helpers";
|
|
38
|
+
import {
|
|
39
|
+
abortTargetRefusal,
|
|
40
|
+
crossPrincipalRefusal,
|
|
41
|
+
localDeliveryPrincipal,
|
|
42
|
+
remoteSessionRoute,
|
|
43
|
+
roomStatusPrincipal,
|
|
44
|
+
} from "./actor-policy";
|
|
45
|
+
import { createSessionHistoryOfReader } from "./history-target";
|
|
46
|
+
import { registerSessionHistoryOfTools } from "./history-tools";
|
|
47
|
+
import {
|
|
48
|
+
hubRemoteAbort,
|
|
49
|
+
hubRemoteAsk,
|
|
50
|
+
hubRemotePeek,
|
|
51
|
+
hubRemoteSessions,
|
|
52
|
+
hubRemoteTell,
|
|
53
|
+
} from "./hub-remote-session";
|
|
54
|
+
import { forwardToPeer, peerSessionsForUser } from "./peer-forward";
|
|
55
|
+
import {
|
|
56
|
+
cronSessionId,
|
|
57
|
+
currentDepth,
|
|
58
|
+
currentTopic,
|
|
59
|
+
currentTopicId,
|
|
60
|
+
isManagerTopic,
|
|
61
|
+
isReplyOnly,
|
|
62
|
+
MAX_MESSAGE_LENGTH,
|
|
63
|
+
MAX_TELL_DEPTH,
|
|
64
|
+
peerHostQueryId,
|
|
65
|
+
sessionCommContext,
|
|
66
|
+
subagentParentTopicId,
|
|
67
|
+
userId,
|
|
68
|
+
} from "./runtime";
|
|
69
|
+
import { canSubagentTellTarget, resolveSubagentTellIdentity } from "./tell-permissions";
|
|
70
|
+
import {
|
|
71
|
+
currentApiTopicId,
|
|
72
|
+
getMcpConfig,
|
|
73
|
+
setCurrentTopicDescription,
|
|
74
|
+
setMcpConfig,
|
|
75
|
+
} from "./topic-config";
|
|
76
|
+
import {
|
|
77
|
+
currentSessionSurface,
|
|
78
|
+
getTopicsForUser,
|
|
79
|
+
listSessionTargetsForUser,
|
|
80
|
+
type QueryState,
|
|
81
|
+
validateTarget,
|
|
82
|
+
} from "./topics";
|
|
83
|
+
|
|
84
|
+
/** Addressing: "<nodeName>/<topicTitle>". Node names never contain "/", so
|
|
85
|
+
* the first slash splits reliably (kept for future cross-node adapters). */
|
|
86
|
+
interface PeerTarget {
|
|
87
|
+
node: string;
|
|
88
|
+
topic: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A target is remote when it is not a local topic name AND parses as
|
|
92
|
+
* "node/topic". Local titles containing "/" keep working — the local map is
|
|
93
|
+
* checked first. */
|
|
94
|
+
function remotePeerTarget(to: string): PeerTarget | null {
|
|
95
|
+
// Local titles always win; placement routing is adapter-owned (an otium
|
|
96
|
+
// worker keeps its own placement store), so core never remote-routes a
|
|
97
|
+
// local topic.
|
|
98
|
+
const local = getTopicsForUser()[to];
|
|
99
|
+
if (local?.topicId) return null;
|
|
100
|
+
const slash = to.indexOf("/");
|
|
101
|
+
if (slash <= 0 || slash === to.length - 1) return null;
|
|
102
|
+
return { node: to.slice(0, slash), topic: to.slice(slash + 1) };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Principal a local inbox entry for `targetTopicId` is filed under, and the
|
|
107
|
+
* target's turn runs as: this turn's own, or `null` (refuse) when it is not a
|
|
108
|
+
* participant of the target room (see `localDeliveryPrincipal`). Same rule as
|
|
109
|
+
* the hosted host, from the same module.
|
|
110
|
+
*/
|
|
111
|
+
function deliveryPrincipal(targetTopicId: string): string | null {
|
|
112
|
+
return localDeliveryPrincipal({
|
|
113
|
+
callerUserId: userId,
|
|
114
|
+
targetParticipants: getTopic(targetTopicId)?.participants,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Which transport serves `node/topic` targets for this turn (see `remoteSessionRoute`). */
|
|
119
|
+
function currentRemoteRoute() {
|
|
120
|
+
return remoteSessionRoute(currentSessionSurface(), sessionCommContext.remoteSession);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// --- MCP Server ---
|
|
124
|
+
|
|
125
|
+
const server = new McpServer({
|
|
126
|
+
name: "session-comm",
|
|
127
|
+
version: "1.0.0",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
function queryStateFileName(topicId: string): string {
|
|
131
|
+
return `${sanitizeId(topicId)}.json`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function readQueryState(
|
|
135
|
+
activeQueriesDir: string,
|
|
136
|
+
topicId: string | undefined,
|
|
137
|
+
legacyTopicName: string,
|
|
138
|
+
): QueryState | null {
|
|
139
|
+
if (topicId) {
|
|
140
|
+
const current = readJsonFile<QueryState>(join(activeQueriesDir, queryStateFileName(topicId)));
|
|
141
|
+
if (current) return current;
|
|
142
|
+
}
|
|
143
|
+
if (
|
|
144
|
+
!legacyTopicName ||
|
|
145
|
+
legacyTopicName === "." ||
|
|
146
|
+
legacyTopicName === ".." ||
|
|
147
|
+
basename(legacyTopicName) !== legacyTopicName
|
|
148
|
+
) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return readJsonFile<QueryState>(join(activeQueriesDir, `${legacyTopicName}.json`));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function currentTopicRef(): { key: string; title: string; topicId?: string } {
|
|
155
|
+
if (currentTopicId) {
|
|
156
|
+
try {
|
|
157
|
+
const topic = getTopic(currentTopicId);
|
|
158
|
+
if (topic) {
|
|
159
|
+
return {
|
|
160
|
+
key: `${topic.kind ?? "channel"}:${topic.title}`,
|
|
161
|
+
title: topic.title,
|
|
162
|
+
topicId: topic.id,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
} catch {
|
|
166
|
+
// Fall back to the CLI title below.
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
key: currentTopic,
|
|
171
|
+
title: currentTopic,
|
|
172
|
+
...(currentTopicId ? { topicId: currentTopicId } : {}),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const currentSubagentIdentity = resolveSubagentTellIdentity(currentTopicId, subagentParentTopicId);
|
|
177
|
+
const currentSubagentRestricted = currentSubagentIdentity.restricted;
|
|
178
|
+
|
|
179
|
+
function canCurrentSubagentTell(targetTopicId: string): boolean {
|
|
180
|
+
return canSubagentTellTarget(currentSubagentIdentity, targetTopicId);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// --- always available ---
|
|
184
|
+
|
|
185
|
+
server.tool(
|
|
186
|
+
"list_sessions",
|
|
187
|
+
"List all available AI sessions (forum topics) for inter-session communication. Topics without an active session are still valid targets — ask_session / tell_session will wake them with a fresh session on first delivery.",
|
|
188
|
+
{},
|
|
189
|
+
async () => {
|
|
190
|
+
const entries = listSessionTargetsForUser()
|
|
191
|
+
.filter(
|
|
192
|
+
({ topic }) =>
|
|
193
|
+
!currentSubagentRestricted ||
|
|
194
|
+
Boolean(topic.topicId && canCurrentSubagentTell(topic.topicId)),
|
|
195
|
+
)
|
|
196
|
+
.filter(({ topic }) => Boolean(topic.agent))
|
|
197
|
+
.map(({ key, topic: t }) => {
|
|
198
|
+
const status = !t.agent
|
|
199
|
+
? "no AI invited"
|
|
200
|
+
: t.sessionId
|
|
201
|
+
? `active (${t.sessionId.slice(0, 8)})`
|
|
202
|
+
: "fresh-start ready";
|
|
203
|
+
const desc = t.description
|
|
204
|
+
? `\n description: ${t.description.slice(0, 80)}${t.description.length > 80 ? "..." : ""}`
|
|
205
|
+
: "";
|
|
206
|
+
return `- ${key}: ${status}${desc}`;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Multi-node: append each peer node's rooms, addressed as "node/topic".
|
|
210
|
+
// Disabled or unattached nodes answer with an error — skip silently so
|
|
211
|
+
// single-node behavior is untouched. On Otium the remote rooms are the
|
|
212
|
+
// hub's answer for this turn's grant, and none without one (see
|
|
213
|
+
// `remoteSessionRoute`).
|
|
214
|
+
const remoteSections: string[] = [];
|
|
215
|
+
const route = currentSubagentRestricted ? null : currentRemoteRoute();
|
|
216
|
+
if (route?.kind === "hub") {
|
|
217
|
+
const remote = await hubRemoteSessions(route.grant);
|
|
218
|
+
if (!remote.ok) {
|
|
219
|
+
remoteSections.push(`\nRemote nodes: (${remote.error})`);
|
|
220
|
+
} else {
|
|
221
|
+
for (const node of remote.nodes) {
|
|
222
|
+
if (!node.node) continue;
|
|
223
|
+
if (node.error) {
|
|
224
|
+
remoteSections.push(`\nNode ${node.node}: (unreachable: ${node.error})`);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const lines = (node.sessions ?? [])
|
|
228
|
+
.filter((session) => Boolean(session.agent))
|
|
229
|
+
.map((s) => {
|
|
230
|
+
const status = s.status === "active" ? "active" : "fresh-start ready";
|
|
231
|
+
const desc = s.description ? ` — ${s.description.slice(0, 60)}` : "";
|
|
232
|
+
return `- ${node.node}/${s.name}: ${status}${desc}`;
|
|
233
|
+
});
|
|
234
|
+
remoteSections.push(
|
|
235
|
+
`\nNode ${node.node}:\n${lines.join("\n") || " (no rooms for this user)"}`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const peers =
|
|
241
|
+
route?.kind !== "peer"
|
|
242
|
+
? { ok: true as const, nodes: [] }
|
|
243
|
+
: await peerSessionsForUser(userId, peerHostQueryId || undefined, currentTopicId);
|
|
244
|
+
if (peers.ok && peers.nodes) {
|
|
245
|
+
for (const node of peers.nodes) {
|
|
246
|
+
if (!node.node) continue;
|
|
247
|
+
if (node.error) {
|
|
248
|
+
remoteSections.push(`\nNode ${node.node}: (unreachable: ${node.error})`);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const lines = (node.sessions ?? [])
|
|
252
|
+
.filter((session) => Boolean(session.agent))
|
|
253
|
+
.map((s) => {
|
|
254
|
+
const status = s.hasSession ? "active" : "fresh-start ready";
|
|
255
|
+
const desc = s.description ? ` — ${s.description.slice(0, 60)}` : "";
|
|
256
|
+
return `- ${node.node}/${s.name}: ${status}${desc}`;
|
|
257
|
+
});
|
|
258
|
+
remoteSections.push(
|
|
259
|
+
`\nNode ${node.node}:\n${lines.join("\n") || " (no rooms for this user)"}`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (entries.length === 0 && remoteSections.length === 0) {
|
|
265
|
+
return mcpOk("No other sessions available.");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
content: [
|
|
270
|
+
{
|
|
271
|
+
type: "text" as const,
|
|
272
|
+
text:
|
|
273
|
+
`Current session: ${currentTopic}\nTell depth: ${currentDepth}/${MAX_TELL_DEPTH}\n\n` +
|
|
274
|
+
`Available sessions:\n${entries.join("\n")}${remoteSections.join("\n")}`,
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
server.tool(
|
|
282
|
+
"configure_mcp",
|
|
283
|
+
`Configure MCP servers for the current topic. Changes take effect on the next user message automatically (no restart needed).\n` +
|
|
284
|
+
`- enabled: optional servers to whitelist on top of required ones (null or [] = required-only). Required servers are always active regardless: ${REQUIRED_FORUM_MCP_SERVERS.join(", ")}\n` +
|
|
285
|
+
`- Optional servers you can toggle: ${OPTIONAL_FORUM_MCP_SERVERS.join(", ")}.`,
|
|
286
|
+
{
|
|
287
|
+
enabled: z
|
|
288
|
+
.array(z.string())
|
|
289
|
+
.nullable()
|
|
290
|
+
.optional()
|
|
291
|
+
.describe(
|
|
292
|
+
`Optional servers to enable on top of required ones. null or [] = required-only, or a subset of: ${OPTIONAL_FORUM_MCP_SERVERS.join(", ")}`,
|
|
293
|
+
),
|
|
294
|
+
},
|
|
295
|
+
async ({ enabled }) => {
|
|
296
|
+
if (!currentTopic || !userId) {
|
|
297
|
+
return mcpError("Error: No current topic.");
|
|
298
|
+
}
|
|
299
|
+
if (isManagerTopic) {
|
|
300
|
+
return mcpError(
|
|
301
|
+
"Error: General is a manager room and does not use per-topic MCP whitelists. Use topic-admin set_topic_mcp for a target topic.",
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
setMcpConfig(enabled);
|
|
306
|
+
const current = getMcpConfig();
|
|
307
|
+
const lines = [
|
|
308
|
+
`MCP 설정 저장됨 (다음 사용자 메시지부터 자동 적용, 재시작 불필요)`,
|
|
309
|
+
``,
|
|
310
|
+
...formatMcpStatus(current),
|
|
311
|
+
];
|
|
312
|
+
return mcpOk(lines.join("\n"));
|
|
313
|
+
} catch (err) {
|
|
314
|
+
return mcpError(`Error: ${errMsg(err)}`);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
server.tool(
|
|
320
|
+
"get_mcp_config",
|
|
321
|
+
"Get the current MCP server configuration for this topic. Required servers are always active regardless of whitelist settings.",
|
|
322
|
+
{},
|
|
323
|
+
async () => {
|
|
324
|
+
if (isManagerTopic) {
|
|
325
|
+
return mcpOk(
|
|
326
|
+
"General is a manager room. It uses the manager MCP bundle directly; per-topic MCP whitelist settings do not apply. Use topic-admin get_topic_mcp for a target topic.",
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
const config = getMcpConfig();
|
|
330
|
+
const lines = [`현재 토픽: ${currentTopic}`, ``, ...formatMcpStatus(config)];
|
|
331
|
+
return mcpOk(lines.join("\n"));
|
|
332
|
+
},
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
server.tool(
|
|
336
|
+
"get_browser_profile",
|
|
337
|
+
"Get this topic's browser profile and the other owned topics assigned to each profile.",
|
|
338
|
+
{},
|
|
339
|
+
async () => {
|
|
340
|
+
const topicId = currentApiTopicId();
|
|
341
|
+
if (!topicId || !userId) return mcpError("Error: No current API topic.");
|
|
342
|
+
if (!isTopicBrowserProfileOwner(topicId, userId)) {
|
|
343
|
+
return mcpError("Error: Only the topic owner can inspect its browser profiles.");
|
|
344
|
+
}
|
|
345
|
+
const ownerId = getBrowserProfileOwner(topicId, userId);
|
|
346
|
+
return mcpOk(
|
|
347
|
+
JSON.stringify(
|
|
348
|
+
{
|
|
349
|
+
current: getTopicBrowserProfile(topicId),
|
|
350
|
+
profiles: listBrowserProfiles(ownerId),
|
|
351
|
+
},
|
|
352
|
+
null,
|
|
353
|
+
2,
|
|
354
|
+
),
|
|
355
|
+
);
|
|
356
|
+
},
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
server.tool(
|
|
360
|
+
"set_browser_profile",
|
|
361
|
+
"Assign this topic to a named shared browser profile. Topics with the same owner and profile share login state but keep owner-isolated tabs. Takes effect next turn.",
|
|
362
|
+
{
|
|
363
|
+
profile: z
|
|
364
|
+
.string()
|
|
365
|
+
.describe("1-48 lowercase letters, numbers, '-' or '_'; use default for the default profile"),
|
|
366
|
+
},
|
|
367
|
+
async ({ profile }) => {
|
|
368
|
+
const topicId = currentApiTopicId();
|
|
369
|
+
if (!topicId || !userId) return mcpError("Error: No current API topic.");
|
|
370
|
+
try {
|
|
371
|
+
if (!isTopicBrowserProfileOwner(topicId, userId)) {
|
|
372
|
+
return mcpError("Error: Only the topic owner can change its browser profile.");
|
|
373
|
+
}
|
|
374
|
+
const result = assignTopicBrowserProfile({ topicId, actorUserId: userId, profile });
|
|
375
|
+
let cleanupWarning = "";
|
|
376
|
+
if (result.previous !== result.profile) {
|
|
377
|
+
try {
|
|
378
|
+
await closeBrowserOwnerTabs(userId, result.previous, `topic:${topicId}`);
|
|
379
|
+
} catch (err) {
|
|
380
|
+
cleanupWarning = ` Previous-profile tab cleanup failed: ${errMsg(err)}`;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return mcpOk(
|
|
384
|
+
`Browser profile changed: ${result.previous} -> ${result.profile}. It takes effect next turn.${cleanupWarning}`,
|
|
385
|
+
);
|
|
386
|
+
} catch (err) {
|
|
387
|
+
return mcpError(`Error: ${errMsg(err)}`);
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
server.tool(
|
|
393
|
+
"delete_browser_profile",
|
|
394
|
+
"Delete an unused named browser profile and its on-disk data. The default or an assigned profile cannot be deleted.",
|
|
395
|
+
{
|
|
396
|
+
profile: z
|
|
397
|
+
.string()
|
|
398
|
+
.describe("Unused named profile to delete; the default profile cannot be deleted"),
|
|
399
|
+
},
|
|
400
|
+
async ({ profile }) => {
|
|
401
|
+
const topicId = currentApiTopicId();
|
|
402
|
+
if (!topicId || !userId) return mcpError("Error: No current API topic.");
|
|
403
|
+
if (!isTopicBrowserProfileOwner(topicId, userId)) {
|
|
404
|
+
return mcpError("Error: Only the topic owner can delete its browser profiles.");
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
const ownerId = getBrowserProfileOwner(topicId, userId);
|
|
408
|
+
const result = await deleteManagedBrowserProfile(ownerId, profile);
|
|
409
|
+
return mcpOk(JSON.stringify(result, null, 2));
|
|
410
|
+
} catch (err) {
|
|
411
|
+
return mcpError(`Error: ${errMsg(err)}`);
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
// --- always-available session inspection / self-config ---
|
|
417
|
+
|
|
418
|
+
server.tool(
|
|
419
|
+
"peek_session",
|
|
420
|
+
"Check which sessions are currently running a query (busy) vs idle. Useful before abort_session.",
|
|
421
|
+
{},
|
|
422
|
+
async () => {
|
|
423
|
+
const targets = listSessionTargetsForUser().filter(
|
|
424
|
+
({ topic }) =>
|
|
425
|
+
!currentSubagentRestricted ||
|
|
426
|
+
Boolean(topic.topicId && canCurrentSubagentTell(topic.topicId)),
|
|
427
|
+
);
|
|
428
|
+
const activeQueriesDir = join(USERS_LOG_DIR, userId, "active-queries");
|
|
429
|
+
|
|
430
|
+
// Read own query state for consistent display
|
|
431
|
+
let selfLabel = `${currentTopic} (자신 — 실행 중)`;
|
|
432
|
+
const selfState = readQueryState(activeQueriesDir, currentTopicId || undefined, currentTopic);
|
|
433
|
+
if (selfState) {
|
|
434
|
+
const selfElapsed = Date.now() - new Date(selfState.since).getTime();
|
|
435
|
+
const selfMins = Math.floor(selfElapsed / 60000);
|
|
436
|
+
const selfSecs = Math.floor((selfElapsed % 60000) / 1000);
|
|
437
|
+
const selfTimeStr = selfMins > 0 ? `${selfMins}분 ${selfSecs}초` : `${selfSecs}초`;
|
|
438
|
+
const selfTaskStr = selfState.task ? ` | ${selfState.task}` : "";
|
|
439
|
+
selfLabel = `${currentTopic} (자신 — ${selfTimeStr}${selfTaskStr})`;
|
|
440
|
+
}
|
|
441
|
+
const running: string[] = [selfLabel];
|
|
442
|
+
const idle: string[] = [];
|
|
443
|
+
|
|
444
|
+
for (const { key: name, topic } of targets) {
|
|
445
|
+
let isRunning = false;
|
|
446
|
+
// Read-only: a visible room of another principal (otium, Q1) records its
|
|
447
|
+
// turns under that principal. Never used to file an inbox entry.
|
|
448
|
+
const principal = topic.topicId
|
|
449
|
+
? roomStatusPrincipal({
|
|
450
|
+
callerUserId: userId,
|
|
451
|
+
targetParticipants: getTopic(topic.topicId)?.participants,
|
|
452
|
+
})
|
|
453
|
+
: null;
|
|
454
|
+
const state = readQueryState(
|
|
455
|
+
principal && principal !== userId
|
|
456
|
+
? join(USERS_LOG_DIR, principal, "active-queries")
|
|
457
|
+
: activeQueriesDir,
|
|
458
|
+
topic.topicId,
|
|
459
|
+
topic.name,
|
|
460
|
+
);
|
|
461
|
+
if (state) {
|
|
462
|
+
const elapsed = Date.now() - new Date(state.since).getTime();
|
|
463
|
+
if (elapsed <= ACTIVE_QUERY_STALE_MS) {
|
|
464
|
+
const mins = Math.floor(elapsed / 60000);
|
|
465
|
+
const secs = Math.floor((elapsed % 60000) / 1000);
|
|
466
|
+
const timeStr = mins > 0 ? `${mins}분 ${secs}초` : `${secs}초`;
|
|
467
|
+
const taskStr = state.task ? ` | ${state.task}` : "";
|
|
468
|
+
running.push(`${name} (${timeStr}${taskStr})`);
|
|
469
|
+
isRunning = true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (!isRunning) idle.push(name);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const runningHeader = `실행 중 (${running.length}):\n${running.map((r) => ` ${r}`).join("\n")}`;
|
|
476
|
+
const pendingAsks = listPendingAsksForCaller({
|
|
477
|
+
userId,
|
|
478
|
+
from: currentTopicRef().key,
|
|
479
|
+
});
|
|
480
|
+
const lines = [
|
|
481
|
+
`현재 세션 상태`,
|
|
482
|
+
``,
|
|
483
|
+
runningHeader,
|
|
484
|
+
`유휴 (${idle.length}): ${idle.join(", ") || "없음"}`,
|
|
485
|
+
];
|
|
486
|
+
if (pendingAsks.length) {
|
|
487
|
+
lines.push(
|
|
488
|
+
``,
|
|
489
|
+
`내 ask_session 대기:`,
|
|
490
|
+
...pendingAsks.map(
|
|
491
|
+
(ask) =>
|
|
492
|
+
` ${ask.to}: ${describePendingAskState(ask.state)} (request_id: ${ask.requestId})`,
|
|
493
|
+
),
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
// Remote rooms (v1): the hub's active/ready view only — no elapsed time
|
|
497
|
+
// or task text, since the hub does not fan out to every node for a peek.
|
|
498
|
+
const route = currentSubagentRestricted ? null : currentRemoteRoute();
|
|
499
|
+
if (route?.kind === "hub") {
|
|
500
|
+
const remote = await hubRemotePeek(route.grant);
|
|
501
|
+
if (!remote.ok) {
|
|
502
|
+
lines.push(``, `원격 노드: (${remote.error})`);
|
|
503
|
+
} else {
|
|
504
|
+
const remoteRunning: string[] = [];
|
|
505
|
+
const remoteIdle: string[] = [];
|
|
506
|
+
const unreachable: string[] = [];
|
|
507
|
+
for (const node of remote.nodes) {
|
|
508
|
+
if (node.error) {
|
|
509
|
+
unreachable.push(` ${node.node}: (unreachable: ${node.error})`);
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
for (const session of node.sessions ?? []) {
|
|
513
|
+
// Same policy as the listing: a room with no AI is not a session.
|
|
514
|
+
if (session.agent === null) continue;
|
|
515
|
+
(session.status === "active" ? remoteRunning : remoteIdle).push(
|
|
516
|
+
`${node.node}/${session.name}`,
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
lines.push(
|
|
521
|
+
``,
|
|
522
|
+
`원격 실행 중 (${remoteRunning.length}): ${remoteRunning.join(", ") || "없음"}`,
|
|
523
|
+
`원격 유휴 (${remoteIdle.length}): ${remoteIdle.join(", ") || "없음"}`,
|
|
524
|
+
...unreachable,
|
|
525
|
+
);
|
|
526
|
+
if (remote.pendingAsks.length) {
|
|
527
|
+
lines.push(
|
|
528
|
+
`내 원격 ask_session 대기:`,
|
|
529
|
+
...remote.pendingAsks.map(
|
|
530
|
+
(ask) => ` ${ask.to}: ${ask.status} (request_id: ${ask.requestId})`,
|
|
531
|
+
),
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return mcpOk(lines.join("\n"));
|
|
537
|
+
},
|
|
538
|
+
);
|
|
539
|
+
|
|
540
|
+
server.tool(
|
|
541
|
+
"set_description",
|
|
542
|
+
"Set a description for the current session. Acts as a system prompt addition and routing hint for other sessions using list_sessions. Call this once at session start based on the topic's CLAUDE.md.",
|
|
543
|
+
{
|
|
544
|
+
description: z
|
|
545
|
+
.string()
|
|
546
|
+
.describe(
|
|
547
|
+
"What this session specializes in (e.g. 'UE5 graphics development, shader optimization')",
|
|
548
|
+
),
|
|
549
|
+
},
|
|
550
|
+
async ({ description }) => {
|
|
551
|
+
try {
|
|
552
|
+
setCurrentTopicDescription(description);
|
|
553
|
+
return mcpOk(`Description set for "${currentTopic}".`);
|
|
554
|
+
} catch (err) {
|
|
555
|
+
return mcpError(`Error: ${errMsg(err)}`);
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
// --- cross-topic session history (read-only, so reply-only forks keep it) ---
|
|
561
|
+
// Scope = this server's session-comm catalog (validateTarget) plus the
|
|
562
|
+
// subagent tell rule; see history-target.ts. Same tools as the hosted host.
|
|
563
|
+
registerSessionHistoryOfTools(
|
|
564
|
+
server,
|
|
565
|
+
createSessionHistoryOfReader({
|
|
566
|
+
callerUserId: userId,
|
|
567
|
+
validateTarget,
|
|
568
|
+
subagentIdentity: currentSubagentIdentity,
|
|
569
|
+
}),
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
// --- outbound session-to-session tools ---
|
|
573
|
+
// Suppressed when running as a silent fork that exists only to generate an
|
|
574
|
+
// ask_session reply — such a fork has no reason to initiate further calls.
|
|
575
|
+
|
|
576
|
+
if (!isReplyOnly) {
|
|
577
|
+
if (!currentSubagentRestricted) {
|
|
578
|
+
server.tool(
|
|
579
|
+
"ask_session",
|
|
580
|
+
"ASK — Delegate to another session and pull the result back INTO YOUR CONTEXT. The question runs as a visible turn in the target's own session (queued behind its current turn; the exchange stays in the target's history), processes with full tools, and the answer is auto-injected into your conversation. Use ONLY when YOU need the output to drive your next action (code reviews whose verdict determines your next edit, fact checks you'll cite, lookups that decide your next step). If the user can just read the result in the target topic, use tell_session — ask burns your context window with content you don't actually need. Decision rule: 'Do I need this output in MY context to proceed?' Yes → ask. No (result lives in target topic, user reads it there) → tell_session. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it — the target can read it with read_session_history_of.",
|
|
581
|
+
{
|
|
582
|
+
to: z.string().describe("Target session/topic name (e.g. '회의록', '신건')"),
|
|
583
|
+
message: z.string().describe("Message to send to the target session"),
|
|
584
|
+
},
|
|
585
|
+
async ({ to, message }) => {
|
|
586
|
+
if (message.length > MAX_MESSAGE_LENGTH) {
|
|
587
|
+
return mcpError(
|
|
588
|
+
`Error: message too long (${message.length} chars, max ${MAX_MESSAGE_LENGTH})`,
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Remote target ("node/topic") — hand to the runtime's peer forwarder.
|
|
593
|
+
const remote = remotePeerTarget(to);
|
|
594
|
+
if (remote) {
|
|
595
|
+
const route = currentRemoteRoute();
|
|
596
|
+
if (route.kind === "refused") return mcpError(route.error);
|
|
597
|
+
const fromRef = currentTopicRef();
|
|
598
|
+
if (!fromRef.topicId) {
|
|
599
|
+
return mcpError(
|
|
600
|
+
"Error: 이 세션은 원격 ask_session을 사용할 수 없습니다 (topic id 없음).",
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
604
|
+
let pending: ReturnType<typeof createPendingAsk> | null = null;
|
|
605
|
+
const alreadyPending = () => {
|
|
606
|
+
const existing = pending && !pending.ok ? pending.existing : null;
|
|
607
|
+
const detail = existing
|
|
608
|
+
? `${describePendingAskState(existing.state)} (request_id: ${existing.requestId})`
|
|
609
|
+
: "상태 파일 확인 중";
|
|
610
|
+
return mcpError(
|
|
611
|
+
`"${to}"에 이미 진행 중인 ask_session 요청이 있습니다: ${detail}. 응답이 이 세션에 자동으로 돌아올 때까지 기다리세요.`,
|
|
612
|
+
);
|
|
613
|
+
};
|
|
614
|
+
const createMarker = () => {
|
|
615
|
+
pending = createPendingAsk({ userId, from: fromRef.key, to, requestId });
|
|
616
|
+
return pending.ok;
|
|
617
|
+
};
|
|
618
|
+
if (route.kind === "hub") {
|
|
619
|
+
// Durable caller record first: the hub's `ask-reply` delivery is
|
|
620
|
+
// routed back through it, possibly after this process restarted.
|
|
621
|
+
// Row and pending marker are one state machine (see
|
|
622
|
+
// `RemoteSessionAskDispatchState`): the row never goes while its
|
|
623
|
+
// marker may remain, and a crash anywhere is reconciled later.
|
|
624
|
+
const releaseAsk = () =>
|
|
625
|
+
releasePendingAsk({ userId, from: fromRef.key, to, requestId });
|
|
626
|
+
let begun: "ok" | "pending";
|
|
627
|
+
try {
|
|
628
|
+
begun = beginRemoteSessionAsk({
|
|
629
|
+
requestId,
|
|
630
|
+
callerTopicId: fromRef.topicId,
|
|
631
|
+
userId,
|
|
632
|
+
fromKey: fromRef.key,
|
|
633
|
+
toKey: to,
|
|
634
|
+
...(sessionCommContext.currentThreadRootId
|
|
635
|
+
? { callerThreadRootId: sessionCommContext.currentThreadRootId }
|
|
636
|
+
: {}),
|
|
637
|
+
createMarker,
|
|
638
|
+
releaseMarker: releaseAsk,
|
|
639
|
+
});
|
|
640
|
+
} catch (err) {
|
|
641
|
+
return mcpError(
|
|
642
|
+
`Error: "${to}" 원격 ask를 기록하지 못해 전송하지 않았습니다: ${err instanceof Error ? err.message : String(err)}`,
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
if (begun === "pending") return alreadyPending();
|
|
646
|
+
const sent = await hubRemoteAsk(route.grant, {
|
|
647
|
+
requestId,
|
|
648
|
+
to: remote,
|
|
649
|
+
message,
|
|
650
|
+
fromDepth: currentDepth,
|
|
651
|
+
fromLabel: { key: fromRef.key, title: fromRef.title },
|
|
652
|
+
});
|
|
653
|
+
if (!sent.ok) {
|
|
654
|
+
if (sent.uncertain) {
|
|
655
|
+
return mcpOk(
|
|
656
|
+
`"${to}" 세션(노드 ${remote.node})에 참조 요청을 보냈지만 hub의 확인을 받지 못했습니다 (${sent.error}).\n\nrequest_id: ${requestId}\n\n응답이 도착하면 '[Reply from ${remote.node}/${remote.topic}]' 형식으로 이 세션에 돌아옵니다. 같은 요청으로 ask_session을 재호출하지 마세요.`,
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
abandonRemoteSessionAsk(requestId, releaseAsk);
|
|
660
|
+
return mcpError(`Error: "${to}" 원격 세션에 전송 실패: ${sent.error}`);
|
|
661
|
+
}
|
|
662
|
+
markRemoteSessionAskSent(requestId);
|
|
663
|
+
return mcpOk(
|
|
664
|
+
`"${to}" 세션(노드 ${remote.node})에 참조 요청을 보냈습니다.\n\nrequest_id: ${requestId}\n\n응답은 '[Reply from ${remote.node}/${remote.topic}]' 형식으로 이 세션에 자동으로 돌아옵니다. 응답이 도착할 때까지 같은 요청으로 ask_session을 재호출하지 마세요.`,
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
if (!createMarker()) return alreadyPending();
|
|
668
|
+
const result = await forwardToPeer({
|
|
669
|
+
action: "ask",
|
|
670
|
+
toNode: remote.node,
|
|
671
|
+
toTopic: remote.topic,
|
|
672
|
+
userId,
|
|
673
|
+
fromKey: fromRef.key,
|
|
674
|
+
fromTitle: fromRef.title,
|
|
675
|
+
fromTopicId: fromRef.topicId,
|
|
676
|
+
message,
|
|
677
|
+
requestId,
|
|
678
|
+
fromDepth: currentDepth,
|
|
679
|
+
...(peerHostQueryId ? { sourceQueryId: peerHostQueryId } : {}),
|
|
680
|
+
});
|
|
681
|
+
if (!result.ok) {
|
|
682
|
+
clearPendingAsk({ userId, from: fromRef.key, to, requestId });
|
|
683
|
+
return mcpError(`Error: "${to}" 원격 세션에 전송 실패: ${result.error}`);
|
|
684
|
+
}
|
|
685
|
+
return mcpOk(
|
|
686
|
+
`"${to}" 세션(노드 ${remote.node})에 참조 요청을 보냈습니다.\n\nrequest_id: ${requestId}\n\n응답은 '[Reply from ${remote.node}/${remote.topic}]' 형식으로 이 세션에 자동으로 돌아옵니다. 응답이 도착할 때까지 같은 요청으로 ask_session을 재호출하지 마세요.`,
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const validation = validateTarget(to);
|
|
691
|
+
if (!validation.ok) return validation.error;
|
|
692
|
+
if (!validation.target.agent) {
|
|
693
|
+
return mcpError(
|
|
694
|
+
`Error: "${to}" 토픽에는 AI가 초대되어 있지 않아 ask_session을 실행할 수 없습니다.`,
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
if (validation.target.topicId && deliveryPrincipal(validation.target.topicId) !== userId) {
|
|
698
|
+
return mcpError(crossPrincipalRefusal("ask_session", to));
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const fromRef = currentTopicRef();
|
|
702
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
703
|
+
const pending = createPendingAsk({
|
|
704
|
+
userId,
|
|
705
|
+
from: fromRef.key,
|
|
706
|
+
to,
|
|
707
|
+
requestId,
|
|
708
|
+
});
|
|
709
|
+
if (!pending.ok) {
|
|
710
|
+
const detail = pending.existing
|
|
711
|
+
? `${describePendingAskState(pending.existing.state)} (request_id: ${pending.existing.requestId})`
|
|
712
|
+
: "상태 파일 확인 중";
|
|
713
|
+
return mcpError(
|
|
714
|
+
`"${to}"에 이미 진행 중인 ask_session 요청이 있습니다: ${detail}. 응답이 이 세션에 자동으로 돌아올 때까지 기다리세요.`,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
try {
|
|
719
|
+
const targetTopicId = validation.target.topicId;
|
|
720
|
+
if (!targetTopicId) {
|
|
721
|
+
clearPendingAsk({ userId, from: fromRef.key, to, requestId });
|
|
722
|
+
return mcpError(`Error: "${to}" 세션의 토픽 ID를 찾을 수 없습니다.`);
|
|
723
|
+
}
|
|
724
|
+
const entry = {
|
|
725
|
+
type: "ask" as const,
|
|
726
|
+
requestId,
|
|
727
|
+
from: fromRef.key,
|
|
728
|
+
fromTitle: fromRef.title,
|
|
729
|
+
...(fromRef.topicId ? { fromTopicId: fromRef.topicId } : {}),
|
|
730
|
+
message,
|
|
731
|
+
// Caller's depth — used to resume this session at the correct depth
|
|
732
|
+
// when the target's reply is injected back.
|
|
733
|
+
fromDepth: currentDepth,
|
|
734
|
+
timestamp: new Date().toISOString(),
|
|
735
|
+
};
|
|
736
|
+
enqueueSessionInbox({ userId, topicId: targetTopicId, entry });
|
|
737
|
+
process.stderr.write(
|
|
738
|
+
`[session-comm] ask_session: ${fromRef.key} → ${to} requestId=${requestId}\n`,
|
|
739
|
+
);
|
|
740
|
+
} catch (err) {
|
|
741
|
+
clearPendingAsk({
|
|
742
|
+
userId,
|
|
743
|
+
from: fromRef.key,
|
|
744
|
+
to,
|
|
745
|
+
requestId,
|
|
746
|
+
});
|
|
747
|
+
const e = err as { message?: string };
|
|
748
|
+
process.stderr.write(
|
|
749
|
+
`[session-comm] ask_session: failed ${currentTopic} → ${to} requestId=${requestId}: ${e?.message || "Unknown"}\n`,
|
|
750
|
+
);
|
|
751
|
+
return mcpError(`Error: "${to}" 세션에 메시지 전송 실패: ${e?.message || "Unknown"}`);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return mcpOk(
|
|
755
|
+
`"${to}" 세션에 참조 요청을 보냈습니다.\n\nrequest_id: ${requestId}\n\n"${to}"의 응답은 '[ask_session 응답 ← ${to} | request_id: ${requestId}]' 형식으로 이 세션에 자동으로 돌아옵니다. 응답이 도착할 때까지 같은 요청으로 ask_session을 재호출하지 마세요.`,
|
|
756
|
+
);
|
|
757
|
+
},
|
|
758
|
+
);
|
|
759
|
+
|
|
760
|
+
server.tool(
|
|
761
|
+
"ask_cron",
|
|
762
|
+
"Ask this topic's shared Cron session a question. The query runs asynchronously in a fork and the answer is injected back into this conversation.",
|
|
763
|
+
{
|
|
764
|
+
message: z.string().describe("Question or message to send to the Cron session"),
|
|
765
|
+
},
|
|
766
|
+
async ({ message }) => {
|
|
767
|
+
if (message.length > MAX_MESSAGE_LENGTH) {
|
|
768
|
+
return mcpError(
|
|
769
|
+
`Error: message too long (${message.length} chars, max ${MAX_MESSAGE_LENGTH})`,
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
const fromRef = currentTopicRef();
|
|
773
|
+
if (!fromRef.topicId) return mcpError("Error: 현재 토픽 ID를 찾을 수 없습니다.");
|
|
774
|
+
if (!cronSessionId) {
|
|
775
|
+
return mcpError(
|
|
776
|
+
`Error: "${fromRef.title}" 토픽에 cron 세션이 없습니다. 크론 작업이 최소 한 번 실행되어야 합니다.`,
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
780
|
+
const pending = createPendingAsk({
|
|
781
|
+
userId,
|
|
782
|
+
from: fromRef.key,
|
|
783
|
+
to: fromRef.title,
|
|
784
|
+
requestId,
|
|
785
|
+
});
|
|
786
|
+
if (!pending.ok) {
|
|
787
|
+
return mcpError(`Error: "${fromRef.title}"에 이미 진행 중인 요청이 있습니다.`);
|
|
788
|
+
}
|
|
789
|
+
try {
|
|
790
|
+
enqueueSessionInbox({
|
|
791
|
+
userId,
|
|
792
|
+
topicId: fromRef.topicId,
|
|
793
|
+
entry: {
|
|
794
|
+
type: "ask" as const,
|
|
795
|
+
target: "cron" as const,
|
|
796
|
+
requestId,
|
|
797
|
+
from: fromRef.key,
|
|
798
|
+
fromTitle: fromRef.title,
|
|
799
|
+
fromTopicId: fromRef.topicId,
|
|
800
|
+
message,
|
|
801
|
+
fromDepth: currentDepth,
|
|
802
|
+
timestamp: new Date().toISOString(),
|
|
803
|
+
},
|
|
804
|
+
});
|
|
805
|
+
} catch (err) {
|
|
806
|
+
clearPendingAsk({ userId, from: fromRef.key, to: fromRef.title, requestId });
|
|
807
|
+
const e = err as { message?: string };
|
|
808
|
+
process.stderr.write(
|
|
809
|
+
`[session-comm] ask_cron: failed ${currentTopic} requestId=${requestId}: ${e.message || "Unknown"}\n`,
|
|
810
|
+
);
|
|
811
|
+
return mcpError("Error: cron 세션에 메시지를 전송하지 못했습니다.");
|
|
812
|
+
}
|
|
813
|
+
return mcpOk(
|
|
814
|
+
`"${fromRef.title}:cron" 세션에 참조 요청을 보냈습니다.\n\nrequest_id: ${requestId}\n\n응답은 '[Reply from ${fromRef.title}:cron]' 형식으로 이 세션에 자동으로 돌아옵니다. 응답이 도착할 때까지 같은 요청으로 ask_cron을 재호출하지 마세요.`,
|
|
815
|
+
);
|
|
816
|
+
},
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
if (!currentSubagentRestricted) {
|
|
821
|
+
server.tool(
|
|
822
|
+
"abort_session",
|
|
823
|
+
"Abort the currently running query in another session. Use peek_session first to confirm it is busy.",
|
|
824
|
+
{
|
|
825
|
+
to: z.string().describe("Target session/topic name to abort"),
|
|
826
|
+
},
|
|
827
|
+
async ({ to }) => {
|
|
828
|
+
const remote = remotePeerTarget(to);
|
|
829
|
+
if (remote) {
|
|
830
|
+
const route = currentRemoteRoute();
|
|
831
|
+
if (route.kind === "refused") return mcpError(route.error);
|
|
832
|
+
if (route.kind === "hub") {
|
|
833
|
+
const sent = await hubRemoteAbort(route.grant, {
|
|
834
|
+
requestId: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
835
|
+
to: remote,
|
|
836
|
+
});
|
|
837
|
+
if (!sent.ok) return mcpError(`Error: "${to}" 원격 abort 실패: ${sent.error}`);
|
|
838
|
+
return mcpOk(`"${to}" 세션(노드 ${remote.node})에 abort 신호를 보냈습니다.`);
|
|
839
|
+
}
|
|
840
|
+
const result = await forwardToPeer({
|
|
841
|
+
action: "abort",
|
|
842
|
+
toNode: remote.node,
|
|
843
|
+
toTopic: remote.topic,
|
|
844
|
+
userId,
|
|
845
|
+
...(peerHostQueryId ? { sourceQueryId: peerHostQueryId } : {}),
|
|
846
|
+
});
|
|
847
|
+
if (!result.ok) {
|
|
848
|
+
return mcpError(`Error: "${to}" 원격 abort 실패: ${result.error}`);
|
|
849
|
+
}
|
|
850
|
+
return mcpOk(`"${to}" 세션(노드 ${remote.node})에 abort 신호를 보냈습니다.`);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
const validation = validateTarget(to);
|
|
854
|
+
if (!validation.ok) return validation.error;
|
|
855
|
+
|
|
856
|
+
if (to === currentTopic) {
|
|
857
|
+
return mcpError(`Error: 자기 자신은 abort할 수 없습니다.`);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
try {
|
|
861
|
+
const targetTopicId = validation.target.topicId;
|
|
862
|
+
if (!targetTopicId) {
|
|
863
|
+
return mcpError(`Error: "${to}" 세션의 토픽 ID를 찾을 수 없습니다.`);
|
|
864
|
+
}
|
|
865
|
+
// Same owner rule as the hosted host, from the same module.
|
|
866
|
+
const refused = abortTargetRefusal({
|
|
867
|
+
surface: currentSessionSurface(),
|
|
868
|
+
currentTopicId: currentTopicId || undefined,
|
|
869
|
+
actorTopicScope: sessionCommContext.actorTopicScope,
|
|
870
|
+
clock: { maxAgeMs: sessionCommContext.actorTopicScopeMaxAgeMs },
|
|
871
|
+
targetTopicId,
|
|
872
|
+
to,
|
|
873
|
+
});
|
|
874
|
+
if (refused) return mcpError(refused);
|
|
875
|
+
if (deliveryPrincipal(targetTopicId) !== userId) {
|
|
876
|
+
return mcpError(crossPrincipalRefusal("abort_session", to));
|
|
877
|
+
}
|
|
878
|
+
// Send query abort signal via inbox
|
|
879
|
+
enqueueSessionInbox({
|
|
880
|
+
userId,
|
|
881
|
+
topicId: targetTopicId,
|
|
882
|
+
entry: {
|
|
883
|
+
type: "abort",
|
|
884
|
+
timestamp: new Date().toISOString(),
|
|
885
|
+
},
|
|
886
|
+
});
|
|
887
|
+
process.stderr.write(`[session-comm] abort_session: ${currentTopic} → ${to}\n`);
|
|
888
|
+
} catch (err) {
|
|
889
|
+
const e = err as { message?: string };
|
|
890
|
+
process.stderr.write(
|
|
891
|
+
`[session-comm] abort_session: failed ${currentTopic} → ${to}: ${e?.message || "Unknown"}\n`,
|
|
892
|
+
);
|
|
893
|
+
return mcpError(`Error: abort 신호 전송 실패: ${e?.message || "Unknown"}`);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
return mcpOk(`"${to}" 세션에 abort 신호를 보냈습니다. 실행 중인 쿼리가 있으면 중단됩니다.`);
|
|
897
|
+
},
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
server.tool(
|
|
902
|
+
"tell_session",
|
|
903
|
+
"TELL — Delegate work or push context TO another session (one-way, nothing returns to your context). Message joins target's history; target processes async with full tools and the result lives in the target topic. Use for: delegating long-running or self-contained work (experiments, benchmarks, monitoring runs, file generation), status updates, persistent context injection — anything whose output the user can simply read in the target topic without you needing it. Prefer tell over ask_session whenever YOUR context doesn't need the result, since ask injects the full reply back and burns context. Decision rule: 'Do I need this output in MY context to proceed?' No → tell. Yes → ask_session. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it — the target can read it with read_session_history_of.",
|
|
904
|
+
{
|
|
905
|
+
to: z.string().describe("Target session/topic name (e.g. '회의록', '신건')"),
|
|
906
|
+
message: z.string().describe("Message to send to the target session"),
|
|
907
|
+
},
|
|
908
|
+
async ({ to, message }) => {
|
|
909
|
+
if (message.length > MAX_MESSAGE_LENGTH) {
|
|
910
|
+
return mcpError(
|
|
911
|
+
`Error: message too long (${message.length} chars, max ${MAX_MESSAGE_LENGTH})`,
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
if (currentDepth + 1 > MAX_TELL_DEPTH) {
|
|
916
|
+
return mcpError(
|
|
917
|
+
`Error: depth limit reached (current ${currentDepth}, max ${MAX_TELL_DEPTH}). Cannot build any more tell_session chains.`,
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Remote target ("node/topic") — hand to the runtime's peer forwarder.
|
|
922
|
+
const remote = remotePeerTarget(to);
|
|
923
|
+
if (remote) {
|
|
924
|
+
if (currentSubagentRestricted) {
|
|
925
|
+
return mcpError("Error: subagent tell_session cannot target remote topics.");
|
|
926
|
+
}
|
|
927
|
+
const route = currentRemoteRoute();
|
|
928
|
+
if (route.kind === "refused") return mcpError(route.error);
|
|
929
|
+
const fromRef = currentTopicRef();
|
|
930
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
931
|
+
if (route.kind === "hub") {
|
|
932
|
+
const sent = await hubRemoteTell(route.grant, {
|
|
933
|
+
requestId,
|
|
934
|
+
to: remote,
|
|
935
|
+
message,
|
|
936
|
+
depth: currentDepth + 1,
|
|
937
|
+
fromLabel: { key: fromRef.key, title: fromRef.title },
|
|
938
|
+
});
|
|
939
|
+
if (!sent.ok) {
|
|
940
|
+
// A timed-out response may still have been delivered; say so
|
|
941
|
+
// rather than invite a duplicate.
|
|
942
|
+
if (sent.uncertain) {
|
|
943
|
+
return mcpOk(
|
|
944
|
+
`"${to}" 토픽(노드 ${remote.node})에 메시지를 보냈지만 hub의 확인을 받지 못했습니다 (${sent.error}).\n\nrequest_id: ${requestId}\n\n같은 메시지를 다시 보내지 마세요.`,
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
return mcpError(`Error: "${to}" 원격 세션에 전송 실패: ${sent.error}`);
|
|
948
|
+
}
|
|
949
|
+
return mcpOk(
|
|
950
|
+
`"${to}" 토픽(노드 ${remote.node})에 메시지를 전달했습니다.\n\nrequest_id: ${requestId}\n\n결과는 해당 노드의 "${remote.topic}" 대화 기록에 남습니다.`,
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
const result = await forwardToPeer({
|
|
954
|
+
action: "tell",
|
|
955
|
+
toNode: remote.node,
|
|
956
|
+
toTopic: remote.topic,
|
|
957
|
+
userId,
|
|
958
|
+
fromKey: fromRef.key,
|
|
959
|
+
fromTitle: fromRef.title,
|
|
960
|
+
...(fromRef.topicId ? { fromTopicId: fromRef.topicId } : {}),
|
|
961
|
+
message,
|
|
962
|
+
requestId,
|
|
963
|
+
depth: currentDepth + 1,
|
|
964
|
+
...(peerHostQueryId ? { sourceQueryId: peerHostQueryId } : {}),
|
|
965
|
+
});
|
|
966
|
+
if (!result.ok) {
|
|
967
|
+
return mcpError(`Error: "${to}" 원격 세션에 전송 실패: ${result.error}`);
|
|
968
|
+
}
|
|
969
|
+
return mcpOk(
|
|
970
|
+
`"${to}" 토픽(노드 ${remote.node})에 메시지를 전달했습니다.\n\nrequest_id: ${requestId}\n\n결과는 해당 노드의 "${remote.topic}" 대화 기록에 남습니다.`,
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const validation = validateTarget(to);
|
|
975
|
+
if (!validation.ok) return validation.error;
|
|
976
|
+
if (!validation.target.agent) {
|
|
977
|
+
return mcpError(
|
|
978
|
+
`Error: "${to}" 토픽에는 AI가 초대되어 있지 않아 tell_session으로 작업을 trigger할 수 없습니다.`,
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
const targetTopicId = validation.target.topicId;
|
|
983
|
+
if (!targetTopicId) {
|
|
984
|
+
return mcpError(`Error: "${to}" 세션의 토픽 ID를 찾을 수 없습니다.`);
|
|
985
|
+
}
|
|
986
|
+
if (!canCurrentSubagentTell(targetTopicId)) {
|
|
987
|
+
return mcpError(
|
|
988
|
+
"Error: subagents can tell_session only direct parents, direct children, or topics explicitly granted by an ancestor.",
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// Write to inbox — the Otium consumer will persist the DB message
|
|
993
|
+
// and trigger the AI turn. This matches the ask_session / abort_session
|
|
994
|
+
// pattern where the MCP is a pure writer and the consumer is the consumer.
|
|
995
|
+
//
|
|
996
|
+
// NOTE: no direct DB write here; the consumer in the Otium server process
|
|
997
|
+
// handles `deliverMessageToTopic` + the AI trigger.
|
|
998
|
+
if (deliveryPrincipal(targetTopicId) !== userId) {
|
|
999
|
+
return mcpError(crossPrincipalRefusal("tell_session", to));
|
|
1000
|
+
}
|
|
1001
|
+
const fromRef = currentTopicRef();
|
|
1002
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1003
|
+
try {
|
|
1004
|
+
enqueueSessionInbox({
|
|
1005
|
+
userId,
|
|
1006
|
+
topicId: targetTopicId,
|
|
1007
|
+
entry: {
|
|
1008
|
+
type: "tell",
|
|
1009
|
+
requestId,
|
|
1010
|
+
from: fromRef.key,
|
|
1011
|
+
fromTitle: fromRef.title,
|
|
1012
|
+
...(fromRef.topicId ? { fromTopicId: fromRef.topicId } : {}),
|
|
1013
|
+
message,
|
|
1014
|
+
depth: currentDepth + 1,
|
|
1015
|
+
timestamp: new Date().toISOString(),
|
|
1016
|
+
},
|
|
1017
|
+
});
|
|
1018
|
+
} catch (err: unknown) {
|
|
1019
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
1020
|
+
process.stderr.write(
|
|
1021
|
+
`[session-comm] tell_session: failed to write inbox ${currentTopic} → ${to}: ${e.message}\n`,
|
|
1022
|
+
);
|
|
1023
|
+
return mcpError(`Error: "${to}" 세션에 메시지 전송 실패: ${e.message}`);
|
|
1024
|
+
}
|
|
1025
|
+
process.stderr.write(
|
|
1026
|
+
`[session-comm] tell_session: ${fromRef.key} → ${to} requestId=${requestId} (topic ${validation.target.topicId ?? validation.target.name})\n`,
|
|
1027
|
+
);
|
|
1028
|
+
|
|
1029
|
+
return mcpOk(
|
|
1030
|
+
`"${to}" 토픽에 메시지를 전달했습니다.\n\nrequest_id: ${requestId}\n\n"${to}"의 대화 기록에 남습니다(다시 열거나 새로고침하면 보입니다).`,
|
|
1031
|
+
);
|
|
1032
|
+
},
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
await connectStdio(server);
|