@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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// input: MCP SDK, Slack WebClient, tools/slack registration
|
|
2
|
+
// output: cortex-slack MCP stdio server — Slack platform-specific tools (slack_send_file)
|
|
3
|
+
// pos: Standalone MCP server (peer of core-server.ts & feishu-server.ts); loaded only for Slack-originated
|
|
4
|
+
// sessions (channel carries the `slack:` prefix) — Claude via mcp-config-slack.json layering,
|
|
5
|
+
// PI via the mcp-bridge slack handle. Not loaded for thread/core sessions.
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
9
|
+
import { WebClient } from '@slack/web-api';
|
|
10
|
+
import { registerSlackTools } from './tools/slack.js';
|
|
11
|
+
import { isMainModule } from '../../core/utils.js';
|
|
12
|
+
import { createLogger } from '../../core/log.js';
|
|
13
|
+
import { CORTEX_VERSION } from '../../core/version.js';
|
|
14
|
+
const log = createLogger('mcp-slack');
|
|
15
|
+
// --- Config from env / CLI args ---
|
|
16
|
+
const token = process.env.SLACK_BOT_TOKEN;
|
|
17
|
+
const fallbackChannel = process.env.SLACK_CHANNEL;
|
|
18
|
+
const branchMachine = process.env.CORTEX_BRANCH_MACHINE;
|
|
19
|
+
const fallbackCallbackSource = process.env.CORTEX_CALLBACK_SOURCE;
|
|
20
|
+
// --- Slack client ---
|
|
21
|
+
const slack = token ? new WebClient(token) : null;
|
|
22
|
+
// --- McpServer + tool registration ---
|
|
23
|
+
const server = new McpServer({ name: 'cortex-slack', version: CORTEX_VERSION });
|
|
24
|
+
registerSlackTools(server, {
|
|
25
|
+
slack,
|
|
26
|
+
fallbackChannel,
|
|
27
|
+
routeContextFile: null,
|
|
28
|
+
branchMachine,
|
|
29
|
+
callbackSource: fallbackCallbackSource,
|
|
30
|
+
});
|
|
31
|
+
export const TOOL_NAMES = ['slack_send_file'];
|
|
32
|
+
// --- Start (called by barrel when run as standalone) ---
|
|
33
|
+
export async function startServer() {
|
|
34
|
+
if (!token || !fallbackChannel) {
|
|
35
|
+
log.warn('SLACK_BOT_TOKEN or SLACK_CHANNEL not set — slack_send_file will be unavailable');
|
|
36
|
+
}
|
|
37
|
+
const transport = new StdioServerTransport();
|
|
38
|
+
await server.connect(transport);
|
|
39
|
+
}
|
|
40
|
+
export { uploadFileToSlack } from './tools/slack.js';
|
|
41
|
+
if (isMainModule(import.meta.url)) {
|
|
42
|
+
startServer().catch((e) => {
|
|
43
|
+
log.error(e);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -39,7 +39,7 @@ export async function resolveCortexContext(deps) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
export function registerContextTools(server, deps) {
|
|
42
|
-
server.tool('cortex_context', 'Return the current Cortex execution context: sessionId, sessionName (cortex-XXXX), threadId, profile, project, backend. Use this to discover the current scope before calling cortex_schedule_add with target=current-project/current-
|
|
42
|
+
server.tool('cortex_context', 'Return the current Cortex execution context: sessionId, sessionName (cortex-XXXX), threadId, profile, project, backend. Use this to discover the current scope before calling cortex_schedule_add with target=current-project/current-thread.', {}, { readOnlyHint: true }, async () => {
|
|
43
43
|
try {
|
|
44
44
|
const ctxInternal = await resolveCortexContext(deps);
|
|
45
45
|
// Strip channel from public response — consumers address by project/sessionId/threadId.
|
|
@@ -18,6 +18,6 @@ export interface CortexContextSnapshot {
|
|
|
18
18
|
/** Target spec accepted by cortex_schedule_add: shorthand string OR explicit object.
|
|
19
19
|
* Shorthand strings are resolved to concrete ScheduleTarget objects at create time
|
|
20
20
|
* (decision: list/get always shows real IDs). */
|
|
21
|
-
export type TargetSpec = undefined | 'fresh' | 'current-project' | 'current-
|
|
21
|
+
export type TargetSpec = undefined | 'fresh' | 'current-project' | 'current-thread' | ScheduleTarget;
|
|
22
22
|
export declare function resolveTargetShorthand(spec: TargetSpec, ctx: CortexContextSnapshot): ScheduleTarget;
|
|
23
23
|
export declare function registerScheduleTools(server: McpServer, deps: ContextToolDeps): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// input: McpServer + scheduleRepo + Scheduler (for timing math) + cortex_context resolver
|
|
2
2
|
// output: cortex_schedule_{add,list,get,remove,pause,resume} tool registrations
|
|
3
3
|
// pos: MCP entry that lets the running LLM CRUD scheduled tasks without shelling out
|
|
4
|
-
// to bin/schedule. Resolves __current__ shorthand (current-project/current-
|
|
5
|
-
//
|
|
6
|
-
// record always shows real project/
|
|
4
|
+
// to bin/schedule. Resolves __current__ shorthand (current-project/current-thread)
|
|
5
|
+
// against the live execution context at create time so the persisted
|
|
6
|
+
// record always shows real project/thread IDs.
|
|
7
7
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { Scheduler, parseDuration } from '../../scheduling/scheduler.js';
|
|
@@ -17,12 +17,6 @@ export function resolveTargetShorthand(spec, ctx) {
|
|
|
17
17
|
throw new Error('current-project requested but no project in current context');
|
|
18
18
|
return { kind: 'project', projectId: ctx.project };
|
|
19
19
|
}
|
|
20
|
-
if (spec === 'current-session') {
|
|
21
|
-
if (!ctx.sessionName || !ctx.sessionId || !ctx.channel) {
|
|
22
|
-
throw new Error('current-session requested but session context incomplete (need sessionName + sessionId + channel)');
|
|
23
|
-
}
|
|
24
|
-
return { kind: 'session', sessionName: ctx.sessionName, sessionId: ctx.sessionId, channel: ctx.channel };
|
|
25
|
-
}
|
|
26
20
|
if (spec === 'current-thread') {
|
|
27
21
|
if (!ctx.threadId || !ctx.channel) {
|
|
28
22
|
throw new Error('current-thread requested but no threadId or channel in current context');
|
|
@@ -38,12 +32,6 @@ export function resolveTargetShorthand(spec, ctx) {
|
|
|
38
32
|
throw new Error('project target requires { projectId }');
|
|
39
33
|
return { kind: 'project', projectId: spec.projectId };
|
|
40
34
|
}
|
|
41
|
-
if (spec.kind === 'session') {
|
|
42
|
-
if (!spec.sessionName || !spec.sessionId || !spec.channel) {
|
|
43
|
-
throw new Error('session target requires { sessionName, sessionId, channel }');
|
|
44
|
-
}
|
|
45
|
-
return { kind: 'session', sessionName: spec.sessionName, sessionId: spec.sessionId, channel: spec.channel };
|
|
46
|
-
}
|
|
47
35
|
if (spec.kind === 'thread') {
|
|
48
36
|
if (!spec.threadId || !spec.channel) {
|
|
49
37
|
throw new Error('thread target requires { threadId, channel }');
|
|
@@ -89,11 +77,9 @@ function makeWriteOnlyScheduler() {
|
|
|
89
77
|
const targetSchema = z.union([
|
|
90
78
|
z.literal('fresh'),
|
|
91
79
|
z.literal('current-project'),
|
|
92
|
-
z.literal('current-session'),
|
|
93
80
|
z.literal('current-thread'),
|
|
94
81
|
z.object({ kind: z.literal('fresh') }),
|
|
95
82
|
z.object({ kind: z.literal('project'), projectId: z.string() }),
|
|
96
|
-
z.object({ kind: z.literal('session'), sessionName: z.string(), sessionId: z.string(), channel: z.string() }),
|
|
97
83
|
z.object({ kind: z.literal('thread'), threadId: z.string(), channel: z.string() }),
|
|
98
84
|
]).optional();
|
|
99
85
|
const fallbackSchema = z.enum(['fresh', 'skip', 'wait']).optional();
|
|
@@ -104,8 +90,8 @@ const addInputShape = {
|
|
|
104
90
|
time: z.string().optional().describe('For type=daily/weekly: HH:MM 24-hour'),
|
|
105
91
|
dayOfWeek: z.union([z.string(), z.number()]).optional().describe('For type=weekly: 0-6 (0=Sun) or sun/mon/tue/wed/thu/fri/sat'),
|
|
106
92
|
delay: z.union([z.string(), z.number()]).optional().describe('For type=once: delay from now (duration string or ms)'),
|
|
107
|
-
target: targetSchema.describe('Where to land the fired task. Shorthand: "fresh" (default) | "current-project" | "current-
|
|
108
|
-
fallback: fallbackSchema.describe('What to do if target
|
|
93
|
+
target: targetSchema.describe('Where to land the fired task. Shorthand: "fresh" (default) | "current-project" | "current-thread", or explicit { kind, ...ids }. __current__ shorthand is resolved to concrete IDs at create time.'),
|
|
94
|
+
fallback: fallbackSchema.describe('What to do if the target thread is gone at fire time. fresh (default): silently fall back. skip: post one-line note, do not run. wait: not yet implemented (treated as fresh).'),
|
|
109
95
|
profile: z.string().optional().describe('Agent profile name (defaults to active profile)'),
|
|
110
96
|
preCheck: z.string().optional().describe('Optional shell command; non-zero exit → skip this fire. 15s timeout. Receives PRECHECK_LAST_RUN env var.'),
|
|
111
97
|
channel: z.string().optional().describe('Override the channel used for fresh-fallback. Defaults to current-context channel.'),
|
|
@@ -173,7 +159,7 @@ async function runScheduleAdd(input, deps) {
|
|
|
173
159
|
}
|
|
174
160
|
// --- Tool registrations ---
|
|
175
161
|
export function registerScheduleTools(server, deps) {
|
|
176
|
-
server.tool('cortex_schedule_add', 'Create a scheduled task. Supports interval/daily/weekly/once. target shorthand "current-project" | "current-
|
|
162
|
+
server.tool('cortex_schedule_add', 'Create a scheduled task. Supports interval/daily/weekly/once. target shorthand "current-project" | "current-thread" | "fresh" auto-resolves to concrete IDs against the running agent context — no need to call cortex_context first unless you need an explicit ID.', addInputShape, async (input) => {
|
|
177
163
|
try {
|
|
178
164
|
const result = await runScheduleAdd(input, deps);
|
|
179
165
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
@@ -6,6 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
import * as fs from 'fs';
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { TokenBucketRateLimiter } from '../../../platform/utils/rate-limiter.js';
|
|
9
|
+
import { Icons } from '../../../core/icons.js';
|
|
9
10
|
/** Per-process rate limiter for the MCP server's Slack API calls.
|
|
10
11
|
* The MCP server runs as a separate subprocess, so it maintains its own
|
|
11
12
|
* rate limiter state. Configure via the same CORTEX_SLACK_RL_* env vars. */
|
|
@@ -35,9 +36,9 @@ function withReplyPrefix(text, { branchMachine, callbackSource }) {
|
|
|
35
36
|
if (!text)
|
|
36
37
|
return text;
|
|
37
38
|
if (branchMachine)
|
|
38
|
-
return
|
|
39
|
+
return `${Icons.satellite} *[branch: ${branchMachine}]* ${text}`;
|
|
39
40
|
if (callbackSource)
|
|
40
|
-
return
|
|
41
|
+
return `${Icons.reply} *[callback: ${callbackSource}]* ${text}`;
|
|
41
42
|
return text;
|
|
42
43
|
}
|
|
43
44
|
function resolveReadableFilePath(filePathInput) {
|
|
@@ -53,6 +54,16 @@ function resolveReadableFilePath(filePathInput) {
|
|
|
53
54
|
}
|
|
54
55
|
return { resolved, size: stat.size };
|
|
55
56
|
}
|
|
57
|
+
/** Strip the 'slack:' prefix from a channel ID (tolerates already-bare values for back-compat).
|
|
58
|
+
* Multi-platform conduits carry the 'slack:' prefix from SLACK_CHANNEL env var;
|
|
59
|
+
* the Slack WebClient API expects bare channel IDs.
|
|
60
|
+
* This mirrors SlackAdapter._unwrap() behavior. */
|
|
61
|
+
function stripSlackPrefix(channelId) {
|
|
62
|
+
const PREFIX = 'slack:';
|
|
63
|
+
if (!channelId)
|
|
64
|
+
return channelId;
|
|
65
|
+
return channelId.startsWith(PREFIX) ? channelId.slice(PREFIX.length) : channelId;
|
|
66
|
+
}
|
|
56
67
|
/** Lazy-initialized per-process rate limiter for Slack API calls in the MCP server. */
|
|
57
68
|
let _rateLimiter = null;
|
|
58
69
|
export async function uploadFileToSlack(slack, { channel, filePath, fileName, title, initialComment }) {
|
|
@@ -60,11 +71,13 @@ export async function uploadFileToSlack(slack, { channel, filePath, fileName, ti
|
|
|
60
71
|
const { resolved, size } = resolveReadableFilePath(filePath);
|
|
61
72
|
const body = fs.readFileSync(resolved);
|
|
62
73
|
const uploadName = fileName || path.basename(resolved);
|
|
74
|
+
// Strip 'slack:' prefix from channel ID for Slack API compatibility
|
|
75
|
+
const bareChannel = stripSlackPrefix(channel);
|
|
63
76
|
if (initialComment) {
|
|
64
|
-
await rl.acquire('chat.postMessage',
|
|
65
|
-
await slack.chat.postMessage({ channel, text: initialComment });
|
|
77
|
+
await rl.acquire('chat.postMessage', bareChannel);
|
|
78
|
+
await slack.chat.postMessage({ channel: bareChannel, text: initialComment });
|
|
66
79
|
}
|
|
67
|
-
await rl.acquire('files.getUploadURLExternal',
|
|
80
|
+
await rl.acquire('files.getUploadURLExternal', bareChannel);
|
|
68
81
|
const uploadInit = await slack.files.getUploadURLExternal({
|
|
69
82
|
filename: uploadName,
|
|
70
83
|
length: size,
|
|
@@ -82,10 +95,10 @@ export async function uploadFileToSlack(slack, { channel, filePath, fileName, ti
|
|
|
82
95
|
const suffix = errBody ? `: ${errBody.slice(0, 300)}` : '';
|
|
83
96
|
throw new Error(`Slack file upload failed (${uploadRes.status} ${uploadRes.statusText})${suffix}`);
|
|
84
97
|
}
|
|
85
|
-
await rl.acquire('files.completeUploadExternal',
|
|
98
|
+
await rl.acquire('files.completeUploadExternal', bareChannel);
|
|
86
99
|
await slack.files.completeUploadExternal({
|
|
87
100
|
files: [{ id: uploadInit.file_id, title: title || uploadName }],
|
|
88
|
-
channel_id:
|
|
101
|
+
channel_id: bareChannel,
|
|
89
102
|
});
|
|
90
103
|
return { path: resolved, fileName: uploadName, size };
|
|
91
104
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// input: McpServer, webhook proxy, CORTEX_* env (channel/project/depth)
|
|
2
|
+
// output: thread_start/status/result/list_templates/cancel tool registrations
|
|
3
|
+
// pos: MCP tools letting any agent drive the Thread (multi-agent pipeline) system, proxied
|
|
4
|
+
// through the daemon webhook. Async: thread_start fires-and-returns a threadId; poll
|
|
5
|
+
// thread_status / thread_result. Depth guard caps agent→thread→agent recursion.
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
// Thread operations proxied through the daemon webhook (separate process, no shared memory with
|
|
9
|
+
// the thread runner / store / live PlatformAdapter, all of which live in the daemon).
|
|
10
|
+
const WEBHOOK_BASE = `http://127.0.0.1:${process.env.WEBHOOK_PORT || '3001'}`;
|
|
11
|
+
async function proxyThreadOp(action, payload) {
|
|
12
|
+
const res = await fetch(`${WEBHOOK_BASE}/webhook/thread-op`, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: { 'Content-Type': 'application/json' },
|
|
15
|
+
body: JSON.stringify({ action, ...payload }),
|
|
16
|
+
});
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
if (!data.success)
|
|
19
|
+
throw new Error(data.error || 'thread-op failed');
|
|
20
|
+
return data.data;
|
|
21
|
+
}
|
|
22
|
+
export function registerThreadTools(server) {
|
|
23
|
+
// --- thread_start ---
|
|
24
|
+
server.tool('thread_start', 'Start a Thread (multi-agent pipeline) and return its threadId immediately (async — does NOT wait for completion). Provide exactly one of `template` (a multi-agent pipeline) or `agent` (a single ad-hoc agent); use thread_list_templates to discover both. '
|
|
25
|
+
+ 'For substantive delegated work, pass a structured contract (goal / done_when / deliverable_path / context_files / budget_usd) — your child is graded against done_when and you must verify its deliverable before accepting. Reserve bare-message calls for small, quick side-quests; substantial multi-step work belongs in the task system ([SPLIT]) instead. '
|
|
26
|
+
+ 'If you are an agent inside a thread: spawns default to wait=true — after spawning, end your current step with the marker [WAIT_CHILDREN] to suspend; you will be re-entered with each child\'s result once ALL awaited children finish. Pass wait=false for fire-and-forget. Interactive (non-thread) callers are woken automatically on completion. Spawns can be rejected by tree guards (max children / nodes / budget) — do not retry a rejected spawn; fold the work in or escalate.', {
|
|
27
|
+
template: z.string().optional().describe('Template name for a multi-agent pipeline (mutually exclusive with `agent`)'),
|
|
28
|
+
agent: z.string().optional().describe('Agent name for a single ad-hoc agent (mutually exclusive with `template`)'),
|
|
29
|
+
message: z.string().min(1).describe('The initial user message / task prompt for the thread'),
|
|
30
|
+
project: z.string().optional().describe('Project id for cost attribution & routing. Defaults to the current context project, else "general".'),
|
|
31
|
+
goal: z.string().optional().describe('One-line objective of this delegation (becomes the child\'s mission-chain entry). Defaults to the message when other contract fields are set.'),
|
|
32
|
+
done_when: z.string().optional().describe('Verifiable completion criteria. You (the parent) must check the deliverable against these before accepting the result.'),
|
|
33
|
+
context_files: z.array(z.string()).optional().describe('Absolute paths the child must read before working.'),
|
|
34
|
+
deliverable_path: z.string().optional().describe('Where the child must write its output.'),
|
|
35
|
+
budget_usd: z.number().optional().describe('Budget for the child\'s subtree in USD. Exhaustion trips the circuit breaker.'),
|
|
36
|
+
wait: z.boolean().optional().describe('Thread-parent only. true (default): child is awaited — emit [WAIT_CHILDREN] to suspend until all awaited children finish. false: fire-and-forget (result still lands in your pendingMessages).'),
|
|
37
|
+
}, async ({ template, agent, message, project, goal, done_when, context_files, deliverable_path, budget_usd, wait }) => {
|
|
38
|
+
try {
|
|
39
|
+
if ((template && agent) || (!template && !agent)) {
|
|
40
|
+
return { content: [{ type: 'text', text: 'thread_start error: provide exactly one of `template` or `agent`.' }], isError: true };
|
|
41
|
+
}
|
|
42
|
+
const projectId = project || process.env.CORTEX_PROJECT || undefined;
|
|
43
|
+
const channel = process.env.SLACK_CHANNEL || undefined;
|
|
44
|
+
const depth = parseInt(process.env.CORTEX_THREAD_DEPTH || '0', 10) || 0;
|
|
45
|
+
const parentSessionId = process.env.CORTEX_SESSION_ID || null;
|
|
46
|
+
const parentThreadId = process.env.CORTEX_THREAD_ID || null;
|
|
47
|
+
const parentChannel = process.env.SLACK_CHANNEL || null;
|
|
48
|
+
const parentProfile = process.env.CORTEX_PROFILE || null;
|
|
49
|
+
const result = await proxyThreadOp('start', {
|
|
50
|
+
template, agent, message, projectId, channel, depth, parentSessionId, parentThreadId, parentChannel, parentProfile,
|
|
51
|
+
goal, done_when, context_files, deliverable_path, budget_usd, wait,
|
|
52
|
+
});
|
|
53
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
return { content: [{ type: 'text', text: `thread_start error: ${e.message}` }], isError: true };
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// --- thread_status ---
|
|
60
|
+
server.tool('thread_status', 'Query a thread\'s execution status: status (running/waiting/completed/failed/cancelled/aborted), active agent, step count, accumulated cost, abort reason, and artifact path.', {
|
|
61
|
+
threadId: z.string().describe('Thread id (thr_XXXX) returned by thread_start'),
|
|
62
|
+
}, { readOnlyHint: true }, async ({ threadId }) => {
|
|
63
|
+
try {
|
|
64
|
+
const result = await proxyThreadOp('status', { threadId });
|
|
65
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
return { content: [{ type: 'text', text: `thread_status error: ${e.message}` }], isError: true };
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// --- thread_result ---
|
|
72
|
+
server.tool('thread_result', 'Fetch a thread\'s output: the shared artifact.md content plus the last agent step\'s output. If the thread is not yet terminal, the result is partial (a note flags this) — poll thread_status until terminal for the final result.', {
|
|
73
|
+
threadId: z.string().describe('Thread id (thr_XXXX) returned by thread_start'),
|
|
74
|
+
}, { readOnlyHint: true }, async ({ threadId }) => {
|
|
75
|
+
try {
|
|
76
|
+
const result = await proxyThreadOp('result', { threadId });
|
|
77
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
return { content: [{ type: 'text', text: `thread_result error: ${e.message}` }], isError: true };
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// --- thread_list ---
|
|
84
|
+
server.tool('thread_list', 'List threads you started, newest first. scope "mine" (default) returns threads spawned from your current session; "project" returns all threads in the current project. Each entry has threadId, status, template/agent, step count, cost, and timestamps — use thread_status / thread_result for full detail.', {
|
|
85
|
+
scope: z.enum(['mine', 'project']).optional().describe('"mine" (default): threads you started from this session. "project": all threads in the current project (any starter).'),
|
|
86
|
+
limit: z.number().optional().describe('Max threads to return (default 50, newest first).'),
|
|
87
|
+
view: z.enum(['flat', 'tree']).optional().describe('"flat" (default): newest-first list. "tree": nested thread trees (children under parents) with per-root rollups (nodeCount / totalCostUsd / byStatus / maxDepth).'),
|
|
88
|
+
}, { readOnlyHint: true }, async ({ scope, limit, view }) => {
|
|
89
|
+
try {
|
|
90
|
+
const parentSessionId = process.env.CORTEX_SESSION_ID || null;
|
|
91
|
+
const projectId = process.env.CORTEX_PROJECT || undefined;
|
|
92
|
+
const result = await proxyThreadOp('list-threads', { scope: scope || 'mine', parentSessionId, projectId, limit, view });
|
|
93
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return { content: [{ type: 'text', text: `thread_list error: ${e.message}` }], isError: true };
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// --- thread_list_templates ---
|
|
100
|
+
server.tool('thread_list_templates', 'List available thread templates (multi-agent pipelines) and agents (single ad-hoc roles) with their descriptions. Use to discover what can be passed to thread_start.', {}, { readOnlyHint: true }, async () => {
|
|
101
|
+
try {
|
|
102
|
+
const result = await proxyThreadOp('list', {});
|
|
103
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
return { content: [{ type: 'text', text: `thread_list_templates error: ${e.message}` }], isError: true };
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
// --- thread_cancel ---
|
|
110
|
+
server.tool('thread_cancel', 'Cancel a running thread. Returns whether a running thread was found and cancelled.', {
|
|
111
|
+
threadId: z.string().describe('Thread id (thr_XXXX) to cancel'),
|
|
112
|
+
}, async ({ threadId }) => {
|
|
113
|
+
try {
|
|
114
|
+
const result = await proxyThreadOp('cancel', { threadId });
|
|
115
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
return { content: [{ type: 'text', text: `thread_cancel error: ${e.message}` }], isError: true };
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// input: McpServer, Intl APIs
|
|
2
|
+
// output: current_time tool registration (wall-clock with optional IANA timezone)
|
|
3
|
+
// pos: MCP tool for fetching current time — agents have no implicit clock otherwise
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/** Format `now` in the given IANA timezone. Throws RangeError if the timezone is invalid. */
|
|
7
|
+
function describeTime(now, timezone) {
|
|
8
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
9
|
+
timeZone: timezone,
|
|
10
|
+
year: 'numeric',
|
|
11
|
+
month: '2-digit',
|
|
12
|
+
day: '2-digit',
|
|
13
|
+
hour: '2-digit',
|
|
14
|
+
minute: '2-digit',
|
|
15
|
+
second: '2-digit',
|
|
16
|
+
hour12: false,
|
|
17
|
+
weekday: 'short',
|
|
18
|
+
timeZoneName: 'shortOffset',
|
|
19
|
+
}).formatToParts(now);
|
|
20
|
+
const get = (type) => parts.find((p) => p.type === type)?.value ?? '';
|
|
21
|
+
const date = `${get('year')}-${get('month')}-${get('day')}`;
|
|
22
|
+
// en-CA renders 24h hour as "24" at midnight; normalize to "00".
|
|
23
|
+
const hour = get('hour') === '24' ? '00' : get('hour');
|
|
24
|
+
const time = `${hour}:${get('minute')}:${get('second')}`;
|
|
25
|
+
const offset = get('timeZoneName').replace(/^GMT/, 'UTC');
|
|
26
|
+
return {
|
|
27
|
+
timezone,
|
|
28
|
+
local: `${date} ${time}`,
|
|
29
|
+
offset,
|
|
30
|
+
weekday: get('weekday'),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function registerTimeTools(server) {
|
|
34
|
+
server.tool('current_time', 'Get the current date and time. Optionally specify an IANA timezone (e.g. "Asia/Shanghai", "America/New_York", "UTC"); defaults to the server local timezone. Returns the Unix epoch, UTC ISO string, and the localized wall-clock time with UTC offset.', {
|
|
35
|
+
timezone: z
|
|
36
|
+
.string()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('IANA timezone name, e.g. "Asia/Shanghai", "Europe/London", "UTC". Defaults to the server local timezone.'),
|
|
39
|
+
}, { readOnlyHint: true }, async ({ timezone }) => {
|
|
40
|
+
const now = new Date();
|
|
41
|
+
const tz = timezone || Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
42
|
+
try {
|
|
43
|
+
const d = describeTime(now, tz);
|
|
44
|
+
const result = {
|
|
45
|
+
timezone: d.timezone,
|
|
46
|
+
local: d.local,
|
|
47
|
+
weekday: d.weekday,
|
|
48
|
+
offset: d.offset,
|
|
49
|
+
iso_utc: now.toISOString(),
|
|
50
|
+
unix_ms: now.getTime(),
|
|
51
|
+
};
|
|
52
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return {
|
|
56
|
+
content: [
|
|
57
|
+
{
|
|
58
|
+
type: 'text',
|
|
59
|
+
text: `Invalid timezone "${tz}": ${e.message}. Use an IANA name like "Asia/Shanghai" or "UTC".`,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
isError: true,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -104,5 +104,5 @@ export function registerTuiAskTools(server, deps) {
|
|
|
104
104
|
})).optional().describe('Optional multiple-choice options. Omit for free-text answer.'),
|
|
105
105
|
multiSelect: z.boolean().optional().describe('If true, the user may select multiple options (default false).'),
|
|
106
106
|
})).min(1).max(4).describe('Questions to ask (1-4 questions).'),
|
|
107
|
-
},
|
|
107
|
+
}, async (args) => (await runAskUser(args, deps)));
|
|
108
108
|
}
|
|
@@ -110,9 +110,9 @@ export async function runPlanExit(args, deps) {
|
|
|
110
110
|
// MCP server registration
|
|
111
111
|
// =====================================================================================
|
|
112
112
|
export function registerTuiPlanTools(server, deps) {
|
|
113
|
-
server.tool('cortex_plan_enter', 'Enter Cortex plan mode. Use this BEFORE designing a non-trivial implementation. Replaces native EnterPlanMode in Cortex TUI sessions — investigation is read-only, the plan must be written to a file under `plan/`, and cortex_plan_exit is required before implementation. Optional `reasoning` is recorded for the audit trail.', { reasoning: z.string().optional() },
|
|
113
|
+
server.tool('cortex_plan_enter', 'Enter Cortex plan mode. Use this BEFORE designing a non-trivial implementation. Replaces native EnterPlanMode in Cortex TUI sessions — investigation is read-only, the plan must be written to a file under `plan/`, and cortex_plan_exit is required before implementation. Optional `reasoning` is recorded for the audit trail.', { reasoning: z.string().optional() }, async (args) => runPlanEnter(args ?? {}));
|
|
114
114
|
server.tool('cortex_plan_exit', 'Submit a written plan for human approval (replaces native ExitPlanMode). Reads the plan file at `plan_file_path`, posts it to the Cortex approval channel along with the optional `summary`, and BLOCKS until the human approves, denies, or requests revisions. Returns approval status and any feedback as a tool_result. Do not call this until the plan file is complete.', {
|
|
115
115
|
plan_file_path: z.string().describe('Absolute path of the plan file to submit'),
|
|
116
116
|
summary: z.string().optional().describe('Optional one-paragraph summary surfaced alongside the plan'),
|
|
117
|
-
},
|
|
117
|
+
}, async (args) => (await runPlanExit(args, deps)));
|
|
118
118
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// input: MCP SDK + tui-plan + tui-ask tool modules + agent-server webhook
|
|
2
2
|
// output: MCP stdio service for TUI-mode Claude — exposes cortex_plan_enter / cortex_plan_exit / cortex_ask_user
|
|
3
3
|
// pos: DR-0012 Phase 3 — cortex-tui-bridge MCP server, loaded ONLY by Claude TUI sessions
|
|
4
|
+
// NOTE: "TUI" here refers to Claude CLI's Ink terminal mode (DR-0012), not to the upcoming Cortex TUI.
|
|
4
5
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
6
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
7
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { promises as fsp } from 'fs';
|
|
6
6
|
import { createLogger } from '../../core/log.js';
|
|
7
|
+
import { Icons } from '../../core/icons.js';
|
|
7
8
|
const log = createLogger('disk-monitor');
|
|
8
9
|
const DEFAULT_CHECK_INTERVAL_MS = 5 * 60 * 1000;
|
|
9
10
|
const WARN_BYTES = 500 * 1024 * 1024;
|
|
@@ -60,7 +61,7 @@ async function checkDiskOnce() {
|
|
|
60
61
|
const decision = shouldAlert(freeBytes, _state, Date.now());
|
|
61
62
|
_state = decision.newState;
|
|
62
63
|
if (decision.alert) {
|
|
63
|
-
const msg =
|
|
64
|
+
const msg = `${Icons.warning} Disk low on \`${WATCH_PATH}\`: only *${formatBytes(freeBytes)}* free (< ${formatBytes(WARN_BYTES)} threshold). Clean up or Cortex may crash.`;
|
|
64
65
|
log.info(`ALERT: free=${formatBytes(freeBytes)}`);
|
|
65
66
|
sendDM(msg);
|
|
66
67
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { getMachineRegistry } from '../tasks/dispatch-utils.js';
|
|
6
6
|
import { sendCommand, isDeviceOnline } from '../remote/client-manager.js';
|
|
7
|
+
import { Icons } from '../../core/icons.js';
|
|
7
8
|
const GPU_QUERY = 'nvidia-smi --query-gpu=index,uuid,name,utilization.gpu,memory.used,memory.total,temperature.gpu,power.draw --format=csv,noheader,nounits 2>/dev/null';
|
|
8
9
|
const PROC_QUERY = 'nvidia-smi --query-compute-apps=pid,process_name,used_memory,gpu_uuid --format=csv,noheader,nounits 2>/dev/null || echo ""';
|
|
9
10
|
const SPARK_CHARS = '▁▂▃▄▅▆▇█';
|
|
@@ -111,7 +112,7 @@ function formatGiB(mb) {
|
|
|
111
112
|
return `${(mb / 1024).toFixed(1)} GB`;
|
|
112
113
|
}
|
|
113
114
|
function renderGpuSnapshot(snapshot, historyByGpu, refreshSeconds = 5) {
|
|
114
|
-
const lines = [
|
|
115
|
+
const lines = [`${Icons.desktop} ${snapshot.machine} · refresh ${refreshSeconds}s`, ''];
|
|
115
116
|
for (const gpu of snapshot.gpus) {
|
|
116
117
|
const history = historyByGpu.get(gpu.uuid) || [];
|
|
117
118
|
const memPercent = gpu.memTotalMB > 0 ? (gpu.memUsedMB / gpu.memTotalMB) * 100 : 0;
|
|
@@ -10,6 +10,7 @@ import { getMachineRegistry } from '../tasks/dispatch-utils.js';
|
|
|
10
10
|
import { sshExec, clientPids, buildRemoteSpawnCommand } from './client-manager.js';
|
|
11
11
|
import { STORE_DIR } from '../../core/utils.js';
|
|
12
12
|
import { createLogger } from '../../core/log.js';
|
|
13
|
+
import { Icons } from '../../core/icons.js';
|
|
13
14
|
const log = createLogger('client-hot-reload');
|
|
14
15
|
const VERSION_FILE = path.join(STORE_DIR, 'client-version.json');
|
|
15
16
|
// --- Mode detection ---
|
|
@@ -362,10 +363,10 @@ function formatUpdateSlackMessage(result) {
|
|
|
362
363
|
? `mtime \`${result.oldVersion}\` → \`${result.newVersion}\``
|
|
363
364
|
: `\`${result.oldVersion}\` → \`${result.newVersion}\``;
|
|
364
365
|
const lines = [
|
|
365
|
-
|
|
366
|
+
`${Icons.refresh} *Client hot-reload ${modeLabel}* ${versionLabel} (${(result.duration / 1000).toFixed(1)}s)`,
|
|
366
367
|
];
|
|
367
368
|
for (const d of result.devices) {
|
|
368
|
-
const icon = d.updated && d.restarted ?
|
|
369
|
+
const icon = d.updated && d.restarted ? Icons.ok : Icons.error;
|
|
369
370
|
lines.push(` ${d.device}: ${icon}${d.error ? ` _${d.error}_` : ''}`);
|
|
370
371
|
}
|
|
371
372
|
return lines.join('\n');
|
|
@@ -12,8 +12,7 @@ import { getMachineRegistry } from '../tasks/dispatch-utils.js';
|
|
|
12
12
|
import { STORE_DIR } from '../../core/utils.js';
|
|
13
13
|
import { createLogger } from '../../core/log.js';
|
|
14
14
|
import { readTasks, findTask } from '../tasks/system/task-lifecycle-edit.js';
|
|
15
|
-
import {
|
|
16
|
-
import { blockTask } from '../tasks/system/task-state.js';
|
|
15
|
+
import { taskMutator } from '../tasks/mutator.js';
|
|
17
16
|
const log = createLogger('client-manager');
|
|
18
17
|
// --- State ---
|
|
19
18
|
const devices = new Map();
|
|
@@ -87,7 +86,7 @@ function startClientManager(port) {
|
|
|
87
86
|
return;
|
|
88
87
|
}
|
|
89
88
|
if (msg.type === 'task-callback') {
|
|
90
|
-
handleTaskCallback(ws, msg);
|
|
89
|
+
void handleTaskCallback(ws, msg).catch((e) => log.error(`task-callback: ${e.message}`));
|
|
91
90
|
return;
|
|
92
91
|
}
|
|
93
92
|
});
|
|
@@ -410,7 +409,7 @@ function sendAck(ws, callbackId, ok, message) {
|
|
|
410
409
|
ws.send(JSON.stringify({ type: 'task-callback-ack', callbackId, ok, message }));
|
|
411
410
|
}
|
|
412
411
|
}
|
|
413
|
-
function handleTaskCallback(ws, msg) {
|
|
412
|
+
async function handleTaskCallback(ws, msg) {
|
|
414
413
|
const { taskProject, taskId, termination, exitCode, durationHuman, remoteResultPath, remoteLogPath, device, callbackId, logTail } = msg;
|
|
415
414
|
// No task linkage: ack-true immediately (client doesn't need to retry)
|
|
416
415
|
if (!taskProject || !taskId) {
|
|
@@ -435,12 +434,15 @@ function handleTaskCallback(ws, msg) {
|
|
|
435
434
|
const note = isSuccess
|
|
436
435
|
? `cortex-run on ${device} completed in ${durationHuman || '?'}, exit 0. Remote: ${remoteRef}`
|
|
437
436
|
: `cortex-run on ${device} ${termination || '?'} after ${durationHuman || '?'}, exit ${exitCode ?? '?'}. Remote: ${remoteRef}\n--- log tail ---\n${logTail || '(no log tail)'}`;
|
|
437
|
+
// Route through taskMutator (not the bare lifecycle functions) so task.completed /
|
|
438
|
+
// task.blocked events fire — a manager thread suspended on this task (DR-0014 §8)
|
|
439
|
+
// is woken by exactly these events, possibly days after dispatch.
|
|
438
440
|
let result;
|
|
439
441
|
if (isSuccess) {
|
|
440
|
-
result =
|
|
442
|
+
result = await taskMutator.complete(taskId, note, { skipVerify: true, skipVerifyReason: 'remote-run' });
|
|
441
443
|
}
|
|
442
444
|
else {
|
|
443
|
-
result =
|
|
445
|
+
result = await taskMutator.block(taskId, note);
|
|
444
446
|
}
|
|
445
447
|
const ackMessage = result.verify_warning
|
|
446
448
|
? `${result.message} (${result.verify_warning})`
|
|
@@ -24,6 +24,10 @@ export declare const ctx: {
|
|
|
24
24
|
schedulerRef: Scheduler | null;
|
|
25
25
|
bus: EventBus | null;
|
|
26
26
|
buildInteractiveCallbacks: InteractiveCallbacksFactory | null;
|
|
27
|
+
/** DR-0014 §8: injected by app.ts (→ orchestration/thread-callback.reconcileWaitingTasks)
|
|
28
|
+
* so the dispatch path can close the suspension race window for manager threads
|
|
29
|
+
* without a domain → orchestration import. */
|
|
30
|
+
onThreadSuspended: ((threadId: string) => Promise<void>) | null;
|
|
27
31
|
};
|
|
28
32
|
export declare function register(key: string, runner: JobRunner): void;
|
|
29
33
|
export declare function dispatch(key: string, payload: unknown): boolean;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// pos: shared helper functions used by both the scheduled-task and task-dispatch jobs
|
|
4
4
|
import { buildSessionTag, buildUserProcessingMessage, computeElapsed, formatMetricsSuffix } from '../../../core/status-format.js';
|
|
5
5
|
import { createLogger } from '../../../core/log.js';
|
|
6
|
+
import { Icons } from '../../../core/icons.js';
|
|
6
7
|
import { sessionStore } from '../../../store/session-registry-repo.js';
|
|
7
8
|
import { getOutboundQueue, durableUpdate } from '../../../store/outbound-queue.js';
|
|
8
9
|
import { getActiveBackend, getActiveProfile } from '../../agents/index.js';
|
|
@@ -34,7 +35,7 @@ export async function finalizeThreadSuccess(adapter, channel, statusMsg, { start
|
|
|
34
35
|
}
|
|
35
36
|
const metrics = formatMetricsSuffix({ costUsd: threadResult.totalCostUsd, numTurns: threadResult.totalNumTurns });
|
|
36
37
|
if (statusMsg) {
|
|
37
|
-
const text =
|
|
38
|
+
const text = `${Icons.ok} ${statusPrefix} | ${buildSessionTag(sessionName, result?.sessionId)}(${elapsedStr}${metrics})`;
|
|
38
39
|
const queue = getOutboundQueue();
|
|
39
40
|
if (queue) {
|
|
40
41
|
await durableUpdate(queue, adapter, statusMsg, { text });
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
// output: memory-index-regen job runner — registers as 'memory-index-regen'
|
|
3
3
|
// pos: periodic memory index regeneration (non-LLM programmatic work)
|
|
4
4
|
import { register, ctx } from '../job-registry.js';
|
|
5
|
+
import { Icons } from '../../../core/icons.js';
|
|
5
6
|
import { regenAll as runMemoryIndexRegen } from '../../memory/index-regen.js';
|
|
6
7
|
// Self-register
|
|
7
8
|
register('memory-index-regen', async (payload) => {
|
|
8
9
|
const { channel } = payload;
|
|
9
10
|
try {
|
|
10
11
|
const projects = runMemoryIndexRegen();
|
|
11
|
-
await ctx.adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text:
|
|
12
|
+
await ctx.adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.brain} Memory index regen: ${projects.length} projects updated` });
|
|
12
13
|
}
|
|
13
14
|
catch (err) {
|
|
14
|
-
await ctx.adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text:
|
|
15
|
+
await ctx.adapter.postMessage({ type: 'interactive-reply', conduit: channel }, { text: `${Icons.warning} Memory index regen error: ${err}` });
|
|
15
16
|
}
|
|
16
17
|
});
|