@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,14 +1,17 @@
|
|
|
1
1
|
// input: AgentHandle-like kill function, EventBus
|
|
2
|
-
// output: RunningExecutions singleton —
|
|
3
|
-
// pos: orch/ layer, encapsulates
|
|
4
|
-
//
|
|
2
|
+
// output: RunningExecutions singleton — executionId-keyed registry with channel/thread secondary indices
|
|
3
|
+
// pos: orch/ layer, encapsulates the in-memory live-execution registry + publishes agent.* lifecycle events
|
|
4
|
+
//
|
|
5
|
+
// Primary key is the executionId (globally unique), so multiple live executions can coexist on one
|
|
6
|
+
// channel without evicting each other (the P3 fix). channel and threadId are secondary lookup indices.
|
|
7
|
+
// An ad-hoc string registryKey is supported for executions with no executionId (rare).
|
|
5
8
|
export class RunningExecutions {
|
|
6
|
-
/** Primary index: key is
|
|
9
|
+
/** Primary index: key is executionId (or ad-hoc registryKey when executionId is null). */
|
|
7
10
|
byKey = new Map();
|
|
8
11
|
/** Secondary index: threadId → RunningExecution, only if threadId is non-null. */
|
|
9
12
|
byThreadId = new Map();
|
|
10
|
-
/** Secondary index:
|
|
11
|
-
|
|
13
|
+
/** Secondary index: channel → set of RunningExecutions on that channel. */
|
|
14
|
+
byChannel = new Map();
|
|
12
15
|
/** EventBus for publishing agent.* lifecycle events. May be set after construction. */
|
|
13
16
|
_bus = null;
|
|
14
17
|
constructor(bus) {
|
|
@@ -19,27 +22,42 @@ export class RunningExecutions {
|
|
|
19
22
|
this._bus = bus;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
|
-
* Register a
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Publishes agent.started if executionId is non-null and bus is wired.
|
|
25
|
+
* Register a live execution, keyed by its executionId (or an ad-hoc registryKey).
|
|
26
|
+
* Returns the primary key. Secondary indices (byThreadId / byChannel) are kept in sync.
|
|
27
|
+
* Publishes agent.started if executionId is non-null and a bus is wired.
|
|
26
28
|
*/
|
|
27
|
-
register(
|
|
28
|
-
|
|
29
|
+
register(exec) {
|
|
30
|
+
const key = exec.executionId ?? exec.registryKey;
|
|
31
|
+
if (!key)
|
|
32
|
+
throw new Error('RunningExecutions.register requires an executionId or registryKey');
|
|
33
|
+
// Replace any existing entry at this key (same executionId re-registered) — keeps indices clean.
|
|
29
34
|
const existing = this.byKey.get(key);
|
|
30
|
-
if (existing)
|
|
35
|
+
if (existing)
|
|
31
36
|
this._removeFromIndices(existing);
|
|
32
|
-
}
|
|
33
37
|
const entry = {
|
|
34
|
-
|
|
38
|
+
threadId: exec.threadId,
|
|
39
|
+
channel: exec.channel,
|
|
35
40
|
registryKey: key,
|
|
41
|
+
agentSlotId: exec.agentSlotId,
|
|
42
|
+
executionId: exec.executionId,
|
|
43
|
+
kind: exec.kind ?? null,
|
|
44
|
+
kill: exec.kill,
|
|
36
45
|
startTime: Date.now(),
|
|
46
|
+
backend: exec.backend,
|
|
47
|
+
agentProcess: exec.agentProcess,
|
|
48
|
+
sessionId: exec.sessionId,
|
|
37
49
|
};
|
|
38
50
|
this.byKey.set(key, entry);
|
|
39
51
|
if (entry.threadId)
|
|
40
52
|
this.byThreadId.set(entry.threadId, entry);
|
|
41
|
-
if (entry.
|
|
42
|
-
this.
|
|
53
|
+
if (entry.channel) {
|
|
54
|
+
let set = this.byChannel.get(entry.channel);
|
|
55
|
+
if (!set) {
|
|
56
|
+
set = new Set();
|
|
57
|
+
this.byChannel.set(entry.channel, set);
|
|
58
|
+
}
|
|
59
|
+
set.add(entry);
|
|
60
|
+
}
|
|
43
61
|
if (this._bus && entry.executionId) {
|
|
44
62
|
this._bus.publish({
|
|
45
63
|
type: 'agent.started',
|
|
@@ -48,39 +66,48 @@ export class RunningExecutions {
|
|
|
48
66
|
backend: entry.backend,
|
|
49
67
|
});
|
|
50
68
|
}
|
|
69
|
+
return key;
|
|
51
70
|
}
|
|
52
|
-
/** Look up an execution by its primary
|
|
53
|
-
|
|
54
|
-
return this.byKey.get(
|
|
71
|
+
/** Look up an execution by its primary key (executionId or ad-hoc registryKey). */
|
|
72
|
+
getById(id) {
|
|
73
|
+
return this.byKey.get(id) ?? null;
|
|
55
74
|
}
|
|
56
|
-
/**
|
|
75
|
+
/** Returns true if an execution is registered under the given id/key. */
|
|
76
|
+
hasId(id) {
|
|
77
|
+
return this.byKey.has(id);
|
|
78
|
+
}
|
|
79
|
+
/** Look up an execution by threadId. Returns null if not found. */
|
|
57
80
|
getByThreadId(threadId) {
|
|
58
81
|
return this.byThreadId.get(threadId) ?? null;
|
|
59
82
|
}
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
83
|
+
/** Return all live executions registered on a channel (empty array if none). */
|
|
84
|
+
getByChannel(channel) {
|
|
85
|
+
const set = this.byChannel.get(channel);
|
|
86
|
+
return set ? Array.from(set) : [];
|
|
87
|
+
}
|
|
88
|
+
/** Returns true if at least one live execution is registered on the channel. */
|
|
89
|
+
hasChannel(channel) {
|
|
90
|
+
const set = this.byChannel.get(channel);
|
|
91
|
+
return !!set && set.size > 0;
|
|
63
92
|
}
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
return this.byKey.
|
|
93
|
+
/** Return all registered executions (snapshot of the primary index). */
|
|
94
|
+
getAll() {
|
|
95
|
+
return Array.from(this.byKey.values());
|
|
67
96
|
}
|
|
68
97
|
/**
|
|
69
|
-
* Kill the execution for
|
|
70
|
-
* Returns false if no entry is registered for the
|
|
98
|
+
* Kill the execution for an id, remove it from all indices, and return the result of kill().
|
|
99
|
+
* Returns false if no entry is registered for the id.
|
|
71
100
|
*/
|
|
72
|
-
|
|
73
|
-
const entry = this.byKey.get(
|
|
101
|
+
killById(id) {
|
|
102
|
+
const entry = this.byKey.get(id);
|
|
74
103
|
if (!entry)
|
|
75
104
|
return false;
|
|
76
105
|
const killed = entry.kill();
|
|
77
|
-
this.
|
|
78
|
-
this.byKey.delete(key);
|
|
106
|
+
this._delete(entry);
|
|
79
107
|
return killed;
|
|
80
108
|
}
|
|
81
109
|
/**
|
|
82
110
|
* Kill the execution for a threadId, remove it from all indices, and return true.
|
|
83
|
-
* Resolves through byThreadId secondary index.
|
|
84
111
|
* Returns false if no entry has that threadId.
|
|
85
112
|
*/
|
|
86
113
|
killByThreadId(threadId) {
|
|
@@ -88,36 +115,37 @@ export class RunningExecutions {
|
|
|
88
115
|
if (!entry)
|
|
89
116
|
return false;
|
|
90
117
|
entry.kill();
|
|
91
|
-
this.
|
|
92
|
-
this.byKey.delete(entry.registryKey);
|
|
118
|
+
this._delete(entry);
|
|
93
119
|
return true;
|
|
94
120
|
}
|
|
121
|
+
/** Kill every execution on a channel; returns the number killed. */
|
|
122
|
+
killByChannel(channel) {
|
|
123
|
+
const entries = this.getByChannel(channel);
|
|
124
|
+
for (const entry of entries) {
|
|
125
|
+
entry.kill();
|
|
126
|
+
this._delete(entry);
|
|
127
|
+
}
|
|
128
|
+
return entries.length;
|
|
129
|
+
}
|
|
95
130
|
/**
|
|
96
|
-
* Remove an execution by
|
|
97
|
-
* No-op if the
|
|
131
|
+
* Remove an execution by id without calling kill() or publishing events.
|
|
132
|
+
* No-op if the id is not registered.
|
|
98
133
|
*/
|
|
99
|
-
remove(
|
|
100
|
-
const entry = this.byKey.get(
|
|
134
|
+
remove(id) {
|
|
135
|
+
const entry = this.byKey.get(id);
|
|
101
136
|
if (!entry)
|
|
102
137
|
return;
|
|
103
|
-
this.
|
|
104
|
-
this.byKey.delete(key);
|
|
105
|
-
}
|
|
106
|
-
/** Return all registered executions (snapshot of the primary index). */
|
|
107
|
-
getAll() {
|
|
108
|
-
return Array.from(this.byKey.values());
|
|
138
|
+
this._delete(entry);
|
|
109
139
|
}
|
|
110
140
|
/**
|
|
111
|
-
* Mark the execution for
|
|
112
|
-
* Returns false if no entry is registered
|
|
113
|
-
* Publishes agent.completed only if executionId is non-null and bus is wired.
|
|
141
|
+
* Mark the execution for an id as completed and publish agent.completed.
|
|
142
|
+
* Returns false if no entry is registered (e.g., already removed).
|
|
114
143
|
*/
|
|
115
|
-
complete(
|
|
116
|
-
const entry = this.byKey.get(
|
|
144
|
+
complete(id, costUsd = 0) {
|
|
145
|
+
const entry = this.byKey.get(id);
|
|
117
146
|
if (!entry)
|
|
118
147
|
return false;
|
|
119
|
-
this.
|
|
120
|
-
this.byKey.delete(key);
|
|
148
|
+
this._delete(entry);
|
|
121
149
|
if (this._bus && entry.executionId) {
|
|
122
150
|
this._bus.publish({
|
|
123
151
|
type: 'agent.completed',
|
|
@@ -129,16 +157,14 @@ export class RunningExecutions {
|
|
|
129
157
|
return true;
|
|
130
158
|
}
|
|
131
159
|
/**
|
|
132
|
-
* Mark the execution for
|
|
133
|
-
* Returns false if no entry is registered
|
|
134
|
-
* Publishes agent.failed only if executionId is non-null and bus is wired.
|
|
160
|
+
* Mark the execution for an id as failed and publish agent.failed.
|
|
161
|
+
* Returns false if no entry is registered (e.g., already removed).
|
|
135
162
|
*/
|
|
136
|
-
fail(
|
|
137
|
-
const entry = this.byKey.get(
|
|
163
|
+
fail(id, error) {
|
|
164
|
+
const entry = this.byKey.get(id);
|
|
138
165
|
if (!entry)
|
|
139
166
|
return false;
|
|
140
|
-
this.
|
|
141
|
-
this.byKey.delete(key);
|
|
167
|
+
this._delete(entry);
|
|
142
168
|
if (this._bus && entry.executionId) {
|
|
143
169
|
this._bus.publish({
|
|
144
170
|
type: 'agent.failed',
|
|
@@ -149,17 +175,15 @@ export class RunningExecutions {
|
|
|
149
175
|
return true;
|
|
150
176
|
}
|
|
151
177
|
/**
|
|
152
|
-
* Kill the execution for
|
|
153
|
-
* Returns false if no entry is registered for the
|
|
154
|
-
* Publishes agent.superseded only if executionId is non-null and bus is wired.
|
|
178
|
+
* Kill the execution for an id, remove it, and publish agent.superseded.
|
|
179
|
+
* Returns false if no entry is registered for the id.
|
|
155
180
|
*/
|
|
156
|
-
supersede(
|
|
157
|
-
const entry = this.byKey.get(
|
|
181
|
+
supersede(id, reason) {
|
|
182
|
+
const entry = this.byKey.get(id);
|
|
158
183
|
if (!entry)
|
|
159
184
|
return false;
|
|
160
185
|
entry.kill();
|
|
161
|
-
this.
|
|
162
|
-
this.byKey.delete(key);
|
|
186
|
+
this._delete(entry);
|
|
163
187
|
if (this._bus && entry.executionId) {
|
|
164
188
|
this._bus.publish({
|
|
165
189
|
type: 'agent.superseded',
|
|
@@ -169,17 +193,40 @@ export class RunningExecutions {
|
|
|
169
193
|
}
|
|
170
194
|
return true;
|
|
171
195
|
}
|
|
196
|
+
/** Supersede (kill + event) every execution on a channel; returns the number superseded. */
|
|
197
|
+
supersedeByChannel(channel, reason) {
|
|
198
|
+
const entries = this.getByChannel(channel);
|
|
199
|
+
for (const entry of entries) {
|
|
200
|
+
entry.kill();
|
|
201
|
+
this._delete(entry);
|
|
202
|
+
if (this._bus && entry.executionId) {
|
|
203
|
+
this._bus.publish({ type: 'agent.superseded', executionId: entry.executionId, reason });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return entries.length;
|
|
207
|
+
}
|
|
208
|
+
/** Delete an entry from the primary map and all secondary indices. */
|
|
209
|
+
_delete(entry) {
|
|
210
|
+
this.byKey.delete(entry.registryKey);
|
|
211
|
+
this._removeFromIndices(entry);
|
|
212
|
+
}
|
|
172
213
|
/**
|
|
173
|
-
* Remove an entry from secondary indices (byThreadId /
|
|
174
|
-
* Guards each delete with identity check: only clears the index if it still points
|
|
175
|
-
* to this entry
|
|
176
|
-
*
|
|
214
|
+
* Remove an entry from secondary indices (byThreadId / byChannel).
|
|
215
|
+
* Guards each delete with an identity check: only clears the index if it still points
|
|
216
|
+
* to this entry, preventing corruption when a stale entry (whose threadId has been
|
|
217
|
+
* claimed by a newer entry) is removed.
|
|
177
218
|
*/
|
|
178
219
|
_removeFromIndices(entry) {
|
|
179
220
|
if (entry.threadId && this.byThreadId.get(entry.threadId) === entry)
|
|
180
221
|
this.byThreadId.delete(entry.threadId);
|
|
181
|
-
if (entry.
|
|
182
|
-
this.
|
|
222
|
+
if (entry.channel) {
|
|
223
|
+
const set = this.byChannel.get(entry.channel);
|
|
224
|
+
if (set) {
|
|
225
|
+
set.delete(entry);
|
|
226
|
+
if (set.size === 0)
|
|
227
|
+
this.byChannel.delete(entry.channel);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
183
230
|
}
|
|
184
231
|
}
|
|
185
232
|
/** Singleton instance of RunningExecutions. */
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Probe whether a PID is alive. Signal 0 performs the permission/existence check
|
|
2
|
+
* without actually delivering a signal; a throw (ESRCH/EPERM-as-dead handled by caller)
|
|
3
|
+
* means the process is not addressable as a live, signalable target. */
|
|
4
|
+
export declare function isProcessAlive(pid: number): boolean;
|
|
5
|
+
export interface AcquireResult {
|
|
6
|
+
acquired: boolean;
|
|
7
|
+
/** Set when acquired === true: whether a stale/corrupt lock was reclaimed. */
|
|
8
|
+
stale?: boolean;
|
|
9
|
+
/** Set when acquired === false: the PID currently holding the lock. */
|
|
10
|
+
holderPid?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Attempt to take a PID-file singleton lock.
|
|
14
|
+
* - File missing → write own pid, { acquired: true, stale: false }
|
|
15
|
+
* - File holds a live, valid pid → { acquired: false, holderPid }
|
|
16
|
+
* - File holds a dead/corrupt pid → overwrite with own pid, { acquired: true, stale: true }
|
|
17
|
+
*
|
|
18
|
+
* This function never exits the process or logs — the caller decides how to react to a
|
|
19
|
+
* conflict (typically: log a message and process.exit(1)).
|
|
20
|
+
*/
|
|
21
|
+
export declare function tryAcquireSingletonLock(pidFile: string): AcquireResult;
|
|
22
|
+
/** Release the lock iff it is still owned by the current process. Best-effort; swallows errors. */
|
|
23
|
+
export declare function releaseSingletonLock(pidFile: string): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// input: a pidfile path
|
|
2
|
+
// output: tryAcquireSingletonLock / releaseSingletonLock / isProcessAlive
|
|
3
|
+
// pos: L0 zero-dependency singleton-lock primitive, shared by daemon.ts and app.ts
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'fs';
|
|
6
|
+
/** Probe whether a PID is alive. Signal 0 performs the permission/existence check
|
|
7
|
+
* without actually delivering a signal; a throw (ESRCH/EPERM-as-dead handled by caller)
|
|
8
|
+
* means the process is not addressable as a live, signalable target. */
|
|
9
|
+
export function isProcessAlive(pid) {
|
|
10
|
+
try {
|
|
11
|
+
process.kill(pid, 0);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Attempt to take a PID-file singleton lock.
|
|
20
|
+
* - File missing → write own pid, { acquired: true, stale: false }
|
|
21
|
+
* - File holds a live, valid pid → { acquired: false, holderPid }
|
|
22
|
+
* - File holds a dead/corrupt pid → overwrite with own pid, { acquired: true, stale: true }
|
|
23
|
+
*
|
|
24
|
+
* This function never exits the process or logs — the caller decides how to react to a
|
|
25
|
+
* conflict (typically: log a message and process.exit(1)).
|
|
26
|
+
*/
|
|
27
|
+
export function tryAcquireSingletonLock(pidFile) {
|
|
28
|
+
if (existsSync(pidFile)) {
|
|
29
|
+
const raw = readFileSync(pidFile, 'utf8').trim();
|
|
30
|
+
const holderPid = Number(raw);
|
|
31
|
+
if (Number.isFinite(holderPid) && holderPid > 0 && isProcessAlive(holderPid)) {
|
|
32
|
+
return { acquired: false, holderPid };
|
|
33
|
+
}
|
|
34
|
+
// Stale (previous owner died without cleanup) or corrupt content — reclaim it.
|
|
35
|
+
writeFileSync(pidFile, String(process.pid), 'utf8');
|
|
36
|
+
return { acquired: true, stale: true };
|
|
37
|
+
}
|
|
38
|
+
writeFileSync(pidFile, String(process.pid), 'utf8');
|
|
39
|
+
return { acquired: true, stale: false };
|
|
40
|
+
}
|
|
41
|
+
/** Release the lock iff it is still owned by the current process. Best-effort; swallows errors. */
|
|
42
|
+
export function releaseSingletonLock(pidFile) {
|
|
43
|
+
try {
|
|
44
|
+
if (!existsSync(pidFile))
|
|
45
|
+
return;
|
|
46
|
+
const raw = readFileSync(pidFile, 'utf8').trim();
|
|
47
|
+
if (Number(raw) === process.pid)
|
|
48
|
+
unlinkSync(pidFile);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
/* best-effort cleanup */
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// pos: zero-dependency pure functions in the core layer; the subset imported by domain-layer status-helpers
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { formatDurationCompact } from './utils.js';
|
|
6
|
+
import { Icons } from './icons.js';
|
|
7
|
+
import { t } from './i18n.js';
|
|
6
8
|
export function computeElapsed(startTime) {
|
|
7
9
|
const elapsedS = (Date.now() - startTime) / 1000;
|
|
8
10
|
return { elapsedStr: formatDurationCompact(elapsedS), elapsedS };
|
|
@@ -26,6 +28,6 @@ export function buildSessionTag(sessionName, sessionId) {
|
|
|
26
28
|
export function buildUserProcessingMessage({ startTime, elapsed_s = null, num_turns = null, profileName, sessionName = null, sessionId = null }) {
|
|
27
29
|
const elapsed = elapsed_s ?? ((Date.now() - startTime) / 1000);
|
|
28
30
|
const sessionTag = buildSessionTag(sessionName, sessionId);
|
|
29
|
-
const turnsStr = num_turns != null ? ` |
|
|
30
|
-
return
|
|
31
|
+
const turnsStr = num_turns != null ? ` | ${Icons.repeat} ${num_turns} turns` : '';
|
|
32
|
+
return `${Icons.processing} ${t('status.processing')} | ${sessionTag}${profileName || 'default'} | ${Icons.stopwatch} ${formatDurationCompact(elapsed || 0)}${turnsStr}`;
|
|
31
33
|
}
|
|
@@ -8,6 +8,9 @@ export interface Task {
|
|
|
8
8
|
template: string;
|
|
9
9
|
plan: string;
|
|
10
10
|
project: string;
|
|
11
|
+
/** Parent task id (DR-0014 task tree). Children created by decompose --keep-parent point
|
|
12
|
+
* at the retained parent, which becomes the join/acceptance node via depends_on. */
|
|
13
|
+
parent: string | null;
|
|
11
14
|
depends_on: string[];
|
|
12
15
|
gpu: string | null;
|
|
13
16
|
gpu_count: number;
|
package/dist/core/task-parser.js
CHANGED
|
@@ -33,6 +33,7 @@ const VALID_STATUSES = new Set([
|
|
|
33
33
|
'pending', 'completed', 'approval-needed', 'approved',
|
|
34
34
|
]);
|
|
35
35
|
const TASK_DEFAULTS = {
|
|
36
|
+
parent: null,
|
|
36
37
|
depends_on: [],
|
|
37
38
|
gpu: null,
|
|
38
39
|
gpu_count: 1,
|
|
@@ -63,6 +64,7 @@ function rawToTask(raw, project) {
|
|
|
63
64
|
template: String(mapped.template ?? ''),
|
|
64
65
|
plan: String(mapped.plan ?? ''),
|
|
65
66
|
project,
|
|
67
|
+
parent: mapped.parent != null ? String(mapped.parent) : null,
|
|
66
68
|
depends_on: Array.isArray(mapped.depends_on) ? mapped.depends_on.map(String) : [],
|
|
67
69
|
gpu: mapped.gpu != null ? String(mapped.gpu) : null,
|
|
68
70
|
gpu_count: typeof mapped.gpu_count === 'number' ? mapped.gpu_count : 1,
|
|
@@ -122,7 +124,7 @@ function parseTasksFileWithLock(content, project) {
|
|
|
122
124
|
// ── Serialization ──
|
|
123
125
|
const REQUIRED_KEYS = ['id', 'text', 'why', 'done_when', 'priority', 'status', 'template', 'plan'];
|
|
124
126
|
const OPTIONAL_KEY_ORDER = [
|
|
125
|
-
'depends_on', 'gpu', 'gpu_count', 'blocked_by', 'claimed_by', 'claimed_at',
|
|
127
|
+
'parent', 'depends_on', 'gpu', 'gpu_count', 'blocked_by', 'claimed_by', 'claimed_at',
|
|
126
128
|
'paused', 'approval_needed', 'approved_at', 'not_before', 'pending_at', 'completed_at', 'completed_note',
|
|
127
129
|
];
|
|
128
130
|
function isDefault(key, value) {
|
|
@@ -197,13 +197,66 @@ export interface ThreadRecord {
|
|
|
197
197
|
abortReason: string | null;
|
|
198
198
|
metadata?: ThreadMetadata | null;
|
|
199
199
|
}
|
|
200
|
+
/** Structured delegation contract attached to a spawned (child) thread (DR-0014).
|
|
201
|
+
* Composed into the child's prompt by buildContractPrompt and echoed back to the
|
|
202
|
+
* parent in the completion notice so the parent can verify the deliverable. */
|
|
203
|
+
export interface ThreadContract {
|
|
204
|
+
goal: string;
|
|
205
|
+
doneWhen?: string | null;
|
|
206
|
+
contextFiles?: string[];
|
|
207
|
+
deliverablePath?: string | null;
|
|
208
|
+
budgetUsd?: number | null;
|
|
209
|
+
}
|
|
200
210
|
/** Caller-provided metadata stored on ThreadRecord, used by thread-runner for execution registry etc. */
|
|
201
211
|
export interface ThreadMetadata {
|
|
202
212
|
scheduleTaskId?: string | null;
|
|
203
213
|
trigger?: string | null;
|
|
204
214
|
profileOverride?: string | null;
|
|
215
|
+
/** Recursion depth: 0 for top-level (direct-agent-spawned) threads, incremented per nested
|
|
216
|
+
* thread_start via the MCP thread-op bridge. Surfaced to spawned agents as CORTEX_THREAD_DEPTH
|
|
217
|
+
* so the depth guard can cap runaway agent→thread→agent recursion. */
|
|
218
|
+
depth?: number;
|
|
219
|
+
/** Identity of the agent that spawned this thread via the MCP thread_start bridge, so an agent
|
|
220
|
+
* can later enumerate the threads it started (thread_list scope=mine). Null for threads not
|
|
221
|
+
* spawned by an agent (Slack / scheduler / dispatch). */
|
|
222
|
+
parentSessionId?: string | null;
|
|
223
|
+
parentThreadId?: string | null;
|
|
224
|
+
/** Parent's channel + profile, captured at spawn time so the completion callback can wake the
|
|
225
|
+
* parent (interactive parent → resume its channel session) or address a notice to it. */
|
|
226
|
+
parentChannel?: string | null;
|
|
227
|
+
parentProfile?: string | null;
|
|
205
228
|
/** Messages buffered while a step was executing, to be included in the next step's prompt. */
|
|
206
229
|
pendingMessages?: string[];
|
|
230
|
+
/** Root of the thread tree this thread belongs to. Unset on root threads —
|
|
231
|
+
* use tree.getRootThreadId() which falls back to the thread's own id. */
|
|
232
|
+
rootThreadId?: string | null;
|
|
233
|
+
/** All children ever spawned by this thread via thread_start (terminal ones included).
|
|
234
|
+
* Doubles as the width / rework hard-cap counter for checkSpawnGuards. */
|
|
235
|
+
childThreadIds?: string[];
|
|
236
|
+
/** Children this thread is still waiting on. status==='waiting' && waitingOn.length>0
|
|
237
|
+
* identifies a suspended parent (vs. the legacy waiting-for-user semantics). */
|
|
238
|
+
waitingOn?: string[];
|
|
239
|
+
/** Child TASK ids (4-hex) this manager thread is waiting on (DR-0014 §8). Snapshotted from
|
|
240
|
+
* TASKS.yaml (tasks with parent === metadata.taskId, open and unblocked) at suspension.
|
|
241
|
+
* task.completed / task.blocked events drain it; resume requires waitingOn AND
|
|
242
|
+
* waitingOnTasks both empty. Unlike thread children, task children survive restarts. */
|
|
243
|
+
waitingOnTasks?: string[];
|
|
244
|
+
/** Children whose results were already queued into pendingMessages — persistent
|
|
245
|
+
* idempotency for completion callbacks (survives restarts, unlike the in-memory fired set). */
|
|
246
|
+
deliveredChildResults?: string[];
|
|
247
|
+
/** Delegation contract this thread was spawned with (child side). */
|
|
248
|
+
contract?: ThreadContract | null;
|
|
249
|
+
/** Ancestor goal chain, root-first — injected into the child prompt to prevent drift. */
|
|
250
|
+
missionChain?: string[];
|
|
251
|
+
/** Task association for task-dispatch threads, so a suspended parent can rebuild its
|
|
252
|
+
* onEnd task-status-check hook on re-entry (extraHooks are not persisted). */
|
|
253
|
+
taskId?: string | null;
|
|
254
|
+
taskProject?: string | null;
|
|
255
|
+
/** Destination kind decided at spawn time, so re-entry can rebuild RunThreadOptions. */
|
|
256
|
+
resumeDest?: 'interactive-reply' | 'project-report' | null;
|
|
257
|
+
/** Live status message persisted at suspension so the post-resume settle can refresh it
|
|
258
|
+
* (otherwise it reads "suspended — waiting on children" forever — 2026-06-11 finding). */
|
|
259
|
+
statusMsgRef?: MessageRef | null;
|
|
207
260
|
}
|
|
208
261
|
export interface StepResult {
|
|
209
262
|
done: boolean;
|
|
@@ -223,18 +276,11 @@ export interface RunThreadOptions {
|
|
|
223
276
|
channel: string;
|
|
224
277
|
/** Destination for the thread's OutputStream. Caller must supply — never inferred. */
|
|
225
278
|
destination: Destination;
|
|
226
|
-
|
|
279
|
+
threadAnchorId: string | null;
|
|
227
280
|
statusMsg: MessageRef | null;
|
|
228
281
|
startTime: number;
|
|
229
|
-
existingSessionId: string | null;
|
|
230
|
-
/** Pre-resolved session name from the caller (e.g. agent-runner).
|
|
231
|
-
* buildStepConfig reuses it for default threads instead of generating a new name. */
|
|
232
|
-
sessionName?: string | null;
|
|
233
|
-
onAssistantMessage?: ((text: string) => void) | null;
|
|
234
282
|
onProgress?: ((progress: any) => void) | null;
|
|
235
|
-
onFallback?: any;
|
|
236
283
|
onToolUse?: ((name: string, input: any) => void) | null;
|
|
237
|
-
isUserInitiated?: boolean;
|
|
238
284
|
files?: any[];
|
|
239
285
|
/** Called by the facade event loop when a plan_written NormalizedEvent fires (PI backend: during turn, not after). */
|
|
240
286
|
onPlanWritten?: ((event: {
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -26,4 +26,12 @@ declare function todayISO(): string;
|
|
|
26
26
|
* `cortex-task lock-status`, `stats`, id-assignment, etc.).
|
|
27
27
|
*/
|
|
28
28
|
declare function listProjectDirs(projectsDir?: string): string[];
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Sentinel ANTHROPIC_API_KEY value set when the gateway is healthy but no real key exists.
|
|
31
|
+
* Its only purpose is to satisfy Claude Code's startup credential check on machines without
|
|
32
|
+
* OAuth login — upstream auth is handled by the gateway's own configured keys. Anything that
|
|
33
|
+
* treats ANTHROPIC_API_KEY as a real credential (gateway-generator discovery, saved-env
|
|
34
|
+
* snapshots) must ignore this value.
|
|
35
|
+
*/
|
|
36
|
+
declare const GATEWAY_MANAGED_KEY_PLACEHOLDER = "cortex-gateway-managed";
|
|
37
|
+
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
|
package/dist/core/utils.js
CHANGED
|
@@ -95,4 +95,12 @@ function listProjectDirs(projectsDir = PROJECTS_DIR) {
|
|
|
95
95
|
return [];
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Sentinel ANTHROPIC_API_KEY value set when the gateway is healthy but no real key exists.
|
|
100
|
+
* Its only purpose is to satisfy Claude Code's startup credential check on machines without
|
|
101
|
+
* OAuth login — upstream auth is handled by the gateway's own configured keys. Anything that
|
|
102
|
+
* treats ANTHROPIC_API_KEY as a real credential (gateway-generator discovery, saved-env
|
|
103
|
+
* snapshots) must ignore this value.
|
|
104
|
+
*/
|
|
105
|
+
const GATEWAY_MANAGED_KEY_PLACEHOLDER = 'cortex-gateway-managed';
|
|
106
|
+
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GATEWAY_MANAGED_KEY_PLACEHOLDER } from '../../core/utils.js';
|
|
1
2
|
export interface ModeFileData {
|
|
2
3
|
mode?: string;
|
|
3
4
|
claudeMode?: string;
|
|
@@ -55,4 +56,4 @@ export declare function resolveAgentModel({ profileName, modelOverride }?: {
|
|
|
55
56
|
modelOverride?: string | null;
|
|
56
57
|
}): string;
|
|
57
58
|
export declare function detectBillingMode(): string;
|
|
58
|
-
export { GATEWAY_ANTHROPIC_URL, saveModeFile, loadModeFile, };
|
|
59
|
+
export { GATEWAY_ANTHROPIC_URL, GATEWAY_MANAGED_KEY_PLACEHOLDER, saveModeFile, loadModeFile, };
|
|
@@ -5,7 +5,7 @@ import { readFileSync, writeFileSync } from 'fs';
|
|
|
5
5
|
import { parse as parseDotenv } from 'dotenv';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import * as http from 'http';
|
|
8
|
-
import { STORE_DIR, CONFIG_DIR } from '../../core/utils.js';
|
|
8
|
+
import { STORE_DIR, CONFIG_DIR, GATEWAY_MANAGED_KEY_PLACEHOLDER } from '../../core/utils.js';
|
|
9
9
|
import { getProfileModel, resolveProfileConfig } from './profile-manager.js';
|
|
10
10
|
import { GATEWAY_URL, isGatewayHealthy } from '../costs/gateway-manager.js';
|
|
11
11
|
import { createLogger } from '../../core/log.js';
|
|
@@ -52,8 +52,12 @@ function readApiEnvFromDotenvFile() {
|
|
|
52
52
|
}
|
|
53
53
|
function captureApiEnvSnapshot() {
|
|
54
54
|
const fileEnv = readApiEnvFromDotenvFile();
|
|
55
|
+
// The gateway-managed placeholder is not a real credential — never let it
|
|
56
|
+
// pollute the saved env used for direct (gateway-down) connections.
|
|
57
|
+
const liveKey = normalizeEnvValue(process.env.ANTHROPIC_API_KEY);
|
|
58
|
+
const realLiveKey = liveKey === GATEWAY_MANAGED_KEY_PLACEHOLDER ? undefined : liveKey;
|
|
55
59
|
return {
|
|
56
|
-
ANTHROPIC_API_KEY:
|
|
60
|
+
ANTHROPIC_API_KEY: realLiveKey || fileEnv.ANTHROPIC_API_KEY,
|
|
57
61
|
ANTHROPIC_BASE_URL: normalizeEnvValue(process.env.ANTHROPIC_BASE_URL) || fileEnv.ANTHROPIC_BASE_URL,
|
|
58
62
|
};
|
|
59
63
|
}
|
|
@@ -234,7 +238,18 @@ export function configureEnvForMode(mode, metadata) {
|
|
|
234
238
|
if (isGatewayHealthy()) {
|
|
235
239
|
const url = gatewayModeUrl(mode, metadata);
|
|
236
240
|
process.env.ANTHROPIC_BASE_URL = url;
|
|
237
|
-
|
|
241
|
+
if (mode === 'plan') {
|
|
242
|
+
// Plan mode rides the gateway's passthrough: Claude Code must send its own OAuth
|
|
243
|
+
// bearer token, and an env API key would take precedence over OAuth — delete it.
|
|
244
|
+
delete process.env.ANTHROPIC_API_KEY;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
// Non-plan modes: upstream auth is the gateway's job (it injects its own configured
|
|
248
|
+
// keys). Keep a key in env purely so Claude Code passes its startup credential check
|
|
249
|
+
// on machines without OAuth login (otherwise it exits with "Please run /login").
|
|
250
|
+
const saved = getSavedApiEnv();
|
|
251
|
+
process.env.ANTHROPIC_API_KEY = saved.ANTHROPIC_API_KEY || GATEWAY_MANAGED_KEY_PLACEHOLDER;
|
|
252
|
+
}
|
|
238
253
|
return url;
|
|
239
254
|
}
|
|
240
255
|
// Gateway unhealthy — fallback to direct connection
|
|
@@ -308,6 +323,10 @@ export function detectBillingMode() {
|
|
|
308
323
|
catch { }
|
|
309
324
|
return 'api';
|
|
310
325
|
}
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
|
|
326
|
+
// NOTE: deliberately NO configureEnvForMode() call at module scope. This module is imported
|
|
327
|
+
// transitively by CLI processes (cortex init / setup-gateway via domain/threads), where the
|
|
328
|
+
// gateway is always unhealthy — an import-time call would delete ANTHROPIC_API_KEY (plan mode)
|
|
329
|
+
// before gateway-generator discovery runs, breaking api endpoint generation. The server entry
|
|
330
|
+
// (app.ts) applies the persisted mode explicitly after dotenv loads; every agent spawn also
|
|
331
|
+
// calls configureEnvForMode() per-request (facade.runAgentOnce).
|
|
332
|
+
export { GATEWAY_ANTHROPIC_URL, GATEWAY_MANAGED_KEY_PLACEHOLDER, saveModeFile, loadModeFile, };
|
|
@@ -4,6 +4,8 @@ export interface AgentConfig {
|
|
|
4
4
|
model: string;
|
|
5
5
|
backend: string;
|
|
6
6
|
mode: string | null;
|
|
7
|
+
/** PI `--provider` (protocol). null → defaults to "anthropic". Only used for backend='pi'. */
|
|
8
|
+
provider?: string | null;
|
|
7
9
|
extraEnv?: Record<string, string>;
|
|
8
10
|
extraOption?: Record<string, string>;
|
|
9
11
|
/** DR-0012: Claude adapter mode (print/tui). Only meaningful for backend='claude'. */
|
|
@@ -30,12 +32,28 @@ export interface RunAgentOptions {
|
|
|
30
32
|
/** When true, load only core MCP server (remote_* tools). Used by template thread sessions.
|
|
31
33
|
* Default (undefined/false) loads full MCP config with cortex-ext tools. */
|
|
32
34
|
useCoreMcp?: boolean;
|
|
35
|
+
/** Recursion depth of the owning thread, surfaced to the spawned agent as CORTEX_THREAD_DEPTH
|
|
36
|
+
* so the thread_start MCP tool can forward it for the depth guard. */
|
|
37
|
+
threadDepth?: number | null;
|
|
33
38
|
onProgress?: ((progress: any) => void) | null;
|
|
34
39
|
onAssistantMessage?: ((msg: string) => void) | null;
|
|
35
40
|
onToolUse?: ((name: string, input: any) => void) | null;
|
|
36
41
|
onFallback?: (current: AgentConfig, next: AgentConfig, result: AgentResult | null, error?: Error) => Promise<void>;
|
|
37
42
|
[key: string]: any;
|
|
38
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Build the gateway sub-path for a PI provider's models.json override, following the gateway's URL
|
|
46
|
+
* convention `/m/<mode>/<endpoint>`. The `mode` selects the gateway route (gateway.yaml owns the
|
|
47
|
+
* upstream + keys); the `provider` is both the PI `--provider` and the gateway endpoint segment.
|
|
48
|
+
*
|
|
49
|
+
* `provider` is required for pi profiles (validated at load time — no default, no fallback). Returns
|
|
50
|
+
* undefined when `mode` is absent — the PI adapter then falls back to the default `/<provider>` path
|
|
51
|
+
* (direct per-provider routing, no `/m/` mode indirection).
|
|
52
|
+
*
|
|
53
|
+
* Keeping this derivation in code (not in the profile) means profiles only carry the logical
|
|
54
|
+
* `mode` name; no gateway path string leaks into profiles.json.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildPiGatewaySubPath(mode: string | null, provider: string): string | undefined;
|
|
39
57
|
declare function buildSpawnConfig(options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentSpawnConfig;
|
|
40
58
|
export declare function runWithAdapter(adapter: AgentAdapter, message: string, options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentHandle;
|
|
41
59
|
export declare function runAgentOnce(message: string, options: RunAgentOptions, config: AgentConfig): AgentHandle;
|