@cortex-agent/server 2026.5.25 → 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/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.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,92 @@
|
|
|
1
|
+
// input: DEFAULTS_DIR/hooks/*.mjs (version-stamped) + HOOKS_DIR (DATA_DIR/hooks)
|
|
2
|
+
// output: syncManagedHooks() — refreshes a deployed hook when the shipped default is newer
|
|
3
|
+
// pos: Startup asset-sync sibling to runMigrations; keeps DATA_DIR/hooks in sync with defaults.
|
|
4
|
+
// init.ts deployHooks() uses safeCopy (copy-if-missing) so an existing hook is NEVER
|
|
5
|
+
// refreshed on upgrade — code-level hook fixes would never reach an existing install.
|
|
6
|
+
// This closes that gap for *managed* (version-stamped) hooks.
|
|
7
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
8
|
+
import * as fs from 'node:fs/promises';
|
|
9
|
+
import { existsSync } from 'node:fs';
|
|
10
|
+
import * as path from 'node:path';
|
|
11
|
+
import { DEFAULTS_DIR, HOOKS_DIR } from '../core/paths.js';
|
|
12
|
+
import { atomicWrite } from '../core/atomic-write.js';
|
|
13
|
+
import { compareCalVer } from './version-migrations.js';
|
|
14
|
+
import { createLogger } from '../core/log.js';
|
|
15
|
+
const log = createLogger('hook-sync');
|
|
16
|
+
// A managed hook declares its version in a header comment:
|
|
17
|
+
// // @cortex-hook-version 2026.6.4
|
|
18
|
+
// Set it to the current release version (agent-server/package.json / CORTEX_VERSION) whenever you
|
|
19
|
+
// change the hook, so an existing install gets the new code on next startup.
|
|
20
|
+
const VERSION_MARKER_RE = /@cortex-hook-version\s+(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/;
|
|
21
|
+
/** Parse the @cortex-hook-version stamp from hook source, or null if absent/malformed. */
|
|
22
|
+
export function parseHookVersion(src) {
|
|
23
|
+
const m = src.match(VERSION_MARKER_RE);
|
|
24
|
+
return m ? m[1] : null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Keep version-stamped hooks in HOOKS_DIR in sync with the shipped defaults.
|
|
28
|
+
*
|
|
29
|
+
* A default hook that carries an `// @cortex-hook-version YYYY.M.D` stamp is (re)written into
|
|
30
|
+
* HOOKS_DIR whenever the shipped stamp is newer than the deployed one. A missing or unstamped
|
|
31
|
+
* deployed copy counts as oldest, so legacy installs are brought under management on first run.
|
|
32
|
+
* Unmanaged defaults (no stamp) are left to init's copy-if-missing (deployHooks/safeCopy) and are
|
|
33
|
+
* never touched here. Idempotent and crash-safe via atomicWrite.
|
|
34
|
+
*
|
|
35
|
+
* `opts` exists for tests; production calls it with no args (real DEFAULTS_DIR/HOOKS_DIR).
|
|
36
|
+
* Returns the list of hook filenames that were updated.
|
|
37
|
+
*/
|
|
38
|
+
export async function syncManagedHooks(opts = {}) {
|
|
39
|
+
const srcDir = opts.srcDir ?? path.join(DEFAULTS_DIR, 'hooks');
|
|
40
|
+
const dstDir = opts.dstDir ?? HOOKS_DIR;
|
|
41
|
+
if (!existsSync(srcDir))
|
|
42
|
+
return [];
|
|
43
|
+
let files;
|
|
44
|
+
try {
|
|
45
|
+
files = await fs.readdir(srcDir);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
await fs.mkdir(dstDir, { recursive: true });
|
|
51
|
+
const updated = [];
|
|
52
|
+
for (const file of files) {
|
|
53
|
+
if (!file.endsWith('.mjs'))
|
|
54
|
+
continue;
|
|
55
|
+
let srcContent;
|
|
56
|
+
try {
|
|
57
|
+
srcContent = await fs.readFile(path.join(srcDir, file), 'utf8');
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const srcVer = parseHookVersion(srcContent);
|
|
63
|
+
if (!srcVer)
|
|
64
|
+
continue; // unmanaged default → leave to init's copy-if-missing
|
|
65
|
+
const dstPath = path.join(dstDir, file);
|
|
66
|
+
if (existsSync(dstPath)) {
|
|
67
|
+
let dstVer = null;
|
|
68
|
+
try {
|
|
69
|
+
dstVer = parseHookVersion(await fs.readFile(dstPath, 'utf8'));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
dstVer = null;
|
|
73
|
+
}
|
|
74
|
+
// Deployed copy already at or ahead of the shipped version → current; skip.
|
|
75
|
+
// An unstamped deployed copy (dstVer === null) counts as oldest → refresh it.
|
|
76
|
+
if (dstVer && compareCalVer(dstVer, srcVer) >= 0)
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await atomicWrite(dstPath, srcContent);
|
|
81
|
+
updated.push(file);
|
|
82
|
+
log.info(`synced hook ${file} → ${srcVer}`);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
log.error(`failed to sync hook ${file}: ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (updated.length === 0) {
|
|
89
|
+
log.info('managed hooks up to date');
|
|
90
|
+
}
|
|
91
|
+
return updated;
|
|
92
|
+
}
|
|
@@ -128,7 +128,7 @@ export class OutboundQueue {
|
|
|
128
128
|
}
|
|
129
129
|
else {
|
|
130
130
|
try {
|
|
131
|
-
await this.adapter.updateMessage({
|
|
131
|
+
await this.adapter.updateMessage({ conduit: entry.channel, messageId: entry.messageId }, { text: entry.text, ...(entry.richBlocks && { richBlocks: entry.richBlocks }) });
|
|
132
132
|
await this.markSent(entry.id);
|
|
133
133
|
}
|
|
134
134
|
catch {
|
|
@@ -255,7 +255,7 @@ export async function durablePost(queue, sender, destination, content, opts) {
|
|
|
255
255
|
export async function durableUpdate(queue, sender, ref, content) {
|
|
256
256
|
const walId = await queue.enqueue({
|
|
257
257
|
type: 'update',
|
|
258
|
-
channel: ref.
|
|
258
|
+
channel: ref.conduit,
|
|
259
259
|
messageId: ref.messageId,
|
|
260
260
|
text: content.text,
|
|
261
261
|
richBlocks: content.richBlocks,
|
|
@@ -14,6 +14,7 @@ import * as path from 'path';
|
|
|
14
14
|
import { JsonRepository } from '../core/json-repository.js';
|
|
15
15
|
import { CONFIG_DIR } from '../core/paths.js';
|
|
16
16
|
import { createLogger } from '../core/log.js';
|
|
17
|
+
import { Icons } from '../core/icons.js';
|
|
17
18
|
const log = createLogger('profile-repo');
|
|
18
19
|
export const PROFILES_FILE = path.join(CONFIG_DIR, 'profiles.json');
|
|
19
20
|
export class ProfileRepo {
|
|
@@ -98,11 +99,11 @@ export function startProfileWatcher(repo = profileRepo, filePath = PROFILES_FILE
|
|
|
98
99
|
repo.invalidate();
|
|
99
100
|
repo.readSync(); // re-fill cache from the validated content
|
|
100
101
|
log.info('Hot-reload: profiles.json reloaded');
|
|
101
|
-
_adminNotifier?.(
|
|
102
|
+
_adminNotifier?.(`${Icons.refresh} \`profiles.json\` hot-reloaded`);
|
|
102
103
|
}
|
|
103
104
|
catch (e) {
|
|
104
105
|
log.error(`Hot-reload profiles.json failed: ${e.message} — keeping previous config`);
|
|
105
|
-
_adminNotifier?.(
|
|
106
|
+
_adminNotifier?.(`${Icons.warning} \`profiles.json\` hot-reload FAILED — keeping previous config`);
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
const setup = () => {
|
|
@@ -12,13 +12,6 @@ export type ScheduleTarget = {
|
|
|
12
12
|
kind: 'project';
|
|
13
13
|
projectId: string;
|
|
14
14
|
}
|
|
15
|
-
/** Fire into a specific cortex-XXXX session, reusing its sessionId. Channel+sessionId are locked at create time. */
|
|
16
|
-
| {
|
|
17
|
-
kind: 'session';
|
|
18
|
-
sessionName: string;
|
|
19
|
-
sessionId: string;
|
|
20
|
-
channel: string;
|
|
21
|
-
}
|
|
22
15
|
/** Continue a specific thread; only valid while thread.status is running|waiting. */
|
|
23
16
|
| {
|
|
24
17
|
kind: 'thread';
|
|
@@ -48,7 +41,7 @@ export interface ScheduleTask {
|
|
|
48
41
|
taskConfigHash?: string;
|
|
49
42
|
/** Dispatch routing — defaults to { kind: 'fresh' } for legacy records. */
|
|
50
43
|
target?: ScheduleTarget;
|
|
51
|
-
/** What to do when target
|
|
44
|
+
/** What to do when the target thread no longer exists at fire time.
|
|
52
45
|
* fresh: silently fall back to fresh-thread dispatch.
|
|
53
46
|
* skip: record lastSkipped, post a Slack one-liner, do not run.
|
|
54
47
|
* wait: reschedule short delay (max 3 retries), then fall back to fresh. */
|
|
@@ -17,11 +17,19 @@ export declare class SessionRegistryRepo {
|
|
|
17
17
|
private readonly _repo;
|
|
18
18
|
/** name → sessionId index keeping lookupSession O(1). */
|
|
19
19
|
private _nameIndex;
|
|
20
|
+
/** True once the name index has been fully rebuilt from the complete registry data.
|
|
21
|
+
* Guards against the index being treated as authoritative when it only holds entries
|
|
22
|
+
* added incrementally by registerSession() before any full build (which would make
|
|
23
|
+
* lookupSession() miss every session created in a previous process lifetime). */
|
|
24
|
+
private _indexBuilt;
|
|
20
25
|
/** Optional callback invoked when a session is pruned. Receives the sessionId. */
|
|
21
26
|
private _onPruneSession;
|
|
22
27
|
constructor(filePath?: string);
|
|
23
28
|
private _rebuildNameIndex;
|
|
24
|
-
/** Read registry data,
|
|
29
|
+
/** Read registry data, performing a one-time full rebuild of the name index.
|
|
30
|
+
* Must NOT gate on _nameIndex.size: registerSession() populates the index
|
|
31
|
+
* incrementally, so a non-empty-but-incomplete index would otherwise never be
|
|
32
|
+
* fully rebuilt and lookups for pre-existing sessions would silently miss. */
|
|
25
33
|
private _readWithIndex;
|
|
26
34
|
/** Rebuild the name index from the current cached data (zero I/O on cache hit). */
|
|
27
35
|
private _syncIndex;
|
|
@@ -20,6 +20,11 @@ export class SessionRegistryRepo {
|
|
|
20
20
|
_repo;
|
|
21
21
|
/** name → sessionId index keeping lookupSession O(1). */
|
|
22
22
|
_nameIndex = new Map();
|
|
23
|
+
/** True once the name index has been fully rebuilt from the complete registry data.
|
|
24
|
+
* Guards against the index being treated as authoritative when it only holds entries
|
|
25
|
+
* added incrementally by registerSession() before any full build (which would make
|
|
26
|
+
* lookupSession() miss every session created in a previous process lifetime). */
|
|
27
|
+
_indexBuilt = false;
|
|
23
28
|
/** Optional callback invoked when a session is pruned. Receives the sessionId. */
|
|
24
29
|
_onPruneSession = null;
|
|
25
30
|
constructor(filePath = REGISTRY_FILE) {
|
|
@@ -85,11 +90,15 @@ export class SessionRegistryRepo {
|
|
|
85
90
|
for (const [sid, record] of Object.entries(data)) {
|
|
86
91
|
this._nameIndex.set(record.name, sid);
|
|
87
92
|
}
|
|
93
|
+
this._indexBuilt = true;
|
|
88
94
|
}
|
|
89
|
-
/** Read registry data,
|
|
95
|
+
/** Read registry data, performing a one-time full rebuild of the name index.
|
|
96
|
+
* Must NOT gate on _nameIndex.size: registerSession() populates the index
|
|
97
|
+
* incrementally, so a non-empty-but-incomplete index would otherwise never be
|
|
98
|
+
* fully rebuilt and lookups for pre-existing sessions would silently miss. */
|
|
90
99
|
async _readWithIndex() {
|
|
91
100
|
const data = await this._repo.read();
|
|
92
|
-
if (this.
|
|
101
|
+
if (!this._indexBuilt) {
|
|
93
102
|
this._rebuildNameIndex(data);
|
|
94
103
|
}
|
|
95
104
|
return data;
|
|
@@ -151,7 +160,13 @@ export class SessionRegistryRepo {
|
|
|
151
160
|
}
|
|
152
161
|
async lookupSession(name) {
|
|
153
162
|
const registry = await this._readWithIndex();
|
|
154
|
-
|
|
163
|
+
let sid = this._nameIndex.get(name);
|
|
164
|
+
if (!sid) {
|
|
165
|
+
// Defensive: if the index somehow drifted from the data (e.g. mutated by a
|
|
166
|
+
// concurrent path), do a full rebuild and retry once before declaring a miss.
|
|
167
|
+
this._rebuildNameIndex(registry);
|
|
168
|
+
sid = this._nameIndex.get(name);
|
|
169
|
+
}
|
|
155
170
|
if (!sid)
|
|
156
171
|
return null;
|
|
157
172
|
return registry[sid] ?? null;
|
|
@@ -250,6 +265,7 @@ export class SessionRegistryRepo {
|
|
|
250
265
|
invalidate() {
|
|
251
266
|
this._repo.invalidate();
|
|
252
267
|
this._nameIndex.clear();
|
|
268
|
+
this._indexBuilt = false;
|
|
253
269
|
}
|
|
254
270
|
/** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
|
|
255
271
|
flush() {
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A conduit provider resolves session+project info for non-file-based conduits
|
|
3
|
+
* (e.g., TUI in-memory conduit state). Returns null for unrecognized conduitIds
|
|
4
|
+
* so the file-based lookup is used as fallback.
|
|
5
|
+
*/
|
|
6
|
+
export type ConduitProvider = (conduitId: string, backend: string) => {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
projectId: string;
|
|
9
|
+
} | null;
|
|
10
|
+
/**
|
|
11
|
+
* Register a conduit provider callback. Called by adapters (e.g., TuiGatewayAdapter)
|
|
12
|
+
* during start() so session lookup can resolve in-memory conduit state.
|
|
13
|
+
*/
|
|
14
|
+
export declare function registerConduitProvider(provider: ConduitProvider): void;
|
|
1
15
|
/** Shape of sessions.json: `{"backend:channel": sessionId, "legacyChannel": sessionId, ...}` */
|
|
2
16
|
export type SessionsData = Record<string, string>;
|
|
3
17
|
declare class SessionRepo {
|
|
@@ -6,6 +6,24 @@ import * as path from 'path';
|
|
|
6
6
|
import { JsonRepository } from '../core/json-repository.js';
|
|
7
7
|
import { STORE_DIR } from '../core/paths.js';
|
|
8
8
|
const SESSIONS_FILE = path.join(STORE_DIR, 'sessions.json');
|
|
9
|
+
/** Registered conduit providers, tried in registration order before file lookup. */
|
|
10
|
+
const conduitProviders = [];
|
|
11
|
+
/**
|
|
12
|
+
* Register a conduit provider callback. Called by adapters (e.g., TuiGatewayAdapter)
|
|
13
|
+
* during start() so session lookup can resolve in-memory conduit state.
|
|
14
|
+
*/
|
|
15
|
+
export function registerConduitProvider(provider) {
|
|
16
|
+
conduitProviders.push(provider);
|
|
17
|
+
}
|
|
18
|
+
/** Try conduit providers in registration order; returns null if none match. */
|
|
19
|
+
async function lookupViaProviders(channel, backend) {
|
|
20
|
+
for (const provider of conduitProviders) {
|
|
21
|
+
const result = provider(channel, backend);
|
|
22
|
+
if (result)
|
|
23
|
+
return result.sessionId;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
9
27
|
/** Key format: `backend:channel`. */
|
|
10
28
|
function sessionKey(backend, channel) {
|
|
11
29
|
return `${backend}:${channel}`;
|
|
@@ -27,6 +45,11 @@ class SessionRepo {
|
|
|
27
45
|
migrate: (raw) => (typeof raw === 'object' && raw !== null ? raw : ({})),
|
|
28
46
|
});
|
|
29
47
|
async getSessionAsync(channel, backend) {
|
|
48
|
+
// Try conduit providers first (TUI in-memory state, etc.)
|
|
49
|
+
const providerResult = await lookupViaProviders(channel, backend);
|
|
50
|
+
if (providerResult !== undefined)
|
|
51
|
+
return providerResult;
|
|
52
|
+
// Fall back to file storage
|
|
30
53
|
const sessions = await this._repo.read();
|
|
31
54
|
return sessions[sessionKey(backend, channel)] ?? sessions[channel] ?? undefined;
|
|
32
55
|
}
|
|
@@ -35,6 +35,9 @@ declare class ThreadRepo {
|
|
|
35
35
|
findByPlatformThread(channel: string, platformThreadId: string): ThreadRecord | null;
|
|
36
36
|
findActive(channel: string): ThreadRecord | null;
|
|
37
37
|
getAll(): ThreadRecord[];
|
|
38
|
+
/** Does this waiting record still await any live (open/pending, unblocked) child TASK?
|
|
39
|
+
* Reads TASKS.yaml via the zero-dependency core parser (store → core is layer-legal). */
|
|
40
|
+
private hasLiveTaskChildren;
|
|
38
41
|
markRunningAsFailedOnStartup(): Promise<number>;
|
|
39
42
|
/** Remove threads older than maxAge (default 7 days), including workspace directories.
|
|
40
43
|
* Auto-records (no workspace) use a shorter 24h TTL since they only need to
|
|
@@ -9,6 +9,7 @@ import { JsonRepository } from '../core/json-repository.js';
|
|
|
9
9
|
import { createLogger } from '../core/log.js';
|
|
10
10
|
import { AsyncMutex } from '../core/async-mutex.js';
|
|
11
11
|
import { STORE_DIR } from '../core/paths.js';
|
|
12
|
+
import { scanAllTasks } from '../core/task-parser.js';
|
|
12
13
|
const log = createLogger('thread-store');
|
|
13
14
|
const THREADS_FILE = path.join(STORE_DIR, 'threads.json');
|
|
14
15
|
class ThreadRepo {
|
|
@@ -124,11 +125,36 @@ class ThreadRepo {
|
|
|
124
125
|
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
125
126
|
}
|
|
126
127
|
// --- Lifecycle helpers ---
|
|
128
|
+
/** Does this waiting record still await any live (open/pending, unblocked) child TASK?
|
|
129
|
+
* Reads TASKS.yaml via the zero-dependency core parser (store → core is layer-legal). */
|
|
130
|
+
hasLiveTaskChildren(record) {
|
|
131
|
+
const ids = record.metadata?.waitingOnTasks;
|
|
132
|
+
const project = record.metadata?.taskProject;
|
|
133
|
+
if (!ids?.length || !project)
|
|
134
|
+
return false;
|
|
135
|
+
try {
|
|
136
|
+
const waiting = new Set(ids);
|
|
137
|
+
return scanAllTasks(project).some((t) => waiting.has(t.id) && t.status !== 'done' && !t.blocked_by);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
127
143
|
async markRunningAsFailedOnStartup() {
|
|
128
144
|
await this._pendingPersist;
|
|
129
145
|
return this.mutex.run(async () => {
|
|
130
146
|
let count = 0;
|
|
131
147
|
for (const record of this.map.values()) {
|
|
148
|
+
// Suspended parents (waiting on child threads, DR-0014) survive restarts —
|
|
149
|
+
// recoverWaitingThreads() re-delivers child results after startup. childThreadIds
|
|
150
|
+
// also qualifies: a parent that delivered its last child result but crashed before
|
|
151
|
+
// re-entry has an empty waitingOn yet must still be recovered, not failed. Only
|
|
152
|
+
// in-flight running threads and legacy waiting (no children) are interrupted.
|
|
153
|
+
const isSuspendedParent = record.status === 'waiting'
|
|
154
|
+
&& !!(record.metadata?.waitingOn?.length || record.metadata?.childThreadIds?.length
|
|
155
|
+
|| record.metadata?.waitingOnTasks?.length);
|
|
156
|
+
if (isSuspendedParent)
|
|
157
|
+
continue;
|
|
132
158
|
if (record.status === 'running' || record.status === 'waiting') {
|
|
133
159
|
record.status = 'failed';
|
|
134
160
|
record.error = 'Interrupted by server restart';
|
|
@@ -153,6 +179,26 @@ class ThreadRepo {
|
|
|
153
179
|
const cutoff = new Date(Date.now() - maxAgeMs).toISOString();
|
|
154
180
|
const autoRecordCutoff = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
|
|
155
181
|
let count = 0;
|
|
182
|
+
let staleWaiting = 0;
|
|
183
|
+
for (const record of this.map.values()) {
|
|
184
|
+
// Leak safety net (DR-0014): a parent stuck in waiting beyond maxAge has lost its
|
|
185
|
+
// children (records purged / callbacks dropped). This is ORPHAN detection, not an
|
|
186
|
+
// age limit: a manager waiting on a multi-day child TASK (e.g. a long training run,
|
|
187
|
+
// DR-0014 §8) is legitimately silent — spare it while any awaited task is still
|
|
188
|
+
// open/pending in TASKS.yaml. Fail true orphans; the next cleanup cycle
|
|
189
|
+
// garbage-collects them through the normal terminal path below.
|
|
190
|
+
if (record.status === 'waiting' && record.updatedAt < cutoff) {
|
|
191
|
+
if (this.hasLiveTaskChildren(record))
|
|
192
|
+
continue;
|
|
193
|
+
record.status = 'failed';
|
|
194
|
+
record.error = 'stale waiting parent — children never completed';
|
|
195
|
+
record.endedAt = new Date().toISOString();
|
|
196
|
+
record.updatedAt = new Date().toISOString();
|
|
197
|
+
staleWaiting++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (staleWaiting > 0)
|
|
201
|
+
log.info(`Failed ${staleWaiting} stale waiting threads (leak safety net)`);
|
|
156
202
|
for (const [id, record] of this.map) {
|
|
157
203
|
const isTerminal = record.status === 'completed' || record.status === 'failed'
|
|
158
204
|
|| record.status === 'cancelled' || record.status === 'aborted';
|
|
@@ -169,9 +215,10 @@ class ThreadRepo {
|
|
|
169
215
|
count++;
|
|
170
216
|
}
|
|
171
217
|
}
|
|
172
|
-
if (count > 0) {
|
|
218
|
+
if (count > 0 || staleWaiting > 0) {
|
|
173
219
|
await this.persist();
|
|
174
|
-
|
|
220
|
+
if (count > 0)
|
|
221
|
+
log.info(`Cleaned up ${count} old threads (including workspaces)`);
|
|
175
222
|
}
|
|
176
223
|
return count;
|
|
177
224
|
});
|
|
@@ -70,6 +70,101 @@ const migrations = [
|
|
|
70
70
|
return data;
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
|
+
// M2: Backfill `provider` on pi profiles that predate the gateway-routing split (6e50225f).
|
|
74
|
+
// That commit made `provider` REQUIRED for backend='pi' with no default — so any pre-upgrade
|
|
75
|
+
// profiles.json with a pi profile lacking `provider` now fails the whole-file validation in
|
|
76
|
+
// profile-manager (loadProfilesFile re-throws on ANY entry error → the entire config won't load
|
|
77
|
+
// → agent-server can't start). Pre-split, the PI `--provider` was sourced from the profile's
|
|
78
|
+
// `mode`, so `provider := mode` exactly reproduces the old behavior. Falls back to "anthropic"
|
|
79
|
+
// (the PI adapter's own default) when `mode` is also absent. Idempotent: entries that already
|
|
80
|
+
// declare `provider` are left untouched. Covers both primary entries and fallback[] entries,
|
|
81
|
+
// mirroring profile-manager's effective-backend/mode inheritance (fallback inherits the primary's
|
|
82
|
+
// backend and mode when its own are omitted).
|
|
83
|
+
{
|
|
84
|
+
filePath: 'config/profiles.json',
|
|
85
|
+
version: '2026.5.25',
|
|
86
|
+
migrate(data) {
|
|
87
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data))
|
|
88
|
+
return data;
|
|
89
|
+
const profiles = data.profiles;
|
|
90
|
+
if (typeof profiles !== 'object' || profiles === null || Array.isArray(profiles))
|
|
91
|
+
return data;
|
|
92
|
+
const backfill = (entry, inheritedBackend, inheritedMode) => {
|
|
93
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry))
|
|
94
|
+
return;
|
|
95
|
+
const e = entry;
|
|
96
|
+
const backend = typeof e.backend === 'string' ? e.backend : inheritedBackend;
|
|
97
|
+
if (backend !== 'pi' || e.provider !== undefined)
|
|
98
|
+
return;
|
|
99
|
+
const mode = typeof e.mode === 'string' ? e.mode : inheritedMode;
|
|
100
|
+
e.provider = mode && mode.length > 0 ? mode : 'anthropic';
|
|
101
|
+
};
|
|
102
|
+
for (const entry of Object.values(profiles)) {
|
|
103
|
+
backfill(entry, 'claude', undefined);
|
|
104
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry))
|
|
105
|
+
continue;
|
|
106
|
+
const e = entry;
|
|
107
|
+
const primaryBackend = typeof e.backend === 'string' ? e.backend : 'claude';
|
|
108
|
+
const primaryMode = typeof e.mode === 'string' ? e.mode : undefined;
|
|
109
|
+
if (Array.isArray(e.fallback)) {
|
|
110
|
+
for (const fb of e.fallback)
|
|
111
|
+
backfill(fb, primaryBackend, primaryMode);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return data;
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
// M3: Prefix session-store conduits with their platform namespace.
|
|
118
|
+
// The multi-platform release made each adapter expose conduits in a canonical
|
|
119
|
+
// prefixed form (`slack:C123`, `feishu:oc_xxx`) so Slack + Feishu + TUI can be
|
|
120
|
+
// online simultaneously behind CompositeAdapter. sessions.json keys are
|
|
121
|
+
// `backend:channel` (e.g. `claude:C123`) or legacy bare `channel`; after the
|
|
122
|
+
// change, lookups use the prefixed conduit, so the old keys no longer resolve.
|
|
123
|
+
// This migration rewrites the channel segment to its prefixed form so existing
|
|
124
|
+
// sessions survive the upgrade. The platform is inferred from CORTEX_PLATFORM —
|
|
125
|
+
// only run when EXACTLY ONE of slack/feishu is configured, since bare channels
|
|
126
|
+
// cannot otherwise be attributed to a platform. TUI conduits (`tui-`/`tui:`)
|
|
127
|
+
// and already-prefixed keys are left untouched (idempotent).
|
|
128
|
+
{
|
|
129
|
+
filePath: 'data/sessions.json',
|
|
130
|
+
version: '2026.6.4',
|
|
131
|
+
migrate(data) {
|
|
132
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data))
|
|
133
|
+
return data;
|
|
134
|
+
const platforms = (process.env.CORTEX_PLATFORM || 'slack')
|
|
135
|
+
.split(',').map(s => s.trim().toLowerCase()).filter(Boolean);
|
|
136
|
+
const single = platforms.length === 1 ? platforms[0] : null;
|
|
137
|
+
if (single !== 'slack' && single !== 'feishu')
|
|
138
|
+
return data; // can't attribute bare channels
|
|
139
|
+
const prefix = `${single}:`;
|
|
140
|
+
const isPrefixed = (s) => s.startsWith('slack:') || s.startsWith('feishu:');
|
|
141
|
+
const isTui = (s) => s.startsWith('tui-') || s.startsWith('tui:');
|
|
142
|
+
const src = data;
|
|
143
|
+
const out = {};
|
|
144
|
+
for (const [key, val] of Object.entries(src)) {
|
|
145
|
+
// Already-migrated legacy bare key (`slack:C2`) or a TUI conduit
|
|
146
|
+
// (`tui-abc`): the whole key is already in canonical form. Backends are
|
|
147
|
+
// claude/pi/tui — never `slack`/`feishu` — so a leading platform prefix
|
|
148
|
+
// unambiguously means an already-prefixed bare key, not `backend:channel`.
|
|
149
|
+
if (isPrefixed(key) || isTui(key)) {
|
|
150
|
+
out[key] = val;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const colon = key.indexOf(':');
|
|
154
|
+
if (colon === -1) {
|
|
155
|
+
// Legacy bare-channel key.
|
|
156
|
+
out[`${prefix}${key}`] = val;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// `backend:channel` key — prefix the channel segment only.
|
|
160
|
+
const backend = key.slice(0, colon);
|
|
161
|
+
const channel = key.slice(colon + 1);
|
|
162
|
+
out[isTui(channel) || isPrefixed(channel) ? key : `${backend}:${prefix}${channel}`] = val;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
},
|
|
167
|
+
},
|
|
73
168
|
];
|
|
74
169
|
// ── Versions file I/O ──────────────────────────────────────────
|
|
75
170
|
async function loadVersionsFrom(filePath) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ResumableSession } from './components/SessionPicker.js';
|
|
3
|
+
import type { WsState } from './ws-client.js';
|
|
4
|
+
import type { TuiFrame, HandshakeAck } from '../platform/tui/protocol.js';
|
|
5
|
+
export interface AppProps {
|
|
6
|
+
sendFrame: (frame: TuiFrame) => void;
|
|
7
|
+
connectionState: WsState;
|
|
8
|
+
ack: HandshakeAck | null;
|
|
9
|
+
onReconnect: () => void;
|
|
10
|
+
onDisconnect: () => void;
|
|
11
|
+
onSendCancel: () => void;
|
|
12
|
+
serverVersion: string | null;
|
|
13
|
+
projectId: string | null;
|
|
14
|
+
sessionName: string | null;
|
|
15
|
+
/** Fatal/connection error surfaced from the entry layer (e.g. backoff cap exceeded). */
|
|
16
|
+
errorMessage?: string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Called when this App component is ready to receive frames for dispatch.
|
|
19
|
+
* The parent (index.tsx) calls this function for each WS frame.
|
|
20
|
+
*/
|
|
21
|
+
onSetDispatch?: (dispatch: (frame: TuiFrame) => void) => void;
|
|
22
|
+
resumableSessions?: ResumableSession[] | null;
|
|
23
|
+
resumePending?: boolean;
|
|
24
|
+
onResumeSelect?: (sessionId: string, projectId: string) => void;
|
|
25
|
+
onResumeCancel?: () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect, onSendCancel, serverVersion, projectId, sessionName, errorMessage, onSetDispatch, resumableSessions, resumePending, onResumeSelect, onResumeCancel, }: AppProps): React.JSX.Element;
|