@cortex-agent/server 2026.5.25-1 → 2026.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/config/thread-templates.json +28 -1
- package/defaults/hooks/cortex-md-injector.mjs +47 -31
- package/defaults/hooks/post-task-hook.mjs +6 -0
- package/defaults/hooks/task-status-check.mjs +8 -0
- package/defaults/mcp-config-slack.json +11 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +18 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +5 -6
- package/defaults/prompts/directives/manager.md +67 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +35 -3
- package/dist/agent-adapter/claude/adapter-tui.js +91 -12
- package/dist/agent-adapter/claude/adapter.js +11 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +30 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +2 -2
- package/dist/agent-adapter/claude/jsonl-tail.js +25 -20
- package/dist/agent-adapter/claude/spawn-args.d.ts +11 -0
- package/dist/agent-adapter/claude/spawn-args.js +49 -7
- package/dist/agent-adapter/claude/tmux-control.d.ts +20 -0
- package/dist/agent-adapter/claude/tmux-control.js +54 -8
- package/dist/agent-adapter/codex/adapter.js +1 -1
- package/dist/agent-adapter/normalize/event-types.d.ts +1 -0
- package/dist/agent-adapter/pi/adapter.js +46 -19
- package/dist/agent-adapter/pi/agent-dir.d.ts +21 -0
- package/dist/agent-adapter/pi/agent-dir.js +53 -2
- package/dist/agent-adapter/pi/event-parser.js +13 -1
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +12 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +47 -9
- package/dist/agent-adapter/pi/tool-shims.d.ts +14 -0
- package/dist/agent-adapter/pi/tool-shims.js +167 -140
- package/dist/agent-adapter/types.d.ts +7 -2
- package/dist/core/atomic-write.js +21 -0
- package/dist/core/config-generator.d.ts +10 -0
- package/dist/core/config-generator.js +28 -0
- package/dist/core/gateway-generator.d.ts +77 -7
- package/dist/core/gateway-generator.js +301 -29
- package/dist/core/icons.d.ts +68 -0
- package/dist/core/icons.js +67 -0
- package/dist/core/profile-generator.d.ts +6 -0
- package/dist/core/profile-generator.js +35 -7
- package/dist/core/running-executions.d.ts +51 -41
- package/dist/core/running-executions.js +120 -73
- package/dist/core/status-format.js +3 -2
- package/dist/core/task-parser.d.ts +3 -0
- package/dist/core/task-parser.js +3 -1
- package/dist/core/types/thread-types.d.ts +54 -8
- package/dist/domain/agents/facade.d.ts +18 -0
- package/dist/domain/agents/facade.js +26 -3
- package/dist/domain/agents/profile-manager.d.ts +11 -0
- package/dist/domain/agents/profile-manager.js +21 -2
- package/dist/domain/costs/codex-usage-monitor.js +2 -1
- package/dist/domain/costs/rate-limit-throttle.js +14 -2
- package/dist/domain/executions/registry.d.ts +24 -0
- package/dist/domain/executions/registry.js +38 -0
- package/dist/domain/mcp/core-server.js +15 -3
- package/dist/domain/mcp/feishu/bitable.d.ts +3 -0
- package/dist/domain/mcp/feishu/bitable.js +168 -0
- package/dist/domain/mcp/feishu/block-types.d.ts +44 -0
- package/dist/domain/mcp/feishu/block-types.js +127 -0
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +19 -0
- package/dist/domain/mcp/feishu/blocks-to-text.js +43 -0
- package/dist/domain/mcp/feishu/client.d.ts +46 -0
- package/dist/domain/mcp/feishu/client.js +87 -0
- package/dist/domain/mcp/feishu/docx.d.ts +3 -0
- package/dist/domain/mcp/feishu/docx.js +163 -0
- package/dist/domain/mcp/feishu/drive.d.ts +23 -0
- package/dist/domain/mcp/feishu/drive.js +66 -0
- package/dist/domain/mcp/feishu/file.d.ts +14 -0
- package/dist/domain/mcp/feishu/file.js +107 -0
- package/dist/domain/mcp/feishu/index.d.ts +6 -0
- package/dist/domain/mcp/feishu/index.js +61 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +40 -0
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +191 -0
- package/dist/domain/mcp/feishu/sheets.d.ts +3 -0
- package/dist/domain/mcp/feishu/sheets.js +119 -0
- package/dist/domain/mcp/feishu/types.d.ts +26 -0
- package/dist/domain/mcp/feishu/types.js +38 -0
- package/dist/domain/mcp/feishu/user-auth.d.ts +140 -0
- package/dist/domain/mcp/feishu/user-auth.js +286 -0
- package/dist/domain/mcp/feishu/wiki.d.ts +3 -0
- package/dist/domain/mcp/feishu/wiki.js +77 -0
- package/dist/domain/mcp/feishu-server.d.ts +2 -0
- package/dist/domain/mcp/feishu-server.js +33 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +6 -25
- package/dist/domain/mcp/slack-server.d.ts +3 -0
- package/dist/domain/mcp/slack-server.js +46 -0
- package/dist/domain/mcp/tools/context.js +1 -1
- package/dist/domain/mcp/tools/schedule.d.ts +1 -1
- package/dist/domain/mcp/tools/schedule.js +6 -20
- package/dist/domain/mcp/tools/slack.js +20 -7
- package/dist/domain/mcp/tools/thread-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/thread-ops.js +121 -0
- package/dist/domain/mcp/tools/time.d.ts +2 -0
- package/dist/domain/mcp/tools/time.js +66 -0
- package/dist/domain/mcp/tools/tui-ask.js +1 -1
- package/dist/domain/mcp/tools/tui-plan.js +2 -2
- package/dist/domain/mcp/tui-server.js +1 -0
- package/dist/domain/monitor/disk-monitor.js +2 -1
- package/dist/domain/monitor/gpu-monitor.js +2 -1
- package/dist/domain/remote/client-hot-reload.js +3 -2
- package/dist/domain/remote/client-manager.js +8 -6
- package/dist/domain/scheduling/job-registry.d.ts +4 -0
- package/dist/domain/scheduling/job-registry.js +1 -0
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/memory-index-regen.js +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +9 -23
- package/dist/domain/scheduling/jobs/sync-public.js +4 -3
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +1 -8
- package/dist/domain/scheduling/jobs/target-dispatch.js +0 -7
- package/dist/domain/scheduling/jobs/task-archive.js +3 -2
- package/dist/domain/scheduling/jobs/task-dispatch.js +120 -10
- package/dist/domain/scheduling/schedule-command.js +16 -15
- package/dist/domain/scheduling/scheduler.d.ts +1 -1
- package/dist/domain/scheduling/scheduler.js +2 -1
- package/dist/domain/sessions/session-hooks.d.ts +2 -2
- package/dist/domain/sessions/session-hooks.js +19 -18
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -0
- package/dist/domain/sessions/session-lifecycle.js +44 -0
- package/dist/domain/system/install-cli.d.ts +7 -0
- package/dist/domain/system/install-cli.js +106 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +58 -1
- package/dist/domain/tasks/dispatch-utils.js +53 -4
- package/dist/domain/tasks/dispatcher.js +26 -0
- package/dist/domain/tasks/lint.js +28 -0
- package/dist/domain/tasks/mutator.d.ts +16 -3
- package/dist/domain/tasks/mutator.js +41 -12
- package/dist/domain/tasks/pending-tracker.js +6 -5
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.js +6 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +41 -3
- package/dist/domain/tasks/system/task-mutations.js +166 -8
- package/dist/domain/threads/contract.d.ts +17 -0
- package/dist/domain/threads/contract.js +59 -0
- package/dist/domain/threads/hook-runner.js +7 -6
- package/dist/domain/threads/index.d.ts +2 -0
- package/dist/domain/threads/index.js +3 -1
- package/dist/domain/threads/prompt-builder.d.ts +15 -1
- package/dist/domain/threads/prompt-builder.js +41 -2
- package/dist/domain/threads/runner.d.ts +6 -5
- package/dist/domain/threads/runner.js +128 -79
- package/dist/domain/threads/state-machine.d.ts +23 -21
- package/dist/domain/threads/state-machine.js +113 -54
- package/dist/domain/threads/template-loader.js +3 -2
- package/dist/domain/threads/tree.d.ts +45 -0
- package/dist/domain/threads/tree.js +171 -0
- package/dist/domain/tui-session/index.d.ts +2 -0
- package/dist/domain/tui-session/index.js +3 -0
- package/dist/domain/tui-session/tui-session-service.d.ts +2 -0
- package/dist/domain/tui-session/tui-session-service.js +103 -0
- package/dist/domain/tui-session/types.d.ts +67 -0
- package/dist/domain/tui-session/types.js +4 -0
- package/dist/domain/ui-service/index.d.ts +5 -0
- package/dist/domain/ui-service/index.js +3 -0
- package/dist/domain/ui-service/mutate/executions.d.ts +4 -0
- package/dist/domain/ui-service/mutate/executions.js +15 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +10 -0
- package/dist/domain/ui-service/mutate/schedules.js +39 -0
- package/dist/domain/ui-service/mutate/tasks.d.ts +23 -0
- package/dist/domain/ui-service/mutate/tasks.js +59 -0
- package/dist/domain/ui-service/mutate/threads.d.ts +4 -0
- package/dist/domain/ui-service/mutate/threads.js +21 -0
- package/dist/domain/ui-service/query/cost.d.ts +3 -0
- package/dist/domain/ui-service/query/cost.js +6 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -0
- package/dist/domain/ui-service/query/executions.js +35 -0
- package/dist/domain/ui-service/query/projects.d.ts +2 -0
- package/dist/domain/ui-service/query/projects.js +30 -0
- package/dist/domain/ui-service/query/schedules.d.ts +2 -0
- package/dist/domain/ui-service/query/schedules.js +23 -0
- package/dist/domain/ui-service/query/sessions.d.ts +2 -0
- package/dist/domain/ui-service/query/sessions.js +35 -0
- package/dist/domain/ui-service/query/tasks.d.ts +2 -0
- package/dist/domain/ui-service/query/tasks.js +30 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -0
- package/dist/domain/ui-service/query/threads.js +27 -0
- package/dist/domain/ui-service/subscribe.d.ts +5 -0
- package/dist/domain/ui-service/subscribe.js +118 -0
- package/dist/domain/ui-service/types.d.ts +237 -0
- package/dist/domain/ui-service/types.js +5 -0
- package/dist/domain/ui-service/ui-service.d.ts +2 -0
- package/dist/domain/ui-service/ui-service.js +83 -0
- package/dist/entry/app.js +94 -5
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +122 -12
- package/dist/entry/feishu-login.d.ts +28 -0
- package/dist/entry/feishu-login.js +218 -0
- package/dist/entry/init.d.ts +25 -2
- package/dist/entry/init.js +211 -64
- package/dist/events/event-types.d.ts +14 -0
- package/dist/hooks/cortex-md-injector.mjs +47 -31
- package/dist/hooks/post-task-hook.mjs +6 -0
- package/dist/hooks/task-status-check.mjs +8 -0
- package/dist/orchestration/agent-runner.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +55 -55
- package/dist/orchestration/conduit-queue.d.ts +18 -0
- package/dist/orchestration/conduit-queue.js +32 -0
- package/dist/orchestration/conversation-runner.d.ts +48 -0
- package/dist/orchestration/conversation-runner.js +109 -0
- package/dist/orchestration/dispatch-reconciler.js +8 -1
- package/dist/orchestration/interactions/ask-user-question.d.ts +1 -1
- package/dist/orchestration/interactions/ask-user-question.js +3 -3
- package/dist/orchestration/interactions/interaction-handlers.js +48 -17
- package/dist/orchestration/interactions/plan-handler.d.ts +2 -2
- package/dist/orchestration/interactions/plan-handler.js +4 -3
- package/dist/orchestration/interactions/update-prompt.d.ts +6 -0
- package/dist/orchestration/interactions/update-prompt.js +100 -0
- package/dist/orchestration/lifecycle.d.ts +4 -4
- package/dist/orchestration/lifecycle.js +24 -22
- package/dist/orchestration/orchestrator.d.ts +1 -1
- package/dist/orchestration/routing/commands/cancel.js +39 -47
- package/dist/orchestration/routing/commands/channel.js +24 -11
- package/dist/orchestration/routing/commands/cost.js +2 -1
- package/dist/orchestration/routing/commands/device.js +3 -2
- package/dist/orchestration/routing/commands/dispatch.js +6 -5
- package/dist/orchestration/routing/commands/index.d.ts +1 -1
- package/dist/orchestration/routing/commands/index.js +11 -10
- package/dist/orchestration/routing/commands/mode.js +19 -18
- package/dist/orchestration/routing/commands/nvtop.js +10 -9
- package/dist/orchestration/routing/commands/sendfile.js +7 -6
- package/dist/orchestration/routing/commands/session.d.ts +1 -1
- package/dist/orchestration/routing/commands/session.js +17 -33
- package/dist/orchestration/routing/commands/tail.js +4 -3
- package/dist/orchestration/routing/commands/task.js +4 -3
- package/dist/orchestration/routing/commands/thread-handlers.js +16 -6
- package/dist/orchestration/routing/edit-handler.js +8 -7
- package/dist/orchestration/routing/hook-bridge-subscribers.js +17 -1
- package/dist/orchestration/routing/message-router.d.ts +1 -1
- package/dist/orchestration/routing/message-router.js +9 -9
- package/dist/orchestration/routing/webhook.js +233 -2
- package/dist/orchestration/status-helpers.d.ts +5 -1
- package/dist/orchestration/status-helpers.js +7 -6
- package/dist/orchestration/thread-callback.d.ts +67 -0
- package/dist/orchestration/thread-callback.js +465 -0
- package/dist/orchestration/thread-executor.d.ts +22 -1
- package/dist/orchestration/thread-executor.js +85 -36
- package/dist/platform/adapter.d.ts +6 -2
- package/dist/platform/adapters/composite-adapter.d.ts +89 -0
- package/dist/platform/adapters/composite-adapter.js +318 -0
- package/dist/platform/adapters/feishu-output-stream.d.ts +26 -4
- package/dist/platform/adapters/feishu-output-stream.js +274 -36
- package/dist/platform/adapters/feishu.d.ts +50 -5
- package/dist/platform/adapters/feishu.js +370 -116
- package/dist/platform/adapters/index.d.ts +24 -3
- package/dist/platform/adapters/index.js +89 -11
- package/dist/platform/adapters/project-conduits.d.ts +9 -0
- package/dist/platform/adapters/project-conduits.js +42 -0
- package/dist/platform/adapters/slack-project-conduits.d.ts +1 -9
- package/dist/platform/adapters/slack-project-conduits.js +6 -40
- package/dist/platform/adapters/slack.d.ts +9 -2
- package/dist/platform/adapters/slack.js +83 -39
- package/dist/platform/adapters/tui/index.d.ts +9 -0
- package/dist/platform/adapters/tui/index.js +10 -0
- package/dist/platform/adapters/tui/ports.d.ts +20 -0
- package/dist/platform/adapters/tui/ports.js +4 -0
- package/dist/platform/adapters/tui/tui-conduit-state.d.ts +10 -0
- package/dist/platform/adapters/tui/tui-conduit-state.js +17 -0
- package/dist/platform/adapters/tui/tui-connection.d.ts +30 -0
- package/dist/platform/adapters/tui/tui-connection.js +53 -0
- package/dist/platform/adapters/tui/tui-gateway.d.ts +120 -0
- package/dist/platform/adapters/tui/tui-gateway.js +919 -0
- package/dist/platform/adapters/tui/tui-notifications.d.ts +12 -0
- package/dist/platform/adapters/tui/tui-notifications.js +60 -0
- package/dist/platform/adapters/tui/tui-output-stream.d.ts +36 -0
- package/dist/platform/adapters/tui/tui-output-stream.js +99 -0
- package/dist/platform/adapters/tui/tui-transcript.d.ts +8 -0
- package/dist/platform/adapters/tui/tui-transcript.js +56 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +2 -1
- package/dist/platform/interactive-builder.js +3 -2
- package/dist/platform/output-stream.d.ts +5 -0
- package/dist/platform/testing.d.ts +7 -11
- package/dist/platform/testing.js +18 -15
- package/dist/platform/tool-trace.js +15 -5
- package/dist/platform/tui/protocol.d.ts +355 -0
- package/dist/platform/tui/protocol.js +199 -0
- package/dist/platform/types.d.ts +12 -3
- package/dist/store/execution-repo.d.ts +6 -1
- package/dist/store/execution-repo.js +13 -3
- package/dist/store/hook-sync.d.ts +18 -0
- package/dist/store/hook-sync.js +92 -0
- package/dist/store/outbound-queue.js +2 -2
- package/dist/store/profile-repo.js +3 -2
- package/dist/store/schedule-repo.d.ts +1 -8
- package/dist/store/session-registry-repo.d.ts +9 -1
- package/dist/store/session-registry-repo.js +19 -3
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +23 -0
- package/dist/store/thread-repo.d.ts +3 -0
- package/dist/store/thread-repo.js +49 -2
- package/dist/store/version-migrations.js +95 -0
- package/dist/tui/App.d.ts +27 -0
- package/dist/tui/App.js +219 -0
- package/dist/tui/components/AskUserModal.d.ts +11 -0
- package/dist/tui/components/AskUserModal.js +364 -0
- package/dist/tui/components/ConfirmModal.d.ts +12 -0
- package/dist/tui/components/ConfirmModal.js +31 -0
- package/dist/tui/components/Dashboard.d.ts +23 -0
- package/dist/tui/components/Dashboard.js +80 -0
- package/dist/tui/components/DashboardCostTab.d.ts +7 -0
- package/dist/tui/components/DashboardCostTab.js +16 -0
- package/dist/tui/components/DashboardExecutionsTab.d.ts +11 -0
- package/dist/tui/components/DashboardExecutionsTab.js +94 -0
- package/dist/tui/components/DashboardSchedulesTab.d.ts +11 -0
- package/dist/tui/components/DashboardSchedulesTab.js +124 -0
- package/dist/tui/components/DashboardTasksTab.d.ts +12 -0
- package/dist/tui/components/DashboardTasksTab.js +200 -0
- package/dist/tui/components/DashboardThreadsTab.d.ts +11 -0
- package/dist/tui/components/DashboardThreadsTab.js +81 -0
- package/dist/tui/components/Header.d.ts +11 -0
- package/dist/tui/components/Header.js +5 -0
- package/dist/tui/components/InputBox.d.ts +10 -0
- package/dist/tui/components/InputBox.js +19 -0
- package/dist/tui/components/MessageRow.d.ts +7 -0
- package/dist/tui/components/MessageRow.js +10 -0
- package/dist/tui/components/Notifications.d.ts +19 -0
- package/dist/tui/components/Notifications.js +72 -0
- package/dist/tui/components/PlanFeedbackModal.d.ts +11 -0
- package/dist/tui/components/PlanFeedbackModal.js +161 -0
- package/dist/tui/components/ProjectSwitcher.d.ts +18 -0
- package/dist/tui/components/ProjectSwitcher.js +43 -0
- package/dist/tui/components/SessionPicker.d.ts +14 -0
- package/dist/tui/components/SessionPicker.js +34 -0
- package/dist/tui/components/SidePanel.d.ts +19 -0
- package/dist/tui/components/SidePanel.js +8 -0
- package/dist/tui/components/StatusLine.d.ts +10 -0
- package/dist/tui/components/StatusLine.js +29 -0
- package/dist/tui/components/Transcript.d.ts +13 -0
- package/dist/tui/components/Transcript.js +56 -0
- package/dist/tui/hooks/useDashboardData.d.ts +32 -0
- package/dist/tui/hooks/useDashboardData.js +104 -0
- package/dist/tui/hooks/useKeybindings.d.ts +19 -0
- package/dist/tui/hooks/useKeybindings.js +87 -0
- package/dist/tui/hooks/useMutate.d.ts +22 -0
- package/dist/tui/hooks/useMutate.js +56 -0
- package/dist/tui/hooks/useNotifications.d.ts +28 -0
- package/dist/tui/hooks/useNotifications.js +70 -0
- package/dist/tui/hooks/useTranscript.d.ts +39 -0
- package/dist/tui/hooks/useTranscript.js +265 -0
- package/dist/tui/hooks/useWsClient.d.ts +29 -0
- package/dist/tui/hooks/useWsClient.js +69 -0
- package/dist/tui/index.d.ts +2 -0
- package/dist/tui/index.js +210 -0
- package/dist/tui/logic.d.ts +16 -0
- package/dist/tui/logic.js +49 -0
- package/dist/tui/render/markdown.d.ts +10 -0
- package/dist/tui/render/markdown.js +38 -0
- package/dist/tui/render/rich-blocks.d.ts +11 -0
- package/dist/tui/render/rich-blocks.js +24 -0
- package/dist/tui/ws-client.d.ts +44 -0
- package/dist/tui/ws-client.js +157 -0
- package/package.json +11 -3
- package/dist/orchestration/channel-queue.d.ts +0 -18
- package/dist/orchestration/channel-queue.js +0 -32
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// input: DATA_DIR
|
|
2
2
|
// output: PI_AGENT_DIR / PI_SESSIONS_DIR / PI_MODELS_PATH constants
|
|
3
|
-
// + writeProvidersConfig (multi-provider models.json override
|
|
3
|
+
// + writeProvidersConfig (multi-provider models.json override; re-asserts PI compat
|
|
4
|
+
// flags lost when baseUrl is rewritten to the gateway — see PROVIDER_COMPAT_OVERRIDES,
|
|
5
|
+
// e.g. deepseek supportsDeveloperRole=false to avoid HTTP 400 on the `developer` role)
|
|
6
|
+
// + buildProviderOverrides (routing-driven override set: discovered ∪ current provider)
|
|
4
7
|
// + ensureAuthVisible (symlink user's ~/.pi/agent/auth.json into PI_AGENT_DIR
|
|
5
8
|
// so the PI subprocess can resolve OAuth/API key credentials)
|
|
6
9
|
// + ensurePIAgentDirs
|
|
@@ -20,6 +23,18 @@ export const PI_SESSIONS_DIR = path.join(DATA_DIR, 'logs', 'sessions-pi');
|
|
|
20
23
|
export const PI_MODELS_PATH = path.join(PI_AGENT_DIR, 'models.json');
|
|
21
24
|
/** Default location of the user's PI OAuth/API-key credentials. */
|
|
22
25
|
const USER_PI_AUTH_PATH = path.join(os.homedir(), '.pi', 'agent', 'auth.json');
|
|
26
|
+
/**
|
|
27
|
+
* PI compat flags that PI auto-detects from the provider's *real* endpoint URL but loses once
|
|
28
|
+
* cortex rewrites `baseUrl` to the gateway. PI's `detectCompat()` keys `supportsDeveloperRole`
|
|
29
|
+
* off `baseUrl.includes("deepseek.com")` ONLY (not the provider name), so routing DeepSeek
|
|
30
|
+
* through `http://127.0.0.1:9880/deepseek` makes PI wrongly assume the endpoint accepts the
|
|
31
|
+
* OpenAI `developer` system-prompt role — DeepSeek's API rejects it with HTTP 400 (empty output).
|
|
32
|
+
* We re-assert the lost flags here, keyed by PI provider name (the override preserves the name).
|
|
33
|
+
* Add a row here if another gateway-routed provider exhibits the same URL-detection loss.
|
|
34
|
+
*/
|
|
35
|
+
const PROVIDER_COMPAT_OVERRIDES = {
|
|
36
|
+
deepseek: { supportsDeveloperRole: false },
|
|
37
|
+
};
|
|
23
38
|
/**
|
|
24
39
|
* Atomic-write models.json with multi-provider baseUrl overrides. Each provider entry has a
|
|
25
40
|
* `baseUrl` pointing to `<gatewayUrl><basePath>`; no apiKey is written so PI resolves credentials
|
|
@@ -32,7 +47,15 @@ export function writeProvidersConfig(providers, gatewayUrl, opts) {
|
|
|
32
47
|
const providersBlock = {};
|
|
33
48
|
for (const p of providers) {
|
|
34
49
|
const basePath = p.basePath ?? `/${p.name}`;
|
|
35
|
-
|
|
50
|
+
const entry = {
|
|
51
|
+
baseUrl: `${gatewayUrl}${basePath}`,
|
|
52
|
+
};
|
|
53
|
+
// Re-assert compat flags PI can no longer auto-detect now that baseUrl is the gateway.
|
|
54
|
+
// Static table first, then per-override compat (explicit wins).
|
|
55
|
+
const compat = { ...PROVIDER_COMPAT_OVERRIDES[p.name], ...p.compat };
|
|
56
|
+
if (Object.keys(compat).length > 0)
|
|
57
|
+
entry.compat = compat;
|
|
58
|
+
providersBlock[p.name] = entry;
|
|
36
59
|
}
|
|
37
60
|
const data = { providers: providersBlock };
|
|
38
61
|
const content = JSON.stringify(data, null, 2) + '\n';
|
|
@@ -53,6 +76,34 @@ export function writeProvidersConfig(providers, gatewayUrl, opts) {
|
|
|
53
76
|
throw err;
|
|
54
77
|
}
|
|
55
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Compute the set of PI providers whose baseUrl should be overridden to the gateway for a spawn.
|
|
81
|
+
*
|
|
82
|
+
* Design: "route through gateway" and "PI has credentials" are independent concerns. Discovery
|
|
83
|
+
* (`pi --list-models`) only reports providers the user is authenticated to, but a profile may
|
|
84
|
+
* legitimately route a provider through the gateway even without direct PI credentials (the
|
|
85
|
+
* gateway injects managed keys). So the override set is the union of:
|
|
86
|
+
* - `discovered` — providers PI reports creds for (credential passthrough via auth.json)
|
|
87
|
+
* - `currentProvider` — the provider THIS spawn uses (`--provider`); it MUST be routed, always
|
|
88
|
+
*
|
|
89
|
+
* `gatewayPath`, when set, becomes the current provider's `basePath` (decouples the gateway route
|
|
90
|
+
* from the provider name — e.g. provider "anthropic" landing on "/deepseek-anthropic"). It wins
|
|
91
|
+
* over the default `/<name>` even if the current provider was also discovered.
|
|
92
|
+
*/
|
|
93
|
+
export function buildProviderOverrides(discovered, currentProvider, gatewayPath) {
|
|
94
|
+
const byName = new Map();
|
|
95
|
+
for (const name of discovered) {
|
|
96
|
+
if (!byName.has(name))
|
|
97
|
+
byName.set(name, { name });
|
|
98
|
+
}
|
|
99
|
+
if (currentProvider) {
|
|
100
|
+
byName.set(currentProvider, {
|
|
101
|
+
name: currentProvider,
|
|
102
|
+
...(gatewayPath ? { basePath: gatewayPath } : {}),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return Array.from(byName.values());
|
|
106
|
+
}
|
|
56
107
|
/**
|
|
57
108
|
* Make the user's PI OAuth/API-key credentials visible to the PI subprocess running under
|
|
58
109
|
* cortex's PI_CODING_AGENT_DIR. Uses symlink on Linux/macOS so PI's automatic OAuth refresh
|
|
@@ -233,11 +233,19 @@ function handleAgentEnd(ev) {
|
|
|
233
233
|
let model = '';
|
|
234
234
|
let tokensIn = 0;
|
|
235
235
|
let tokensOut = 0;
|
|
236
|
+
// Turn-level error: PI marks a failed assistant message with stopReason "error" (e.g. a gateway
|
|
237
|
+
// 400). This mirrors Claude's result.is_error — captured here so the adapter can fail the turn
|
|
238
|
+
// instead of silently resolving it as success.
|
|
239
|
+
let turnError = null;
|
|
236
240
|
for (const msg of msgs) {
|
|
237
241
|
const mr = asRecord(msg);
|
|
238
242
|
if (mr['role'] !== 'assistant')
|
|
239
243
|
continue;
|
|
240
244
|
numTurns++;
|
|
245
|
+
if (turnError === null && mr['stopReason'] === 'error') {
|
|
246
|
+
const em = mr['errorMessage'];
|
|
247
|
+
turnError = typeof em === 'string' && em.length > 0 ? em : 'PI agent reported an error during execution';
|
|
248
|
+
}
|
|
241
249
|
// First assistant message with a non-empty provider wins
|
|
242
250
|
if (provider === '' && typeof mr['provider'] === 'string' && mr['provider'].length > 0) {
|
|
243
251
|
provider = mr['provider'];
|
|
@@ -268,7 +276,11 @@ function handleAgentEnd(ev) {
|
|
|
268
276
|
if (provider !== '') {
|
|
269
277
|
result.push({ type: 'cost_record', provider, model, tokens_in: tokensIn, tokens_out: tokensOut, cost_usd: totalCostUsd });
|
|
270
278
|
}
|
|
271
|
-
|
|
279
|
+
// Only attach `error` when the turn actually failed, so success events stay minimal and existing
|
|
280
|
+
// deepEqual assertions on turn_complete keep passing.
|
|
281
|
+
result.push(turnError !== null
|
|
282
|
+
? { type: 'turn_complete', numTurns, totalCostUsd, error: turnError }
|
|
283
|
+
: { type: 'turn_complete', numTurns, totalCostUsd });
|
|
272
284
|
return result;
|
|
273
285
|
}
|
|
274
286
|
function handleExtensionUiRequest(ev) {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { ExtensionAPI } from './pi-ext-types.js';
|
|
2
|
+
/** The cortex-slack server (slack_send_file tool) is loaded only for sessions that originate from
|
|
3
|
+
* Slack. The PI adapter forwards the source channel into the subprocess env as SLACK_CHANNEL; the
|
|
4
|
+
* SlackAdapter tags its conduits with the `slack:` prefix, so that prefix is the source marker. */
|
|
5
|
+
export declare function shouldLoadSlack(channel: string | undefined): boolean;
|
|
6
|
+
/** The cortex-feishu server (Feishu document tools) is loaded only for sessions that originate from
|
|
7
|
+
* Feishu. The PI adapter forwards the source channel into the subprocess env as SLACK_CHANNEL; the
|
|
8
|
+
* FeishuAdapter tags its conduits with the `feishu:` prefix, so that prefix is the source marker. */
|
|
9
|
+
export declare function shouldLoadFeishu(channel: string | undefined): boolean;
|
|
2
10
|
type PiTextContent = {
|
|
3
11
|
type: 'text';
|
|
4
12
|
text: string;
|
|
@@ -20,7 +28,11 @@ export declare function mapMcpContent(item: {
|
|
|
20
28
|
export default function mcpBridge(pi: ExtensionAPI): Promise<void>;
|
|
21
29
|
export declare const _test: {
|
|
22
30
|
mapMcpContent: typeof mapMcpContent;
|
|
31
|
+
shouldLoadSlack: typeof shouldLoadSlack;
|
|
32
|
+
shouldLoadFeishu: typeof shouldLoadFeishu;
|
|
23
33
|
CORE_SERVER_PATH: string;
|
|
24
34
|
EXT_SERVER_PATH: string;
|
|
35
|
+
SLACK_SERVER_PATH: string;
|
|
36
|
+
FEISHU_SERVER_PATH: string;
|
|
25
37
|
};
|
|
26
38
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// input: PI ExtensionAPI, @modelcontextprotocol/sdk, core-server.ts + server.ts
|
|
2
|
-
// output: Register Cortex MCP tools (core + ext) into the PI tool table and forward calls transparently
|
|
3
|
-
// pos: PI --extension bridging
|
|
2
|
+
// output: Register Cortex MCP tools (core + ext, + feishu for Feishu-originated sessions) into the PI tool table and forward calls transparently
|
|
3
|
+
// pos: PI --extension bridging the Cortex MCP servers
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
6
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
@@ -12,10 +12,24 @@ import { fileURLToPath } from 'node:url';
|
|
|
12
12
|
// eslint-disable-next-line no-undef
|
|
13
13
|
const _dirname = (typeof __dirname === 'string' ? __dirname : null) ?? dirname(fileURLToPath(import.meta.url));
|
|
14
14
|
// Once compiled, this file lives at dist/agent-adapter/pi/mcp-bridge.js; sibling MCP servers
|
|
15
|
-
// live at dist/domain/mcp/{core-server,server}.js. Point at the compiled .js so the
|
|
16
|
-
// package (which does not ship src/) can locate them.
|
|
15
|
+
// live at dist/domain/mcp/{core-server,server,slack-server,feishu-server}.js. Point at the compiled .js so the
|
|
16
|
+
// installed package (which does not ship src/) can locate them.
|
|
17
17
|
const CORE_SERVER_PATH = resolve(_dirname, '../../domain/mcp/core-server.js');
|
|
18
18
|
const EXT_SERVER_PATH = resolve(_dirname, '../../domain/mcp/server.js');
|
|
19
|
+
const SLACK_SERVER_PATH = resolve(_dirname, '../../domain/mcp/slack-server.js');
|
|
20
|
+
const FEISHU_SERVER_PATH = resolve(_dirname, '../../domain/mcp/feishu-server.js');
|
|
21
|
+
/** The cortex-slack server (slack_send_file tool) is loaded only for sessions that originate from
|
|
22
|
+
* Slack. The PI adapter forwards the source channel into the subprocess env as SLACK_CHANNEL; the
|
|
23
|
+
* SlackAdapter tags its conduits with the `slack:` prefix, so that prefix is the source marker. */
|
|
24
|
+
export function shouldLoadSlack(channel) {
|
|
25
|
+
return !!channel && channel.startsWith('slack:');
|
|
26
|
+
}
|
|
27
|
+
/** The cortex-feishu server (Feishu document tools) is loaded only for sessions that originate from
|
|
28
|
+
* Feishu. The PI adapter forwards the source channel into the subprocess env as SLACK_CHANNEL; the
|
|
29
|
+
* FeishuAdapter tags its conduits with the `feishu:` prefix, so that prefix is the source marker. */
|
|
30
|
+
export function shouldLoadFeishu(channel) {
|
|
31
|
+
return !!channel && channel.startsWith('feishu:');
|
|
32
|
+
}
|
|
19
33
|
/** Map an MCP CallToolResult content item to a PI text content item. */
|
|
20
34
|
export function mapMcpContent(item) {
|
|
21
35
|
if (item.type === 'text' && typeof item.text === 'string') {
|
|
@@ -48,6 +62,7 @@ async function spawnMcpClient(serverPath, serverName) {
|
|
|
48
62
|
...process.env,
|
|
49
63
|
SLACK_BOT_TOKEN: process.env.SLACK_BOT_TOKEN || '',
|
|
50
64
|
SLACK_CHANNEL: process.env.SLACK_CHANNEL || '',
|
|
65
|
+
FEISHU_CHANNEL: process.env.SLACK_CHANNEL || '',
|
|
51
66
|
},
|
|
52
67
|
});
|
|
53
68
|
const client = new Client({ name: `pi-mcp-bridge-${serverName}`, version: '1.0.0' });
|
|
@@ -58,18 +73,29 @@ async function spawnMcpClient(serverPath, serverName) {
|
|
|
58
73
|
export default async function mcpBridge(pi) {
|
|
59
74
|
let coreHandle = null;
|
|
60
75
|
let extHandle = null;
|
|
76
|
+
let slackHandle = null;
|
|
77
|
+
let feishuHandle = null;
|
|
61
78
|
let toolsRegistered = false;
|
|
79
|
+
// The source channel is forwarded by the PI adapter as SLACK_CHANNEL (see pi/adapter.ts spawn env).
|
|
80
|
+
const loadSlack = shouldLoadSlack(process.env.SLACK_CHANNEL);
|
|
81
|
+
const loadFeishu = shouldLoadFeishu(process.env.SLACK_CHANNEL);
|
|
62
82
|
async function ensureAllConnected() {
|
|
63
|
-
if (coreHandle && extHandle)
|
|
64
|
-
return;
|
|
65
83
|
// Spawn core server (remote_* tools) — always loaded
|
|
66
84
|
if (!coreHandle) {
|
|
67
85
|
coreHandle = await spawnMcpClient(CORE_SERVER_PATH, 'core').catch(() => null);
|
|
68
86
|
}
|
|
69
|
-
// Spawn ext server (everything else:
|
|
87
|
+
// Spawn ext server (everything else: cost, context, schedule)
|
|
70
88
|
if (!extHandle) {
|
|
71
89
|
extHandle = await spawnMcpClient(EXT_SERVER_PATH, 'ext').catch(() => null);
|
|
72
90
|
}
|
|
91
|
+
// Spawn slack server (slack_send_file tool) only for Slack-originated sessions.
|
|
92
|
+
if (loadSlack && !slackHandle) {
|
|
93
|
+
slackHandle = await spawnMcpClient(SLACK_SERVER_PATH, 'slack').catch(() => null);
|
|
94
|
+
}
|
|
95
|
+
// Spawn feishu server (Feishu document tools) only for Feishu-originated sessions.
|
|
96
|
+
if (loadFeishu && !feishuHandle) {
|
|
97
|
+
feishuHandle = await spawnMcpClient(FEISHU_SERVER_PATH, 'feishu').catch(() => null);
|
|
98
|
+
}
|
|
73
99
|
}
|
|
74
100
|
async function registerToolsFrom(handle) {
|
|
75
101
|
let toolList;
|
|
@@ -112,15 +138,21 @@ export default async function mcpBridge(pi) {
|
|
|
112
138
|
// Register from core server (remote_*)
|
|
113
139
|
if (coreHandle)
|
|
114
140
|
await registerToolsFrom(coreHandle);
|
|
115
|
-
// Register from ext server (
|
|
141
|
+
// Register from ext server (cost, context, schedule)
|
|
116
142
|
if (extHandle)
|
|
117
143
|
await registerToolsFrom(extHandle);
|
|
144
|
+
// Register from slack server (slack_send_file) — Slack-originated sessions only
|
|
145
|
+
if (slackHandle)
|
|
146
|
+
await registerToolsFrom(slackHandle);
|
|
147
|
+
// Register from feishu server (Feishu document tools) — Feishu-originated sessions only
|
|
148
|
+
if (feishuHandle)
|
|
149
|
+
await registerToolsFrom(feishuHandle);
|
|
118
150
|
toolsRegistered = true;
|
|
119
151
|
});
|
|
120
152
|
// Clean up MCP subprocesses when the PI session ends.
|
|
121
153
|
pi.on('session_shutdown', async (_event, _ctx) => {
|
|
122
154
|
toolsRegistered = false;
|
|
123
|
-
for (const h of [coreHandle, extHandle]) {
|
|
155
|
+
for (const h of [coreHandle, extHandle, slackHandle, feishuHandle]) {
|
|
124
156
|
if (h) {
|
|
125
157
|
try {
|
|
126
158
|
await h.transport.close();
|
|
@@ -130,11 +162,17 @@ export default async function mcpBridge(pi) {
|
|
|
130
162
|
}
|
|
131
163
|
coreHandle = null;
|
|
132
164
|
extHandle = null;
|
|
165
|
+
slackHandle = null;
|
|
166
|
+
feishuHandle = null;
|
|
133
167
|
});
|
|
134
168
|
}
|
|
135
169
|
// Exported for tests
|
|
136
170
|
export const _test = {
|
|
137
171
|
mapMcpContent,
|
|
172
|
+
shouldLoadSlack,
|
|
173
|
+
shouldLoadFeishu,
|
|
138
174
|
CORE_SERVER_PATH,
|
|
139
175
|
EXT_SERVER_PATH,
|
|
176
|
+
SLACK_SERVER_PATH,
|
|
177
|
+
FEISHU_SERVER_PATH,
|
|
140
178
|
};
|
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
import type { ExtensionAPI } from './pi-ext-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build a predicate that decides whether a pseudo-tool (identified by its Claude-native label,
|
|
4
|
+
* e.g. "ExitPlanMode") may be registered, given the agent's tool allowlist.
|
|
5
|
+
*
|
|
6
|
+
* `allowedToolsEnv` mirrors the agent's `tools` config in Claude-native, comma-separated form —
|
|
7
|
+
* the PI adapter forwards it via the CORTEX_PI_ALLOWED_TOOLS env var, exactly the same allowlist
|
|
8
|
+
* the Claude backend passes to `--tools`. When unset/empty (interactive sessions, or callers that
|
|
9
|
+
* don't constrain tools) ALL pseudo-tools are allowed, preserving prior behavior.
|
|
10
|
+
*
|
|
11
|
+
* This is what stops thread-dispatched agents (coder, reviewer, …) from being handed
|
|
12
|
+
* AskUserQuestion / EnterPlanMode / ExitPlanMode — interaction tools that deadlock a headless
|
|
13
|
+
* thread because no human can ever answer the approval prompt.
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeToolGate(allowedToolsEnv: string | undefined): (label: string) => boolean;
|
|
2
16
|
export default function toolShims(pi: ExtensionAPI): void;
|