@cortex-agent/server 2026.5.25 → 2026.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/config/thread-templates.json +28 -1
- package/defaults/hooks/cortex-md-injector.mjs +47 -31
- package/defaults/hooks/post-task-hook.mjs +6 -0
- package/defaults/hooks/task-status-check.mjs +8 -0
- package/defaults/mcp-config-slack.json +11 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
- package/defaults/prompts/directives/manager.md +67 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
- package/dist/agent-adapter/claude/adapter-tui.js +91 -12
- package/dist/agent-adapter/claude/adapter.js +11 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +30 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
- package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
- package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
- package/dist/agent-adapter/claude/spawn-args.js +49 -7
- package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
- package/dist/agent-adapter/claude/tmux-control.js +54 -8
- package/dist/agent-adapter/codex/adapter.js +1 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
- package/dist/agent-adapter/pi/adapter.js +46 -19
- package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
- package/dist/agent-adapter/pi/agent-dir.js +53 -2
- package/dist/agent-adapter/pi/event-parser.js +13 -1
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
- package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
- package/dist/agent-adapter/pi/tool-shims.js +167 -140
- package/dist/agent-adapter/types.d.ts +7 -2
- package/dist/core/atomic-write.js +21 -0
- package/dist/core/config-generator.d.ts +10 -0
- package/dist/core/config-generator.js +28 -0
- package/dist/core/gateway-generator.d.ts +77 -7
- package/dist/core/gateway-generator.js +323 -30
- package/dist/core/i18n.d.ts +19 -0
- package/dist/core/i18n.js +46 -0
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -0
- package/dist/core/locales/en.d.ts +438 -0
- package/dist/core/locales/en.js +24 -0
- package/dist/core/locales/slices/commands.d.ts +214 -0
- package/dist/core/locales/slices/commands.js +462 -0
- package/dist/core/locales/slices/init.d.ts +121 -0
- package/dist/core/locales/slices/init.js +380 -0
- package/dist/core/locales/slices/interactions.d.ts +47 -0
- package/dist/core/locales/slices/interactions.js +102 -0
- package/dist/core/locales/slices/lang.d.ts +8 -0
- package/dist/core/locales/slices/lang.js +18 -0
- package/dist/core/locales/slices/scheduling.d.ts +36 -0
- package/dist/core/locales/slices/scheduling.js +74 -0
- package/dist/core/locales/slices/startup.d.ts +6 -0
- package/dist/core/locales/slices/startup.js +14 -0
- package/dist/core/locales/slices/status.d.ts +20 -0
- package/dist/core/locales/slices/status.js +48 -0
- package/dist/core/locales/zh.d.ts +5 -0
- package/dist/core/locales/zh.js +23 -0
- package/dist/core/profile-generator.d.ts +6 -0
- package/dist/core/profile-generator.js +35 -7
- package/dist/core/running-executions.d.ts +51 -41
- package/dist/core/running-executions.js +120 -73
- package/dist/core/singleton-lock.d.ts +23 -0
- package/dist/core/singleton-lock.js +53 -0
- package/dist/core/status-format.js +4 -2
- package/dist/core/task-parser.d.ts +3 -0
- package/dist/core/task-parser.js +3 -1
- package/dist/core/types/thread-types.d.ts +54 -8
- package/dist/core/utils.d.ts +9 -1
- package/dist/core/utils.js +9 -1
- package/dist/domain/agents/config.d.ts +2 -1
- package/dist/domain/agents/config.js +25 -6
- package/dist/domain/agents/facade.d.ts +18 -0
- package/dist/domain/agents/facade.js +26 -3
- package/dist/domain/agents/profile-manager.d.ts +11 -0
- package/dist/domain/agents/profile-manager.js +21 -2
- package/dist/domain/costs/codex-usage-monitor.js +2 -1
- package/dist/domain/costs/rate-limit-throttle.js +14 -2
- package/dist/domain/executions/registry.d.ts +24 -0
- package/dist/domain/executions/registry.js +38 -0
- package/dist/domain/mcp/core-server.js +15 -3
- package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
- package/dist/domain/mcp/feishu/bitable.js +168 -0
- package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
- package/dist/domain/mcp/feishu/block-types.js +127 -0
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
- package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
- package/dist/domain/mcp/feishu/client.d.ts +46 -0
- package/dist/domain/mcp/feishu/client.js +87 -0
- package/dist/domain/mcp/feishu/docx.d.ts +3 -0
- package/dist/domain/mcp/feishu/docx.js +163 -0
- package/dist/domain/mcp/feishu/drive.d.ts +23 -0
- package/dist/domain/mcp/feishu/drive.js +66 -0
- package/dist/domain/mcp/feishu/file.d.ts +14 -0
- package/dist/domain/mcp/feishu/file.js +107 -0
- package/dist/domain/mcp/feishu/index.d.ts +6 -0
- package/dist/domain/mcp/feishu/index.js +61 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
- package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
- package/dist/domain/mcp/feishu/sheets.js +119 -0
- package/dist/domain/mcp/feishu/types.d.ts +26 -0
- package/dist/domain/mcp/feishu/types.js +38 -0
- package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
- package/dist/domain/mcp/feishu/user-auth.js +286 -0
- package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
- package/dist/domain/mcp/feishu/wiki.js +77 -0
- package/dist/domain/mcp/feishu-server.d.ts +2 -0
- package/dist/domain/mcp/feishu-server.js +33 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +6 -25
- package/dist/domain/mcp/slack-server.d.ts +3 -0
- package/dist/domain/mcp/slack-server.js +46 -0
- package/dist/domain/mcp/tools/context.js +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +1 -1
- package/dist/domain/mcp/tools/schedule.js +6 -20
- package/dist/domain/mcp/tools/slack.js +20 -7
- package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/thread-ops.js +121 -0
- package/dist/domain/mcp/tools/time.d.ts +2 -0
- package/dist/domain/mcp/tools/time.js +66 -0
- package/dist/domain/mcp/tools/tui-ask.js +1 -1
- package/dist/domain/mcp/tools/tui-plan.js +2 -2
- package/dist/domain/mcp/tui-server.js +1 -0
- package/dist/domain/monitor/disk-monitor.js +2 -1
- package/dist/domain/monitor/gpu-monitor.js +2 -1
- package/dist/domain/remote/client-hot-reload.js +3 -2
- package/dist/domain/remote/client-manager.js +8 -6
- package/dist/domain/scheduling/job-registry.d.ts +4 -0
- package/dist/domain/scheduling/job-registry.js +1 -0
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
- package/dist/domain/scheduling/jobs/sync-public.js +4 -3
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
- package/dist/domain/scheduling/jobs/task-archive.js +3 -2
- package/dist/domain/scheduling/jobs/task-dispatch.js +126 -20
- package/dist/domain/scheduling/schedule-command.js +45 -43
- package/dist/domain/scheduling/scheduler.d.ts +1 -1
- package/dist/domain/scheduling/scheduler.js +2 -1
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-hooks.js +19 -18
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
- package/dist/domain/sessions/session-lifecycle.js +44 -0
- package/dist/domain/system/github-release.d.ts +18 -0
- package/dist/domain/system/github-release.js +106 -0
- package/dist/domain/system/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/system/preferences.d.ts +12 -0
- package/dist/domain/system/preferences.js +36 -0
- package/dist/domain/system/server-update-check.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.d.ts +11 -2
- package/dist/domain/tasks/dispatcher.js +63 -7
- package/dist/domain/tasks/lint.js +28 -0
- package/dist/domain/tasks/mutator.d.ts +16 -3
- package/dist/domain/tasks/mutator.js +41 -12
- package/dist/domain/tasks/pending-tracker.js +6 -5
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
- package/dist/domain/tasks/system/task-mutations.js +166 -8
- package/dist/domain/threads/contract.d.ts +17 -0
- package/dist/domain/threads/contract.js +59 -0
- package/dist/domain/threads/hook-runner.js +7 -6
- package/dist/domain/threads/index.d.ts +2 -0
- package/dist/domain/threads/index.js +3 -1
- package/dist/domain/threads/prompt-builder.d.ts +21 -1
- package/dist/domain/threads/prompt-builder.js +60 -4
- package/dist/domain/threads/runner.d.ts +6 -5
- package/dist/domain/threads/runner.js +128 -79
- package/dist/domain/threads/state-machine.d.ts +23 -21
- package/dist/domain/threads/state-machine.js +113 -54
- package/dist/domain/threads/template-loader.js +3 -2
- package/dist/domain/threads/tree.d.ts +45 -0
- package/dist/domain/threads/tree.js +171 -0
- package/dist/domain/tui-session/index.d.ts +2 -0
- package/dist/domain/tui-session/index.js +3 -0
- package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
- package/dist/domain/tui-session/tui-session-service.js +103 -0
- package/dist/domain/tui-session/types.d.ts +67 -0
- package/dist/domain/tui-session/types.js +4 -0
- package/dist/domain/ui-service/index.d.ts +5 -0
- package/dist/domain/ui-service/index.js +3 -0
- package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
- package/dist/domain/ui-service/mutate/executions.js +15 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
- package/dist/domain/ui-service/mutate/schedules.js +39 -0
- package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
- package/dist/domain/ui-service/mutate/tasks.js +59 -0
- package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
- package/dist/domain/ui-service/mutate/threads.js +21 -0
- package/dist/domain/ui-service/query/cost.d.ts +3 -0
- package/dist/domain/ui-service/query/cost.js +6 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -0
- package/dist/domain/ui-service/query/executions.js +35 -0
- package/dist/domain/ui-service/query/projects.d.ts +2 -0
- package/dist/domain/ui-service/query/projects.js +30 -0
- package/dist/domain/ui-service/query/schedules.d.ts +2 -0
- package/dist/domain/ui-service/query/schedules.js +23 -0
- package/dist/domain/ui-service/query/sessions.d.ts +2 -0
- package/dist/domain/ui-service/query/sessions.js +35 -0
- package/dist/domain/ui-service/query/tasks.d.ts +2 -0
- package/dist/domain/ui-service/query/tasks.js +30 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -0
- package/dist/domain/ui-service/query/threads.js +27 -0
- package/dist/domain/ui-service/subscribe.d.ts +5 -0
- package/dist/domain/ui-service/subscribe.js +118 -0
- package/dist/domain/ui-service/types.d.ts +237 -0
- package/dist/domain/ui-service/types.js +5 -0
- package/dist/domain/ui-service/ui-service.d.ts +2 -0
- package/dist/domain/ui-service/ui-service.js +83 -0
- package/dist/entry/app.js +130 -8
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/daemon.js +12 -30
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +29 -5
- package/dist/entry/init.js +323 -233
- package/dist/entry/startup-notify.js +6 -3
- package/dist/events/event-types.d.ts +14 -0
- package/dist/hooks/cortex-md-injector.mjs +47 -31
- package/dist/hooks/post-task-hook.mjs +6 -0
- package/dist/hooks/task-status-check.mjs +8 -0
- package/dist/orchestration/agent-runner.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +55 -55
- package/dist/orchestration/conduit-queue.d.ts +18 -0
- package/dist/orchestration/conduit-queue.js +32 -0
- package/dist/orchestration/conversation-runner.d.ts +48 -0
- package/dist/orchestration/conversation-runner.js +109 -0
- package/dist/orchestration/dispatch-reconciler.js +8 -1
- package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
- package/dist/orchestration/interactions/ask-user-question.js +3 -3
- package/dist/orchestration/interactions/interaction-handlers.js +55 -23
- package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
- package/dist/orchestration/interactions/plan-handler.js +4 -3
- package/dist/orchestration/interactions/update-prompt-slack.js +11 -10
- package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +155 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +25 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +45 -52
- package/dist/orchestration/routing/commands/channel.js +41 -27
- package/dist/orchestration/routing/commands/cost.js +11 -2
- package/dist/orchestration/routing/commands/device.js +12 -9
- package/dist/orchestration/routing/commands/dispatch.js +11 -10
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +15 -10
- package/dist/orchestration/routing/commands/lang.d.ts +3 -0
- package/dist/orchestration/routing/commands/lang.js +31 -0
- package/dist/orchestration/routing/commands/mode.js +32 -30
- package/dist/orchestration/routing/commands/nvtop.js +15 -13
- package/dist/orchestration/routing/commands/orient.js +2 -1
- package/dist/orchestration/routing/commands/schedule.js +23 -22
- package/dist/orchestration/routing/commands/sendfile.js +9 -7
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +24 -39
- package/dist/orchestration/routing/commands/status.js +78 -71
- package/dist/orchestration/routing/commands/tail.js +7 -5
- package/dist/orchestration/routing/commands/task.js +25 -23
- package/dist/orchestration/routing/commands/thread-handlers.js +55 -44
- package/dist/orchestration/routing/edit-handler.js +8 -7
- package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
- package/dist/orchestration/routing/message-router.d.ts +1 -1
- package/dist/orchestration/routing/message-router.js +9 -9
- package/dist/orchestration/routing/webhook.js +233 -2
- package/dist/orchestration/status-helpers.d.ts +5 -1
- package/dist/orchestration/status-helpers.js +13 -11
- package/dist/orchestration/thread-callback.d.ts +67 -0
- package/dist/orchestration/thread-callback.js +465 -0
- package/dist/orchestration/thread-executor.d.ts +22 -1
- package/dist/orchestration/thread-executor.js +85 -36
- package/dist/platform/adapter.d.ts +6 -2
- package/dist/platform/adapters/composite-adapter.d.ts +89 -0
- package/dist/platform/adapters/composite-adapter.js +318 -0
- package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
- package/dist/platform/adapters/feishu-output-stream.js +274 -36
- package/dist/platform/adapters/feishu.d.ts +50 -5
- package/dist/platform/adapters/feishu.js +370 -116
- package/dist/platform/adapters/index.d.ts +24 -3
- package/dist/platform/adapters/index.js +89 -11
- package/dist/platform/adapters/project-conduits.d.ts +9 -0
- package/dist/platform/adapters/project-conduits.js +42 -0
- package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
- package/dist/platform/adapters/slack-project-conduits.js +6 -40
- package/dist/platform/adapters/slack.d.ts +9 -2
- package/dist/platform/adapters/slack.js +83 -39
- package/dist/platform/adapters/tui/index.d.ts +9 -0
- package/dist/platform/adapters/tui/index.js +10 -0
- package/dist/platform/adapters/tui/ports.d.ts +20 -0
- package/dist/platform/adapters/tui/ports.js +4 -0
- package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
- package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
- package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
- package/dist/platform/adapters/tui/tui-connection.js +53 -0
- package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
- package/dist/platform/adapters/tui/tui-gateway.js +919 -0
- package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
- package/dist/platform/adapters/tui/tui-notifications.js +60 -0
- package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
- package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
- package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
- package/dist/platform/adapters/tui/tui-transcript.js +56 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +2 -1
- package/dist/platform/interactive-builder.js +21 -19
- package/dist/platform/output-stream.d.ts +5 -0
- package/dist/platform/testing.d.ts +7 -11
- package/dist/platform/testing.js +18 -15
- package/dist/platform/tool-trace.js +15 -5
- package/dist/platform/tui/protocol.d.ts +355 -0
- package/dist/platform/tui/protocol.js +199 -0
- package/dist/platform/types.d.ts +12 -3
- package/dist/store/execution-repo.d.ts +6 -1
- package/dist/store/execution-repo.js +13 -3
- package/dist/store/hook-sync.d.ts +18 -0
- package/dist/store/hook-sync.js +92 -0
- package/dist/store/outbound-queue.js +2 -2
- package/dist/store/profile-repo.js +3 -2
- package/dist/store/schedule-repo.d.ts +1 -8
- package/dist/store/session-registry-repo.d.ts +9 -1
- package/dist/store/session-registry-repo.js +19 -3
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +23 -0
- package/dist/store/thread-repo.d.ts +3 -0
- package/dist/store/thread-repo.js +49 -2
- package/dist/store/version-migrations.d.ts +7 -0
- package/dist/store/version-migrations.js +183 -0
- package/dist/tui/App.d.ts +27 -0
- package/dist/tui/App.js +219 -0
- package/dist/tui/components/AskUserModal.d.ts +11 -0
- package/dist/tui/components/AskUserModal.js +364 -0
- package/dist/tui/components/ConfirmModal.d.ts +12 -0
- package/dist/tui/components/ConfirmModal.js +31 -0
- package/dist/tui/components/Dashboard.d.ts +23 -0
- package/dist/tui/components/Dashboard.js +80 -0
- package/dist/tui/components/DashboardCostTab.d.ts +7 -0
- package/dist/tui/components/DashboardCostTab.js +16 -0
- package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
- package/dist/tui/components/DashboardExecutionsTab.js +94 -0
- package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
- package/dist/tui/components/DashboardSchedulesTab.js +124 -0
- package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
- package/dist/tui/components/DashboardTasksTab.js +200 -0
- package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
- package/dist/tui/components/DashboardThreadsTab.js +81 -0
- package/dist/tui/components/Header.d.ts +11 -0
- package/dist/tui/components/Header.js +5 -0
- package/dist/tui/components/InputBox.d.ts +10 -0
- package/dist/tui/components/InputBox.js +19 -0
- package/dist/tui/components/MessageRow.d.ts +7 -0
- package/dist/tui/components/MessageRow.js +10 -0
- package/dist/tui/components/Notifications.d.ts +19 -0
- package/dist/tui/components/Notifications.js +72 -0
- package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
- package/dist/tui/components/PlanFeedbackModal.js +161 -0
- package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
- package/dist/tui/components/ProjectSwitcher.js +43 -0
- package/dist/tui/components/SessionPicker.d.ts +14 -0
- package/dist/tui/components/SessionPicker.js +34 -0
- package/dist/tui/components/SidePanel.d.ts +19 -0
- package/dist/tui/components/SidePanel.js +8 -0
- package/dist/tui/components/StatusLine.d.ts +10 -0
- package/dist/tui/components/StatusLine.js +29 -0
- package/dist/tui/components/Transcript.d.ts +13 -0
- package/dist/tui/components/Transcript.js +56 -0
- package/dist/tui/hooks/useDashboardData.d.ts +32 -0
- package/dist/tui/hooks/useDashboardData.js +104 -0
- package/dist/tui/hooks/useKeybindings.d.ts +19 -0
- package/dist/tui/hooks/useKeybindings.js +87 -0
- package/dist/tui/hooks/useMutate.d.ts +22 -0
- package/dist/tui/hooks/useMutate.js +56 -0
- package/dist/tui/hooks/useNotifications.d.ts +28 -0
- package/dist/tui/hooks/useNotifications.js +70 -0
- package/dist/tui/hooks/useTranscript.d.ts +39 -0
- package/dist/tui/hooks/useTranscript.js +265 -0
- package/dist/tui/hooks/useWsClient.d.ts +29 -0
- package/dist/tui/hooks/useWsClient.js +69 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +210 -0
- package/dist/tui/logic.d.ts +16 -0
- package/dist/tui/logic.js +49 -0
- package/dist/tui/render/markdown.d.ts +10 -0
- package/dist/tui/render/markdown.js +38 -0
- package/dist/tui/render/rich-blocks.d.ts +11 -0
- package/dist/tui/render/rich-blocks.js +24 -0
- package/dist/tui/ws-client.d.ts +44 -0
- package/dist/tui/ws-client.js +157 -0
- package/package.json +11 -3
- package/dist/orchestration/channel-queue.d.ts +0 -18
- package/dist/orchestration/channel-queue.js +0 -32
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// pos: Agent runtime lifecycle handling (success/failure/approval/resume)
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { createLogger } from '../core/log.js';
|
|
6
|
+
import { Icons } from '../core/icons.js';
|
|
7
|
+
import { t } from '../core/i18n.js';
|
|
6
8
|
import { trackPendingTask } from './busy-tracker.js';
|
|
7
|
-
import { enqueue } from './
|
|
9
|
+
import { enqueue } from './conduit-queue.js';
|
|
8
10
|
import { supersededEdits } from './superseded-edits.js';
|
|
9
11
|
import { runningExecutions } from '../core/running-executions.js';
|
|
10
12
|
import { finalizeLocalExecution, buildSessionTag, buildUserProcessingMessage, makeFallbackNotifier, makeStreamingMessageCallback, computeElapsed, formatMetricsSuffix, writeStatus, sealStatus, buildStatusActionBlocks, buildSealedStatusActionBlocks, initStatusBlocks } from './status-helpers.js';
|
|
@@ -24,7 +26,7 @@ import { getOutboundQueue } from '../store/outbound-queue.js';
|
|
|
24
26
|
import { buildDurableHooks, durablePost } from './durable-helpers.js';
|
|
25
27
|
const log = createLogger('lifecycle');
|
|
26
28
|
// --- Agent success handler ---
|
|
27
|
-
export async function handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger = 'user', sessionName = null,
|
|
29
|
+
export async function handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger = 'user', sessionName = null, threadAnchorId = null, userMessageTs = null, onAssistantMessage = null }) {
|
|
28
30
|
if (result?.sessionId)
|
|
29
31
|
await setSessionAsync(channel, result.sessionId, resolveBackendForChannel(channel));
|
|
30
32
|
await registerOrUpdateSession(result, sessionName, channel, trigger, projectStore.resolveFromMessage(userMessage)?.id ?? 'general');
|
|
@@ -34,10 +36,10 @@ export async function handleAgentSuccess({ result, channel, adapter, statusMsg,
|
|
|
34
36
|
const metrics = formatMetricsSuffix({ costUsd: result?.total_cost_usd ?? null, numTurns: result?.num_turns ?? null });
|
|
35
37
|
const sessionTag = buildSessionTag(sessionName, result?.sessionId);
|
|
36
38
|
const stream = onAssistantMessage?.stream ?? null;
|
|
37
|
-
const askCount = await askUserQuestion.sendMessages(result, channel, adapter, statusMsg.messageId,
|
|
39
|
+
const askCount = await askUserQuestion.sendMessages(result, channel, adapter, statusMsg.messageId, threadAnchorId, stream);
|
|
38
40
|
const statusText = askCount > 0
|
|
39
|
-
?
|
|
40
|
-
:
|
|
41
|
+
? `${Icons.waiting} ${sessionTag}${t('status.waitingForUserInput')} (${elapsedStr}${metrics})`
|
|
42
|
+
: `${Icons.ok} ${t('status.done')} | ${sessionTag}(${elapsedStr}${metrics})`;
|
|
41
43
|
await sealStatus(adapter, statusMsg, statusText, buildSealedStatusActionBlocks(statusText, { channel, sessionName, isDm: true }));
|
|
42
44
|
if (userMessageTs) {
|
|
43
45
|
await conversationLedger.completeTurn(channel, userMessageTs, { executionId });
|
|
@@ -100,15 +102,16 @@ async function backfillLedgerSessionId(result, channel) {
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
// --- Agent error handler ---
|
|
103
|
-
export async function handleAgentError({ error, channel, adapter, statusMsg, startTime, executionId, sessionName = null, sessionId = null, effectiveSessionId = null,
|
|
104
|
-
|
|
105
|
+
export async function handleAgentError({ error, channel, adapter, statusMsg, startTime, executionId, sessionName = null, sessionId = null, effectiveSessionId = null, threadAnchorId = null, userMessageTs = null }) {
|
|
106
|
+
if (executionId)
|
|
107
|
+
runningExecutions.fail(executionId, error.message);
|
|
105
108
|
const resolvedSessionId = effectiveSessionId || sessionId;
|
|
106
109
|
const sessionTag = buildSessionTag(sessionName, resolvedSessionId);
|
|
107
110
|
const { elapsedStr, elapsedS } = computeElapsed(startTime);
|
|
108
111
|
if (error?.cancelled && supersededEdits.check(channel)) {
|
|
109
112
|
supersededEdits.clear(channel);
|
|
110
113
|
finalizeLocalExecution({ executionId, status: 'cancelled', error, durationS: elapsedS });
|
|
111
|
-
const supersededText =
|
|
114
|
+
const supersededText = `${Icons.superseded} ${sessionTag}${t('status.supersededByEdit')} (${elapsedStr})`;
|
|
112
115
|
await sealStatus(adapter, statusMsg, supersededText, buildSealedStatusActionBlocks(supersededText, { channel, sessionName, isDm: true }));
|
|
113
116
|
return;
|
|
114
117
|
}
|
|
@@ -117,21 +120,21 @@ export async function handleAgentError({ error, channel, adapter, statusMsg, sta
|
|
|
117
120
|
await conversationLedger.completeTurn(channel, userMessageTs, { executionId });
|
|
118
121
|
if (error?.cancelled) {
|
|
119
122
|
finalizeLocalExecution({ executionId, status: 'failed', error, durationS: elapsedS });
|
|
120
|
-
const cancelledText =
|
|
123
|
+
const cancelledText = `${Icons.stopped} ${sessionTag}${t('status.cancelled')} (${elapsedStr})`;
|
|
121
124
|
await sealStatus(adapter, statusMsg, cancelledText, buildSealedStatusActionBlocks(cancelledText, { channel, sessionName, isDm: true }));
|
|
122
125
|
return;
|
|
123
126
|
}
|
|
124
127
|
log.error('Agent error:', error.message);
|
|
125
128
|
finalizeLocalExecution({ executionId, status: 'failed', error, durationS: elapsedS });
|
|
126
|
-
const errorText =
|
|
129
|
+
const errorText = `${Icons.error} ${sessionTag}${t('status.error')} (${elapsedStr})`;
|
|
127
130
|
await sealStatus(adapter, statusMsg, errorText, buildSealedStatusActionBlocks(errorText, { channel, sessionName, isDm: true }));
|
|
128
131
|
const errorDest = { type: 'interactive-reply', conduit: channel, sessionId: resolvedSessionId ?? '' };
|
|
129
132
|
const queue = getOutboundQueue();
|
|
130
133
|
if (queue) {
|
|
131
|
-
await durablePost(queue, adapter, errorDest, { text:
|
|
134
|
+
await durablePost(queue, adapter, errorDest, { text: t('status.errorBody', { message: error.message }) }, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
132
135
|
}
|
|
133
136
|
else {
|
|
134
|
-
await adapter.postMessage(errorDest, { text:
|
|
137
|
+
await adapter.postMessage(errorDest, { text: t('status.errorBody', { message: error.message }) }, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
async function persistErrorSession(resolvedSessionId, sessionName, channel, adapter) {
|
|
@@ -150,7 +153,7 @@ async function persistErrorSession(resolvedSessionId, sessionName, channel, adap
|
|
|
150
153
|
// --- AskUserQuestion resume ---
|
|
151
154
|
export async function resumeAskUserQuestionGroup({ adapter, group, responseText }) {
|
|
152
155
|
const askDest = { type: 'interactive-reply', conduit: group.channel, sessionId: group.sessionId };
|
|
153
|
-
const statusMsg = await adapter.postMessage(askDest, { text:
|
|
156
|
+
const statusMsg = await adapter.postMessage(askDest, { text: `${Icons.processing} ${t('status.processingAskResponse')}` });
|
|
154
157
|
const startTime = Date.now();
|
|
155
158
|
let executionId = null;
|
|
156
159
|
let handle;
|
|
@@ -168,9 +171,9 @@ export async function resumeAskUserQuestionGroup({ adapter, group, responseText
|
|
|
168
171
|
const askDurable = askQueue ? buildDurableHooks(askQueue) : null;
|
|
169
172
|
const onAssistantMsg = makeStreamingMessageCallback(adapter, askDest, null, null, askDurable);
|
|
170
173
|
handle = runAgent(responseText, { channel: group.channel, sessionId: group.sessionId, files: [], project: projectStore.resolveFromMessage(responseText)?.id ?? 'general', trigger: 'ask-user-question', onAssistantMessage: onAssistantMsg });
|
|
171
|
-
runningExecutions.register(
|
|
174
|
+
runningExecutions.register({ threadId: group.threadId ?? null, channel: group.channel, agentSlotId: null, executionId, kill: () => handle.kill(), backend: askBackend });
|
|
172
175
|
const result = await handle.promise;
|
|
173
|
-
runningExecutions.complete(
|
|
176
|
+
runningExecutions.complete(executionId, result?.total_cost_usd ?? 0);
|
|
174
177
|
await maybeNotifyCodexLowUsage({ adapter, result });
|
|
175
178
|
await handleAgentSuccess({ result, channel: group.channel, adapter, statusMsg, startTime, userMessage: responseText, executionId, trigger: 'ask-user-question', onAssistantMessage: onAssistantMsg });
|
|
176
179
|
}
|
|
@@ -199,7 +202,7 @@ async function executeRetry(channel, text, adapter, opts) {
|
|
|
199
202
|
const sessionName = opts.sessionName || await sessionStore.generateSessionName();
|
|
200
203
|
const userMessageTs = opts.originalTs;
|
|
201
204
|
const retryDest = { type: 'interactive-reply', conduit: channel, sessionId: sessionId ?? '' };
|
|
202
|
-
const retryPrefix = '
|
|
205
|
+
const retryPrefix = `${Icons.refresh} ${t('status.retry')} (${t('status.retryEdited')}) | `;
|
|
203
206
|
const retryStatusText = retryPrefix + buildUserProcessingMessage({ startTime, profileName: getActiveProfile(channel), sessionName, sessionId });
|
|
204
207
|
const retryBlocksTemplate = { channel, sessionName, isDm: true };
|
|
205
208
|
const statusMsg = await adapter.postMessage(retryDest, {
|
|
@@ -233,14 +236,14 @@ async function runRetryAgent({ channel, text, adapter, statusMsg, startTime, ses
|
|
|
233
236
|
isUserInitiated: true, onAssistantMessage: onAssistantMsg,
|
|
234
237
|
onProgress: buildRetryProgressUpdater(adapter, channel, statusMsg, retryPrefix, startTime, sessionName, sessionId),
|
|
235
238
|
});
|
|
236
|
-
runningExecutions.register(
|
|
239
|
+
runningExecutions.register({ threadId: null /* A5: edit-retry — threadId not yet wired; Cancel button will warn */, channel, agentSlotId: null, executionId, kill: () => handle.kill(), backend: retryBackend });
|
|
237
240
|
const result = await handle.promise;
|
|
238
|
-
runningExecutions.complete(
|
|
241
|
+
runningExecutions.complete(executionId, result?.total_cost_usd ?? 0);
|
|
239
242
|
clearStreamingCallback(channel);
|
|
240
243
|
await maybeNotifyCodexLowUsage({ adapter, result });
|
|
241
244
|
if (result?.rateLimited) {
|
|
242
245
|
const { elapsedStr } = computeElapsed(startTime);
|
|
243
|
-
const rateLimitText =
|
|
246
|
+
const rateLimitText = `${Icons.warning} ${buildSessionTag(sessionName, sessionId)}${t('status.rateLimitedExhausted')} (${elapsedStr})`;
|
|
244
247
|
await sealStatus(adapter, statusMsg, rateLimitText, buildSealedStatusActionBlocks(rateLimitText, { channel, sessionName, isDm: true }));
|
|
245
248
|
}
|
|
246
249
|
else {
|
|
@@ -263,17 +266,17 @@ function buildRetryProgressUpdater(adapter, channel, statusMsg, retryPrefix, sta
|
|
|
263
266
|
}
|
|
264
267
|
// --- Internal helpers ---
|
|
265
268
|
function updateRetryPermalinks(adapter, channel, userMessageTs, statusMsg, supersededTimestamps, retryPrefix, startTime, sessionName, sessionId) {
|
|
266
|
-
const userPermalinkP = adapter.getPermalink({ channel, messageId: userMessageTs }).catch(() => null);
|
|
269
|
+
const userPermalinkP = adapter.getPermalink({ conduit: channel, messageId: userMessageTs }).catch(() => null);
|
|
267
270
|
const statusPermalinkP = supersededTimestamps?.length
|
|
268
271
|
? adapter.getPermalink(statusMsg).catch(() => null)
|
|
269
272
|
: Promise.resolve(null);
|
|
270
273
|
Promise.all([userPermalinkP, statusPermalinkP]).then(([userPermalink, statusPermalink]) => {
|
|
271
274
|
if (userPermalink) {
|
|
272
|
-
writeStatus(adapter, statusMsg,
|
|
275
|
+
writeStatus(adapter, statusMsg, `${Icons.refresh} ${t('status.retry')} (<${userPermalink}|${t('status.retryEdited')}>) | ` + buildUserProcessingMessage({ startTime, profileName: getActiveProfile(channel), sessionName, sessionId }));
|
|
273
276
|
}
|
|
274
277
|
if (statusPermalink && supersededTimestamps?.length) {
|
|
275
278
|
for (const oldTs of supersededTimestamps) {
|
|
276
|
-
adapter.updateMessage({ channel, messageId: oldTs }, { text:
|
|
279
|
+
adapter.updateMessage({ conduit: channel, messageId: oldTs }, { text: `${Icons.superseded} ${t('status.supersededByEdit')} \u2014 <${statusPermalink}|${t('status.supersededSeeNewReply')}>` }).catch(() => { });
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
}).catch(() => { });
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { createLogger } from '../../../core/log.js';
|
|
2
|
+
import { Icons } from '../../../core/icons.js';
|
|
3
|
+
import { t } from '../../../core/i18n.js';
|
|
2
4
|
import { runningExecutions } from '../../../core/running-executions.js';
|
|
3
|
-
import {
|
|
5
|
+
import { conduitQueues } from '../../conduit-queue.js';
|
|
4
6
|
import { cancelThread as cancelThreadById } from '../../../domain/threads/index.js';
|
|
5
7
|
import { setSessionAsync } from '../../../domain/sessions/session.js';
|
|
6
8
|
import { getActiveBackend } from '../../../domain/agents/index.js';
|
|
9
|
+
import * as executionRegistry from '../../../domain/executions/registry.js';
|
|
10
|
+
/** Cancel one live execution: preserve its session, cancel its thread record, then tear it down as
|
|
11
|
+
* 'cancelled'. teardownExecution sets the persistent record cancelled BEFORE killing the handle, so
|
|
12
|
+
* the kill-error path's failExecution is a terminal no-op — and it publishes a balanced terminal
|
|
13
|
+
* event so agent.started is not left dangling. */
|
|
14
|
+
async function cancelLive(exec, channel) {
|
|
15
|
+
if (exec.sessionId)
|
|
16
|
+
await setSessionAsync(channel, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
17
|
+
if (exec.threadId)
|
|
18
|
+
await cancelThreadById(exec.threadId).catch(() => { });
|
|
19
|
+
if (exec.executionId) {
|
|
20
|
+
executionRegistry.teardownExecution({ executionId: exec.executionId, status: 'cancelled', durationS: 0 });
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
runningExecutions.killById(exec.registryKey);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
/** Matches thread IDs like `thr_a1b2c3d4`. */
|
|
8
27
|
const THREAD_ID_RE = /^thr_[0-9a-f]{8}$/;
|
|
9
28
|
const log = createLogger('cancel');
|
|
@@ -11,29 +30,19 @@ const MAX_CANCEL_BUTTONS = 10;
|
|
|
11
30
|
export function createCancelHandler(cancelDispatchedTask, router) {
|
|
12
31
|
if (router) {
|
|
13
32
|
const cancelHandler = async (ctx) => {
|
|
14
|
-
const { threadId,
|
|
33
|
+
const { threadId, executionId } = JSON.parse(ctx.value);
|
|
15
34
|
const adapter = router.getAdapter();
|
|
16
35
|
if (!adapter)
|
|
17
36
|
return;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
runningExecutions.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else if (registryKey) {
|
|
27
|
-
const exec = runningExecutions.getByKey(registryKey);
|
|
28
|
-
if (exec?.sessionId) {
|
|
29
|
-
await setSessionAsync(ctx.channelId, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
30
|
-
}
|
|
31
|
-
runningExecutions.killByKey(registryKey);
|
|
32
|
-
}
|
|
33
|
-
channelQueues.delete(registryKey || threadId || ctx.channelId);
|
|
37
|
+
const exec = threadId
|
|
38
|
+
? runningExecutions.getByThreadId(threadId)
|
|
39
|
+
: (executionId ? runningExecutions.getById(executionId) : null);
|
|
40
|
+
if (exec)
|
|
41
|
+
await cancelLive(exec, ctx.channelId);
|
|
42
|
+
conduitQueues.delete(ctx.channelId);
|
|
34
43
|
if (ctx.messageRef) {
|
|
35
44
|
await adapter.updateMessage(ctx.messageRef, {
|
|
36
|
-
text:
|
|
45
|
+
text: `${Icons.stopped} ${t('cmd.cancel.cancelledShort', { id: threadId || executionId })}`,
|
|
37
46
|
}).catch(() => { });
|
|
38
47
|
}
|
|
39
48
|
};
|
|
@@ -51,43 +60,34 @@ export function createCancelHandler(cancelDispatchedTask, router) {
|
|
|
51
60
|
const firstArg = args[0];
|
|
52
61
|
// --all: kill all running executions in the current channel
|
|
53
62
|
if (firstArg === '--all') {
|
|
54
|
-
const executions = runningExecutions.
|
|
63
|
+
const executions = runningExecutions.getByChannel(channel);
|
|
55
64
|
if (executions.length === 0) {
|
|
56
|
-
await adapter.postMessage(dest, { text: '
|
|
65
|
+
await adapter.postMessage(dest, { text: t('cmd.cancel.nothingRunning') });
|
|
57
66
|
return;
|
|
58
67
|
}
|
|
59
68
|
for (const exec of executions) {
|
|
60
|
-
|
|
61
|
-
await cancelThreadById(exec.threadId).catch(() => { });
|
|
62
|
-
}
|
|
63
|
-
if (exec.sessionId) {
|
|
64
|
-
await setSessionAsync(channel, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
65
|
-
}
|
|
66
|
-
runningExecutions.killByKey(exec.registryKey);
|
|
69
|
+
await cancelLive(exec, channel);
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
await adapter.postMessage(dest, { text:
|
|
71
|
+
conduitQueues.delete(channel);
|
|
72
|
+
await adapter.postMessage(dest, { text: `${Icons.stopped} ${t('cmd.cancel.cancelledN', { n: executions.length })}` });
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
72
75
|
// Thread ID pattern: kill by threadId + cancel thread store record
|
|
73
76
|
if (THREAD_ID_RE.test(firstArg)) {
|
|
74
77
|
const exec = runningExecutions.getByThreadId(firstArg);
|
|
75
|
-
if (
|
|
76
|
-
await
|
|
77
|
-
if (exec?.sessionId) {
|
|
78
|
-
await setSessionAsync(channel, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
79
|
-
}
|
|
78
|
+
if (exec) {
|
|
79
|
+
await cancelLive(exec, channel);
|
|
80
80
|
log.info('Cancel requested for thread:', firstArg);
|
|
81
|
-
await adapter.postMessage(dest, { text:
|
|
81
|
+
await adapter.postMessage(dest, { text: `${Icons.stopped} ${t('cmd.cancel.threadCancelled', { id: firstArg })}` });
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
-
await adapter.postMessage(dest, { text:
|
|
84
|
+
await adapter.postMessage(dest, { text: t('cmd.cancel.threadNotFound', { id: firstArg }) });
|
|
85
85
|
}
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
// Fallback: dispatched-task cancellation
|
|
89
89
|
if (!cancelDispatchedTask) {
|
|
90
|
-
await adapter.postMessage(dest, { text: '
|
|
90
|
+
await adapter.postMessage(dest, { text: t('cmd.cancel.dispatchUnavailable') });
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
const result = await cancelDispatchedTask({ taskId: firstArg, channel });
|
|
@@ -95,7 +95,7 @@ export function createCancelHandler(cancelDispatchedTask, router) {
|
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
// No args: check how many executions are running on this channel
|
|
98
|
-
const executions = runningExecutions.
|
|
98
|
+
const executions = runningExecutions.getByChannel(channel);
|
|
99
99
|
// 0 executions: nothing to cancel
|
|
100
100
|
if (executions.length === 0) {
|
|
101
101
|
await adapter.postMessage(dest, { text: 'Nothing running to cancel.' });
|
|
@@ -103,32 +103,25 @@ export function createCancelHandler(cancelDispatchedTask, router) {
|
|
|
103
103
|
}
|
|
104
104
|
// 1 execution: cancel directly (existing default behavior)
|
|
105
105
|
if (executions.length === 1) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
runningExecutions.killByKey(exec.registryKey);
|
|
111
|
-
if (exec.sessionId) {
|
|
112
|
-
await setSessionAsync(channel, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
113
|
-
}
|
|
114
|
-
channelQueues.delete(channel);
|
|
115
|
-
await adapter.postMessage(dest, { text: ':octagonal_sign: Cancelled. Session preserved — next message will resume.' });
|
|
106
|
+
await cancelLive(executions[0], channel);
|
|
107
|
+
conduitQueues.delete(channel);
|
|
108
|
+
await adapter.postMessage(dest, { text: `${Icons.stopped} ${t('cmd.cancel.cancelledSessionPreserved')}` });
|
|
116
109
|
return;
|
|
117
110
|
}
|
|
118
111
|
// 2+ executions: show interactive list with cancel buttons
|
|
119
112
|
return {
|
|
120
|
-
text:
|
|
113
|
+
text: t('cmd.cancel.runningTasks', { n: executions.length }),
|
|
121
114
|
richBlocks: executions.map(exec => ({
|
|
122
115
|
type: 'section',
|
|
123
116
|
text: `\`${exec.threadId || exec.registryKey}\` · started ${new Date(exec.startTime).toLocaleTimeString()} · ${exec.backend}${exec.channel ? ` · ${exec.channel}` : ''}`,
|
|
124
117
|
})),
|
|
125
118
|
actions: executions.map((exec, i) => ({
|
|
126
119
|
type: 'button',
|
|
127
|
-
text:
|
|
120
|
+
text: t('cmd.cancel.cancelButton', { id: exec.threadId || exec.registryKey }),
|
|
128
121
|
actionId: `cmd:cancel:exec-${i}`,
|
|
129
122
|
value: JSON.stringify({
|
|
130
123
|
threadId: exec.threadId,
|
|
131
|
-
|
|
124
|
+
executionId: exec.executionId,
|
|
132
125
|
}),
|
|
133
126
|
style: 'danger',
|
|
134
127
|
})),
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
import { projectStore } from '../../../domain/projects/index.js';
|
|
2
2
|
import { projectDirRepo } from '../../../store/project-dir-repo.js';
|
|
3
|
+
import { Icons } from '../../../core/icons.js';
|
|
4
|
+
import { t } from '../../../core/i18n.js';
|
|
3
5
|
import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Render a (possibly platform-prefixed) conduit for display.
|
|
8
|
+
* Slack channels become a `<#id>` mention; other platforms (Feishu/TUI) show
|
|
9
|
+
* the bare id in code formatting since `<#…>` is Slack-only syntax.
|
|
10
|
+
*/
|
|
11
|
+
function displayConduit(conduit) {
|
|
12
|
+
if (conduit.startsWith('slack:'))
|
|
13
|
+
return `<#${conduit.slice('slack:'.length)}>`;
|
|
14
|
+
const colon = conduit.indexOf(':');
|
|
15
|
+
const bare = colon === -1 ? conduit : conduit.slice(colon + 1);
|
|
16
|
+
return `\`${bare}\``;
|
|
17
|
+
}
|
|
4
18
|
export async function handleProjectsCmd(channel, adapter) {
|
|
5
19
|
const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
6
20
|
const projects = projectStore.list().map(p => p.id);
|
|
7
21
|
if (projects.length === 0) {
|
|
8
|
-
await adapter.postMessage(dest, { text: '
|
|
22
|
+
await adapter.postMessage(dest, { text: t('cmd.channel.noProjects') });
|
|
9
23
|
return;
|
|
10
24
|
}
|
|
11
25
|
const registrations = await adapter.getProjectConduits();
|
|
12
26
|
const lines = projects.map(p => {
|
|
13
27
|
const ch = registrations[p];
|
|
14
|
-
const status = ch ? ` →
|
|
28
|
+
const status = ch ? ` → ${displayConduit(ch)}` : '';
|
|
15
29
|
return `• \`${p}\`${status}`;
|
|
16
30
|
});
|
|
17
|
-
await adapter.postMessage(dest, { text:
|
|
31
|
+
await adapter.postMessage(dest, { text: t('cmd.channel.projectsHeader', { list: lines.join('\n') }) });
|
|
18
32
|
}
|
|
19
33
|
const MAX_PROJECT_BUTTONS = 10;
|
|
20
34
|
export function createRegisterHandler(router) {
|
|
@@ -28,7 +42,7 @@ export function createRegisterHandler(router) {
|
|
|
28
42
|
await adapter.bindProjectConduit(project, ctx.channelId);
|
|
29
43
|
if (ctx.messageRef) {
|
|
30
44
|
await adapter.updateMessage(ctx.messageRef, {
|
|
31
|
-
text:
|
|
45
|
+
text: `${Icons.ok} ${t('cmd.channel.registeredNotification', { project })}`,
|
|
32
46
|
}).catch(() => { });
|
|
33
47
|
}
|
|
34
48
|
}
|
|
@@ -48,11 +62,11 @@ export function createRegisterHandler(router) {
|
|
|
48
62
|
const project = args[0];
|
|
49
63
|
const projects = projectStore.list().map(p => p.id);
|
|
50
64
|
if (!projects.includes(project)) {
|
|
51
|
-
await adapter.postMessage(dest, { text:
|
|
65
|
+
await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.unknownProject', { project, available: projects.map(p => `\`${p}\``).join(', ') })}` });
|
|
52
66
|
return;
|
|
53
67
|
}
|
|
54
68
|
await adapter.bindProjectConduit(project, channel);
|
|
55
|
-
await adapter.postMessage(dest, { text:
|
|
69
|
+
await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.channelRegistered', { project })}` });
|
|
56
70
|
return;
|
|
57
71
|
}
|
|
58
72
|
const registrations = await adapter.getProjectConduits();
|
|
@@ -61,13 +75,13 @@ export function createRegisterHandler(router) {
|
|
|
61
75
|
const unbound = projects.filter(p => !bound.includes(p));
|
|
62
76
|
const lines = [];
|
|
63
77
|
if (bound.length > 0) {
|
|
64
|
-
lines.push(
|
|
78
|
+
lines.push(t('cmd.channel.registeredList', { list: bound.map(p => `\`${p}\``).join(', ') }));
|
|
65
79
|
}
|
|
66
80
|
else {
|
|
67
|
-
lines.push('
|
|
81
|
+
lines.push(t('cmd.channel.notRegisteredAny'));
|
|
68
82
|
}
|
|
69
83
|
if (unbound.length > 0) {
|
|
70
|
-
lines.push(
|
|
84
|
+
lines.push(t('cmd.channel.availableList', { list: unbound.map(p => `\`${p}\``).join(', ') }));
|
|
71
85
|
}
|
|
72
86
|
const text = lines.join('\n');
|
|
73
87
|
if (!router || unbound.length === 0) {
|
|
@@ -96,33 +110,33 @@ export async function handleUnregisterCmd(channel, adapter, trimmedMessage) {
|
|
|
96
110
|
const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
97
111
|
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
98
112
|
if (args.length === 0) {
|
|
99
|
-
await adapter.postMessage(dest, { text: '
|
|
113
|
+
await adapter.postMessage(dest, { text: t('cmd.channel.unregisterUsage') });
|
|
100
114
|
return;
|
|
101
115
|
}
|
|
102
116
|
const project = args[0];
|
|
103
117
|
const registrations = await adapter.getProjectConduits();
|
|
104
118
|
const current = registrations[project] ?? null;
|
|
105
119
|
if (!current || current !== channel) {
|
|
106
|
-
await adapter.postMessage(dest, { text:
|
|
120
|
+
await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.notRegistered', { project })}` });
|
|
107
121
|
return;
|
|
108
122
|
}
|
|
109
123
|
await adapter.unbindProjectConduit(project);
|
|
110
|
-
await adapter.postMessage(dest, { text:
|
|
124
|
+
await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.unregistered', { project })}` });
|
|
111
125
|
}
|
|
112
126
|
function buildProjectDirModal(channel) {
|
|
113
127
|
const machines = Object.keys(getMachineRegistry());
|
|
114
128
|
return {
|
|
115
129
|
callbackId: 'cmd_project_dir_add',
|
|
116
|
-
title: '
|
|
117
|
-
submitLabel: '
|
|
130
|
+
title: t('cmd.channel.modalTitle'),
|
|
131
|
+
submitLabel: t('cmd.channel.modalSubmit'),
|
|
118
132
|
privateMetadata: JSON.stringify({ channel }),
|
|
119
133
|
fields: [
|
|
120
|
-
{ type: 'text_input', blockId: 'pd_project', label: '
|
|
134
|
+
{ type: 'text_input', blockId: 'pd_project', label: t('cmd.channel.modalProjectLabel'), actionId: 'text', placeholder: t('cmd.channel.modalProjectPlaceholder') },
|
|
121
135
|
{
|
|
122
|
-
type: 'select', blockId: 'pd_machine', label: '
|
|
136
|
+
type: 'select', blockId: 'pd_machine', label: t('cmd.channel.modalMachineLabel'), actionId: 'selection',
|
|
123
137
|
options: machines.map(m => ({ label: m, value: m })),
|
|
124
138
|
},
|
|
125
|
-
{ type: 'text_input', blockId: 'pd_path', label: '
|
|
139
|
+
{ type: 'text_input', blockId: 'pd_path', label: t('cmd.channel.modalPathLabel'), actionId: 'text', placeholder: t('cmd.channel.modalPathPlaceholder') },
|
|
126
140
|
],
|
|
127
141
|
};
|
|
128
142
|
}
|
|
@@ -154,7 +168,7 @@ export function createProjectDirHandler(router) {
|
|
|
154
168
|
return;
|
|
155
169
|
await projectDirRepo.setProjectDir(project, machine, dirPath);
|
|
156
170
|
await adapter.postMessage(modalDest, {
|
|
157
|
-
text:
|
|
171
|
+
text: `${Icons.ok} ${t('cmd.channel.dirSet', { project, machine, dir: dirPath })}`,
|
|
158
172
|
});
|
|
159
173
|
},
|
|
160
174
|
}],
|
|
@@ -165,42 +179,42 @@ export function createProjectDirHandler(router) {
|
|
|
165
179
|
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
166
180
|
if (args.length > 0) {
|
|
167
181
|
if (args.length < 2) {
|
|
168
|
-
await adapter.postMessage(dest, { text: '
|
|
182
|
+
await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.projectDirUsage')}` });
|
|
169
183
|
return;
|
|
170
184
|
}
|
|
171
185
|
const [project, machine] = args;
|
|
172
186
|
const validMachines = Object.keys(getMachineRegistry());
|
|
173
187
|
if (!validMachines.includes(machine)) {
|
|
174
|
-
await adapter.postMessage(dest, { text:
|
|
188
|
+
await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.unknownMachine', { machine, valid: validMachines.map(m => `\`${m}\``).join(', ') })}` });
|
|
175
189
|
return;
|
|
176
190
|
}
|
|
177
191
|
if (args.length === 2 || args[2] === '--remove') {
|
|
178
192
|
if (args[2] === '--remove') {
|
|
179
193
|
await projectDirRepo.removeProjectDir(project, machine);
|
|
180
|
-
await adapter.postMessage(dest, { text:
|
|
194
|
+
await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.dirRemoved', { project, machine })}` });
|
|
181
195
|
}
|
|
182
196
|
else {
|
|
183
197
|
const dir = await projectDirRepo.getProjectDir(project, machine);
|
|
184
198
|
if (dir) {
|
|
185
|
-
await adapter.postMessage(dest, { text:
|
|
199
|
+
await adapter.postMessage(dest, { text: t('cmd.channel.dirShow', { project, machine, dir }) });
|
|
186
200
|
}
|
|
187
201
|
else {
|
|
188
|
-
await adapter.postMessage(dest, { text:
|
|
202
|
+
await adapter.postMessage(dest, { text: t('cmd.channel.dirNone', { project, machine }) });
|
|
189
203
|
}
|
|
190
204
|
}
|
|
191
205
|
return;
|
|
192
206
|
}
|
|
193
207
|
const dirPath = args.slice(2).join(' ');
|
|
194
208
|
await projectDirRepo.setProjectDir(project, machine, dirPath);
|
|
195
|
-
await adapter.postMessage(dest, { text:
|
|
209
|
+
await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.dirSet', { project, machine, dir: dirPath })}` });
|
|
196
210
|
return;
|
|
197
211
|
}
|
|
198
212
|
const allDirs = await projectDirRepo.getAllProjectDirs();
|
|
199
213
|
const entries = Object.entries(allDirs);
|
|
200
214
|
const lines = entries.length > 0
|
|
201
215
|
? entries.flatMap(([project, machines]) => Object.entries(machines).map(([machine, dir]) => `• \`${project}\` on \`${machine}\` → \`${dir}\``))
|
|
202
|
-
: ['
|
|
203
|
-
const text =
|
|
216
|
+
: [t('cmd.channel.noProjectDirs')];
|
|
217
|
+
const text = t('cmd.channel.projectDirsHeader', { list: lines.join('\n') });
|
|
204
218
|
if (!router) {
|
|
205
219
|
await adapter.postMessage(dest, { text });
|
|
206
220
|
return;
|
|
@@ -210,7 +224,7 @@ export function createProjectDirHandler(router) {
|
|
|
210
224
|
richBlocks: [{ type: 'section', text }],
|
|
211
225
|
actions: [{
|
|
212
226
|
type: 'button',
|
|
213
|
-
text: '
|
|
227
|
+
text: t('cmd.channel.addButton'),
|
|
214
228
|
actionId: 'cmd:project-dir:open-add',
|
|
215
229
|
value: 'add',
|
|
216
230
|
style: 'primary',
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { formatCostReport, checkBudget, setBudget } from '../../../domain/costs/cost-tracker.js';
|
|
2
|
+
import { Icons } from '../../../core/icons.js';
|
|
3
|
+
import { t } from '../../../core/i18n.js';
|
|
2
4
|
export async function handleCostCmd(channel, adapter, trimmedMessage) {
|
|
3
5
|
const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
4
6
|
const project = trimmedMessage.split(/\s+/).slice(1).join(' ').trim() || null;
|
|
@@ -10,7 +12,14 @@ export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
|
|
|
10
12
|
if (args.length === 0) {
|
|
11
13
|
const b = await checkBudget();
|
|
12
14
|
await adapter.postMessage(dest, {
|
|
13
|
-
text:
|
|
15
|
+
text: t('cmd.cost.budgetHeader', {
|
|
16
|
+
dailyBudget: b.dailyBudget,
|
|
17
|
+
dailySpent: b.dailySpent.toFixed(2),
|
|
18
|
+
dailyRemaining: b.dailyRemaining.toFixed(2),
|
|
19
|
+
monthlyBudget: b.monthlyBudget,
|
|
20
|
+
monthlySpent: b.monthlySpent.toFixed(2),
|
|
21
|
+
monthlyRemaining: b.monthlyRemaining.toFixed(2),
|
|
22
|
+
}),
|
|
14
23
|
});
|
|
15
24
|
return;
|
|
16
25
|
}
|
|
@@ -20,5 +29,5 @@ export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
|
|
|
20
29
|
daily_usd: daily ? parseFloat(daily) : undefined,
|
|
21
30
|
monthly_usd: monthly ? parseFloat(monthly) : undefined,
|
|
22
31
|
});
|
|
23
|
-
await adapter.postMessage(dest, { text:
|
|
32
|
+
await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.cost.budgetUpdated', { daily: result.daily_usd, monthly: result.monthly_usd })}` });
|
|
24
33
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getOnlineDevices } from '../../../domain/remote/client-manager.js';
|
|
2
2
|
import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
|
|
3
|
+
import { Icons } from '../../../core/icons.js';
|
|
4
|
+
import { t } from '../../../core/i18n.js';
|
|
3
5
|
function formatTimeAgo(ms) {
|
|
4
6
|
const seconds = Math.floor(ms / 1000);
|
|
5
7
|
if (seconds < 60)
|
|
@@ -19,29 +21,30 @@ function buildDevicesText() {
|
|
|
19
21
|
for (const d of onlineDevices)
|
|
20
22
|
knownNames.add(d.device);
|
|
21
23
|
const now = Date.now();
|
|
22
|
-
const lines = ['
|
|
24
|
+
const lines = [t('cmd.device.header')];
|
|
23
25
|
for (const name of [...knownNames].sort()) {
|
|
24
26
|
const online = onlineDevices.find(d => d.device === name);
|
|
25
27
|
if (online) {
|
|
26
28
|
const connAgo = formatTimeAgo(now - online.connectedAt.getTime());
|
|
27
29
|
const hbAgo = formatTimeAgo(now - online.lastHeartbeat.getTime());
|
|
28
|
-
lines.push(
|
|
30
|
+
lines.push(`${Icons.ok} ${t('cmd.device.online', { name, platform: online.platform, connAgo, hbAgo })}`);
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
|
-
lines.push(
|
|
33
|
+
lines.push(`${Icons.error} ${t('cmd.device.offline', { name })}`);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
if (knownNames.size === 0) {
|
|
35
|
-
lines.push('
|
|
37
|
+
lines.push(t('cmd.device.none'));
|
|
36
38
|
}
|
|
37
39
|
return lines.join('\n');
|
|
38
40
|
}
|
|
39
|
-
|
|
41
|
+
// Built per call so the label is resolved in the active locale (not frozen at import time).
|
|
42
|
+
const refreshButton = () => ({
|
|
40
43
|
type: 'button',
|
|
41
|
-
text: '
|
|
44
|
+
text: t('cmd.device.refreshButton'),
|
|
42
45
|
actionId: 'cmd:devices:refresh',
|
|
43
46
|
value: 'refresh',
|
|
44
|
-
};
|
|
47
|
+
});
|
|
45
48
|
export function createDevicesHandler(router) {
|
|
46
49
|
if (router) {
|
|
47
50
|
router.registerCommand('devices', {
|
|
@@ -56,7 +59,7 @@ export function createDevicesHandler(router) {
|
|
|
56
59
|
text,
|
|
57
60
|
richBlocks: [
|
|
58
61
|
{ type: 'section', text },
|
|
59
|
-
{ type: 'actions', elements: [
|
|
62
|
+
{ type: 'actions', elements: [refreshButton()] },
|
|
60
63
|
],
|
|
61
64
|
}).catch(() => { });
|
|
62
65
|
},
|
|
@@ -73,7 +76,7 @@ export function createDevicesHandler(router) {
|
|
|
73
76
|
return {
|
|
74
77
|
text,
|
|
75
78
|
richBlocks: [{ type: 'section', text }],
|
|
76
|
-
actions: [
|
|
79
|
+
actions: [refreshButton()],
|
|
77
80
|
};
|
|
78
81
|
};
|
|
79
82
|
}
|