@cortex-agent/server 2026.5.25-1 → 2026.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/config/thread-templates.json +28 -1
- package/defaults/hooks/cortex-md-injector.mjs +47 -31
- package/defaults/hooks/post-task-hook.mjs +6 -0
- package/defaults/hooks/task-status-check.mjs +8 -0
- package/defaults/mcp-config-slack.json +11 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
- package/defaults/prompts/directives/manager.md +67 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
- package/dist/agent-adapter/claude/adapter-tui.js +91 -12
- package/dist/agent-adapter/claude/adapter.js +11 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +30 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
- package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
- package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
- package/dist/agent-adapter/claude/spawn-args.js +49 -7
- package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
- package/dist/agent-adapter/claude/tmux-control.js +54 -8
- package/dist/agent-adapter/codex/adapter.js +1 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
- package/dist/agent-adapter/pi/adapter.js +46 -19
- package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
- package/dist/agent-adapter/pi/agent-dir.js +53 -2
- package/dist/agent-adapter/pi/event-parser.js +13 -1
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
- package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
- package/dist/agent-adapter/pi/tool-shims.js +167 -140
- package/dist/agent-adapter/types.d.ts +7 -2
- package/dist/core/atomic-write.js +21 -0
- package/dist/core/config-generator.d.ts +10 -0
- package/dist/core/config-generator.js +28 -0
- package/dist/core/gateway-generator.d.ts +77 -7
- package/dist/core/gateway-generator.js +301 -29
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -0
- package/dist/core/profile-generator.d.ts +6 -0
- package/dist/core/profile-generator.js +35 -7
- package/dist/core/running-executions.d.ts +51 -41
- package/dist/core/running-executions.js +120 -73
- package/dist/core/status-format.js +3 -2
- package/dist/core/task-parser.d.ts +3 -0
- package/dist/core/task-parser.js +3 -1
- package/dist/core/types/thread-types.d.ts +54 -8
- package/dist/domain/agents/facade.d.ts +18 -0
- package/dist/domain/agents/facade.js +26 -3
- package/dist/domain/agents/profile-manager.d.ts +11 -0
- package/dist/domain/agents/profile-manager.js +21 -2
- package/dist/domain/costs/codex-usage-monitor.js +2 -1
- package/dist/domain/costs/rate-limit-throttle.js +14 -2
- package/dist/domain/executions/registry.d.ts +24 -0
- package/dist/domain/executions/registry.js +38 -0
- package/dist/domain/mcp/core-server.js +15 -3
- package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
- package/dist/domain/mcp/feishu/bitable.js +168 -0
- package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
- package/dist/domain/mcp/feishu/block-types.js +127 -0
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
- package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
- package/dist/domain/mcp/feishu/client.d.ts +46 -0
- package/dist/domain/mcp/feishu/client.js +87 -0
- package/dist/domain/mcp/feishu/docx.d.ts +3 -0
- package/dist/domain/mcp/feishu/docx.js +163 -0
- package/dist/domain/mcp/feishu/drive.d.ts +23 -0
- package/dist/domain/mcp/feishu/drive.js +66 -0
- package/dist/domain/mcp/feishu/file.d.ts +14 -0
- package/dist/domain/mcp/feishu/file.js +107 -0
- package/dist/domain/mcp/feishu/index.d.ts +6 -0
- package/dist/domain/mcp/feishu/index.js +61 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
- package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
- package/dist/domain/mcp/feishu/sheets.js +119 -0
- package/dist/domain/mcp/feishu/types.d.ts +26 -0
- package/dist/domain/mcp/feishu/types.js +38 -0
- package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
- package/dist/domain/mcp/feishu/user-auth.js +286 -0
- package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
- package/dist/domain/mcp/feishu/wiki.js +77 -0
- package/dist/domain/mcp/feishu-server.d.ts +2 -0
- package/dist/domain/mcp/feishu-server.js +33 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +6 -25
- package/dist/domain/mcp/slack-server.d.ts +3 -0
- package/dist/domain/mcp/slack-server.js +46 -0
- package/dist/domain/mcp/tools/context.js +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +1 -1
- package/dist/domain/mcp/tools/schedule.js +6 -20
- package/dist/domain/mcp/tools/slack.js +20 -7
- package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/thread-ops.js +121 -0
- package/dist/domain/mcp/tools/time.d.ts +2 -0
- package/dist/domain/mcp/tools/time.js +66 -0
- package/dist/domain/mcp/tools/tui-ask.js +1 -1
- package/dist/domain/mcp/tools/tui-plan.js +2 -2
- package/dist/domain/mcp/tui-server.js +1 -0
- package/dist/domain/monitor/disk-monitor.js +2 -1
- package/dist/domain/monitor/gpu-monitor.js +2 -1
- package/dist/domain/remote/client-hot-reload.js +3 -2
- package/dist/domain/remote/client-manager.js +8 -6
- package/dist/domain/scheduling/job-registry.d.ts +4 -0
- package/dist/domain/scheduling/job-registry.js +1 -0
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
- package/dist/domain/scheduling/jobs/sync-public.js +4 -3
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
- package/dist/domain/scheduling/jobs/task-archive.js +3 -2
- package/dist/domain/scheduling/jobs/task-dispatch.js +120 -10
- package/dist/domain/scheduling/schedule-command.js +16 -15
- package/dist/domain/scheduling/scheduler.d.ts +1 -1
- package/dist/domain/scheduling/scheduler.js +2 -1
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-hooks.js +19 -18
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
- package/dist/domain/sessions/session-lifecycle.js +44 -0
- package/dist/domain/system/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.js +26 -0
- package/dist/domain/tasks/lint.js +28 -0
- package/dist/domain/tasks/mutator.d.ts +16 -3
- package/dist/domain/tasks/mutator.js +41 -12
- package/dist/domain/tasks/pending-tracker.js +6 -5
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
- package/dist/domain/tasks/system/task-mutations.js +166 -8
- package/dist/domain/threads/contract.d.ts +17 -0
- package/dist/domain/threads/contract.js +59 -0
- package/dist/domain/threads/hook-runner.js +7 -6
- package/dist/domain/threads/index.d.ts +2 -0
- package/dist/domain/threads/index.js +3 -1
- package/dist/domain/threads/prompt-builder.d.ts +15 -1
- package/dist/domain/threads/prompt-builder.js +41 -2
- package/dist/domain/threads/runner.d.ts +6 -5
- package/dist/domain/threads/runner.js +128 -79
- package/dist/domain/threads/state-machine.d.ts +23 -21
- package/dist/domain/threads/state-machine.js +113 -54
- package/dist/domain/threads/template-loader.js +3 -2
- package/dist/domain/threads/tree.d.ts +45 -0
- package/dist/domain/threads/tree.js +171 -0
- package/dist/domain/tui-session/index.d.ts +2 -0
- package/dist/domain/tui-session/index.js +3 -0
- package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
- package/dist/domain/tui-session/tui-session-service.js +103 -0
- package/dist/domain/tui-session/types.d.ts +67 -0
- package/dist/domain/tui-session/types.js +4 -0
- package/dist/domain/ui-service/index.d.ts +5 -0
- package/dist/domain/ui-service/index.js +3 -0
- package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
- package/dist/domain/ui-service/mutate/executions.js +15 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
- package/dist/domain/ui-service/mutate/schedules.js +39 -0
- package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
- package/dist/domain/ui-service/mutate/tasks.js +59 -0
- package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
- package/dist/domain/ui-service/mutate/threads.js +21 -0
- package/dist/domain/ui-service/query/cost.d.ts +3 -0
- package/dist/domain/ui-service/query/cost.js +6 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -0
- package/dist/domain/ui-service/query/executions.js +35 -0
- package/dist/domain/ui-service/query/projects.d.ts +2 -0
- package/dist/domain/ui-service/query/projects.js +30 -0
- package/dist/domain/ui-service/query/schedules.d.ts +2 -0
- package/dist/domain/ui-service/query/schedules.js +23 -0
- package/dist/domain/ui-service/query/sessions.d.ts +2 -0
- package/dist/domain/ui-service/query/sessions.js +35 -0
- package/dist/domain/ui-service/query/tasks.d.ts +2 -0
- package/dist/domain/ui-service/query/tasks.js +30 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -0
- package/dist/domain/ui-service/query/threads.js +27 -0
- package/dist/domain/ui-service/subscribe.d.ts +5 -0
- package/dist/domain/ui-service/subscribe.js +118 -0
- package/dist/domain/ui-service/types.d.ts +237 -0
- package/dist/domain/ui-service/types.js +5 -0
- package/dist/domain/ui-service/ui-service.d.ts +2 -0
- package/dist/domain/ui-service/ui-service.js +83 -0
- package/dist/entry/app.js +94 -5
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +25 -2
- package/dist/entry/init.js +211 -64
- package/dist/events/event-types.d.ts +14 -0
- package/dist/hooks/cortex-md-injector.mjs +47 -31
- package/dist/hooks/post-task-hook.mjs +6 -0
- package/dist/hooks/task-status-check.mjs +8 -0
- package/dist/orchestration/agent-runner.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +55 -55
- package/dist/orchestration/conduit-queue.d.ts +18 -0
- package/dist/orchestration/conduit-queue.js +32 -0
- package/dist/orchestration/conversation-runner.d.ts +48 -0
- package/dist/orchestration/conversation-runner.js +109 -0
- package/dist/orchestration/dispatch-reconciler.js +8 -1
- package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
- package/dist/orchestration/interactions/ask-user-question.js +3 -3
- package/dist/orchestration/interactions/interaction-handlers.js +48 -17
- package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
- package/dist/orchestration/interactions/plan-handler.js +4 -3
- package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +100 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +24 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +39 -47
- package/dist/orchestration/routing/commands/channel.js +24 -11
- package/dist/orchestration/routing/commands/cost.js +2 -1
- package/dist/orchestration/routing/commands/device.js +3 -2
- package/dist/orchestration/routing/commands/dispatch.js +6 -5
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +11 -10
- package/dist/orchestration/routing/commands/mode.js +19 -18
- package/dist/orchestration/routing/commands/nvtop.js +10 -9
- package/dist/orchestration/routing/commands/sendfile.js +7 -6
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +17 -33
- package/dist/orchestration/routing/commands/tail.js +4 -3
- package/dist/orchestration/routing/commands/task.js +4 -3
- package/dist/orchestration/routing/commands/thread-handlers.js +16 -6
- package/dist/orchestration/routing/edit-handler.js +8 -7
- package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
- package/dist/orchestration/routing/message-router.d.ts +1 -1
- package/dist/orchestration/routing/message-router.js +9 -9
- package/dist/orchestration/routing/webhook.js +233 -2
- package/dist/orchestration/status-helpers.d.ts +5 -1
- package/dist/orchestration/status-helpers.js +7 -6
- package/dist/orchestration/thread-callback.d.ts +67 -0
- package/dist/orchestration/thread-callback.js +465 -0
- package/dist/orchestration/thread-executor.d.ts +22 -1
- package/dist/orchestration/thread-executor.js +85 -36
- package/dist/platform/adapter.d.ts +6 -2
- package/dist/platform/adapters/composite-adapter.d.ts +89 -0
- package/dist/platform/adapters/composite-adapter.js +318 -0
- package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
- package/dist/platform/adapters/feishu-output-stream.js +274 -36
- package/dist/platform/adapters/feishu.d.ts +50 -5
- package/dist/platform/adapters/feishu.js +370 -116
- package/dist/platform/adapters/index.d.ts +24 -3
- package/dist/platform/adapters/index.js +89 -11
- package/dist/platform/adapters/project-conduits.d.ts +9 -0
- package/dist/platform/adapters/project-conduits.js +42 -0
- package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
- package/dist/platform/adapters/slack-project-conduits.js +6 -40
- package/dist/platform/adapters/slack.d.ts +9 -2
- package/dist/platform/adapters/slack.js +83 -39
- package/dist/platform/adapters/tui/index.d.ts +9 -0
- package/dist/platform/adapters/tui/index.js +10 -0
- package/dist/platform/adapters/tui/ports.d.ts +20 -0
- package/dist/platform/adapters/tui/ports.js +4 -0
- package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
- package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
- package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
- package/dist/platform/adapters/tui/tui-connection.js +53 -0
- package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
- package/dist/platform/adapters/tui/tui-gateway.js +919 -0
- package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
- package/dist/platform/adapters/tui/tui-notifications.js +60 -0
- package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
- package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
- package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
- package/dist/platform/adapters/tui/tui-transcript.js +56 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +2 -1
- package/dist/platform/interactive-builder.js +3 -2
- package/dist/platform/output-stream.d.ts +5 -0
- package/dist/platform/testing.d.ts +7 -11
- package/dist/platform/testing.js +18 -15
- package/dist/platform/tool-trace.js +15 -5
- package/dist/platform/tui/protocol.d.ts +355 -0
- package/dist/platform/tui/protocol.js +199 -0
- package/dist/platform/types.d.ts +12 -3
- package/dist/store/execution-repo.d.ts +6 -1
- package/dist/store/execution-repo.js +13 -3
- package/dist/store/hook-sync.d.ts +18 -0
- package/dist/store/hook-sync.js +92 -0
- package/dist/store/outbound-queue.js +2 -2
- package/dist/store/profile-repo.js +3 -2
- package/dist/store/schedule-repo.d.ts +1 -8
- package/dist/store/session-registry-repo.d.ts +9 -1
- package/dist/store/session-registry-repo.js +19 -3
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +23 -0
- package/dist/store/thread-repo.d.ts +3 -0
- package/dist/store/thread-repo.js +49 -2
- package/dist/store/version-migrations.js +95 -0
- package/dist/tui/App.d.ts +27 -0
- package/dist/tui/App.js +219 -0
- package/dist/tui/components/AskUserModal.d.ts +11 -0
- package/dist/tui/components/AskUserModal.js +364 -0
- package/dist/tui/components/ConfirmModal.d.ts +12 -0
- package/dist/tui/components/ConfirmModal.js +31 -0
- package/dist/tui/components/Dashboard.d.ts +23 -0
- package/dist/tui/components/Dashboard.js +80 -0
- package/dist/tui/components/DashboardCostTab.d.ts +7 -0
- package/dist/tui/components/DashboardCostTab.js +16 -0
- package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
- package/dist/tui/components/DashboardExecutionsTab.js +94 -0
- package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
- package/dist/tui/components/DashboardSchedulesTab.js +124 -0
- package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
- package/dist/tui/components/DashboardTasksTab.js +200 -0
- package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
- package/dist/tui/components/DashboardThreadsTab.js +81 -0
- package/dist/tui/components/Header.d.ts +11 -0
- package/dist/tui/components/Header.js +5 -0
- package/dist/tui/components/InputBox.d.ts +10 -0
- package/dist/tui/components/InputBox.js +19 -0
- package/dist/tui/components/MessageRow.d.ts +7 -0
- package/dist/tui/components/MessageRow.js +10 -0
- package/dist/tui/components/Notifications.d.ts +19 -0
- package/dist/tui/components/Notifications.js +72 -0
- package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
- package/dist/tui/components/PlanFeedbackModal.js +161 -0
- package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
- package/dist/tui/components/ProjectSwitcher.js +43 -0
- package/dist/tui/components/SessionPicker.d.ts +14 -0
- package/dist/tui/components/SessionPicker.js +34 -0
- package/dist/tui/components/SidePanel.d.ts +19 -0
- package/dist/tui/components/SidePanel.js +8 -0
- package/dist/tui/components/StatusLine.d.ts +10 -0
- package/dist/tui/components/StatusLine.js +29 -0
- package/dist/tui/components/Transcript.d.ts +13 -0
- package/dist/tui/components/Transcript.js +56 -0
- package/dist/tui/hooks/useDashboardData.d.ts +32 -0
- package/dist/tui/hooks/useDashboardData.js +104 -0
- package/dist/tui/hooks/useKeybindings.d.ts +19 -0
- package/dist/tui/hooks/useKeybindings.js +87 -0
- package/dist/tui/hooks/useMutate.d.ts +22 -0
- package/dist/tui/hooks/useMutate.js +56 -0
- package/dist/tui/hooks/useNotifications.d.ts +28 -0
- package/dist/tui/hooks/useNotifications.js +70 -0
- package/dist/tui/hooks/useTranscript.d.ts +39 -0
- package/dist/tui/hooks/useTranscript.js +265 -0
- package/dist/tui/hooks/useWsClient.d.ts +29 -0
- package/dist/tui/hooks/useWsClient.js +69 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +210 -0
- package/dist/tui/logic.d.ts +16 -0
- package/dist/tui/logic.js +49 -0
- package/dist/tui/render/markdown.d.ts +10 -0
- package/dist/tui/render/markdown.js +38 -0
- package/dist/tui/render/rich-blocks.d.ts +11 -0
- package/dist/tui/render/rich-blocks.js +24 -0
- package/dist/tui/ws-client.d.ts +44 -0
- package/dist/tui/ws-client.js +157 -0
- package/package.json +11 -3
- package/dist/orchestration/channel-queue.d.ts +0 -18
- package/dist/orchestration/channel-queue.js +0 -32
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// input: none (pure regex transforms)
|
|
2
|
+
// output: Minimal markdown renderer: bold/italic/code/links
|
|
3
|
+
// pos: RichBlock handles full structural formatting; this handles inline markdown within text
|
|
4
|
+
/**
|
|
5
|
+
* Parse inline markdown into typed segments.
|
|
6
|
+
* Supports: **bold**, *italic*, `code`, [text](url)
|
|
7
|
+
*/
|
|
8
|
+
export function parseMarkdown(text) {
|
|
9
|
+
const segments = [];
|
|
10
|
+
let remaining = text;
|
|
11
|
+
const regex = /(\*\*(.+?)\*\*)|(\*(.+?)\*)|(`(.+?)`)|(\[(.+?)\]\((.+?)\))/g;
|
|
12
|
+
let lastIndex = 0;
|
|
13
|
+
let match;
|
|
14
|
+
while ((match = regex.exec(remaining)) !== null) {
|
|
15
|
+
// Text before this match
|
|
16
|
+
if (match.index > lastIndex) {
|
|
17
|
+
segments.push({ type: 'text', text: remaining.slice(lastIndex, match.index) });
|
|
18
|
+
}
|
|
19
|
+
if (match[2] !== undefined) {
|
|
20
|
+
segments.push({ type: 'bold', text: match[2] });
|
|
21
|
+
}
|
|
22
|
+
else if (match[4] !== undefined) {
|
|
23
|
+
segments.push({ type: 'italic', text: match[4] });
|
|
24
|
+
}
|
|
25
|
+
else if (match[6] !== undefined) {
|
|
26
|
+
segments.push({ type: 'code', text: match[6] });
|
|
27
|
+
}
|
|
28
|
+
else if (match[8] !== undefined) {
|
|
29
|
+
segments.push({ type: 'link', text: match[8], url: match[9] });
|
|
30
|
+
}
|
|
31
|
+
lastIndex = match.index + match[0].length;
|
|
32
|
+
}
|
|
33
|
+
// Remaining text
|
|
34
|
+
if (lastIndex < remaining.length) {
|
|
35
|
+
segments.push({ type: 'text', text: remaining.slice(lastIndex) });
|
|
36
|
+
}
|
|
37
|
+
return segments;
|
|
38
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface RichBlocksProps {
|
|
3
|
+
blocks: Array<{
|
|
4
|
+
type: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
/** Render a RichBlock[] array into Ink elements */
|
|
10
|
+
export declare function RichBlocks({ blocks }: RichBlocksProps): React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
/** Render a RichBlock[] array into Ink elements */
|
|
4
|
+
export function RichBlocks({ blocks }) {
|
|
5
|
+
return (_jsx(Box, { flexDirection: "column", children: blocks.map((block, i) => (_jsx(RichBlockItem, { block: block }, i))) }));
|
|
6
|
+
}
|
|
7
|
+
function RichBlockItem({ block }) {
|
|
8
|
+
switch (block.type) {
|
|
9
|
+
case 'markdown':
|
|
10
|
+
return _jsx(Text, { children: String(block.text ?? '') });
|
|
11
|
+
case 'section':
|
|
12
|
+
return _jsx(Text, { children: String(block.text ?? '') });
|
|
13
|
+
case 'context':
|
|
14
|
+
return _jsx(Text, { dimColor: true, children: String(block.text ?? '') });
|
|
15
|
+
case 'divider':
|
|
16
|
+
return _jsx(Text, { dimColor: true, children: '─'.repeat(40) });
|
|
17
|
+
case 'actions': {
|
|
18
|
+
const elements = block.elements ?? [];
|
|
19
|
+
return _jsx(Text, { dimColor: true, children: elements.map(e => `[${e.text}]`).join(' ') });
|
|
20
|
+
}
|
|
21
|
+
default:
|
|
22
|
+
return _jsx(Text, { children: String(block.text ?? '') });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { TuiFrame, HandshakeHello, HandshakeAck } from '../platform/tui/protocol.js';
|
|
2
|
+
export type WsState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
|
|
3
|
+
export interface WsClientOpts {
|
|
4
|
+
/** Client version string sent in handshake.hello */
|
|
5
|
+
clientVersion: string;
|
|
6
|
+
/** Optional project for initial handshake */
|
|
7
|
+
project?: string | null;
|
|
8
|
+
/** Called on successful connection after handshake.ack */
|
|
9
|
+
onConnected?: (ack: HandshakeAck) => void;
|
|
10
|
+
/** Called for every parsed frame received */
|
|
11
|
+
onFrame?: (frame: TuiFrame) => void;
|
|
12
|
+
/** Called when connection closes or fails */
|
|
13
|
+
onClose?: (reason: string) => void;
|
|
14
|
+
/** Called when state changes */
|
|
15
|
+
onStateChange?: (state: WsState) => void;
|
|
16
|
+
/** Called when the exponential backoff cap is exceeded (all attempts exhausted) */
|
|
17
|
+
onCapExceeded?: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare class WsClient {
|
|
20
|
+
private _ws;
|
|
21
|
+
private _address;
|
|
22
|
+
private _opts;
|
|
23
|
+
private _state;
|
|
24
|
+
private _lastSessionId;
|
|
25
|
+
private _retryCount;
|
|
26
|
+
private _retryTimer;
|
|
27
|
+
private _closed;
|
|
28
|
+
private _sendBuffer;
|
|
29
|
+
/** Latest handshake ack data */
|
|
30
|
+
private _ack;
|
|
31
|
+
get state(): WsState;
|
|
32
|
+
get lastSessionId(): string | null;
|
|
33
|
+
get ack(): HandshakeAck | null;
|
|
34
|
+
connect(address: string, opts?: WsClientOpts): void;
|
|
35
|
+
private _doConnect;
|
|
36
|
+
send(frame: TuiFrame): void;
|
|
37
|
+
markAck(ack: HandshakeAck): void;
|
|
38
|
+
markSessionId(id: string): void;
|
|
39
|
+
markConnected(): void;
|
|
40
|
+
private _scheduleReconnect;
|
|
41
|
+
close(): void;
|
|
42
|
+
private _setState;
|
|
43
|
+
}
|
|
44
|
+
export declare function createHandshakeHello(clientVersion: string, resume?: string | null, project?: string | null): HandshakeHello;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// input: src/platform/tui/protocol.js
|
|
2
|
+
// output: Typed WebSocket client wrapping M4 protocol — connect, frame I/O via parseFrame/encodeFrame, reconnect with exponential backoff
|
|
3
|
+
// pos: Foundation for M5 Ink client; zero UI dependency, testable outside React
|
|
4
|
+
import WebSocket from 'ws';
|
|
5
|
+
import { parseFrame, encodeFrame } from '../platform/tui/protocol.js';
|
|
6
|
+
// ── Constants ──
|
|
7
|
+
const BACKOFF_MS = [250, 500, 1000, 2000, 4000, 8000]; // then 30_000 cap
|
|
8
|
+
const BACKOFF_CAP_MS = 30_000;
|
|
9
|
+
// ── Client ──
|
|
10
|
+
export class WsClient {
|
|
11
|
+
_ws = null;
|
|
12
|
+
_address = '';
|
|
13
|
+
_opts = { clientVersion: 'unknown' };
|
|
14
|
+
_state = 'disconnected';
|
|
15
|
+
_lastSessionId = null;
|
|
16
|
+
_retryCount = 0;
|
|
17
|
+
_retryTimer = null;
|
|
18
|
+
_closed = false; // intentional close — don't reconnect
|
|
19
|
+
_sendBuffer = []; // queued frames while connecting
|
|
20
|
+
/** Latest handshake ack data */
|
|
21
|
+
_ack = null;
|
|
22
|
+
get state() { return this._state; }
|
|
23
|
+
get lastSessionId() { return this._lastSessionId; }
|
|
24
|
+
get ack() { return this._ack; }
|
|
25
|
+
// ── Connection ──
|
|
26
|
+
connect(address, opts = { clientVersion: 'unknown' }) {
|
|
27
|
+
this._address = address;
|
|
28
|
+
this._opts = opts;
|
|
29
|
+
this._closed = false;
|
|
30
|
+
this._retryCount = 0;
|
|
31
|
+
this._doConnect();
|
|
32
|
+
}
|
|
33
|
+
_doConnect() {
|
|
34
|
+
if (this._closed)
|
|
35
|
+
return;
|
|
36
|
+
this._setState('connecting');
|
|
37
|
+
this._ws = new WebSocket(this._address);
|
|
38
|
+
this._ws.on('open', () => {
|
|
39
|
+
this._retryCount = 0;
|
|
40
|
+
// Send handshake.hello on every connection (initial + reconnect)
|
|
41
|
+
const hello = {
|
|
42
|
+
type: 'handshake.hello',
|
|
43
|
+
protocolVersion: 1,
|
|
44
|
+
clientName: 'cortex-tui',
|
|
45
|
+
clientVersion: this._opts.clientVersion,
|
|
46
|
+
};
|
|
47
|
+
if (this._lastSessionId)
|
|
48
|
+
hello.resume = { sessionId: this._lastSessionId };
|
|
49
|
+
if (this._opts.project)
|
|
50
|
+
hello.project = this._opts.project;
|
|
51
|
+
this._ws.send(encodeFrame(hello));
|
|
52
|
+
// Flush buffered frames
|
|
53
|
+
const buf = this._sendBuffer;
|
|
54
|
+
this._sendBuffer = [];
|
|
55
|
+
for (const frame of buf) {
|
|
56
|
+
this._ws.send(encodeFrame(frame));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this._ws.on('message', (data) => {
|
|
60
|
+
const raw = data.toString('utf-8');
|
|
61
|
+
const frame = parseFrame(raw);
|
|
62
|
+
if (frame === null)
|
|
63
|
+
return; // ignore malformed frames
|
|
64
|
+
this._opts.onFrame?.(frame);
|
|
65
|
+
});
|
|
66
|
+
this._ws.on('close', (code, reason) => {
|
|
67
|
+
this._ws = null;
|
|
68
|
+
const reasonStr = reason.toString('utf-8') || `code=${code}`;
|
|
69
|
+
if (this._state === 'connected') {
|
|
70
|
+
// Unexpected disconnect — reconnect
|
|
71
|
+
this._scheduleReconnect(reasonStr);
|
|
72
|
+
}
|
|
73
|
+
else if (this._state === 'connecting') {
|
|
74
|
+
// Connection failed — retry
|
|
75
|
+
this._scheduleReconnect(reasonStr);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
this._ws.on('error', () => {
|
|
79
|
+
// Error event is followed by close, so we handle cleanup in on('close')
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// ── Sending ──
|
|
83
|
+
send(frame) {
|
|
84
|
+
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
|
85
|
+
this._ws.send(encodeFrame(frame));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Buffer for sending once connection opens
|
|
89
|
+
this._sendBuffer.push(frame);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// ── Handshake helpers ──
|
|
93
|
+
markAck(ack) {
|
|
94
|
+
this._ack = ack;
|
|
95
|
+
}
|
|
96
|
+
markSessionId(id) {
|
|
97
|
+
this._lastSessionId = id;
|
|
98
|
+
}
|
|
99
|
+
markConnected() {
|
|
100
|
+
this._setState('connected');
|
|
101
|
+
}
|
|
102
|
+
// ── Reconnect ──
|
|
103
|
+
_scheduleReconnect(reason) {
|
|
104
|
+
if (this._closed)
|
|
105
|
+
return;
|
|
106
|
+
this._setState('reconnecting');
|
|
107
|
+
this._opts.onClose?.(reason);
|
|
108
|
+
const delay = this._retryCount < BACKOFF_MS.length
|
|
109
|
+
? BACKOFF_MS[this._retryCount]
|
|
110
|
+
: BACKOFF_CAP_MS;
|
|
111
|
+
this._retryCount++;
|
|
112
|
+
// Check cap exceeded — settle into a terminal 'disconnected' state so the UI
|
|
113
|
+
// shows the retry hint instead of spinning on 'reconnecting' forever.
|
|
114
|
+
if (this._retryCount > BACKOFF_MS.length + 3) {
|
|
115
|
+
this._setState('disconnected');
|
|
116
|
+
this._opts.onCapExceeded?.();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this._retryTimer = setTimeout(() => {
|
|
120
|
+
this._retryTimer = null;
|
|
121
|
+
this._doConnect();
|
|
122
|
+
}, delay);
|
|
123
|
+
}
|
|
124
|
+
// ── Close ──
|
|
125
|
+
close() {
|
|
126
|
+
this._closed = true;
|
|
127
|
+
if (this._retryTimer !== null) {
|
|
128
|
+
clearTimeout(this._retryTimer);
|
|
129
|
+
this._retryTimer = null;
|
|
130
|
+
}
|
|
131
|
+
if (this._ws) {
|
|
132
|
+
this._ws.close();
|
|
133
|
+
this._ws = null;
|
|
134
|
+
}
|
|
135
|
+
this._setState('disconnected');
|
|
136
|
+
}
|
|
137
|
+
// ── Internal ──
|
|
138
|
+
_setState(state) {
|
|
139
|
+
if (this._state !== state) {
|
|
140
|
+
this._state = state;
|
|
141
|
+
this._opts.onStateChange?.(state);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function createHandshakeHello(clientVersion, resume, project) {
|
|
146
|
+
const hello = {
|
|
147
|
+
type: 'handshake.hello',
|
|
148
|
+
protocolVersion: 1,
|
|
149
|
+
clientName: 'cortex-tui',
|
|
150
|
+
clientVersion,
|
|
151
|
+
};
|
|
152
|
+
if (resume)
|
|
153
|
+
hello.resume = { sessionId: resume };
|
|
154
|
+
if (project)
|
|
155
|
+
hello.project = project;
|
|
156
|
+
return hello;
|
|
157
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortex-agent/server",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.6.11",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"description": "Autonomous agent system for long-running projects — mission-driven, multi-agent pipelines, self-evolving skills.",
|
|
6
7
|
"engines": {
|
|
7
8
|
"node": ">=20.0.0"
|
|
@@ -29,16 +30,21 @@
|
|
|
29
30
|
"test": "bash scripts/run-tests.sh",
|
|
30
31
|
"test:quick": "bash scripts/run-tests.sh --quick",
|
|
31
32
|
"test:integration": "node --import tsx --test tests/integration-init-startup.test.ts",
|
|
32
|
-
"
|
|
33
|
+
"test:file": "node --import tsx --import ./tests/_test-home.ts --test",
|
|
34
|
+
"depcruise": "npx depcruise src --validate",
|
|
35
|
+
"lint:no-slack-shortcodes": "node --import tsx scripts/lint-no-slack-shortcodes.ts"
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
38
|
"@clack/prompts": "^1.3.0",
|
|
36
39
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
37
40
|
"@slack/bolt": "^4.6.0",
|
|
38
41
|
"@slack/web-api": "^7.14.1",
|
|
39
|
-
"aistatus": "^0.0.
|
|
42
|
+
"aistatus": "^0.0.7",
|
|
40
43
|
"diff": "^7.0.0",
|
|
41
44
|
"dotenv": "^16.4.7",
|
|
45
|
+
"ink": "^5.2.1",
|
|
46
|
+
"ink-text-input": "^6.0.0",
|
|
47
|
+
"react": "^18.3.1",
|
|
42
48
|
"ws": "^8.20.0",
|
|
43
49
|
"yaml": "^2.8.3"
|
|
44
50
|
},
|
|
@@ -49,8 +55,10 @@
|
|
|
49
55
|
"devDependencies": {
|
|
50
56
|
"@sinclair/typebox": "^0.34.49",
|
|
51
57
|
"@types/diff": "^7.0.2",
|
|
58
|
+
"@types/react": "^18.3.29",
|
|
52
59
|
"@types/ws": "^8.18.1",
|
|
53
60
|
"dependency-cruiser": "^17.3.10",
|
|
61
|
+
"ink-testing-library": "^4.0.0",
|
|
54
62
|
"tsc-alias": "^1.8.0",
|
|
55
63
|
"tsx": "^4.21.0",
|
|
56
64
|
"typescript": "^5.9.3"
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-channel serial Promise queue. Each channel has at most one tail entry.
|
|
3
|
-
* Consumers may call .has(channel) to check whether a queue is already running
|
|
4
|
-
* (e.g. to show a hourglass reaction), and .delete(channel) to discard a
|
|
5
|
-
* pending tail (e.g. !cancel).
|
|
6
|
-
*/
|
|
7
|
-
export declare const channelQueues: Map<string, Promise<void>>;
|
|
8
|
-
/**
|
|
9
|
-
* Append fn to the channel's serial queue.
|
|
10
|
-
*
|
|
11
|
-
* Returns true if a queue was already running for this channel when enqueue()
|
|
12
|
-
* was called (useful for showing backpressure indicators). Returns false if
|
|
13
|
-
* this is the first entry for the channel.
|
|
14
|
-
*
|
|
15
|
-
* The queue entry is automatically removed once fn resolves or rejects, so
|
|
16
|
-
* the Map never accumulates stale entries for completed channels.
|
|
17
|
-
*/
|
|
18
|
-
export declare function enqueue(channel: string, fn: () => Promise<void>): boolean;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// input: nothing (leaf module)
|
|
2
|
-
// output: channelQueues Map + enqueue() — per-channel 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-channel serial Promise queue. Each channel has at most one tail entry.
|
|
7
|
-
* Consumers may call .has(channel) to check whether a queue is already running
|
|
8
|
-
* (e.g. to show a hourglass reaction), and .delete(channel) to discard a
|
|
9
|
-
* pending tail (e.g. !cancel).
|
|
10
|
-
*/
|
|
11
|
-
export const channelQueues = new Map();
|
|
12
|
-
/**
|
|
13
|
-
* Append fn to the channel's serial queue.
|
|
14
|
-
*
|
|
15
|
-
* Returns true if a queue was already running for this channel when enqueue()
|
|
16
|
-
* was called (useful for showing backpressure indicators). Returns false if
|
|
17
|
-
* this is the first entry for the channel.
|
|
18
|
-
*
|
|
19
|
-
* The queue entry is automatically removed once fn resolves or rejects, so
|
|
20
|
-
* the Map never accumulates stale entries for completed channels.
|
|
21
|
-
*/
|
|
22
|
-
export function enqueue(channel, fn) {
|
|
23
|
-
const hadExisting = channelQueues.has(channel);
|
|
24
|
-
const prev = channelQueues.get(channel) || Promise.resolve();
|
|
25
|
-
const next = prev.then(fn, fn);
|
|
26
|
-
channelQueues.set(channel, next);
|
|
27
|
-
next.finally(() => {
|
|
28
|
-
if (channelQueues.get(channel) === next)
|
|
29
|
-
channelQueues.delete(channel);
|
|
30
|
-
});
|
|
31
|
-
return hadExisting;
|
|
32
|
-
}
|