@cortex-agent/server 2026.7.30 → 2026.8.3-2
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/README.md +1 -1
- package/defaults/CORTEX.md +1 -0
- package/defaults/config/CORTEX.md +2 -1
- package/defaults/config/hooks/13-status-md-guard.json +11 -0
- package/defaults/config/hooks/CORTEX.md +1 -0
- package/defaults/config/mcp-config-empty.json +3 -0
- package/defaults/config/thread-templates/agents/benchmark-coder.json +22 -0
- package/defaults/config/thread-templates/agents/benchmark-reviewer.json +22 -0
- package/defaults/config/thread-templates/agents/coder-reviewer.json +4 -9
- package/defaults/config/thread-templates/agents/coder.json +4 -14
- package/defaults/config/thread-templates/templates/benchmark-coder-review.json +37 -0
- package/defaults/config/thread-templates/templates/coder-review.json +3 -27
- package/defaults/context/projects/CORTEX.md +1 -1
- package/defaults/data/schedules.json +12 -0
- package/defaults/hooks/CORTEX.md +1 -0
- package/defaults/hooks/new-session-hook.mjs +2 -2
- package/defaults/hooks/status-md-guard.mjs +193 -0
- package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +28 -2
- package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-common/skills/compound/SKILL.md +1 -1
- package/defaults/plugins/cortex-common/skills/compound-simple/SKILL.md +4 -2
- package/defaults/plugins/cortex-common/skills/postmortem/SKILL.md +1 -1
- package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +1 -1
- package/defaults/plugins/cortex-stage-gate/skills/need-approval/SKILL.md +1 -0
- package/defaults/plugins/cortex-stage-gate/skills/reorient/SKILL.md +2 -2
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +11 -8
- package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +13 -16
- package/defaults/prompts/directives/coder-reviewer.md +24 -20
- package/defaults/prompts/directives/coder.md +4 -5
- package/defaults/prompts/directives/director.md +4 -10
- package/defaults/prompts/directives/manager.md +9 -10
- package/defaults/prompts/systemPrompts/worker.md +2 -2
- package/defaults/rules/cortex-md.md +31 -0
- package/defaults/rules/experiment-format.md +8 -1
- package/defaults/rules/issues-md.md +10 -9
- package/defaults/rules/meta-conventions.md +5 -4
- package/defaults/rules/mission-md.md +2 -1
- package/defaults/rules/status-md.md +39 -21
- package/dist/agent-adapter/bg-wait.d.ts +10 -12
- package/dist/agent-adapter/bg-wait.js +209 -129
- package/dist/agent-adapter/claude/adapter-tui.d.ts +3 -1
- package/dist/agent-adapter/claude/adapter-tui.js +8 -5
- package/dist/agent-adapter/claude/adapter.d.ts +43 -14
- package/dist/agent-adapter/claude/adapter.js +276 -161
- package/dist/agent-adapter/claude/defaults.d.ts +2 -0
- package/dist/agent-adapter/claude/defaults.js +5 -5
- package/dist/agent-adapter/claude/event-parser.d.ts +3 -8
- package/dist/agent-adapter/claude/event-parser.js +28 -31
- package/dist/agent-adapter/claude/hooks-builder.js +4 -3
- package/dist/agent-adapter/claude/jsonl-tail.js +54 -35
- package/dist/agent-adapter/claude/spawn-args.d.ts +15 -12
- package/dist/agent-adapter/claude/spawn-args.js +44 -38
- package/dist/agent-adapter/claude/tmux-control.d.ts +4 -17
- package/dist/agent-adapter/claude/tmux-control.js +39 -32
- package/dist/agent-adapter/event-tee.d.ts +19 -0
- package/dist/agent-adapter/event-tee.js +145 -0
- package/dist/agent-adapter/index.d.ts +1 -0
- package/dist/agent-adapter/index.js +7 -3
- package/dist/agent-adapter/normalize/event-types.d.ts +17 -9
- package/dist/agent-adapter/normalize/event-types.js +4 -4
- package/dist/agent-adapter/pi/adapter.d.ts +16 -4
- package/dist/agent-adapter/pi/adapter.js +69 -36
- package/dist/agent-adapter/pi/discovery.d.ts +19 -3
- package/dist/agent-adapter/pi/discovery.js +81 -43
- package/dist/agent-adapter/pi/event-parser.js +4 -2
- package/dist/agent-adapter/pi/spawn-args.d.ts +2 -4
- package/dist/agent-adapter/pi/spawn-args.js +6 -5
- package/dist/agent-adapter/types.d.ts +43 -2
- package/dist/agent-adapter/types.js +8 -4
- package/dist/core/atomic-write.d.ts +6 -1
- package/dist/core/atomic-write.js +183 -7
- package/dist/core/cli-utils.d.ts +15 -2
- package/dist/core/cli-utils.js +46 -41
- package/dist/core/config-generator.d.ts +4 -0
- package/dist/core/config-generator.js +34 -21
- package/dist/core/json-repository.d.ts +4 -0
- package/dist/core/json-repository.js +6 -3
- package/dist/core/locales/en.d.ts +94 -0
- package/dist/core/locales/slices/commands.d.ts +76 -0
- package/dist/core/locales/slices/commands.js +155 -1
- package/dist/core/locales/slices/status.d.ts +18 -0
- package/dist/core/locales/slices/status.js +43 -2
- package/dist/core/log.d.ts +5 -0
- package/dist/core/log.js +25 -23
- package/dist/core/pi-session-filename.d.ts +2 -0
- package/dist/core/pi-session-filename.js +18 -0
- package/dist/core/resume-reminder.d.ts +5 -0
- package/dist/core/resume-reminder.js +18 -0
- package/dist/core/runtime-env.d.ts +1 -0
- package/dist/core/runtime-env.js +15 -0
- package/dist/core/settings-migration.d.ts +5 -0
- package/dist/core/settings-migration.js +128 -0
- package/dist/core/settings-spec.d.ts +174 -0
- package/dist/core/settings-spec.js +150 -0
- package/dist/core/settings.d.ts +10 -0
- package/dist/core/settings.js +235 -0
- package/dist/core/task-parser.d.ts +11 -1
- package/dist/core/task-parser.js +34 -3
- package/dist/core/types/agent-types.d.ts +19 -0
- package/dist/core/types/agent-types.js +1 -1
- package/dist/core/types/thread-types.d.ts +48 -3
- package/dist/core/types/thread-types.js +2 -2
- package/dist/core/utils.d.ts +21 -1
- package/dist/core/utils.js +37 -1
- package/dist/domain/agent-run/access-probe-cli.d.ts +7 -0
- package/dist/domain/agent-run/access-probe-cli.js +139 -0
- package/dist/domain/agent-run/access-probe-policy.d.ts +61 -0
- package/dist/domain/agent-run/access-probe-policy.js +614 -0
- package/dist/domain/agent-run/access-probe.d.ts +21 -0
- package/dist/domain/agent-run/access-probe.js +194 -0
- package/dist/domain/agent-run/agent-run-cli.d.ts +19 -0
- package/dist/domain/agent-run/agent-run-cli.js +171 -0
- package/dist/domain/agent-run/atif.d.ts +54 -0
- package/dist/domain/agent-run/atif.js +211 -0
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +32 -0
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +616 -0
- package/dist/domain/agent-run/benchmark-thread-identity.d.ts +34 -0
- package/dist/domain/agent-run/benchmark-thread-identity.js +106 -0
- package/dist/domain/agent-run/identity.d.ts +62 -0
- package/dist/domain/agent-run/identity.js +118 -0
- package/dist/domain/agent-run/journal.d.ts +51 -0
- package/dist/domain/agent-run/journal.js +259 -0
- package/dist/domain/agent-run/manifest-contract.d.ts +44 -0
- package/dist/domain/agent-run/manifest-contract.js +134 -0
- package/dist/domain/agent-run/manifest.d.ts +51 -0
- package/dist/domain/agent-run/manifest.js +801 -0
- package/dist/domain/agent-run/pinned-node-process.d.ts +35 -0
- package/dist/domain/agent-run/pinned-node-process.js +206 -0
- package/dist/domain/agent-run/role-surface.d.ts +4 -0
- package/dist/domain/agent-run/role-surface.js +99 -0
- package/dist/domain/agent-run/run-config.d.ts +22 -0
- package/dist/domain/agent-run/run-config.js +135 -0
- package/dist/domain/agent-run/runner.d.ts +7 -0
- package/dist/domain/agent-run/runner.js +518 -0
- package/dist/domain/agent-run/supervisor.d.ts +78 -0
- package/dist/domain/agent-run/supervisor.js +425 -0
- package/dist/domain/agent-run/trajectory-merge-cli.d.ts +11 -0
- package/dist/domain/agent-run/trajectory-merge-cli.js +111 -0
- package/dist/domain/agent-run/trajectory-merge.d.ts +39 -0
- package/dist/domain/agent-run/trajectory-merge.js +505 -0
- package/dist/domain/agents/config.d.ts +10 -0
- package/dist/domain/agents/config.js +149 -44
- package/dist/domain/agents/facade.d.ts +42 -7
- package/dist/domain/agents/facade.js +174 -170
- package/dist/domain/agents/provider-run-lifecycle.d.ts +18 -0
- package/dist/domain/agents/provider-run-lifecycle.js +60 -0
- package/dist/domain/auth/auth-events.d.ts +18 -0
- package/dist/domain/auth/auth-events.js +38 -0
- package/dist/domain/auth/auth-format.d.ts +2 -0
- package/dist/domain/auth/auth-format.js +58 -0
- package/dist/domain/auth/auth-status.d.ts +61 -0
- package/dist/domain/auth/auth-status.js +304 -0
- package/dist/domain/auth/auth-watch.d.ts +16 -0
- package/dist/domain/auth/auth-watch.js +125 -0
- package/dist/domain/auth/cc-login.d.ts +7 -0
- package/dist/domain/auth/cc-login.js +16 -0
- package/dist/domain/auth/cc-subscription.d.ts +38 -0
- package/dist/domain/auth/cc-subscription.js +204 -0
- package/dist/domain/auth/index.d.ts +12 -0
- package/dist/domain/auth/index.js +16 -0
- package/dist/domain/auth/login-flow.d.ts +120 -0
- package/dist/domain/auth/login-flow.js +253 -0
- package/dist/domain/auth/login-service.d.ts +32 -0
- package/dist/domain/auth/login-service.js +97 -0
- package/dist/domain/auth/logout.d.ts +32 -0
- package/dist/domain/auth/logout.js +123 -0
- package/dist/domain/auth/pi-login.d.ts +36 -0
- package/dist/domain/auth/pi-login.js +72 -0
- package/dist/domain/auth/pi-oauth.d.ts +36 -0
- package/dist/domain/auth/pi-oauth.js +84 -0
- package/dist/domain/auth/pi-runtime.d.ts +72 -0
- package/dist/domain/auth/pi-runtime.js +86 -0
- package/dist/domain/mcp/benchmark-thread-server.d.ts +1 -0
- package/dist/domain/mcp/benchmark-thread-server.js +26 -0
- package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +23 -0
- package/dist/domain/mcp/tools/benchmark-thread-run.js +146 -0
- package/dist/domain/memory/user-context.js +6 -8
- package/dist/domain/monitor/disk-monitor.js +47 -16
- package/dist/domain/projects/project-store.js +23 -6
- package/dist/domain/remote/client-hot-reload.d.ts +9 -1
- package/dist/domain/remote/client-hot-reload.js +60 -12
- package/dist/domain/remote/client-manager.js +12 -6
- package/dist/domain/scheduling/jobs/auth-expiry-scan.d.ts +14 -0
- package/dist/domain/scheduling/jobs/auth-expiry-scan.js +86 -0
- package/dist/domain/scheduling/jobs/task-dispatch.js +36 -40
- package/dist/domain/scheduling/runner.d.ts +2 -0
- package/dist/domain/scheduling/runner.js +7 -4
- package/dist/domain/sessions/session-backup.d.ts +14 -20
- package/dist/domain/sessions/session-backup.js +57 -68
- package/dist/domain/system/doctor.d.ts +4 -0
- package/dist/domain/system/doctor.js +113 -28
- package/dist/domain/system/install-cli.js +8 -3
- package/dist/domain/system/server-update-check.js +7 -5
- package/dist/domain/system/system-notice.d.ts +3 -1
- package/dist/domain/system/system-notice.js +6 -11
- package/dist/domain/tasks/archiver.d.ts +1 -0
- package/dist/domain/tasks/archiver.js +13 -7
- package/dist/domain/tasks/claim-recovery.d.ts +3 -3
- package/dist/domain/tasks/claim-recovery.js +12 -8
- package/dist/domain/tasks/dispatch-utils.d.ts +15 -14
- package/dist/domain/tasks/dispatch-utils.js +22 -18
- package/dist/domain/tasks/dispatcher.d.ts +1 -0
- package/dist/domain/tasks/dispatcher.js +9 -5
- package/dist/domain/tasks/mutator.d.ts +21 -11
- package/dist/domain/tasks/mutator.js +30 -24
- package/dist/domain/tasks/pending-tracker.d.ts +5 -2
- package/dist/domain/tasks/pending-tracker.js +11 -5
- package/dist/domain/tasks/system/cortex-run.d.ts +2 -1
- package/dist/domain/tasks/system/cortex-run.js +24 -4
- package/dist/domain/tasks/system/task-cli.d.ts +1 -0
- package/dist/domain/tasks/system/task-cli.js +72 -22
- package/dist/domain/tasks/system/task-completion.d.ts +19 -2
- package/dist/domain/tasks/system/task-completion.js +31 -17
- package/dist/domain/tasks/system/task-file-input.d.ts +10 -0
- package/dist/domain/tasks/system/task-file-input.js +57 -0
- package/dist/domain/tasks/system/task-id-utils.d.ts +9 -9
- package/dist/domain/tasks/system/task-id-utils.js +13 -4
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -2
- package/dist/domain/tasks/system/task-lifecycle-edit.js +200 -6
- package/dist/domain/tasks/system/task-lock.js +19 -5
- package/dist/domain/tasks/system/task-mutations.d.ts +22 -12
- package/dist/domain/tasks/system/task-mutations.js +28 -4
- package/dist/domain/tasks/system/task-process.js +10 -8
- package/dist/domain/tasks/system/task-state.d.ts +65 -11
- package/dist/domain/tasks/system/task-state.js +86 -13
- package/dist/domain/threads/local-runtime-deps.d.ts +32 -0
- package/dist/domain/threads/local-runtime-deps.js +91 -0
- package/dist/domain/threads/local-runtime-scope.d.ts +6 -0
- package/dist/domain/threads/local-runtime-scope.js +12 -0
- package/dist/domain/threads/pending-user-inputs.d.ts +3 -0
- package/dist/domain/threads/pending-user-inputs.js +37 -0
- package/dist/domain/threads/prompt-builder.d.ts +12 -1
- package/dist/domain/threads/prompt-builder.js +73 -26
- package/dist/domain/threads/runner.d.ts +15 -3
- package/dist/domain/threads/runner.js +261 -105
- package/dist/domain/threads/state-machine.d.ts +1 -1
- package/dist/domain/threads/state-machine.js +17 -8
- package/dist/domain/ui-service/app-router.d.ts +86 -6
- package/dist/domain/ui-service/app-router.js +171 -133
- package/dist/domain/ui-service/input-schemas.d.ts +132 -10
- package/dist/domain/ui-service/input-schemas.js +59 -5
- package/dist/domain/ui-service/mutate/approvals.d.ts +2 -1
- package/dist/domain/ui-service/mutate/approvals.js +2 -1
- package/dist/domain/ui-service/mutate/auth.d.ts +6 -0
- package/dist/domain/ui-service/mutate/auth.js +83 -0
- package/dist/domain/ui-service/mutate/config.js +11 -10
- package/dist/domain/ui-service/query/approvals.js +3 -0
- package/dist/domain/ui-service/query/auth.d.ts +6 -0
- package/dist/domain/ui-service/query/auth.js +12 -0
- package/dist/domain/ui-service/query/config.d.ts +5 -5
- package/dist/domain/ui-service/query/config.js +27 -17
- package/dist/domain/ui-service/query/tasks.d.ts +1 -1
- package/dist/domain/ui-service/query/tasks.js +69 -30
- package/dist/domain/ui-service/query/threads.js +3 -3
- package/dist/domain/ui-service/types.d.ts +67 -8
- package/dist/domain/ui-service/types.js +2 -2
- package/dist/domain/ui-service/ui-service.js +16 -2
- package/dist/entry/admin-channel-hot-reload.d.ts +4 -0
- package/dist/entry/admin-channel-hot-reload.js +22 -0
- package/dist/entry/app.js +38 -38
- package/dist/entry/auth-cli.d.ts +10 -0
- package/dist/entry/auth-cli.js +52 -0
- package/dist/entry/cli-help.d.ts +5 -0
- package/dist/entry/cli-help.js +130 -0
- package/dist/entry/cli.d.ts +5 -5
- package/dist/entry/cli.js +174 -248
- package/dist/entry/daemon.d.ts +11 -0
- package/dist/entry/daemon.js +204 -103
- package/dist/entry/draft-attachments.d.ts +8 -0
- package/dist/entry/draft-attachments.js +83 -0
- package/dist/entry/feishu-login.d.ts +2 -6
- package/dist/entry/feishu-login.js +16 -21
- package/dist/entry/init.js +6 -4
- package/dist/entry/start-ui-http.d.ts +2 -8
- package/dist/entry/start-ui-http.js +7 -34
- package/dist/events/event-logger.js +11 -13
- package/dist/events/event-types.d.ts +19 -1
- package/dist/events/event-types.js +3 -3
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +3 -3
- package/dist/hooks/new-session-hook.mjs +2 -2
- package/dist/hooks/status-md-guard.mjs +193 -0
- package/dist/orchestration/agent-file-send.js +44 -14
- package/dist/orchestration/agent-runner.d.ts +7 -3
- package/dist/orchestration/agent-runner.js +65 -41
- package/dist/orchestration/conversation-runner.d.ts +5 -1
- package/dist/orchestration/conversation-runner.js +16 -7
- package/dist/orchestration/lifecycle.d.ts +23 -1
- package/dist/orchestration/lifecycle.js +103 -40
- package/dist/orchestration/mid-turn-inject.d.ts +2 -0
- package/dist/orchestration/mid-turn-inject.js +29 -13
- package/dist/orchestration/resume-dispatcher.d.ts +3 -5
- package/dist/orchestration/resume-dispatcher.js +9 -17
- package/dist/orchestration/routing/commands/index.d.ts +4 -1
- package/dist/orchestration/routing/commands/index.js +83 -61
- package/dist/orchestration/routing/commands/login-notice.d.ts +21 -0
- package/dist/orchestration/routing/commands/login-notice.js +97 -0
- package/dist/orchestration/routing/commands/login.d.ts +12 -0
- package/dist/orchestration/routing/commands/login.js +555 -0
- package/dist/orchestration/routing/commands/status.js +45 -59
- package/dist/orchestration/routing/edit-handler.d.ts +5 -0
- package/dist/orchestration/routing/edit-handler.js +127 -73
- package/dist/orchestration/routing/webhook.js +5 -4
- package/dist/orchestration/session-rewind.d.ts +5 -1
- package/dist/orchestration/session-rewind.js +106 -62
- package/dist/orchestration/session-send.d.ts +2 -0
- package/dist/orchestration/session-send.js +5 -6
- package/dist/orchestration/status-helpers.d.ts +1 -2
- package/dist/orchestration/status-helpers.js +7 -10
- package/dist/orchestration/thread-callback.d.ts +19 -11
- package/dist/orchestration/thread-callback.js +132 -61
- package/dist/orchestration/thread-executor.js +37 -27
- package/dist/orchestration/turn-mutation-lock.d.ts +3 -0
- package/dist/orchestration/turn-mutation-lock.js +36 -0
- package/dist/orchestration/turn-notify.d.ts +2 -5
- package/dist/orchestration/turn-notify.js +9 -21
- package/dist/platform/adapter.d.ts +1 -0
- package/dist/platform/adapter.js +2 -2
- package/dist/platform/adapters/composite-adapter.d.ts +2 -0
- package/dist/platform/adapters/composite-adapter.js +13 -3
- package/dist/platform/adapters/feishu.d.ts +2 -4
- package/dist/platform/adapters/feishu.js +38 -59
- package/dist/platform/adapters/index.d.ts +1 -1
- package/dist/platform/adapters/index.js +13 -12
- package/dist/platform/adapters/slack.d.ts +1 -1
- package/dist/platform/adapters/slack.js +12 -35
- package/dist/platform/index.d.ts +2 -1
- package/dist/platform/index.js +3 -3
- package/dist/platform/testing.d.ts +1 -0
- package/dist/platform/testing.js +13 -4
- package/dist/platform/tool-trace.js +6 -11
- package/dist/platform/ui-http/ui-http-server.d.ts +1 -1
- package/dist/platform/ui-http/ui-http-server.js +6 -18
- package/dist/store/execution-repo.d.ts +17 -1
- package/dist/store/execution-repo.js +55 -4
- package/dist/store/prompt-migration-replacements.d.ts +4 -0
- package/dist/store/prompt-migration-replacements.js +149 -0
- package/dist/store/thread-repo.d.ts +15 -4
- package/dist/store/thread-repo.js +61 -24
- package/dist/store/version-migrations.js +36 -1
- package/native/cortex-supervisor/dist/build-manifest.json +22 -0
- package/native/cortex-supervisor/dist/cortex-supervisor +0 -0
- package/package.json +5 -2
- package/web/dist/assets/index-XqBCYtkw.js +139 -0
- package/web/dist/assets/index-zpf3OSKC.css +1 -0
- package/web/dist/index.html +2 -2
- package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +0 -1
- package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +0 -78
- package/web/dist/assets/index-B19jLgji.js +0 -138
- package/web/dist/assets/index-BuFyPyRW.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// input: Environment, filesystem,
|
|
1
|
+
// input: Environment, filesystem, gateway, auth, and PI probes
|
|
2
2
|
// output: Doctor reports, default probes, and safe-fix actuators
|
|
3
3
|
// pos: Runs install-wide health diagnostics for cortex doctor
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
@@ -10,6 +10,8 @@ import { parse as parseDotenvLib } from 'dotenv';
|
|
|
10
10
|
import { DATA_DIR, CONFIG_DIR, STORE_DIR, GATEWAY_MANAGED_KEY_PLACEHOLDER } from '../../core/utils.js';
|
|
11
11
|
import { ensureAuthTokens, CLIENT_TOKEN_ENV, WEBHOOK_TOKEN_ENV } from '../../core/auth.js';
|
|
12
12
|
import { generateMcpConfig } from '../../core/config-generator.js';
|
|
13
|
+
import { getAuthStatus as readAuthStatus, } from '../auth/auth-status.js';
|
|
14
|
+
import { loadPiRuntime as loadInstalledPiRuntime, } from '../auth/pi-runtime.js';
|
|
13
15
|
// ─── Helpers ──────────────────────────────────────────────────────
|
|
14
16
|
const GW_HOST = '127.0.0.1';
|
|
15
17
|
const GW_PORT = 9880;
|
|
@@ -78,46 +80,60 @@ function sectionRuntime(deps) {
|
|
|
78
80
|
return { title: 'Runtime & Process', checks };
|
|
79
81
|
}
|
|
80
82
|
// ─── Section: Backend Install / Login ─────────────────────────────
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
// Directories exist + writable.
|
|
85
|
-
const dirProblems = [];
|
|
86
|
-
for (const [name, p] of [['DATA_DIR', data], ['CONFIG_DIR', config], ['STORE_DIR', store]]) {
|
|
83
|
+
function pushDirectoryCheck(checks, deps) {
|
|
84
|
+
const problems = [];
|
|
85
|
+
for (const [name, p] of Object.entries(deps.paths)) {
|
|
87
86
|
if (!deps.fileExists(p))
|
|
88
|
-
|
|
87
|
+
problems.push(`${name} missing (${p})`);
|
|
89
88
|
else if (!deps.isWritable(p))
|
|
90
|
-
|
|
89
|
+
problems.push(`${name} not writable (${p})`);
|
|
91
90
|
}
|
|
92
|
-
checks.push(
|
|
91
|
+
checks.push(problems.length === 0
|
|
93
92
|
? { id: 'dirs', label: 'Data directories', status: 'pass', detail: 'present and writable' }
|
|
94
|
-
: { id: 'dirs', label: 'Data directories', status: 'fail', detail:
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
: { id: 'dirs', label: 'Data directories', status: 'fail', detail: problems.join('; '), hint: 'run `cortex doctor --fix` or `cortex init`', fixable: true });
|
|
94
|
+
}
|
|
95
|
+
function pushEnvAndTokenChecks(checks, deps, getEnv) {
|
|
96
|
+
const envPath = path.join(deps.paths.CONFIG_DIR, '.env');
|
|
97
97
|
checks.push(deps.fileExists(envPath)
|
|
98
98
|
? { id: 'env-file', label: '.env file', status: 'pass', detail: envPath }
|
|
99
99
|
: { id: 'env-file', label: '.env file', status: 'fail', detail: `missing (${envPath})`, hint: 'run `cortex init`' });
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
checks.push(missingTokens.length === 0
|
|
100
|
+
const missing = [CLIENT_TOKEN_ENV, WEBHOOK_TOKEN_ENV].filter(name => !getEnv(name));
|
|
101
|
+
checks.push(missing.length === 0
|
|
103
102
|
? { id: 'auth-tokens', label: 'Auth tokens', status: 'pass', detail: 'client + webhook tokens set' }
|
|
104
|
-
: { id: 'auth-tokens', label: 'Auth tokens', status: 'fail', detail: `missing: ${
|
|
105
|
-
|
|
103
|
+
: { id: 'auth-tokens', label: 'Auth tokens', status: 'fail', detail: `missing: ${missing.join(', ')}`, hint: 'run `cortex doctor --fix` to generate', fixable: true });
|
|
104
|
+
}
|
|
105
|
+
function usesClaudeApiMode(deps) {
|
|
106
|
+
try {
|
|
107
|
+
const parsed = JSON.parse(deps.readText(path.join(deps.paths.STORE_DIR, 'mode.json')) ?? '');
|
|
108
|
+
return parsed.claudeMode === 'api'
|
|
109
|
+
|| (parsed.backend === 'claude' && parsed.mode === 'api');
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function gatewayBacksClaudeApi(deps, getEnv, gatewayHealthy) {
|
|
116
|
+
const apiKey = getEnv('ANTHROPIC_API_KEY');
|
|
117
|
+
const localKeyMissing = !apiKey || apiKey === GATEWAY_MANAGED_KEY_PLACEHOLDER;
|
|
118
|
+
return gatewayHealthy && localKeyMissing && usesClaudeApiMode(deps);
|
|
119
|
+
}
|
|
120
|
+
function pushAnthropicKeyCheck(checks, getEnv, gatewayBacked) {
|
|
106
121
|
const apiKey = getEnv('ANTHROPIC_API_KEY');
|
|
107
|
-
if (
|
|
108
|
-
checks.push({ id: 'anthropic-key', label: 'Anthropic API key', status: 'pass', detail: 'managed by gateway' });
|
|
122
|
+
if (gatewayBacked) {
|
|
123
|
+
checks.push({ id: 'anthropic-key', label: 'Anthropic API key', status: 'pass', detail: 'managed by healthy gateway' });
|
|
109
124
|
}
|
|
110
125
|
else if (apiKey) {
|
|
111
|
-
|
|
126
|
+
const detail = apiKey === GATEWAY_MANAGED_KEY_PLACEHOLDER ? 'managed by gateway' : 'set';
|
|
127
|
+
checks.push({ id: 'anthropic-key', label: 'Anthropic API key', status: 'pass', detail });
|
|
112
128
|
}
|
|
113
129
|
else {
|
|
114
130
|
checks.push({ id: 'anthropic-key', label: 'Anthropic API key', status: 'warn', detail: 'not set — required for API mode (plan/subscription mode can ignore)', hint: 'set ANTHROPIC_API_KEY in .env or run `cortex init`' });
|
|
115
131
|
}
|
|
116
|
-
|
|
132
|
+
}
|
|
133
|
+
function pushConfigChecks(checks, deps) {
|
|
134
|
+
const { CONFIG_DIR: config, STORE_DIR: store } = deps.paths;
|
|
117
135
|
pushJsonCheck(checks, deps, path.join(store, 'mode.json'), 'mode-json', 'mode.json', 'warn');
|
|
118
|
-
// profiles.json (schema-lite)
|
|
119
136
|
checks.push(checkProfiles(deps, path.join(config, 'profiles.json')));
|
|
120
|
-
// mcp-config.json
|
|
121
137
|
const mcpPath = path.join(config, 'mcp-config.json');
|
|
122
138
|
if (!deps.fileExists(mcpPath)) {
|
|
123
139
|
checks.push({ id: 'mcp-config', label: 'mcp-config.json', status: 'warn', detail: `missing (${mcpPath})`, hint: 'run `cortex doctor --fix` to regenerate', fixable: true });
|
|
@@ -128,6 +144,73 @@ function sectionBackend(deps, getEnv) {
|
|
|
128
144
|
else {
|
|
129
145
|
checks.push({ id: 'mcp-config', label: 'mcp-config.json', status: 'pass', detail: 'valid' });
|
|
130
146
|
}
|
|
147
|
+
}
|
|
148
|
+
const BACKEND_DOC_HINT = 'See docs/backends.md#remote-login';
|
|
149
|
+
const UNHEALTHY_AUTH_STATES = new Set(['expired', 'logged-out']);
|
|
150
|
+
async function checkPiRuntime(deps) {
|
|
151
|
+
if (!deps.commandExists('pi')) {
|
|
152
|
+
return { id: 'pi-runtime', label: 'PI runtime', status: 'skip', detail: 'pi not installed' };
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const result = await deps.loadPiRuntime();
|
|
156
|
+
if (result.available && typeof result.runtime.login === 'function') {
|
|
157
|
+
const version = result.version ? ` (${result.version})` : '';
|
|
158
|
+
return { id: 'pi-runtime', label: 'PI runtime', status: 'pass', detail: `available${version}; login export found` };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Report the stable diagnostic only; dependency errors may contain sensitive paths or values.
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
id: 'pi-runtime', label: 'PI runtime', status: 'warn',
|
|
166
|
+
detail: 'installed PI runtime or login export unavailable', hint: BACKEND_DOC_HINT,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function gatewayCovered(account, gatewayBacked) {
|
|
170
|
+
return gatewayBacked
|
|
171
|
+
&& account.backend === 'claude'
|
|
172
|
+
&& account.provider === 'anthropic'
|
|
173
|
+
&& account.state === 'logged-out';
|
|
174
|
+
}
|
|
175
|
+
function backendAuthSummary(snapshot, gatewayBacked) {
|
|
176
|
+
const inUse = snapshot.accounts.filter(account => account.inUse);
|
|
177
|
+
const covered = inUse.filter(account => gatewayCovered(account, gatewayBacked));
|
|
178
|
+
const unhealthy = inUse.filter(account => (UNHEALTHY_AUTH_STATES.has(account.state) && !gatewayCovered(account, gatewayBacked)));
|
|
179
|
+
const providers = [...new Set(unhealthy.map(account => account.provider))].sort();
|
|
180
|
+
if (unhealthy.length > 0) {
|
|
181
|
+
return {
|
|
182
|
+
id: 'backend-auth', label: 'Backend authentication', status: 'warn',
|
|
183
|
+
detail: `${inUse.length} in use; ${unhealthy.length} expired or logged out: ${providers.join(', ')}`,
|
|
184
|
+
hint: BACKEND_DOC_HINT,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const gateway = covered.length > 0 ? '; gateway-backed: anthropic' : '';
|
|
188
|
+
return {
|
|
189
|
+
id: 'backend-auth', label: 'Backend authentication', status: 'pass',
|
|
190
|
+
detail: `${inUse.length} in use; 0 expired or logged out${gateway}`,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async function checkBackendAuth(deps, gatewayBacked) {
|
|
194
|
+
try {
|
|
195
|
+
return backendAuthSummary(await deps.getAuthStatus(), gatewayBacked);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return {
|
|
199
|
+
id: 'backend-auth', label: 'Backend authentication', status: 'warn',
|
|
200
|
+
detail: 'authentication summary unavailable', hint: BACKEND_DOC_HINT,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async function sectionBackend(deps, getEnv, gatewayHealthy) {
|
|
205
|
+
const checks = [];
|
|
206
|
+
const gatewayBacked = gatewayBacksClaudeApi(deps, getEnv, gatewayHealthy);
|
|
207
|
+
pushDirectoryCheck(checks, deps);
|
|
208
|
+
pushEnvAndTokenChecks(checks, deps, getEnv);
|
|
209
|
+
pushAnthropicKeyCheck(checks, getEnv, gatewayBacked);
|
|
210
|
+
pushConfigChecks(checks, deps);
|
|
211
|
+
checks.push(...await Promise.all([
|
|
212
|
+
checkPiRuntime(deps), checkBackendAuth(deps, gatewayBacked),
|
|
213
|
+
]));
|
|
131
214
|
return { title: 'Backend Install / Login', checks };
|
|
132
215
|
}
|
|
133
216
|
function isValidJson(text) {
|
|
@@ -217,14 +300,13 @@ function sectionPlatform(deps, getEnv) {
|
|
|
217
300
|
return { title: 'Messaging Platform', checks };
|
|
218
301
|
}
|
|
219
302
|
// ─── Section: Gateway ─────────────────────────────────────────────
|
|
220
|
-
|
|
303
|
+
function sectionGateway(deps, getEnv, healthy) {
|
|
221
304
|
const checks = [];
|
|
222
305
|
const gwYaml = path.join(deps.homeDir, '.aistatus', 'gateway.yaml');
|
|
223
306
|
const gwConfigured = deps.fileExists(gwYaml);
|
|
224
307
|
checks.push(gwConfigured
|
|
225
308
|
? { id: 'gateway-config', label: 'Gateway config', status: 'pass', detail: gwYaml }
|
|
226
309
|
: { id: 'gateway-config', label: 'Gateway config', status: 'skip', detail: 'not configured (no ~/.aistatus/gateway.yaml)', hint: 'run `cortex setup-gateway` if you use the gateway' });
|
|
227
|
-
const healthy = await deps.probeGateway();
|
|
228
310
|
const gatewayInUse = getEnv('ANTHROPIC_API_KEY') === GATEWAY_MANAGED_KEY_PLACEHOLDER || gwConfigured;
|
|
229
311
|
if (healthy) {
|
|
230
312
|
checks.push({ id: 'gateway-health', label: 'Gateway health', status: 'pass', detail: `responding at ${GW_HOST}:${GW_PORT}` });
|
|
@@ -240,11 +322,12 @@ async function sectionGateway(deps, getEnv) {
|
|
|
240
322
|
// ─── Engine ───────────────────────────────────────────────────────
|
|
241
323
|
export async function runDiagnostics(deps) {
|
|
242
324
|
const getEnv = buildEnvReader(deps);
|
|
325
|
+
const gatewayHealthy = await deps.probeGateway();
|
|
243
326
|
const sections = [
|
|
244
327
|
sectionRuntime(deps),
|
|
245
|
-
sectionBackend(deps, getEnv),
|
|
328
|
+
await sectionBackend(deps, getEnv, gatewayHealthy),
|
|
246
329
|
sectionPlatform(deps, getEnv),
|
|
247
|
-
|
|
330
|
+
sectionGateway(deps, getEnv, gatewayHealthy),
|
|
248
331
|
];
|
|
249
332
|
const counts = { pass: 0, warn: 0, fail: 0, skip: 0 };
|
|
250
333
|
for (const s of sections)
|
|
@@ -342,6 +425,8 @@ export function createDefaultDoctorDeps() {
|
|
|
342
425
|
return false;
|
|
343
426
|
} },
|
|
344
427
|
probeGateway: probeGatewayHttp,
|
|
428
|
+
loadPiRuntime: () => loadInstalledPiRuntime(),
|
|
429
|
+
getAuthStatus: () => readAuthStatus(),
|
|
345
430
|
};
|
|
346
431
|
}
|
|
347
432
|
export function createDefaultFixActuators() {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// input: CORTEX_VERSION, child_process (execSync, spawn), compareCalVer from server-update-check
|
|
1
|
+
// input: CORTEX_VERSION, child_process (execSync, spawn), compareCalVer from server-update-check, withNpmPrefix
|
|
2
2
|
// output: cortex install latest CLI
|
|
3
3
|
// pos: CLI module for cortex install — install latest Cortex version from npm
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { execSync, spawn } from 'node:child_process';
|
|
6
6
|
import { CORTEX_VERSION } from '../../core/version.js';
|
|
7
|
+
import { withNpmPrefix } from '../../core/utils.js';
|
|
7
8
|
import { compareCalVer } from './server-update-check.js';
|
|
8
9
|
// ─── Help ─────────────────────────────────────────────────────────
|
|
9
10
|
export function getInstallHelp() {
|
|
@@ -56,9 +57,13 @@ async function installLatest() {
|
|
|
56
57
|
process.stdout.write(`Current version: ${CORTEX_VERSION}\n`);
|
|
57
58
|
process.stdout.write(`Latest version: ${latest}\n`);
|
|
58
59
|
process.stdout.write(`Installing @cortex-agent/server@${latest}...\n\n`);
|
|
59
|
-
// 4. Run npm install -g (stdio: 'inherit' so user sees npm progress)
|
|
60
|
+
// 4. Run npm install -g (stdio: 'inherit' so user sees npm progress).
|
|
61
|
+
// The prefix is pinned to the root the running `cortex` binary lives in — without it
|
|
62
|
+
// npm falls back to its configured/system prefix (root-owned → EACCES) on machines
|
|
63
|
+
// that were installed with `--prefix ~/.npm-global` but no .npmrc entry.
|
|
60
64
|
return new Promise((resolve) => {
|
|
61
|
-
const
|
|
65
|
+
const args = withNpmPrefix(['install', '-g', `@cortex-agent/server@${latest}`], 'cortex');
|
|
66
|
+
const child = spawn('npm', args, {
|
|
62
67
|
stdio: 'inherit',
|
|
63
68
|
cwd: '/tmp',
|
|
64
69
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output: compareCalVer
|
|
3
|
-
// pos:
|
|
1
|
+
// input: update prompt/state, version, runtime settings
|
|
2
|
+
// output: compareCalVer, isUpdateDevMode, checkServerUpdate
|
|
3
|
+
// pos: Checks and dispatches server package updates
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
4
5
|
import * as fs from 'node:fs';
|
|
5
6
|
import { execSync, spawn } from 'node:child_process';
|
|
7
|
+
import { getSettings } from '../../core/settings.js';
|
|
6
8
|
import { CORTEX_VERSION } from '../../core/version.js';
|
|
7
9
|
import { loadUpdateState, saveUpdateState } from './update-state.js';
|
|
8
10
|
// ── CalVer comparison ────────────────────────────────────────────
|
|
@@ -51,8 +53,8 @@ function defaultNow() {
|
|
|
51
53
|
}
|
|
52
54
|
// ── Main check-and-prompt flow ──────────────────────────────────
|
|
53
55
|
export async function checkServerUpdate(deps) {
|
|
54
|
-
// 1. Disable toggle: auto-update is on by default
|
|
55
|
-
if (
|
|
56
|
+
// 1. Disable toggle: auto-update is on by default.
|
|
57
|
+
if (getSettings().serverUpdateDisable) {
|
|
56
58
|
return { action: null, latestVersion: null };
|
|
57
59
|
}
|
|
58
60
|
// 2. Dev mode: skip entirely
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PlatformAdapter } from '../../platform/index.js';
|
|
1
|
+
import type { PlatformAdapter, RichBlock } from '../../platform/index.js';
|
|
2
2
|
export type SystemNoticeLevel = 'info' | 'warning' | 'error';
|
|
3
3
|
export interface SystemNoticeInput {
|
|
4
4
|
/** The notice body (same text that goes to the admin channel). */
|
|
@@ -7,6 +7,8 @@ export interface SystemNoticeInput {
|
|
|
7
7
|
level?: SystemNoticeLevel;
|
|
8
8
|
/** Optional short title (e.g. "Disk", "Rate limit"); the Web UI falls back to a level label. */
|
|
9
9
|
title?: string;
|
|
10
|
+
/** Optional platform-native content; Web notices continue to use the secret-free text fields. */
|
|
11
|
+
richBlocks?: RichBlock[];
|
|
10
12
|
}
|
|
11
13
|
/** Publish a `system.notice` event on the shared EventBus (the Web notification-toast source).
|
|
12
14
|
* No-op when no bus is wired (matches publishSessionMessage). */
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output:
|
|
3
|
-
// pos:
|
|
4
|
-
//
|
|
5
|
-
// shared EventBus from the job-registry ctx (same seam session-events uses), so the
|
|
6
|
-
// `system.notice` event feeds the Web notification toaster while the platform post
|
|
7
|
-
// keeps delivering to the configured admin channel. Bus publish is a no-op if no bus
|
|
8
|
-
// is wired; the platform post is best-effort and never throws.
|
|
9
|
-
// >>> If I am updated, update the parent folder's CORTEX.md <<<
|
|
1
|
+
// input: PlatformAdapter, notice payload, shared job context
|
|
2
|
+
// output: Web publication and rich best-effort admin delivery
|
|
3
|
+
// pos: Domain seam for admin and system broadcasts
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
10
5
|
import { ctx as jobCtx } from '../scheduling/job-registry.js';
|
|
11
6
|
/** Publish a `system.notice` event on the shared EventBus (the Web notification-toast source).
|
|
12
7
|
* No-op when no bus is wired (matches publishSessionMessage). */
|
|
@@ -25,8 +20,8 @@ export function publishSystemNotice(p) {
|
|
|
25
20
|
export async function emitSystemNotice(adapter, p) {
|
|
26
21
|
publishSystemNotice(p);
|
|
27
22
|
try {
|
|
28
|
-
await adapter.postMessage({ type: 'system-notice' }, { text: p.text });
|
|
29
|
-
return
|
|
23
|
+
const ref = await adapter.postMessage({ type: 'system-notice' }, { text: p.text, ...(p.richBlocks ? { richBlocks: p.richBlocks } : {}) });
|
|
24
|
+
return ref.conduit.length > 0;
|
|
30
25
|
}
|
|
31
26
|
catch {
|
|
32
27
|
return false;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
// input: task store, project paths, filesystem, git, task mutation lock
|
|
2
|
+
// output: atomically removed and archived completed tasks plus archive commits
|
|
3
|
+
// pos: Scheduled retention job serialized with lifecycle writers
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
1
5
|
import * as fs from 'fs';
|
|
2
6
|
import * as path from 'path';
|
|
3
7
|
import { execSync } from 'child_process';
|
|
4
8
|
import { PROJECTS_DIR, DATA_DIR } from '../../core/utils.js';
|
|
5
9
|
import { createLogger } from '../../core/log.js';
|
|
6
|
-
import {
|
|
10
|
+
import { readTasks, withTaskFileMutationLock, writeTasks, } from './system/task-lifecycle-edit.js';
|
|
7
11
|
import { taskStore } from './store.js';
|
|
8
12
|
const log = createLogger('task-archiver');
|
|
9
13
|
const ARCHIVE_AGE_DAYS = 3;
|
|
10
|
-
function isOlderThan(dateStr, days) {
|
|
11
|
-
const completed = new Date(dateStr
|
|
14
|
+
export function isOlderThan(dateStr, days) {
|
|
15
|
+
const completed = new Date(`${dateStr.slice(0, 10)}T00:00:00Z`);
|
|
12
16
|
const cutoff = new Date();
|
|
13
17
|
cutoff.setUTCDate(cutoff.getUTCDate() - days);
|
|
14
18
|
cutoff.setUTCHours(0, 0, 0, 0);
|
|
@@ -26,12 +30,11 @@ function formatTaskForArchive(task) {
|
|
|
26
30
|
lines.push(` Completed: ${task.completed_at}${task.completed_note ? ` (${task.completed_note})` : ''}`);
|
|
27
31
|
return lines.join('\n');
|
|
28
32
|
}
|
|
29
|
-
function
|
|
33
|
+
function processProjectUnlocked(projectName) {
|
|
30
34
|
const tasksPath = path.join(PROJECTS_DIR, projectName, 'TASKS.yaml');
|
|
31
35
|
if (!fs.existsSync(tasksPath))
|
|
32
36
|
return null;
|
|
33
|
-
const
|
|
34
|
-
const tasks = parseTasksFile(content, projectName);
|
|
37
|
+
const tasks = readTasks(projectName);
|
|
35
38
|
const toArchive = [];
|
|
36
39
|
const toKeep = [];
|
|
37
40
|
for (const task of tasks) {
|
|
@@ -57,10 +60,13 @@ function processProject(projectName) {
|
|
|
57
60
|
for (const task of toArchive) {
|
|
58
61
|
archiveContent += '\n' + formatTaskForArchive(task) + '\n';
|
|
59
62
|
}
|
|
60
|
-
|
|
63
|
+
writeTasks(projectName, toKeep);
|
|
61
64
|
fs.writeFileSync(archivePath, archiveContent);
|
|
62
65
|
return { project: projectName, ids: archivedIds };
|
|
63
66
|
}
|
|
67
|
+
function processProject(projectName) {
|
|
68
|
+
return withTaskFileMutationLock(projectName, () => processProjectUnlocked(projectName));
|
|
69
|
+
}
|
|
64
70
|
function gitCommit(results) {
|
|
65
71
|
const files = [];
|
|
66
72
|
for (const r of results) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Task } from '../../core/task-parser.js';
|
|
2
2
|
export interface ClaimRecoveryDeps {
|
|
3
3
|
scan?: () => Task[];
|
|
4
|
-
ownedByLiveThread?: (
|
|
5
|
-
isTracked?: (
|
|
6
|
-
unclaim?: (taskId: string) => Promise<unknown>;
|
|
4
|
+
ownedByLiveThread?: (task: Task) => boolean;
|
|
5
|
+
isTracked?: (task: Task) => boolean;
|
|
6
|
+
unclaim?: (taskId: string, generation: string | null) => Promise<unknown>;
|
|
7
7
|
}
|
|
8
8
|
/** Unclaim every dispatcher claim with no surviving owner. Returns the recovered task ids.
|
|
9
9
|
* Idempotent and fail-soft: one failing unclaim never aborts the sweep. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// input: TASKS.yaml
|
|
2
|
-
// output:
|
|
1
|
+
// input: TASKS.yaml generations, threadStore, pending-tracker, taskMutator
|
|
2
|
+
// output: generation-fenced startup reconciliation of orphaned dispatch claims
|
|
3
3
|
// pos: called once from entry/app.ts right after threadStore.markRunningAsFailedOnStartup.
|
|
4
4
|
// A claimed task is invisible to the dispatcher (isActionable excludes claimed_by), so a
|
|
5
5
|
// dispatch claim whose owner died with the server would otherwise stay in-progress forever
|
|
@@ -26,9 +26,11 @@ const CLAIM_HOLDING_THREAD_STATUSES = new Set(['running', 'waiting', 'rate_limit
|
|
|
26
26
|
* Idempotent and fail-soft: one failing unclaim never aborts the sweep. */
|
|
27
27
|
export async function recoverOrphanedClaims(deps = {}) {
|
|
28
28
|
const scan = deps.scan ?? (() => scanAllTasks());
|
|
29
|
-
const ownedByLiveThread = deps.ownedByLiveThread ?? ((
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const ownedByLiveThread = deps.ownedByLiveThread ?? ((task) => threadStore.getAll().some((t) => CLAIM_HOLDING_THREAD_STATUSES.has(t.status)
|
|
30
|
+
&& t.metadata?.taskId === task.id
|
|
31
|
+
&& (t.metadata?.dispatchGeneration ?? null) === task.dispatch_generation));
|
|
32
|
+
const isTracked = deps.isTracked ?? ((task) => pendingTaskTracker.isTaskTracked(task.id, task.project, task.dispatch_generation));
|
|
33
|
+
const unclaim = deps.unclaim ?? ((taskId, generation) => taskMutator.unclaim(taskId, { ownership: { generation } }));
|
|
32
34
|
let tasks;
|
|
33
35
|
try {
|
|
34
36
|
tasks = scan();
|
|
@@ -45,12 +47,14 @@ export async function recoverOrphanedClaims(deps = {}) {
|
|
|
45
47
|
continue; // pending → cortex-run owns it
|
|
46
48
|
if (task.blocked_by)
|
|
47
49
|
continue; // blocked is already a terminal signal for the tree
|
|
48
|
-
if (ownedByLiveThread(task
|
|
50
|
+
if (ownedByLiveThread(task))
|
|
49
51
|
continue; // suspended manager / rate-limit-paused thread
|
|
50
|
-
if (isTracked(task
|
|
52
|
+
if (isTracked(task))
|
|
51
53
|
continue; // remote dispatch tracked in pending-tasks.json
|
|
52
54
|
try {
|
|
53
|
-
await unclaim(task.id);
|
|
55
|
+
const result = await unclaim(task.id, task.dispatch_generation);
|
|
56
|
+
if (result?.success === false)
|
|
57
|
+
continue;
|
|
54
58
|
recovered.push(task.id);
|
|
55
59
|
log.info(`recovered orphaned dispatch claim on [${task.project}] ${task.id} — task returned to the queue`);
|
|
56
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TaskGenerationExpectation } from '../../core/task-parser.js';
|
|
1
2
|
export interface MachineEntry {
|
|
2
3
|
cortexPath: string;
|
|
3
4
|
gpuCount: number;
|
|
@@ -58,24 +59,22 @@ export interface SplitOutcome {
|
|
|
58
59
|
note?: string;
|
|
59
60
|
error?: string;
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
* decompose keep-parent (the task becomes a join/acceptance node over its new children)
|
|
63
|
-
* and unclaim it so the children flow through the normal queue. Parse errors are surfaced
|
|
64
|
-
* (and the task still unclaimed) instead of silently dropped. Deps are injected by the
|
|
65
|
-
* caller (task-dispatch wires the real detect/decompose/unclaim) — keeps this testable
|
|
66
|
-
* and this module free of thread-system imports. */
|
|
67
|
-
declare function processSplitOutcome(args: {
|
|
62
|
+
interface SplitOutcomeArgs {
|
|
68
63
|
threadId: string;
|
|
69
64
|
taskId: string | null;
|
|
70
65
|
project: string;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
ownership?: TaskGenerationExpectation;
|
|
67
|
+
}
|
|
68
|
+
interface SplitDetection {
|
|
69
|
+
split: boolean;
|
|
70
|
+
subtasks: any[] | null;
|
|
71
|
+
error: string | null;
|
|
72
|
+
}
|
|
73
|
+
interface SplitOutcomeDeps {
|
|
74
|
+
detect: (threadId: string) => SplitDetection;
|
|
77
75
|
decompose: (project: string, text: string | null, subtasks: any[], taskId: string | null, options: {
|
|
78
76
|
keepParent?: boolean;
|
|
77
|
+
ownership?: TaskGenerationExpectation;
|
|
79
78
|
}) => {
|
|
80
79
|
success: boolean;
|
|
81
80
|
message: string;
|
|
@@ -84,7 +83,9 @@ declare function processSplitOutcome(args: {
|
|
|
84
83
|
message: string;
|
|
85
84
|
}>;
|
|
86
85
|
unclaim: (taskId: string) => Promise<unknown>;
|
|
87
|
-
}
|
|
86
|
+
}
|
|
87
|
+
/** Process a worker thread's [SPLIT] proposal and preserve dispatch ownership. */
|
|
88
|
+
declare function processSplitOutcome(args: SplitOutcomeArgs, deps: SplitOutcomeDeps): Promise<SplitOutcome>;
|
|
88
89
|
export interface AbortOutcome {
|
|
89
90
|
handled: boolean;
|
|
90
91
|
note?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output:
|
|
3
|
-
// pos:
|
|
1
|
+
// input: machine config, task generation ownership
|
|
2
|
+
// output: device registry, task IDs, dispatch outcome helpers
|
|
3
|
+
// pos: Shared task dispatch utilities
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import * as crypto from 'crypto';
|
|
6
6
|
import { readFileSync, watch, existsSync } from 'fs';
|
|
@@ -141,25 +141,29 @@ function _testSetRegistry(registry) {
|
|
|
141
141
|
_registry = { ...registry };
|
|
142
142
|
_loaded = true;
|
|
143
143
|
}
|
|
144
|
-
|
|
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 };
|
|
144
|
+
async function invalidSplitOutcome(args, detection, deps) {
|
|
154
145
|
if (!args.taskId) {
|
|
155
146
|
log.warn(`[SPLIT] marker in thread ${args.threadId} but no associated task — ignoring`);
|
|
156
147
|
return { handled: false };
|
|
157
148
|
}
|
|
158
|
-
if (detection.error
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
149
|
+
if (!detection.error && detection.subtasks)
|
|
150
|
+
return null;
|
|
151
|
+
await deps.unclaim(args.taskId);
|
|
152
|
+
return { handled: true, error: detection.error || '[SPLIT] proposal empty' };
|
|
153
|
+
}
|
|
154
|
+
/** Process a worker thread's [SPLIT] proposal and preserve dispatch ownership. */
|
|
155
|
+
async function processSplitOutcome(args, deps) {
|
|
156
|
+
const detection = deps.detect(args.threadId);
|
|
157
|
+
if (!detection.split)
|
|
158
|
+
return { handled: false };
|
|
159
|
+
const invalid = await invalidSplitOutcome(args, detection, deps);
|
|
160
|
+
if (invalid)
|
|
161
|
+
return invalid;
|
|
162
|
+
const ownershipOption = args.ownership ? { ownership: args.ownership } : {};
|
|
163
|
+
const result = await deps.decompose(args.project, null, detection.subtasks, args.taskId, {
|
|
164
|
+
keepParent: true,
|
|
165
|
+
...ownershipOption,
|
|
166
|
+
});
|
|
163
167
|
if (!result.success) {
|
|
164
168
|
await deps.unclaim(args.taskId);
|
|
165
169
|
return { handled: true, error: result.message };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// input: task
|
|
2
|
-
// output:
|
|
3
|
-
// pos:
|
|
1
|
+
// input: task store, execution registry, templates, rate limits
|
|
2
|
+
// output: generation-owned claims, dispatch filters, interval helpers
|
|
3
|
+
// pos: Selects and claims the next dispatchable task
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
5
6
|
import { createLogger } from '../../core/log.js';
|
|
6
7
|
import { isProjectLocked } from './system/task-lock.js';
|
|
7
8
|
const log = createLogger('task-dispatch');
|
|
@@ -327,10 +328,12 @@ async function selectAndClaimTask({ scheduleTaskId, dryRun = false, profileName
|
|
|
327
328
|
task: selectedTask,
|
|
328
329
|
prompt: buildDispatchPrompt(selectedTask),
|
|
329
330
|
template: selectedTask.template || null,
|
|
331
|
+
dispatchGeneration: null,
|
|
330
332
|
};
|
|
331
333
|
}
|
|
332
|
-
// Claim task
|
|
333
|
-
const
|
|
334
|
+
// Claim task under a fresh incarnation fence.
|
|
335
|
+
const dispatchGeneration = randomUUID();
|
|
336
|
+
const claimResult = await taskMutator.claim(selectedTask.id, 'task-dispatcher', { generation: dispatchGeneration });
|
|
334
337
|
if (!claimResult.success) {
|
|
335
338
|
log.info(`Claim failed: ${claimResult.message}`);
|
|
336
339
|
return null;
|
|
@@ -340,6 +343,7 @@ async function selectAndClaimTask({ scheduleTaskId, dryRun = false, profileName
|
|
|
340
343
|
task: selectedTask,
|
|
341
344
|
prompt,
|
|
342
345
|
template: selectedTask.template || null,
|
|
346
|
+
dispatchGeneration,
|
|
343
347
|
};
|
|
344
348
|
}
|
|
345
349
|
export { selectAndClaimTask, hasRunningExecutionForSchedule, computeNextInterval, updateScheduleInterval, isValidDispatchPrompt, isTemplateRateLimited,
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import { TaskRepo } from '../../store/task-repo.js';
|
|
2
|
+
import type { TaskGenerationExpectation } from '../../core/task-parser.js';
|
|
2
3
|
import type { EventBus } from '../../events/index.js';
|
|
4
|
+
interface ClaimTaskOptions {
|
|
5
|
+
generation?: string | null;
|
|
6
|
+
}
|
|
7
|
+
interface OwnedMutationOptions {
|
|
8
|
+
ownership?: TaskGenerationExpectation;
|
|
9
|
+
}
|
|
10
|
+
interface CompleteTaskOptions extends OwnedMutationOptions {
|
|
11
|
+
skipVerify?: boolean;
|
|
12
|
+
skipVerifyReason?: string;
|
|
13
|
+
ownership?: TaskGenerationExpectation;
|
|
14
|
+
}
|
|
3
15
|
interface AddTaskOptions {
|
|
4
16
|
plan?: string;
|
|
5
17
|
system?: boolean;
|
|
6
18
|
}
|
|
19
|
+
interface DecomposeTaskOptions extends OwnedMutationOptions {
|
|
20
|
+
keepParent?: boolean;
|
|
21
|
+
system?: boolean;
|
|
22
|
+
}
|
|
7
23
|
export declare class TaskMutator {
|
|
8
24
|
private store;
|
|
9
25
|
private bus?;
|
|
@@ -13,14 +29,11 @@ export declare class TaskMutator {
|
|
|
13
29
|
* threads) reach the in-memory cache only on refresh — callers like the cortex-run
|
|
14
30
|
* callback may fire before any dispatch cycle has reloaded TASKS.yaml. */
|
|
15
31
|
private getByIdFresh;
|
|
16
|
-
claim(taskId: string, agent: string): Promise<any>;
|
|
17
|
-
unclaim(taskId: string): Promise<any>;
|
|
18
|
-
complete(taskId: string, note?: string, options?:
|
|
19
|
-
skipVerify?: boolean;
|
|
20
|
-
skipVerifyReason?: string;
|
|
21
|
-
}): Promise<any>;
|
|
32
|
+
claim(taskId: string, agent: string, options?: ClaimTaskOptions): Promise<any>;
|
|
33
|
+
unclaim(taskId: string, options?: OwnedMutationOptions): Promise<any>;
|
|
34
|
+
complete(taskId: string, note?: string, options?: CompleteTaskOptions): Promise<any>;
|
|
22
35
|
uncomplete(taskId: string): Promise<any>;
|
|
23
|
-
block(taskId: string, reason: string): Promise<any>;
|
|
36
|
+
block(taskId: string, reason: string, options?: OwnedMutationOptions): Promise<any>;
|
|
24
37
|
unblock(taskId: string): Promise<any>;
|
|
25
38
|
pause(taskId: string): Promise<any>;
|
|
26
39
|
resume(taskId: string): Promise<any>;
|
|
@@ -31,10 +44,7 @@ export declare class TaskMutator {
|
|
|
31
44
|
add(project: string, text: string, why: string, doneWhen: string, priority?: string, template?: string, dependsOn?: string[], options?: AddTaskOptions): Promise<any>;
|
|
32
45
|
private addSystemTask;
|
|
33
46
|
edit(project: string, options: any): Promise<any>;
|
|
34
|
-
decompose(project: string, taskText: string | null, subtasks: any[], taskId?: string | null, options?:
|
|
35
|
-
keepParent?: boolean;
|
|
36
|
-
system?: boolean;
|
|
37
|
-
}): Promise<any>;
|
|
47
|
+
decompose(project: string, taskText: string | null, subtasks: any[], taskId?: string | null, options?: DecomposeTaskOptions): Promise<any>;
|
|
38
48
|
}
|
|
39
49
|
export declare const taskMutator: TaskMutator;
|
|
40
50
|
export {};
|