@cortex-agent/server 2026.5.25-1 → 2026.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +301 -29
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -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/status-format.js +3 -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/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 +120 -10
- package/dist/domain/scheduling/schedule-command.js +16 -15
- 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/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.js +26 -0
- 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 +15 -1
- package/dist/domain/threads/prompt-builder.js +41 -2
- 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 +94 -5
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +25 -2
- package/dist/entry/init.js +211 -64
- 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 +48 -17
- 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.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +100 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +24 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +39 -47
- package/dist/orchestration/routing/commands/channel.js +24 -11
- package/dist/orchestration/routing/commands/cost.js +2 -1
- package/dist/orchestration/routing/commands/device.js +3 -2
- package/dist/orchestration/routing/commands/dispatch.js +6 -5
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +11 -10
- package/dist/orchestration/routing/commands/mode.js +19 -18
- package/dist/orchestration/routing/commands/nvtop.js +10 -9
- package/dist/orchestration/routing/commands/sendfile.js +7 -6
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +17 -33
- package/dist/orchestration/routing/commands/tail.js +4 -3
- package/dist/orchestration/routing/commands/task.js +4 -3
- package/dist/orchestration/routing/commands/thread-handlers.js +16 -6
- 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 +7 -6
- 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 +3 -2
- 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.js +95 -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,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: Tab definitions + sendFrame + dashState
|
|
3
|
+
// output: Tab-cycled dashboard panel — Tab key cycles, ↑/↓ navigates rows
|
|
4
|
+
// pos: Dashboard tab container for M5 side panel
|
|
5
|
+
import React, { useRef } from 'react';
|
|
6
|
+
import { Box, Text, useInput } from 'ink';
|
|
7
|
+
import { TAB_SCOPES } from '../hooks/useDashboardData.js';
|
|
8
|
+
import { DashboardThreadsTab } from './DashboardThreadsTab.js';
|
|
9
|
+
import { DashboardTasksTab } from './DashboardTasksTab.js';
|
|
10
|
+
import { DashboardSchedulesTab } from './DashboardSchedulesTab.js';
|
|
11
|
+
import { DashboardExecutionsTab } from './DashboardExecutionsTab.js';
|
|
12
|
+
import { DashboardCostTab } from './DashboardCostTab.js';
|
|
13
|
+
export const DASHBOARD_TABS = [
|
|
14
|
+
{ key: 'threads', label: 'Threads' },
|
|
15
|
+
{ key: 'tasks', label: 'Tasks' },
|
|
16
|
+
{ key: 'schedules', label: 'Schedules' },
|
|
17
|
+
{ key: 'executions', label: 'Executions' },
|
|
18
|
+
{ key: 'cost', label: 'Cost' },
|
|
19
|
+
];
|
|
20
|
+
// ── Tab content renderer ──
|
|
21
|
+
function TabContent({ tab, active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, }) {
|
|
22
|
+
const initialQuerySent = useRef(false);
|
|
23
|
+
// Initial query + subscribe (runs once per tab mount)
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
const scope = TAB_SCOPES[tab];
|
|
26
|
+
if (!scope)
|
|
27
|
+
return;
|
|
28
|
+
const queryId = scope.queryId;
|
|
29
|
+
if (!initialQuerySent.current) {
|
|
30
|
+
initialQuerySent.current = true;
|
|
31
|
+
// Send query for initial data
|
|
32
|
+
sendFrame({ type: 'ui.query', id: queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
|
|
33
|
+
onMarkPending(tab);
|
|
34
|
+
// Subscribe to events
|
|
35
|
+
sendFrame({ type: 'ui.subscribe', id: queryId, filter: { events: scope.events, projectId } });
|
|
36
|
+
onRegisterSubscription(queryId, tab);
|
|
37
|
+
}
|
|
38
|
+
// Cleanup on unmount
|
|
39
|
+
return () => {
|
|
40
|
+
sendFrame({ type: 'ui.unsubscribe', id: queryId });
|
|
41
|
+
onUnregisterSubscription(queryId);
|
|
42
|
+
initialQuerySent.current = false;
|
|
43
|
+
};
|
|
44
|
+
}, [tab, projectId, sendFrame, onMarkPending, onRegisterSubscription, onUnregisterSubscription]);
|
|
45
|
+
// Re-fetch when loading is triggered by a subscription event
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
const scope = TAB_SCOPES[tab];
|
|
48
|
+
if (!scope || !initialQuerySent.current)
|
|
49
|
+
return;
|
|
50
|
+
if (dashState.tabs[tab].loading) {
|
|
51
|
+
sendFrame({ type: 'ui.query', id: scope.queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
|
|
52
|
+
onMarkPending(tab);
|
|
53
|
+
}
|
|
54
|
+
}, [dashState.tabs[tab].loading, tab, projectId, sendFrame, onMarkPending]);
|
|
55
|
+
switch (tab) {
|
|
56
|
+
case 'threads':
|
|
57
|
+
return _jsx(DashboardThreadsTab, { data: dashState.tabs.threads, mutate: mutate, active: active });
|
|
58
|
+
case 'tasks':
|
|
59
|
+
return _jsx(DashboardTasksTab, { data: dashState.tabs.tasks, mutate: mutate, projectId: projectId ?? undefined, active: active });
|
|
60
|
+
case 'schedules':
|
|
61
|
+
return _jsx(DashboardSchedulesTab, { data: dashState.tabs.schedules, mutate: mutate, active: active });
|
|
62
|
+
case 'executions':
|
|
63
|
+
return _jsx(DashboardExecutionsTab, { data: dashState.tabs.executions, mutate: mutate, active: active });
|
|
64
|
+
case 'cost':
|
|
65
|
+
return _jsx(DashboardCostTab, { data: dashState.tabs.cost });
|
|
66
|
+
default:
|
|
67
|
+
return _jsx(Text, { dimColor: true, children: "Unknown tab" });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// ── Component ──
|
|
71
|
+
export function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, }) {
|
|
72
|
+
useInput((_input, key) => {
|
|
73
|
+
if (key.tab) {
|
|
74
|
+
const currentIdx = DASHBOARD_TABS.findIndex(t => t.key === activeTab);
|
|
75
|
+
const nextIdx = (currentIdx + 1) % DASHBOARD_TABS.length;
|
|
76
|
+
onSetActiveTab(DASHBOARD_TABS[nextIdx].key);
|
|
77
|
+
}
|
|
78
|
+
}, { isActive: active });
|
|
79
|
+
return (_jsxs(Box, { flexDirection: "column", width: "100%", children: [_jsx(Box, { children: DASHBOARD_TABS.map(t => (_jsx(Box, { paddingX: 1, borderStyle: t.key === activeTab ? 'bold' : 'single', borderDimColor: t.key !== activeTab, children: _jsx(Text, { bold: t.key === activeTab, children: t.label }) }, t.key))) }), _jsx(Box, { flexDirection: "column", flexGrow: 1, paddingX: 1, children: _jsx(TabContent, { tab: activeTab, active: active, sendFrame: sendFrame, mutate: mutate, projectId: projectId, dashState: dashState, onMarkPending: onMarkPending, onRegisterSubscription: onRegisterSubscription, onUnregisterSubscription: onUnregisterSubscription }) })] }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
export function DashboardCostTab({ data }) {
|
|
4
|
+
if (data.loading && data.data.length === 0) {
|
|
5
|
+
return _jsx(Text, { dimColor: true, children: "Loading cost summary..." });
|
|
6
|
+
}
|
|
7
|
+
if (data.error) {
|
|
8
|
+
return _jsxs(Text, { color: "red", children: ["Error: ", data.error] });
|
|
9
|
+
}
|
|
10
|
+
if (!data.data || (Array.isArray(data.data) && data.data.length === 0)) {
|
|
11
|
+
return _jsx(Text, { dimColor: true, children: "No cost data" });
|
|
12
|
+
}
|
|
13
|
+
// data.data might be a CostSummary object — handle both array and object
|
|
14
|
+
const costData = Array.isArray(data.data) ? data.data[0] : data.data;
|
|
15
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "Cost Summary" }) }), costData?.totalCost != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Total: " }), _jsxs(Text, { bold: true, children: ["$", typeof costData.totalCost === 'number' ? costData.totalCost.toFixed(4) : costData.totalCost] })] })) : null, costData?.monthlyCost != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "This month: " }), _jsxs(Text, { bold: true, children: ["$", typeof costData.monthlyCost === 'number' ? costData.monthlyCost.toFixed(4) : costData.monthlyCost] })] })) : null, costData?.dailyCost != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Today: " }), _jsxs(Text, { bold: true, children: ["$", typeof costData.dailyCost === 'number' ? costData.dailyCost.toFixed(4) : costData.dailyCost] })] })) : null, costData?.models && typeof costData.models === 'object' ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "By model:" }), Object.entries(costData.models).map(([model, cost]) => (_jsxs(Box, { marginLeft: 1, children: [_jsxs(Text, { dimColor: true, children: [model, ": "] }), _jsxs(Text, { children: ["$", typeof cost === 'number' ? cost.toFixed(4) : String(cost)] })] }, model)))] })) : null, costData?.budgetRemaining != null ? (_jsxs(Box, { marginTop: 1, children: [_jsx(Text, { children: "Budget remaining: " }), _jsxs(Text, { color: costData.budgetRemaining < 1 ? 'red' : 'green', children: ["$", typeof costData.budgetRemaining === 'number' ? costData.budgetRemaining.toFixed(4) : costData.budgetRemaining] })] })) : null, costData?.totalCost == null && costData?.monthlyCost == null && (!costData?.models || Object.keys(costData.models).length === 0) ? (_jsx(Text, { dimColor: true, children: "No cost summary available" })) : null] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TabData } from '../hooks/useDashboardData.js';
|
|
3
|
+
import type { MutateResult } from '../hooks/useMutate.js';
|
|
4
|
+
interface DashboardExecutionsTabProps {
|
|
5
|
+
data: TabData;
|
|
6
|
+
mutate?: (op: string, args: Record<string, unknown>) => Promise<MutateResult>;
|
|
7
|
+
/** Whether the dashboard owns the keyboard. Defaults true for standalone tests. */
|
|
8
|
+
active?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function DashboardExecutionsTab({ data, mutate, active }: DashboardExecutionsTabProps): React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: TabData for executions tab + optional mutate for cancel
|
|
3
|
+
// output: Executions list — status badge + type + machine + duration + cost + cancel via [c]
|
|
4
|
+
// pos: Dashboard tab: execution list with per-row cancel mutation
|
|
5
|
+
import { useState, useCallback, useRef, useEffect } from 'react';
|
|
6
|
+
import { Box, Text, useInput } from 'ink';
|
|
7
|
+
import { ConfirmModal } from './ConfirmModal.js';
|
|
8
|
+
export function DashboardExecutionsTab({ data, mutate, active = true }) {
|
|
9
|
+
const [focusedIndex, setFocusedIndex] = useState(0);
|
|
10
|
+
const [showConfirm, setShowConfirm] = useState(false);
|
|
11
|
+
const [notFoundMsg, setNotFoundMsg] = useState(null);
|
|
12
|
+
const notFoundTimerRef = useRef(null);
|
|
13
|
+
// Cleanup not-found timer on unmount
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
return () => {
|
|
16
|
+
if (notFoundTimerRef.current)
|
|
17
|
+
clearTimeout(notFoundTimerRef.current);
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
// Capture focusedIndex at confirm trigger (stable across async mutate)
|
|
21
|
+
const confirmIndexRef = useRef(0);
|
|
22
|
+
useInput((input, key) => {
|
|
23
|
+
if (showConfirm)
|
|
24
|
+
return;
|
|
25
|
+
if (key.upArrow) {
|
|
26
|
+
setFocusedIndex(i => Math.max(0, i - 1));
|
|
27
|
+
}
|
|
28
|
+
else if (key.downArrow) {
|
|
29
|
+
setFocusedIndex(i => Math.min(data.data.length - 1, i + 1));
|
|
30
|
+
}
|
|
31
|
+
else if (input === 'c') {
|
|
32
|
+
confirmIndexRef.current = focusedIndex;
|
|
33
|
+
setShowConfirm(true);
|
|
34
|
+
}
|
|
35
|
+
}, { isActive: active });
|
|
36
|
+
const handleConfirm = useCallback(async () => {
|
|
37
|
+
setShowConfirm(false);
|
|
38
|
+
if (!mutate)
|
|
39
|
+
return;
|
|
40
|
+
const exec = data.data[confirmIndexRef.current];
|
|
41
|
+
if (!exec?.id)
|
|
42
|
+
return;
|
|
43
|
+
const result = await mutate('executions.cancel', { executionId: exec.id });
|
|
44
|
+
if (!result.ok) {
|
|
45
|
+
const err = result;
|
|
46
|
+
if (err.error.code === 'not-found') {
|
|
47
|
+
setNotFoundMsg({ index: confirmIndexRef.current, message: 'not found' });
|
|
48
|
+
if (notFoundTimerRef.current)
|
|
49
|
+
clearTimeout(notFoundTimerRef.current);
|
|
50
|
+
notFoundTimerRef.current = setTimeout(() => setNotFoundMsg(null), 5000);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ok: subscribe will refresh data — no explicit action needed
|
|
54
|
+
}, [mutate, data.data]);
|
|
55
|
+
const handleCancel = useCallback(() => {
|
|
56
|
+
setShowConfirm(false);
|
|
57
|
+
}, []);
|
|
58
|
+
if (data.loading && data.data.length === 0) {
|
|
59
|
+
return _jsx(Text, { dimColor: true, children: "Loading executions..." });
|
|
60
|
+
}
|
|
61
|
+
if (data.error) {
|
|
62
|
+
return _jsxs(Text, { color: "red", children: ["Error: ", data.error] });
|
|
63
|
+
}
|
|
64
|
+
if (data.data.length === 0) {
|
|
65
|
+
return _jsx(Text, { dimColor: true, children: "No executions" });
|
|
66
|
+
}
|
|
67
|
+
// Clamp focused index to valid range
|
|
68
|
+
const safeFocused = Math.min(focusedIndex, data.data.length - 1);
|
|
69
|
+
const focusedExec = showConfirm ? data.data[confirmIndexRef.current] : null;
|
|
70
|
+
// Build ConfirmModal body from focused execution fields
|
|
71
|
+
let confirmBody = '';
|
|
72
|
+
if (focusedExec) {
|
|
73
|
+
const parts = [focusedExec.type ?? 'local'];
|
|
74
|
+
if (focusedExec.machine)
|
|
75
|
+
parts.push(`@${focusedExec.machine}`);
|
|
76
|
+
if (focusedExec.durationMs != null)
|
|
77
|
+
parts.push(`${(focusedExec.durationMs / 1000).toFixed(1)}s`);
|
|
78
|
+
if (focusedExec.cost != null) {
|
|
79
|
+
parts.push(`$${typeof focusedExec.cost === 'number' ? focusedExec.cost.toFixed(4) : focusedExec.cost}`);
|
|
80
|
+
}
|
|
81
|
+
confirmBody = parts.join(' | ');
|
|
82
|
+
}
|
|
83
|
+
return (_jsxs(Box, { flexDirection: "column", children: [data.data.map((exec, i) => (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [_jsx(Text, { children: i === safeFocused ? '>' : ' ' }), _jsx(Text, { children: " " }), _jsx(ExecStatusIcon, { status: exec.status }), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: exec.type ?? 'local' }), exec.machine ? _jsxs(Text, { dimColor: true, children: [" @", exec.machine] }) : null] }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: [exec.durationMs ? `${(exec.durationMs / 1000).toFixed(1)}s` : '', exec.cost != null ? ` | $${typeof exec.cost === 'number' ? exec.cost.toFixed(4) : exec.cost}` : '', exec.finishedAt ? ` | ${new Date(exec.finishedAt).toLocaleString()}` : ''] }) }), notFoundMsg?.index === i ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "red", children: notFoundMsg.message }) })) : null] }, exec.id ?? i))), showConfirm && focusedExec ? (_jsx(ConfirmModal, { title: "Cancel execution?", body: confirmBody, onConfirm: handleConfirm, onCancel: handleCancel })) : null] }));
|
|
84
|
+
}
|
|
85
|
+
function ExecStatusIcon({ status }) {
|
|
86
|
+
switch (status) {
|
|
87
|
+
case 'running': return _jsx(Text, { color: "green", children: "\u25B6" });
|
|
88
|
+
case 'completed': return _jsx(Text, { color: "blue", children: "\u2713" });
|
|
89
|
+
case 'failed': return _jsx(Text, { color: "red", children: "\u2717" });
|
|
90
|
+
case 'cancelled': return _jsx(Text, { dimColor: true, children: "\u2298" });
|
|
91
|
+
case 'stale': return _jsx(Text, { color: "yellow", children: "\u25F7" });
|
|
92
|
+
default: return _jsx(Text, { dimColor: true, children: "?" });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TabData } from '../hooks/useDashboardData.js';
|
|
3
|
+
import type { MutateResult } from '../hooks/useMutate.js';
|
|
4
|
+
interface DashboardSchedulesTabProps {
|
|
5
|
+
data: TabData;
|
|
6
|
+
mutate: (op: string, args: Record<string, unknown>) => Promise<MutateResult>;
|
|
7
|
+
/** Whether the dashboard owns the keyboard. Defaults true for standalone tests. */
|
|
8
|
+
active?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function DashboardSchedulesTab({ data, mutate, active }: DashboardSchedulesTabProps): React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: TabData for schedules tab + mutate function
|
|
3
|
+
// output: Schedules list — type badge + message + nextRun + paused indicator + per-row mutations
|
|
4
|
+
// pos: Dashboard tab: interactive schedule list with pause/resume/remove via ui.mutate
|
|
5
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
6
|
+
import { Box, Text, useInput } from 'ink';
|
|
7
|
+
import { ConfirmModal } from './ConfirmModal.js';
|
|
8
|
+
export function DashboardSchedulesTab({ data, mutate, active = true }) {
|
|
9
|
+
if (data.loading && data.data.length === 0) {
|
|
10
|
+
return _jsx(Text, { dimColor: true, children: "Loading schedules..." });
|
|
11
|
+
}
|
|
12
|
+
if (data.error) {
|
|
13
|
+
return _jsxs(Text, { color: "red", children: ["Error: ", data.error] });
|
|
14
|
+
}
|
|
15
|
+
if (data.data.length === 0) {
|
|
16
|
+
return _jsx(Text, { dimColor: true, children: "No schedules" });
|
|
17
|
+
}
|
|
18
|
+
return _jsx(SchedulesList, { data: data, mutate: mutate, active: active });
|
|
19
|
+
}
|
|
20
|
+
function SchedulesList({ data, mutate, active = true }) {
|
|
21
|
+
const schedules = data.data;
|
|
22
|
+
const [focusedRowIndex, setFocusedRowIndex] = useState(0);
|
|
23
|
+
const [removingScheduleId, setRemovingScheduleId] = useState(null);
|
|
24
|
+
// Refs for stale-closure-safe access inside useInput / callbacks
|
|
25
|
+
const removingScheduleIdRef = useRef(null);
|
|
26
|
+
const focusedRowIndexRef = useRef(0);
|
|
27
|
+
focusedRowIndexRef.current = focusedRowIndex;
|
|
28
|
+
const mutateRef = useRef(mutate);
|
|
29
|
+
mutateRef.current = mutate;
|
|
30
|
+
// Ensure focusedRowIndex is valid when data changes
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (schedules.length > 0 && focusedRowIndex >= schedules.length) {
|
|
33
|
+
setFocusedRowIndex(Math.max(0, schedules.length - 1));
|
|
34
|
+
}
|
|
35
|
+
}, [schedules.length, focusedRowIndex]);
|
|
36
|
+
// ── Error state with 5s auto-clear ──
|
|
37
|
+
const [errorState, setErrorState] = useState(null);
|
|
38
|
+
const errorTimerRef = useRef(null);
|
|
39
|
+
const showError = useCallback((scheduleId, code, message) => {
|
|
40
|
+
if (errorTimerRef.current)
|
|
41
|
+
clearTimeout(errorTimerRef.current);
|
|
42
|
+
setErrorState({ scheduleId, code, message });
|
|
43
|
+
errorTimerRef.current = setTimeout(() => {
|
|
44
|
+
setErrorState(null);
|
|
45
|
+
errorTimerRef.current = null;
|
|
46
|
+
}, 5000);
|
|
47
|
+
}, []);
|
|
48
|
+
// Cleanup timer on unmount
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
return () => {
|
|
51
|
+
if (errorTimerRef.current)
|
|
52
|
+
clearTimeout(errorTimerRef.current);
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
// ── Mutate result handler ──
|
|
56
|
+
const handleResult = useCallback((scheduleId) => (result) => {
|
|
57
|
+
if (!result.ok) {
|
|
58
|
+
const err = result;
|
|
59
|
+
showError(scheduleId, err.error.code, err.error.message);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
setErrorState(prev => prev?.scheduleId === scheduleId ? null : prev);
|
|
63
|
+
}
|
|
64
|
+
}, [showError]);
|
|
65
|
+
// ── Keyboard handler ──
|
|
66
|
+
const isInputActive = active && removingScheduleId === null && schedules.length > 0;
|
|
67
|
+
useInput((input, key) => {
|
|
68
|
+
if (removingScheduleIdRef.current !== null)
|
|
69
|
+
return;
|
|
70
|
+
if (key.upArrow) {
|
|
71
|
+
setFocusedRowIndex(prev => Math.max(0, prev - 1));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (key.downArrow) {
|
|
75
|
+
setFocusedRowIndex(prev => Math.min(schedules.length - 1, prev + 1));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const sched = schedules[focusedRowIndexRef.current];
|
|
79
|
+
if (!sched)
|
|
80
|
+
return;
|
|
81
|
+
if (input === 'p') {
|
|
82
|
+
mutateRef.current('schedules.pause', { scheduleId: sched.id }).then(handleResult(sched.id));
|
|
83
|
+
}
|
|
84
|
+
else if (input === 'r') {
|
|
85
|
+
mutateRef.current('schedules.resume', { scheduleId: sched.id }).then(handleResult(sched.id));
|
|
86
|
+
}
|
|
87
|
+
else if (input === 'x') {
|
|
88
|
+
setRemovingScheduleId(sched.id);
|
|
89
|
+
removingScheduleIdRef.current = sched.id;
|
|
90
|
+
}
|
|
91
|
+
}, { isActive: isInputActive });
|
|
92
|
+
// ── Build schedule rows ──
|
|
93
|
+
const rows = schedules.map((sched, i) => {
|
|
94
|
+
const isFocused = i === focusedRowIndex;
|
|
95
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [isFocused ? _jsx(Text, { bold: true, children: '> ' }) : _jsx(Text, { children: " " }), _jsx(ScheduleTypeBadge, { type: sched.type, paused: sched.paused, focused: isFocused }), _jsx(Text, { children: " " }), _jsxs(Text, { bold: isFocused, dimColor: !isFocused, children: [String(sched.message ?? '').slice(0, 25), (sched.message ?? '').length > 25 ? '…' : ''] })] }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: sched.paused
|
|
96
|
+
? `paused by ${sched.pausedBy ?? '?'}`
|
|
97
|
+
: `next: ${sched.nextRun ? new Date(sched.nextRun).toLocaleString() : 'never'}` }) }), isFocused ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { children: "[p] Pause [r] Resume [x] Remove" }) })) : null, errorState?.scheduleId === sched.id ? (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "red", children: [errorState.code, ": ", errorState.message] }) })) : null] }, sched.id ?? i));
|
|
98
|
+
});
|
|
99
|
+
// ── Remove confirmation modal (inline, consistent with ExecutionsTab pattern) ──
|
|
100
|
+
let confirmModal = null;
|
|
101
|
+
if (removingScheduleId !== null) {
|
|
102
|
+
const sched = schedules.find(s => s.id === removingScheduleId);
|
|
103
|
+
const body = sched
|
|
104
|
+
? `${sched.type}: ${sched.message ?? ''} | next: ${sched.nextRun ? new Date(sched.nextRun).toLocaleString() : 'never'}`
|
|
105
|
+
: '';
|
|
106
|
+
confirmModal = (_jsx(ConfirmModal, { title: "Remove schedule?", body: body, onConfirm: () => {
|
|
107
|
+
const id = removingScheduleIdRef.current;
|
|
108
|
+
if (id) {
|
|
109
|
+
mutateRef.current('schedules.remove', { scheduleId: id }).then(handleResult(id));
|
|
110
|
+
}
|
|
111
|
+
setRemovingScheduleId(null);
|
|
112
|
+
removingScheduleIdRef.current = null;
|
|
113
|
+
}, onCancel: () => {
|
|
114
|
+
setRemovingScheduleId(null);
|
|
115
|
+
removingScheduleIdRef.current = null;
|
|
116
|
+
} }));
|
|
117
|
+
}
|
|
118
|
+
return (_jsxs(Box, { flexDirection: "column", children: [rows, confirmModal] }));
|
|
119
|
+
}
|
|
120
|
+
function ScheduleTypeBadge({ type, paused, focused }) {
|
|
121
|
+
const color = paused ? 'yellow' : 'green';
|
|
122
|
+
const label = paused ? `⏸ ${type}` : `▶ ${type}`;
|
|
123
|
+
return _jsx(Text, { color: color, bold: focused, children: label });
|
|
124
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TabData } from '../hooks/useDashboardData.js';
|
|
3
|
+
import type { MutateResult } from '../hooks/useMutate.js';
|
|
4
|
+
interface DashboardTasksTabProps {
|
|
5
|
+
data: TabData;
|
|
6
|
+
mutate?: (op: string, args: Record<string, unknown>) => Promise<MutateResult>;
|
|
7
|
+
projectId?: string;
|
|
8
|
+
/** Whether the dashboard owns the keyboard. Defaults true for standalone tests. */
|
|
9
|
+
active?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function DashboardTasksTab({ data, mutate, projectId, active }: DashboardTasksTabProps): React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: TabData for tasks tab + optional mutate + projectId
|
|
3
|
+
// output: Tasks list — status badge + priority + text + claimed indicator + per-row mutations
|
|
4
|
+
// pos: Dashboard tab: interactive task list with claim/unclaim/complete/block/unblock via ui.mutate
|
|
5
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
6
|
+
import { Box, Text, useInput } from 'ink';
|
|
7
|
+
import { ConfirmModal } from './ConfirmModal.js';
|
|
8
|
+
// ── Component ──
|
|
9
|
+
export function DashboardTasksTab({ data, mutate, projectId, active = true }) {
|
|
10
|
+
if (data.loading && data.data.length === 0) {
|
|
11
|
+
return _jsx(Text, { dimColor: true, children: "Loading tasks..." });
|
|
12
|
+
}
|
|
13
|
+
if (data.error) {
|
|
14
|
+
return _jsxs(Text, { color: "red", children: ["Error: ", data.error] });
|
|
15
|
+
}
|
|
16
|
+
if (data.data.length === 0) {
|
|
17
|
+
return _jsx(Text, { dimColor: true, children: "No tasks" });
|
|
18
|
+
}
|
|
19
|
+
return _jsx(TasksList, { data: data, mutate: mutate, projectId: projectId, active: active });
|
|
20
|
+
}
|
|
21
|
+
// ── Tasks List ──
|
|
22
|
+
function TasksList({ data, mutate, projectId, active = true }) {
|
|
23
|
+
const tasks = data.data;
|
|
24
|
+
const [focusedIndex, setFocusedIndex] = useState(0);
|
|
25
|
+
const [confirmingIndex, setConfirmingIndex] = useState(null);
|
|
26
|
+
const [confirmMode, setConfirmMode] = useState(null);
|
|
27
|
+
// Refs for stale-closure-safe access inside useInput / callbacks
|
|
28
|
+
const confirmingIndexRef = useRef(null);
|
|
29
|
+
const confirmModeRef = useRef(null);
|
|
30
|
+
const focusedIndexRef = useRef(0);
|
|
31
|
+
focusedIndexRef.current = focusedIndex;
|
|
32
|
+
const mutateRef = useRef(mutate);
|
|
33
|
+
mutateRef.current = mutate;
|
|
34
|
+
const projectIdRef = useRef(projectId);
|
|
35
|
+
projectIdRef.current = projectId;
|
|
36
|
+
// ── Error state with 5s auto-clear ──
|
|
37
|
+
const [errorState, setErrorState] = useState(null);
|
|
38
|
+
const [lockBusyRows, setLockBusyRows] = useState(new Set());
|
|
39
|
+
const errorTimerRef = useRef(null);
|
|
40
|
+
const lockBusyTimerRef = useRef(null);
|
|
41
|
+
const showError = useCallback((index, code, message) => {
|
|
42
|
+
if (errorTimerRef.current)
|
|
43
|
+
clearTimeout(errorTimerRef.current);
|
|
44
|
+
setErrorState({ index, code, message });
|
|
45
|
+
errorTimerRef.current = setTimeout(() => {
|
|
46
|
+
setErrorState(null);
|
|
47
|
+
errorTimerRef.current = null;
|
|
48
|
+
}, 5000);
|
|
49
|
+
}, []);
|
|
50
|
+
const showLockBusy = useCallback((index) => {
|
|
51
|
+
if (lockBusyTimerRef.current)
|
|
52
|
+
clearTimeout(lockBusyTimerRef.current);
|
|
53
|
+
setLockBusyRows(new Set([index]));
|
|
54
|
+
lockBusyTimerRef.current = setTimeout(() => {
|
|
55
|
+
setLockBusyRows(new Set());
|
|
56
|
+
lockBusyTimerRef.current = null;
|
|
57
|
+
}, 5000);
|
|
58
|
+
}, []);
|
|
59
|
+
// Cleanup timers on unmount
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
return () => {
|
|
62
|
+
if (errorTimerRef.current)
|
|
63
|
+
clearTimeout(errorTimerRef.current);
|
|
64
|
+
if (lockBusyTimerRef.current)
|
|
65
|
+
clearTimeout(lockBusyTimerRef.current);
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
// Clamp focused index when data shrinks
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (tasks.length > 0 && focusedIndex >= tasks.length) {
|
|
71
|
+
setFocusedIndex(tasks.length - 1);
|
|
72
|
+
}
|
|
73
|
+
}, [tasks.length, focusedIndex]);
|
|
74
|
+
// ── Mutate result handler ──
|
|
75
|
+
const handleResult = useCallback((index) => (result) => {
|
|
76
|
+
if (!result.ok) {
|
|
77
|
+
const err = result;
|
|
78
|
+
if (err.error.code === 'task-lock-busy') {
|
|
79
|
+
showLockBusy(index);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
showError(index, err.error.code, err.error.message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Success: subscribe will refresh data — no explicit action needed
|
|
86
|
+
}, [showError, showLockBusy]);
|
|
87
|
+
// ── Mutate helpers ──
|
|
88
|
+
const doMutate = useCallback((op, taskId, extra) => {
|
|
89
|
+
const fn = mutateRef.current;
|
|
90
|
+
if (!fn)
|
|
91
|
+
return;
|
|
92
|
+
const args = { projectId: projectIdRef.current, taskId, ...extra };
|
|
93
|
+
fn(op, args).then(handleResult(focusedIndexRef.current));
|
|
94
|
+
}, [handleResult]);
|
|
95
|
+
// ── Keyboard handler ──
|
|
96
|
+
const isInputActive = active && confirmingIndex === null && tasks.length > 0;
|
|
97
|
+
useInput((input, key) => {
|
|
98
|
+
if (confirmingIndexRef.current !== null)
|
|
99
|
+
return;
|
|
100
|
+
if (key.upArrow) {
|
|
101
|
+
setFocusedIndex(prev => Math.max(0, prev - 1));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (key.downArrow) {
|
|
105
|
+
setFocusedIndex(prev => Math.min(tasks.length - 1, prev + 1));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const task = tasks[focusedIndexRef.current];
|
|
109
|
+
if (!task)
|
|
110
|
+
return;
|
|
111
|
+
if (input === 'c' && !key.ctrl) {
|
|
112
|
+
doMutate('tasks.claim', task.id);
|
|
113
|
+
}
|
|
114
|
+
else if (input === 'u') {
|
|
115
|
+
doMutate('tasks.unclaim', task.id);
|
|
116
|
+
}
|
|
117
|
+
else if (input === 'd' && !key.ctrl) {
|
|
118
|
+
confirmingIndexRef.current = focusedIndexRef.current;
|
|
119
|
+
confirmModeRef.current = 'complete';
|
|
120
|
+
setConfirmingIndex(focusedIndexRef.current);
|
|
121
|
+
setConfirmMode('complete');
|
|
122
|
+
}
|
|
123
|
+
else if (input === 'b' && !key.shift) {
|
|
124
|
+
confirmingIndexRef.current = focusedIndexRef.current;
|
|
125
|
+
confirmModeRef.current = 'block';
|
|
126
|
+
setConfirmingIndex(focusedIndexRef.current);
|
|
127
|
+
setConfirmMode('block');
|
|
128
|
+
}
|
|
129
|
+
else if (input === 'B' || (input === 'b' && key.shift)) {
|
|
130
|
+
doMutate('tasks.unblock', task.id);
|
|
131
|
+
}
|
|
132
|
+
}, { isActive: isInputActive });
|
|
133
|
+
// ── ConfirmModal rendering ──
|
|
134
|
+
if (confirmingIndex !== null && confirmMode) {
|
|
135
|
+
const task = tasks[confirmingIndex];
|
|
136
|
+
if (!task) {
|
|
137
|
+
// Safety: clear invalid state
|
|
138
|
+
setConfirmingIndex(null);
|
|
139
|
+
setConfirmMode(null);
|
|
140
|
+
}
|
|
141
|
+
else if (confirmMode === 'complete') {
|
|
142
|
+
return (_jsx(ConfirmModal, { title: "Mark task done?", body: String(task.text ?? ''), onConfirm: () => {
|
|
143
|
+
const idx = confirmingIndexRef.current;
|
|
144
|
+
if (idx !== null) {
|
|
145
|
+
doMutate('tasks.complete', tasks[idx].id);
|
|
146
|
+
}
|
|
147
|
+
confirmingIndexRef.current = null;
|
|
148
|
+
confirmModeRef.current = null;
|
|
149
|
+
setConfirmingIndex(null);
|
|
150
|
+
setConfirmMode(null);
|
|
151
|
+
}, onCancel: () => {
|
|
152
|
+
confirmingIndexRef.current = null;
|
|
153
|
+
confirmModeRef.current = null;
|
|
154
|
+
setConfirmingIndex(null);
|
|
155
|
+
setConfirmMode(null);
|
|
156
|
+
} }));
|
|
157
|
+
}
|
|
158
|
+
else if (confirmMode === 'block') {
|
|
159
|
+
return (_jsx(ConfirmModal, { title: "Block task", body: String(task.text ?? ''), reasonInput: { label: 'Block reason' }, onConfirm: (reason) => {
|
|
160
|
+
const idx = confirmingIndexRef.current;
|
|
161
|
+
if (idx !== null) {
|
|
162
|
+
doMutate('tasks.block', tasks[idx].id, { reason });
|
|
163
|
+
}
|
|
164
|
+
confirmingIndexRef.current = null;
|
|
165
|
+
confirmModeRef.current = null;
|
|
166
|
+
setConfirmingIndex(null);
|
|
167
|
+
setConfirmMode(null);
|
|
168
|
+
}, onCancel: () => {
|
|
169
|
+
confirmingIndexRef.current = null;
|
|
170
|
+
confirmModeRef.current = null;
|
|
171
|
+
setConfirmingIndex(null);
|
|
172
|
+
setConfirmMode(null);
|
|
173
|
+
} }));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// ── Task list ──
|
|
177
|
+
return (_jsx(Box, { flexDirection: "column", children: tasks.map((task, i) => {
|
|
178
|
+
const isFocused = i === focusedIndex;
|
|
179
|
+
const isLockBusy = lockBusyRows.has(i);
|
|
180
|
+
const hasError = errorState?.index === i;
|
|
181
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Box, { children: [isFocused ? _jsx(Text, { color: "cyan", children: "\u25B8 " }) : _jsx(Text, { children: " " }), _jsx(TaskStatusIcon, { status: task.status }), _jsx(Text, { children: " " }), _jsx(PriorityBadge, { priority: task.priority }), _jsx(Text, { children: " " }), _jsxs(Text, { bold: isFocused, children: [String(task.text ?? '').slice(0, 30), (task.text ?? '').length > 30 ? '…' : ''] })] }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { dimColor: true, children: [task.claimedBy ? `👤 ${task.claimedBy}` : 'unclaimed', task.blockedBy ? ` | blocked: ${task.blockedBy}` : ''] }) }), isFocused && mutate ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { dimColor: true, children: "[c] Claim [u] Unclaim [d] Done [b] Block [B] Unblock" }) })) : null, isLockBusy ? (_jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: "yellow", children: "busy \u2014 another agent holds the lock (auto-expires in 20m)" }) })) : null, hasError ? (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: "red", children: [errorState.code, ": ", errorState.message] }) })) : null] }, task.id ?? i));
|
|
182
|
+
}) }));
|
|
183
|
+
}
|
|
184
|
+
// ── Sub-components ──
|
|
185
|
+
function TaskStatusIcon({ status }) {
|
|
186
|
+
switch (status) {
|
|
187
|
+
case 'done': return _jsx(Text, { color: "green", children: "\u2713" });
|
|
188
|
+
case 'blocked': return _jsx(Text, { color: "red", children: "\u2298" });
|
|
189
|
+
case 'in-progress': return _jsx(Text, { color: "yellow", children: "\u25F7" });
|
|
190
|
+
default: return _jsx(Text, { color: "white", children: "\u25CB" });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function PriorityBadge({ priority }) {
|
|
194
|
+
switch (priority) {
|
|
195
|
+
case 'high': return _jsx(Text, { color: "red", children: "high" });
|
|
196
|
+
case 'medium': return _jsx(Text, { color: "yellow", children: "med" });
|
|
197
|
+
case 'low': return _jsx(Text, { color: "green", children: "low" });
|
|
198
|
+
default: return _jsx(Text, { dimColor: true, children: priority });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TabData } from '../hooks/useDashboardData.js';
|
|
3
|
+
import type { MutateResult } from '../hooks/useMutate.js';
|
|
4
|
+
interface DashboardThreadsTabProps {
|
|
5
|
+
data: TabData;
|
|
6
|
+
mutate?: (op: string, args: Record<string, unknown>) => Promise<MutateResult>;
|
|
7
|
+
/** Whether the dashboard owns the keyboard. Defaults true for standalone tests. */
|
|
8
|
+
active?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function DashboardThreadsTab({ data, mutate, active }: DashboardThreadsTabProps): React.JSX.Element;
|
|
11
|
+
export {};
|