@cortex-agent/server 2026.5.25 → 2026.6.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/config/thread-templates.json +28 -1
- package/defaults/hooks/cortex-md-injector.mjs +47 -31
- package/defaults/hooks/post-task-hook.mjs +6 -0
- package/defaults/hooks/task-status-check.mjs +8 -0
- package/defaults/mcp-config-slack.json +11 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
- package/defaults/prompts/directives/manager.md +67 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
- package/dist/agent-adapter/claude/adapter-tui.js +91 -12
- package/dist/agent-adapter/claude/adapter.js +11 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +30 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
- package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
- package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
- package/dist/agent-adapter/claude/spawn-args.js +49 -7
- package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
- package/dist/agent-adapter/claude/tmux-control.js +54 -8
- package/dist/agent-adapter/codex/adapter.js +1 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
- package/dist/agent-adapter/pi/adapter.js +46 -19
- package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
- package/dist/agent-adapter/pi/agent-dir.js +53 -2
- package/dist/agent-adapter/pi/event-parser.js +13 -1
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
- package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
- package/dist/agent-adapter/pi/tool-shims.js +167 -140
- package/dist/agent-adapter/types.d.ts +7 -2
- package/dist/core/atomic-write.js +21 -0
- package/dist/core/config-generator.d.ts +10 -0
- package/dist/core/config-generator.js +28 -0
- package/dist/core/gateway-generator.d.ts +77 -7
- package/dist/core/gateway-generator.js +323 -30
- package/dist/core/i18n.d.ts +19 -0
- package/dist/core/i18n.js +46 -0
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -0
- package/dist/core/locales/en.d.ts +438 -0
- package/dist/core/locales/en.js +24 -0
- package/dist/core/locales/slices/commands.d.ts +214 -0
- package/dist/core/locales/slices/commands.js +462 -0
- package/dist/core/locales/slices/init.d.ts +121 -0
- package/dist/core/locales/slices/init.js +380 -0
- package/dist/core/locales/slices/interactions.d.ts +47 -0
- package/dist/core/locales/slices/interactions.js +102 -0
- package/dist/core/locales/slices/lang.d.ts +8 -0
- package/dist/core/locales/slices/lang.js +18 -0
- package/dist/core/locales/slices/scheduling.d.ts +36 -0
- package/dist/core/locales/slices/scheduling.js +74 -0
- package/dist/core/locales/slices/startup.d.ts +6 -0
- package/dist/core/locales/slices/startup.js +14 -0
- package/dist/core/locales/slices/status.d.ts +20 -0
- package/dist/core/locales/slices/status.js +48 -0
- package/dist/core/locales/zh.d.ts +5 -0
- package/dist/core/locales/zh.js +23 -0
- package/dist/core/profile-generator.d.ts +6 -0
- package/dist/core/profile-generator.js +35 -7
- package/dist/core/running-executions.d.ts +51 -41
- package/dist/core/running-executions.js +120 -73
- package/dist/core/singleton-lock.d.ts +23 -0
- package/dist/core/singleton-lock.js +53 -0
- package/dist/core/status-format.js +4 -2
- package/dist/core/task-parser.d.ts +3 -0
- package/dist/core/task-parser.js +3 -1
- package/dist/core/types/thread-types.d.ts +54 -8
- package/dist/core/utils.d.ts +9 -1
- package/dist/core/utils.js +9 -1
- package/dist/domain/agents/config.d.ts +2 -1
- package/dist/domain/agents/config.js +25 -6
- package/dist/domain/agents/facade.d.ts +18 -0
- package/dist/domain/agents/facade.js +26 -3
- package/dist/domain/agents/profile-manager.d.ts +11 -0
- package/dist/domain/agents/profile-manager.js +21 -2
- package/dist/domain/costs/codex-usage-monitor.js +2 -1
- package/dist/domain/costs/rate-limit-throttle.js +14 -2
- package/dist/domain/executions/registry.d.ts +24 -0
- package/dist/domain/executions/registry.js +38 -0
- package/dist/domain/mcp/core-server.js +15 -3
- package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
- package/dist/domain/mcp/feishu/bitable.js +168 -0
- package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
- package/dist/domain/mcp/feishu/block-types.js +127 -0
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
- package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
- package/dist/domain/mcp/feishu/client.d.ts +46 -0
- package/dist/domain/mcp/feishu/client.js +87 -0
- package/dist/domain/mcp/feishu/docx.d.ts +3 -0
- package/dist/domain/mcp/feishu/docx.js +163 -0
- package/dist/domain/mcp/feishu/drive.d.ts +23 -0
- package/dist/domain/mcp/feishu/drive.js +66 -0
- package/dist/domain/mcp/feishu/file.d.ts +14 -0
- package/dist/domain/mcp/feishu/file.js +107 -0
- package/dist/domain/mcp/feishu/index.d.ts +6 -0
- package/dist/domain/mcp/feishu/index.js +61 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
- package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
- package/dist/domain/mcp/feishu/sheets.js +119 -0
- package/dist/domain/mcp/feishu/types.d.ts +26 -0
- package/dist/domain/mcp/feishu/types.js +38 -0
- package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
- package/dist/domain/mcp/feishu/user-auth.js +286 -0
- package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
- package/dist/domain/mcp/feishu/wiki.js +77 -0
- package/dist/domain/mcp/feishu-server.d.ts +2 -0
- package/dist/domain/mcp/feishu-server.js +33 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +6 -25
- package/dist/domain/mcp/slack-server.d.ts +3 -0
- package/dist/domain/mcp/slack-server.js +46 -0
- package/dist/domain/mcp/tools/context.js +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +1 -1
- package/dist/domain/mcp/tools/schedule.js +6 -20
- package/dist/domain/mcp/tools/slack.js +20 -7
- package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/thread-ops.js +121 -0
- package/dist/domain/mcp/tools/time.d.ts +2 -0
- package/dist/domain/mcp/tools/time.js +66 -0
- package/dist/domain/mcp/tools/tui-ask.js +1 -1
- package/dist/domain/mcp/tools/tui-plan.js +2 -2
- package/dist/domain/mcp/tui-server.js +1 -0
- package/dist/domain/monitor/disk-monitor.js +2 -1
- package/dist/domain/monitor/gpu-monitor.js +2 -1
- package/dist/domain/remote/client-hot-reload.js +3 -2
- package/dist/domain/remote/client-manager.js +8 -6
- package/dist/domain/scheduling/job-registry.d.ts +4 -0
- package/dist/domain/scheduling/job-registry.js +1 -0
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
- package/dist/domain/scheduling/jobs/sync-public.js +4 -3
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
- package/dist/domain/scheduling/jobs/task-archive.js +3 -2
- package/dist/domain/scheduling/jobs/task-dispatch.js +126 -20
- package/dist/domain/scheduling/schedule-command.js +45 -43
- package/dist/domain/scheduling/scheduler.d.ts +1 -1
- package/dist/domain/scheduling/scheduler.js +2 -1
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-hooks.js +19 -18
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
- package/dist/domain/sessions/session-lifecycle.js +44 -0
- package/dist/domain/system/github-release.d.ts +18 -0
- package/dist/domain/system/github-release.js +106 -0
- package/dist/domain/system/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/system/preferences.d.ts +12 -0
- package/dist/domain/system/preferences.js +36 -0
- package/dist/domain/system/server-update-check.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.d.ts +11 -2
- package/dist/domain/tasks/dispatcher.js +63 -7
- package/dist/domain/tasks/lint.js +28 -0
- package/dist/domain/tasks/mutator.d.ts +16 -3
- package/dist/domain/tasks/mutator.js +41 -12
- package/dist/domain/tasks/pending-tracker.js +6 -5
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
- package/dist/domain/tasks/system/task-mutations.js +166 -8
- package/dist/domain/threads/contract.d.ts +17 -0
- package/dist/domain/threads/contract.js +59 -0
- package/dist/domain/threads/hook-runner.js +7 -6
- package/dist/domain/threads/index.d.ts +2 -0
- package/dist/domain/threads/index.js +3 -1
- package/dist/domain/threads/prompt-builder.d.ts +21 -1
- package/dist/domain/threads/prompt-builder.js +60 -4
- package/dist/domain/threads/runner.d.ts +6 -5
- package/dist/domain/threads/runner.js +128 -79
- package/dist/domain/threads/state-machine.d.ts +23 -21
- package/dist/domain/threads/state-machine.js +113 -54
- package/dist/domain/threads/template-loader.js +3 -2
- package/dist/domain/threads/tree.d.ts +45 -0
- package/dist/domain/threads/tree.js +171 -0
- package/dist/domain/tui-session/index.d.ts +2 -0
- package/dist/domain/tui-session/index.js +3 -0
- package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
- package/dist/domain/tui-session/tui-session-service.js +103 -0
- package/dist/domain/tui-session/types.d.ts +67 -0
- package/dist/domain/tui-session/types.js +4 -0
- package/dist/domain/ui-service/index.d.ts +5 -0
- package/dist/domain/ui-service/index.js +3 -0
- package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
- package/dist/domain/ui-service/mutate/executions.js +15 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
- package/dist/domain/ui-service/mutate/schedules.js +39 -0
- package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
- package/dist/domain/ui-service/mutate/tasks.js +59 -0
- package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
- package/dist/domain/ui-service/mutate/threads.js +21 -0
- package/dist/domain/ui-service/query/cost.d.ts +3 -0
- package/dist/domain/ui-service/query/cost.js +6 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -0
- package/dist/domain/ui-service/query/executions.js +35 -0
- package/dist/domain/ui-service/query/projects.d.ts +2 -0
- package/dist/domain/ui-service/query/projects.js +30 -0
- package/dist/domain/ui-service/query/schedules.d.ts +2 -0
- package/dist/domain/ui-service/query/schedules.js +23 -0
- package/dist/domain/ui-service/query/sessions.d.ts +2 -0
- package/dist/domain/ui-service/query/sessions.js +35 -0
- package/dist/domain/ui-service/query/tasks.d.ts +2 -0
- package/dist/domain/ui-service/query/tasks.js +30 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -0
- package/dist/domain/ui-service/query/threads.js +27 -0
- package/dist/domain/ui-service/subscribe.d.ts +5 -0
- package/dist/domain/ui-service/subscribe.js +118 -0
- package/dist/domain/ui-service/types.d.ts +237 -0
- package/dist/domain/ui-service/types.js +5 -0
- package/dist/domain/ui-service/ui-service.d.ts +2 -0
- package/dist/domain/ui-service/ui-service.js +83 -0
- package/dist/entry/app.js +130 -8
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/daemon.js +12 -30
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +29 -5
- package/dist/entry/init.js +323 -233
- package/dist/entry/startup-notify.js +6 -3
- package/dist/events/event-types.d.ts +14 -0
- package/dist/hooks/cortex-md-injector.mjs +47 -31
- package/dist/hooks/post-task-hook.mjs +6 -0
- package/dist/hooks/task-status-check.mjs +8 -0
- package/dist/orchestration/agent-runner.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +55 -55
- package/dist/orchestration/conduit-queue.d.ts +18 -0
- package/dist/orchestration/conduit-queue.js +32 -0
- package/dist/orchestration/conversation-runner.d.ts +48 -0
- package/dist/orchestration/conversation-runner.js +109 -0
- package/dist/orchestration/dispatch-reconciler.js +8 -1
- package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
- package/dist/orchestration/interactions/ask-user-question.js +3 -3
- package/dist/orchestration/interactions/interaction-handlers.js +55 -23
- package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
- package/dist/orchestration/interactions/plan-handler.js +4 -3
- package/dist/orchestration/interactions/update-prompt-slack.js +11 -10
- package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +155 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +25 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +45 -52
- package/dist/orchestration/routing/commands/channel.js +41 -27
- package/dist/orchestration/routing/commands/cost.js +11 -2
- package/dist/orchestration/routing/commands/device.js +12 -9
- package/dist/orchestration/routing/commands/dispatch.js +11 -10
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +15 -10
- package/dist/orchestration/routing/commands/lang.d.ts +3 -0
- package/dist/orchestration/routing/commands/lang.js +31 -0
- package/dist/orchestration/routing/commands/mode.js +32 -30
- package/dist/orchestration/routing/commands/nvtop.js +15 -13
- package/dist/orchestration/routing/commands/orient.js +2 -1
- package/dist/orchestration/routing/commands/schedule.js +23 -22
- package/dist/orchestration/routing/commands/sendfile.js +9 -7
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +24 -39
- package/dist/orchestration/routing/commands/status.js +78 -71
- package/dist/orchestration/routing/commands/tail.js +7 -5
- package/dist/orchestration/routing/commands/task.js +25 -23
- package/dist/orchestration/routing/commands/thread-handlers.js +55 -44
- package/dist/orchestration/routing/edit-handler.js +8 -7
- package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
- package/dist/orchestration/routing/message-router.d.ts +1 -1
- package/dist/orchestration/routing/message-router.js +9 -9
- package/dist/orchestration/routing/webhook.js +233 -2
- package/dist/orchestration/status-helpers.d.ts +5 -1
- package/dist/orchestration/status-helpers.js +13 -11
- package/dist/orchestration/thread-callback.d.ts +67 -0
- package/dist/orchestration/thread-callback.js +465 -0
- package/dist/orchestration/thread-executor.d.ts +22 -1
- package/dist/orchestration/thread-executor.js +85 -36
- package/dist/platform/adapter.d.ts +6 -2
- package/dist/platform/adapters/composite-adapter.d.ts +89 -0
- package/dist/platform/adapters/composite-adapter.js +318 -0
- package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
- package/dist/platform/adapters/feishu-output-stream.js +274 -36
- package/dist/platform/adapters/feishu.d.ts +50 -5
- package/dist/platform/adapters/feishu.js +370 -116
- package/dist/platform/adapters/index.d.ts +24 -3
- package/dist/platform/adapters/index.js +89 -11
- package/dist/platform/adapters/project-conduits.d.ts +9 -0
- package/dist/platform/adapters/project-conduits.js +42 -0
- package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
- package/dist/platform/adapters/slack-project-conduits.js +6 -40
- package/dist/platform/adapters/slack.d.ts +9 -2
- package/dist/platform/adapters/slack.js +83 -39
- package/dist/platform/adapters/tui/index.d.ts +9 -0
- package/dist/platform/adapters/tui/index.js +10 -0
- package/dist/platform/adapters/tui/ports.d.ts +20 -0
- package/dist/platform/adapters/tui/ports.js +4 -0
- package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
- package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
- package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
- package/dist/platform/adapters/tui/tui-connection.js +53 -0
- package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
- package/dist/platform/adapters/tui/tui-gateway.js +919 -0
- package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
- package/dist/platform/adapters/tui/tui-notifications.js +60 -0
- package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
- package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
- package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
- package/dist/platform/adapters/tui/tui-transcript.js +56 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +2 -1
- package/dist/platform/interactive-builder.js +21 -19
- package/dist/platform/output-stream.d.ts +5 -0
- package/dist/platform/testing.d.ts +7 -11
- package/dist/platform/testing.js +18 -15
- package/dist/platform/tool-trace.js +15 -5
- package/dist/platform/tui/protocol.d.ts +355 -0
- package/dist/platform/tui/protocol.js +199 -0
- package/dist/platform/types.d.ts +12 -3
- package/dist/store/execution-repo.d.ts +6 -1
- package/dist/store/execution-repo.js +13 -3
- package/dist/store/hook-sync.d.ts +18 -0
- package/dist/store/hook-sync.js +92 -0
- package/dist/store/outbound-queue.js +2 -2
- package/dist/store/profile-repo.js +3 -2
- package/dist/store/schedule-repo.d.ts +1 -8
- package/dist/store/session-registry-repo.d.ts +9 -1
- package/dist/store/session-registry-repo.js +19 -3
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +23 -0
- package/dist/store/thread-repo.d.ts +3 -0
- package/dist/store/thread-repo.js +49 -2
- package/dist/store/version-migrations.d.ts +7 -0
- package/dist/store/version-migrations.js +183 -0
- package/dist/tui/App.d.ts +27 -0
- package/dist/tui/App.js +219 -0
- package/dist/tui/components/AskUserModal.d.ts +11 -0
- package/dist/tui/components/AskUserModal.js +364 -0
- package/dist/tui/components/ConfirmModal.d.ts +12 -0
- package/dist/tui/components/ConfirmModal.js +31 -0
- package/dist/tui/components/Dashboard.d.ts +23 -0
- package/dist/tui/components/Dashboard.js +80 -0
- package/dist/tui/components/DashboardCostTab.d.ts +7 -0
- package/dist/tui/components/DashboardCostTab.js +16 -0
- package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
- package/dist/tui/components/DashboardExecutionsTab.js +94 -0
- package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
- package/dist/tui/components/DashboardSchedulesTab.js +124 -0
- package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
- package/dist/tui/components/DashboardTasksTab.js +200 -0
- package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
- package/dist/tui/components/DashboardThreadsTab.js +81 -0
- package/dist/tui/components/Header.d.ts +11 -0
- package/dist/tui/components/Header.js +5 -0
- package/dist/tui/components/InputBox.d.ts +10 -0
- package/dist/tui/components/InputBox.js +19 -0
- package/dist/tui/components/MessageRow.d.ts +7 -0
- package/dist/tui/components/MessageRow.js +10 -0
- package/dist/tui/components/Notifications.d.ts +19 -0
- package/dist/tui/components/Notifications.js +72 -0
- package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
- package/dist/tui/components/PlanFeedbackModal.js +161 -0
- package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
- package/dist/tui/components/ProjectSwitcher.js +43 -0
- package/dist/tui/components/SessionPicker.d.ts +14 -0
- package/dist/tui/components/SessionPicker.js +34 -0
- package/dist/tui/components/SidePanel.d.ts +19 -0
- package/dist/tui/components/SidePanel.js +8 -0
- package/dist/tui/components/StatusLine.d.ts +10 -0
- package/dist/tui/components/StatusLine.js +29 -0
- package/dist/tui/components/Transcript.d.ts +13 -0
- package/dist/tui/components/Transcript.js +56 -0
- package/dist/tui/hooks/useDashboardData.d.ts +32 -0
- package/dist/tui/hooks/useDashboardData.js +104 -0
- package/dist/tui/hooks/useKeybindings.d.ts +19 -0
- package/dist/tui/hooks/useKeybindings.js +87 -0
- package/dist/tui/hooks/useMutate.d.ts +22 -0
- package/dist/tui/hooks/useMutate.js +56 -0
- package/dist/tui/hooks/useNotifications.d.ts +28 -0
- package/dist/tui/hooks/useNotifications.js +70 -0
- package/dist/tui/hooks/useTranscript.d.ts +39 -0
- package/dist/tui/hooks/useTranscript.js +265 -0
- package/dist/tui/hooks/useWsClient.d.ts +29 -0
- package/dist/tui/hooks/useWsClient.js +69 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +210 -0
- package/dist/tui/logic.d.ts +16 -0
- package/dist/tui/logic.js +49 -0
- package/dist/tui/render/markdown.d.ts +10 -0
- package/dist/tui/render/markdown.js +38 -0
- package/dist/tui/render/rich-blocks.d.ts +11 -0
- package/dist/tui/render/rich-blocks.js +24 -0
- package/dist/tui/ws-client.d.ts +44 -0
- package/dist/tui/ws-client.js +157 -0
- package/package.json +11 -3
- package/dist/orchestration/channel-queue.d.ts +0 -18
- package/dist/orchestration/channel-queue.js +0 -32
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
// pos: send DM notification to admin channel during startup
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { CORTEX_VERSION } from '../core/version.js';
|
|
6
|
+
import { t } from '../core/i18n.js';
|
|
6
7
|
function buildStartupMessage({ machine, restartReason }) {
|
|
7
8
|
const machineLabel = machine || 'unknown-machine';
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const base = t(restartReason ? 'startup.restarted' : 'startup.started', {
|
|
10
|
+
version: CORTEX_VERSION,
|
|
11
|
+
machine: machineLabel,
|
|
12
|
+
});
|
|
13
|
+
return restartReason ? `${base}${t('startup.reason', { reason: restartReason })}` : base;
|
|
11
14
|
}
|
|
12
15
|
async function sendStartupDmIfConfigured(adapter, { machine, restartReason } = {}) {
|
|
13
16
|
try {
|
|
@@ -111,6 +111,11 @@ export type CortexEvent = {
|
|
|
111
111
|
ts: string;
|
|
112
112
|
taskId: string;
|
|
113
113
|
machine: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'task.blocked';
|
|
116
|
+
ts: string;
|
|
117
|
+
taskId: string;
|
|
118
|
+
reason: string;
|
|
114
119
|
} | {
|
|
115
120
|
type: 'llm.active-count-delta';
|
|
116
121
|
ts: string;
|
|
@@ -124,6 +129,15 @@ export type CortexEvent = {
|
|
|
124
129
|
ts: string;
|
|
125
130
|
provider: string;
|
|
126
131
|
percent: number;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'ui.mutate-invoked';
|
|
134
|
+
ts: string;
|
|
135
|
+
op: string;
|
|
136
|
+
args: unknown;
|
|
137
|
+
result: {
|
|
138
|
+
ok: boolean;
|
|
139
|
+
code?: string;
|
|
140
|
+
} | null;
|
|
127
141
|
} | {
|
|
128
142
|
type: 'event-bus.handler-failed';
|
|
129
143
|
ts: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// @cortex-hook-version 2026.6.4 ← set to the current release version (agent-server/package.json) whenever you change this hook; syncManagedHooks then refreshes deployed installs
|
|
2
3
|
// input: stdin JSON — Claude Code hook event or PI hook-bridge payload
|
|
3
4
|
// output: { hookSpecificOutput: { hookEventName, additionalContext, matched } }
|
|
4
5
|
// pos: Inject CORTEX.md / CORTEX.local.md ancestor chain into agent context
|
|
@@ -6,8 +7,11 @@
|
|
|
6
7
|
// PostToolUse (Read) — from tool_input.file_path/path
|
|
7
8
|
// SessionStart (startup|resume|clear|compact) — from payload.cwd
|
|
8
9
|
// Per-session disk-backed dedup cache (~/.cortex/tmp/cortexmd-cache/<sessionId>.json)
|
|
10
|
+
// — only files actually injected are marked seen; truncated files stay eligible so
|
|
11
|
+
// a later Read re-attempts them (they are never silently suppressed)
|
|
9
12
|
// markOnlyPaths: tool operating on a CORTEX.md itself → cache update only, no inject
|
|
10
|
-
// Total length guard at 9,500 chars
|
|
13
|
+
// Total length guard at 9,500 chars; files that overflow the budget are turned into an
|
|
14
|
+
// explicit "Read EACH of these files now" instruction instead of a silent drop
|
|
11
15
|
// >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
|
|
12
16
|
|
|
13
17
|
import { readFileSync, statSync, existsSync, mkdirSync, renameSync, writeFileSync } from 'fs';
|
|
@@ -123,35 +127,44 @@ function saveCache(sessionId, cache) {
|
|
|
123
127
|
// ── context builder ──
|
|
124
128
|
|
|
125
129
|
function buildContext(entries) {
|
|
126
|
-
if (entries.length === 0) return '';
|
|
127
|
-
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
const
|
|
130
|
+
if (entries.length === 0) return { text: '', includedPaths: [] };
|
|
131
|
+
|
|
132
|
+
// Walk entries in original order (leaf→root), inlining each as a block until the char
|
|
133
|
+
// budget is exhausted. Once exhausted, the remaining entries are NOT inlined — instead
|
|
134
|
+
// they are turned into an explicit read-instruction below, so their rules are never
|
|
135
|
+
// silently dropped (e.g. a root-level CORTEX.local.md carrying dev/safety rules).
|
|
136
|
+
const includedBlocks = [];
|
|
137
|
+
const includedPaths = [];
|
|
138
|
+
const truncated = [];
|
|
134
139
|
let totalLen = 0;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
let budgetExhausted = false;
|
|
141
|
+
|
|
142
|
+
for (const e of entries) {
|
|
143
|
+
const block = `<system-reminder>\nAuto-loaded CORTEX.md from ${HOSTNAME}:${e.path} (ancestor of accessed path). These instructions apply to files under this directory.\n\n${e.content}\n</system-reminder>`;
|
|
144
|
+
if (budgetExhausted || totalLen + block.length > MAX_CONTEXT_CHARS) {
|
|
145
|
+
budgetExhausted = true; // match prior behavior: stop inlining at the first overflow
|
|
146
|
+
truncated.push(e);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
includedBlocks.push(block);
|
|
150
|
+
includedPaths.push(e.path);
|
|
139
151
|
totalLen += block.length;
|
|
140
152
|
}
|
|
141
153
|
|
|
142
|
-
const
|
|
154
|
+
const parts = [...includedBlocks];
|
|
143
155
|
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
// Overflow → actionable instruction. Reading these files delivers their content via the
|
|
157
|
+
// Read tool result; the markOnlyPaths branch then suppresses a duplicate inject.
|
|
158
|
+
if (truncated.length > 0) {
|
|
159
|
+
const list = truncated.map(e => `- ${e.path}`).join('\n');
|
|
160
|
+
parts.push(
|
|
161
|
+
`<system-reminder>\n⚠️ ${truncated.length} CORTEX rule file(s) were too large to inline here. ` +
|
|
162
|
+
`Read EACH of the following files now to load their rules before proceeding:\n${list}\n</system-reminder>`
|
|
163
|
+
);
|
|
152
164
|
}
|
|
153
165
|
|
|
154
|
-
return
|
|
166
|
+
if (parts.length === 0) return { text: '', includedPaths: [] };
|
|
167
|
+
return { text: parts.join('\n\n'), includedPaths };
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
// ── main ──
|
|
@@ -213,23 +226,26 @@ function main() {
|
|
|
213
226
|
const cache = loadCache(sessionId);
|
|
214
227
|
const newEntries = entries.filter(e => cache.get(e.path) !== e.mtimeMs);
|
|
215
228
|
|
|
216
|
-
// Update cache with all scanned entries
|
|
217
|
-
for (const entry of entries) {
|
|
218
|
-
cache.set(entry.path, entry.mtimeMs);
|
|
219
|
-
}
|
|
220
|
-
saveCache(sessionId, cache);
|
|
221
|
-
|
|
222
229
|
if (newEntries.length === 0) return;
|
|
223
230
|
|
|
224
231
|
// Build context with truncation guard
|
|
225
|
-
const additionalContext = buildContext(newEntries);
|
|
232
|
+
const { text: additionalContext, includedPaths } = buildContext(newEntries);
|
|
226
233
|
if (!additionalContext) return;
|
|
227
234
|
|
|
235
|
+
// Mark as seen ONLY the entries actually injected. Truncated entries stay "unseen" so a
|
|
236
|
+
// later Read re-attempts their injection (or re-emits the read-instruction) — they must
|
|
237
|
+
// never be silently suppressed by being cached before the truncation filter runs.
|
|
238
|
+
const injected = new Set(includedPaths);
|
|
239
|
+
for (const entry of entries) {
|
|
240
|
+
if (injected.has(entry.path)) cache.set(entry.path, entry.mtimeMs);
|
|
241
|
+
}
|
|
242
|
+
saveCache(sessionId, cache);
|
|
243
|
+
|
|
228
244
|
process.stdout.write(JSON.stringify({
|
|
229
245
|
hookSpecificOutput: {
|
|
230
246
|
hookEventName,
|
|
231
247
|
additionalContext,
|
|
232
|
-
matched:
|
|
248
|
+
matched: includedPaths,
|
|
233
249
|
},
|
|
234
250
|
}));
|
|
235
251
|
}
|
|
@@ -50,6 +50,12 @@ async function main() {
|
|
|
50
50
|
parts.push('After completing the task, run `git status` to check for your uncommitted changes. If there are changes, commit them with an appropriate commit message. Do not commit changes that are not made by you.');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// Worktree integration reminder (concurrent-safe code isolation). Piggybacks on the
|
|
54
|
+
// turn we are already injecting, so it costs no extra agent step. Self-gates: a no-op
|
|
55
|
+
// for tasks that never created a worktree.
|
|
56
|
+
const threadId = context.threadId || '$CORTEX_THREAD_ID';
|
|
57
|
+
parts.push(`If you created a git worktree for this task (branch cortex/${threadId}), integrate it back now before finishing: pull the latest main branch, merge your branch into it, resolve conflicts, push, then \`git worktree remove\` and delete the branch. On remote machines run these commands via remote_bash on the device you worked on. If conflicts cannot be resolved automatically, stop and report it — never force-overwrite another thread's work. If you did NOT create a worktree, ignore this.`);
|
|
58
|
+
|
|
53
59
|
console.log(JSON.stringify({
|
|
54
60
|
insertAgent: false,
|
|
55
61
|
targetAgent,
|
|
@@ -119,6 +119,14 @@ async function main() {
|
|
|
119
119
|
|
|
120
120
|
if (!project || !taskId) { noop(); return; }
|
|
121
121
|
|
|
122
|
+
// [SPLIT] decomposition proposal (DR-0014): the task is INTENTIONALLY not done — the
|
|
123
|
+
// dispatcher decomposes it keep-parent and unclaims. Don't burn an agent turn nagging.
|
|
124
|
+
if ((ctx.artifactContent || '').includes('[SPLIT]')) { noop(); return; }
|
|
125
|
+
|
|
126
|
+
// [ABORT] worker escalation (DR-0014 §8): the dispatcher blocks the task with the abort
|
|
127
|
+
// reason right after this hook returns — the task is intentionally not done.
|
|
128
|
+
if (/\[ABORT(?::|\])/.test(ctx.artifactContent || '')) { noop(); return; }
|
|
129
|
+
|
|
122
130
|
const tasksPath = path.join(PROJECTS_DIR, project, 'TASKS.yaml');
|
|
123
131
|
if (!existsSync(tasksPath)) { noop(); return; }
|
|
124
132
|
|
|
@@ -16,7 +16,7 @@ export interface AgentRunnerCtx {
|
|
|
16
16
|
message: IncomingMessage;
|
|
17
17
|
channel: string;
|
|
18
18
|
adapter: PlatformAdapter;
|
|
19
|
-
|
|
19
|
+
threadAnchorId: string | null;
|
|
20
20
|
hasFiles: boolean;
|
|
21
21
|
userMessage: string;
|
|
22
22
|
agentMessage: string;
|
|
@@ -37,6 +37,7 @@ export declare class AgentRunner {
|
|
|
37
37
|
export declare const agentRunner: AgentRunner;
|
|
38
38
|
/** Exposed for unit testing. */
|
|
39
39
|
export declare function resolveDefaultAgent(agentMessage: string, channel?: string): AgentConfig;
|
|
40
|
+
export declare function resolveSessionName(sessionId: string | null, channel: string, userMessage: string, adapter: PlatformAdapter): Promise<string>;
|
|
40
41
|
/**
|
|
41
42
|
* Build interactive callbacks for plan_written, ask_user_question, and tool_use events.
|
|
42
43
|
* These fire during the turn (not after) and publish bus events so the existing
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output: AgentRunner —
|
|
3
|
-
// pos: orch/ — sole
|
|
1
|
+
// input: conversation-runner, agent-lifecycle, orch/channel-queue, orch/busy-tracker, orch/active-agents
|
|
2
|
+
// output: AgentRunner — plain user-message path: session/status/ledger/callbacks + runConversation (no thread) [S8]
|
|
3
|
+
// pos: orch/ — sole plain user-message execution path
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { resolveDestinationConduit } from '../platform/types.js';
|
|
6
|
-
import {
|
|
6
|
+
import { conduitQueues, enqueue } from './conduit-queue.js';
|
|
7
7
|
import { trackPendingTask } from './busy-tracker.js';
|
|
8
8
|
import { getSessionAsync } from '../domain/sessions/session.js';
|
|
9
9
|
import { sessionStore } from '../store/session-registry-repo.js';
|
|
10
10
|
import { conversationLedger } from '../store/conversation-ledger-repo.js';
|
|
11
11
|
import { getActiveProfile, getDefaultAgent, resolveBackendForChannel } from '../domain/agents/index.js';
|
|
12
|
+
import { registerNamedSession } from '../domain/sessions/session-lifecycle.js';
|
|
12
13
|
import { handleAgentSuccess, handleAgentError, initTurnTracking } from './lifecycle.js';
|
|
13
14
|
import { buildSessionTag, buildUserProcessingMessage, makeFallbackNotifier, makeStreamingMessageCallback, computeElapsed, writeStatus, sealStatus, buildStatusActionBlocks, buildSealedStatusActionBlocks, initStatusBlocks } from './status-helpers.js';
|
|
14
15
|
import { readFileSync } from 'fs';
|
|
15
16
|
import { createLogger } from '../core/log.js';
|
|
17
|
+
import { Icons } from '../core/icons.js';
|
|
16
18
|
import { getOutboundQueue } from '../store/outbound-queue.js';
|
|
17
19
|
import { buildDurableHooks } from './durable-helpers.js';
|
|
18
20
|
const log = createLogger('agent-runner');
|
|
19
21
|
import { createToolTrace } from '../platform/index.js';
|
|
20
22
|
import { setStreamingCallback, clearStreamingCallback, publishPlanSubmitted, publishAskUserRequested } from './routing/hook-bridge.js';
|
|
21
23
|
import { maybeNotifyCodexLowUsage } from '../domain/costs/codex-usage-monitor.js';
|
|
22
|
-
import { getAgent
|
|
23
|
-
import {
|
|
24
|
+
import { getAgent } from '../domain/threads/index.js';
|
|
25
|
+
import { runConversation } from './conversation-runner.js';
|
|
24
26
|
import { downloadFiles as downloadPlatformFiles } from './routing/file-handler.js';
|
|
25
27
|
import { WORKSPACE_DIR } from '../core/utils.js';
|
|
26
28
|
const TEMP_DIR = WORKSPACE_DIR;
|
|
@@ -36,8 +38,8 @@ export class AgentRunner {
|
|
|
36
38
|
}
|
|
37
39
|
async route(ctx) {
|
|
38
40
|
const { message, channel, adapter } = ctx;
|
|
39
|
-
if (
|
|
40
|
-
await adapter.
|
|
41
|
+
if (conduitQueues.has(channel)) {
|
|
42
|
+
await adapter.markQueued({ conduit: channel, messageId: message.ref.messageId }).catch(() => { });
|
|
41
43
|
}
|
|
42
44
|
this._track(+1);
|
|
43
45
|
this._enqueue(channel, async () => {
|
|
@@ -50,7 +52,7 @@ export class AgentRunner {
|
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
async _executeReal(ctx) {
|
|
53
|
-
const { message, channel, adapter,
|
|
55
|
+
const { message, channel, adapter, threadAnchorId, hasFiles, userMessage, agentMessage } = ctx;
|
|
54
56
|
const downloadedFiles = await downloadFiles(message.files, hasFiles, adapter);
|
|
55
57
|
const startTime = Date.now();
|
|
56
58
|
const sessionId = await getSessionAsync(channel, resolveBackendForChannel(channel));
|
|
@@ -59,60 +61,54 @@ export class AgentRunner {
|
|
|
59
61
|
// 1. Orchestration side effects (keep — ledger, status, hook-bridge)
|
|
60
62
|
const statusText = buildUserProcessingMessage({ startTime, profileName: getActiveProfile(channel), sessionName, sessionId });
|
|
61
63
|
const blocksTemplate = { channel, sessionName, isDm: true };
|
|
62
|
-
// Post status message WITHOUT Cancel button initially — Cancel is added
|
|
63
|
-
//
|
|
64
|
+
// Post status message WITHOUT Cancel button initially — Cancel is added once runConversation
|
|
65
|
+
// creates the execution record (onExecutionStarted), keyed by executionId (no thread).
|
|
64
66
|
const statusMsg = await adapter.postMessage(dest, {
|
|
65
67
|
text: statusText,
|
|
66
68
|
richBlocks: buildSealedStatusActionBlocks(statusText, blocksTemplate),
|
|
67
|
-
},
|
|
69
|
+
}, threadAnchorId ? { threadId: threadAnchorId } : undefined);
|
|
68
70
|
const messageTs = message.ref.messageId;
|
|
69
71
|
await initTurnTracking(channel, sessionId, sessionName, messageTs, userMessage || '', statusMsg.messageId);
|
|
70
72
|
const onMessagePosted = (ref) => void conversationLedger.addResponseTs(channel, messageTs, ref.messageId).catch((e) => log.error(e));
|
|
71
|
-
// 2.
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// 3. Update status message with Cancel button now that we have thread.id
|
|
80
|
-
const blocksTemplateWithThread = { ...blocksTemplate, threadId: thread.id };
|
|
81
|
-
await adapter.updateMessage(statusMsg, {
|
|
82
|
-
text: statusText,
|
|
83
|
-
richBlocks: buildStatusActionBlocks(statusText, blocksTemplateWithThread),
|
|
84
|
-
}).catch(() => { });
|
|
85
|
-
initStatusBlocks(statusMsg, blocksTemplateWithThread);
|
|
86
|
-
// 4. Build agent callbacks (streaming, fallback, progress — passed to runThread)
|
|
87
|
-
const callbacks = buildAgentCallbacks(adapter, dest, statusMsg, threadTs, startTime, sessionName, sessionId, onMessagePosted);
|
|
88
|
-
// 5. Build PI interactive-event callbacks (plan approval / ask-user-question routing)
|
|
89
|
-
const interactiveCallbacks = buildInteractiveCallbacks(channel, sessionId, thread.id);
|
|
90
|
-
// 6. Call runThread instead of runAgent
|
|
91
|
-
let result;
|
|
73
|
+
// 2. Build agent callbacks (streaming, fallback, progress)
|
|
74
|
+
const callbacks = buildAgentCallbacks(adapter, dest, statusMsg, threadAnchorId, startTime, sessionName, sessionId, onMessagePosted);
|
|
75
|
+
// 3. Build PI interactive-event callbacks (plan approval / ask-user-question routing).
|
|
76
|
+
// No threadId — plain user messages are no longer wrapped in a thread.
|
|
77
|
+
const interactiveCallbacks = buildInteractiveCallbacks(channel, sessionId, null);
|
|
78
|
+
// 4. Run the conversation turn directly (no thread). The Cancel button is attached once the
|
|
79
|
+
// execution record exists (execution-scoped cancel), via onExecutionStarted.
|
|
80
|
+
let capturedExecutionId = null;
|
|
92
81
|
try {
|
|
93
|
-
const
|
|
82
|
+
const convResult = await runConversation({
|
|
94
83
|
adapter, channel,
|
|
95
|
-
|
|
96
|
-
threadTs: threadTs || statusMsg.messageId,
|
|
97
|
-
statusMsg, startTime,
|
|
84
|
+
userMessage: agentMessage,
|
|
98
85
|
existingSessionId: sessionId,
|
|
99
86
|
sessionName,
|
|
100
87
|
files: downloadedFiles,
|
|
88
|
+
startTime,
|
|
89
|
+
trigger: 'user',
|
|
90
|
+
onExecutionStarted: async (executionId) => {
|
|
91
|
+
capturedExecutionId = executionId;
|
|
92
|
+
const blocksTemplateWithExec = { ...blocksTemplate, executionId };
|
|
93
|
+
await adapter.updateMessage(statusMsg, {
|
|
94
|
+
text: statusText,
|
|
95
|
+
richBlocks: buildStatusActionBlocks(statusText, blocksTemplateWithExec),
|
|
96
|
+
}).catch(() => { });
|
|
97
|
+
initStatusBlocks(statusMsg, blocksTemplateWithExec);
|
|
98
|
+
},
|
|
101
99
|
onAssistantMessage: callbacks.onAssistantMsg,
|
|
102
100
|
onProgress: callbacks.onProgress,
|
|
103
101
|
onFallback: callbacks.onFallback,
|
|
104
102
|
onToolUse: composeToolUse(callbacks.onToolUse, interactiveCallbacks.onToolUse),
|
|
105
103
|
onPlanWritten: interactiveCallbacks.onPlanWritten,
|
|
106
104
|
onAskUserQuestion: interactiveCallbacks.onAskUserQuestion,
|
|
107
|
-
isUserInitiated: true,
|
|
108
105
|
});
|
|
109
|
-
result = threadResult.lastAgentResult;
|
|
110
106
|
clearStreamingCallback(channel);
|
|
111
|
-
await maybeNotifyCodexLowUsage({ adapter, result });
|
|
107
|
+
await maybeNotifyCodexLowUsage({ adapter, result: convResult.result });
|
|
112
108
|
await handleDefaultAgentResult({
|
|
113
|
-
result, channel, adapter, statusMsg, startTime, userMessage,
|
|
114
|
-
executionId:
|
|
115
|
-
sessionName, sessionId,
|
|
109
|
+
result: convResult.result, channel, adapter, statusMsg, startTime, userMessage,
|
|
110
|
+
executionId: convResult.executionId,
|
|
111
|
+
sessionName, sessionId, threadAnchorId, messageTs, callbacks,
|
|
116
112
|
});
|
|
117
113
|
}
|
|
118
114
|
catch (error) {
|
|
@@ -120,8 +116,8 @@ export class AgentRunner {
|
|
|
120
116
|
await handleAgentError({
|
|
121
117
|
error: error,
|
|
122
118
|
channel, adapter, statusMsg, startTime,
|
|
123
|
-
executionId:
|
|
124
|
-
sessionName, sessionId,
|
|
119
|
+
executionId: capturedExecutionId,
|
|
120
|
+
sessionName, sessionId, threadAnchorId, userMessageTs: messageTs,
|
|
125
121
|
});
|
|
126
122
|
}
|
|
127
123
|
}
|
|
@@ -148,34 +144,38 @@ export function resolveDefaultAgent(agentMessage, channel) {
|
|
|
148
144
|
pluginDirs: defaultAgentDef?.pluginDirs || null,
|
|
149
145
|
};
|
|
150
146
|
}
|
|
151
|
-
async function handleDefaultAgentResult({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, sessionName, sessionId,
|
|
147
|
+
async function handleDefaultAgentResult({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, sessionName, sessionId, threadAnchorId, messageTs, callbacks }) {
|
|
152
148
|
if (result?.rateLimited) {
|
|
153
149
|
const { elapsedStr } = computeElapsed(startTime);
|
|
154
|
-
const fallbackText =
|
|
150
|
+
const fallbackText = `${Icons.warning} ${buildSessionTag(sessionName, sessionId)}Rate limited — all fallbacks exhausted (${elapsedStr})`;
|
|
155
151
|
await sealStatus(adapter, statusMsg, fallbackText, buildSealedStatusActionBlocks(fallbackText, { channel, sessionName, isDm: true }));
|
|
156
152
|
return;
|
|
157
153
|
}
|
|
158
|
-
await handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger: 'user', sessionName,
|
|
159
|
-
// NOTE: createAutoThread removed — thread was created pre-execution via createDefaultThread
|
|
154
|
+
await handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger: 'user', sessionName, threadAnchorId, userMessageTs: messageTs, onAssistantMessage: callbacks.onAssistantMsg });
|
|
160
155
|
}
|
|
161
|
-
async function resolveSessionName(sessionId, channel, userMessage, adapter) {
|
|
156
|
+
export async function resolveSessionName(sessionId, channel, userMessage, adapter) {
|
|
162
157
|
if (sessionId) {
|
|
163
158
|
const existing = await sessionStore.lookupBySessionId(sessionId);
|
|
164
159
|
if (existing)
|
|
165
160
|
return existing;
|
|
166
|
-
const name = await sessionStore.generateSessionName();
|
|
167
161
|
const channelProject = await adapter.resolveInboundProject(channel);
|
|
168
|
-
|
|
169
|
-
|
|
162
|
+
return registerNamedSession(sessionStore, {
|
|
163
|
+
sessionId,
|
|
164
|
+
channel,
|
|
165
|
+
backend: resolveBackendForChannel(channel),
|
|
166
|
+
label: userMessage?.substring(0, 60),
|
|
167
|
+
profileName: getActiveProfile(channel),
|
|
168
|
+
projectId: channelProject ?? 'general',
|
|
169
|
+
});
|
|
170
170
|
}
|
|
171
171
|
return sessionStore.generateSessionName();
|
|
172
172
|
}
|
|
173
|
-
function buildAgentCallbacks(adapter, destination, statusMsg,
|
|
173
|
+
function buildAgentCallbacks(adapter, destination, statusMsg, threadAnchorId, startTime, sessionName, sessionId, onMessagePosted) {
|
|
174
174
|
const channel = resolveDestinationConduit(destination);
|
|
175
175
|
const onFallback = makeFallbackNotifier(channel, statusMsg, adapter);
|
|
176
176
|
const queue = getOutboundQueue();
|
|
177
177
|
const durable = queue ? buildDurableHooks(queue) : null;
|
|
178
|
-
const baseAssistantMsg = makeStreamingMessageCallback(adapter, destination,
|
|
178
|
+
const baseAssistantMsg = makeStreamingMessageCallback(adapter, destination, threadAnchorId, onMessagePosted, durable);
|
|
179
179
|
// Tool trace: when CORTEX_SHOW_TOOL_CALLS is enabled, emit a compact per-tool Slack line
|
|
180
180
|
// that merges consecutive same-tool calls and splits on different tool / assistant text.
|
|
181
181
|
const toolTrace = createToolTrace(baseAssistantMsg.stream);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-conduit serial Promise queue. Each conduit has at most one tail entry.
|
|
3
|
+
* Consumers may call .has(conduitId) to check whether a queue is already running
|
|
4
|
+
* (e.g. to show a hourglass reaction), and .delete(conduitId) to discard a
|
|
5
|
+
* pending tail (e.g. !cancel).
|
|
6
|
+
*/
|
|
7
|
+
export declare const conduitQueues: Map<string, Promise<void>>;
|
|
8
|
+
/**
|
|
9
|
+
* Append fn to the conduit's serial queue.
|
|
10
|
+
*
|
|
11
|
+
* Returns true if a queue was already running for this conduit when enqueue()
|
|
12
|
+
* was called (useful for showing backpressure indicators). Returns false if
|
|
13
|
+
* this is the first entry for the conduit.
|
|
14
|
+
*
|
|
15
|
+
* The queue entry is automatically removed once fn resolves or rejects, so
|
|
16
|
+
* the Map never accumulates stale entries for completed conduits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function enqueue(conduitId: string, fn: () => Promise<void>): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// input: nothing (leaf module)
|
|
2
|
+
// output: conduitQueues Map + enqueue() — per-conduit serial work queue
|
|
3
|
+
// pos: orch/ layer [S6-B]
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
/**
|
|
6
|
+
* Per-conduit serial Promise queue. Each conduit has at most one tail entry.
|
|
7
|
+
* Consumers may call .has(conduitId) to check whether a queue is already running
|
|
8
|
+
* (e.g. to show a hourglass reaction), and .delete(conduitId) to discard a
|
|
9
|
+
* pending tail (e.g. !cancel).
|
|
10
|
+
*/
|
|
11
|
+
export const conduitQueues = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Append fn to the conduit's serial queue.
|
|
14
|
+
*
|
|
15
|
+
* Returns true if a queue was already running for this conduit when enqueue()
|
|
16
|
+
* was called (useful for showing backpressure indicators). Returns false if
|
|
17
|
+
* this is the first entry for the conduit.
|
|
18
|
+
*
|
|
19
|
+
* The queue entry is automatically removed once fn resolves or rejects, so
|
|
20
|
+
* the Map never accumulates stale entries for completed conduits.
|
|
21
|
+
*/
|
|
22
|
+
export function enqueue(conduitId, fn) {
|
|
23
|
+
const hadExisting = conduitQueues.has(conduitId);
|
|
24
|
+
const prev = conduitQueues.get(conduitId) || Promise.resolve();
|
|
25
|
+
const next = prev.then(fn, fn);
|
|
26
|
+
conduitQueues.set(conduitId, next);
|
|
27
|
+
next.finally(() => {
|
|
28
|
+
if (conduitQueues.get(conduitId) === next)
|
|
29
|
+
conduitQueues.delete(conduitId);
|
|
30
|
+
});
|
|
31
|
+
return hadExisting;
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { PlatformAdapter, DownloadedFile } from '../platform/index.js';
|
|
2
|
+
import type { AgentResult } from '../core/types/agent-types.js';
|
|
3
|
+
export interface RunConversationOptions {
|
|
4
|
+
adapter: PlatformAdapter;
|
|
5
|
+
channel: string;
|
|
6
|
+
/** The raw user message (without the default agent's directive). */
|
|
7
|
+
userMessage: string;
|
|
8
|
+
/** Channel-level session to resume, or null for a fresh session. */
|
|
9
|
+
existingSessionId: string | null;
|
|
10
|
+
/** Resolved session name for this turn. */
|
|
11
|
+
sessionName: string;
|
|
12
|
+
files: DownloadedFile[];
|
|
13
|
+
startTime: number;
|
|
14
|
+
/** Execution trigger; defaults to 'user'. Scheduled session-target dispatch passes 'scheduled'. */
|
|
15
|
+
trigger?: string;
|
|
16
|
+
scheduleTaskId?: string | null;
|
|
17
|
+
/** Profile override for `__active__` agents (used by scheduler). */
|
|
18
|
+
profileOverride?: string | null;
|
|
19
|
+
/** Fired once the execution record is created, before the agent starts — lets the caller
|
|
20
|
+
* attach an execution-scoped Cancel button to the status message. */
|
|
21
|
+
onExecutionStarted?: (executionId: string) => void | Promise<void>;
|
|
22
|
+
onAssistantMessage?: ((text: string) => void) | null;
|
|
23
|
+
onProgress?: ((progress: any) => void) | null;
|
|
24
|
+
onFallback?: ((...args: any[]) => Promise<void>) | null;
|
|
25
|
+
onToolUse?: ((name: string, input: any) => void) | null;
|
|
26
|
+
onPlanWritten?: ((event: {
|
|
27
|
+
path: string;
|
|
28
|
+
content: string;
|
|
29
|
+
toolUseId: string;
|
|
30
|
+
}) => void) | null;
|
|
31
|
+
onAskUserQuestion?: ((event: any) => void) | null;
|
|
32
|
+
}
|
|
33
|
+
export interface ConversationResult {
|
|
34
|
+
result: AgentResult;
|
|
35
|
+
executionId: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Execute a single plain user-conversation turn against the active default agent — no thread,
|
|
39
|
+
* no workspace, no artifact. Mirrors the legacy default-thread branch of runThread() exactly
|
|
40
|
+
* (channel session reuse, useCoreMcp:false, isUserInitiated:true, single step) and the
|
|
41
|
+
* register/complete lifecycle of lifecycle.ts:runRetryAgent.
|
|
42
|
+
*
|
|
43
|
+
* Does NOT catch agent errors: the caller's try/catch (agent-runner._executeReal) invokes
|
|
44
|
+
* handleAgentError, which finalizes the execution record and removes the running-execution
|
|
45
|
+
* entry via runningExecutions.fail(executionId). On success this function removes the entry via
|
|
46
|
+
* runningExecutions.complete(executionId); handleAgentSuccess finalizes the execution record.
|
|
47
|
+
*/
|
|
48
|
+
export declare function runConversation(opts: RunConversationOptions): Promise<ConversationResult>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// input: domain/agents (runAgent + config getters), domain/threads (agent-slot + prompt assembly),
|
|
2
|
+
// domain/executions/registry, core/running-executions, domain/projects
|
|
3
|
+
// output: runConversation — executes a single plain user-conversation turn WITHOUT a thread
|
|
4
|
+
// pos: orch/ — dedicated execution path for plain user messages (replaces the default-thread wrapper)
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
//
|
|
7
|
+
// Why this exists: plain user chat messages used to be wrapped in a `templateName:'default'`
|
|
8
|
+
// ThreadRecord and run through runThread() with ~12 `isDefault` short-circuits. That coupled
|
|
9
|
+
// conversations to the thread machinery (workspace, artifact.md, threads.json) for no benefit —
|
|
10
|
+
// none of the thread concepts (artifact comms, transitions, hooks, multi-agent) apply to a single
|
|
11
|
+
// conversation turn. This module runs the default agent directly via the agent facade. Session
|
|
12
|
+
// continuity (channel session), cost/execution tracking (executionRegistry) and turn tracking
|
|
13
|
+
// (conversation ledger) are all thread-independent and handled by the caller (agent-runner).
|
|
14
|
+
import { runAgent, getClaudeMode, getActiveBackend, getActiveProfile, getDefaultAgent, } from '../domain/agents/index.js';
|
|
15
|
+
import { resolveAgentSlotConfigByName, resolveSystemVars, buildConversationPrompt } from '../domain/threads/index.js';
|
|
16
|
+
import * as executionRegistry from '../domain/executions/registry.js';
|
|
17
|
+
import { projectStore } from '../domain/projects/index.js';
|
|
18
|
+
import { runningExecutions } from '../core/running-executions.js';
|
|
19
|
+
/**
|
|
20
|
+
* Execute a single plain user-conversation turn against the active default agent — no thread,
|
|
21
|
+
* no workspace, no artifact. Mirrors the legacy default-thread branch of runThread() exactly
|
|
22
|
+
* (channel session reuse, useCoreMcp:false, isUserInitiated:true, single step) and the
|
|
23
|
+
* register/complete lifecycle of lifecycle.ts:runRetryAgent.
|
|
24
|
+
*
|
|
25
|
+
* Does NOT catch agent errors: the caller's try/catch (agent-runner._executeReal) invokes
|
|
26
|
+
* handleAgentError, which finalizes the execution record and removes the running-execution
|
|
27
|
+
* entry via runningExecutions.fail(executionId). On success this function removes the entry via
|
|
28
|
+
* runningExecutions.complete(executionId); handleAgentSuccess finalizes the execution record.
|
|
29
|
+
*/
|
|
30
|
+
export async function runConversation(opts) {
|
|
31
|
+
const defaultAgentName = getDefaultAgent() || 'main';
|
|
32
|
+
const agentConfig = resolveAgentSlotConfigByName(defaultAgentName);
|
|
33
|
+
if (!agentConfig)
|
|
34
|
+
throw new Error(`Unknown default agent: ${defaultAgentName}`);
|
|
35
|
+
const prompt = buildConversationPrompt(agentConfig, opts.userMessage);
|
|
36
|
+
const project = projectStore.resolveFromMessage(opts.userMessage)?.id ?? 'general';
|
|
37
|
+
// Resolve profile: hardcoded agent profiles win; __active__ honors the optional override
|
|
38
|
+
// (scheduler) then the channel's active profile.
|
|
39
|
+
const profileName = agentConfig.profile === '__active__'
|
|
40
|
+
? (opts.profileOverride || getActiveProfile(opts.channel))
|
|
41
|
+
: agentConfig.profile;
|
|
42
|
+
const trigger = opts.trigger || 'user';
|
|
43
|
+
const execution = executionRegistry.startLocalExecution({
|
|
44
|
+
kind: trigger === 'scheduled' ? 'scheduled' : 'local',
|
|
45
|
+
channel: opts.channel,
|
|
46
|
+
project,
|
|
47
|
+
trigger,
|
|
48
|
+
backend: getActiveBackend(),
|
|
49
|
+
billingMode: getClaudeMode(),
|
|
50
|
+
sessionId: opts.existingSessionId,
|
|
51
|
+
label: prompt.substring(0, 60),
|
|
52
|
+
scheduleTaskId: opts.scheduleTaskId || null,
|
|
53
|
+
threadId: null,
|
|
54
|
+
agentSlotId: null,
|
|
55
|
+
});
|
|
56
|
+
if (opts.onExecutionStarted)
|
|
57
|
+
await opts.onExecutionStarted(execution.id);
|
|
58
|
+
const handle = runAgent(prompt, {
|
|
59
|
+
channel: opts.channel,
|
|
60
|
+
executionId: execution.id,
|
|
61
|
+
sessionId: opts.existingSessionId,
|
|
62
|
+
sessionKey: null, // falls back to channel key in the adapter
|
|
63
|
+
files: opts.files || [],
|
|
64
|
+
profileName,
|
|
65
|
+
project,
|
|
66
|
+
trigger,
|
|
67
|
+
threadId: null,
|
|
68
|
+
useCoreMcp: false,
|
|
69
|
+
sessionName: opts.sessionName,
|
|
70
|
+
claudeAgent: agentConfig.claudeAgent || null,
|
|
71
|
+
systemPrompt: agentConfig.systemPrompt ? resolveSystemVars(agentConfig.systemPrompt) : null,
|
|
72
|
+
outputStyle: agentConfig.outputStyle || null,
|
|
73
|
+
tools: agentConfig.tools || null,
|
|
74
|
+
pluginDirs: agentConfig.pluginDirs || null,
|
|
75
|
+
onFallback: opts.onFallback ?? null,
|
|
76
|
+
isUserInitiated: true,
|
|
77
|
+
onAssistantMessage: opts.onAssistantMessage,
|
|
78
|
+
onProgress: opts.onProgress,
|
|
79
|
+
onToolUse: opts.onToolUse,
|
|
80
|
+
onPlanWritten: opts.onPlanWritten ?? null,
|
|
81
|
+
onAskUserQuestion: opts.onAskUserQuestion ?? null,
|
|
82
|
+
});
|
|
83
|
+
// Track the handle for cancellation under the channel key (preserves !cancel / supersede /
|
|
84
|
+
// killByKey paths); executionId is indexed too so the Cancel button can resolve it.
|
|
85
|
+
runningExecutions.register({
|
|
86
|
+
threadId: null,
|
|
87
|
+
channel: opts.channel,
|
|
88
|
+
agentSlotId: null,
|
|
89
|
+
executionId: execution.id,
|
|
90
|
+
kind: execution.kind,
|
|
91
|
+
kill: () => handle.kill(),
|
|
92
|
+
backend: getActiveBackend(),
|
|
93
|
+
agentProcess: handle.agentProcess,
|
|
94
|
+
sessionId: handle.sessionId,
|
|
95
|
+
});
|
|
96
|
+
const result = await handle.promise;
|
|
97
|
+
// Finalize the execution here (persistent record + registry teardown + balanced agent.* event)
|
|
98
|
+
// so this function is self-contained and serves both the interactive path (agent-runner) and
|
|
99
|
+
// the scheduler. teardownExecution is idempotent (execution-repo guards terminal status), so the
|
|
100
|
+
// interactive path's later handleAgentSuccess→finalizeLocalExecution call is a harmless no-op.
|
|
101
|
+
const durationS = (Date.now() - opts.startTime) / 1000;
|
|
102
|
+
if (result?.rateLimited) {
|
|
103
|
+
executionRegistry.teardownExecution({ executionId: execution.id, status: 'failed', durationS, error: { message: 'Rate limited' } });
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
executionRegistry.teardownExecution({ executionId: execution.id, status: 'completed', durationS, result });
|
|
107
|
+
}
|
|
108
|
+
return { result, executionId: execution.id };
|
|
109
|
+
}
|