@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,723 @@
|
|
|
1
|
+
import { basename, join } from "node:path";
|
|
2
|
+
import type { SessionCommMcpHost, SessionCommMcpResult } from "#mcp/factories/session-comm";
|
|
3
|
+
import {
|
|
4
|
+
abortTargetRefusal,
|
|
5
|
+
crossPrincipalRefusal,
|
|
6
|
+
excludesAgentlessTargets,
|
|
7
|
+
localDeliveryPrincipal,
|
|
8
|
+
remoteSessionRoute,
|
|
9
|
+
roomStatusPrincipal,
|
|
10
|
+
rosterBoundsSessionTargets,
|
|
11
|
+
} from "#mcp/session-comm/actor-policy";
|
|
12
|
+
import type { SessionCommContext } from "#mcp/session-comm/context";
|
|
13
|
+
import { createSessionHistoryOfReader } from "#mcp/session-comm/history-target";
|
|
14
|
+
import {
|
|
15
|
+
hubRemoteAbort,
|
|
16
|
+
hubRemoteAsk,
|
|
17
|
+
hubRemotePeek,
|
|
18
|
+
hubRemoteSessions,
|
|
19
|
+
hubRemoteTell,
|
|
20
|
+
} from "#mcp/session-comm/hub-remote-session";
|
|
21
|
+
import { forwardToPeer, peerSessionsForUser } from "#mcp/session-comm/peer-forward";
|
|
22
|
+
import {
|
|
23
|
+
canSubagentTellTarget,
|
|
24
|
+
resolveSubagentTellIdentity,
|
|
25
|
+
} from "#mcp/session-comm/tell-permissions";
|
|
26
|
+
import { createSessionTargetCatalog } from "#mcp/session-comm/topic-catalog";
|
|
27
|
+
import { ACTIVE_QUERY_STALE_MS, MAX_TELL_DEPTH, USERS_LOG_DIR } from "#platform/config";
|
|
28
|
+
import { readJsonFile } from "#platform/jsonl";
|
|
29
|
+
import { logger } from "#platform/logger";
|
|
30
|
+
import { OPTIONAL_FORUM_MCP_SERVERS, REQUIRED_FORUM_MCP_SERVERS } from "#platform/mcp-config";
|
|
31
|
+
import { closeBrowserOwnerTabs } from "#platform/playwright/manager";
|
|
32
|
+
import { deleteManagedBrowserProfile } from "#platform/playwright/profile-management";
|
|
33
|
+
import { actorReachableTopicIds } from "#runtime/actor-topic-reach";
|
|
34
|
+
import { getRegisteredCronSession } from "#runtime/cron-sessions";
|
|
35
|
+
import { sanitizeId } from "#security/sanitize";
|
|
36
|
+
import { getApiTopicConfig, setApiTopicConfig } from "#storage/api-topic-config";
|
|
37
|
+
import {
|
|
38
|
+
defaultSurfaceScope,
|
|
39
|
+
defaultTopicSurface,
|
|
40
|
+
getTopic,
|
|
41
|
+
listTopics,
|
|
42
|
+
upsertTopic,
|
|
43
|
+
} from "#storage/api-topics";
|
|
44
|
+
import {
|
|
45
|
+
assignTopicBrowserProfile,
|
|
46
|
+
getBrowserProfileOwner,
|
|
47
|
+
getTopicBrowserProfile,
|
|
48
|
+
isTopicBrowserProfileOwner,
|
|
49
|
+
listBrowserProfiles,
|
|
50
|
+
} from "#storage/browser-profiles";
|
|
51
|
+
import {
|
|
52
|
+
abandonRemoteSessionAsk,
|
|
53
|
+
beginRemoteSessionAsk,
|
|
54
|
+
markRemoteSessionAskSent,
|
|
55
|
+
} from "#storage/remote-session";
|
|
56
|
+
import {
|
|
57
|
+
clearPendingAsk,
|
|
58
|
+
createPendingAsk,
|
|
59
|
+
describePendingAskState,
|
|
60
|
+
listPendingAsksForCaller,
|
|
61
|
+
releasePendingAsk,
|
|
62
|
+
} from "#storage/session-asks";
|
|
63
|
+
import { enqueueSessionInbox } from "#storage/session-inbox";
|
|
64
|
+
import { isAgentKind, type QueryState } from "#types";
|
|
65
|
+
|
|
66
|
+
const MAX_MESSAGE_LENGTH = 10_000;
|
|
67
|
+
|
|
68
|
+
function ok(text: string): SessionCommMcpResult {
|
|
69
|
+
return { content: [{ type: "text", text }] };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function error(text: string): SessionCommMcpResult {
|
|
73
|
+
return { content: [{ type: "text", text }], isError: true };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function currentTopic(context: SessionCommContext) {
|
|
77
|
+
const topic = context.currentTopicId ? getTopic(context.currentTopicId) : null;
|
|
78
|
+
if (!topic?.participants.some((participant) => participant.userId === context.userId)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return topic;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Surface of the room this turn runs in; the host default when unknown. */
|
|
85
|
+
function currentSurface(context: SessionCommContext) {
|
|
86
|
+
return (
|
|
87
|
+
(context.currentTopicId ? getTopic(context.currentTopicId) : null)?.surface ??
|
|
88
|
+
defaultTopicSurface()
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function targetCatalog(context: SessionCommContext) {
|
|
93
|
+
const current = context.currentTopicId ? getTopic(context.currentTopicId) : null;
|
|
94
|
+
const surface = current?.surface ?? defaultTopicSurface();
|
|
95
|
+
// A room may only address rooms in its own workspace (M-8): with several
|
|
96
|
+
// Otium workspaces attached, "same surface" is no longer a boundary — two
|
|
97
|
+
// workspaces share the `otium` surface and must still be invisible to each
|
|
98
|
+
// other. A room with no scope addresses the other unscoped rooms.
|
|
99
|
+
const surfaceScope = current
|
|
100
|
+
? (current.surfaceScope ?? null)
|
|
101
|
+
: surface === "otium"
|
|
102
|
+
? defaultSurfaceScope()
|
|
103
|
+
: null;
|
|
104
|
+
// Off `otium` the node's roster is the boundary. On `otium` it is not
|
|
105
|
+
// (design Q1, see `rosterBoundsSessionTargets`): participants there are only
|
|
106
|
+
// execution principals (`local`, a synced room's person, or both), so the
|
|
107
|
+
// workspace (the store query) intersected with the reach set below is the
|
|
108
|
+
// whole rule. The hub's signed per-turn assertion is that set when present;
|
|
109
|
+
// without one (a turn no person started) only the current room plus its own
|
|
110
|
+
// subagent lineage — direct parent, granted targets, own workers — is
|
|
111
|
+
// reachable (fail-closed).
|
|
112
|
+
const rosterBound = rosterBoundsSessionTargets(surface);
|
|
113
|
+
const reachable = actorReachableTopicIds({
|
|
114
|
+
surface,
|
|
115
|
+
currentTopicId: context.currentTopicId,
|
|
116
|
+
actorTopicScope: context.actorTopicScope,
|
|
117
|
+
});
|
|
118
|
+
return createSessionTargetCatalog({
|
|
119
|
+
currentTopicId: context.currentTopicId,
|
|
120
|
+
currentTopicName: context.currentTopic,
|
|
121
|
+
currentSurface: surface,
|
|
122
|
+
excludeAgentless: excludesAgentlessTargets(surface),
|
|
123
|
+
isAgent: isAgentKind,
|
|
124
|
+
// Scoped in the store query, not after the fact.
|
|
125
|
+
listRows: () =>
|
|
126
|
+
listTopics({ surface, surfaceScope })
|
|
127
|
+
.filter(
|
|
128
|
+
(topic) => !rosterBound || topic.participants.some((p) => p.userId === context.userId),
|
|
129
|
+
)
|
|
130
|
+
.filter((topic) => !reachable || reachable.has(topic.id))
|
|
131
|
+
.map((topic) => ({
|
|
132
|
+
id: topic.id,
|
|
133
|
+
title: topic.title,
|
|
134
|
+
kind: topic.kind ?? null,
|
|
135
|
+
agent: topic.agent ?? null,
|
|
136
|
+
sessionId: null,
|
|
137
|
+
description: topic.description ?? null,
|
|
138
|
+
surface: topic.surface ?? null,
|
|
139
|
+
})),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function currentRef(context: SessionCommContext) {
|
|
144
|
+
const topic = currentTopic(context);
|
|
145
|
+
return topic
|
|
146
|
+
? { key: `${topic.kind}:${topic.title}`, title: topic.title, topicId: topic.id }
|
|
147
|
+
: { key: context.currentTopic, title: context.currentTopic, topicId: context.currentTopicId };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function remoteTarget(context: SessionCommContext, to: string) {
|
|
151
|
+
if (targetCatalog(context).getTopics()[to]?.topicId) return null;
|
|
152
|
+
const slash = to.indexOf("/");
|
|
153
|
+
if (slash <= 0 || slash === to.length - 1) return null;
|
|
154
|
+
return { node: to.slice(0, slash), topic: to.slice(slash + 1) };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Principal a local inbox entry for `targetTopicId` is filed under: the
|
|
159
|
+
* caller's own, or `null` (refuse) when the caller is not a participant of
|
|
160
|
+
* the target room (see `localDeliveryPrincipal`). Only for resolved targets.
|
|
161
|
+
*/
|
|
162
|
+
function deliveryPrincipal(context: SessionCommContext, targetTopicId: string): string | null {
|
|
163
|
+
return localDeliveryPrincipal({
|
|
164
|
+
callerUserId: context.userId,
|
|
165
|
+
targetParticipants: getTopic(targetTopicId)?.participants,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Which transport serves `node/topic` targets for this turn (see `remoteSessionRoute`). */
|
|
170
|
+
function remoteRoute(context: SessionCommContext) {
|
|
171
|
+
return remoteSessionRoute(currentSurface(context), context.remoteSession);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function newRequestId(): string {
|
|
175
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function activeQuery(context: SessionCommContext, topicId: string, title: string) {
|
|
179
|
+
// Read-only: a visible room of another principal (otium, Q1) records its
|
|
180
|
+
// turns under that principal. Never used to file an inbox entry.
|
|
181
|
+
const principal =
|
|
182
|
+
roomStatusPrincipal({
|
|
183
|
+
callerUserId: context.userId,
|
|
184
|
+
targetParticipants: getTopic(topicId)?.participants,
|
|
185
|
+
}) ?? context.userId;
|
|
186
|
+
const dir = join(USERS_LOG_DIR, principal, "active-queries");
|
|
187
|
+
const candidates = [join(dir, `${sanitizeId(topicId)}.json`)];
|
|
188
|
+
if (title && basename(title) === title && title !== "." && title !== "..") {
|
|
189
|
+
candidates.push(join(dir, `${title}.json`));
|
|
190
|
+
}
|
|
191
|
+
for (const path of candidates) {
|
|
192
|
+
const state = readJsonFile<QueryState>(path);
|
|
193
|
+
if (state && Date.now() - new Date(state.since).getTime() <= ACTIVE_QUERY_STALE_MS)
|
|
194
|
+
return state;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function normalizeMcp(enabled: readonly string[] | null | undefined): string[] | undefined {
|
|
200
|
+
if (enabled === undefined || enabled === null) return undefined;
|
|
201
|
+
const requested = [...new Set(enabled.map((name) => name.trim()).filter(Boolean))];
|
|
202
|
+
const invalid = requested.filter(
|
|
203
|
+
(name) =>
|
|
204
|
+
!OPTIONAL_FORUM_MCP_SERVERS.includes(name) && !REQUIRED_FORUM_MCP_SERVERS.includes(name),
|
|
205
|
+
);
|
|
206
|
+
if (invalid.length) throw new Error(`Unknown MCP server(s): ${invalid.join(", ")}`);
|
|
207
|
+
return requested.filter((name) => OPTIONAL_FORUM_MCP_SERVERS.includes(name));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function createDefaultSessionCommMcpHost(): SessionCommMcpHost {
|
|
211
|
+
return {
|
|
212
|
+
async listSessions(context) {
|
|
213
|
+
const identity = resolveSubagentTellIdentity(
|
|
214
|
+
context.currentTopicId,
|
|
215
|
+
context.subagentParentTopicId,
|
|
216
|
+
);
|
|
217
|
+
const entries = targetCatalog(context)
|
|
218
|
+
.listTargets()
|
|
219
|
+
.filter(
|
|
220
|
+
({ topic }) =>
|
|
221
|
+
!identity.restricted ||
|
|
222
|
+
Boolean(topic.topicId && canSubagentTellTarget(identity, topic.topicId)),
|
|
223
|
+
)
|
|
224
|
+
.filter(({ topic }) => Boolean(topic.agent))
|
|
225
|
+
.map(
|
|
226
|
+
({ key, topic }) =>
|
|
227
|
+
`- ${key}: ${topic.sessionId ? "active" : "fresh-start ready"}${topic.description ? `\n description: ${topic.description.slice(0, 80)}` : ""}`,
|
|
228
|
+
);
|
|
229
|
+
// Remote rooms are listed only where a remote call could be authorized
|
|
230
|
+
// for this turn (see `remoteSessionRoute`): through the hub with the
|
|
231
|
+
// turn's grant on Otium, through the peer bridge elsewhere, else not.
|
|
232
|
+
const route = identity.restricted ? null : remoteRoute(context);
|
|
233
|
+
if (route?.kind === "hub") {
|
|
234
|
+
const remote = await hubRemoteSessions(route.grant);
|
|
235
|
+
if (!remote.ok) {
|
|
236
|
+
entries.push(`- remote nodes: (${remote.error})`);
|
|
237
|
+
} else {
|
|
238
|
+
for (const node of remote.nodes) {
|
|
239
|
+
if (node.error) {
|
|
240
|
+
entries.push(`- ${node.node}/: (unreachable: ${node.error})`);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
for (const session of node.sessions ?? []) {
|
|
244
|
+
if (!session.agent) continue;
|
|
245
|
+
entries.push(
|
|
246
|
+
`- ${node.node}/${session.name}: ${session.status === "active" ? "active" : "fresh-start ready"}${session.description ? `\n description: ${session.description.slice(0, 80)}` : ""}`,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} else if (route?.kind === "peer") {
|
|
252
|
+
const peers = await peerSessionsForUser(
|
|
253
|
+
context.userId,
|
|
254
|
+
context.peerHostQueryId,
|
|
255
|
+
context.currentTopicId,
|
|
256
|
+
);
|
|
257
|
+
for (const node of peers.nodes ?? []) {
|
|
258
|
+
for (const session of node.sessions ?? []) {
|
|
259
|
+
if (session.agent)
|
|
260
|
+
entries.push(
|
|
261
|
+
`- ${node.node}/${session.name}: ${session.hasSession ? "active" : "fresh-start ready"}`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return ok(
|
|
267
|
+
`Current session: ${context.currentTopic}\nTell depth: ${context.depth}/${MAX_TELL_DEPTH}\n\nAvailable sessions:\n${entries.join("\n") || "none"}`,
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
configureMcp(context, enabled) {
|
|
272
|
+
const topic = currentTopic(context);
|
|
273
|
+
if (!topic) return error("Error: No current topic.");
|
|
274
|
+
if (topic.kind === "manager")
|
|
275
|
+
return error("Error: General does not use per-topic MCP settings.");
|
|
276
|
+
try {
|
|
277
|
+
const existing = getApiTopicConfig(topic.id) ?? {};
|
|
278
|
+
setApiTopicConfig(topic.id, { ...existing, mcp: normalizeMcp(enabled) });
|
|
279
|
+
return ok("MCP settings saved. Changes apply on the next user message.");
|
|
280
|
+
} catch (err) {
|
|
281
|
+
return error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
getMcpConfig(context) {
|
|
286
|
+
const topic = currentTopic(context);
|
|
287
|
+
if (!topic) return error("Error: No current topic.");
|
|
288
|
+
if (topic.kind === "manager") return ok("General uses the manager MCP bundle.");
|
|
289
|
+
return ok(JSON.stringify({ enabled: getApiTopicConfig(topic.id)?.mcp ?? [] }));
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
getBrowserProfile(context) {
|
|
293
|
+
const topic = currentTopic(context);
|
|
294
|
+
if (!topic) return error("Error: No current API topic.");
|
|
295
|
+
if (!isTopicBrowserProfileOwner(topic.id, context.userId)) {
|
|
296
|
+
return error("Error: Only the topic owner can inspect its browser profiles.");
|
|
297
|
+
}
|
|
298
|
+
const ownerId = getBrowserProfileOwner(topic.id, context.userId);
|
|
299
|
+
return ok(
|
|
300
|
+
JSON.stringify(
|
|
301
|
+
{ current: getTopicBrowserProfile(topic.id), profiles: listBrowserProfiles(ownerId) },
|
|
302
|
+
null,
|
|
303
|
+
2,
|
|
304
|
+
),
|
|
305
|
+
);
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
async setBrowserProfile(context, profile) {
|
|
309
|
+
const topic = currentTopic(context);
|
|
310
|
+
if (!topic) return error("Error: No current API topic.");
|
|
311
|
+
if (!isTopicBrowserProfileOwner(topic.id, context.userId)) {
|
|
312
|
+
return error("Error: Only the topic owner can change its browser profile.");
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
const result = assignTopicBrowserProfile({
|
|
316
|
+
topicId: topic.id,
|
|
317
|
+
actorUserId: context.userId,
|
|
318
|
+
profile,
|
|
319
|
+
});
|
|
320
|
+
if (result.previous !== result.profile) {
|
|
321
|
+
await closeBrowserOwnerTabs(context.userId, result.previous, `topic:${topic.id}`);
|
|
322
|
+
}
|
|
323
|
+
return ok(`Browser profile changed: ${result.previous} -> ${result.profile}.`);
|
|
324
|
+
} catch (err) {
|
|
325
|
+
return error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
async deleteBrowserProfile(context, profile) {
|
|
330
|
+
const topic = currentTopic(context);
|
|
331
|
+
if (!topic) return error("Error: No current API topic.");
|
|
332
|
+
if (!isTopicBrowserProfileOwner(topic.id, context.userId)) {
|
|
333
|
+
return error("Error: Only the topic owner can delete its browser profiles.");
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
const ownerId = getBrowserProfileOwner(topic.id, context.userId);
|
|
337
|
+
const result = await deleteManagedBrowserProfile(ownerId, profile);
|
|
338
|
+
return ok(JSON.stringify(result, null, 2));
|
|
339
|
+
} catch (err) {
|
|
340
|
+
return error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
async peekSession(context) {
|
|
345
|
+
const targets = targetCatalog(context).listTargets();
|
|
346
|
+
const running: string[] = [];
|
|
347
|
+
const idle: string[] = [];
|
|
348
|
+
for (const { key, topic } of targets) {
|
|
349
|
+
if (!topic.topicId) continue;
|
|
350
|
+
const state = activeQuery(context, topic.topicId, topic.name);
|
|
351
|
+
if (state)
|
|
352
|
+
running.push(
|
|
353
|
+
`${key} (${Math.round((Date.now() - new Date(state.since).getTime()) / 1000)}s)`,
|
|
354
|
+
);
|
|
355
|
+
else idle.push(key);
|
|
356
|
+
}
|
|
357
|
+
const pending = listPendingAsksForCaller({
|
|
358
|
+
userId: context.userId,
|
|
359
|
+
from: currentRef(context).key,
|
|
360
|
+
});
|
|
361
|
+
// Remote rooms (v1): the hub's own active/ready view, no elapsed time
|
|
362
|
+
// or task text — the hub does not fan out to every node for a peek.
|
|
363
|
+
const remoteLines: string[] = [];
|
|
364
|
+
const route = remoteRoute(context);
|
|
365
|
+
if (route.kind === "hub") {
|
|
366
|
+
const remote = await hubRemotePeek(route.grant);
|
|
367
|
+
if (!remote.ok) {
|
|
368
|
+
remoteLines.push(`Remote: (${remote.error})`);
|
|
369
|
+
} else {
|
|
370
|
+
const remoteRunning: string[] = [];
|
|
371
|
+
const remoteIdle: string[] = [];
|
|
372
|
+
for (const node of remote.nodes) {
|
|
373
|
+
if (node.error) {
|
|
374
|
+
remoteLines.push(`Remote ${node.node}: (unreachable: ${node.error})`);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
for (const session of node.sessions ?? []) {
|
|
378
|
+
// Same policy as the listing: a room with no AI is not a session.
|
|
379
|
+
if (session.agent === null) continue;
|
|
380
|
+
(session.status === "active" ? remoteRunning : remoteIdle).push(
|
|
381
|
+
`${node.node}/${session.name}`,
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
remoteLines.push(
|
|
386
|
+
`Remote running: ${remoteRunning.join(", ") || "none"}`,
|
|
387
|
+
`Remote idle: ${remoteIdle.join(", ") || "none"}`,
|
|
388
|
+
...remote.pendingAsks.map(
|
|
389
|
+
(ask) => `Pending ${ask.to}: ${ask.status} (${ask.requestId})`,
|
|
390
|
+
),
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return ok(
|
|
395
|
+
[
|
|
396
|
+
`Running: ${running.join(", ") || "none"}`,
|
|
397
|
+
`Idle: ${idle.join(", ") || "none"}`,
|
|
398
|
+
...pending.map(
|
|
399
|
+
(ask) => `Pending ${ask.to}: ${describePendingAskState(ask.state)} (${ask.requestId})`,
|
|
400
|
+
),
|
|
401
|
+
...remoteLines,
|
|
402
|
+
].join("\n"),
|
|
403
|
+
);
|
|
404
|
+
},
|
|
405
|
+
|
|
406
|
+
setDescription(context, description) {
|
|
407
|
+
const topic = currentTopic(context);
|
|
408
|
+
if (!topic) return error("Error: No current topic.");
|
|
409
|
+
upsertTopic({ ...topic, description });
|
|
410
|
+
return ok(`Description set for "${topic.title}".`);
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
async askSession(context, { to, message }) {
|
|
414
|
+
if (message.length > MAX_MESSAGE_LENGTH) return error("Error: message too long.");
|
|
415
|
+
const from = currentRef(context);
|
|
416
|
+
const remote = remoteTarget(context, to);
|
|
417
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
418
|
+
/*
|
|
419
|
+
* Every refusal — the route, the target, and above all the principal
|
|
420
|
+
* check — is decided before the pending-ask row exists (the stdio server
|
|
421
|
+
* does the same). The row is created only right before the entry is
|
|
422
|
+
* queued or sent, so a refused ask never leaves, or even briefly holds,
|
|
423
|
+
* a pending marker under the caller's principal for a room it may not
|
|
424
|
+
* reach.
|
|
425
|
+
*/
|
|
426
|
+
const createAsk = () =>
|
|
427
|
+
createPendingAsk({ userId: context.userId, from: from.key, to, requestId });
|
|
428
|
+
const alreadyPending = () =>
|
|
429
|
+
error(`Error: an ask_session request to "${to}" is already pending.`);
|
|
430
|
+
const clearAsk = () =>
|
|
431
|
+
clearPendingAsk({ userId: context.userId, from: from.key, to, requestId });
|
|
432
|
+
const releaseAsk = () =>
|
|
433
|
+
releasePendingAsk({ userId: context.userId, from: from.key, to, requestId });
|
|
434
|
+
if (remote) {
|
|
435
|
+
const route = remoteRoute(context);
|
|
436
|
+
if (route.kind === "refused") return error(route.error);
|
|
437
|
+
if (!from.topicId) return error("Error: current topic id is unavailable.");
|
|
438
|
+
if (route.kind === "hub") {
|
|
439
|
+
// Durable caller record first: the hub's `ask-reply` delivery is
|
|
440
|
+
// routed back through it, possibly after this process restarted.
|
|
441
|
+
// Row and pending marker are one state machine (see
|
|
442
|
+
// `RemoteSessionAskDispatchState`): the row never goes while its
|
|
443
|
+
// marker may remain, and a crash anywhere is reconciled later.
|
|
444
|
+
let begun: "ok" | "pending";
|
|
445
|
+
try {
|
|
446
|
+
begun = beginRemoteSessionAsk({
|
|
447
|
+
requestId,
|
|
448
|
+
callerTopicId: from.topicId,
|
|
449
|
+
userId: context.userId,
|
|
450
|
+
fromKey: from.key,
|
|
451
|
+
toKey: to,
|
|
452
|
+
...(context.currentThreadRootId
|
|
453
|
+
? { callerThreadRootId: context.currentThreadRootId }
|
|
454
|
+
: {}),
|
|
455
|
+
createMarker: () => createAsk().ok,
|
|
456
|
+
releaseMarker: releaseAsk,
|
|
457
|
+
});
|
|
458
|
+
} catch (err) {
|
|
459
|
+
logger.warn({ err, requestId, to }, "session-comm: could not record remote ask");
|
|
460
|
+
return error("Error: could not record the remote ask; nothing was sent.");
|
|
461
|
+
}
|
|
462
|
+
if (begun === "pending") return alreadyPending();
|
|
463
|
+
const sent = await hubRemoteAsk(route.grant, {
|
|
464
|
+
requestId,
|
|
465
|
+
to: remote,
|
|
466
|
+
message,
|
|
467
|
+
fromDepth: context.depth,
|
|
468
|
+
fromLabel: { key: from.key, title: from.title },
|
|
469
|
+
});
|
|
470
|
+
if (!sent.ok) {
|
|
471
|
+
if (sent.uncertain) {
|
|
472
|
+
// The hub may have forwarded it: the row stays `dispatched` so a
|
|
473
|
+
// late answer still lands; reconciliation turns it `unknown`
|
|
474
|
+
// (marker released) and the caller hears if none ever arrives.
|
|
475
|
+
return ok(
|
|
476
|
+
`Ask sent to "${to}" (delivery unconfirmed: ${sent.error}). request_id: ${requestId}`,
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
abandonRemoteSessionAsk(requestId, releaseAsk);
|
|
480
|
+
return error(`Error: ${sent.error}`);
|
|
481
|
+
}
|
|
482
|
+
markRemoteSessionAskSent(requestId);
|
|
483
|
+
return ok(`Ask sent to "${to}". request_id: ${requestId}`);
|
|
484
|
+
}
|
|
485
|
+
if (!createAsk().ok) return alreadyPending();
|
|
486
|
+
const result = await forwardToPeer({
|
|
487
|
+
action: "ask",
|
|
488
|
+
toNode: remote.node,
|
|
489
|
+
toTopic: remote.topic,
|
|
490
|
+
userId: context.userId,
|
|
491
|
+
fromKey: from.key,
|
|
492
|
+
fromTitle: from.title,
|
|
493
|
+
fromTopicId: from.topicId,
|
|
494
|
+
message,
|
|
495
|
+
requestId,
|
|
496
|
+
fromDepth: context.depth,
|
|
497
|
+
...(context.peerHostQueryId ? { sourceQueryId: context.peerHostQueryId } : {}),
|
|
498
|
+
});
|
|
499
|
+
if (!result.ok) {
|
|
500
|
+
clearAsk();
|
|
501
|
+
return error(`Error: ${result.error}`);
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
const validation = targetCatalog(context).validateTarget(to);
|
|
505
|
+
if (!validation.ok) return validation.error;
|
|
506
|
+
if (!validation.target.agent) return error(`Error: "${to}" has no AI agent.`);
|
|
507
|
+
const targetTopicId = validation.target.topicId;
|
|
508
|
+
if (!targetTopicId) return error(`Error: "${to}" has no topic id.`);
|
|
509
|
+
if (deliveryPrincipal(context, targetTopicId) !== context.userId) {
|
|
510
|
+
return error(crossPrincipalRefusal("ask_session", to));
|
|
511
|
+
}
|
|
512
|
+
if (!createAsk().ok) return alreadyPending();
|
|
513
|
+
try {
|
|
514
|
+
enqueueSessionInbox({
|
|
515
|
+
userId: context.userId,
|
|
516
|
+
topicId: targetTopicId,
|
|
517
|
+
entry: {
|
|
518
|
+
type: "ask",
|
|
519
|
+
requestId,
|
|
520
|
+
from: from.key,
|
|
521
|
+
fromTitle: from.title,
|
|
522
|
+
...(from.topicId ? { fromTopicId: from.topicId } : {}),
|
|
523
|
+
...(context.currentThreadRootId
|
|
524
|
+
? { fromThreadRootId: context.currentThreadRootId }
|
|
525
|
+
: {}),
|
|
526
|
+
message,
|
|
527
|
+
fromDepth: context.depth,
|
|
528
|
+
timestamp: new Date().toISOString(),
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
} catch (err) {
|
|
532
|
+
clearAsk();
|
|
533
|
+
throw err;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return ok(`Ask sent to "${to}". request_id: ${requestId}`);
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
askCron(context, message) {
|
|
540
|
+
if (message.length > MAX_MESSAGE_LENGTH) return error("Error: message too long.");
|
|
541
|
+
const topic = currentTopic(context);
|
|
542
|
+
if (!topic) return error("Error: 현재 토픽을 찾을 수 없습니다.");
|
|
543
|
+
if (!getRegisteredCronSession(topic.id, context.agent)) {
|
|
544
|
+
return error(
|
|
545
|
+
`Error: "${topic.title}" 토픽에 cron 세션이 없습니다. 크론 작업이 최소 한 번 실행되어야 합니다.`,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
const from = currentRef(context);
|
|
549
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
550
|
+
const pending = createPendingAsk({
|
|
551
|
+
userId: context.userId,
|
|
552
|
+
from: from.key,
|
|
553
|
+
to: topic.title,
|
|
554
|
+
requestId,
|
|
555
|
+
});
|
|
556
|
+
if (!pending.ok) {
|
|
557
|
+
return error(`Error: "${topic.title}"에 이미 진행 중인 요청이 있습니다.`);
|
|
558
|
+
}
|
|
559
|
+
try {
|
|
560
|
+
enqueueSessionInbox({
|
|
561
|
+
userId: context.userId,
|
|
562
|
+
topicId: topic.id,
|
|
563
|
+
entry: {
|
|
564
|
+
type: "ask",
|
|
565
|
+
target: "cron",
|
|
566
|
+
requestId,
|
|
567
|
+
from: from.key,
|
|
568
|
+
fromTitle: from.title,
|
|
569
|
+
fromTopicId: topic.id,
|
|
570
|
+
message,
|
|
571
|
+
fromDepth: context.depth,
|
|
572
|
+
timestamp: new Date().toISOString(),
|
|
573
|
+
},
|
|
574
|
+
});
|
|
575
|
+
} catch (err) {
|
|
576
|
+
clearPendingAsk({ userId: context.userId, from: from.key, to: topic.title, requestId });
|
|
577
|
+
logger.warn(
|
|
578
|
+
{ err, topicId: topic.id, requestId },
|
|
579
|
+
"session-comm: failed to enqueue cron ask",
|
|
580
|
+
);
|
|
581
|
+
return error("Error: cron 세션에 메시지를 전송하지 못했습니다.");
|
|
582
|
+
}
|
|
583
|
+
return ok(
|
|
584
|
+
`"${topic.title}:cron" 세션에 참조 요청을 보냈습니다.\n\nrequest_id: ${requestId}\n\n응답은 '[Reply from ${topic.title}:cron]' 형식으로 이 세션에 자동으로 돌아옵니다. 응답이 도착할 때까지 같은 요청으로 ask_cron을 재호출하지 마세요.`,
|
|
585
|
+
);
|
|
586
|
+
},
|
|
587
|
+
|
|
588
|
+
async abortSession(context, to) {
|
|
589
|
+
const remote = remoteTarget(context, to);
|
|
590
|
+
if (remote) {
|
|
591
|
+
const route = remoteRoute(context);
|
|
592
|
+
if (route.kind === "refused") return error(route.error);
|
|
593
|
+
if (route.kind === "hub") {
|
|
594
|
+
const sent = await hubRemoteAbort(route.grant, { requestId: newRequestId(), to: remote });
|
|
595
|
+
return sent.ok ? ok(`Abort sent to "${to}".`) : error(`Error: ${sent.error}`);
|
|
596
|
+
}
|
|
597
|
+
const result = await forwardToPeer({
|
|
598
|
+
action: "abort",
|
|
599
|
+
toNode: remote.node,
|
|
600
|
+
toTopic: remote.topic,
|
|
601
|
+
userId: context.userId,
|
|
602
|
+
...(context.peerHostQueryId ? { sourceQueryId: context.peerHostQueryId } : {}),
|
|
603
|
+
});
|
|
604
|
+
return result.ok ? ok(`Abort sent to "${to}".`) : error(`Error: ${result.error}`);
|
|
605
|
+
}
|
|
606
|
+
const validation = targetCatalog(context).validateTarget(to);
|
|
607
|
+
if (!validation.ok) return validation.error;
|
|
608
|
+
const targetTopicId = validation.target.topicId;
|
|
609
|
+
if (!targetTopicId) return error(`Error: "${to}" has no topic id.`);
|
|
610
|
+
if (targetTopicId === context.currentTopicId) return error("Error: cannot abort self.");
|
|
611
|
+
const refused = abortTargetRefusal({
|
|
612
|
+
surface: currentSurface(context),
|
|
613
|
+
currentTopicId: context.currentTopicId,
|
|
614
|
+
actorTopicScope: context.actorTopicScope,
|
|
615
|
+
targetTopicId,
|
|
616
|
+
to,
|
|
617
|
+
});
|
|
618
|
+
if (refused) return error(refused);
|
|
619
|
+
if (deliveryPrincipal(context, targetTopicId) !== context.userId) {
|
|
620
|
+
return error(crossPrincipalRefusal("abort_session", to));
|
|
621
|
+
}
|
|
622
|
+
enqueueSessionInbox({
|
|
623
|
+
userId: context.userId,
|
|
624
|
+
topicId: targetTopicId,
|
|
625
|
+
entry: {
|
|
626
|
+
type: "abort",
|
|
627
|
+
timestamp: new Date().toISOString(),
|
|
628
|
+
},
|
|
629
|
+
});
|
|
630
|
+
return ok(`Abort sent to "${to}".`);
|
|
631
|
+
},
|
|
632
|
+
|
|
633
|
+
async tellSession(context, { to, message }) {
|
|
634
|
+
if (message.length > MAX_MESSAGE_LENGTH) return error("Error: message too long.");
|
|
635
|
+
if (context.depth + 1 > MAX_TELL_DEPTH) return error("Error: depth limit reached.");
|
|
636
|
+
const from = currentRef(context);
|
|
637
|
+
const remote = remoteTarget(context, to);
|
|
638
|
+
if (remote) {
|
|
639
|
+
const route = remoteRoute(context);
|
|
640
|
+
if (route.kind === "refused") return error(route.error);
|
|
641
|
+
if (route.kind === "hub") {
|
|
642
|
+
const requestId = newRequestId();
|
|
643
|
+
const sent = await hubRemoteTell(route.grant, {
|
|
644
|
+
requestId,
|
|
645
|
+
to: remote,
|
|
646
|
+
message,
|
|
647
|
+
depth: context.depth + 1,
|
|
648
|
+
fromLabel: { key: from.key, title: from.title },
|
|
649
|
+
});
|
|
650
|
+
if (!sent.ok) {
|
|
651
|
+
// A timed-out response may still have been delivered; report it
|
|
652
|
+
// as sent-but-unconfirmed rather than invite a duplicate.
|
|
653
|
+
if (sent.uncertain) {
|
|
654
|
+
return ok(
|
|
655
|
+
`Message sent to "${to}" (delivery unconfirmed: ${sent.error}). request_id: ${requestId}`,
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
return error(`Error: ${sent.error}`);
|
|
659
|
+
}
|
|
660
|
+
return ok(`Message sent to "${to}". request_id: ${requestId}`);
|
|
661
|
+
}
|
|
662
|
+
const result = await forwardToPeer({
|
|
663
|
+
action: "tell",
|
|
664
|
+
toNode: remote.node,
|
|
665
|
+
toTopic: remote.topic,
|
|
666
|
+
userId: context.userId,
|
|
667
|
+
fromKey: from.key,
|
|
668
|
+
fromTitle: from.title,
|
|
669
|
+
fromTopicId: from.topicId,
|
|
670
|
+
message,
|
|
671
|
+
requestId: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
672
|
+
depth: context.depth + 1,
|
|
673
|
+
...(context.peerHostQueryId ? { sourceQueryId: context.peerHostQueryId } : {}),
|
|
674
|
+
});
|
|
675
|
+
return result.ok ? ok(`Message sent to "${to}".`) : error(`Error: ${result.error}`);
|
|
676
|
+
}
|
|
677
|
+
const validation = targetCatalog(context).validateTarget(to);
|
|
678
|
+
if (!validation.ok) return validation.error;
|
|
679
|
+
if (!validation.target.agent) return error(`Error: "${to}" has no AI agent.`);
|
|
680
|
+
const targetTopicId = validation.target.topicId;
|
|
681
|
+
if (!targetTopicId) return error(`Error: "${to}" has no topic id.`);
|
|
682
|
+
const identity = resolveSubagentTellIdentity(
|
|
683
|
+
context.currentTopicId,
|
|
684
|
+
context.subagentParentTopicId,
|
|
685
|
+
);
|
|
686
|
+
if (!canSubagentTellTarget(identity, targetTopicId)) {
|
|
687
|
+
return error("Error: subagent tell_session target is not permitted.");
|
|
688
|
+
}
|
|
689
|
+
if (deliveryPrincipal(context, targetTopicId) !== context.userId) {
|
|
690
|
+
return error(crossPrincipalRefusal("tell_session", to));
|
|
691
|
+
}
|
|
692
|
+
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
693
|
+
enqueueSessionInbox({
|
|
694
|
+
userId: context.userId,
|
|
695
|
+
topicId: targetTopicId,
|
|
696
|
+
entry: {
|
|
697
|
+
type: "tell",
|
|
698
|
+
requestId,
|
|
699
|
+
from: from.key,
|
|
700
|
+
fromTitle: from.title,
|
|
701
|
+
...(from.topicId ? { fromTopicId: from.topicId } : {}),
|
|
702
|
+
message,
|
|
703
|
+
depth: context.depth + 1,
|
|
704
|
+
timestamp: new Date().toISOString(),
|
|
705
|
+
},
|
|
706
|
+
});
|
|
707
|
+
return ok(`Message sent to "${to}". request_id: ${requestId}`);
|
|
708
|
+
},
|
|
709
|
+
|
|
710
|
+
sessionHistoryOf(context) {
|
|
711
|
+
return createSessionHistoryOfReader({
|
|
712
|
+
callerUserId: context.userId,
|
|
713
|
+
// A fresh catalog per lookup: the hub reach assertion is checked for
|
|
714
|
+
// freshness on every resolution, like every other session-comm tool.
|
|
715
|
+
validateTarget: (to) => targetCatalog(context).validateTarget(to),
|
|
716
|
+
subagentIdentity: resolveSubagentTellIdentity(
|
|
717
|
+
context.currentTopicId,
|
|
718
|
+
context.subagentParentTopicId,
|
|
719
|
+
),
|
|
720
|
+
});
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
}
|