@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,35 @@
|
|
|
1
|
+
// input: UiServiceDeps + ExecutionsListParams
|
|
2
|
+
// output: handleExecutionsList → ExecutionInfo[]
|
|
3
|
+
// pos: query handler for 'executions.list'
|
|
4
|
+
export async function handleExecutionsList(deps, params) {
|
|
5
|
+
const { status, limit } = params;
|
|
6
|
+
let executions = deps.executionRegistry.getAll();
|
|
7
|
+
if (status && status.length > 0) {
|
|
8
|
+
const statusSet = new Set(status);
|
|
9
|
+
executions = executions.filter((e) => statusSet.has(e.status));
|
|
10
|
+
}
|
|
11
|
+
// Sort by startedAt descending
|
|
12
|
+
executions.sort((a, b) => (b.runtime?.startedAt || '').localeCompare(a.runtime?.startedAt || ''));
|
|
13
|
+
if (limit && limit > 0) {
|
|
14
|
+
executions = executions.slice(0, limit);
|
|
15
|
+
}
|
|
16
|
+
return executions.map((e) => {
|
|
17
|
+
const startedAt = e.runtime?.startedAt || '';
|
|
18
|
+
const finishedAt = e.runtime?.endedAt || null;
|
|
19
|
+
const startMs = new Date(startedAt).getTime();
|
|
20
|
+
const endMs = finishedAt ? new Date(finishedAt).getTime() : null;
|
|
21
|
+
return {
|
|
22
|
+
id: e.id,
|
|
23
|
+
type: e.kind === 'dispatch' ? 'dispatch' : 'local',
|
|
24
|
+
status: e.status,
|
|
25
|
+
taskId: e.dispatch?.taskId ?? null,
|
|
26
|
+
sessionId: e.session?.sessionId ?? null,
|
|
27
|
+
projectId: e.project ?? null,
|
|
28
|
+
machine: e.dispatch?.machine ?? null,
|
|
29
|
+
startedAt,
|
|
30
|
+
finishedAt,
|
|
31
|
+
durationMs: endMs ? endMs - startMs : null,
|
|
32
|
+
cost: e.metrics?.costUsd ?? null,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// input: UiServiceDeps
|
|
2
|
+
// output: handleProjectsList → ProjectConduitInfo[]
|
|
3
|
+
// pos: query handler for 'projects.list'
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
function projectHasMission(contextDir) {
|
|
7
|
+
try {
|
|
8
|
+
return fs.existsSync(path.join(contextDir, 'mission.md'));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function handleProjectsList(deps) {
|
|
15
|
+
const projects = deps.projectStore.list();
|
|
16
|
+
let conduits = {};
|
|
17
|
+
try {
|
|
18
|
+
conduits = await deps.adapter.getProjectConduits();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// conduit lookup failure is non-fatal; projects still listed with empty conduits
|
|
22
|
+
}
|
|
23
|
+
return projects.map((p) => ({
|
|
24
|
+
id: p.id,
|
|
25
|
+
kind: p.kind === 'general' ? 'general' : 'research',
|
|
26
|
+
contextDir: p.contextDir,
|
|
27
|
+
hasMission: projectHasMission(p.contextDir),
|
|
28
|
+
conduits,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// input: UiServiceDeps + SchedulesListParams
|
|
2
|
+
// output: handleSchedulesList → ScheduleInfo[]
|
|
3
|
+
// pos: query handler for 'schedules.list'
|
|
4
|
+
export async function handleSchedulesList(deps, params) {
|
|
5
|
+
const { projectId, paused } = params;
|
|
6
|
+
let schedules = await deps.scheduler.list();
|
|
7
|
+
if (projectId) {
|
|
8
|
+
schedules = schedules.filter((s) => s.projectId === projectId);
|
|
9
|
+
}
|
|
10
|
+
if (paused !== undefined) {
|
|
11
|
+
schedules = schedules.filter((s) => (s.isPaused ?? false) === paused);
|
|
12
|
+
}
|
|
13
|
+
return schedules.map((s) => ({
|
|
14
|
+
id: s.id,
|
|
15
|
+
type: s.type,
|
|
16
|
+
message: s.message,
|
|
17
|
+
projectId: s.projectId,
|
|
18
|
+
nextRun: s.nextRun != null ? new Date(s.nextRun).toISOString() : null,
|
|
19
|
+
lastRun: s.lastRun != null ? new Date(s.lastRun).toISOString() : null,
|
|
20
|
+
paused: s.isPaused ?? false,
|
|
21
|
+
pausedBy: s.pausedBy ?? null,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// input: UiServiceDeps + SessionsListParams
|
|
2
|
+
// output: handleSessionsList → SessionInfo[]
|
|
3
|
+
// pos: query handler for 'sessions.list'
|
|
4
|
+
export async function handleSessionsList(deps, params) {
|
|
5
|
+
const { projectId, resumable } = params;
|
|
6
|
+
let sessions;
|
|
7
|
+
if (resumable) {
|
|
8
|
+
sessions = await deps.sessionStore.listResumable(projectId);
|
|
9
|
+
}
|
|
10
|
+
else if (projectId) {
|
|
11
|
+
sessions = await deps.sessionStore.listByProject(projectId);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// list all — iterate through listByProject for each known project
|
|
15
|
+
// or fall back to listing all sessions via the store
|
|
16
|
+
const allProjects = deps.projectStore.list();
|
|
17
|
+
const results = [];
|
|
18
|
+
for (const p of allProjects) {
|
|
19
|
+
const projectSessions = await deps.sessionStore.listByProject(p.id);
|
|
20
|
+
results.push(...projectSessions);
|
|
21
|
+
}
|
|
22
|
+
sessions = results;
|
|
23
|
+
}
|
|
24
|
+
return sessions.map((s) => ({
|
|
25
|
+
sessionId: s.sessionId,
|
|
26
|
+
name: s.name,
|
|
27
|
+
projectId: s.projectId,
|
|
28
|
+
backend: s.backend,
|
|
29
|
+
kind: s.kind,
|
|
30
|
+
createdAt: s.createdAt,
|
|
31
|
+
lastUsedAt: s.lastUsedAt,
|
|
32
|
+
resumable: s.kind !== 'scheduled',
|
|
33
|
+
label: s.label ?? null,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// input: UiServiceDeps + TasksListParams
|
|
2
|
+
// output: handleTasksList → TaskInfo[]
|
|
3
|
+
// pos: query handler for 'tasks.list'
|
|
4
|
+
export async function handleTasksList(deps, params) {
|
|
5
|
+
const { projectId, status, actionable } = params;
|
|
6
|
+
deps.taskStore.refresh();
|
|
7
|
+
let tasks = deps.taskStore.getAll(projectId || undefined);
|
|
8
|
+
if (status) {
|
|
9
|
+
tasks = tasks.filter((t) => t.status === status);
|
|
10
|
+
}
|
|
11
|
+
if (actionable !== undefined) {
|
|
12
|
+
tasks = tasks.filter((t) => {
|
|
13
|
+
const isActionable = t.status === 'open' && !t.claimed_by && !t.blocked_by && !t.paused;
|
|
14
|
+
return actionable ? isActionable : !isActionable;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return tasks.map((t) => ({
|
|
18
|
+
id: t.id,
|
|
19
|
+
text: t.text,
|
|
20
|
+
project: t.project,
|
|
21
|
+
status: t.status === 'done' ? 'done' : 'open',
|
|
22
|
+
priority: t.priority || 'medium',
|
|
23
|
+
actionable: !!(t.status === 'open' && !t.claimed_by && !t.blocked_by && !t.paused),
|
|
24
|
+
claimedBy: t.claimed_by ?? null,
|
|
25
|
+
blockedBy: t.blocked_by ?? null,
|
|
26
|
+
dependsOn: t.depends_on || [],
|
|
27
|
+
plan: t.plan ?? null,
|
|
28
|
+
template: t.template || 'coder-review',
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// input: UiServiceDeps + ThreadsListParams
|
|
2
|
+
// output: handleThreadsList → ThreadInfo[]
|
|
3
|
+
// pos: query handler for 'threads.list'
|
|
4
|
+
export async function handleThreadsList(deps, params) {
|
|
5
|
+
const { projectId, status } = params;
|
|
6
|
+
let threads = deps.threadStore.getAll();
|
|
7
|
+
if (projectId) {
|
|
8
|
+
threads = threads.filter((t) => t.projectId === projectId);
|
|
9
|
+
}
|
|
10
|
+
if (status && status.length > 0) {
|
|
11
|
+
const statusSet = new Set(status);
|
|
12
|
+
threads = threads.filter((t) => statusSet.has(t.status));
|
|
13
|
+
}
|
|
14
|
+
return threads.map((t) => ({
|
|
15
|
+
id: t.id,
|
|
16
|
+
templateName: t.templateName || 'unknown',
|
|
17
|
+
currentStep: t.currentStepIndex != null
|
|
18
|
+
? { index: t.currentStepIndex, name: t.currentStepName || `step-${t.currentStepIndex}` }
|
|
19
|
+
: null,
|
|
20
|
+
status: t.status,
|
|
21
|
+
projectId: t.projectId,
|
|
22
|
+
createdAt: t.createdAt,
|
|
23
|
+
updatedAt: t.updatedAt,
|
|
24
|
+
totalSteps: (t.template?.agents?.length) || t.steps?.length || 0,
|
|
25
|
+
artifactPath: t.artifactPath ?? null,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// input: EventBus + SubscribeFilter
|
|
2
|
+
// output: AsyncIterable<UiEvent> & { close() } — bounded queue, overflow emits synthetic dropped event
|
|
3
|
+
// pos: subscribe primitive for UiService
|
|
4
|
+
const QUEUE_CAP = 256;
|
|
5
|
+
/**
|
|
6
|
+
* Create an async queue with bounded capacity. When `onOverflow` is set, it
|
|
7
|
+
* is called from within a re-entrant guard so that push() calls from the
|
|
8
|
+
* callback do not recursively trigger overflow — guaranteeing that exactly
|
|
9
|
+
* one oldest item is dropped per real overflow.
|
|
10
|
+
*/
|
|
11
|
+
function createAsyncQueue(cap, onOverflow) {
|
|
12
|
+
const buffer = [];
|
|
13
|
+
let resolve = null;
|
|
14
|
+
let _closed = false;
|
|
15
|
+
let _inOverflow = false;
|
|
16
|
+
return {
|
|
17
|
+
push(item) {
|
|
18
|
+
if (_closed)
|
|
19
|
+
return;
|
|
20
|
+
if (!_inOverflow && buffer.length >= cap) {
|
|
21
|
+
buffer.shift();
|
|
22
|
+
if (onOverflow) {
|
|
23
|
+
_inOverflow = true;
|
|
24
|
+
try {
|
|
25
|
+
onOverflow();
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
_inOverflow = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (resolve) {
|
|
33
|
+
const r = resolve;
|
|
34
|
+
resolve = null;
|
|
35
|
+
r({ value: item, done: false });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
buffer.push(item);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
close() {
|
|
42
|
+
_closed = true;
|
|
43
|
+
if (resolve) {
|
|
44
|
+
const r = resolve;
|
|
45
|
+
resolve = null;
|
|
46
|
+
r({ value: undefined, done: true });
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
[Symbol.asyncIterator]() {
|
|
50
|
+
return {
|
|
51
|
+
next: () => {
|
|
52
|
+
if (buffer.length > 0) {
|
|
53
|
+
const value = buffer.shift();
|
|
54
|
+
return Promise.resolve({ value, done: false });
|
|
55
|
+
}
|
|
56
|
+
if (_closed) {
|
|
57
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
58
|
+
}
|
|
59
|
+
return new Promise((res) => {
|
|
60
|
+
resolve = res;
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function createSubscription(bus, filter) {
|
|
68
|
+
const eventTypes = filter.events;
|
|
69
|
+
const projectId = filter.projectId ?? null;
|
|
70
|
+
let droppedCount = 0;
|
|
71
|
+
// Wire overflow handler: push a synthetic UiEvent onto the queue.
|
|
72
|
+
// The queue's _inOverflow guard ensures push() from this callback does
|
|
73
|
+
// NOT re-trigger overflow, so the synthetic always lands safely.
|
|
74
|
+
const queue = createAsyncQueue(QUEUE_CAP, () => {
|
|
75
|
+
droppedCount++;
|
|
76
|
+
const synthetic = {
|
|
77
|
+
type: 'ui-subscribe.dropped',
|
|
78
|
+
ts: new Date().toISOString(),
|
|
79
|
+
payload: { droppedCount },
|
|
80
|
+
};
|
|
81
|
+
// push() from within the guard: no overflow shift, item always appended.
|
|
82
|
+
queue.push(synthetic);
|
|
83
|
+
});
|
|
84
|
+
const subscriptions = eventTypes.map((type) => {
|
|
85
|
+
const sub = bus.subscribe(type, (event) => {
|
|
86
|
+
// Post-filter by projectId if specified
|
|
87
|
+
if (projectId && event.projectId && event.projectId !== projectId) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (projectId && event.payload?.projectId && event.payload.projectId !== projectId) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const uiEvent = {
|
|
94
|
+
type: event.type,
|
|
95
|
+
ts: event.ts,
|
|
96
|
+
payload: event,
|
|
97
|
+
};
|
|
98
|
+
queue.push(uiEvent);
|
|
99
|
+
});
|
|
100
|
+
return sub;
|
|
101
|
+
});
|
|
102
|
+
let closed = false;
|
|
103
|
+
const close = () => {
|
|
104
|
+
if (closed)
|
|
105
|
+
return;
|
|
106
|
+
closed = true;
|
|
107
|
+
for (const sub of subscriptions) {
|
|
108
|
+
sub.unsubscribe();
|
|
109
|
+
}
|
|
110
|
+
queue.close();
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
[Symbol.asyncIterator]() {
|
|
114
|
+
return queue[Symbol.asyncIterator]();
|
|
115
|
+
},
|
|
116
|
+
close,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { Project } from '../projects/index.js';
|
|
2
|
+
import type { CostSummary } from '../costs/cost-tracker.js';
|
|
3
|
+
import type { EventBus } from '../../events/index.js';
|
|
4
|
+
import type { RunningExecutions } from '../../core/running-executions.js';
|
|
5
|
+
import type { PlatformAdapter } from '../../platform/adapter.js';
|
|
6
|
+
import type { Session } from '../../store/session-registry-repo.js';
|
|
7
|
+
import type { ScheduleTask } from '../../store/schedule-repo.js';
|
|
8
|
+
export type Ok<T> = {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: T;
|
|
11
|
+
};
|
|
12
|
+
export type Err = {
|
|
13
|
+
ok: false;
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
export type Result<T> = Ok<T> | Err;
|
|
18
|
+
export type QueryScope = 'projects.list' | 'sessions.list' | 'threads.list' | 'tasks.list' | 'schedules.list' | 'executions.list' | 'cost.summary';
|
|
19
|
+
export type MutateOp = 'threads.cancel' | 'executions.cancel' | 'schedules.pause' | 'schedules.resume' | 'schedules.remove' | 'tasks.claim' | 'tasks.unclaim' | 'tasks.complete' | 'tasks.block' | 'tasks.unblock';
|
|
20
|
+
export interface SubscribeFilter {
|
|
21
|
+
events: string[];
|
|
22
|
+
projectId?: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface UiEvent {
|
|
25
|
+
type: string;
|
|
26
|
+
ts: string;
|
|
27
|
+
payload: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface SessionsListParams {
|
|
30
|
+
projectId?: string;
|
|
31
|
+
resumable?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ThreadsListParams {
|
|
34
|
+
projectId?: string;
|
|
35
|
+
status?: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface TasksListParams {
|
|
38
|
+
projectId?: string;
|
|
39
|
+
status?: 'open' | 'done';
|
|
40
|
+
actionable?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface SchedulesListParams {
|
|
43
|
+
projectId?: string;
|
|
44
|
+
paused?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ExecutionsListParams {
|
|
47
|
+
status?: string[];
|
|
48
|
+
limit?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface CostSummaryParams {
|
|
51
|
+
projectId?: string | null;
|
|
52
|
+
}
|
|
53
|
+
export interface ThreadsCancelArgs {
|
|
54
|
+
threadId: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ExecutionsCancelArgs {
|
|
57
|
+
executionId: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ScheduleActionArgs {
|
|
60
|
+
scheduleId: string;
|
|
61
|
+
}
|
|
62
|
+
export interface TaskActionArgs {
|
|
63
|
+
projectId: string;
|
|
64
|
+
taskId: string;
|
|
65
|
+
}
|
|
66
|
+
export interface TaskCompleteArgs extends TaskActionArgs {
|
|
67
|
+
note?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface TaskBlockArgs extends TaskActionArgs {
|
|
70
|
+
reason: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ProjectConduitInfo {
|
|
73
|
+
id: string;
|
|
74
|
+
kind: 'research' | 'general';
|
|
75
|
+
contextDir: string;
|
|
76
|
+
hasMission: boolean;
|
|
77
|
+
conduits: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
export interface SessionInfo {
|
|
80
|
+
sessionId: string;
|
|
81
|
+
name: string;
|
|
82
|
+
projectId: string;
|
|
83
|
+
backend: string;
|
|
84
|
+
kind: 'local' | 'scheduled';
|
|
85
|
+
createdAt: string;
|
|
86
|
+
lastUsedAt: string;
|
|
87
|
+
resumable: boolean;
|
|
88
|
+
label: string | null;
|
|
89
|
+
}
|
|
90
|
+
export interface ThreadInfo {
|
|
91
|
+
id: string;
|
|
92
|
+
templateName: string;
|
|
93
|
+
currentStep: {
|
|
94
|
+
index: number;
|
|
95
|
+
name: string;
|
|
96
|
+
} | null;
|
|
97
|
+
status: 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled' | 'aborted';
|
|
98
|
+
projectId: string;
|
|
99
|
+
createdAt: string;
|
|
100
|
+
updatedAt: string;
|
|
101
|
+
totalSteps: number;
|
|
102
|
+
artifactPath: string | null;
|
|
103
|
+
}
|
|
104
|
+
export interface TaskInfo {
|
|
105
|
+
id: string;
|
|
106
|
+
text: string;
|
|
107
|
+
project: string;
|
|
108
|
+
status: 'open' | 'done';
|
|
109
|
+
priority: 'high' | 'medium' | 'low';
|
|
110
|
+
actionable: boolean;
|
|
111
|
+
claimedBy: string | null;
|
|
112
|
+
blockedBy: string | null;
|
|
113
|
+
dependsOn: string[];
|
|
114
|
+
plan: string | null;
|
|
115
|
+
template: string;
|
|
116
|
+
}
|
|
117
|
+
export interface ScheduleInfo {
|
|
118
|
+
id: string;
|
|
119
|
+
type: 'interval' | 'daily' | 'weekly' | 'once';
|
|
120
|
+
message: string;
|
|
121
|
+
projectId: string;
|
|
122
|
+
nextRun: string | null;
|
|
123
|
+
lastRun: string | null;
|
|
124
|
+
paused: boolean;
|
|
125
|
+
pausedBy: string | null;
|
|
126
|
+
}
|
|
127
|
+
export interface ExecutionInfo {
|
|
128
|
+
id: string;
|
|
129
|
+
type: 'local' | 'dispatch';
|
|
130
|
+
status: 'running' | 'completed' | 'failed' | 'cancelled' | 'stale';
|
|
131
|
+
taskId: string | null;
|
|
132
|
+
sessionId: string | null;
|
|
133
|
+
projectId: string | null;
|
|
134
|
+
machine: string | null;
|
|
135
|
+
startedAt: string;
|
|
136
|
+
finishedAt: string | null;
|
|
137
|
+
durationMs: number | null;
|
|
138
|
+
cost: number | null;
|
|
139
|
+
}
|
|
140
|
+
export interface ThreadsCancelReturn {
|
|
141
|
+
cancelled: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface ExecutionsCancelReturn {
|
|
144
|
+
cancelled: boolean;
|
|
145
|
+
}
|
|
146
|
+
export interface QueryParamMap {
|
|
147
|
+
'projects.list': Record<string, never>;
|
|
148
|
+
'sessions.list': SessionsListParams;
|
|
149
|
+
'threads.list': ThreadsListParams;
|
|
150
|
+
'tasks.list': TasksListParams;
|
|
151
|
+
'schedules.list': SchedulesListParams;
|
|
152
|
+
'executions.list': ExecutionsListParams;
|
|
153
|
+
'cost.summary': CostSummaryParams;
|
|
154
|
+
}
|
|
155
|
+
export interface QueryReturnMap {
|
|
156
|
+
'projects.list': ProjectConduitInfo[];
|
|
157
|
+
'sessions.list': SessionInfo[];
|
|
158
|
+
'threads.list': ThreadInfo[];
|
|
159
|
+
'tasks.list': TaskInfo[];
|
|
160
|
+
'schedules.list': ScheduleInfo[];
|
|
161
|
+
'executions.list': ExecutionInfo[];
|
|
162
|
+
'cost.summary': CostSummary;
|
|
163
|
+
}
|
|
164
|
+
export interface MutateArgsMap {
|
|
165
|
+
'threads.cancel': ThreadsCancelArgs;
|
|
166
|
+
'executions.cancel': ExecutionsCancelArgs;
|
|
167
|
+
'schedules.pause': ScheduleActionArgs;
|
|
168
|
+
'schedules.resume': ScheduleActionArgs;
|
|
169
|
+
'schedules.remove': ScheduleActionArgs;
|
|
170
|
+
'tasks.claim': TaskActionArgs;
|
|
171
|
+
'tasks.unclaim': TaskActionArgs;
|
|
172
|
+
'tasks.complete': TaskCompleteArgs;
|
|
173
|
+
'tasks.block': TaskBlockArgs;
|
|
174
|
+
'tasks.unblock': TaskActionArgs;
|
|
175
|
+
}
|
|
176
|
+
export interface MutateReturnMap {
|
|
177
|
+
'threads.cancel': ThreadsCancelReturn;
|
|
178
|
+
'executions.cancel': ExecutionsCancelReturn;
|
|
179
|
+
'schedules.pause': void;
|
|
180
|
+
'schedules.resume': void;
|
|
181
|
+
'schedules.remove': void;
|
|
182
|
+
'tasks.claim': void;
|
|
183
|
+
'tasks.unclaim': void;
|
|
184
|
+
'tasks.complete': void;
|
|
185
|
+
'tasks.block': void;
|
|
186
|
+
'tasks.unblock': void;
|
|
187
|
+
}
|
|
188
|
+
export type QueryParams<S extends QueryScope> = S extends keyof QueryParamMap ? QueryParamMap[S] : never;
|
|
189
|
+
export type QueryReturn<S extends QueryScope> = S extends keyof QueryReturnMap ? QueryReturnMap[S] : never;
|
|
190
|
+
export type MutateArgs<O extends MutateOp> = O extends keyof MutateArgsMap ? MutateArgsMap[O] : never;
|
|
191
|
+
export type MutateReturn<O extends MutateOp> = O extends keyof MutateReturnMap ? MutateReturnMap[O] : never;
|
|
192
|
+
export interface UiService {
|
|
193
|
+
query<S extends QueryScope>(scope: S, params: QueryParams<S>): Promise<Result<QueryReturn<S>>>;
|
|
194
|
+
mutate<O extends MutateOp>(op: O, args: MutateArgs<O>): Promise<Result<MutateReturn<O>>>;
|
|
195
|
+
subscribe(filter: SubscribeFilter): AsyncIterable<UiEvent> & {
|
|
196
|
+
close(): void;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
export interface UiServiceDeps {
|
|
200
|
+
projectStore: {
|
|
201
|
+
list(): Project[];
|
|
202
|
+
get(id: string): Project | undefined;
|
|
203
|
+
exists(id: string): boolean;
|
|
204
|
+
getDefault(): Project;
|
|
205
|
+
};
|
|
206
|
+
sessionStore: {
|
|
207
|
+
listByProject(projectId: string): Promise<Session[]>;
|
|
208
|
+
listResumable(projectId?: string): Promise<Session[]>;
|
|
209
|
+
getById(sessionId: string): Promise<Session | null>;
|
|
210
|
+
};
|
|
211
|
+
threadStore: {
|
|
212
|
+
getAll(): any[];
|
|
213
|
+
get(id: string): any | null;
|
|
214
|
+
};
|
|
215
|
+
taskStore: {
|
|
216
|
+
getAll(project?: string): any[];
|
|
217
|
+
getById(taskId: string): any | null;
|
|
218
|
+
load(): void;
|
|
219
|
+
refresh(): void;
|
|
220
|
+
};
|
|
221
|
+
scheduler: {
|
|
222
|
+
list(): Promise<ScheduleTask[]>;
|
|
223
|
+
get(id: string): Promise<ScheduleTask | null>;
|
|
224
|
+
pause(id: string, pausedBy?: 'user' | 'rate-limit'): Promise<ScheduleTask | null>;
|
|
225
|
+
resume(id: string): Promise<ScheduleTask | null>;
|
|
226
|
+
remove(id: string): Promise<boolean>;
|
|
227
|
+
};
|
|
228
|
+
executionRegistry: {
|
|
229
|
+
getExecution(id: string): any | null;
|
|
230
|
+
getAll(): any[];
|
|
231
|
+
cancelExecution(id: string, metrics?: any): any | null;
|
|
232
|
+
};
|
|
233
|
+
runningExecutions: RunningExecutions;
|
|
234
|
+
costSummary: (projectId?: string | null) => Promise<CostSummary>;
|
|
235
|
+
bus: EventBus;
|
|
236
|
+
adapter: PlatformAdapter;
|
|
237
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// input: nothing (leaf module)
|
|
2
|
+
// output: UiService types — Result, QueryScope, MutateOp, DTOs, UiService interface, UiServiceDeps
|
|
3
|
+
// pos: leaf types module, depends only on domain types pulled in by query/mutate handlers
|
|
4
|
+
// >>> If I am updated, update CORTEX.md and the parent folder's CORTEX.md <<<
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// input: UiServiceDeps
|
|
2
|
+
// output: createUiService(deps): UiService — facade routing scope/op strings to per-module handlers
|
|
3
|
+
// pos: transport-agnostic UI service facade
|
|
4
|
+
import { handleProjectsList } from './query/projects.js';
|
|
5
|
+
import { handleSessionsList } from './query/sessions.js';
|
|
6
|
+
import { handleThreadsList } from './query/threads.js';
|
|
7
|
+
import { handleTasksList } from './query/tasks.js';
|
|
8
|
+
import { handleSchedulesList } from './query/schedules.js';
|
|
9
|
+
import { handleExecutionsList } from './query/executions.js';
|
|
10
|
+
import { handleCostSummary } from './query/cost.js';
|
|
11
|
+
import { handleCancelThread } from './mutate/threads.js';
|
|
12
|
+
import { handleCancelExecution } from './mutate/executions.js';
|
|
13
|
+
import { handlePauseSchedule, handleResumeSchedule, handleRemoveSchedule, } from './mutate/schedules.js';
|
|
14
|
+
import { handleClaimTask, handleUnclaimTask, handleCompleteTask, handleBlockTask, handleUnblockTask, } from './mutate/tasks.js';
|
|
15
|
+
import { createSubscription } from './subscribe.js';
|
|
16
|
+
const queryHandlers = {
|
|
17
|
+
'projects.list': (deps) => handleProjectsList(deps),
|
|
18
|
+
'sessions.list': (deps, params) => handleSessionsList(deps, params),
|
|
19
|
+
'threads.list': (deps, params) => handleThreadsList(deps, params),
|
|
20
|
+
'tasks.list': (deps, params) => handleTasksList(deps, params),
|
|
21
|
+
'schedules.list': (deps, params) => handleSchedulesList(deps, params),
|
|
22
|
+
'executions.list': (deps, params) => handleExecutionsList(deps, params),
|
|
23
|
+
'cost.summary': (deps, params) => handleCostSummary(deps, params),
|
|
24
|
+
};
|
|
25
|
+
const mutateHandlers = {
|
|
26
|
+
'threads.cancel': (deps, args) => handleCancelThread(deps, args),
|
|
27
|
+
'executions.cancel': (deps, args) => handleCancelExecution(deps, args),
|
|
28
|
+
'schedules.pause': (deps, args) => handlePauseSchedule(deps, args),
|
|
29
|
+
'schedules.resume': (deps, args) => handleResumeSchedule(deps, args),
|
|
30
|
+
'schedules.remove': (deps, args) => handleRemoveSchedule(deps, args),
|
|
31
|
+
'tasks.claim': (deps, args) => handleClaimTask(deps, args),
|
|
32
|
+
'tasks.unclaim': (deps, args) => handleUnclaimTask(deps, args),
|
|
33
|
+
'tasks.complete': (deps, args) => handleCompleteTask(deps, args),
|
|
34
|
+
'tasks.block': (deps, args) => handleBlockTask(deps, args),
|
|
35
|
+
'tasks.unblock': (deps, args) => handleUnblockTask(deps, args),
|
|
36
|
+
};
|
|
37
|
+
export function createUiService(deps) {
|
|
38
|
+
return {
|
|
39
|
+
async query(scope, params) {
|
|
40
|
+
const handler = queryHandlers[scope];
|
|
41
|
+
if (!handler) {
|
|
42
|
+
return { ok: false, code: 'invalid-args', message: `Unknown query scope: ${scope}` };
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const data = await handler(deps, params);
|
|
46
|
+
return { ok: true, data };
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
return { ok: false, code: 'internal', message: err?.message || String(err) };
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async mutate(op, args) {
|
|
53
|
+
const handler = mutateHandlers[op];
|
|
54
|
+
if (!handler) {
|
|
55
|
+
return { ok: false, code: 'invalid-args', message: `Unknown mutate op: ${op}` };
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const result = await handler(deps, args);
|
|
59
|
+
// Publish audit event before returning
|
|
60
|
+
deps.bus.publish({
|
|
61
|
+
type: 'ui.mutate-invoked',
|
|
62
|
+
op,
|
|
63
|
+
args,
|
|
64
|
+
result: result.ok ? { ok: true } : { ok: false, code: result.code },
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
const errResult = { ok: false, code: 'internal', message: err?.message || String(err) };
|
|
70
|
+
deps.bus.publish({
|
|
71
|
+
type: 'ui.mutate-invoked',
|
|
72
|
+
op,
|
|
73
|
+
args,
|
|
74
|
+
result: { ok: false, code: 'internal' },
|
|
75
|
+
});
|
|
76
|
+
return errResult;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
subscribe(filter) {
|
|
80
|
+
return createSubscription(deps.bus, filter);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|