@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
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// output: handleScheduleCommand dispatcher
|
|
3
3
|
// pos: !schedule subcommand routing and profile pinning
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { Icons } from '../../core/icons.js';
|
|
6
|
+
import { t } from '../../core/i18n.js';
|
|
5
7
|
import { formatDuration, formatTimeUntil, parseDuration } from './scheduler.js';
|
|
6
8
|
import { channelToProjectId } from '../../store/schedule-repo.js';
|
|
7
9
|
import { listProfiles, resolveProfile, getDefaultProfileName } from '../agents/profile-manager.js';
|
|
@@ -12,16 +14,16 @@ function toDest(channel) {
|
|
|
12
14
|
function scheduleHelp() {
|
|
13
15
|
const profileNames = listProfiles().map(p => `\`${p.name}\``).join(', ');
|
|
14
16
|
return [
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
|
|
17
|
+
t('schedule.help.title'),
|
|
18
|
+
t('schedule.help.addInterval'),
|
|
19
|
+
t('schedule.help.addDaily'),
|
|
20
|
+
t('schedule.help.addWeekly'),
|
|
21
|
+
t('schedule.help.addOnce'),
|
|
22
|
+
t('schedule.help.list'),
|
|
23
|
+
t('schedule.help.pause'),
|
|
24
|
+
t('schedule.help.resume'),
|
|
25
|
+
t('schedule.help.remove'),
|
|
26
|
+
t('schedule.help.availableProfiles', { profileNames }),
|
|
25
27
|
].join('\n');
|
|
26
28
|
}
|
|
27
29
|
const DAY_MAP = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 };
|
|
@@ -30,12 +32,12 @@ const fmtTime = (ts) => new Date(ts).toLocaleString('en-US', FMT_OPTS);
|
|
|
30
32
|
async function handleList(parts, channel, adapter, scheduler) {
|
|
31
33
|
const tasks = await scheduler.list();
|
|
32
34
|
if (tasks.length === 0) {
|
|
33
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
35
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.list.empty') });
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
38
|
const now = Date.now();
|
|
37
|
-
const lines = tasks.map((
|
|
38
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
39
|
+
const lines = tasks.map((task) => formatTaskLine(task, now));
|
|
40
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.list.header', { count: tasks.length, lines: lines.join('\n') }) });
|
|
39
41
|
}
|
|
40
42
|
function formatTaskLine(t, now) {
|
|
41
43
|
const id = `\`${t.id}\``;
|
|
@@ -74,51 +76,51 @@ async function handleRemove(parts, channel, adapter, scheduler) {
|
|
|
74
76
|
const rawId = parts[2];
|
|
75
77
|
const id = normalizeTaskId(rawId);
|
|
76
78
|
if (!id) {
|
|
77
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
79
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.remove.usage') });
|
|
78
80
|
return;
|
|
79
81
|
}
|
|
80
82
|
const removed = await scheduler.remove(id);
|
|
81
83
|
await adapter.postMessage(toDest(channel), {
|
|
82
|
-
text: removed ?
|
|
84
|
+
text: removed ? `${Icons.ok} ${t('schedule.remove.ok', { id })}` : `${Icons.error} ${t('schedule.taskNotFound', { id })}`,
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
87
|
async function handlePause(parts, channel, adapter, scheduler) {
|
|
86
88
|
const rawId = parts[2];
|
|
87
89
|
const id = normalizeTaskId(rawId);
|
|
88
90
|
if (!id) {
|
|
89
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
91
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.pause.usage') });
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
try {
|
|
93
95
|
const task = await scheduler.pause(id);
|
|
94
96
|
if (!task) {
|
|
95
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
97
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${t('schedule.taskNotFound', { id })}` });
|
|
96
98
|
return;
|
|
97
99
|
}
|
|
98
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
100
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.paused} ${t('schedule.pause.ok', { id })}` });
|
|
99
101
|
}
|
|
100
102
|
catch (error) {
|
|
101
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
103
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
async function handleResume(parts, channel, adapter, scheduler) {
|
|
105
107
|
const rawId = parts[2];
|
|
106
108
|
const id = normalizeTaskId(rawId);
|
|
107
109
|
if (!id) {
|
|
108
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
110
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.resume.usage') });
|
|
109
111
|
return;
|
|
110
112
|
}
|
|
111
113
|
try {
|
|
112
114
|
const task = await scheduler.resume(id);
|
|
113
115
|
if (!task) {
|
|
114
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
116
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${t('schedule.taskNotFound', { id })}` });
|
|
115
117
|
return;
|
|
116
118
|
}
|
|
117
|
-
const nextAt = task.nextRun ?
|
|
118
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
119
|
+
const nextAt = task.nextRun ? t('schedule.resume.nextRun', { time: fmtTime(task.nextRun) }) : '';
|
|
120
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.resume} ${t('schedule.resume.ok', { id, nextAt })}` });
|
|
119
121
|
}
|
|
120
122
|
catch (error) {
|
|
121
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
123
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
function parseProfileArgs(args, usage) {
|
|
@@ -130,7 +132,7 @@ function parseProfileArgs(args, usage) {
|
|
|
130
132
|
}
|
|
131
133
|
const profileName = args[1];
|
|
132
134
|
if (!profileName)
|
|
133
|
-
throw new Error(
|
|
135
|
+
throw new Error(t('schedule.profileUsage', { usage }));
|
|
134
136
|
try {
|
|
135
137
|
resolveProfile(profileName);
|
|
136
138
|
}
|
|
@@ -150,23 +152,23 @@ async function handleAddInterval(parts, channel, adapter, scheduler) {
|
|
|
150
152
|
parsed = parseProfileArgs(parts.slice(4), '`!schedule add interval <duration> [--profile <name>] <message>`');
|
|
151
153
|
}
|
|
152
154
|
catch (error) {
|
|
153
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
155
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
154
156
|
return;
|
|
155
157
|
}
|
|
156
158
|
const msg = parsed.rest.join(' ');
|
|
157
159
|
const ms = parseDuration(durationStr);
|
|
158
160
|
if (!ms) {
|
|
159
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
161
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidDuration', { duration: durationStr }) });
|
|
160
162
|
return;
|
|
161
163
|
}
|
|
162
164
|
if (!msg) {
|
|
163
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
165
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.intervalUsage') });
|
|
164
166
|
return;
|
|
165
167
|
}
|
|
166
168
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
167
169
|
const task = await scheduler.add('interval', { intervalMs: ms, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
168
170
|
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
169
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(
|
|
171
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledInterval', { duration: formatDuration(ms), message: msg })}`, task, nextAt) });
|
|
170
172
|
}
|
|
171
173
|
async function handleAddDaily(parts, channel, adapter, scheduler) {
|
|
172
174
|
const time = parts[3];
|
|
@@ -175,22 +177,22 @@ async function handleAddDaily(parts, channel, adapter, scheduler) {
|
|
|
175
177
|
parsed = parseProfileArgs(parts.slice(4), '`!schedule add daily <HH:MM> [--profile <name>] <message>`');
|
|
176
178
|
}
|
|
177
179
|
catch (error) {
|
|
178
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
180
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
179
181
|
return;
|
|
180
182
|
}
|
|
181
183
|
const msg = parsed.rest.join(' ');
|
|
182
184
|
if (!/^\d{2}:\d{2}$/.test(time)) {
|
|
183
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
185
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidTime', { time, example: '09:00' }) });
|
|
184
186
|
return;
|
|
185
187
|
}
|
|
186
188
|
if (!msg) {
|
|
187
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
189
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.dailyUsage') });
|
|
188
190
|
return;
|
|
189
191
|
}
|
|
190
192
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
191
193
|
const task = await scheduler.add('daily', { time, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
192
194
|
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
193
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(
|
|
195
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledDaily', { time, message: msg })}`, task, nextAt) });
|
|
194
196
|
}
|
|
195
197
|
async function handleAddWeekly(parts, channel, adapter, scheduler) {
|
|
196
198
|
const dayStr = (parts[3] || '').toLowerCase();
|
|
@@ -200,28 +202,28 @@ async function handleAddWeekly(parts, channel, adapter, scheduler) {
|
|
|
200
202
|
parsed = parseProfileArgs(parts.slice(5), '`!schedule add weekly <day> <HH:MM> [--profile <name>] <message>`');
|
|
201
203
|
}
|
|
202
204
|
catch (error) {
|
|
203
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
205
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
204
206
|
return;
|
|
205
207
|
}
|
|
206
208
|
const msg = parsed.rest.join(' ');
|
|
207
209
|
const dayOfWeek = DAY_MAP[dayStr];
|
|
208
210
|
if (dayOfWeek == null) {
|
|
209
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
211
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidDay', { day: parts[3] }) });
|
|
210
212
|
return;
|
|
211
213
|
}
|
|
212
214
|
if (!/^\d{2}:\d{2}$/.test(time)) {
|
|
213
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
215
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidTime', { time, example: '21:00' }) });
|
|
214
216
|
return;
|
|
215
217
|
}
|
|
216
218
|
if (!msg) {
|
|
217
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
219
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.weeklyUsage') });
|
|
218
220
|
return;
|
|
219
221
|
}
|
|
220
222
|
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
221
223
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
222
224
|
const task = await scheduler.add('weekly', { dayOfWeek, time, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
223
225
|
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
224
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(
|
|
226
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledWeekly', { day: dayNames[dayOfWeek], time, message: msg })}`, task, nextAt) });
|
|
225
227
|
}
|
|
226
228
|
async function handleAddOnce(parts, channel, adapter, scheduler) {
|
|
227
229
|
const durationStr = parts[3];
|
|
@@ -230,23 +232,23 @@ async function handleAddOnce(parts, channel, adapter, scheduler) {
|
|
|
230
232
|
parsed = parseProfileArgs(parts.slice(4), '`!schedule add once <duration> [--profile <name>] <message>`');
|
|
231
233
|
}
|
|
232
234
|
catch (error) {
|
|
233
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
235
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
234
236
|
return;
|
|
235
237
|
}
|
|
236
238
|
const msg = parsed.rest.join(' ');
|
|
237
239
|
const ms = parseDuration(durationStr);
|
|
238
240
|
if (!ms) {
|
|
239
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
241
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidDuration', { duration: durationStr }) });
|
|
240
242
|
return;
|
|
241
243
|
}
|
|
242
244
|
if (!msg) {
|
|
243
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
245
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.onceUsage') });
|
|
244
246
|
return;
|
|
245
247
|
}
|
|
246
248
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
247
249
|
const task = await scheduler.add('once', { delay: ms, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
248
250
|
const runAt = task.runAt ? ` | runs at: ${fmtTime(task.runAt)}` : '';
|
|
249
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(
|
|
251
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledOnce', { duration: formatDuration(ms), message: msg })}`, task, runAt) });
|
|
250
252
|
}
|
|
251
253
|
const ADD_TYPE_HANDLERS = {
|
|
252
254
|
interval: handleAddInterval,
|
|
@@ -260,7 +262,7 @@ async function handleAdd(parts, channel, adapter, scheduler) {
|
|
|
260
262
|
if (handler)
|
|
261
263
|
return handler(parts, channel, adapter, scheduler);
|
|
262
264
|
if (type) {
|
|
263
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
265
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.unknownType', { type }) });
|
|
264
266
|
return;
|
|
265
267
|
}
|
|
266
268
|
await adapter.postMessage(toDest(channel), { text: scheduleHelp() });
|
|
@@ -11,7 +11,7 @@ interface RunnerParams {
|
|
|
11
11
|
profileName: string;
|
|
12
12
|
/** Where the fired task should land — passed through so scheduled-task.ts can pick its dispatch branch. */
|
|
13
13
|
target?: ScheduleTask['target'];
|
|
14
|
-
/** What to do if the chosen target
|
|
14
|
+
/** What to do if the chosen target thread no longer exists at fire time. */
|
|
15
15
|
fallback?: ScheduleTask['fallback'];
|
|
16
16
|
}
|
|
17
17
|
interface TaskDispatchParams {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { watch } from 'fs';
|
|
6
6
|
import { execSync } from 'child_process';
|
|
7
7
|
import { randomBytes } from 'crypto';
|
|
8
|
+
import { Icons } from '../../core/icons.js';
|
|
8
9
|
import { DATA_DIR } from '../../core/utils.js';
|
|
9
10
|
import { createLogger } from '../../core/log.js';
|
|
10
11
|
import { getDefaultProfileName } from '../agents/profile-manager.js';
|
|
@@ -307,7 +308,7 @@ class Scheduler {
|
|
|
307
308
|
}
|
|
308
309
|
if (added || removed || updated) {
|
|
309
310
|
log.info(`Hot-reload: +${added} -${removed} ~${updated} task(s), total ${this.timers.size}`);
|
|
310
|
-
this._adminNotifier?.(
|
|
311
|
+
this._adminNotifier?.(`${Icons.refresh} \`schedules.json\` hot-reloaded: +${added} -${removed} ~${updated} task(s), ${this.timers.size} total`);
|
|
311
312
|
}
|
|
312
313
|
}
|
|
313
314
|
// Add a new scheduled task and return it
|
|
@@ -81,11 +81,11 @@ export declare function resolveOnNewProfileName(channel: string, sessionId: stri
|
|
|
81
81
|
* Returns immediately; the hook subprocess and any injected agent turn run async
|
|
82
82
|
* via the unified pipeline. The session is closed by the caller in parallel —
|
|
83
83
|
* sessionId is captured up-front so the JSONL still resolves after deletion. */
|
|
84
|
-
export declare function fireAndForgetPreCloseHook(channel: string, adapter: PlatformAdapter,
|
|
84
|
+
export declare function fireAndForgetPreCloseHook(channel: string, adapter: PlatformAdapter, threadAnchorId?: string | null): Promise<void>;
|
|
85
85
|
/** Synchronous variant of fireAndForgetPreCloseHook — awaits the hook to completion.
|
|
86
86
|
* Reserved for cases where the caller wants to block on the !new pipeline (e.g.
|
|
87
87
|
* test harness, scripted teardown). */
|
|
88
|
-
export declare function runPreCloseHook(channel: string, adapter: PlatformAdapter,
|
|
88
|
+
export declare function runPreCloseHook(channel: string, adapter: PlatformAdapter, threadAnchorId?: string | null): Promise<void>;
|
|
89
89
|
export interface OnMessageEndArgs {
|
|
90
90
|
channel: string;
|
|
91
91
|
sessionId: string;
|
|
@@ -8,6 +8,7 @@ import { readFileSync } from 'fs';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import { DATA_DIR, CONFIG_DIR } from '../../core/paths.js';
|
|
10
10
|
import { createLogger } from '../../core/log.js';
|
|
11
|
+
import { Icons } from '../../core/icons.js';
|
|
11
12
|
import { runAgent, resolveBackendForChannel } from '../agents/index.js';
|
|
12
13
|
import { getSessionAsync } from '../sessions/session.js';
|
|
13
14
|
import { sessionStore } from '../../store/session-registry-repo.js';
|
|
@@ -174,7 +175,7 @@ export async function runSessionHook(spec, stream) {
|
|
|
174
175
|
catch (err) {
|
|
175
176
|
const msg = err?.message || String(err);
|
|
176
177
|
log.error(`hook ${spec.name} injected agent failed: ${msg}`);
|
|
177
|
-
stream.emitText(
|
|
178
|
+
stream.emitText(`${Icons.warning} ${spec.name} hook follow-up failed: ${msg}`);
|
|
178
179
|
}
|
|
179
180
|
finally {
|
|
180
181
|
await stream.flush().catch((e) => log.warn(`stream.flush after inject failed (${label}): ${e?.message || e}`));
|
|
@@ -182,31 +183,31 @@ export async function runSessionHook(spec, stream) {
|
|
|
182
183
|
}
|
|
183
184
|
// ── onNew (pre-close) entry points ────────────────────────────────────────────
|
|
184
185
|
const ONNEW_FORMAT = {
|
|
185
|
-
statusLine: () =>
|
|
186
|
+
statusLine: () => `${Icons.hook} Running \`!new\` hook…`,
|
|
186
187
|
previewLine: (out) => {
|
|
187
188
|
const preview = out.length > 80 ? out.slice(0, 80) + '…' : out;
|
|
188
|
-
return
|
|
189
|
+
return `${Icons.hook} ${preview}`;
|
|
189
190
|
},
|
|
190
|
-
errorLine: (err) =>
|
|
191
|
-
emptyLine: () =>
|
|
191
|
+
errorLine: (err) => `${Icons.warning} \`!new\` hook failed: ${err}`,
|
|
192
|
+
emptyLine: () => `${Icons.hook} hook returned empty output — nothing to inject.`,
|
|
192
193
|
};
|
|
193
194
|
const ONMESSAGEEND_FORMAT = {
|
|
194
|
-
statusLine: () =>
|
|
195
|
+
statusLine: () => `${Icons.hook} Checking for unreleased locks…`,
|
|
195
196
|
previewLine: (out) => {
|
|
196
197
|
const preview = out.length > 80 ? out.slice(0, 80) + '…' : out;
|
|
197
|
-
return
|
|
198
|
+
return `${Icons.hook} ${preview}`;
|
|
198
199
|
},
|
|
199
|
-
errorLine: (err) =>
|
|
200
|
+
errorLine: (err) => `${Icons.warning} Lock check failed: ${err}`,
|
|
200
201
|
// onMessageEnd is silent on empty output — the common case is "nothing to remind".
|
|
201
202
|
emptyLine: () => null,
|
|
202
203
|
};
|
|
203
204
|
/** Resolve the Slack thread anchor for a fresh onNew vm:
|
|
204
|
-
* 1. Caller-supplied
|
|
205
|
+
* 1. Caller-supplied threadAnchorId (e.g. user typed !new in-thread).
|
|
205
206
|
* 2. Last turn's statusMessageTs from the conversation ledger.
|
|
206
207
|
* 3. null → vm starts a top-level message and self-anchors. */
|
|
207
|
-
async function resolveOnNewThreadAnchor(channel,
|
|
208
|
-
if (
|
|
209
|
-
return
|
|
208
|
+
async function resolveOnNewThreadAnchor(channel, threadAnchorId) {
|
|
209
|
+
if (threadAnchorId)
|
|
210
|
+
return threadAnchorId;
|
|
210
211
|
const conv = await conversationLedger.getConversation(channel);
|
|
211
212
|
if (conv?.turns.length) {
|
|
212
213
|
for (let i = conv.turns.length - 1; i >= 0; i--) {
|
|
@@ -238,7 +239,7 @@ async function defaultLookupLedgerProfile(channel) {
|
|
|
238
239
|
}
|
|
239
240
|
/** Build the onNew SessionHookSpec + a fresh stream. Returns null when the hook isn't
|
|
240
241
|
* configured or there's no live session to capture context from. */
|
|
241
|
-
async function prepareOnNewRun(channel, adapter,
|
|
242
|
+
async function prepareOnNewRun(channel, adapter, threadAnchorId) {
|
|
242
243
|
if (!isOnNewHookConfigured())
|
|
243
244
|
return null;
|
|
244
245
|
const backend = resolveBackendForChannel(channel);
|
|
@@ -254,7 +255,7 @@ async function prepareOnNewRun(channel, adapter, threadTs) {
|
|
|
254
255
|
lookupRegistryProfile: defaultLookupRegistryProfile,
|
|
255
256
|
lookupLedgerProfile: defaultLookupLedgerProfile,
|
|
256
257
|
});
|
|
257
|
-
const anchor = await resolveOnNewThreadAnchor(channel,
|
|
258
|
+
const anchor = await resolveOnNewThreadAnchor(channel, threadAnchorId);
|
|
258
259
|
const stream = adapter.openOutputStream({ type: 'interactive-reply', conduit: channel, sessionId: '' }, { threadId: anchor });
|
|
259
260
|
const spec = {
|
|
260
261
|
name: 'onNew',
|
|
@@ -268,8 +269,8 @@ async function prepareOnNewRun(channel, adapter, threadTs) {
|
|
|
268
269
|
* Returns immediately; the hook subprocess and any injected agent turn run async
|
|
269
270
|
* via the unified pipeline. The session is closed by the caller in parallel —
|
|
270
271
|
* sessionId is captured up-front so the JSONL still resolves after deletion. */
|
|
271
|
-
export async function fireAndForgetPreCloseHook(channel, adapter,
|
|
272
|
-
const prepared = await prepareOnNewRun(channel, adapter,
|
|
272
|
+
export async function fireAndForgetPreCloseHook(channel, adapter, threadAnchorId) {
|
|
273
|
+
const prepared = await prepareOnNewRun(channel, adapter, threadAnchorId);
|
|
273
274
|
if (!prepared)
|
|
274
275
|
return;
|
|
275
276
|
void runSessionHook(prepared.spec, prepared.stream).catch((err) => {
|
|
@@ -279,8 +280,8 @@ export async function fireAndForgetPreCloseHook(channel, adapter, threadTs) {
|
|
|
279
280
|
/** Synchronous variant of fireAndForgetPreCloseHook — awaits the hook to completion.
|
|
280
281
|
* Reserved for cases where the caller wants to block on the !new pipeline (e.g.
|
|
281
282
|
* test harness, scripted teardown). */
|
|
282
|
-
export async function runPreCloseHook(channel, adapter,
|
|
283
|
-
const prepared = await prepareOnNewRun(channel, adapter,
|
|
283
|
+
export async function runPreCloseHook(channel, adapter, threadAnchorId) {
|
|
284
|
+
const prepared = await prepareOnNewRun(channel, adapter, threadAnchorId);
|
|
284
285
|
if (!prepared)
|
|
285
286
|
return;
|
|
286
287
|
await runSessionHook(prepared.spec, prepared.stream);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const SESSION_BACKENDS: readonly ["claude", "pi", "codex"];
|
|
2
|
+
export interface SessionRegistryWriter {
|
|
3
|
+
generateSessionName(): Promise<string>;
|
|
4
|
+
registerSession(name: string, opts: {
|
|
5
|
+
sessionId: string;
|
|
6
|
+
channel: string;
|
|
7
|
+
backend: string;
|
|
8
|
+
kind: 'local' | 'scheduled';
|
|
9
|
+
projectId: string;
|
|
10
|
+
label?: string | null;
|
|
11
|
+
profileName?: string | null;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface RegisterNamedSessionOpts {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
channel: string;
|
|
17
|
+
backend: string;
|
|
18
|
+
projectId: string;
|
|
19
|
+
kind?: 'local' | 'scheduled';
|
|
20
|
+
label?: string | null;
|
|
21
|
+
profileName?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Generate a fresh session name and register a registry record for sessionId. Returns the name.
|
|
24
|
+
* Centralizes the generateSessionName + registerSession pairing used by inbound-message session
|
|
25
|
+
* creation (agent-runner) and TUI fresh-session creation. */
|
|
26
|
+
export declare function registerNamedSession(store: SessionRegistryWriter, opts: RegisterNamedSessionOpts): Promise<string>;
|
|
27
|
+
export interface AttachExistingSessionOpts {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
sessionName: string;
|
|
30
|
+
backend: string;
|
|
31
|
+
profileName?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** Attach a channel to an existing session: restore its profile (if any), point sessions.json at it,
|
|
34
|
+
* and switch the conversation ledger. Mirrors the !resume switch sequence. */
|
|
35
|
+
export declare function attachExistingSession(channel: string, opts: AttachExistingSessionOpts): Promise<void>;
|
|
36
|
+
/** Clear a channel's session state: drop sessions.json keys for every backend, clean session
|
|
37
|
+
* backups, and clear the conversation ledger. Mirrors the store-level half of !new. */
|
|
38
|
+
export declare function resetChannelSession(channel: string): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// input: session-registry-repo (sessionStore), session-repo (sessions.json), conversation-ledger-repo, session-backup, setActiveProfile
|
|
2
|
+
// output: registerNamedSession / attachExistingSession / resetChannelSession — shared session lifecycle primitives
|
|
3
|
+
// pos: domain/sessions — centralized session lifecycle for agent-runner, tui-session-service, and commands/session
|
|
4
|
+
import { setSessionAsync, deleteSessionAsync } from './session.js';
|
|
5
|
+
import { conversationLedger } from '../../store/conversation-ledger-repo.js';
|
|
6
|
+
import { setActiveProfile } from '../agents/index.js';
|
|
7
|
+
import * as sessionBackup from './session-backup.js';
|
|
8
|
+
export const SESSION_BACKENDS = ['claude', 'pi', 'codex'];
|
|
9
|
+
/** Generate a fresh session name and register a registry record for sessionId. Returns the name.
|
|
10
|
+
* Centralizes the generateSessionName + registerSession pairing used by inbound-message session
|
|
11
|
+
* creation (agent-runner) and TUI fresh-session creation. */
|
|
12
|
+
export async function registerNamedSession(store, opts) {
|
|
13
|
+
const name = await store.generateSessionName();
|
|
14
|
+
await store.registerSession(name, {
|
|
15
|
+
sessionId: opts.sessionId,
|
|
16
|
+
channel: opts.channel,
|
|
17
|
+
backend: opts.backend,
|
|
18
|
+
kind: opts.kind ?? 'local',
|
|
19
|
+
projectId: opts.projectId,
|
|
20
|
+
label: opts.label ?? null,
|
|
21
|
+
profileName: opts.profileName ?? null,
|
|
22
|
+
});
|
|
23
|
+
return name;
|
|
24
|
+
}
|
|
25
|
+
/** Attach a channel to an existing session: restore its profile (if any), point sessions.json at it,
|
|
26
|
+
* and switch the conversation ledger. Mirrors the !resume switch sequence. */
|
|
27
|
+
export async function attachExistingSession(channel, opts) {
|
|
28
|
+
if (opts.profileName)
|
|
29
|
+
setActiveProfile(opts.profileName, channel);
|
|
30
|
+
await setSessionAsync(channel, opts.sessionId, opts.backend);
|
|
31
|
+
await conversationLedger.switchSession(channel, {
|
|
32
|
+
sessionId: opts.sessionId, sessionName: opts.sessionName, backend: opts.backend, profileName: opts.profileName,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Clear a channel's session state: drop sessions.json keys for every backend, clean session
|
|
36
|
+
* backups, and clear the conversation ledger. Mirrors the store-level half of !new. */
|
|
37
|
+
export async function resetChannelSession(channel) {
|
|
38
|
+
const conv = await conversationLedger.getConversation(channel);
|
|
39
|
+
if (conv) {
|
|
40
|
+
sessionBackup.cleanupAllBackups(conv.sessionId);
|
|
41
|
+
await conversationLedger.clearConversation(channel);
|
|
42
|
+
}
|
|
43
|
+
await Promise.all(SESSION_BACKENDS.map(b => deleteSessionAsync(channel, b).catch(() => { })));
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ReleaseInfo {
|
|
2
|
+
tagName: string;
|
|
3
|
+
version: string;
|
|
4
|
+
name: string;
|
|
5
|
+
body: string;
|
|
6
|
+
htmlUrl: string;
|
|
7
|
+
publishedAt: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Build GitHub Release web URL for a given version.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildGitHubReleaseUrl(version: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Fetch release notes from GitHub API for a given version.
|
|
15
|
+
* Returns cached result if available and not expired.
|
|
16
|
+
* Returns null if fetch fails or release doesn't exist.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchReleaseNote(version: string): Promise<ReleaseInfo | null>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// input: version string (CalVer format), fetch, file I/O
|
|
2
|
+
// output: ReleaseInfo | null, cached release notes
|
|
3
|
+
// pos: GitHub Release API client with local caching
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { STORE_DIR } from '../../core/paths.js';
|
|
7
|
+
import { createLogger } from '../../core/log.js';
|
|
8
|
+
const log = createLogger('github-release');
|
|
9
|
+
const GITHUB_API_BASE = 'https://api.github.com';
|
|
10
|
+
const REPO_OWNER = 'fangxm233';
|
|
11
|
+
const REPO_NAME = 'cortex-agent';
|
|
12
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
13
|
+
const CACHE_FILE = path.join(STORE_DIR, 'release-cache.json');
|
|
14
|
+
/**
|
|
15
|
+
* Load cache from disk, or return empty structure if missing/invalid.
|
|
16
|
+
*/
|
|
17
|
+
function loadCache() {
|
|
18
|
+
if (!fs.existsSync(CACHE_FILE)) {
|
|
19
|
+
return { releases: {} };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const data = fs.readFileSync(CACHE_FILE, 'utf8');
|
|
23
|
+
return JSON.parse(data);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
log.warn(`Failed to load release cache: ${e.message}`);
|
|
27
|
+
return { releases: {} };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save cache to disk.
|
|
32
|
+
*/
|
|
33
|
+
function saveCache(cache) {
|
|
34
|
+
try {
|
|
35
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
log.warn(`Failed to save release cache: ${e.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build GitHub Release API URL for a given version.
|
|
43
|
+
* GitHub tag format: server-v{version}
|
|
44
|
+
*/
|
|
45
|
+
function buildGitHubApiUrl(version) {
|
|
46
|
+
const tagName = `server-v${version}`;
|
|
47
|
+
return `${GITHUB_API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${tagName}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build GitHub Release web URL for a given version.
|
|
51
|
+
*/
|
|
52
|
+
export function buildGitHubReleaseUrl(version) {
|
|
53
|
+
const tagName = `server-v${version}`;
|
|
54
|
+
return `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/${tagName}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetch release notes from GitHub API for a given version.
|
|
58
|
+
* Returns cached result if available and not expired.
|
|
59
|
+
* Returns null if fetch fails or release doesn't exist.
|
|
60
|
+
*/
|
|
61
|
+
export async function fetchReleaseNote(version) {
|
|
62
|
+
const cache = loadCache();
|
|
63
|
+
const cached = cache.releases[version];
|
|
64
|
+
// Check if cache is valid (not expired)
|
|
65
|
+
if (cached) {
|
|
66
|
+
const age = Date.now() - cached.fetchedAt;
|
|
67
|
+
if (age < CACHE_TTL_MS) {
|
|
68
|
+
log.debug(`Using cached release note for ${version}`);
|
|
69
|
+
return cached.info;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Fetch from GitHub API
|
|
73
|
+
const url = buildGitHubApiUrl(version);
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(url);
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
if (response.status === 404) {
|
|
78
|
+
log.warn(`Release not found for version ${version}`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
log.warn(`GitHub API error: ${response.status} ${response.statusText}`);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const data = (await response.json());
|
|
86
|
+
const releaseInfo = {
|
|
87
|
+
tagName: data.tag_name,
|
|
88
|
+
version,
|
|
89
|
+
name: data.name || `Release ${version}`,
|
|
90
|
+
body: data.body || '',
|
|
91
|
+
htmlUrl: data.html_url,
|
|
92
|
+
publishedAt: data.published_at,
|
|
93
|
+
};
|
|
94
|
+
// Update cache
|
|
95
|
+
cache.releases[version] = {
|
|
96
|
+
info: releaseInfo,
|
|
97
|
+
fetchedAt: Date.now(),
|
|
98
|
+
};
|
|
99
|
+
saveCache(cache);
|
|
100
|
+
return releaseInfo;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
log.error(`Failed to fetch release note for ${version}: ${error.message}`);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|