@cortex-agent/server 2026.5.25 → 2026.6.15
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/defaults/config/thread-templates.json +28 -1
- package/defaults/hooks/cortex-md-injector.mjs +47 -31
- package/defaults/hooks/post-task-hook.mjs +6 -0
- package/defaults/hooks/task-status-check.mjs +8 -0
- package/defaults/mcp-config-slack.json +11 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
- package/defaults/prompts/directives/manager.md +67 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
- package/dist/agent-adapter/claude/adapter-tui.js +91 -12
- package/dist/agent-adapter/claude/adapter.js +11 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +30 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
- package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
- package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
- package/dist/agent-adapter/claude/spawn-args.js +49 -7
- package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
- package/dist/agent-adapter/claude/tmux-control.js +54 -8
- package/dist/agent-adapter/codex/adapter.js +1 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
- package/dist/agent-adapter/pi/adapter.js +46 -19
- package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
- package/dist/agent-adapter/pi/agent-dir.js +53 -2
- package/dist/agent-adapter/pi/event-parser.js +13 -1
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
- package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
- package/dist/agent-adapter/pi/tool-shims.js +167 -140
- package/dist/agent-adapter/types.d.ts +7 -2
- package/dist/core/atomic-write.js +21 -0
- package/dist/core/config-generator.d.ts +10 -0
- package/dist/core/config-generator.js +28 -0
- package/dist/core/gateway-generator.d.ts +77 -7
- package/dist/core/gateway-generator.js +323 -30
- package/dist/core/i18n.d.ts +19 -0
- package/dist/core/i18n.js +46 -0
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -0
- package/dist/core/locales/en.d.ts +438 -0
- package/dist/core/locales/en.js +24 -0
- package/dist/core/locales/slices/commands.d.ts +214 -0
- package/dist/core/locales/slices/commands.js +462 -0
- package/dist/core/locales/slices/init.d.ts +121 -0
- package/dist/core/locales/slices/init.js +380 -0
- package/dist/core/locales/slices/interactions.d.ts +47 -0
- package/dist/core/locales/slices/interactions.js +102 -0
- package/dist/core/locales/slices/lang.d.ts +8 -0
- package/dist/core/locales/slices/lang.js +18 -0
- package/dist/core/locales/slices/scheduling.d.ts +36 -0
- package/dist/core/locales/slices/scheduling.js +74 -0
- package/dist/core/locales/slices/startup.d.ts +6 -0
- package/dist/core/locales/slices/startup.js +14 -0
- package/dist/core/locales/slices/status.d.ts +20 -0
- package/dist/core/locales/slices/status.js +48 -0
- package/dist/core/locales/zh.d.ts +5 -0
- package/dist/core/locales/zh.js +23 -0
- package/dist/core/profile-generator.d.ts +6 -0
- package/dist/core/profile-generator.js +35 -7
- package/dist/core/running-executions.d.ts +51 -41
- package/dist/core/running-executions.js +120 -73
- package/dist/core/singleton-lock.d.ts +23 -0
- package/dist/core/singleton-lock.js +53 -0
- package/dist/core/status-format.js +4 -2
- package/dist/core/task-parser.d.ts +3 -0
- package/dist/core/task-parser.js +3 -1
- package/dist/core/types/thread-types.d.ts +54 -8
- package/dist/core/utils.d.ts +9 -1
- package/dist/core/utils.js +9 -1
- package/dist/domain/agents/config.d.ts +2 -1
- package/dist/domain/agents/config.js +25 -6
- package/dist/domain/agents/facade.d.ts +18 -0
- package/dist/domain/agents/facade.js +26 -3
- package/dist/domain/agents/profile-manager.d.ts +11 -0
- package/dist/domain/agents/profile-manager.js +21 -2
- package/dist/domain/costs/codex-usage-monitor.js +2 -1
- package/dist/domain/costs/rate-limit-throttle.js +14 -2
- package/dist/domain/executions/registry.d.ts +24 -0
- package/dist/domain/executions/registry.js +38 -0
- package/dist/domain/mcp/core-server.js +15 -3
- package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
- package/dist/domain/mcp/feishu/bitable.js +168 -0
- package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
- package/dist/domain/mcp/feishu/block-types.js +127 -0
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
- package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
- package/dist/domain/mcp/feishu/client.d.ts +46 -0
- package/dist/domain/mcp/feishu/client.js +87 -0
- package/dist/domain/mcp/feishu/docx.d.ts +3 -0
- package/dist/domain/mcp/feishu/docx.js +163 -0
- package/dist/domain/mcp/feishu/drive.d.ts +23 -0
- package/dist/domain/mcp/feishu/drive.js +66 -0
- package/dist/domain/mcp/feishu/file.d.ts +14 -0
- package/dist/domain/mcp/feishu/file.js +107 -0
- package/dist/domain/mcp/feishu/index.d.ts +6 -0
- package/dist/domain/mcp/feishu/index.js +61 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
- package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
- package/dist/domain/mcp/feishu/sheets.js +119 -0
- package/dist/domain/mcp/feishu/types.d.ts +26 -0
- package/dist/domain/mcp/feishu/types.js +38 -0
- package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
- package/dist/domain/mcp/feishu/user-auth.js +286 -0
- package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
- package/dist/domain/mcp/feishu/wiki.js +77 -0
- package/dist/domain/mcp/feishu-server.d.ts +2 -0
- package/dist/domain/mcp/feishu-server.js +33 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +6 -25
- package/dist/domain/mcp/slack-server.d.ts +3 -0
- package/dist/domain/mcp/slack-server.js +46 -0
- package/dist/domain/mcp/tools/context.js +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +1 -1
- package/dist/domain/mcp/tools/schedule.js +6 -20
- package/dist/domain/mcp/tools/slack.js +20 -7
- package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/thread-ops.js +121 -0
- package/dist/domain/mcp/tools/time.d.ts +2 -0
- package/dist/domain/mcp/tools/time.js +66 -0
- package/dist/domain/mcp/tools/tui-ask.js +1 -1
- package/dist/domain/mcp/tools/tui-plan.js +2 -2
- package/dist/domain/mcp/tui-server.js +1 -0
- package/dist/domain/monitor/disk-monitor.js +2 -1
- package/dist/domain/monitor/gpu-monitor.js +2 -1
- package/dist/domain/remote/client-hot-reload.js +3 -2
- package/dist/domain/remote/client-manager.js +8 -6
- package/dist/domain/scheduling/job-registry.d.ts +4 -0
- package/dist/domain/scheduling/job-registry.js +1 -0
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
- package/dist/domain/scheduling/jobs/sync-public.js +4 -3
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
- package/dist/domain/scheduling/jobs/task-archive.js +3 -2
- package/dist/domain/scheduling/jobs/task-dispatch.js +126 -20
- package/dist/domain/scheduling/schedule-command.js +45 -43
- package/dist/domain/scheduling/scheduler.d.ts +1 -1
- package/dist/domain/scheduling/scheduler.js +2 -1
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-hooks.js +19 -18
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
- package/dist/domain/sessions/session-lifecycle.js +44 -0
- package/dist/domain/system/github-release.d.ts +18 -0
- package/dist/domain/system/github-release.js +106 -0
- package/dist/domain/system/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/system/preferences.d.ts +12 -0
- package/dist/domain/system/preferences.js +36 -0
- package/dist/domain/system/server-update-check.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.d.ts +11 -2
- package/dist/domain/tasks/dispatcher.js +63 -7
- package/dist/domain/tasks/lint.js +28 -0
- package/dist/domain/tasks/mutator.d.ts +16 -3
- package/dist/domain/tasks/mutator.js +41 -12
- package/dist/domain/tasks/pending-tracker.js +6 -5
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
- package/dist/domain/tasks/system/task-mutations.js +166 -8
- package/dist/domain/threads/contract.d.ts +17 -0
- package/dist/domain/threads/contract.js +59 -0
- package/dist/domain/threads/hook-runner.js +7 -6
- package/dist/domain/threads/index.d.ts +2 -0
- package/dist/domain/threads/index.js +3 -1
- package/dist/domain/threads/prompt-builder.d.ts +21 -1
- package/dist/domain/threads/prompt-builder.js +60 -4
- package/dist/domain/threads/runner.d.ts +6 -5
- package/dist/domain/threads/runner.js +128 -79
- package/dist/domain/threads/state-machine.d.ts +23 -21
- package/dist/domain/threads/state-machine.js +113 -54
- package/dist/domain/threads/template-loader.js +3 -2
- package/dist/domain/threads/tree.d.ts +45 -0
- package/dist/domain/threads/tree.js +171 -0
- package/dist/domain/tui-session/index.d.ts +2 -0
- package/dist/domain/tui-session/index.js +3 -0
- package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
- package/dist/domain/tui-session/tui-session-service.js +103 -0
- package/dist/domain/tui-session/types.d.ts +67 -0
- package/dist/domain/tui-session/types.js +4 -0
- package/dist/domain/ui-service/index.d.ts +5 -0
- package/dist/domain/ui-service/index.js +3 -0
- package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
- package/dist/domain/ui-service/mutate/executions.js +15 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
- package/dist/domain/ui-service/mutate/schedules.js +39 -0
- package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
- package/dist/domain/ui-service/mutate/tasks.js +59 -0
- package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
- package/dist/domain/ui-service/mutate/threads.js +21 -0
- package/dist/domain/ui-service/query/cost.d.ts +3 -0
- package/dist/domain/ui-service/query/cost.js +6 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -0
- package/dist/domain/ui-service/query/executions.js +35 -0
- package/dist/domain/ui-service/query/projects.d.ts +2 -0
- package/dist/domain/ui-service/query/projects.js +30 -0
- package/dist/domain/ui-service/query/schedules.d.ts +2 -0
- package/dist/domain/ui-service/query/schedules.js +23 -0
- package/dist/domain/ui-service/query/sessions.d.ts +2 -0
- package/dist/domain/ui-service/query/sessions.js +35 -0
- package/dist/domain/ui-service/query/tasks.d.ts +2 -0
- package/dist/domain/ui-service/query/tasks.js +30 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -0
- package/dist/domain/ui-service/query/threads.js +27 -0
- package/dist/domain/ui-service/subscribe.d.ts +5 -0
- package/dist/domain/ui-service/subscribe.js +118 -0
- package/dist/domain/ui-service/types.d.ts +237 -0
- package/dist/domain/ui-service/types.js +5 -0
- package/dist/domain/ui-service/ui-service.d.ts +2 -0
- package/dist/domain/ui-service/ui-service.js +83 -0
- package/dist/entry/app.js +130 -8
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/daemon.js +12 -30
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +29 -5
- package/dist/entry/init.js +323 -233
- package/dist/entry/startup-notify.js +6 -3
- package/dist/events/event-types.d.ts +14 -0
- package/dist/hooks/cortex-md-injector.mjs +47 -31
- package/dist/hooks/post-task-hook.mjs +6 -0
- package/dist/hooks/task-status-check.mjs +8 -0
- package/dist/orchestration/agent-runner.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +55 -55
- package/dist/orchestration/conduit-queue.d.ts +18 -0
- package/dist/orchestration/conduit-queue.js +32 -0
- package/dist/orchestration/conversation-runner.d.ts +48 -0
- package/dist/orchestration/conversation-runner.js +109 -0
- package/dist/orchestration/dispatch-reconciler.js +8 -1
- package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
- package/dist/orchestration/interactions/ask-user-question.js +3 -3
- package/dist/orchestration/interactions/interaction-handlers.js +55 -23
- package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
- package/dist/orchestration/interactions/plan-handler.js +4 -3
- package/dist/orchestration/interactions/update-prompt-slack.js +11 -10
- package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +155 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +25 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +45 -52
- package/dist/orchestration/routing/commands/channel.js +41 -27
- package/dist/orchestration/routing/commands/cost.js +11 -2
- package/dist/orchestration/routing/commands/device.js +12 -9
- package/dist/orchestration/routing/commands/dispatch.js +11 -10
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +15 -10
- package/dist/orchestration/routing/commands/lang.d.ts +3 -0
- package/dist/orchestration/routing/commands/lang.js +31 -0
- package/dist/orchestration/routing/commands/mode.js +32 -30
- package/dist/orchestration/routing/commands/nvtop.js +15 -13
- package/dist/orchestration/routing/commands/orient.js +2 -1
- package/dist/orchestration/routing/commands/schedule.js +23 -22
- package/dist/orchestration/routing/commands/sendfile.js +9 -7
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +24 -39
- package/dist/orchestration/routing/commands/status.js +78 -71
- package/dist/orchestration/routing/commands/tail.js +7 -5
- package/dist/orchestration/routing/commands/task.js +25 -23
- package/dist/orchestration/routing/commands/thread-handlers.js +55 -44
- package/dist/orchestration/routing/edit-handler.js +8 -7
- package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
- package/dist/orchestration/routing/message-router.d.ts +1 -1
- package/dist/orchestration/routing/message-router.js +9 -9
- package/dist/orchestration/routing/webhook.js +233 -2
- package/dist/orchestration/status-helpers.d.ts +5 -1
- package/dist/orchestration/status-helpers.js +13 -11
- package/dist/orchestration/thread-callback.d.ts +67 -0
- package/dist/orchestration/thread-callback.js +465 -0
- package/dist/orchestration/thread-executor.d.ts +22 -1
- package/dist/orchestration/thread-executor.js +85 -36
- package/dist/platform/adapter.d.ts +6 -2
- package/dist/platform/adapters/composite-adapter.d.ts +89 -0
- package/dist/platform/adapters/composite-adapter.js +318 -0
- package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
- package/dist/platform/adapters/feishu-output-stream.js +274 -36
- package/dist/platform/adapters/feishu.d.ts +50 -5
- package/dist/platform/adapters/feishu.js +370 -116
- package/dist/platform/adapters/index.d.ts +24 -3
- package/dist/platform/adapters/index.js +89 -11
- package/dist/platform/adapters/project-conduits.d.ts +9 -0
- package/dist/platform/adapters/project-conduits.js +42 -0
- package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
- package/dist/platform/adapters/slack-project-conduits.js +6 -40
- package/dist/platform/adapters/slack.d.ts +9 -2
- package/dist/platform/adapters/slack.js +83 -39
- package/dist/platform/adapters/tui/index.d.ts +9 -0
- package/dist/platform/adapters/tui/index.js +10 -0
- package/dist/platform/adapters/tui/ports.d.ts +20 -0
- package/dist/platform/adapters/tui/ports.js +4 -0
- package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
- package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
- package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
- package/dist/platform/adapters/tui/tui-connection.js +53 -0
- package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
- package/dist/platform/adapters/tui/tui-gateway.js +919 -0
- package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
- package/dist/platform/adapters/tui/tui-notifications.js +60 -0
- package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
- package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
- package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
- package/dist/platform/adapters/tui/tui-transcript.js +56 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +2 -1
- package/dist/platform/interactive-builder.js +21 -19
- package/dist/platform/output-stream.d.ts +5 -0
- package/dist/platform/testing.d.ts +7 -11
- package/dist/platform/testing.js +18 -15
- package/dist/platform/tool-trace.js +15 -5
- package/dist/platform/tui/protocol.d.ts +355 -0
- package/dist/platform/tui/protocol.js +199 -0
- package/dist/platform/types.d.ts +12 -3
- package/dist/store/execution-repo.d.ts +6 -1
- package/dist/store/execution-repo.js +13 -3
- package/dist/store/hook-sync.d.ts +18 -0
- package/dist/store/hook-sync.js +92 -0
- package/dist/store/outbound-queue.js +2 -2
- package/dist/store/profile-repo.js +3 -2
- package/dist/store/schedule-repo.d.ts +1 -8
- package/dist/store/session-registry-repo.d.ts +9 -1
- package/dist/store/session-registry-repo.js +19 -3
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +23 -0
- package/dist/store/thread-repo.d.ts +3 -0
- package/dist/store/thread-repo.js +49 -2
- package/dist/store/version-migrations.d.ts +7 -0
- package/dist/store/version-migrations.js +183 -0
- package/dist/tui/App.d.ts +27 -0
- package/dist/tui/App.js +219 -0
- package/dist/tui/components/AskUserModal.d.ts +11 -0
- package/dist/tui/components/AskUserModal.js +364 -0
- package/dist/tui/components/ConfirmModal.d.ts +12 -0
- package/dist/tui/components/ConfirmModal.js +31 -0
- package/dist/tui/components/Dashboard.d.ts +23 -0
- package/dist/tui/components/Dashboard.js +80 -0
- package/dist/tui/components/DashboardCostTab.d.ts +7 -0
- package/dist/tui/components/DashboardCostTab.js +16 -0
- package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
- package/dist/tui/components/DashboardExecutionsTab.js +94 -0
- package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
- package/dist/tui/components/DashboardSchedulesTab.js +124 -0
- package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
- package/dist/tui/components/DashboardTasksTab.js +200 -0
- package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
- package/dist/tui/components/DashboardThreadsTab.js +81 -0
- package/dist/tui/components/Header.d.ts +11 -0
- package/dist/tui/components/Header.js +5 -0
- package/dist/tui/components/InputBox.d.ts +10 -0
- package/dist/tui/components/InputBox.js +19 -0
- package/dist/tui/components/MessageRow.d.ts +7 -0
- package/dist/tui/components/MessageRow.js +10 -0
- package/dist/tui/components/Notifications.d.ts +19 -0
- package/dist/tui/components/Notifications.js +72 -0
- package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
- package/dist/tui/components/PlanFeedbackModal.js +161 -0
- package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
- package/dist/tui/components/ProjectSwitcher.js +43 -0
- package/dist/tui/components/SessionPicker.d.ts +14 -0
- package/dist/tui/components/SessionPicker.js +34 -0
- package/dist/tui/components/SidePanel.d.ts +19 -0
- package/dist/tui/components/SidePanel.js +8 -0
- package/dist/tui/components/StatusLine.d.ts +10 -0
- package/dist/tui/components/StatusLine.js +29 -0
- package/dist/tui/components/Transcript.d.ts +13 -0
- package/dist/tui/components/Transcript.js +56 -0
- package/dist/tui/hooks/useDashboardData.d.ts +32 -0
- package/dist/tui/hooks/useDashboardData.js +104 -0
- package/dist/tui/hooks/useKeybindings.d.ts +19 -0
- package/dist/tui/hooks/useKeybindings.js +87 -0
- package/dist/tui/hooks/useMutate.d.ts +22 -0
- package/dist/tui/hooks/useMutate.js +56 -0
- package/dist/tui/hooks/useNotifications.d.ts +28 -0
- package/dist/tui/hooks/useNotifications.js +70 -0
- package/dist/tui/hooks/useTranscript.d.ts +39 -0
- package/dist/tui/hooks/useTranscript.js +265 -0
- package/dist/tui/hooks/useWsClient.d.ts +29 -0
- package/dist/tui/hooks/useWsClient.js +69 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +210 -0
- package/dist/tui/logic.d.ts +16 -0
- package/dist/tui/logic.js +49 -0
- package/dist/tui/render/markdown.d.ts +10 -0
- package/dist/tui/render/markdown.js +38 -0
- package/dist/tui/render/rich-blocks.d.ts +11 -0
- package/dist/tui/render/rich-blocks.js +24 -0
- package/dist/tui/ws-client.d.ts +44 -0
- package/dist/tui/ws-client.js +157 -0
- package/package.json +11 -3
- package/dist/orchestration/channel-queue.d.ts +0 -18
- package/dist/orchestration/channel-queue.js +0 -32
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// input: domain/threads, thread-runner, orch/channel-queue, orch/busy-tracker
|
|
2
|
-
// output: ThreadExecutor — handles thread-add / thread-continue / thread-start sub-paths [S8]
|
|
3
|
-
//
|
|
2
|
+
// output: ThreadExecutor — handles thread-add / thread-continue / thread-start sub-paths [S8];
|
|
3
|
+
// runThreadDetached — fire-and-forget run that holds the busy gate for the whole pipeline
|
|
4
|
+
// pos: orch/ — sole thread-routing execution path; runThreadDetached is the MCP thread_start path
|
|
4
5
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
-
import {
|
|
6
|
+
import { createLogger } from '../core/log.js';
|
|
7
|
+
import { Icons } from '../core/icons.js';
|
|
8
|
+
import { conduitQueues, enqueue } from './conduit-queue.js';
|
|
6
9
|
import { trackPendingTask } from './busy-tracker.js';
|
|
7
10
|
import { addAgentToThread, createThread, getTemplate, getAgent } from '../domain/threads/index.js';
|
|
8
11
|
import { runThread, continueThread, buildThreadSummary, getActiveHandle } from '../domain/threads/runner.js';
|
|
@@ -12,6 +15,43 @@ import { threadStore } from '../store/thread-repo.js';
|
|
|
12
15
|
import { WORKSPACE_DIR } from '../core/utils.js';
|
|
13
16
|
import { buildInteractiveCallbacks } from './agent-runner.js';
|
|
14
17
|
const TEMP_DIR = WORKSPACE_DIR;
|
|
18
|
+
const log = createLogger('thread-executor');
|
|
19
|
+
/** Run a thread fire-and-forget while holding the daemon busy gate for the ENTIRE pipeline.
|
|
20
|
+
* The Slack `!thread` path (ThreadExecutor.route), the scheduled-task path, and the task-dispatch
|
|
21
|
+
* path all bracket runThread with trackPendingTask(±1). The MCP `thread_start` webhook path did
|
|
22
|
+
* not — so a background thread was invisible to the busy/idle gate, and a deploy/restart deferred
|
|
23
|
+
* during the orchestrating session's turn would fire on the next idle and SIGTERM app.ts
|
|
24
|
+
* mid-thread, stamping it "Interrupted by server restart". This helper closes that gap.
|
|
25
|
+
*
|
|
26
|
+
* track(+1) is synchronous so the daemon observes `busy` before it can act on any idle. The gate
|
|
27
|
+
* is held across BOTH the run AND the onSettled callback: onSettled (the MCP completion callback)
|
|
28
|
+
* may wake the parent agent for a full LLM turn, and `track(-1)` synchronously emits IPC `idle`.
|
|
29
|
+
* If we released the gate before awaiting onSettled, a deferred restart would fire mid-callback and
|
|
30
|
+
* SIGTERM app.ts, dropping the proactive completion notification. So we await onSettled first, then
|
|
31
|
+
* release. track(-1) lives in an inner `finally` so the gate never leaks. The thread runs detached:
|
|
32
|
+
* errors are logged (the caller already returned the threadId to the MCP client, which polls
|
|
33
|
+
* thread_status). `deps` is injectable for unit tests. */
|
|
34
|
+
export function runThreadDetached(threadId, runOpts, deps = {}) {
|
|
35
|
+
const run = deps.run ?? runThread;
|
|
36
|
+
const track = deps.track ?? trackPendingTask;
|
|
37
|
+
track(+1);
|
|
38
|
+
run(threadId, runOpts)
|
|
39
|
+
.catch((e) => log.error(`detached thread ${threadId} failed: ${e.message}`))
|
|
40
|
+
.finally(async () => {
|
|
41
|
+
// Hold the busy gate across the settle callback (which may wake the parent agent for a full
|
|
42
|
+
// turn) so the daemon doesn't observe idle — and fire a deferred restart — mid-callback.
|
|
43
|
+
// track(-1) still always runs in the inner finally, so the gate never leaks.
|
|
44
|
+
try {
|
|
45
|
+
await deps.onSettled?.(threadId);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
log.error(`detached thread ${threadId} onSettled error: ${e.message}`);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
track(-1);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
15
55
|
export class ThreadExecutor {
|
|
16
56
|
_enqueue;
|
|
17
57
|
_track;
|
|
@@ -26,13 +66,19 @@ export class ThreadExecutor {
|
|
|
26
66
|
const { message, channel, adapter } = ctx;
|
|
27
67
|
// Phase 6: buffer user messages when the thread is running a step,
|
|
28
68
|
// so they're included in the next step's prompt instead of being lost.
|
|
29
|
-
|
|
69
|
+
// DR-0014: also buffer for a parent suspended on child threads — routing such a
|
|
70
|
+
// message through handleThreadContinue would prematurely wake the parent AND
|
|
71
|
+
// overwrite its userMessage (the delegation contract).
|
|
72
|
+
const suspendedOnChildren = ctx.existingThread?.status === 'waiting'
|
|
73
|
+
&& !!ctx.existingThread?.metadata?.waitingOn?.length;
|
|
74
|
+
if (ctx.isActiveThread && ctx.existingThread
|
|
75
|
+
&& (ctx.existingThread.status === 'running' || suspendedOnChildren)
|
|
30
76
|
&& !ctx.threadAddMatch && !ctx.threadStartMatch) {
|
|
31
77
|
await bufferUserMessage(ctx);
|
|
32
78
|
return;
|
|
33
79
|
}
|
|
34
|
-
if (
|
|
35
|
-
await adapter.
|
|
80
|
+
if (conduitQueues.has(channel)) {
|
|
81
|
+
await adapter.markQueued({ conduit: channel, messageId: message.ref.messageId }).catch(() => { });
|
|
36
82
|
}
|
|
37
83
|
this._track(+1);
|
|
38
84
|
this._enqueue(channel, async () => {
|
|
@@ -52,13 +98,13 @@ export class ThreadExecutor {
|
|
|
52
98
|
const downloadedFiles = await downloadFiles(ctx.message.files, ctx.hasFiles, ctx.adapter);
|
|
53
99
|
try {
|
|
54
100
|
if (ctx.threadAddMatch) {
|
|
55
|
-
statusMsg = await handleThreadAdd({ threadAddMatch: ctx.threadAddMatch, existingThread: ctx.existingThread, channel, adapter,
|
|
101
|
+
statusMsg = await handleThreadAdd({ threadAddMatch: ctx.threadAddMatch, existingThread: ctx.existingThread, channel, adapter, threadAnchorId: ctx.threadAnchorId, startTime, downloadedFiles }) || undefined;
|
|
56
102
|
}
|
|
57
103
|
else if (ctx.isActiveThread && ctx.existingThread) {
|
|
58
|
-
statusMsg = await handleThreadContinue({ existingThread: ctx.existingThread, agentMessage: ctx.agentMessage, channel, adapter,
|
|
104
|
+
statusMsg = await handleThreadContinue({ existingThread: ctx.existingThread, agentMessage: ctx.agentMessage, channel, adapter, threadAnchorId: ctx.threadAnchorId, startTime, downloadedFiles });
|
|
59
105
|
}
|
|
60
106
|
else if (ctx.threadStartMatch) {
|
|
61
|
-
statusMsg = await handleThreadStart({ threadStartMatch: ctx.threadStartMatch, messageId: ctx.message.ref.messageId, channel, adapter,
|
|
107
|
+
statusMsg = await handleThreadStart({ threadStartMatch: ctx.threadStartMatch, messageId: ctx.message.ref.messageId, channel, adapter, threadAnchorId: ctx.threadAnchorId, startTime, downloadedFiles }) || undefined;
|
|
62
108
|
}
|
|
63
109
|
}
|
|
64
110
|
catch (error) {
|
|
@@ -67,27 +113,27 @@ export class ThreadExecutor {
|
|
|
67
113
|
const errorBlocksTemplate = { channel, sessionName: null, isDm: false };
|
|
68
114
|
if (isCancelled) {
|
|
69
115
|
if (statusMsg) {
|
|
70
|
-
const cancelText =
|
|
116
|
+
const cancelText = `${Icons.stopped} Cancelled (${elapsedStr})`;
|
|
71
117
|
await adapter.updateMessage(statusMsg, {
|
|
72
118
|
text: cancelText,
|
|
73
119
|
richBlocks: buildSealedStatusActionBlocks(cancelText, errorBlocksTemplate),
|
|
74
120
|
}).catch(() => { });
|
|
75
121
|
}
|
|
76
122
|
else {
|
|
77
|
-
await adapter.postMessage(interactiveDest, { text:
|
|
123
|
+
await adapter.postMessage(interactiveDest, { text: `${Icons.stopped} Cancelled` }, ctx.threadAnchorId ? { threadId: ctx.threadAnchorId } : undefined).catch(() => { });
|
|
78
124
|
}
|
|
79
125
|
}
|
|
80
126
|
else {
|
|
81
127
|
const errorMsg = error?.message || 'Unknown error';
|
|
82
128
|
if (statusMsg) {
|
|
83
|
-
const failText =
|
|
129
|
+
const failText = `${Icons.error} Thread failed (${elapsedStr}): ${errorMsg}`;
|
|
84
130
|
await adapter.updateMessage(statusMsg, {
|
|
85
131
|
text: failText,
|
|
86
132
|
richBlocks: buildSealedStatusActionBlocks(failText, errorBlocksTemplate),
|
|
87
133
|
}).catch(() => { });
|
|
88
134
|
}
|
|
89
135
|
else {
|
|
90
|
-
await adapter.postMessage(interactiveDest, { text:
|
|
136
|
+
await adapter.postMessage(interactiveDest, { text: `${Icons.error} Thread failed: ${errorMsg}` }, ctx.threadAnchorId ? { threadId: ctx.threadAnchorId } : undefined).catch(() => { });
|
|
91
137
|
}
|
|
92
138
|
}
|
|
93
139
|
}
|
|
@@ -95,17 +141,17 @@ export class ThreadExecutor {
|
|
|
95
141
|
}
|
|
96
142
|
export const threadExecutor = new ThreadExecutor();
|
|
97
143
|
// --- Thread sub-handlers ---
|
|
98
|
-
async function handleThreadAdd({ threadAddMatch, existingThread, channel, adapter,
|
|
144
|
+
async function handleThreadAdd({ threadAddMatch, existingThread, channel, adapter, threadAnchorId, startTime, downloadedFiles }) {
|
|
99
145
|
const interactiveDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
100
146
|
const addAgentName = threadAddMatch[1];
|
|
101
147
|
const addMessage = threadAddMatch[2]?.trim() || null;
|
|
102
|
-
const targetThread = await validateThreadAddTarget(addAgentName, existingThread, channel, adapter,
|
|
148
|
+
const targetThread = await validateThreadAddTarget(addAgentName, existingThread, channel, adapter, threadAnchorId);
|
|
103
149
|
if (!targetThread)
|
|
104
150
|
return null;
|
|
105
151
|
await addAgentToThread(targetThread.id, addAgentName, addMessage);
|
|
106
|
-
const platformThreadId = targetThread.platformThreadId ||
|
|
152
|
+
const platformThreadId = targetThread.platformThreadId || threadAnchorId;
|
|
107
153
|
const threadBlocksTemplate = { channel, sessionName: null, isDm: false, threadId: targetThread.id };
|
|
108
|
-
const addText =
|
|
154
|
+
const addText = `${Icons.add} Adding *${addAgentName}* to thread ${targetThread.id.substring(0, 12)}...`;
|
|
109
155
|
const statusMsg = await adapter.postMessage(interactiveDest, {
|
|
110
156
|
text: addText,
|
|
111
157
|
richBlocks: buildStatusActionBlocks(addText, threadBlocksTemplate),
|
|
@@ -113,7 +159,7 @@ async function handleThreadAdd({ threadAddMatch, existingThread, channel, adapte
|
|
|
113
159
|
initStatusBlocks(statusMsg, threadBlocksTemplate);
|
|
114
160
|
const interactiveCallbacks = buildInteractiveCallbacks(channel, null);
|
|
115
161
|
const threadResult = await runThread(targetThread.id, {
|
|
116
|
-
adapter, channel,
|
|
162
|
+
adapter, channel, threadAnchorId: platformThreadId, statusMsg, startTime, files: downloadedFiles,
|
|
117
163
|
destination: interactiveDest,
|
|
118
164
|
onToolUse: interactiveCallbacks.onToolUse, onPlanWritten: interactiveCallbacks.onPlanWritten, onAskUserQuestion: interactiveCallbacks.onAskUserQuestion,
|
|
119
165
|
});
|
|
@@ -124,35 +170,38 @@ async function handleThreadAdd({ threadAddMatch, existingThread, channel, adapte
|
|
|
124
170
|
});
|
|
125
171
|
return statusMsg;
|
|
126
172
|
}
|
|
127
|
-
async function validateThreadAddTarget(addAgentName, existingThread, channel, adapter,
|
|
173
|
+
async function validateThreadAddTarget(addAgentName, existingThread, channel, adapter, threadAnchorId) {
|
|
128
174
|
const interactiveDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
129
175
|
if (!getAgent(addAgentName)) {
|
|
130
|
-
await adapter.postMessage(interactiveDest, { text:
|
|
176
|
+
await adapter.postMessage(interactiveDest, { text: `${Icons.error} Unknown agent: \`${addAgentName}\`. Use \`!thread agents\` to see available agents.` }, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
131
177
|
return null;
|
|
132
178
|
}
|
|
133
|
-
|
|
179
|
+
// Plain user conversations are no longer wrapped in a thread (templateName='default'), so they
|
|
180
|
+
// cannot be chained off. Exclude any legacy 'default' threads still present in the store — the
|
|
181
|
+
// user must start an explicit thread with `!thread <agent> <message>` to use `!thread add`.
|
|
182
|
+
const targetThread = existingThread || threadStore.findByChannel(channel).find((t) => (t.status === 'completed' || t.status === 'waiting') && t.templateName !== 'default');
|
|
134
183
|
if (!targetThread) {
|
|
135
|
-
await adapter.postMessage(interactiveDest, { text:
|
|
184
|
+
await adapter.postMessage(interactiveDest, { text: `${Icons.error} No thread found. Start one first with \`!thread <agent> <message>\`.` }, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
136
185
|
return null;
|
|
137
186
|
}
|
|
138
187
|
if (targetThread.status === 'running' && getActiveHandle(channel)) {
|
|
139
|
-
await adapter.postMessage(interactiveDest, { text:
|
|
188
|
+
await adapter.postMessage(interactiveDest, { text: `${Icons.warning} Thread ${targetThread.id.substring(0, 12)} is currently running. Wait for it to finish.` }, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
140
189
|
return null;
|
|
141
190
|
}
|
|
142
191
|
return targetThread;
|
|
143
192
|
}
|
|
144
|
-
async function handleThreadContinue({ existingThread, agentMessage, channel, adapter,
|
|
193
|
+
async function handleThreadContinue({ existingThread, agentMessage, channel, adapter, threadAnchorId, startTime, downloadedFiles }) {
|
|
145
194
|
const interactiveDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
146
195
|
const continueBlocksTemplate = { channel, sessionName: null, isDm: false, threadId: existingThread.id };
|
|
147
|
-
const continueText =
|
|
196
|
+
const continueText = `${Icons.processing} Continuing thread ${existingThread.id.substring(0, 12)}...`;
|
|
148
197
|
const statusMsg = await adapter.postMessage(interactiveDest, {
|
|
149
198
|
text: continueText,
|
|
150
199
|
richBlocks: buildStatusActionBlocks(continueText, continueBlocksTemplate),
|
|
151
|
-
},
|
|
200
|
+
}, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
152
201
|
initStatusBlocks(statusMsg, continueBlocksTemplate);
|
|
153
202
|
const interactiveCallbacks = buildInteractiveCallbacks(channel, null);
|
|
154
203
|
const threadResult = await continueThread(existingThread.id, agentMessage, {
|
|
155
|
-
adapter, channel,
|
|
204
|
+
adapter, channel, threadAnchorId, statusMsg, startTime, files: downloadedFiles,
|
|
156
205
|
destination: interactiveDest,
|
|
157
206
|
onToolUse: interactiveCallbacks.onToolUse, onPlanWritten: interactiveCallbacks.onPlanWritten, onAskUserQuestion: interactiveCallbacks.onAskUserQuestion,
|
|
158
207
|
});
|
|
@@ -163,22 +212,22 @@ async function handleThreadContinue({ existingThread, agentMessage, channel, ada
|
|
|
163
212
|
});
|
|
164
213
|
return statusMsg;
|
|
165
214
|
}
|
|
166
|
-
async function handleThreadStart({ threadStartMatch, messageId, channel, adapter,
|
|
215
|
+
async function handleThreadStart({ threadStartMatch, messageId, channel, adapter, threadAnchorId, startTime, downloadedFiles }) {
|
|
167
216
|
const interactiveDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
168
217
|
const name = threadStartMatch[1];
|
|
169
218
|
const template = getTemplate(name);
|
|
170
219
|
const agent = getAgent(name);
|
|
171
220
|
if (!template && !agent) {
|
|
172
|
-
await adapter.postMessage(interactiveDest, { text:
|
|
221
|
+
await adapter.postMessage(interactiveDest, { text: `${Icons.error} Unknown template or agent: \`${name}\`. Use \`!thread templates\` or \`!thread agents\`.` });
|
|
173
222
|
return null;
|
|
174
223
|
}
|
|
175
224
|
const startBlocksTemplate = { channel, sessionName: null, isDm: false };
|
|
176
|
-
const startText =
|
|
225
|
+
const startText = `${Icons.processing} Starting thread (${template ? name : `agent:${name}`})...`;
|
|
177
226
|
const statusMsg = await adapter.postMessage(interactiveDest, {
|
|
178
227
|
text: startText,
|
|
179
228
|
// No Cancel button initially — threadId needed first
|
|
180
|
-
},
|
|
181
|
-
const platformThreadId =
|
|
229
|
+
}, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
230
|
+
const platformThreadId = threadAnchorId || statusMsg.messageId;
|
|
182
231
|
const thread = createThread(channel, {
|
|
183
232
|
templateName: template ? name : null, agentName: template ? null : name,
|
|
184
233
|
userMessage: threadStartMatch[2].trim(), userMessageTs: messageId, platformThreadId,
|
|
@@ -192,7 +241,7 @@ async function handleThreadStart({ threadStartMatch, messageId, channel, adapter
|
|
|
192
241
|
initStatusBlocks(statusMsg, startBlocksTemplateWithThread);
|
|
193
242
|
const interactiveCallbacks = buildInteractiveCallbacks(channel, null);
|
|
194
243
|
const threadResult = await runThread(thread.id, {
|
|
195
|
-
adapter, channel,
|
|
244
|
+
adapter, channel, threadAnchorId: platformThreadId, statusMsg, startTime, files: downloadedFiles,
|
|
196
245
|
destination: interactiveDest,
|
|
197
246
|
onToolUse: interactiveCallbacks.onToolUse, onPlanWritten: interactiveCallbacks.onPlanWritten, onAskUserQuestion: interactiveCallbacks.onAskUserQuestion,
|
|
198
247
|
});
|
|
@@ -208,7 +257,7 @@ async function handleThreadStart({ threadStartMatch, messageId, channel, adapter
|
|
|
208
257
|
* in the next step's prompt. Used when a step is currently executing
|
|
209
258
|
* and we can't safely call continueThread + runThread concurrently. */
|
|
210
259
|
async function bufferUserMessage(ctx) {
|
|
211
|
-
const { adapter, channel,
|
|
260
|
+
const { adapter, channel, threadAnchorId } = ctx;
|
|
212
261
|
const interactiveDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
213
262
|
const thread = ctx.existingThread;
|
|
214
263
|
const text = ctx.agentMessage || ctx.message.text || '';
|
|
@@ -232,8 +281,8 @@ async function bufferUserMessage(ctx) {
|
|
|
232
281
|
// the next conventional mutate() call on this thread.
|
|
233
282
|
threadStore.set(thread).catch(() => { });
|
|
234
283
|
await adapter.postMessage(interactiveDest, {
|
|
235
|
-
text:
|
|
236
|
-
},
|
|
284
|
+
text: `${Icons.inbox} Message buffered — will be included in the next step’s prompt`,
|
|
285
|
+
}, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
237
286
|
}
|
|
238
287
|
// --- Shared helper ---
|
|
239
288
|
async function downloadFiles(files, hasFiles, adapter) {
|
|
@@ -16,11 +16,10 @@ export interface PlatformAdapter {
|
|
|
16
16
|
actions: ActionElement[];
|
|
17
17
|
}, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
18
18
|
openModal(triggerId: string, modal: ModalDefinition): Promise<void>;
|
|
19
|
-
|
|
19
|
+
markQueued(ref: MessageRef): Promise<void>;
|
|
20
20
|
uploadFile(destination: Destination, filePath: string, opts?: FileUploadOpts): Promise<void>;
|
|
21
21
|
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
22
22
|
getPermalink(ref: MessageRef): Promise<string | null>;
|
|
23
|
-
postEphemeral(channel: string, userId: string, text: string): Promise<void>;
|
|
24
23
|
/** Open a new OutputStream for streaming agent output to the given destination. */
|
|
25
24
|
openOutputStream(destination: Destination, opts?: OpenOutputStreamOpts): OutputStream;
|
|
26
25
|
/** Register a conduit (channel/chat) for project-report destinations. */
|
|
@@ -33,4 +32,9 @@ export interface PlatformAdapter {
|
|
|
33
32
|
* the project it is currently bound to, or null if unbound. Used by the
|
|
34
33
|
* orchestration layer to attach inbound messages to their project. */
|
|
35
34
|
resolveInboundProject(conduit: string): Promise<string | null>;
|
|
35
|
+
/** True if the given (prefixed) conduit belongs to this adapter. Used by
|
|
36
|
+
* CompositeAdapter to route outbound operations to the right sub-adapter when
|
|
37
|
+
* multiple platforms are online simultaneously. Each adapter owns a conduit
|
|
38
|
+
* namespace by prefix: Slack `slack:`, Feishu `feishu:`, TUI `tui-`/`tui:`. */
|
|
39
|
+
ownsConduit(conduit: string): boolean;
|
|
36
40
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../adapter.js';
|
|
2
|
+
import type { MessageRef, MessageContent, MessageContext, MessageEditContext, ActionContext, ModalSubmitContext, ModalDefinition, PlatformCapabilities, PlatformFileRef, DownloadedFile, Destination, PostMessageOpts, FileUploadOpts, ActionElement, RichBlock } from '../types.js';
|
|
3
|
+
import type { OutputStream, MutableRegion, OpenOutputStreamOpts } from '../output-stream.js';
|
|
4
|
+
import { TuiGatewayAdapter } from './tui/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* OutputStream that broadcasts all operations to an array of sub-streams.
|
|
7
|
+
* Used by CompositeAdapter for project-report destinations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class FanOutOutputStream implements OutputStream {
|
|
10
|
+
private _subs;
|
|
11
|
+
constructor(subs: OutputStream[]);
|
|
12
|
+
emitText(text: string): void;
|
|
13
|
+
openMutable(text: string): MutableRegion;
|
|
14
|
+
postInteractive(text: string, opts?: {
|
|
15
|
+
richBlocks?: RichBlock[];
|
|
16
|
+
actions?: ActionElement[];
|
|
17
|
+
}): Promise<MessageRef | null>;
|
|
18
|
+
flush(): Promise<void>;
|
|
19
|
+
getRefs(): MessageRef[];
|
|
20
|
+
getParentRef(): MessageRef | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Combines N sub-adapters (e.g. Slack + Feishu + TUI) behind a single
|
|
24
|
+
* PlatformAdapter surface. Outbound operations route to the owning sub-adapter
|
|
25
|
+
* by conduit prefix (`adapter.ownsConduit(conduit)`); inbound handlers are
|
|
26
|
+
* registered on every sub-adapter; system-notice and project-report fan out.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CompositeAdapter implements PlatformAdapter {
|
|
29
|
+
readonly name = "composite";
|
|
30
|
+
readonly capabilities: PlatformCapabilities;
|
|
31
|
+
private _adapters;
|
|
32
|
+
/** Cached TUI gateway reference (if any) for setBus / extractTuiAdapter. */
|
|
33
|
+
private _tui;
|
|
34
|
+
constructor(adapters: PlatformAdapter[]);
|
|
35
|
+
start(): Promise<void>;
|
|
36
|
+
stop(): Promise<void>;
|
|
37
|
+
onMessage(handler: (ctx: MessageContext) => Promise<void>): void;
|
|
38
|
+
onMessageEdit(handler: (ctx: MessageEditContext) => Promise<void>): void;
|
|
39
|
+
onAction(actionId: string, handler: (ctx: ActionContext) => Promise<void>): void;
|
|
40
|
+
onModalSubmit(callbackId: string, handler: (ctx: ModalSubmitContext) => Promise<void>): void;
|
|
41
|
+
/** Route a conduit to its owning sub-adapter (falls back to the first). */
|
|
42
|
+
private _adapterForConduit;
|
|
43
|
+
private _adapterForRef;
|
|
44
|
+
/** Route a triggerId (same prefix namespace as conduits) to its adapter. */
|
|
45
|
+
private _adapterForTrigger;
|
|
46
|
+
/** Return sub-adapter(s) for a destination (single-target types only).
|
|
47
|
+
* system-notice fans out to every real primary (each drops if its own admin
|
|
48
|
+
* channel is unconfigured) but NOT the TUI gateway, which has no admin
|
|
49
|
+
* channel concept. With a single primary this is just `[primary]`. */
|
|
50
|
+
private _adaptersForDest;
|
|
51
|
+
/** Resolve which sub-adapters should receive a project-report.
|
|
52
|
+
* Real primaries (Slack/Feishu) are ALWAYS targeted: each self-resolves to
|
|
53
|
+
* the bound conduit, or falls back to its own admin DM, or drops internally
|
|
54
|
+
* when neither exists. This makes every platform independently fall back to
|
|
55
|
+
* its DM for projects it has no binding for. The TUI gateway has no admin-DM
|
|
56
|
+
* concept, so it is targeted only when it has at least one live conduit (for
|
|
57
|
+
* cross-project notification fan-out). */
|
|
58
|
+
private _getTargetAdaptersForProjectReport;
|
|
59
|
+
postMessage(destination: Destination, content: MessageContent, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
60
|
+
updateMessage(ref: MessageRef, content: MessageContent): Promise<void>;
|
|
61
|
+
deleteMessage(ref: MessageRef): Promise<void>;
|
|
62
|
+
postInteractive(destination: Destination, content: MessageContent & {
|
|
63
|
+
actions: ActionElement[];
|
|
64
|
+
}, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
65
|
+
openModal(triggerId: string, modal: ModalDefinition): Promise<void>;
|
|
66
|
+
markQueued(ref: MessageRef): Promise<void>;
|
|
67
|
+
uploadFile(destination: Destination, filePath: string, opts?: FileUploadOpts): Promise<void>;
|
|
68
|
+
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
69
|
+
getPermalink(ref: MessageRef): Promise<string | null>;
|
|
70
|
+
openOutputStream(destination: Destination, opts?: OpenOutputStreamOpts): OutputStream;
|
|
71
|
+
/** Resolve the thread anchor messageId for one sub-adapter from the composite anchor.
|
|
72
|
+
* - anchorRef.parts present → the part owned by this adapter (else null → self-anchor).
|
|
73
|
+
* - anchorRef without parts → its messageId only if this adapter owns its conduit.
|
|
74
|
+
* - no anchorRef → legacy behavior: the first adapter gets opts.threadId, the rest null
|
|
75
|
+
* (the bare threadId belongs to whichever adapter produced the original `first` ref). */
|
|
76
|
+
private _resolveAnchorThreadId;
|
|
77
|
+
bindProjectConduit(projectId: string, conduitHint: string): Promise<void>;
|
|
78
|
+
unbindProjectConduit(projectId: string): Promise<void>;
|
|
79
|
+
getProjectConduits(): Promise<Record<string, string>>;
|
|
80
|
+
resolveInboundProject(conduit: string): Promise<string | null>;
|
|
81
|
+
ownsConduit(conduit: string): boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Extract the TuiGatewayAdapter from an adapter.
|
|
85
|
+
* - CompositeAdapter: return the inner gateway (if any)
|
|
86
|
+
* - TuiGatewayAdapter: return itself
|
|
87
|
+
* - otherwise: return null
|
|
88
|
+
*/
|
|
89
|
+
export declare function extractTuiAdapter(adapter: PlatformAdapter): TuiGatewayAdapter | null;
|