@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
|
@@ -1,17 +1,47 @@
|
|
|
1
|
-
// input: fs, path, os, `pi --list-models` output
|
|
2
|
-
// output: discoverEndpoints / generateGatewayYaml /
|
|
3
|
-
//
|
|
1
|
+
// input: fs, path, os, yaml, `pi --list-models` output
|
|
2
|
+
// output: discoverEndpoints / generateGatewayYaml / parsePiListModelsOutput
|
|
3
|
+
// + merge-aware: readGatewayYaml / discoveredToEndpointMap / mergeGatewayConfig /
|
|
4
|
+
// serializeGatewayYaml / writeMergedGatewayYaml / validateProfilesAgainstGateway
|
|
5
|
+
// — spawns pi --list-models, produces & merges gateway.yaml (add-only: never clobbers
|
|
6
|
+
// hand-maintained modes/keys), validates profile↔gateway mode coupling
|
|
4
7
|
// pos: init-time gateway config auto-generation. PI model metadata is owned by the PI agent
|
|
5
8
|
// (we shell out to `pi --list-models` rather than maintain provider/model whitelists).
|
|
6
|
-
// Claude plan mode is
|
|
7
|
-
import { writeFileSync, copyFileSync, mkdirSync, existsSync } from 'fs';
|
|
9
|
+
// Claude plan mode is included when the backends filter includes 'claude' (or is omitted).
|
|
10
|
+
import { writeFileSync, copyFileSync, mkdirSync, existsSync, readFileSync } from 'fs';
|
|
8
11
|
import { execSync } from 'child_process';
|
|
9
12
|
import * as path from 'path';
|
|
10
13
|
import * as os from 'os';
|
|
14
|
+
import { parse as yamlParse, stringify as yamlStringify } from 'yaml';
|
|
15
|
+
import { parse as parseDotenv } from 'dotenv';
|
|
11
16
|
import { createLogger } from './log.js';
|
|
17
|
+
import { CONFIG_DIR, GATEWAY_MANAGED_KEY_PLACEHOLDER } from './utils.js';
|
|
12
18
|
const log = createLogger('gateway-generator');
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the real Anthropic API key for endpoint discovery: process.env first (ignoring the
|
|
21
|
+
* gateway-managed placeholder), then CONFIG_DIR/.env — the canonical key location
|
|
22
|
+
* (docs/configuration.md). CLI processes (cortex init / setup-gateway) never run
|
|
23
|
+
* dotenv.config, so discovery must read the file itself.
|
|
24
|
+
*/
|
|
25
|
+
function resolveAnthropicApiKey() {
|
|
26
|
+
const envKey = process.env.ANTHROPIC_API_KEY?.trim();
|
|
27
|
+
if (envKey && envKey !== GATEWAY_MANAGED_KEY_PLACEHOLDER)
|
|
28
|
+
return envKey;
|
|
29
|
+
try {
|
|
30
|
+
const fileKey = parseDotenv(readFileSync(path.join(CONFIG_DIR, '.env'), 'utf8')).ANTHROPIC_API_KEY?.trim();
|
|
31
|
+
if (fileKey && fileKey !== GATEWAY_MANAGED_KEY_PLACEHOLDER)
|
|
32
|
+
return fileKey;
|
|
33
|
+
}
|
|
34
|
+
catch { /* no .env file — fall through */ }
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/** aistatus reserved top-level keys (mirror of node_modules/aistatus fromDict RESERVED_KEYS). */
|
|
38
|
+
const GATEWAY_RESERVED_KEYS = new Set(['host', 'port', 'mode', 'auth', 'status_check', 'endpoint_modes', 'endpoints']);
|
|
39
|
+
/** Keys that, when present directly on an endpoint value, mark it as a "flat" (single-mode) config. */
|
|
40
|
+
const FLAT_ENDPOINT_KEYS = ['keys', 'base_url', 'auth_style', 'passthrough', 'fallbacks', 'model_fallbacks'];
|
|
41
|
+
/** Synthetic mode name used to hold a flat endpoint config (aistatus assigns these to mode "default"). */
|
|
42
|
+
const FLAT_MODE = 'default';
|
|
13
43
|
// ─── Anthropic models (default tier) ─────────────────────────────
|
|
14
|
-
const ANTHROPIC_MODELS = ['claude-
|
|
44
|
+
const ANTHROPIC_MODELS = ['claude-fable-5', 'claude-4-8', 'claude-sonnet-4-6', 'claude-haiku-4-5'];
|
|
15
45
|
// ─── PI provider → upstream URL lookup (manually maintained) ────────────────
|
|
16
46
|
/**
|
|
17
47
|
* Map a PI built-in provider name to its real upstream URL. Used by `generateGatewayYaml` so PI
|
|
@@ -115,41 +145,50 @@ function scanPIViaListModels() {
|
|
|
115
145
|
/**
|
|
116
146
|
* Scan Claude Code and PI configurations and return discovered endpoints.
|
|
117
147
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
148
|
+
* @param backends - Optional filter: when provided, only discover endpoints for the listed backends
|
|
149
|
+
* (e.g. `['claude']`, `['pi']`, `['claude', 'pi']`). When omitted, all backends are discovered.
|
|
150
|
+
*
|
|
151
|
+
* - Claude Code plan mode: generated when 'claude' is in backends (or backends is omitted).
|
|
152
|
+
* - Claude Code api mode: generated only if ANTHROPIC_API_KEY env var is set and 'claude' is included.
|
|
153
|
+
* - PI providers: discovered via `pi --list-models` when 'pi' is in backends (or backends is omitted).
|
|
154
|
+
* Each provider becomes one endpoint with `mode = endpoint = provider name`. `gatewayManaged`
|
|
155
|
+
* is true only if the provider has a known upstream URL in PI_PROVIDER_UPSTREAM (otherwise profile
|
|
156
|
+
* is generated but gateway.yaml entry is skipped).
|
|
124
157
|
*/
|
|
125
|
-
export function discoverEndpoints() {
|
|
158
|
+
export function discoverEndpoints(backends) {
|
|
126
159
|
const endpoints = [];
|
|
127
|
-
// ── Claude Code → Anthropic plan mode
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
base_url: 'https://api.anthropic.com',
|
|
132
|
-
auth_style: 'bearer',
|
|
133
|
-
keys: [],
|
|
134
|
-
passthrough: true,
|
|
135
|
-
models: ANTHROPIC_MODELS,
|
|
136
|
-
gatewayManaged: true,
|
|
137
|
-
});
|
|
138
|
-
// api mode — only if ANTHROPIC_API_KEY is set
|
|
139
|
-
if (process.env.ANTHROPIC_API_KEY) {
|
|
160
|
+
// ── Claude Code → Anthropic plan mode ──
|
|
161
|
+
// Skip if backends filter is provided and 'claude' is not included.
|
|
162
|
+
const includeClaude = !backends || backends.includes('claude');
|
|
163
|
+
if (includeClaude) {
|
|
140
164
|
endpoints.push({
|
|
141
|
-
mode: '
|
|
165
|
+
mode: 'plan',
|
|
142
166
|
endpoint: 'anthropic',
|
|
143
167
|
base_url: 'https://api.anthropic.com',
|
|
144
|
-
auth_style: '
|
|
145
|
-
keys: [
|
|
168
|
+
auth_style: 'bearer',
|
|
169
|
+
keys: [],
|
|
146
170
|
passthrough: true,
|
|
147
171
|
models: ANTHROPIC_MODELS,
|
|
148
172
|
gatewayManaged: true,
|
|
149
173
|
});
|
|
174
|
+
// api mode — only if a REAL ANTHROPIC_API_KEY is available (the gateway-managed placeholder
|
|
175
|
+
// exists solely to satisfy Claude Code's startup credential check; it is not a key)
|
|
176
|
+
if (resolveAnthropicApiKey()) {
|
|
177
|
+
endpoints.push({
|
|
178
|
+
mode: 'api',
|
|
179
|
+
endpoint: 'anthropic',
|
|
180
|
+
base_url: 'https://api.anthropic.com',
|
|
181
|
+
auth_style: 'anthropic',
|
|
182
|
+
keys: ['$ANTHROPIC_API_KEY'],
|
|
183
|
+
passthrough: true,
|
|
184
|
+
models: ANTHROPIC_MODELS,
|
|
185
|
+
gatewayManaged: true,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
150
188
|
}
|
|
151
189
|
// ── PI → per-provider endpoints (one mode per provider) ──
|
|
152
|
-
const
|
|
190
|
+
const includePi = !backends || backends.includes('pi');
|
|
191
|
+
const piModels = includePi ? scanPIViaListModels() : [];
|
|
153
192
|
// Group models by provider name
|
|
154
193
|
const byProvider = new Map();
|
|
155
194
|
for (const { provider, model } of piModels) {
|
|
@@ -254,6 +293,8 @@ export function generateGatewayYaml(endpoints, defaultMode) {
|
|
|
254
293
|
* Write gateway.yaml to the specified path or ~/.aistatus/gateway.yaml.
|
|
255
294
|
* If file already exists and outputDir is not specified, backs it up as gateway.yaml.bak before overwriting.
|
|
256
295
|
* When outputDir is provided, writes to <outputDir>/gateway.yaml without backup.
|
|
296
|
+
*
|
|
297
|
+
* @deprecated Use writeMergedGatewayYaml — full overwrite drops hand-maintained custom modes.
|
|
257
298
|
*/
|
|
258
299
|
export function writeGatewayYaml(yamlContent, outputDir) {
|
|
259
300
|
const configDir = outputDir || path.join(os.homedir(), '.aistatus');
|
|
@@ -274,6 +315,258 @@ export function writeGatewayYaml(yamlContent, outputDir) {
|
|
|
274
315
|
log.info(`Written gateway.yaml to ${configPath}`);
|
|
275
316
|
return configPath;
|
|
276
317
|
}
|
|
318
|
+
// ─── Merge-aware generation (preserve hand-maintained modes) ──────────────────
|
|
319
|
+
function isPlainObject(v) {
|
|
320
|
+
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
321
|
+
}
|
|
322
|
+
function isFlatEndpointConfig(v) {
|
|
323
|
+
return FLAT_ENDPOINT_KEYS.some((k) => k in v);
|
|
324
|
+
}
|
|
325
|
+
function deepCopy(v) {
|
|
326
|
+
return JSON.parse(JSON.stringify(v));
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Parse an existing gateway.yaml into reserved top-level fields + the endpoint/mode tree.
|
|
330
|
+
* Returns null if the file is absent or unparseable (caller degrades to full generation).
|
|
331
|
+
*/
|
|
332
|
+
export function readGatewayYaml(filePath) {
|
|
333
|
+
if (!existsSync(filePath))
|
|
334
|
+
return null;
|
|
335
|
+
let raw;
|
|
336
|
+
try {
|
|
337
|
+
raw = yamlParse(readFileSync(filePath, 'utf-8'));
|
|
338
|
+
}
|
|
339
|
+
catch (e) {
|
|
340
|
+
log.warn(`Failed to parse existing gateway.yaml (${filePath}): ${e.message} — regenerating from scratch`);
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
if (!isPlainObject(raw))
|
|
344
|
+
return null;
|
|
345
|
+
const top = {};
|
|
346
|
+
const endpoints = {};
|
|
347
|
+
for (const [key, val] of Object.entries(raw)) {
|
|
348
|
+
if (GATEWAY_RESERVED_KEYS.has(key)) {
|
|
349
|
+
top[key] = val;
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (!isPlainObject(val))
|
|
353
|
+
continue; // ignore stray scalars
|
|
354
|
+
if (isFlatEndpointConfig(val)) {
|
|
355
|
+
endpoints[key] ??= {};
|
|
356
|
+
endpoints[key][FLAT_MODE] = val;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
for (const [modeName, modeVal] of Object.entries(val)) {
|
|
360
|
+
if (!isPlainObject(modeVal))
|
|
361
|
+
continue;
|
|
362
|
+
endpoints[key] ??= {};
|
|
363
|
+
endpoints[key][modeName] = modeVal;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return { top, endpoints };
|
|
367
|
+
}
|
|
368
|
+
/** Build an endpoint/mode tree from freshly discovered endpoints (gatewayManaged only). */
|
|
369
|
+
export function discoveredToEndpointMap(endpoints) {
|
|
370
|
+
const map = {};
|
|
371
|
+
for (const ep of endpoints) {
|
|
372
|
+
if (ep.gatewayManaged === false)
|
|
373
|
+
continue;
|
|
374
|
+
const cfg = { base_url: ep.base_url, auth_style: ep.auth_style };
|
|
375
|
+
if (ep.keys.length > 0) {
|
|
376
|
+
cfg.keys = [...ep.keys];
|
|
377
|
+
if (ep.passthrough)
|
|
378
|
+
cfg.passthrough = true;
|
|
379
|
+
}
|
|
380
|
+
map[ep.endpoint] ??= {};
|
|
381
|
+
map[ep.endpoint][ep.mode] = cfg;
|
|
382
|
+
}
|
|
383
|
+
return map;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Merge freshly discovered endpoints over an existing gateway config.
|
|
387
|
+
*
|
|
388
|
+
* Add-only at the (endpoint, mode) PAIR level (mirrors mergeProfilesJson overwrite=false): a pair
|
|
389
|
+
* absent from the existing file is added from discovery; any pair that already exists is preserved
|
|
390
|
+
* verbatim — its base_url, auth_style and (critically) managed keys are never clobbered. This both
|
|
391
|
+
* fixes the original bug (a missing mode gets added) and protects hand-customized routes, e.g. a
|
|
392
|
+
* `deepseek` mode pointed at a private relay with a secret key, even though `pi --list-models`
|
|
393
|
+
* reports the canonical upstream for that provider. A failed/empty discovery therefore can never
|
|
394
|
+
* drop or alter previously-configured modes. To intentionally update an existing route's URL/keys,
|
|
395
|
+
* edit gateway.yaml directly.
|
|
396
|
+
*/
|
|
397
|
+
export function mergeGatewayConfig(discovered, existing, defaultMode) {
|
|
398
|
+
const disc = discoveredToEndpointMap(discovered);
|
|
399
|
+
const merged = existing ? deepCopy(existing.endpoints) : {};
|
|
400
|
+
const preservedCustom = [];
|
|
401
|
+
const droppedFromDiscovery = [];
|
|
402
|
+
// Classify existing pairs against the fresh discovery set (for reporting only — nothing is
|
|
403
|
+
// overwritten). A pair not present in this discovery is "custom"; if it also isn't a Claude
|
|
404
|
+
// builtin (anthropic/plan|api), surface it as droppedFromDiscovery so a failed/under-reporting
|
|
405
|
+
// `pi --list-models` is visible rather than silently keeping stale routes.
|
|
406
|
+
for (const [endpoint, modes] of Object.entries(merged)) {
|
|
407
|
+
for (const mode of Object.keys(modes)) {
|
|
408
|
+
const isDiscoveryOwned = !!disc[endpoint]?.[mode];
|
|
409
|
+
if (!isDiscoveryOwned) {
|
|
410
|
+
preservedCustom.push({ endpoint, mode });
|
|
411
|
+
const isClaudeBuiltin = endpoint === 'anthropic' && (mode === 'plan' || mode === 'api');
|
|
412
|
+
if (!isClaudeBuiltin)
|
|
413
|
+
droppedFromDiscovery.push({ endpoint, mode });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
// Add-only: fill in pairs discovery found that aren't already present. Existing pairs (incl. their
|
|
418
|
+
// keys/base_url) are left untouched.
|
|
419
|
+
for (const [endpoint, modes] of Object.entries(disc)) {
|
|
420
|
+
merged[endpoint] ??= {};
|
|
421
|
+
for (const [mode, cfg] of Object.entries(modes)) {
|
|
422
|
+
if (!merged[endpoint][mode])
|
|
423
|
+
merged[endpoint][mode] = cfg;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// Resolve active billing mode: explicit override → existing-still-valid → first discovered → 'api'.
|
|
427
|
+
const availableModes = new Set();
|
|
428
|
+
for (const modes of Object.values(merged))
|
|
429
|
+
for (const m of Object.keys(modes))
|
|
430
|
+
availableModes.add(m);
|
|
431
|
+
const existingMode = typeof existing?.top.mode === 'string' ? existing.top.mode : undefined;
|
|
432
|
+
const firstDiscovered = discovered.find((e) => e.gatewayManaged !== false)?.mode;
|
|
433
|
+
const activeMode = defaultMode && availableModes.has(defaultMode)
|
|
434
|
+
? defaultMode
|
|
435
|
+
: existingMode && availableModes.has(existingMode)
|
|
436
|
+
? existingMode
|
|
437
|
+
: firstDiscovered && availableModes.has(firstDiscovered)
|
|
438
|
+
? firstDiscovered
|
|
439
|
+
: (availableModes.values().next().value ?? 'api');
|
|
440
|
+
const top = existing ? deepCopy(existing.top) : {};
|
|
441
|
+
top.port = top.port ?? 9880;
|
|
442
|
+
top.mode = activeMode;
|
|
443
|
+
top.status_check = top.status_check ?? true;
|
|
444
|
+
return { endpoints: merged, top, preservedCustom, droppedFromDiscovery };
|
|
445
|
+
}
|
|
446
|
+
/** Serialize a merged gateway config back to YAML (re-serializes; inline comments in custom blocks are not retained). */
|
|
447
|
+
export function serializeGatewayYaml(result) {
|
|
448
|
+
const obj = {};
|
|
449
|
+
// Ordered, well-known top-level fields first.
|
|
450
|
+
obj.port = result.top.port ?? 9880;
|
|
451
|
+
obj.mode = result.top.mode;
|
|
452
|
+
obj.status_check = result.top.status_check ?? true;
|
|
453
|
+
if (result.top.host !== undefined)
|
|
454
|
+
obj.host = result.top.host;
|
|
455
|
+
if (result.top.auth !== undefined)
|
|
456
|
+
obj.auth = result.top.auth;
|
|
457
|
+
if (result.top.endpoint_modes !== undefined)
|
|
458
|
+
obj.endpoint_modes = result.top.endpoint_modes;
|
|
459
|
+
if (result.top.endpoints !== undefined)
|
|
460
|
+
obj.endpoints = result.top.endpoints;
|
|
461
|
+
for (const [endpoint, modes] of Object.entries(result.endpoints)) {
|
|
462
|
+
const modeNames = Object.keys(modes);
|
|
463
|
+
// Flat endpoint: only the synthetic `default` mode → emit config directly under the endpoint.
|
|
464
|
+
if (modeNames.length === 1 && modeNames[0] === FLAT_MODE) {
|
|
465
|
+
obj[endpoint] = modes[FLAT_MODE];
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
obj[endpoint] = modes;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const header = [
|
|
472
|
+
'# aistatus gateway — managed by cortex (merge mode).',
|
|
473
|
+
`# Generated: ${new Date().toISOString()}`,
|
|
474
|
+
'#',
|
|
475
|
+
'# `cortex init` / `cortex setup-gateway` ADD newly discovered modes; existing modes and their',
|
|
476
|
+
'# keys are preserved as-is (never overwritten). Edit a route here to change its URL/keys.',
|
|
477
|
+
'# NOTE: inline comments inside existing blocks are not retained across regeneration.',
|
|
478
|
+
'#',
|
|
479
|
+
'# Docs: https://aistatus.cc/docs',
|
|
480
|
+
'',
|
|
481
|
+
].join('\n');
|
|
482
|
+
return header + yamlStringify(obj, { lineWidth: 0 });
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Read existing gateway.yaml, merge discovery over it, and write the result. Always backs up an
|
|
486
|
+
* existing file to .bak first (including when outputDir is given, since merge now touches real data).
|
|
487
|
+
*/
|
|
488
|
+
export function writeMergedGatewayYaml(discovered, outputDir, defaultMode) {
|
|
489
|
+
const configDir = outputDir || path.join(os.homedir(), '.aistatus');
|
|
490
|
+
const configPath = path.join(configDir, 'gateway.yaml');
|
|
491
|
+
const existing = readGatewayYaml(configPath);
|
|
492
|
+
const result = mergeGatewayConfig(discovered, existing, defaultMode);
|
|
493
|
+
const content = serializeGatewayYaml(result);
|
|
494
|
+
if (existsSync(configPath)) {
|
|
495
|
+
try {
|
|
496
|
+
copyFileSync(configPath, configPath + '.bak');
|
|
497
|
+
log.info(`Backed up existing gateway.yaml to ${configPath}.bak`);
|
|
498
|
+
}
|
|
499
|
+
catch (e) {
|
|
500
|
+
log.warn(`Failed to backup existing gateway.yaml: ${e.message}`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
mkdirSync(configDir, { recursive: true });
|
|
504
|
+
writeFileSync(configPath, content, 'utf-8');
|
|
505
|
+
log.info(`Written merged gateway.yaml to ${configPath}`);
|
|
506
|
+
return { path: configPath, result };
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Validate that every profile (and its fallback chain) in profiles.json references a gateway mode
|
|
510
|
+
* that actually exists in the merged endpoint map. Pure + non-fatal — returns the list of problems
|
|
511
|
+
* so the caller can warn loudly. This is what catches the `400 Unknown mode: <x>` class of bug.
|
|
512
|
+
*/
|
|
513
|
+
export function validateProfilesAgainstGateway(mergedEndpoints, profilesConfigDir) {
|
|
514
|
+
const profilesPath = profilesConfigDir
|
|
515
|
+
? path.join(profilesConfigDir, 'profiles.json')
|
|
516
|
+
: path.join(os.homedir(), '.cortex', 'config', 'profiles.json');
|
|
517
|
+
let parsed;
|
|
518
|
+
try {
|
|
519
|
+
if (!existsSync(profilesPath))
|
|
520
|
+
return [];
|
|
521
|
+
parsed = JSON.parse(readFileSync(profilesPath, 'utf-8'));
|
|
522
|
+
}
|
|
523
|
+
catch (e) {
|
|
524
|
+
log.warn(`Failed to read profiles.json for validation: ${e.message}`);
|
|
525
|
+
return [];
|
|
526
|
+
}
|
|
527
|
+
if (!isPlainObject(parsed) || !isPlainObject(parsed.profiles))
|
|
528
|
+
return [];
|
|
529
|
+
const modeExistsAnywhere = (mode) => Object.values(mergedEndpoints).some((modes) => mode in modes);
|
|
530
|
+
const issues = [];
|
|
531
|
+
const checkEntry = (entry, label) => {
|
|
532
|
+
const backend = typeof entry.backend === 'string' ? entry.backend : undefined;
|
|
533
|
+
const mode = typeof entry.mode === 'string' ? entry.mode : undefined;
|
|
534
|
+
const provider = typeof entry.provider === 'string' ? entry.provider : undefined;
|
|
535
|
+
// No mode → PI uses direct /<provider> routing (no gateway mode indirection); nothing to check.
|
|
536
|
+
if (!mode)
|
|
537
|
+
return;
|
|
538
|
+
let endpoint;
|
|
539
|
+
if (backend === 'claude')
|
|
540
|
+
endpoint = 'anthropic';
|
|
541
|
+
else if (backend === 'pi')
|
|
542
|
+
endpoint = provider;
|
|
543
|
+
else
|
|
544
|
+
return; // codex / unknown backends don't route through gateway modes here
|
|
545
|
+
if (backend === 'pi' && !provider) {
|
|
546
|
+
issues.push({ profile: label, mode, reason: `pi profile is missing a provider (cannot resolve gateway endpoint)` });
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (!endpoint || !mergedEndpoints[endpoint]?.[mode]) {
|
|
550
|
+
const reason = !modeExistsAnywhere(mode)
|
|
551
|
+
? `mode "${mode}" is not configured in gateway.yaml`
|
|
552
|
+
: `endpoint "${endpoint}" is not configured under mode "${mode}"`;
|
|
553
|
+
issues.push({ profile: label, mode, provider, reason });
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
for (const [name, profileVal] of Object.entries(parsed.profiles)) {
|
|
557
|
+
if (!isPlainObject(profileVal))
|
|
558
|
+
continue;
|
|
559
|
+
checkEntry(profileVal, name);
|
|
560
|
+
const fallback = profileVal.fallback;
|
|
561
|
+
if (Array.isArray(fallback)) {
|
|
562
|
+
fallback.forEach((fb, i) => {
|
|
563
|
+
if (isPlainObject(fb))
|
|
564
|
+
checkEntry(fb, `${name} (fallback #${i + 1})`);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return issues;
|
|
569
|
+
}
|
|
277
570
|
/**
|
|
278
571
|
* Run discovery and return the YAML string (without writing to disk).
|
|
279
572
|
* Useful for dry-run / preview.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type MessageKey } from './locales/en.js';
|
|
2
|
+
export type Locale = 'en' | 'zh';
|
|
3
|
+
/** Coerce an arbitrary string (env/config/user input) to a supported Locale, defaulting to 'en'. */
|
|
4
|
+
export declare function normalizeLocale(raw: string | undefined | null): Locale;
|
|
5
|
+
/**
|
|
6
|
+
* Best-effort detection of the operator's system language from POSIX locale env vars.
|
|
7
|
+
* Precedence follows POSIX: LC_ALL > LC_MESSAGES > LANG > LANGUAGE. A value whose language
|
|
8
|
+
* tag starts with "zh" (zh_CN, zh_TW, zh-Hans, ...) maps to 'zh'; everything else (incl. unset,
|
|
9
|
+
* "C", "POSIX") falls back to 'en'. Used by `cortex init` to pre-select the language option.
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectSystemLocale(env?: NodeJS.ProcessEnv): Locale;
|
|
12
|
+
export declare function setLocale(loc: Locale): void;
|
|
13
|
+
export declare function getLocale(): Locale;
|
|
14
|
+
/**
|
|
15
|
+
* Translate a message key in the active locale. Resolution order:
|
|
16
|
+
* active-locale table → en table (fallback) → the raw key (last resort).
|
|
17
|
+
* `${param}` placeholders are substituted from `params`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function t(key: MessageKey | string, params?: Record<string, string | number>): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// input: en/zh locale tables (core/locales), process.env.CORTEX_LANG (initial locale only)
|
|
2
|
+
// output: t(key, params) / setLocale / getLocale / normalizeLocale + Locale type
|
|
3
|
+
// pos: L0 zero-dependency i18n layer. MUST NOT import domain/* — the active locale is set
|
|
4
|
+
// by the wiring layer (entry/app.ts) via setLocale(); this module never reads config.
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import { en } from './locales/en.js';
|
|
7
|
+
import { zh } from './locales/zh.js';
|
|
8
|
+
const LOCALES = { en, zh };
|
|
9
|
+
/** Coerce an arbitrary string (env/config/user input) to a supported Locale, defaulting to 'en'. */
|
|
10
|
+
export function normalizeLocale(raw) {
|
|
11
|
+
return raw === 'zh' ? 'zh' : 'en';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Best-effort detection of the operator's system language from POSIX locale env vars.
|
|
15
|
+
* Precedence follows POSIX: LC_ALL > LC_MESSAGES > LANG > LANGUAGE. A value whose language
|
|
16
|
+
* tag starts with "zh" (zh_CN, zh_TW, zh-Hans, ...) maps to 'zh'; everything else (incl. unset,
|
|
17
|
+
* "C", "POSIX") falls back to 'en'. Used by `cortex init` to pre-select the language option.
|
|
18
|
+
*/
|
|
19
|
+
export function detectSystemLocale(env = process.env) {
|
|
20
|
+
const raw = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || '';
|
|
21
|
+
return raw.toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
22
|
+
}
|
|
23
|
+
// Initial locale comes only from the environment (escape hatch / boot default). The wiring layer
|
|
24
|
+
// overrides it with the persisted preference via setLocale() right after config load.
|
|
25
|
+
let currentLocale = normalizeLocale(process.env.CORTEX_LANG);
|
|
26
|
+
export function setLocale(loc) {
|
|
27
|
+
currentLocale = normalizeLocale(loc);
|
|
28
|
+
}
|
|
29
|
+
export function getLocale() {
|
|
30
|
+
return currentLocale;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Translate a message key in the active locale. Resolution order:
|
|
34
|
+
* active-locale table → en table (fallback) → the raw key (last resort).
|
|
35
|
+
* `${param}` placeholders are substituted from `params`.
|
|
36
|
+
*/
|
|
37
|
+
export function t(key, params) {
|
|
38
|
+
const table = LOCALES[currentLocale] ?? en;
|
|
39
|
+
let str = table[key] ?? en[key] ?? key;
|
|
40
|
+
if (params) {
|
|
41
|
+
for (const [k, v] of Object.entries(params)) {
|
|
42
|
+
str = str.split('${' + k + '}').join(String(v));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return str;
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Semantic icon constants — replaces Slack `:shortcode:` literals.
|
|
2
|
+
* All values are raw Unicode so they render correctly on any platform
|
|
3
|
+
* (Slack, Feishu, TUI). Slack renders Unicode emoji identically to shortcodes. */
|
|
4
|
+
export declare const Icons: {
|
|
5
|
+
/** :warning: */
|
|
6
|
+
readonly warning: "⚠️";
|
|
7
|
+
/** :white_check_mark: */
|
|
8
|
+
readonly ok: "✅";
|
|
9
|
+
/** :x: */
|
|
10
|
+
readonly error: "❌";
|
|
11
|
+
/** :arrows_counterclockwise: */
|
|
12
|
+
readonly refresh: "🔄";
|
|
13
|
+
/** :hourglass_flowing_sand: */
|
|
14
|
+
readonly processing: "⏳";
|
|
15
|
+
/** :stopwatch: */
|
|
16
|
+
readonly stopwatch: "⏱️";
|
|
17
|
+
/** :repeat: */
|
|
18
|
+
readonly repeat: "🔁";
|
|
19
|
+
/** :satellite: */
|
|
20
|
+
readonly satellite: "🛰️";
|
|
21
|
+
/** :leftwards_arrow_with_hook: */
|
|
22
|
+
readonly reply: "↩️";
|
|
23
|
+
/** :hook: */
|
|
24
|
+
readonly hook: "🪝";
|
|
25
|
+
/** :speech_balloon: */
|
|
26
|
+
readonly waiting: "💬";
|
|
27
|
+
/** :fast_forward: */
|
|
28
|
+
readonly superseded: "⏩";
|
|
29
|
+
/** :octagonal_sign: */
|
|
30
|
+
readonly stopped: "🛑";
|
|
31
|
+
/** :memo: */
|
|
32
|
+
readonly memo: "📝";
|
|
33
|
+
/** :brain: */
|
|
34
|
+
readonly brain: "🧠";
|
|
35
|
+
/** :file_folder: */
|
|
36
|
+
readonly folder: "📁";
|
|
37
|
+
/** :desktop_computer: */
|
|
38
|
+
readonly desktop: "🖥️";
|
|
39
|
+
/** :scroll: */
|
|
40
|
+
readonly scroll: "📜";
|
|
41
|
+
/** :wave: */
|
|
42
|
+
readonly wave: "👋";
|
|
43
|
+
/** :no_entry: / :no_entry_sign: */
|
|
44
|
+
readonly blocked: "🚫";
|
|
45
|
+
/** :no_entry_sign: (alias for blocked — identical rendering) */
|
|
46
|
+
readonly noEntry: "🚫";
|
|
47
|
+
/** :heavy_plus_sign: */
|
|
48
|
+
readonly add: "➕";
|
|
49
|
+
/** :inbox_tray: */
|
|
50
|
+
readonly inbox: "📥";
|
|
51
|
+
/** :pencil2: */
|
|
52
|
+
readonly edit: "✏️";
|
|
53
|
+
/** :wrench: */
|
|
54
|
+
readonly tools: "🔧";
|
|
55
|
+
/** :arrow_right: */
|
|
56
|
+
readonly arrowRight: "➡️";
|
|
57
|
+
/** :arrow_left: */
|
|
58
|
+
readonly arrowLeft: "⬅️";
|
|
59
|
+
/** :arrow_forward: */
|
|
60
|
+
readonly resume: "▶️";
|
|
61
|
+
/** :double_vertical_bar: */
|
|
62
|
+
readonly paused: "⏸️";
|
|
63
|
+
/** :clock1: */
|
|
64
|
+
readonly scheduled: "🕐";
|
|
65
|
+
/** :radio_button: */
|
|
66
|
+
readonly pending: "🔘";
|
|
67
|
+
};
|
|
68
|
+
export type IconName = keyof typeof Icons;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Semantic icon constants — replaces Slack `:shortcode:` literals.
|
|
2
|
+
* All values are raw Unicode so they render correctly on any platform
|
|
3
|
+
* (Slack, Feishu, TUI). Slack renders Unicode emoji identically to shortcodes. */
|
|
4
|
+
export const Icons = {
|
|
5
|
+
/** :warning: */
|
|
6
|
+
warning: '⚠️',
|
|
7
|
+
/** :white_check_mark: */
|
|
8
|
+
ok: '✅',
|
|
9
|
+
/** :x: */
|
|
10
|
+
error: '❌',
|
|
11
|
+
/** :arrows_counterclockwise: */
|
|
12
|
+
refresh: '🔄',
|
|
13
|
+
/** :hourglass_flowing_sand: */
|
|
14
|
+
processing: '⏳',
|
|
15
|
+
/** :stopwatch: */
|
|
16
|
+
stopwatch: '⏱️',
|
|
17
|
+
/** :repeat: */
|
|
18
|
+
repeat: '🔁',
|
|
19
|
+
/** :satellite: */
|
|
20
|
+
satellite: '🛰️',
|
|
21
|
+
/** :leftwards_arrow_with_hook: */
|
|
22
|
+
reply: '↩️',
|
|
23
|
+
/** :hook: */
|
|
24
|
+
hook: '🪝',
|
|
25
|
+
/** :speech_balloon: */
|
|
26
|
+
waiting: '💬',
|
|
27
|
+
/** :fast_forward: */
|
|
28
|
+
superseded: '⏩',
|
|
29
|
+
/** :octagonal_sign: */
|
|
30
|
+
stopped: '🛑',
|
|
31
|
+
/** :memo: */
|
|
32
|
+
memo: '📝',
|
|
33
|
+
/** :brain: */
|
|
34
|
+
brain: '🧠',
|
|
35
|
+
/** :file_folder: */
|
|
36
|
+
folder: '📁',
|
|
37
|
+
/** :desktop_computer: */
|
|
38
|
+
desktop: '🖥️',
|
|
39
|
+
/** :scroll: */
|
|
40
|
+
scroll: '📜',
|
|
41
|
+
/** :wave: */
|
|
42
|
+
wave: '👋',
|
|
43
|
+
/** :no_entry: / :no_entry_sign: */
|
|
44
|
+
blocked: '🚫',
|
|
45
|
+
/** :no_entry_sign: (alias for blocked — identical rendering) */
|
|
46
|
+
noEntry: '🚫',
|
|
47
|
+
/** :heavy_plus_sign: */
|
|
48
|
+
add: '➕',
|
|
49
|
+
/** :inbox_tray: */
|
|
50
|
+
inbox: '📥',
|
|
51
|
+
/** :pencil2: */
|
|
52
|
+
edit: '✏️',
|
|
53
|
+
/** :wrench: */
|
|
54
|
+
tools: '🔧',
|
|
55
|
+
/** :arrow_right: */
|
|
56
|
+
arrowRight: '➡️',
|
|
57
|
+
/** :arrow_left: */
|
|
58
|
+
arrowLeft: '⬅️',
|
|
59
|
+
/** :arrow_forward: */
|
|
60
|
+
resume: '▶️',
|
|
61
|
+
/** :double_vertical_bar: */
|
|
62
|
+
paused: '⏸️',
|
|
63
|
+
/** :clock1: */
|
|
64
|
+
scheduled: '🕐',
|
|
65
|
+
/** :radio_button: */
|
|
66
|
+
pending: '🔘',
|
|
67
|
+
};
|