@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
|
@@ -8,6 +8,7 @@ import { readFileSync } from 'fs';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import { DATA_DIR, CONFIG_DIR } from '../../core/paths.js';
|
|
10
10
|
import { createLogger } from '../../core/log.js';
|
|
11
|
+
import { Icons } from '../../core/icons.js';
|
|
11
12
|
import { runAgent, resolveBackendForChannel } from '../agents/index.js';
|
|
12
13
|
import { getSessionAsync } from '../sessions/session.js';
|
|
13
14
|
import { sessionStore } from '../../store/session-registry-repo.js';
|
|
@@ -174,7 +175,7 @@ export async function runSessionHook(spec, stream) {
|
|
|
174
175
|
catch (err) {
|
|
175
176
|
const msg = err?.message || String(err);
|
|
176
177
|
log.error(`hook ${spec.name} injected agent failed: ${msg}`);
|
|
177
|
-
stream.emitText(
|
|
178
|
+
stream.emitText(`${Icons.warning} ${spec.name} hook follow-up failed: ${msg}`);
|
|
178
179
|
}
|
|
179
180
|
finally {
|
|
180
181
|
await stream.flush().catch((e) => log.warn(`stream.flush after inject failed (${label}): ${e?.message || e}`));
|
|
@@ -182,31 +183,31 @@ export async function runSessionHook(spec, stream) {
|
|
|
182
183
|
}
|
|
183
184
|
// ── onNew (pre-close) entry points ────────────────────────────────────────────
|
|
184
185
|
const ONNEW_FORMAT = {
|
|
185
|
-
statusLine: () =>
|
|
186
|
+
statusLine: () => `${Icons.hook} Running \`!new\` hook…`,
|
|
186
187
|
previewLine: (out) => {
|
|
187
188
|
const preview = out.length > 80 ? out.slice(0, 80) + '…' : out;
|
|
188
|
-
return
|
|
189
|
+
return `${Icons.hook} ${preview}`;
|
|
189
190
|
},
|
|
190
|
-
errorLine: (err) =>
|
|
191
|
-
emptyLine: () =>
|
|
191
|
+
errorLine: (err) => `${Icons.warning} \`!new\` hook failed: ${err}`,
|
|
192
|
+
emptyLine: () => `${Icons.hook} hook returned empty output — nothing to inject.`,
|
|
192
193
|
};
|
|
193
194
|
const ONMESSAGEEND_FORMAT = {
|
|
194
|
-
statusLine: () =>
|
|
195
|
+
statusLine: () => `${Icons.hook} Checking for unreleased locks…`,
|
|
195
196
|
previewLine: (out) => {
|
|
196
197
|
const preview = out.length > 80 ? out.slice(0, 80) + '…' : out;
|
|
197
|
-
return
|
|
198
|
+
return `${Icons.hook} ${preview}`;
|
|
198
199
|
},
|
|
199
|
-
errorLine: (err) =>
|
|
200
|
+
errorLine: (err) => `${Icons.warning} Lock check failed: ${err}`,
|
|
200
201
|
// onMessageEnd is silent on empty output — the common case is "nothing to remind".
|
|
201
202
|
emptyLine: () => null,
|
|
202
203
|
};
|
|
203
204
|
/** Resolve the Slack thread anchor for a fresh onNew vm:
|
|
204
|
-
* 1. Caller-supplied
|
|
205
|
+
* 1. Caller-supplied threadAnchorId (e.g. user typed !new in-thread).
|
|
205
206
|
* 2. Last turn's statusMessageTs from the conversation ledger.
|
|
206
207
|
* 3. null → vm starts a top-level message and self-anchors. */
|
|
207
|
-
async function resolveOnNewThreadAnchor(channel,
|
|
208
|
-
if (
|
|
209
|
-
return
|
|
208
|
+
async function resolveOnNewThreadAnchor(channel, threadAnchorId) {
|
|
209
|
+
if (threadAnchorId)
|
|
210
|
+
return threadAnchorId;
|
|
210
211
|
const conv = await conversationLedger.getConversation(channel);
|
|
211
212
|
if (conv?.turns.length) {
|
|
212
213
|
for (let i = conv.turns.length - 1; i >= 0; i--) {
|
|
@@ -238,7 +239,7 @@ async function defaultLookupLedgerProfile(channel) {
|
|
|
238
239
|
}
|
|
239
240
|
/** Build the onNew SessionHookSpec + a fresh stream. Returns null when the hook isn't
|
|
240
241
|
* configured or there's no live session to capture context from. */
|
|
241
|
-
async function prepareOnNewRun(channel, adapter,
|
|
242
|
+
async function prepareOnNewRun(channel, adapter, threadAnchorId) {
|
|
242
243
|
if (!isOnNewHookConfigured())
|
|
243
244
|
return null;
|
|
244
245
|
const backend = resolveBackendForChannel(channel);
|
|
@@ -254,7 +255,7 @@ async function prepareOnNewRun(channel, adapter, threadTs) {
|
|
|
254
255
|
lookupRegistryProfile: defaultLookupRegistryProfile,
|
|
255
256
|
lookupLedgerProfile: defaultLookupLedgerProfile,
|
|
256
257
|
});
|
|
257
|
-
const anchor = await resolveOnNewThreadAnchor(channel,
|
|
258
|
+
const anchor = await resolveOnNewThreadAnchor(channel, threadAnchorId);
|
|
258
259
|
const stream = adapter.openOutputStream({ type: 'interactive-reply', conduit: channel, sessionId: '' }, { threadId: anchor });
|
|
259
260
|
const spec = {
|
|
260
261
|
name: 'onNew',
|
|
@@ -268,8 +269,8 @@ async function prepareOnNewRun(channel, adapter, threadTs) {
|
|
|
268
269
|
* Returns immediately; the hook subprocess and any injected agent turn run async
|
|
269
270
|
* via the unified pipeline. The session is closed by the caller in parallel —
|
|
270
271
|
* sessionId is captured up-front so the JSONL still resolves after deletion. */
|
|
271
|
-
export async function fireAndForgetPreCloseHook(channel, adapter,
|
|
272
|
-
const prepared = await prepareOnNewRun(channel, adapter,
|
|
272
|
+
export async function fireAndForgetPreCloseHook(channel, adapter, threadAnchorId) {
|
|
273
|
+
const prepared = await prepareOnNewRun(channel, adapter, threadAnchorId);
|
|
273
274
|
if (!prepared)
|
|
274
275
|
return;
|
|
275
276
|
void runSessionHook(prepared.spec, prepared.stream).catch((err) => {
|
|
@@ -279,8 +280,8 @@ export async function fireAndForgetPreCloseHook(channel, adapter, threadTs) {
|
|
|
279
280
|
/** Synchronous variant of fireAndForgetPreCloseHook — awaits the hook to completion.
|
|
280
281
|
* Reserved for cases where the caller wants to block on the !new pipeline (e.g.
|
|
281
282
|
* test harness, scripted teardown). */
|
|
282
|
-
export async function runPreCloseHook(channel, adapter,
|
|
283
|
-
const prepared = await prepareOnNewRun(channel, adapter,
|
|
283
|
+
export async function runPreCloseHook(channel, adapter, threadAnchorId) {
|
|
284
|
+
const prepared = await prepareOnNewRun(channel, adapter, threadAnchorId);
|
|
284
285
|
if (!prepared)
|
|
285
286
|
return;
|
|
286
287
|
await runSessionHook(prepared.spec, prepared.stream);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const SESSION_BACKENDS: readonly ["claude", "pi", "codex"];
|
|
2
|
+
export interface SessionRegistryWriter {
|
|
3
|
+
generateSessionName(): Promise<string>;
|
|
4
|
+
registerSession(name: string, opts: {
|
|
5
|
+
sessionId: string;
|
|
6
|
+
channel: string;
|
|
7
|
+
backend: string;
|
|
8
|
+
kind: 'local' | 'scheduled';
|
|
9
|
+
projectId: string;
|
|
10
|
+
label?: string | null;
|
|
11
|
+
profileName?: string | null;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface RegisterNamedSessionOpts {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
channel: string;
|
|
17
|
+
backend: string;
|
|
18
|
+
projectId: string;
|
|
19
|
+
kind?: 'local' | 'scheduled';
|
|
20
|
+
label?: string | null;
|
|
21
|
+
profileName?: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** Generate a fresh session name and register a registry record for sessionId. Returns the name.
|
|
24
|
+
* Centralizes the generateSessionName + registerSession pairing used by inbound-message session
|
|
25
|
+
* creation (agent-runner) and TUI fresh-session creation. */
|
|
26
|
+
export declare function registerNamedSession(store: SessionRegistryWriter, opts: RegisterNamedSessionOpts): Promise<string>;
|
|
27
|
+
export interface AttachExistingSessionOpts {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
sessionName: string;
|
|
30
|
+
backend: string;
|
|
31
|
+
profileName?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** Attach a channel to an existing session: restore its profile (if any), point sessions.json at it,
|
|
34
|
+
* and switch the conversation ledger. Mirrors the !resume switch sequence. */
|
|
35
|
+
export declare function attachExistingSession(channel: string, opts: AttachExistingSessionOpts): Promise<void>;
|
|
36
|
+
/** Clear a channel's session state: drop sessions.json keys for every backend, clean session
|
|
37
|
+
* backups, and clear the conversation ledger. Mirrors the store-level half of !new. */
|
|
38
|
+
export declare function resetChannelSession(channel: string): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// input: session-registry-repo (sessionStore), session-repo (sessions.json), conversation-ledger-repo, session-backup, setActiveProfile
|
|
2
|
+
// output: registerNamedSession / attachExistingSession / resetChannelSession — shared session lifecycle primitives
|
|
3
|
+
// pos: domain/sessions — centralized session lifecycle for agent-runner, tui-session-service, and commands/session
|
|
4
|
+
import { setSessionAsync, deleteSessionAsync } from './session.js';
|
|
5
|
+
import { conversationLedger } from '../../store/conversation-ledger-repo.js';
|
|
6
|
+
import { setActiveProfile } from '../agents/index.js';
|
|
7
|
+
import * as sessionBackup from './session-backup.js';
|
|
8
|
+
export const SESSION_BACKENDS = ['claude', 'pi', 'codex'];
|
|
9
|
+
/** Generate a fresh session name and register a registry record for sessionId. Returns the name.
|
|
10
|
+
* Centralizes the generateSessionName + registerSession pairing used by inbound-message session
|
|
11
|
+
* creation (agent-runner) and TUI fresh-session creation. */
|
|
12
|
+
export async function registerNamedSession(store, opts) {
|
|
13
|
+
const name = await store.generateSessionName();
|
|
14
|
+
await store.registerSession(name, {
|
|
15
|
+
sessionId: opts.sessionId,
|
|
16
|
+
channel: opts.channel,
|
|
17
|
+
backend: opts.backend,
|
|
18
|
+
kind: opts.kind ?? 'local',
|
|
19
|
+
projectId: opts.projectId,
|
|
20
|
+
label: opts.label ?? null,
|
|
21
|
+
profileName: opts.profileName ?? null,
|
|
22
|
+
});
|
|
23
|
+
return name;
|
|
24
|
+
}
|
|
25
|
+
/** Attach a channel to an existing session: restore its profile (if any), point sessions.json at it,
|
|
26
|
+
* and switch the conversation ledger. Mirrors the !resume switch sequence. */
|
|
27
|
+
export async function attachExistingSession(channel, opts) {
|
|
28
|
+
if (opts.profileName)
|
|
29
|
+
setActiveProfile(opts.profileName, channel);
|
|
30
|
+
await setSessionAsync(channel, opts.sessionId, opts.backend);
|
|
31
|
+
await conversationLedger.switchSession(channel, {
|
|
32
|
+
sessionId: opts.sessionId, sessionName: opts.sessionName, backend: opts.backend, profileName: opts.profileName,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Clear a channel's session state: drop sessions.json keys for every backend, clean session
|
|
36
|
+
* backups, and clear the conversation ledger. Mirrors the store-level half of !new. */
|
|
37
|
+
export async function resetChannelSession(channel) {
|
|
38
|
+
const conv = await conversationLedger.getConversation(channel);
|
|
39
|
+
if (conv) {
|
|
40
|
+
sessionBackup.cleanupAllBackups(conv.sessionId);
|
|
41
|
+
await conversationLedger.clearConversation(channel);
|
|
42
|
+
}
|
|
43
|
+
await Promise.all(SESSION_BACKENDS.map(b => deleteSessionAsync(channel, b).catch(() => { })));
|
|
44
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// input: CORTEX_VERSION, child_process (execSync, spawn), compareCalVer from server-update-check
|
|
2
|
+
// output: cortex install latest CLI
|
|
3
|
+
// pos: CLI module for cortex install — install latest Cortex version from npm
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { execSync, spawn } from 'node:child_process';
|
|
6
|
+
import { CORTEX_VERSION } from '../../core/version.js';
|
|
7
|
+
import { compareCalVer } from './server-update-check.js';
|
|
8
|
+
// ─── Help ─────────────────────────────────────────────────────────
|
|
9
|
+
export function getInstallHelp() {
|
|
10
|
+
return [
|
|
11
|
+
'Install the latest version of Cortex from npm',
|
|
12
|
+
'',
|
|
13
|
+
'Usage: cortex install <subcommand>',
|
|
14
|
+
'',
|
|
15
|
+
'Subcommands:',
|
|
16
|
+
' latest Install the latest version of @cortex-agent/server from npm',
|
|
17
|
+
'',
|
|
18
|
+
'Options:',
|
|
19
|
+
' --help, -h Show this help',
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
// ─── Fetch latest version from npm ────────────────────────────────
|
|
23
|
+
function getLatestVersion() {
|
|
24
|
+
try {
|
|
25
|
+
const result = execSync('npm view @cortex-agent/server version', {
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
timeout: 15000,
|
|
28
|
+
stdio: 'pipe',
|
|
29
|
+
}).trim();
|
|
30
|
+
return result || null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// ─── Install latest ───────────────────────────────────────────────
|
|
37
|
+
async function installLatest() {
|
|
38
|
+
// 1. Fetch latest version from npm registry
|
|
39
|
+
const latest = getLatestVersion();
|
|
40
|
+
if (!latest) {
|
|
41
|
+
return {
|
|
42
|
+
exitCode: 1,
|
|
43
|
+
stdout: '',
|
|
44
|
+
stderr: 'Failed to fetch latest version from npm registry. Check your network or npm configuration.\n',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// 2. Check if already on latest
|
|
48
|
+
if (compareCalVer(latest, CORTEX_VERSION) <= 0) {
|
|
49
|
+
return {
|
|
50
|
+
exitCode: 0,
|
|
51
|
+
stdout: `Already on the latest version (${CORTEX_VERSION}).\n`,
|
|
52
|
+
stderr: '',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// 3. Show version info before installing
|
|
56
|
+
process.stdout.write(`Current version: ${CORTEX_VERSION}\n`);
|
|
57
|
+
process.stdout.write(`Latest version: ${latest}\n`);
|
|
58
|
+
process.stdout.write(`Installing @cortex-agent/server@${latest}...\n\n`);
|
|
59
|
+
// 4. Run npm install -g (stdio: 'inherit' so user sees npm progress)
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
const child = spawn('npm', ['install', '-g', `@cortex-agent/server@${latest}`], {
|
|
62
|
+
stdio: 'inherit',
|
|
63
|
+
cwd: '/tmp',
|
|
64
|
+
});
|
|
65
|
+
child.on('exit', (code) => {
|
|
66
|
+
if (code === 0) {
|
|
67
|
+
resolve({
|
|
68
|
+
exitCode: 0,
|
|
69
|
+
stdout: `\nCortex updated to ${latest}. Restart the daemon to apply: cortex daemon restart\n`,
|
|
70
|
+
stderr: '',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
resolve({
|
|
75
|
+
exitCode: 1,
|
|
76
|
+
stdout: '',
|
|
77
|
+
stderr: `npm install failed with exit code ${code}.\n`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
child.on('error', (err) => {
|
|
82
|
+
resolve({
|
|
83
|
+
exitCode: 1,
|
|
84
|
+
stdout: '',
|
|
85
|
+
stderr: `Failed to start npm install: ${err.message}\n`,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// ─── runCli ───────────────────────────────────────────────────────
|
|
91
|
+
export async function runCli(argv) {
|
|
92
|
+
if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
|
|
93
|
+
return { exitCode: 0, stdout: getInstallHelp(), stderr: '' };
|
|
94
|
+
}
|
|
95
|
+
const sub = argv[0];
|
|
96
|
+
switch (sub) {
|
|
97
|
+
case 'latest':
|
|
98
|
+
return installLatest();
|
|
99
|
+
default:
|
|
100
|
+
return {
|
|
101
|
+
exitCode: 1,
|
|
102
|
+
stdout: '',
|
|
103
|
+
stderr: `Unknown install subcommand: '${sub}'. Use 'cortex install latest' or 'cortex install --help'.\n`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -34,4 +34,61 @@ declare function generateTaskId(): string;
|
|
|
34
34
|
declare function buildDispatchSessionName(taskId: any): string;
|
|
35
35
|
/** Test-only: directly set the in-memory machine registry. */
|
|
36
36
|
declare function _testSetRegistry(registry: MachineRegistry): void;
|
|
37
|
-
export
|
|
37
|
+
export interface SplitOutcome {
|
|
38
|
+
handled: boolean;
|
|
39
|
+
note?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Process a worker thread's [SPLIT] decomposition proposal after dispatch:
|
|
43
|
+
* decompose keep-parent (the task becomes a join/acceptance node over its new children)
|
|
44
|
+
* and unclaim it so the children flow through the normal queue. Parse errors are surfaced
|
|
45
|
+
* (and the task still unclaimed) instead of silently dropped. Deps are injected by the
|
|
46
|
+
* caller (task-dispatch wires the real detect/decompose/unclaim) — keeps this testable
|
|
47
|
+
* and this module free of thread-system imports. */
|
|
48
|
+
declare function processSplitOutcome(args: {
|
|
49
|
+
threadId: string;
|
|
50
|
+
taskId: string | null;
|
|
51
|
+
project: string;
|
|
52
|
+
}, deps: {
|
|
53
|
+
detect: (threadId: string) => {
|
|
54
|
+
split: boolean;
|
|
55
|
+
subtasks: any[] | null;
|
|
56
|
+
error: string | null;
|
|
57
|
+
};
|
|
58
|
+
decompose: (project: string, text: string | null, subtasks: any[], taskId: string | null, options: {
|
|
59
|
+
keepParent?: boolean;
|
|
60
|
+
}) => {
|
|
61
|
+
success: boolean;
|
|
62
|
+
message: string;
|
|
63
|
+
} | Promise<{
|
|
64
|
+
success: boolean;
|
|
65
|
+
message: string;
|
|
66
|
+
}>;
|
|
67
|
+
unclaim: (taskId: string) => Promise<unknown>;
|
|
68
|
+
}): Promise<SplitOutcome>;
|
|
69
|
+
export interface AbortOutcome {
|
|
70
|
+
handled: boolean;
|
|
71
|
+
note?: string;
|
|
72
|
+
error?: string;
|
|
73
|
+
}
|
|
74
|
+
/** Process an aborted dispatch thread: the worker said "I can't" ([ABORT: <reason>]) —
|
|
75
|
+
* block the task with the abort reason. taskMutator.block publishes task.blocked, which
|
|
76
|
+
* wakes a manager thread waiting on this task (its parent re-plans); with no manager the
|
|
77
|
+
* block surfaces to humans/stage-gate as usual. Also fixes the pre-existing bug where
|
|
78
|
+
* aborted dispatch threads were finalized as successes (publishing a bogus task.completed).
|
|
79
|
+
* Not counted as a dispatch failure — abort is a judgment, not a fault. */
|
|
80
|
+
declare function processAbortOutcome(args: {
|
|
81
|
+
threadId: string;
|
|
82
|
+
taskId: string | null;
|
|
83
|
+
project: string;
|
|
84
|
+
}, deps: {
|
|
85
|
+
getThread: (threadId: string) => {
|
|
86
|
+
status: string;
|
|
87
|
+
abortReason: string | null;
|
|
88
|
+
} | null;
|
|
89
|
+
block: (taskId: string, reason: string) => Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
message: string;
|
|
92
|
+
}>;
|
|
93
|
+
}): Promise<AbortOutcome>;
|
|
94
|
+
export { getMachineRegistry, getLocalMachine, loadMachinesFromFile, startMachineRegistryWatcher, stopMachineRegistryWatcher, generateTaskId, buildDispatchSessionName, processSplitOutcome, processAbortOutcome, _testSetRegistry, };
|
|
@@ -7,6 +7,7 @@ import { readFileSync, watch, existsSync } from 'fs';
|
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { CONFIG_DIR } from '../../core/utils.js';
|
|
9
9
|
import { createLogger } from '../../core/log.js';
|
|
10
|
+
import { Icons } from '../../core/icons.js';
|
|
10
11
|
const log = createLogger('machine-registry');
|
|
11
12
|
const MACHINES_FILE = path.join(CONFIG_DIR, 'machines.json');
|
|
12
13
|
let _registry = {};
|
|
@@ -39,11 +40,11 @@ function loadMachinesFromFile(failOnError = true) {
|
|
|
39
40
|
if (isReload) {
|
|
40
41
|
if (oldKeys !== newKeys) {
|
|
41
42
|
log.info(`Hot-reload: machines changed [${oldKeys}] → [${newKeys}]`);
|
|
42
|
-
_adminNotifier?.(
|
|
43
|
+
_adminNotifier?.(`${Icons.refresh} \`machines.json\` hot-reloaded: [${oldKeys}] → [${newKeys}]`);
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
46
|
log.info(`Hot-reload: ${Object.keys(parsed).length} machines reloaded`);
|
|
46
|
-
_adminNotifier?.(
|
|
47
|
+
_adminNotifier?.(`${Icons.refresh} \`machines.json\` hot-reloaded (${Object.keys(parsed).length} machines)`);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
@@ -56,7 +57,7 @@ function loadMachinesFromFile(failOnError = true) {
|
|
|
56
57
|
throw new Error(msg);
|
|
57
58
|
}
|
|
58
59
|
log.error(msg + ' — keeping previous config');
|
|
59
|
-
_adminNotifier?.(
|
|
60
|
+
_adminNotifier?.(`${Icons.warning} \`machines.json\` hot-reload FAILED — keeping previous config`);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
@@ -140,4 +141,52 @@ function _testSetRegistry(registry) {
|
|
|
140
141
|
_registry = { ...registry };
|
|
141
142
|
_loaded = true;
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
+
/** Process a worker thread's [SPLIT] decomposition proposal after dispatch:
|
|
145
|
+
* decompose keep-parent (the task becomes a join/acceptance node over its new children)
|
|
146
|
+
* and unclaim it so the children flow through the normal queue. Parse errors are surfaced
|
|
147
|
+
* (and the task still unclaimed) instead of silently dropped. Deps are injected by the
|
|
148
|
+
* caller (task-dispatch wires the real detect/decompose/unclaim) — keeps this testable
|
|
149
|
+
* and this module free of thread-system imports. */
|
|
150
|
+
async function processSplitOutcome(args, deps) {
|
|
151
|
+
const detection = deps.detect(args.threadId);
|
|
152
|
+
if (!detection.split)
|
|
153
|
+
return { handled: false };
|
|
154
|
+
if (!args.taskId) {
|
|
155
|
+
log.warn(`[SPLIT] marker in thread ${args.threadId} but no associated task — ignoring`);
|
|
156
|
+
return { handled: false };
|
|
157
|
+
}
|
|
158
|
+
if (detection.error || !detection.subtasks) {
|
|
159
|
+
await deps.unclaim(args.taskId);
|
|
160
|
+
return { handled: true, error: detection.error || '[SPLIT] proposal empty' };
|
|
161
|
+
}
|
|
162
|
+
const result = await deps.decompose(args.project, null, detection.subtasks, args.taskId, { keepParent: true });
|
|
163
|
+
if (!result.success) {
|
|
164
|
+
await deps.unclaim(args.taskId);
|
|
165
|
+
return { handled: true, error: result.message };
|
|
166
|
+
}
|
|
167
|
+
await deps.unclaim(args.taskId);
|
|
168
|
+
return { handled: true, note: `split into ${detection.subtasks.length} subtask(s) — parent kept as join node` };
|
|
169
|
+
}
|
|
170
|
+
/** Process an aborted dispatch thread: the worker said "I can't" ([ABORT: <reason>]) —
|
|
171
|
+
* block the task with the abort reason. taskMutator.block publishes task.blocked, which
|
|
172
|
+
* wakes a manager thread waiting on this task (its parent re-plans); with no manager the
|
|
173
|
+
* block surfaces to humans/stage-gate as usual. Also fixes the pre-existing bug where
|
|
174
|
+
* aborted dispatch threads were finalized as successes (publishing a bogus task.completed).
|
|
175
|
+
* Not counted as a dispatch failure — abort is a judgment, not a fault. */
|
|
176
|
+
async function processAbortOutcome(args, deps) {
|
|
177
|
+
const thread = deps.getThread(args.threadId);
|
|
178
|
+
if (!thread || thread.status !== 'aborted')
|
|
179
|
+
return { handled: false };
|
|
180
|
+
if (!args.taskId) {
|
|
181
|
+
log.warn(`aborted thread ${args.threadId} has no associated task — ignoring`);
|
|
182
|
+
return { handled: false };
|
|
183
|
+
}
|
|
184
|
+
const rawReason = (thread.abortReason || 'no reason given').replace(/\s+/g, ' ').trim();
|
|
185
|
+
const reason = `worker-abort: ${rawReason}`.slice(0, 280);
|
|
186
|
+
const result = await deps.block(args.taskId, reason);
|
|
187
|
+
if (!result.success) {
|
|
188
|
+
return { handled: true, error: result.message };
|
|
189
|
+
}
|
|
190
|
+
return { handled: true, note: `worker aborted — task blocked (${rawReason.slice(0, 120)})` };
|
|
191
|
+
}
|
|
192
|
+
export { getMachineRegistry, getLocalMachine, loadMachinesFromFile, startMachineRegistryWatcher, stopMachineRegistryWatcher, generateTaskId, buildDispatchSessionName, processSplitOutcome, processAbortOutcome, _testSetRegistry, };
|
|
@@ -213,6 +213,32 @@ function buildDispatchPrompt(task) {
|
|
|
213
213
|
if (task.plan)
|
|
214
214
|
taskSpec.push(`**Plan (MUST read):** ${task.plan}`);
|
|
215
215
|
sections.push(taskSpec.join('\n'));
|
|
216
|
+
const isolation = [
|
|
217
|
+
'## Workspace Isolation (concurrent-safe)',
|
|
218
|
+
'',
|
|
219
|
+
'Other threads may work on this same project in parallel. If this task will MODIFY CODE inside a project code directory (a git repository outside ~/.cortex), do NOT edit the shared checkout directly — isolate your work in a git worktree:',
|
|
220
|
+
'',
|
|
221
|
+
'1. First confirm the code directory is a git repository AND git is installed. If it is NOT a git repo, or git is unavailable, SKIP isolation entirely and work normally.',
|
|
222
|
+
'2. Otherwise create a worktree on a unique branch named with your thread id ($CORTEX_THREAD_ID), so parallel threads never collide:',
|
|
223
|
+
' git -C <code-dir> worktree add <code-dir>-wt-$CORTEX_THREAD_ID -b cortex/$CORTEX_THREAD_ID',
|
|
224
|
+
' Do ALL edits, tests, and commits INSIDE that worktree.',
|
|
225
|
+
'3. When the work is done, integrate back: pull the latest main branch, merge cortex/$CORTEX_THREAD_ID into it, resolve conflicts, push, then remove the worktree and delete the branch. If conflicts cannot be resolved automatically, STOP and report it in your completion note — never force-overwrite work from another thread.',
|
|
226
|
+
'',
|
|
227
|
+
'On REMOTE machines, run every git/worktree command through remote_bash on the same device you worked on (per-machine code paths are in project-dirs.json).',
|
|
228
|
+
'',
|
|
229
|
+
'This applies ONLY to project code directories, NOT to ~/.cortex bookkeeping (STATUS.md, experiments/, TASKS.yaml).',
|
|
230
|
+
];
|
|
231
|
+
sections.push(isolation.join('\n'));
|
|
232
|
+
const escalation = [
|
|
233
|
+
'## If This Task Is Mis-Scoped ([ABORT])',
|
|
234
|
+
'',
|
|
235
|
+
'If during execution you discover this task is far bigger than its description suggests, or its scope is wrong (multiple independent work units crammed together, missing prerequisites, contradictory requirements), do NOT grind through it. Append to the artifact:',
|
|
236
|
+
'',
|
|
237
|
+
' [ABORT: too-big — <one-line diagnosis of what the real structure is>]',
|
|
238
|
+
'',
|
|
239
|
+
'The task will be blocked with your diagnosis and escalated: its manager (or a human) re-plans the decomposition with full context. A precise diagnosis is the most valuable thing you can produce here — it beats a half-done grind every time.',
|
|
240
|
+
];
|
|
241
|
+
sections.push(escalation.join('\n'));
|
|
216
242
|
const completion = [
|
|
217
243
|
'## When Done',
|
|
218
244
|
'',
|
|
@@ -76,6 +76,33 @@ function lintDependencies(tasks, byId, errors) {
|
|
|
76
76
|
errors.push({ code: 'dependency-cycle', cycle });
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
/** DR-0014 task tree: parent must reference an existing task; parent chains must be acyclic. */
|
|
80
|
+
function lintParents(tasks, byId, errors) {
|
|
81
|
+
for (const task of tasks) {
|
|
82
|
+
if (task.parent && !byId[task.parent]) {
|
|
83
|
+
errors.push({ code: 'missing-parent', task_id: task.id || null, missing: task.parent, project: task.project, text: task.text });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const inReportedCycle = new Set();
|
|
87
|
+
for (const task of tasks) {
|
|
88
|
+
if (!task.id || !task.parent || inReportedCycle.has(task.id))
|
|
89
|
+
continue;
|
|
90
|
+
const chain = [task.id];
|
|
91
|
+
const seen = new Set(chain);
|
|
92
|
+
let cursor = task.parent;
|
|
93
|
+
while (cursor && byId[cursor]) {
|
|
94
|
+
if (seen.has(cursor)) {
|
|
95
|
+
errors.push({ code: 'parent-cycle', cycle: [...chain, cursor] });
|
|
96
|
+
for (const id of chain)
|
|
97
|
+
inReportedCycle.add(id);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
seen.add(cursor);
|
|
101
|
+
chain.push(cursor);
|
|
102
|
+
cursor = byId[cursor].parent ?? '';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
79
106
|
function lintSupplyHealth(summary, info) {
|
|
80
107
|
for (const [project, raw] of Object.entries(summary.projects)) {
|
|
81
108
|
const s = raw;
|
|
@@ -96,6 +123,7 @@ export function lintTasks(tasks, options = {}) {
|
|
|
96
123
|
lintSingleTask(task, warnings, errors, duplicateCounts, byId, validTemplateNames);
|
|
97
124
|
lintDuplicates(duplicateCounts, errors);
|
|
98
125
|
lintDependencies(tasks, byId, errors);
|
|
126
|
+
lintParents(tasks, byId, errors);
|
|
99
127
|
const summary = getTaskStatsFromTasks(tasks);
|
|
100
128
|
lintSupplyHealth(summary, info);
|
|
101
129
|
return { ok: errors.length === 0, errors, warnings, info, summary };
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { TaskRepo } from '../../store/task-repo.js';
|
|
2
|
+
import type { EventBus } from '../../events/index.js';
|
|
2
3
|
export declare class TaskMutator {
|
|
3
4
|
private store;
|
|
4
|
-
|
|
5
|
+
private bus?;
|
|
6
|
+
constructor(store?: TaskRepo, bus?: EventBus);
|
|
7
|
+
setBus(bus: EventBus): void;
|
|
8
|
+
/** getById with a one-shot refresh on miss: tasks created out-of-process (CLI, manager
|
|
9
|
+
* threads) reach the in-memory cache only on refresh — callers like the cortex-run
|
|
10
|
+
* callback may fire before any dispatch cycle has reloaded TASKS.yaml. */
|
|
11
|
+
private getByIdFresh;
|
|
5
12
|
claim(taskId: string, agent: string): Promise<any>;
|
|
6
13
|
unclaim(taskId: string): Promise<any>;
|
|
7
|
-
complete(taskId: string, note?: string
|
|
14
|
+
complete(taskId: string, note?: string, options?: {
|
|
15
|
+
skipVerify?: boolean;
|
|
16
|
+
skipVerifyReason?: string;
|
|
17
|
+
}): Promise<any>;
|
|
8
18
|
uncomplete(taskId: string): Promise<any>;
|
|
9
19
|
block(taskId: string, reason: string): Promise<any>;
|
|
10
20
|
unblock(taskId: string): Promise<any>;
|
|
@@ -16,6 +26,9 @@ export declare class TaskMutator {
|
|
|
16
26
|
batchEdit(project: string, taskIds: string[], options: any): Promise<any>;
|
|
17
27
|
add(project: string, text: string, why: string, doneWhen: string, priority?: string, template?: string, dependsOn?: string[]): Promise<any>;
|
|
18
28
|
edit(project: string, options: any): Promise<any>;
|
|
19
|
-
decompose(project: string, taskText: string, subtasks: any[], taskId?: string
|
|
29
|
+
decompose(project: string, taskText: string | null, subtasks: any[], taskId?: string | null, options?: {
|
|
30
|
+
keepParent?: boolean;
|
|
31
|
+
system?: boolean;
|
|
32
|
+
}): Promise<any>;
|
|
20
33
|
}
|
|
21
34
|
export declare const taskMutator: TaskMutator;
|