@cortex-agent/server 2026.5.25 → 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/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.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
package/dist/tui/App.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: All components + hooks
|
|
3
|
+
// output: Top-level layout + global key handler for M5 Ink client
|
|
4
|
+
// pos: Main App component wiring all pieces together
|
|
5
|
+
import { useCallback, useRef, useState, useEffect } from 'react';
|
|
6
|
+
import { Box } from 'ink';
|
|
7
|
+
import { Header } from './components/Header.js';
|
|
8
|
+
import { Transcript } from './components/Transcript.js';
|
|
9
|
+
import { InputBox } from './components/InputBox.js';
|
|
10
|
+
import { StatusLine } from './components/StatusLine.js';
|
|
11
|
+
import { SidePanel } from './components/SidePanel.js';
|
|
12
|
+
import { NotificationsBadge, NotificationsModal } from './components/Notifications.js';
|
|
13
|
+
import { ProjectSwitcher } from './components/ProjectSwitcher.js';
|
|
14
|
+
import { useMutate } from './hooks/useMutate.js';
|
|
15
|
+
import { useTranscript } from './hooks/useTranscript.js';
|
|
16
|
+
import { useKeybindings } from './hooks/useKeybindings.js';
|
|
17
|
+
import { useNotifications } from './hooks/useNotifications.js';
|
|
18
|
+
import { useDashboardData } from './hooks/useDashboardData.js';
|
|
19
|
+
import { SessionPicker } from './components/SessionPicker.js';
|
|
20
|
+
import { AskUserModal } from './components/AskUserModal.js';
|
|
21
|
+
import { PlanFeedbackModal } from './components/PlanFeedbackModal.js';
|
|
22
|
+
import { isNotification, isUiQueryResult, isUiEvent, isErrorFrame } from '../platform/tui/protocol.js';
|
|
23
|
+
import { computeFocusZone, isAgentResponseFrame } from './logic.js';
|
|
24
|
+
export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect, onSendCancel, serverVersion, projectId, sessionName, errorMessage, onSetDispatch, resumableSessions, resumePending, onResumeSelect, onResumeCancel, }) {
|
|
25
|
+
// ── Hooks ──
|
|
26
|
+
const [activeModal, setActiveModal] = useState(null);
|
|
27
|
+
const [modalAckErrors, setModalAckErrors] = useState({});
|
|
28
|
+
const transcript = useTranscript({
|
|
29
|
+
onModalOpen: useCallback((frame) => {
|
|
30
|
+
setActiveModal(frame);
|
|
31
|
+
setModalAckErrors({});
|
|
32
|
+
}, []),
|
|
33
|
+
onModalAck: useCallback((frame) => {
|
|
34
|
+
if (frame.errors && Object.keys(frame.errors).length > 0) {
|
|
35
|
+
setModalAckErrors(frame.errors);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
setActiveModal(null);
|
|
39
|
+
setModalAckErrors({});
|
|
40
|
+
}
|
|
41
|
+
}, []),
|
|
42
|
+
});
|
|
43
|
+
const notif = useNotifications();
|
|
44
|
+
const dashboard = useDashboardData();
|
|
45
|
+
const [queuedCount, setQueuedCount] = useState(0);
|
|
46
|
+
// The user can always type; awaitingResponse only blocks *sending* until the
|
|
47
|
+
// agent starts replying (no explicit turn-end frame exists in the protocol).
|
|
48
|
+
const [awaitingResponse, setAwaitingResponse] = useState(false);
|
|
49
|
+
// Phase 2 state
|
|
50
|
+
const [sidePanelVisible, setSidePanelVisible] = useState(false);
|
|
51
|
+
const [notificationsOpen, setNotificationsOpen] = useState(false);
|
|
52
|
+
const [projectSwitcherOpen, setProjectSwitcherOpen] = useState(false);
|
|
53
|
+
// Project switcher state
|
|
54
|
+
const [projects, setProjects] = useState([]);
|
|
55
|
+
const [projectsLoading, setProjectsLoading] = useState(false);
|
|
56
|
+
const [projectsError, setProjectsError] = useState(null);
|
|
57
|
+
const transcriptRef = useRef(null);
|
|
58
|
+
// Cost summary from dashboard state (computed)
|
|
59
|
+
const costData = dashboard.state.tabs.cost.data.length > 0 ? dashboard.state.tabs.cost.data : [];
|
|
60
|
+
const costSummary = costData.length > 0 && typeof costData[0]?.totalCost === 'number'
|
|
61
|
+
? `$${costData[0].totalCost.toFixed(2)}`
|
|
62
|
+
: null;
|
|
63
|
+
// Active tab for dashboard
|
|
64
|
+
const [activeTab, setActiveTab] = useState('threads');
|
|
65
|
+
// Route non-mutate frames to the appropriate handler
|
|
66
|
+
const routeFrame = useCallback((frame) => {
|
|
67
|
+
// Any agent reply / stream frame means the turn is being answered — unblock
|
|
68
|
+
// sending and clear the queued counter (there is no explicit turn-end frame).
|
|
69
|
+
// An error frame also releases the lock so a failed turn never strands input.
|
|
70
|
+
if (isAgentResponseFrame(frame) || isErrorFrame(frame)) {
|
|
71
|
+
setAwaitingResponse(false);
|
|
72
|
+
setQueuedCount(0);
|
|
73
|
+
}
|
|
74
|
+
if (isNotification(frame)) {
|
|
75
|
+
notif.add(frame);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (isUiQueryResult(frame) || isUiEvent(frame)) {
|
|
79
|
+
// Handle project switcher responses
|
|
80
|
+
if (isUiQueryResult(frame) && frame.id === 'proj-switcher-list') {
|
|
81
|
+
if (frame.ok) {
|
|
82
|
+
setProjects(Array.isArray(frame.data) ? frame.data : []);
|
|
83
|
+
setProjectsLoading(false);
|
|
84
|
+
setProjectsError(null);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
setProjects([]);
|
|
88
|
+
setProjectsLoading(false);
|
|
89
|
+
setProjectsError(frame.error?.message ?? 'Failed to load projects');
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
dashboard.dispatch(frame);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
transcript.dispatch(frame);
|
|
97
|
+
}, [transcript.dispatch, dashboard.dispatch, notif.add]);
|
|
98
|
+
// Mutate hook: sends ui.mutate frames, correlates results by id, 10s timeout
|
|
99
|
+
const { mutate, handleFrame } = useMutate({ sendFrame, onFrame: routeFrame });
|
|
100
|
+
// Combined dispatch: mutate intercepts mutateResult; rest routes normally
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
onSetDispatch?.((frame) => { handleFrame(frame); });
|
|
103
|
+
}, [onSetDispatch, handleFrame]);
|
|
104
|
+
// Send initial cost query for header summary
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
sendFrame({ type: 'ui.query', id: 'dash-cost', scope: 'cost.summary', params: {} });
|
|
107
|
+
}, []);
|
|
108
|
+
// Switching project/session (session.switched is handled in index.tsx and never
|
|
109
|
+
// reaches routeFrame) must release any pending send-lock from the old session.
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
setAwaitingResponse(false);
|
|
112
|
+
setQueuedCount(0);
|
|
113
|
+
}, [projectId, sessionName]);
|
|
114
|
+
// Submit message
|
|
115
|
+
const handleSubmit = useCallback((text) => {
|
|
116
|
+
const id = `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
117
|
+
sendFrame({
|
|
118
|
+
type: 'msg.user',
|
|
119
|
+
id,
|
|
120
|
+
text,
|
|
121
|
+
});
|
|
122
|
+
setQueuedCount(prev => prev + 1);
|
|
123
|
+
setAwaitingResponse(true);
|
|
124
|
+
}, [sendFrame]);
|
|
125
|
+
// Cancel (sends !cancel)
|
|
126
|
+
const handleCancel = useCallback(() => {
|
|
127
|
+
onSendCancel();
|
|
128
|
+
}, [onSendCancel]);
|
|
129
|
+
// Clear view
|
|
130
|
+
const handleClearView = useCallback(() => {
|
|
131
|
+
transcript.clear();
|
|
132
|
+
}, [transcript]);
|
|
133
|
+
// Scroll
|
|
134
|
+
const handleScrollUp = useCallback((page) => {
|
|
135
|
+
transcriptRef.current?.scrollUp(page);
|
|
136
|
+
}, []);
|
|
137
|
+
const handleScrollDown = useCallback((page) => {
|
|
138
|
+
transcriptRef.current?.scrollDown(page);
|
|
139
|
+
}, []);
|
|
140
|
+
// Side panel toggle
|
|
141
|
+
const handleToggleSidePanel = useCallback(() => {
|
|
142
|
+
setSidePanelVisible(prev => !prev);
|
|
143
|
+
}, []);
|
|
144
|
+
// Notifications toggle
|
|
145
|
+
const handleToggleNotifications = useCallback(() => {
|
|
146
|
+
setNotificationsOpen(prev => !prev);
|
|
147
|
+
}, []);
|
|
148
|
+
// Project switcher toggle
|
|
149
|
+
const handleToggleProjectSwitcher = useCallback(() => {
|
|
150
|
+
setProjectSwitcherOpen(prev => !prev);
|
|
151
|
+
}, []);
|
|
152
|
+
// Project switcher select
|
|
153
|
+
const handleProjectSelect = useCallback((selectedProjectId) => {
|
|
154
|
+
sendFrame({
|
|
155
|
+
type: 'session.switch',
|
|
156
|
+
id: 'proj-switch',
|
|
157
|
+
projectId: selectedProjectId,
|
|
158
|
+
sessionId: null,
|
|
159
|
+
});
|
|
160
|
+
}, [sendFrame]);
|
|
161
|
+
// Notification select — switches to notification's project
|
|
162
|
+
const handleNotificationSelect = useCallback((notif) => {
|
|
163
|
+
sendFrame({
|
|
164
|
+
type: 'session.switch',
|
|
165
|
+
id: 'notif-switch',
|
|
166
|
+
projectId: notif.projectId,
|
|
167
|
+
sessionId: notif.sessionId ?? null,
|
|
168
|
+
});
|
|
169
|
+
setNotificationsOpen(false);
|
|
170
|
+
}, [sendFrame]);
|
|
171
|
+
// Project switcher refresh
|
|
172
|
+
const handleProjectsRefresh = useCallback(() => {
|
|
173
|
+
setProjectsLoading(true);
|
|
174
|
+
setProjectsError(null);
|
|
175
|
+
sendFrame({
|
|
176
|
+
type: 'ui.query',
|
|
177
|
+
id: 'proj-switcher-list',
|
|
178
|
+
scope: 'projects.list',
|
|
179
|
+
params: {},
|
|
180
|
+
});
|
|
181
|
+
}, [sendFrame]);
|
|
182
|
+
// Modals pre-empt input; an open dashboard takes keyboard focus from the input.
|
|
183
|
+
const modalOpen = activeModal !== null || notificationsOpen || projectSwitcherOpen;
|
|
184
|
+
const focusZone = computeFocusZone({ modalOpen, sidePanelVisible });
|
|
185
|
+
// Keyboard bindings — toggles/cancel always active outside modals; scroll only
|
|
186
|
+
// when the chat input owns focus; reconnect only when not connected.
|
|
187
|
+
useKeybindings({
|
|
188
|
+
onSubmit: handleSubmit,
|
|
189
|
+
onCancel: handleCancel,
|
|
190
|
+
onScrollUp: handleScrollUp,
|
|
191
|
+
onScrollDown: handleScrollDown,
|
|
192
|
+
onClearView: handleClearView,
|
|
193
|
+
onExit: onDisconnect,
|
|
194
|
+
onToggleSidePanel: handleToggleSidePanel,
|
|
195
|
+
onToggleNotifications: handleToggleNotifications,
|
|
196
|
+
onToggleProjectSwitcher: handleToggleProjectSwitcher,
|
|
197
|
+
onReconnect,
|
|
198
|
+
}, focusZone !== 'modal', {
|
|
199
|
+
allowScroll: focusZone === 'input',
|
|
200
|
+
allowReconnect: connectionState !== 'connected',
|
|
201
|
+
});
|
|
202
|
+
// Dashboard subscription management callbacks
|
|
203
|
+
const handleMarkPending = useCallback((tab) => {
|
|
204
|
+
dashboard.markPending(tab);
|
|
205
|
+
}, [dashboard]);
|
|
206
|
+
const handleRegisterSubscription = useCallback((queryId, tab) => {
|
|
207
|
+
dashboard.registerSubscription(queryId, tab);
|
|
208
|
+
}, [dashboard]);
|
|
209
|
+
const handleUnregisterSubscription = useCallback((queryId) => {
|
|
210
|
+
dashboard.unregisterSubscription(queryId);
|
|
211
|
+
}, [dashboard]);
|
|
212
|
+
// If resume mode with sessions to pick, show picker instead of main layout
|
|
213
|
+
if (resumableSessions && resumableSessions.length > 0 && onResumeSelect && onResumeCancel) {
|
|
214
|
+
return (_jsx(Box, { flexDirection: "column", height: "100%", justifyContent: "center", alignItems: "center", children: _jsx(SessionPicker, { sessions: resumableSessions, onSelect: onResumeSelect, onCancel: onResumeCancel }) }));
|
|
215
|
+
}
|
|
216
|
+
return (_jsxs(Box, { flexDirection: "column", height: "100%", children: [_jsx(Header, { projectId: projectId, sessionName: sessionName, queuedCount: queuedCount, connected: connectionState === 'connected', notificationCount: notif.unreadCount, costSummary: costSummary }), _jsxs(Box, { flexDirection: "row", flexGrow: 1, children: [_jsx(Box, { flexDirection: "column", flexGrow: 1, children: _jsx(Transcript, { ref: transcriptRef, messages: transcript.messages, ids: transcript.ids }) }), _jsx(SidePanel, { visible: sidePanelVisible, active: focusZone === 'dashboard', sendFrame: sendFrame, projectId: projectId, dashState: dashboard.state, onMarkPending: handleMarkPending, onRegisterSubscription: handleRegisterSubscription, onUnregisterSubscription: handleUnregisterSubscription, activeTab: activeTab, onSetActiveTab: setActiveTab, onMutate: mutate })] }), !notificationsOpen && notif.unreadCount > 0 ? (_jsx(Box, { justifyContent: "flex-end", marginRight: 2, children: _jsx(NotificationsBadge, { unreadCount: notif.unreadCount }) })) : null, activeModal ? (activeModal.modal.callbackId.startsWith('plan')
|
|
217
|
+
? _jsx(PlanFeedbackModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })
|
|
218
|
+
: _jsx(AskUserModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })) : modalOpen ? (_jsxs(Box, { borderStyle: "single", borderDimColor: true, paddingX: 1, marginTop: 1, children: [notificationsOpen ? (_jsx(NotificationsModal, { open: notificationsOpen, notifications: notif.notifications, ids: notif.ids, onMarkRead: notif.markRead, onClose: () => setNotificationsOpen(false), onSelect: handleNotificationSelect })) : null, projectSwitcherOpen ? (_jsx(ProjectSwitcher, { open: projectSwitcherOpen, projects: projects, loading: projectsLoading, error: projectsError, onSelect: handleProjectSelect, onClose: () => setProjectSwitcherOpen(false), onRequestRefresh: handleProjectsRefresh })) : null] })) : (_jsx(InputBox, { onSubmit: handleSubmit, awaitingResponse: awaitingResponse, focus: focusZone === 'input' })), _jsx(StatusLine, { connectionState: connectionState, queuedCount: queuedCount, notificationCount: notif.unreadCount, errorMessage: errorMessage })] }));
|
|
219
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ModalDefinition, TuiFrame } from '../../platform/tui/protocol.js';
|
|
3
|
+
interface AskUserModalProps {
|
|
4
|
+
modal: ModalDefinition;
|
|
5
|
+
triggerId: string;
|
|
6
|
+
sendFrame: (frame: TuiFrame) => void;
|
|
7
|
+
ackErrors: Record<string, string>;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function AskUserModal({ modal, triggerId, sendFrame, ackErrors, onClose, }: AskUserModalProps): React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: protocol types (ModalDefinition, ModalField, ModalFieldValue, ModalSubmit)
|
|
3
|
+
// output: Modal renderer for modal.open frames — section/select/multi_select/text_input
|
|
4
|
+
// pos: Modal UI for AskUserQuestion and plan feedback flows
|
|
5
|
+
//
|
|
6
|
+
// Renders per M4 spec:
|
|
7
|
+
// section → static text (dimmed)
|
|
8
|
+
// select → numbered list, ↑/↓ navigate, Enter selects
|
|
9
|
+
// multi_select → numbered list with [x]/[ ] checkboxes, ↑/↓ navigate, Space toggles
|
|
10
|
+
// text_input → character capture via useInput
|
|
11
|
+
// On submit: builds values:Record<blockId,Record<actionId,ModalFieldValue>>
|
|
12
|
+
// matching M4 modal.submit shape and sends via sendFrame.
|
|
13
|
+
// Displays modal.ack errors inline beneath the offending field.
|
|
14
|
+
import { useState, useCallback, useRef, useEffect, useMemo } from 'react';
|
|
15
|
+
import { Box, Text, useInput } from 'ink';
|
|
16
|
+
/** Return all interactive elements for focus navigation. */
|
|
17
|
+
function getInteractiveFields(fields) {
|
|
18
|
+
const result = [];
|
|
19
|
+
for (let i = 0; i < fields.length; i++) {
|
|
20
|
+
const f = fields[i];
|
|
21
|
+
if (f.type === 'select' || f.type === 'multi_select' || f.type === 'text_input') {
|
|
22
|
+
result.push({ field: f, fieldIdx: i });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
// ── Component ──
|
|
28
|
+
export function AskUserModal({ modal, triggerId, sendFrame, ackErrors, onClose, }) {
|
|
29
|
+
// Pre-compute interactive fields for focus initialization (pure function, called before hooks)
|
|
30
|
+
const initInteractiveFields = getInteractiveFields(modal.fields);
|
|
31
|
+
// ── Focus state: start on the first interactive field ──
|
|
32
|
+
const [fieldFocus, setFieldFocus] = useState(initInteractiveFields.length > 0 ? initInteractiveFields[0].fieldIdx : -1);
|
|
33
|
+
const [optionFocus, setOptionFocus] = useState(0);
|
|
34
|
+
const [selections, setSelections] = useState({
|
|
35
|
+
select: {},
|
|
36
|
+
multiSelect: {},
|
|
37
|
+
text: {},
|
|
38
|
+
});
|
|
39
|
+
const [submitted, setSubmitted] = useState(false);
|
|
40
|
+
// Reset submitted when ack errors arrive — user can fix and resubmit
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (Object.keys(ackErrors).length > 0) {
|
|
43
|
+
setSubmitted(false);
|
|
44
|
+
}
|
|
45
|
+
}, [ackErrors]);
|
|
46
|
+
const optionFocusRef = useRef(optionFocus);
|
|
47
|
+
optionFocusRef.current = optionFocus;
|
|
48
|
+
const interactiveFields = useMemo(() => getInteractiveFields(modal.fields), [modal.fields]);
|
|
49
|
+
const submitLabel = modal.submitLabel || 'Submit';
|
|
50
|
+
function buildFocusSlots() {
|
|
51
|
+
const slots = [];
|
|
52
|
+
for (const ifield of interactiveFields) {
|
|
53
|
+
const fi = ifield.fieldIdx;
|
|
54
|
+
if (ifield.field.type === 'select' || ifield.field.type === 'multi_select') {
|
|
55
|
+
for (let oi = 0; oi < ifield.field.options.length; oi++) {
|
|
56
|
+
slots.push({ kind: 'field-option', fieldIdx: fi, optionIdx: oi });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (ifield.field.type === 'text_input') {
|
|
60
|
+
slots.push({ kind: 'text-field', fieldIdx: fi });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
slots.push({ kind: 'submit' });
|
|
64
|
+
return slots;
|
|
65
|
+
}
|
|
66
|
+
// Only resolve slots when fieldFocus corresponds to an interactive field
|
|
67
|
+
const slots = buildFocusSlots();
|
|
68
|
+
const currentSlotIndexRef = useRef(0);
|
|
69
|
+
/** Find the next slot that belongs to a different interactive field (or submit).
|
|
70
|
+
* Used by Enter to move to the next field after confirming a select/multi/text. */
|
|
71
|
+
function findNextFieldSlot(currentFieldIdx) {
|
|
72
|
+
const currentSlot = currentSlotIndexRef.current;
|
|
73
|
+
for (let i = currentSlot + 1; i < slots.length; i++) {
|
|
74
|
+
const s = slots[i];
|
|
75
|
+
if (s.kind === 'submit')
|
|
76
|
+
return s;
|
|
77
|
+
if (s.kind === 'field-option' && s.fieldIdx !== currentFieldIdx)
|
|
78
|
+
return s;
|
|
79
|
+
if (s.kind === 'text-field' && s.fieldIdx !== currentFieldIdx)
|
|
80
|
+
return s;
|
|
81
|
+
}
|
|
82
|
+
// No next field found — return submit
|
|
83
|
+
return slots[slots.length - 1]?.kind === 'submit' ? slots[slots.length - 1] : null;
|
|
84
|
+
}
|
|
85
|
+
// Map focus state to slot index
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (fieldFocus === -1) {
|
|
88
|
+
currentSlotIndexRef.current = slots.length - 1; // submit
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const idx = slots.findIndex(s => (s.kind === 'field-option' && s.fieldIdx === fieldFocus && s.optionIdx === optionFocus) ||
|
|
92
|
+
(s.kind === 'text-field' && s.fieldIdx === fieldFocus));
|
|
93
|
+
if (idx >= 0)
|
|
94
|
+
currentSlotIndexRef.current = idx;
|
|
95
|
+
else if (slots.length > 0)
|
|
96
|
+
currentSlotIndexRef.current = 0;
|
|
97
|
+
}
|
|
98
|
+
}, [fieldFocus, optionFocus, slots]);
|
|
99
|
+
// ── Keyboard handling ──
|
|
100
|
+
const handleClose = useCallback(() => {
|
|
101
|
+
if (!submitted) {
|
|
102
|
+
onClose();
|
|
103
|
+
}
|
|
104
|
+
}, [submitted, onClose]);
|
|
105
|
+
const handleSubmit = useCallback(() => {
|
|
106
|
+
if (submitted)
|
|
107
|
+
return;
|
|
108
|
+
setSubmitted(true);
|
|
109
|
+
const values = {};
|
|
110
|
+
for (const f of modal.fields) {
|
|
111
|
+
if (f.type === 'section')
|
|
112
|
+
continue;
|
|
113
|
+
if (f.type === 'select') {
|
|
114
|
+
const idx = selections.select[f.blockId];
|
|
115
|
+
if (idx !== undefined && f.options[idx]) {
|
|
116
|
+
values[f.blockId] = {
|
|
117
|
+
[f.actionId]: { selectedOption: { value: f.options[idx].value } },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (f.type === 'multi_select') {
|
|
122
|
+
const toggled = selections.multiSelect[f.blockId];
|
|
123
|
+
if (toggled && toggled.size > 0) {
|
|
124
|
+
values[f.blockId] = {
|
|
125
|
+
[f.actionId]: {
|
|
126
|
+
selectedOptions: [...toggled].map(i => ({ value: f.options[i].value })),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (f.type === 'text_input') {
|
|
132
|
+
const val = selections.text[f.blockId];
|
|
133
|
+
if (val !== undefined && val !== '') {
|
|
134
|
+
values[f.blockId] = { [f.actionId]: { value: val } };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
sendFrame({
|
|
139
|
+
type: 'modal.submit',
|
|
140
|
+
id: `modal-submit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
141
|
+
callbackId: modal.callbackId,
|
|
142
|
+
privateMetadata: modal.privateMetadata || '',
|
|
143
|
+
values,
|
|
144
|
+
userId: 'tui',
|
|
145
|
+
});
|
|
146
|
+
}, [submitted, modal, selections, sendFrame]);
|
|
147
|
+
useInput((input, key) => {
|
|
148
|
+
// Esc always closes (if not submitted yet)
|
|
149
|
+
if (key.escape) {
|
|
150
|
+
handleClose();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (submitted)
|
|
154
|
+
return;
|
|
155
|
+
if (key.return) {
|
|
156
|
+
// If submit button is focused, submit
|
|
157
|
+
if (fieldFocus === -1) {
|
|
158
|
+
handleSubmit();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// If on a select option, confirm selection and move to next slot
|
|
162
|
+
const currentField = interactiveFields.find(ifd => ifd.fieldIdx === fieldFocus);
|
|
163
|
+
if (currentField) {
|
|
164
|
+
const cf = currentField.field;
|
|
165
|
+
if (cf.type === 'select') {
|
|
166
|
+
// Confirm selection and move to next FIELD (skip remaining options)
|
|
167
|
+
setSelections(prev => ({
|
|
168
|
+
...prev,
|
|
169
|
+
select: { ...prev.select, [cf.blockId]: optionFocus },
|
|
170
|
+
}));
|
|
171
|
+
const nextField = findNextFieldSlot(fieldFocus);
|
|
172
|
+
if (nextField) {
|
|
173
|
+
if (nextField.kind === 'field-option') {
|
|
174
|
+
setFieldFocus(nextField.fieldIdx);
|
|
175
|
+
setOptionFocus(nextField.optionIdx);
|
|
176
|
+
}
|
|
177
|
+
else if (nextField.kind === 'text-field') {
|
|
178
|
+
setFieldFocus(nextField.fieldIdx);
|
|
179
|
+
}
|
|
180
|
+
else if (nextField.kind === 'submit') {
|
|
181
|
+
setFieldFocus(-1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
setFieldFocus(-1);
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (cf.type === 'multi_select') {
|
|
190
|
+
// Confirm multi selections — move to next FIELD
|
|
191
|
+
const nextField = findNextFieldSlot(fieldFocus);
|
|
192
|
+
if (nextField) {
|
|
193
|
+
if (nextField.kind === 'field-option') {
|
|
194
|
+
setFieldFocus(nextField.fieldIdx);
|
|
195
|
+
setOptionFocus(nextField.optionIdx);
|
|
196
|
+
}
|
|
197
|
+
else if (nextField.kind === 'text-field') {
|
|
198
|
+
setFieldFocus(nextField.fieldIdx);
|
|
199
|
+
}
|
|
200
|
+
else if (nextField.kind === 'submit') {
|
|
201
|
+
setFieldFocus(-1);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
setFieldFocus(-1);
|
|
206
|
+
}
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (cf.type === 'text_input') {
|
|
210
|
+
// Enter on text_input: move to next field
|
|
211
|
+
const nextField = findNextFieldSlot(fieldFocus);
|
|
212
|
+
if (nextField) {
|
|
213
|
+
if (nextField.kind === 'field-option') {
|
|
214
|
+
setFieldFocus(nextField.fieldIdx);
|
|
215
|
+
setOptionFocus(nextField.optionIdx);
|
|
216
|
+
}
|
|
217
|
+
else if (nextField.kind === 'text-field') {
|
|
218
|
+
setFieldFocus(nextField.fieldIdx);
|
|
219
|
+
}
|
|
220
|
+
else if (nextField.kind === 'submit') {
|
|
221
|
+
setFieldFocus(-1);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
setFieldFocus(-1);
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Default: move to submit
|
|
231
|
+
setFieldFocus(-1);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
// Arrow key navigation between slots
|
|
235
|
+
if (key.upArrow || key.downArrow) {
|
|
236
|
+
const currSlot = currentSlotIndexRef.current;
|
|
237
|
+
let nextIdx = null;
|
|
238
|
+
if (key.downArrow && currSlot < slots.length - 1) {
|
|
239
|
+
nextIdx = currSlot + 1;
|
|
240
|
+
}
|
|
241
|
+
else if (key.upArrow && currSlot > 0) {
|
|
242
|
+
nextIdx = currSlot - 1;
|
|
243
|
+
}
|
|
244
|
+
if (nextIdx !== null) {
|
|
245
|
+
const next = slots[nextIdx];
|
|
246
|
+
if (next.kind === 'field-option') {
|
|
247
|
+
setFieldFocus(next.fieldIdx);
|
|
248
|
+
setOptionFocus(next.optionIdx);
|
|
249
|
+
}
|
|
250
|
+
else if (next.kind === 'text-field') {
|
|
251
|
+
setFieldFocus(next.fieldIdx);
|
|
252
|
+
}
|
|
253
|
+
else if (next.kind === 'submit') {
|
|
254
|
+
setFieldFocus(-1);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
// Space toggles multi_select option
|
|
260
|
+
if (input === ' ' && !key.ctrl && !key.meta && !key.shift) {
|
|
261
|
+
const currentField = interactiveFields.find(ifd => ifd.fieldIdx === fieldFocus);
|
|
262
|
+
if (currentField && currentField.field.type === 'multi_select') {
|
|
263
|
+
const cf = currentField.field;
|
|
264
|
+
setSelections(prev => {
|
|
265
|
+
const current = new Set(prev.multiSelect[cf.blockId] || []);
|
|
266
|
+
if (current.has(optionFocus)) {
|
|
267
|
+
current.delete(optionFocus);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
current.add(optionFocus);
|
|
271
|
+
}
|
|
272
|
+
return { ...prev, multiSelect: { ...prev.multiSelect, [cf.blockId]: current } };
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
// Number keys for select/multi_select
|
|
278
|
+
if (/^[1-9]$/.test(input)) {
|
|
279
|
+
const currentField = interactiveFields.find(ifd => ifd.fieldIdx === fieldFocus);
|
|
280
|
+
if (currentField && (currentField.field.type === 'select' || currentField.field.type === 'multi_select')) {
|
|
281
|
+
const cf = currentField.field;
|
|
282
|
+
const numIdx = parseInt(input, 10) - 1;
|
|
283
|
+
if (numIdx >= 0 && numIdx < cf.options.length) {
|
|
284
|
+
if (cf.type === 'multi_select') {
|
|
285
|
+
setSelections(prev => {
|
|
286
|
+
const current = new Set(prev.multiSelect[cf.blockId] || []);
|
|
287
|
+
if (current.has(numIdx)) {
|
|
288
|
+
current.delete(numIdx);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
current.add(numIdx);
|
|
292
|
+
}
|
|
293
|
+
return { ...prev, multiSelect: { ...prev.multiSelect, [cf.blockId]: current } };
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
else if (cf.type === 'select') {
|
|
297
|
+
setSelections(prev => ({
|
|
298
|
+
...prev,
|
|
299
|
+
select: { ...prev.select, [cf.blockId]: numIdx },
|
|
300
|
+
}));
|
|
301
|
+
setOptionFocus(numIdx);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
// Character capture for text_input
|
|
308
|
+
const currentField = interactiveFields.find(ifd => ifd.fieldIdx === fieldFocus);
|
|
309
|
+
if (currentField && currentField.field.type === 'text_input') {
|
|
310
|
+
const cf = currentField.field;
|
|
311
|
+
if (key.backspace || key.delete) {
|
|
312
|
+
setSelections(prev => {
|
|
313
|
+
const current = prev.text[cf.blockId] || '';
|
|
314
|
+
return { ...prev, text: { ...prev.text, [cf.blockId]: current.slice(0, -1) } };
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
else if (input.length === 1 && !key.ctrl && !key.meta && !key.shift) {
|
|
318
|
+
setSelections(prev => ({
|
|
319
|
+
...prev,
|
|
320
|
+
text: { ...prev.text, [cf.blockId]: (prev.text[cf.blockId] || '') + input },
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
// ── Render helpers ──
|
|
327
|
+
function renderField(field, idx) {
|
|
328
|
+
switch (field.type) {
|
|
329
|
+
case 'section':
|
|
330
|
+
return (_jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: field.text }) }, `section-${idx}`));
|
|
331
|
+
case 'select': {
|
|
332
|
+
const selectedIdx = selections.select[field.blockId] ?? optionFocus;
|
|
333
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { bold: fieldFocus === idx, dimColor: fieldFocus !== idx, children: field.label }), field.options.map((opt, oi) => {
|
|
334
|
+
const isFocused = fieldFocus === idx && optionFocus === oi;
|
|
335
|
+
const isSelected = selections.select[field.blockId] === oi;
|
|
336
|
+
const prefix = isFocused ? '▶' : isSelected ? '●' : '○';
|
|
337
|
+
return (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { bold: isFocused, color: isSelected ? 'green' : undefined, children: [prefix, " ", oi + 1, ". ", opt.label] }) }, oi));
|
|
338
|
+
})] }, `field-${idx}`));
|
|
339
|
+
}
|
|
340
|
+
case 'multi_select': {
|
|
341
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { bold: fieldFocus === idx, dimColor: fieldFocus !== idx, children: field.label }), field.options.map((opt, oi) => {
|
|
342
|
+
const isFocused = fieldFocus === idx && optionFocus === oi;
|
|
343
|
+
const isSelected = selections.multiSelect[field.blockId]?.has(oi) ?? false;
|
|
344
|
+
return (_jsx(Box, { marginLeft: 2, children: _jsxs(Text, { bold: isFocused, children: [isFocused ? '▶' : ' ', " [", isSelected ? 'x' : ' ', "] ", oi + 1, ". ", opt.label] }) }, oi));
|
|
345
|
+
})] }, `field-${idx}`));
|
|
346
|
+
}
|
|
347
|
+
case 'text_input': {
|
|
348
|
+
const val = selections.text[field.blockId] || '';
|
|
349
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { bold: fieldFocus === idx, dimColor: fieldFocus !== idx, children: field.label }), _jsx(Box, { borderStyle: "single", borderDimColor: fieldFocus !== idx, paddingX: 1, marginLeft: 2, children: val ? (_jsx(Text, { children: val })) : (_jsx(Text, { dimColor: true, children: field.placeholder || 'Type here...' })) })] }, `field-${idx}`));
|
|
350
|
+
}
|
|
351
|
+
default:
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// ── Render ──
|
|
356
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, paddingY: 1, borderStyle: "single", children: [_jsx(Text, { bold: true, children: modal.title }), modal.fields.map((field, idx) => renderField(field, idx)), Object.keys(ackErrors).length > 0 ? (_jsx(Box, { flexDirection: "column", marginTop: 1, children: Object.entries(ackErrors).map(([blockId, errorMsg]) => {
|
|
357
|
+
const found = modal.fields.find((f) => (f.type === 'select' || f.type === 'multi_select' || f.type === 'text_input') &&
|
|
358
|
+
f.blockId === blockId);
|
|
359
|
+
const label = found?.label ?? blockId;
|
|
360
|
+
return (_jsx(Box, { children: _jsxs(Text, { color: "red", children: ["\u26A0 ", label, ": ", errorMsg] }) }, `err-${blockId}`));
|
|
361
|
+
}) })) : null, _jsx(Box, { marginTop: 1, children: _jsxs(Text, { bold: fieldFocus === -1, dimColor: fieldFocus !== -1, children: [fieldFocus === -1 ? '▶' : ' ', " [", submitLabel, "]"] }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: fieldFocus === -1
|
|
362
|
+
? 'Enter submit · ↑/↓ navigate · Esc cancel'
|
|
363
|
+
: '↑/↓ navigate · Enter select · Esc cancel' }) })] }));
|
|
364
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ConfirmModalProps {
|
|
3
|
+
title: string;
|
|
4
|
+
body: string;
|
|
5
|
+
onConfirm: (reason?: string) => void;
|
|
6
|
+
onCancel: () => void;
|
|
7
|
+
reasonInput?: {
|
|
8
|
+
label: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function ConfirmModal({ title, body, onConfirm, onCancel, reasonInput, }: ConfirmModalProps): React.JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// input: title + body + callbacks + optional reasonInput
|
|
3
|
+
// output: Confirm/Cancel modal — y/Enter confirm, n/Esc cancel. TextInput for reason when set.
|
|
4
|
+
// pos: Reusable confirmation modal for destructive actions
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
import { Box, Text, useInput } from 'ink';
|
|
7
|
+
import { UncontrolledTextInput } from 'ink-text-input';
|
|
8
|
+
export function ConfirmModal({ title, body, onConfirm, onCancel, reasonInput, }) {
|
|
9
|
+
const handleReasonSubmit = useCallback((text) => {
|
|
10
|
+
onConfirm(text);
|
|
11
|
+
}, [onConfirm]);
|
|
12
|
+
useInput((input, key) => {
|
|
13
|
+
if (reasonInput) {
|
|
14
|
+
// When reason Input is active, only Esc cancels.
|
|
15
|
+
// Enter is handled by UncontrolledTextInput's internal onSubmit.
|
|
16
|
+
if (key.escape) {
|
|
17
|
+
onCancel();
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (input === 'y' || key.return) {
|
|
22
|
+
onConfirm();
|
|
23
|
+
}
|
|
24
|
+
else if (input === 'n' || key.escape) {
|
|
25
|
+
onCancel();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, paddingY: 1, borderStyle: "single", children: [_jsx(Text, { bold: true, children: title }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { children: body }) }), reasonInput ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { children: reasonInput.label }), _jsx(UncontrolledTextInput, { placeholder: reasonInput.placeholder ?? '', onSubmit: handleReasonSubmit })] })) : null, _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: reasonInput
|
|
29
|
+
? 'Enter to confirm · Esc to cancel'
|
|
30
|
+
: 'y/Enter confirm · n/Esc cancel' }) })] }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TabName, DashState } from '../hooks/useDashboardData.js';
|
|
3
|
+
import type { MutateResult } from '../hooks/useMutate.js';
|
|
4
|
+
export interface DashboardTabInfo {
|
|
5
|
+
key: TabName;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const DASHBOARD_TABS: DashboardTabInfo[];
|
|
9
|
+
interface DashboardProps {
|
|
10
|
+
/** Whether the dashboard owns the keyboard (focus zone === 'dashboard'). */
|
|
11
|
+
active: boolean;
|
|
12
|
+
sendFrame: (frame: any) => void;
|
|
13
|
+
mutate?: (op: string, args: Record<string, unknown>) => Promise<MutateResult>;
|
|
14
|
+
projectId: string | null;
|
|
15
|
+
dashState: DashState;
|
|
16
|
+
onMarkPending: (tab: string) => void;
|
|
17
|
+
onRegisterSubscription: (queryId: string, tab: string) => void;
|
|
18
|
+
onUnregisterSubscription: (queryId: string) => void;
|
|
19
|
+
activeTab: string;
|
|
20
|
+
onSetActiveTab: (tab: string) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, }: DashboardProps): React.JSX.Element;
|
|
23
|
+
export {};
|