@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
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import * as executionRegistry from '../domain/executions/registry.js';
|
|
6
6
|
import * as pendingTaskTracker from '../domain/tasks/pending-tracker.js';
|
|
7
|
-
|
|
7
|
+
import { runningExecutions } from '../core/running-executions.js';
|
|
8
|
+
const RECONCILE_INTERVAL_MS = 2 * 60 * 1000;
|
|
9
|
+
// Crash-orphan grace: a dispatch that is neither pending-remote nor live-in-process for this long
|
|
10
|
+
// is treated as a crashed in-process orphan and reaped (frees a concurrency slot in minutes).
|
|
11
|
+
const DISPATCH_ORPHAN_GRACE_MS = 2 * 60 * 1000;
|
|
12
|
+
// Hard ceiling for a still-live but wedged dispatch.
|
|
8
13
|
const DISPATCH_STALE_AGE_MS = 3 * 60 * 60 * 1000;
|
|
9
14
|
export function startDispatchReconciler() {
|
|
10
15
|
setInterval(() => {
|
|
11
16
|
executionRegistry.reconcileStaleDispatches({
|
|
12
17
|
isTaskPending: (taskId) => pendingTaskTracker.getTask(taskId) !== null,
|
|
18
|
+
isLive: (executionId) => runningExecutions.getById(executionId) !== null,
|
|
19
|
+
graceMs: DISPATCH_ORPHAN_GRACE_MS,
|
|
13
20
|
maxAgeMs: DISPATCH_STALE_AGE_MS,
|
|
14
21
|
});
|
|
15
22
|
}, RECONCILE_INTERVAL_MS);
|
|
@@ -27,5 +27,5 @@ declare function registerHookResolver(requestId: any, resolver: any): void;
|
|
|
27
27
|
/** If the group is in hook mode and all answers collected, resolve the hook and return true.
|
|
28
28
|
* For PI backend: if a running execution with an agentProcess exists, send extension_ui_response directly. */
|
|
29
29
|
declare function tryResolveHook(group: any): boolean;
|
|
30
|
-
declare function sendMessages(result: any, channel: any, adapter: PlatformAdapter, messageTs: any,
|
|
30
|
+
declare function sendMessages(result: any, channel: any, adapter: PlatformAdapter, messageTs: any, threadAnchorId?: any, stream?: OutputStream | null): Promise<number>;
|
|
31
31
|
export { sendMessages, formatGroupResponse, buildQuestionGroupBlocks, buildQuestionModalDefinition, isExpired, getGroup, deleteGroup, getPendingQuestion, createHookGroup, registerHookResolver, tryResolveHook, };
|
|
@@ -113,7 +113,7 @@ function tryResolveHook(group) {
|
|
|
113
113
|
// NOTE: Check for sendExtensionUiResponse capability directly instead of exec.backend,
|
|
114
114
|
// because the profile's backend (which determines the adapter) may differ from
|
|
115
115
|
// getActiveBackend() (which is stored in exec.backend).
|
|
116
|
-
const exec = runningExecutions.
|
|
116
|
+
const exec = runningExecutions.getByChannel(group.channel).find(e => e.agentProcess) ?? null;
|
|
117
117
|
if (exec && exec.agentProcess) {
|
|
118
118
|
const proc = exec.agentProcess;
|
|
119
119
|
if (typeof proc.sendExtensionUiResponse === 'function') {
|
|
@@ -137,7 +137,7 @@ function tryResolveHook(group) {
|
|
|
137
137
|
return true;
|
|
138
138
|
}
|
|
139
139
|
// --- Send questions via adapter ---
|
|
140
|
-
async function sendMessages(result, channel, adapter, messageTs,
|
|
140
|
+
async function sendMessages(result, channel, adapter, messageTs, threadAnchorId = null, stream = null) {
|
|
141
141
|
let sentCount = 0;
|
|
142
142
|
for (const payload of result.askUserQuestions || []) {
|
|
143
143
|
if (!payload.questions?.length)
|
|
@@ -169,7 +169,7 @@ async function sendMessages(result, channel, adapter, messageTs, threadTs = null
|
|
|
169
169
|
}
|
|
170
170
|
else {
|
|
171
171
|
const askMsgDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
|
|
172
|
-
const ref = await adapter.postMessage(askMsgDest, { text, richBlocks },
|
|
172
|
+
const ref = await adapter.postMessage(askMsgDest, { text, richBlocks }, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
173
173
|
group.responseMessageTs = ref.messageId;
|
|
174
174
|
}
|
|
175
175
|
for (const q of group.questions) {
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
// input: orch/busy-tracker(trackPendingTask), orch/
|
|
1
|
+
// input: orch/busy-tracker(trackPendingTask), orch/conduit-queue, orch/interactions/plan-approvals, ask-user-question, hook-bridge, adapter
|
|
2
2
|
// output: registerInteractionHandlers(adapter)
|
|
3
3
|
// pos: AskUserQuestion + ExitPlanMode interaction handler registration
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { buildPlanFeedbackModal } from '../../platform/index.js';
|
|
6
6
|
import { trackPendingTask } from '../busy-tracker.js';
|
|
7
|
-
import { enqueue } from '../
|
|
7
|
+
import { enqueue } from '../conduit-queue.js';
|
|
8
8
|
import * as askUserQuestion from './ask-user-question.js';
|
|
9
9
|
import { resolveRequest as resolveHookRequest, getStreamingCallback } from '../routing/hook-bridge.js';
|
|
10
10
|
import { resumeAskUserQuestionGroup } from '../lifecycle.js';
|
|
11
11
|
import { planApprovals } from './plan-approvals.js';
|
|
12
12
|
import { runningExecutions } from '../../core/running-executions.js';
|
|
13
|
-
import
|
|
13
|
+
import * as executionRegistry from '../../domain/executions/registry.js';
|
|
14
|
+
import { conduitQueues } from '../conduit-queue.js';
|
|
14
15
|
import { setSessionAsync, deleteSessionAsync } from '../../domain/sessions/session.js';
|
|
15
16
|
import { sessionStore } from '../../store/session-registry-repo.js';
|
|
16
17
|
import { conversationLedger } from '../../store/conversation-ledger-repo.js';
|
|
17
18
|
import { closeSession, getActiveBackend, getActiveProfile, setActiveProfile, resolveBackendForChannel } from '../../domain/agents/index.js';
|
|
18
19
|
import { fireAndForgetPreCloseHook } from '../../domain/sessions/session-hooks.js';
|
|
20
|
+
import { Icons } from '../../core/icons.js';
|
|
21
|
+
import { t } from '../../core/i18n.js';
|
|
19
22
|
import * as sessionBackup from '../../domain/sessions/session-backup.js';
|
|
20
23
|
import { cancelThread as cancelThreadById } from '../../domain/threads/index.js';
|
|
21
24
|
import { createLogger } from '../../core/log.js';
|
|
@@ -44,9 +47,10 @@ async function handleOpenModal(ctx) {
|
|
|
44
47
|
if (!group || askUserQuestion.isExpired(group)) {
|
|
45
48
|
if (group && askUserQuestion.isExpired(group))
|
|
46
49
|
askUserQuestion.deleteGroup(group.groupId);
|
|
47
|
-
const msg = group ? '
|
|
48
|
-
if (ctx.channelId
|
|
49
|
-
|
|
50
|
+
const msg = group ? t('interaction.askExpired') : t('interaction.askInactive');
|
|
51
|
+
if (ctx.channelId) {
|
|
52
|
+
const expiredDest = { type: 'interactive-reply', conduit: ctx.channelId, sessionId: '' };
|
|
53
|
+
await _adapter.postMessage(expiredDest, { text: msg }).catch(() => { });
|
|
50
54
|
}
|
|
51
55
|
return;
|
|
52
56
|
}
|
|
@@ -120,7 +124,7 @@ function collectModalAnswers(group, values) {
|
|
|
120
124
|
answer = q.options[parseInt(idx)]?.label;
|
|
121
125
|
}
|
|
122
126
|
if (!answer || (Array.isArray(answer) && answer.length === 0)) {
|
|
123
|
-
errors[`q_${qIdx}`] = '
|
|
127
|
+
errors[`q_${qIdx}`] = t('interaction.selectOrType');
|
|
124
128
|
}
|
|
125
129
|
else {
|
|
126
130
|
collected.set(q.pendingId, { header: q.header, value: answer });
|
|
@@ -133,8 +137,8 @@ function collectModalAnswers(group, values) {
|
|
|
133
137
|
async function updateQuestionMessage(group) {
|
|
134
138
|
if (!group.responseMessageTs || !_adapter)
|
|
135
139
|
return;
|
|
136
|
-
await _adapter.updateMessage({
|
|
137
|
-
text:
|
|
140
|
+
await _adapter.updateMessage({ conduit: group.channel, messageId: group.responseMessageTs }, {
|
|
141
|
+
text: t('interaction.questionsProgress', { answered: group.answers.size, total: group.questions.length }),
|
|
138
142
|
richBlocks: askUserQuestion.buildQuestionGroupBlocks(group),
|
|
139
143
|
}).catch(() => { });
|
|
140
144
|
}
|
|
@@ -161,7 +165,7 @@ function dispatchAskUserQuestionResume(group) {
|
|
|
161
165
|
function tryResolvePIPlan(pending, value) {
|
|
162
166
|
if (!pending.extensionUiId)
|
|
163
167
|
return false;
|
|
164
|
-
const exec = runningExecutions.
|
|
168
|
+
const exec = runningExecutions.getByChannel(pending.channel).find(e => e.agentProcess) ?? null;
|
|
165
169
|
if (!exec?.agentProcess)
|
|
166
170
|
return false;
|
|
167
171
|
const proc = exec.agentProcess;
|
|
@@ -187,8 +191,8 @@ function registerExitPlanModeHandlers(adapter) {
|
|
|
187
191
|
}
|
|
188
192
|
if (ctx.messageRef) {
|
|
189
193
|
await adapter.updateMessage(ctx.messageRef, {
|
|
190
|
-
text: '
|
|
191
|
-
richBlocks: [{ type: 'section', text: '
|
|
194
|
+
text: `${Icons.ok} ${t('interaction.planApproved')}`,
|
|
195
|
+
richBlocks: [{ type: 'section', text: `${Icons.ok} ${t('interaction.planApprovedRich')}` }],
|
|
192
196
|
}).catch(() => { });
|
|
193
197
|
}
|
|
194
198
|
});
|
|
@@ -204,12 +208,12 @@ function registerExitPlanModeHandlers(adapter) {
|
|
|
204
208
|
const pending = planApprovals.reject(requestId);
|
|
205
209
|
if (!pending)
|
|
206
210
|
return;
|
|
207
|
-
const feedback = ctx.values?.feedback?.text?.value || '
|
|
211
|
+
const feedback = ctx.values?.feedback?.text?.value || t('interaction.noSpecificFeedback');
|
|
208
212
|
// PI path: send extension_ui_response directly; Claude path: resolve pending HTTP request
|
|
209
213
|
if (!tryResolvePIPlan(pending, feedback)) {
|
|
210
214
|
resolveHookRequest(requestId, { approved: false, reason: feedback });
|
|
211
215
|
}
|
|
212
|
-
const feedbackText =
|
|
216
|
+
const feedbackText = `${Icons.edit} ${t('interaction.planFeedbackSent', { feedback })}`;
|
|
213
217
|
const streamingCb = getStreamingCallback(pending.channel);
|
|
214
218
|
const feedbackDest = { type: 'interactive-reply', conduit: pending.channel, sessionId: '' };
|
|
215
219
|
if (streamingCb) {
|
|
@@ -231,16 +235,39 @@ async function handleStatusCancel(ctx) {
|
|
|
231
235
|
return;
|
|
232
236
|
let channel;
|
|
233
237
|
let threadId;
|
|
238
|
+
let executionId;
|
|
234
239
|
try {
|
|
235
240
|
const parsed = JSON.parse(ctx.value);
|
|
236
241
|
channel = parsed.channel;
|
|
237
242
|
threadId = parsed.threadId ?? null;
|
|
243
|
+
executionId = parsed.executionId ?? null;
|
|
238
244
|
}
|
|
239
245
|
catch {
|
|
240
246
|
return;
|
|
241
247
|
}
|
|
248
|
+
// Conversation path: plain user messages are no longer wrapped in a thread, so the
|
|
249
|
+
// Cancel button carries an executionId. Resolve and kill via the execution index;
|
|
250
|
+
// there is no thread to cancel.
|
|
251
|
+
if (!threadId && executionId) {
|
|
252
|
+
const exec = runningExecutions.getById(executionId);
|
|
253
|
+
if (!exec) {
|
|
254
|
+
log.warn('Cancel button clicked but no running execution for executionId', { channel, executionId });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (exec.sessionId)
|
|
258
|
+
await setSessionAsync(exec.channel ?? channel, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
259
|
+
// teardownExecution(cancelled): record→cancelled, kill the handle, publish a balanced event.
|
|
260
|
+
executionRegistry.teardownExecution({ executionId, status: 'cancelled', durationS: 0 });
|
|
261
|
+
conduitQueues.delete(exec.channel ?? channel);
|
|
262
|
+
if (ctx.messageRef) {
|
|
263
|
+
await _adapter.updateMessage(ctx.messageRef, {
|
|
264
|
+
text: `${Icons.stopped} ${t('interaction.cancelledPreserved')}`,
|
|
265
|
+
}).catch(() => { });
|
|
266
|
+
}
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
242
269
|
if (!threadId) {
|
|
243
|
-
log.warn('Cancel button clicked but threadId missing in value', { channel });
|
|
270
|
+
log.warn('Cancel button clicked but threadId/executionId missing in value', { channel });
|
|
244
271
|
return;
|
|
245
272
|
}
|
|
246
273
|
const exec = runningExecutions.getByThreadId(threadId);
|
|
@@ -251,11 +278,16 @@ async function handleStatusCancel(ctx) {
|
|
|
251
278
|
await cancelThreadById(threadId).catch(() => { });
|
|
252
279
|
if (exec.sessionId)
|
|
253
280
|
await setSessionAsync(exec.channel ?? channel, exec.sessionId, getActiveBackend()).catch(() => { });
|
|
254
|
-
|
|
255
|
-
|
|
281
|
+
if (exec.executionId) {
|
|
282
|
+
executionRegistry.teardownExecution({ executionId: exec.executionId, status: 'cancelled', durationS: 0 });
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
runningExecutions.killByThreadId(threadId);
|
|
286
|
+
}
|
|
287
|
+
conduitQueues.delete(exec.channel ?? channel);
|
|
256
288
|
if (ctx.messageRef) {
|
|
257
289
|
await _adapter.updateMessage(ctx.messageRef, {
|
|
258
|
-
text:
|
|
290
|
+
text: `${Icons.stopped} Cancelled. Session preserved — next message will resume.`,
|
|
259
291
|
}).catch(() => { });
|
|
260
292
|
}
|
|
261
293
|
}
|
|
@@ -272,10 +304,10 @@ async function handleStatusResume(ctx) {
|
|
|
272
304
|
await conversationLedger.switchSession(ctx.channelId, {
|
|
273
305
|
sessionId: record.sessionId, sessionName, backend: record.backend, profileName: record.profileName,
|
|
274
306
|
});
|
|
275
|
-
const profileNote = record.profileName ?
|
|
307
|
+
const profileNote = record.profileName ? t('interaction.sessionProfileNote', { profileName: record.profileName }) : '';
|
|
276
308
|
const resumeDest = { type: 'interactive-reply', conduit: ctx.channelId, sessionId: record.sessionId ?? '' };
|
|
277
309
|
await _adapter.postMessage(resumeDest, {
|
|
278
|
-
text:
|
|
310
|
+
text: `${Icons.refresh} ${t('interaction.sessionActive', { sessionName, profileNote })}`,
|
|
279
311
|
}).catch(() => { });
|
|
280
312
|
}
|
|
281
313
|
async function handleStatusNew(ctx) {
|
|
@@ -284,9 +316,9 @@ async function handleStatusNew(ctx) {
|
|
|
284
316
|
const channel = ctx.value;
|
|
285
317
|
// Status message IS the thread parent (no thread_ts on it) — use its messageId
|
|
286
318
|
// as the thread context so hook messages land in the session's thread.
|
|
287
|
-
const
|
|
319
|
+
const threadAnchorId = ctx.messageRef?.threadId || ctx.messageRef?.messageId;
|
|
288
320
|
// Fire-and-forget: hook starts, session closes immediately without waiting
|
|
289
|
-
void fireAndForgetPreCloseHook(channel, _adapter,
|
|
321
|
+
void fireAndForgetPreCloseHook(channel, _adapter, threadAnchorId);
|
|
290
322
|
closeSession(channel);
|
|
291
323
|
const conv = await conversationLedger.getConversation(channel);
|
|
292
324
|
const profileName = getActiveProfile(channel) || 'default';
|
|
@@ -298,6 +330,6 @@ async function handleStatusNew(ctx) {
|
|
|
298
330
|
planApprovals.clearByChannel(channel);
|
|
299
331
|
const newDest = { type: 'interactive-reply', conduit: ctx.channelId, sessionId: '' };
|
|
300
332
|
await _adapter.postMessage(newDest, {
|
|
301
|
-
text:
|
|
333
|
+
text: t('interaction.newConversation', { profileName }),
|
|
302
334
|
}).catch(() => { });
|
|
303
335
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PlatformAdapter } from '../../platform/index.js';
|
|
2
|
-
declare function sendPlanToSlack(planContent: string | null, channel: string, adapter: PlatformAdapter, { machine,
|
|
2
|
+
declare function sendPlanToSlack(planContent: string | null, channel: string, adapter: PlatformAdapter, { machine, threadAnchorId }?: {
|
|
3
3
|
machine?: string;
|
|
4
|
-
|
|
4
|
+
threadAnchorId?: string | null;
|
|
5
5
|
}): Promise<void>;
|
|
6
6
|
export { sendPlanToSlack };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { postOnce } from '../../platform/index.js';
|
|
2
|
-
|
|
2
|
+
import { Icons } from '../../core/icons.js';
|
|
3
|
+
async function sendPlanToSlack(planContent, channel, adapter, { machine, threadAnchorId } = {}) {
|
|
3
4
|
if (!planContent) {
|
|
4
5
|
const label = machine ? `**[PLAN: ${machine}]**` : '**[PLAN]**';
|
|
5
|
-
await postOnce(adapter, { type: 'interactive-reply', conduit: channel, sessionId: '' },
|
|
6
|
+
await postOnce(adapter, { type: 'interactive-reply', conduit: channel, sessionId: '' }, `${Icons.memo} ${label} Plan generated but no content found.`, { threadId: threadAnchorId });
|
|
6
7
|
return;
|
|
7
8
|
}
|
|
8
9
|
const label = '**[PLAN]**';
|
|
9
10
|
const prompt = 'Generated plan — use the buttons below to approve or provide feedback:';
|
|
10
|
-
await postOnce(adapter, { type: 'interactive-reply', conduit: channel, sessionId: '' },
|
|
11
|
+
await postOnce(adapter, { type: 'interactive-reply', conduit: channel, sessionId: '' }, `${Icons.memo} ${label} ${prompt}\n${planContent}`, { threadId: threadAnchorId });
|
|
11
12
|
}
|
|
12
13
|
export { sendPlanToSlack };
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// pos: Slack-specific UpdatePrompt implementation — pre-registers three actionIds on router,
|
|
4
4
|
// posts interactive message to system-notice, resolves ask() promise on button click.
|
|
5
5
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import { t } from '../../core/i18n.js';
|
|
6
7
|
const DEFAULT_TIMEOUT_MS = 86_400_000; // 24h
|
|
7
8
|
// --- Factory ---
|
|
8
9
|
export function createSlackUpdatePrompt(adapter, router, opts) {
|
|
@@ -20,11 +21,11 @@ export function createSlackUpdatePrompt(adapter, router, opts) {
|
|
|
20
21
|
const resolveText = (choice, version) => {
|
|
21
22
|
switch (choice) {
|
|
22
23
|
case 'apply':
|
|
23
|
-
return
|
|
24
|
+
return t('update.installing', { version });
|
|
24
25
|
case 'skip':
|
|
25
|
-
return
|
|
26
|
+
return t('update.skipped', { version });
|
|
26
27
|
case 'cancel':
|
|
27
|
-
return
|
|
28
|
+
return t('update.cancelled');
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
// --- Build click handlers ---
|
|
@@ -51,9 +52,9 @@ export function createSlackUpdatePrompt(adapter, router, opts) {
|
|
|
51
52
|
});
|
|
52
53
|
// --- Button templates (value filled in at ask time) ---
|
|
53
54
|
const buttonTemplates = [
|
|
54
|
-
{ type: 'button', text: '
|
|
55
|
-
{ type: 'button', text: '
|
|
56
|
-
{ type: 'button', text: '
|
|
55
|
+
{ type: 'button', text: t('update.button.update'), actionId: 'cmd:update:apply', value: '', style: 'primary' },
|
|
56
|
+
{ type: 'button', text: t('update.button.skip'), actionId: 'cmd:update:skip', value: '' },
|
|
57
|
+
{ type: 'button', text: t('update.button.cancel'), actionId: 'cmd:update:cancel', value: '', style: 'danger' },
|
|
57
58
|
];
|
|
58
59
|
// --- Return the UpdatePrompt implementation ---
|
|
59
60
|
return {
|
|
@@ -64,7 +65,7 @@ export function createSlackUpdatePrompt(adapter, router, opts) {
|
|
|
64
65
|
clearPending();
|
|
65
66
|
old.resolve(null);
|
|
66
67
|
if (old.messageRef) {
|
|
67
|
-
await adapter.updateMessage(old.messageRef, { text: '
|
|
68
|
+
await adapter.updateMessage(old.messageRef, { text: t('update.superseded') }).catch(() => { });
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
// Stamp version onto buttons
|
|
@@ -77,9 +78,9 @@ export function createSlackUpdatePrompt(adapter, router, opts) {
|
|
|
77
78
|
// button row. Pattern follows buildPlanApprovalContent
|
|
78
79
|
// (platform/interactive-builder.ts:117-127).
|
|
79
80
|
const messageRef = await adapter.postInteractive({ type: 'system-notice' }, {
|
|
80
|
-
text:
|
|
81
|
+
text: t('update.available', { version: spec.latestVersion }),
|
|
81
82
|
richBlocks: [
|
|
82
|
-
{ type: 'section', text:
|
|
83
|
+
{ type: 'section', text: t('update.availableSection', { version: spec.latestVersion }) },
|
|
83
84
|
],
|
|
84
85
|
actions: versionedButtons,
|
|
85
86
|
});
|
|
@@ -92,7 +93,7 @@ export function createSlackUpdatePrompt(adapter, router, opts) {
|
|
|
92
93
|
const ref = pending.messageRef;
|
|
93
94
|
clearPending();
|
|
94
95
|
resolve(null);
|
|
95
|
-
adapter.updateMessage(ref, { text: '
|
|
96
|
+
adapter.updateMessage(ref, { text: t('update.timedOut') }).catch(() => { });
|
|
96
97
|
}, timeoutMs).unref();
|
|
97
98
|
});
|
|
98
99
|
},
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../platform/index.js';
|
|
2
|
+
import type { CommandActionRouter } from '../interactions/command-action-router.js';
|
|
3
|
+
import type { UpdatePrompt } from '../../domain/system/update-prompt.js';
|
|
4
|
+
export declare function createUpdatePrompt(adapter: PlatformAdapter, router: CommandActionRouter, opts?: {
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
}): UpdatePrompt;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// input: @platform/index.js + @orch/interactions/command-action-router.js + @domain/system/update-prompt.js
|
|
2
|
+
// output: createUpdatePrompt(adapter, router, opts?) => UpdatePrompt
|
|
3
|
+
// pos: Platform-neutral UpdatePrompt implementation — pre-registers three actionIds on router,
|
|
4
|
+
// posts interactive message to system-notice, resolves ask() promise on button click.
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import { fetchReleaseNote, buildGitHubReleaseUrl } from '../../domain/system/github-release.js';
|
|
7
|
+
import { createLogger } from '../../core/log.js';
|
|
8
|
+
import { t } from '../../core/i18n.js';
|
|
9
|
+
const log = createLogger('update-prompt');
|
|
10
|
+
const DEFAULT_TIMEOUT_MS = 86_400_000; // 24h
|
|
11
|
+
// --- Factory ---
|
|
12
|
+
export function createUpdatePrompt(adapter, router, opts) {
|
|
13
|
+
const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
14
|
+
let pending = null;
|
|
15
|
+
let timerHandle;
|
|
16
|
+
// --- Internal helpers ---
|
|
17
|
+
const clearPending = () => {
|
|
18
|
+
if (timerHandle !== undefined) {
|
|
19
|
+
clearTimeout(timerHandle);
|
|
20
|
+
timerHandle = undefined;
|
|
21
|
+
}
|
|
22
|
+
pending = null;
|
|
23
|
+
};
|
|
24
|
+
const resolveText = (choice, version) => {
|
|
25
|
+
switch (choice) {
|
|
26
|
+
case 'apply':
|
|
27
|
+
return t('update.installing', { version });
|
|
28
|
+
case 'skip':
|
|
29
|
+
return t('update.skipped', { version });
|
|
30
|
+
case 'cancel':
|
|
31
|
+
return t('update.cancelled');
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Format release note info into a message.
|
|
36
|
+
* Truncates if too long (safe for Slack/Feishu 4000 char limit).
|
|
37
|
+
*/
|
|
38
|
+
const formatReleaseNoteMessage = (releaseInfo) => {
|
|
39
|
+
let body = releaseInfo.body || t('update.releaseNotesEmpty');
|
|
40
|
+
// Truncate to safe length (~3500 chars to leave room for header/footer)
|
|
41
|
+
if (body.length > 3500) {
|
|
42
|
+
body = body.substring(0, 3500).trimEnd() + t('update.releaseNotesTruncated');
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
text: t('update.releaseNotesTitle', { version: releaseInfo.version }),
|
|
46
|
+
richBlocks: [
|
|
47
|
+
{
|
|
48
|
+
type: 'section',
|
|
49
|
+
text: t('update.releaseNotesBody', { name: releaseInfo.name, body, url: releaseInfo.htmlUrl }),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
// --- Build click handlers ---
|
|
55
|
+
const buildHandler = (choice) => {
|
|
56
|
+
return async (ctx) => {
|
|
57
|
+
if (!pending)
|
|
58
|
+
return; // stale click — no pending prompt
|
|
59
|
+
const p = pending;
|
|
60
|
+
const version = p.latestVersion;
|
|
61
|
+
clearPending();
|
|
62
|
+
p.resolve(choice);
|
|
63
|
+
if (ctx.messageRef) {
|
|
64
|
+
await adapter.updateMessage(ctx.messageRef, { text: resolveText(choice, version) }).catch(() => { });
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const handleReleaseNote = async (ctx) => {
|
|
69
|
+
if (!pending)
|
|
70
|
+
return;
|
|
71
|
+
const version = pending.latestVersion;
|
|
72
|
+
log.debug(`Fetching release notes for version ${version}`);
|
|
73
|
+
try {
|
|
74
|
+
const releaseInfo = await fetchReleaseNote(version);
|
|
75
|
+
if (releaseInfo) {
|
|
76
|
+
const message = formatReleaseNoteMessage(releaseInfo);
|
|
77
|
+
await adapter.postMessage({ type: 'system-notice' }, message).catch((e) => {
|
|
78
|
+
log.error(`Failed to post release note message: ${e.message}`);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Fallback: send GitHub link
|
|
83
|
+
const url = buildGitHubReleaseUrl(version);
|
|
84
|
+
await adapter
|
|
85
|
+
.postMessage({ type: 'system-notice' }, {
|
|
86
|
+
text: t('update.releaseNotesFetchFailed', { version, url }),
|
|
87
|
+
})
|
|
88
|
+
.catch((e) => {
|
|
89
|
+
log.error(`Failed to post fallback release note: ${e.message}`);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
log.error(`Error in release note handler: ${error.message}`);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
// --- Pre-register four actionIds on router ---
|
|
98
|
+
router.registerCommand('update', {
|
|
99
|
+
actions: [
|
|
100
|
+
{ actionId: 'apply', handler: buildHandler('apply') },
|
|
101
|
+
{ actionId: 'skip', handler: buildHandler('skip') },
|
|
102
|
+
{ actionId: 'cancel', handler: buildHandler('cancel') },
|
|
103
|
+
{ actionId: 'release-note', handler: handleReleaseNote },
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
// --- Button templates (value filled in at ask time) ---
|
|
107
|
+
const buttonTemplates = [
|
|
108
|
+
{ type: 'button', text: t('update.button.update'), actionId: 'cmd:update:apply', value: '', style: 'primary' },
|
|
109
|
+
{ type: 'button', text: t('update.button.releaseNote'), actionId: 'cmd:update:release-note', value: '' },
|
|
110
|
+
{ type: 'button', text: t('update.button.skip'), actionId: 'cmd:update:skip', value: '' },
|
|
111
|
+
{ type: 'button', text: t('update.button.cancel'), actionId: 'cmd:update:cancel', value: '', style: 'danger' },
|
|
112
|
+
];
|
|
113
|
+
// --- Return the UpdatePrompt implementation ---
|
|
114
|
+
return {
|
|
115
|
+
async ask(spec) {
|
|
116
|
+
// Resolve any existing pending prompt
|
|
117
|
+
if (pending) {
|
|
118
|
+
const old = pending;
|
|
119
|
+
clearPending();
|
|
120
|
+
old.resolve(null);
|
|
121
|
+
if (old.messageRef) {
|
|
122
|
+
await adapter.updateMessage(old.messageRef, { text: t('update.superseded') }).catch(() => { });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Stamp version onto buttons
|
|
126
|
+
const versionedButtons = buttonTemplates.map(b => ({ ...b, value: spec.latestVersion }));
|
|
127
|
+
// Post interactive message to admin DM.
|
|
128
|
+
// Convention: richBlocks contains content-only sections; buttons go in the
|
|
129
|
+
// top-level `actions` field. The Slack adapter's postInteractive
|
|
130
|
+
// (adapters/slack.ts:434-440) appends an actions block from content.actions,
|
|
131
|
+
// so embedding another actions block inside richBlocks would duplicate the
|
|
132
|
+
// button row. Pattern follows buildPlanApprovalContent
|
|
133
|
+
// (platform/interactive-builder.ts:117-127).
|
|
134
|
+
const messageRef = await adapter.postInteractive({ type: 'system-notice' }, {
|
|
135
|
+
text: t('update.available', { version: spec.latestVersion }),
|
|
136
|
+
richBlocks: [
|
|
137
|
+
{ type: 'section', text: t('update.availableSection', { version: spec.latestVersion }) },
|
|
138
|
+
],
|
|
139
|
+
actions: versionedButtons,
|
|
140
|
+
});
|
|
141
|
+
// Create new pending promise
|
|
142
|
+
return new Promise((resolve) => {
|
|
143
|
+
pending = { resolve, messageRef, latestVersion: spec.latestVersion };
|
|
144
|
+
timerHandle = setTimeout(() => {
|
|
145
|
+
if (!pending || pending.resolve !== resolve)
|
|
146
|
+
return; // already handled
|
|
147
|
+
const ref = pending.messageRef;
|
|
148
|
+
clearPending();
|
|
149
|
+
resolve(null);
|
|
150
|
+
adapter.updateMessage(ref, { text: t('update.timedOut') }).catch(() => { });
|
|
151
|
+
}, timeoutMs).unref();
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PlatformAdapter, MessageRef } from '../platform/index.js';
|
|
2
2
|
import type { AgentResult } from '../core/types/agent-types.js';
|
|
3
|
-
export declare function handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger, sessionName,
|
|
3
|
+
export declare function handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger, sessionName, threadAnchorId, userMessageTs, onAssistantMessage }: {
|
|
4
4
|
result: AgentResult;
|
|
5
5
|
channel: string;
|
|
6
6
|
adapter: PlatformAdapter;
|
|
@@ -10,11 +10,11 @@ export declare function handleAgentSuccess({ result, channel, adapter, statusMsg
|
|
|
10
10
|
executionId: string | null;
|
|
11
11
|
trigger?: string;
|
|
12
12
|
sessionName?: string | null;
|
|
13
|
-
|
|
13
|
+
threadAnchorId?: string | null;
|
|
14
14
|
userMessageTs?: string | null;
|
|
15
15
|
onAssistantMessage?: ((text: string) => void) | null;
|
|
16
16
|
}): Promise<void>;
|
|
17
|
-
export declare function handleAgentError({ error, channel, adapter, statusMsg, startTime, executionId, sessionName, sessionId, effectiveSessionId,
|
|
17
|
+
export declare function handleAgentError({ error, channel, adapter, statusMsg, startTime, executionId, sessionName, sessionId, effectiveSessionId, threadAnchorId, userMessageTs }: {
|
|
18
18
|
error: {
|
|
19
19
|
message: string;
|
|
20
20
|
cancelled?: boolean;
|
|
@@ -27,7 +27,7 @@ export declare function handleAgentError({ error, channel, adapter, statusMsg, s
|
|
|
27
27
|
sessionName?: string | null;
|
|
28
28
|
sessionId?: string | null;
|
|
29
29
|
effectiveSessionId?: string | null;
|
|
30
|
-
|
|
30
|
+
threadAnchorId?: string | null;
|
|
31
31
|
userMessageTs?: string | null;
|
|
32
32
|
}): Promise<void>;
|
|
33
33
|
export declare function resumeAskUserQuestionGroup({ adapter, group, responseText }: {
|