@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
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// input: CONFIG_DIR, settings spec, process env, filesystem
|
|
2
|
+
// output: validated settings, disk updates, and test reset
|
|
3
|
+
// pos: L0 file-backed runtime settings boundary
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
|
+
import { readFileSync, watch } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { AsyncMutex } from './async-mutex.js';
|
|
8
|
+
import { atomicWrite } from './atomic-write.js';
|
|
9
|
+
import { createLogger } from './log.js';
|
|
10
|
+
import { CONFIG_DIR } from './paths.js';
|
|
11
|
+
import { SETTINGS_SPEC, } from './settings-spec.js';
|
|
12
|
+
export { SETTINGS_SPEC, } from './settings-spec.js';
|
|
13
|
+
const log = createLogger('settings');
|
|
14
|
+
const SETTINGS_FILE = path.join(CONFIG_DIR, 'settings.json');
|
|
15
|
+
const SETTING_KEYS = Object.keys(SETTINGS_SPEC);
|
|
16
|
+
const TRUTHY_ENV_KEYS = new Set(['adminChannel', 'feishuAdminChannel']);
|
|
17
|
+
const callbacks = new Set();
|
|
18
|
+
const loggedEnvFallbacks = new Set();
|
|
19
|
+
const writeMutex = new AsyncMutex();
|
|
20
|
+
let initialized = false;
|
|
21
|
+
let cachedOverrides = {};
|
|
22
|
+
let cachedSettings = null;
|
|
23
|
+
let cachedSettingsSnapshot = null;
|
|
24
|
+
let settingsWatcher = null;
|
|
25
|
+
let reloadTimer = null;
|
|
26
|
+
let selfWriting = false;
|
|
27
|
+
const typeValidators = {
|
|
28
|
+
boolean: (value) => typeof value === 'boolean',
|
|
29
|
+
number: (value) => typeof value === 'number' && Number.isFinite(value),
|
|
30
|
+
'number|null': (value) => value === null || (typeof value === 'number' && Number.isFinite(value)),
|
|
31
|
+
'string[]': (value) => Array.isArray(value) && value.every((item) => typeof item === 'string'),
|
|
32
|
+
'string|null': (value) => value === null || typeof value === 'string',
|
|
33
|
+
};
|
|
34
|
+
export function validateSettingsOverrides(value) {
|
|
35
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
36
|
+
throw new TypeError('settings.json must contain a JSON object');
|
|
37
|
+
}
|
|
38
|
+
for (const key of SETTING_KEYS) {
|
|
39
|
+
if (!Object.hasOwn(value, key))
|
|
40
|
+
continue;
|
|
41
|
+
const entry = SETTINGS_SPEC[key];
|
|
42
|
+
if (!typeValidators[entry.type](value[key])) {
|
|
43
|
+
throw new TypeError(`settings.json key "${key}" must have type ${entry.type}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function readOverrides() {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(readFileSync(SETTINGS_FILE, 'utf8'));
|
|
50
|
+
validateSettingsOverrides(parsed);
|
|
51
|
+
return parsed;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error?.code === 'ENOENT')
|
|
55
|
+
return {};
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function logEnvFallback(key, envVar) {
|
|
60
|
+
if (loggedEnvFallbacks.has(envVar))
|
|
61
|
+
return;
|
|
62
|
+
loggedEnvFallbacks.add(envVar);
|
|
63
|
+
log.warn(`Deprecated env ${envVar} supplies settings.${key}; move it to settings.json`);
|
|
64
|
+
}
|
|
65
|
+
function resolveSettingEntry(key, overrides, env, warnOnEnv) {
|
|
66
|
+
const entry = SETTINGS_SPEC[key];
|
|
67
|
+
if (Object.hasOwn(overrides, key)) {
|
|
68
|
+
return { key, value: overrides[key], source: 'file' };
|
|
69
|
+
}
|
|
70
|
+
const envVars = typeof entry.envVar === 'string' ? [entry.envVar] : entry.envVar;
|
|
71
|
+
for (const envVar of envVars) {
|
|
72
|
+
const raw = env[envVar];
|
|
73
|
+
if (raw === undefined || (TRUTHY_ENV_KEYS.has(key) && raw.length === 0))
|
|
74
|
+
continue;
|
|
75
|
+
if (warnOnEnv)
|
|
76
|
+
logEnvFallback(key, envVar);
|
|
77
|
+
return { key, value: entry.legacyParse(raw), source: 'env' };
|
|
78
|
+
}
|
|
79
|
+
return { key, value: entry.default, source: 'default' };
|
|
80
|
+
}
|
|
81
|
+
export function resolveSettingsSnapshot(overrides, env = process.env) {
|
|
82
|
+
validateSettingsOverrides(overrides);
|
|
83
|
+
return SETTING_KEYS.map((key) => resolveSettingEntry(key, overrides, env, false));
|
|
84
|
+
}
|
|
85
|
+
function resolveSettings(overrides) {
|
|
86
|
+
return Object.fromEntries(SETTING_KEYS.map((key) => {
|
|
87
|
+
const entry = resolveSettingEntry(key, overrides, process.env, true);
|
|
88
|
+
return [key, entry.value];
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
function sameValue(left, right) {
|
|
92
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
93
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
94
|
+
}
|
|
95
|
+
return Object.is(left, right);
|
|
96
|
+
}
|
|
97
|
+
function changedKeys(previous, next) {
|
|
98
|
+
return SETTING_KEYS.filter((key) => !sameValue(previous[key], next[key]));
|
|
99
|
+
}
|
|
100
|
+
function emitChanges(previous, next) {
|
|
101
|
+
const changed = changedKeys(previous, next);
|
|
102
|
+
if (changed.length === 0)
|
|
103
|
+
return;
|
|
104
|
+
for (const callback of callbacks) {
|
|
105
|
+
try {
|
|
106
|
+
callback(changed);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
log.error('Settings change callback failed:', error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function settingsFromSnapshot(snapshot) {
|
|
114
|
+
return Object.fromEntries(snapshot.map((entry) => [entry.key, entry.value]));
|
|
115
|
+
}
|
|
116
|
+
function snapshotWithValues(overrides, settings) {
|
|
117
|
+
return resolveSettingsSnapshot(overrides).map((entry) => ({
|
|
118
|
+
key: entry.key,
|
|
119
|
+
value: settings[entry.key],
|
|
120
|
+
source: entry.source,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
function acceptSnapshot(overrides, next, snapshot = snapshotWithValues(overrides, next)) {
|
|
124
|
+
const previous = cachedSettings;
|
|
125
|
+
cachedOverrides = overrides;
|
|
126
|
+
cachedSettings = next;
|
|
127
|
+
cachedSettingsSnapshot = snapshot;
|
|
128
|
+
if (previous)
|
|
129
|
+
emitChanges(previous, next);
|
|
130
|
+
}
|
|
131
|
+
function sameOverrides(left, right) {
|
|
132
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
133
|
+
}
|
|
134
|
+
function scheduleReload() {
|
|
135
|
+
if (reloadTimer)
|
|
136
|
+
clearTimeout(reloadTimer);
|
|
137
|
+
reloadTimer = setTimeout(() => {
|
|
138
|
+
reloadTimer = null;
|
|
139
|
+
reloadSettings();
|
|
140
|
+
}, 300);
|
|
141
|
+
}
|
|
142
|
+
function reloadSettings() {
|
|
143
|
+
if (selfWriting)
|
|
144
|
+
return scheduleReload();
|
|
145
|
+
try {
|
|
146
|
+
const overrides = readOverrides();
|
|
147
|
+
if (sameOverrides(cachedOverrides, overrides))
|
|
148
|
+
return;
|
|
149
|
+
acceptSnapshot(overrides, resolveSettings(overrides));
|
|
150
|
+
log.info('Hot-reload: settings.json reloaded');
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
log.error(`Hot-reload settings.json failed: ${error.message} — keeping previous settings`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function handleWatchEvent(filename) {
|
|
157
|
+
if (filename !== null && filename.toString() !== 'settings.json')
|
|
158
|
+
return;
|
|
159
|
+
scheduleReload();
|
|
160
|
+
}
|
|
161
|
+
function startWatcher() {
|
|
162
|
+
try {
|
|
163
|
+
settingsWatcher = watch(CONFIG_DIR, (_eventType, filename) => handleWatchEvent(filename));
|
|
164
|
+
settingsWatcher.on('error', (error) => log.error('settings.json watcher failed:', error));
|
|
165
|
+
settingsWatcher.unref();
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
log.error('Failed to watch settings.json:', error);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function initialize() {
|
|
172
|
+
if (initialized)
|
|
173
|
+
return;
|
|
174
|
+
initialized = true;
|
|
175
|
+
startWatcher();
|
|
176
|
+
try {
|
|
177
|
+
const overrides = readOverrides();
|
|
178
|
+
acceptSnapshot(overrides, resolveSettings(overrides));
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
log.error(`Load settings.json failed: ${error.message} — using env/default settings`);
|
|
182
|
+
acceptSnapshot({}, resolveSettings({}));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export function resetSettingsForTests() {
|
|
186
|
+
if (reloadTimer)
|
|
187
|
+
clearTimeout(reloadTimer);
|
|
188
|
+
reloadTimer = null;
|
|
189
|
+
settingsWatcher?.close();
|
|
190
|
+
settingsWatcher = null;
|
|
191
|
+
initialized = false;
|
|
192
|
+
cachedOverrides = {};
|
|
193
|
+
cachedSettings = null;
|
|
194
|
+
cachedSettingsSnapshot = null;
|
|
195
|
+
selfWriting = false;
|
|
196
|
+
}
|
|
197
|
+
export function getSettings() {
|
|
198
|
+
initialize();
|
|
199
|
+
return cachedSettings;
|
|
200
|
+
}
|
|
201
|
+
export function getSettingsSnapshot() {
|
|
202
|
+
initialize();
|
|
203
|
+
return cachedSettingsSnapshot;
|
|
204
|
+
}
|
|
205
|
+
export function onSettingsChange(callback) {
|
|
206
|
+
initialize();
|
|
207
|
+
callbacks.add(callback);
|
|
208
|
+
return () => callbacks.delete(callback);
|
|
209
|
+
}
|
|
210
|
+
function readOverridesForUpdate() {
|
|
211
|
+
try {
|
|
212
|
+
return readOverrides();
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
log.error(`Update settings.json read failed: ${error.message} — using previous settings`);
|
|
216
|
+
return cachedOverrides;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export async function updateSettings(partial) {
|
|
220
|
+
initialize();
|
|
221
|
+
const env = { ...process.env };
|
|
222
|
+
await writeMutex.run(async () => {
|
|
223
|
+
const nextOverrides = { ...readOverridesForUpdate(), ...partial };
|
|
224
|
+
const nextSnapshot = resolveSettingsSnapshot(nextOverrides, env);
|
|
225
|
+
const nextSettings = settingsFromSnapshot(nextSnapshot);
|
|
226
|
+
selfWriting = true;
|
|
227
|
+
try {
|
|
228
|
+
await atomicWrite(SETTINGS_FILE, `${JSON.stringify(nextOverrides, null, 2)}\n`);
|
|
229
|
+
acceptSnapshot(nextOverrides, nextSettings, nextSnapshot);
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
selfWriting = false;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
@@ -17,6 +17,8 @@ export interface Task {
|
|
|
17
17
|
blocked_by: string | null;
|
|
18
18
|
claimed_by: string | null;
|
|
19
19
|
claimed_at: string | null;
|
|
20
|
+
/** Opaque dispatch incarnation retained through valid automated completion for callback fencing. */
|
|
21
|
+
dispatch_generation: string | null;
|
|
20
22
|
paused: boolean;
|
|
21
23
|
approval_needed: boolean;
|
|
22
24
|
approved_at: string | null;
|
|
@@ -31,6 +33,9 @@ export interface Task {
|
|
|
31
33
|
origin_channel: string | null;
|
|
32
34
|
origin_thread_id: string | null;
|
|
33
35
|
}
|
|
36
|
+
export interface TaskGenerationExpectation {
|
|
37
|
+
generation: string | null;
|
|
38
|
+
}
|
|
34
39
|
export interface LockState {
|
|
35
40
|
owner: string;
|
|
36
41
|
acquired_at: string;
|
|
@@ -52,6 +57,11 @@ declare function serializeTasksFileWithLock({ tasks, lock }: {
|
|
|
52
57
|
lock?: LockState | null;
|
|
53
58
|
}): string;
|
|
54
59
|
declare function getTasksYamlPath(project: string): string;
|
|
60
|
+
/** Test seam: cumulative cache hit/miss counters for the scanAllTasks content cache. */
|
|
61
|
+
declare function _tasksFileCacheStats(): {
|
|
62
|
+
hits: number;
|
|
63
|
+
misses: number;
|
|
64
|
+
};
|
|
55
65
|
declare function scanAllTasks(project?: string | null): Task[];
|
|
56
66
|
declare function completedHashSet(tasks: Task[]): Set<string>;
|
|
57
67
|
declare function isActionable(task: Task, completedHashes?: Set<string> | null): boolean;
|
|
@@ -75,4 +85,4 @@ declare function depsPayload(task: Task, tasks: Task[]): {
|
|
|
75
85
|
dependents: string[];
|
|
76
86
|
depends_on: Task[];
|
|
77
87
|
};
|
|
78
|
-
export { PRIORITY_ORDER, VALID_STATUSES, completedHashSet, depsPayload, filterTasks, getTaskStats, getTaskStatsFromTasks, getTasksYamlPath, isActionable, parseTasksFile, parseTasksFileWithLock, printStatsText, printTaskListToString, rawToTask, scanAllTasks, scanAvailableTasks, serializeTasksFile, serializeTasksFileWithLock, showPayload, taskToYamlObj, taskStatuses, taskTags, };
|
|
88
|
+
export { PRIORITY_ORDER, VALID_STATUSES, completedHashSet, depsPayload, filterTasks, getTaskStats, getTaskStatsFromTasks, getTasksYamlPath, isActionable, parseTasksFile, parseTasksFileWithLock, printStatsText, printTaskListToString, rawToTask, scanAllTasks, scanAvailableTasks, _tasksFileCacheStats, serializeTasksFile, serializeTasksFileWithLock, showPayload, taskToYamlObj, taskStatuses, taskTags, };
|
package/dist/core/task-parser.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// input: fs/path/crypto, YAML task files, project paths
|
|
2
|
+
// output: Task parsing, serialization, filtering, and generation types
|
|
3
|
+
// pos: Canonical TASKS.yaml schema and query helpers
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
1
5
|
import * as fs from 'node:fs';
|
|
2
6
|
import * as path from 'node:path';
|
|
3
7
|
import { parse as yamlParse, stringify as yamlStringify } from 'yaml';
|
|
@@ -11,6 +15,7 @@ const YAML_TO_TS = {
|
|
|
11
15
|
'blocked-by': 'blocked_by',
|
|
12
16
|
'claimed-by': 'claimed_by',
|
|
13
17
|
'claimed-at': 'claimed_at',
|
|
18
|
+
'dispatch-generation': 'dispatch_generation',
|
|
14
19
|
'approval-needed': 'approval_needed',
|
|
15
20
|
'approved-at': 'approved_at',
|
|
16
21
|
'not-before': 'not_before',
|
|
@@ -43,6 +48,7 @@ const TASK_DEFAULTS = {
|
|
|
43
48
|
blocked_by: null,
|
|
44
49
|
claimed_by: null,
|
|
45
50
|
claimed_at: null,
|
|
51
|
+
dispatch_generation: null,
|
|
46
52
|
paused: false,
|
|
47
53
|
approval_needed: false,
|
|
48
54
|
approved_at: null,
|
|
@@ -77,6 +83,7 @@ function rawToTask(raw, project) {
|
|
|
77
83
|
blocked_by: mapped.blocked_by != null ? String(mapped.blocked_by) : null,
|
|
78
84
|
claimed_by: mapped.claimed_by != null ? String(mapped.claimed_by) : null,
|
|
79
85
|
claimed_at: mapped.claimed_at != null ? String(mapped.claimed_at) : null,
|
|
86
|
+
dispatch_generation: mapped.dispatch_generation != null ? String(mapped.dispatch_generation) : null,
|
|
80
87
|
paused: Boolean(mapped.paused),
|
|
81
88
|
approval_needed: Boolean(mapped.approval_needed),
|
|
82
89
|
approved_at: mapped.approved_at != null ? String(mapped.approved_at) : null,
|
|
@@ -134,7 +141,8 @@ function parseTasksFileWithLock(content, project) {
|
|
|
134
141
|
const REQUIRED_KEYS = ['id', 'text', 'why', 'done_when', 'priority', 'status', 'template', 'plan'];
|
|
135
142
|
const OPTIONAL_KEY_ORDER = [
|
|
136
143
|
'parent', 'depends_on', 'gpu', 'gpu_count', 'blocked_by', 'claimed_by', 'claimed_at',
|
|
137
|
-
'paused', 'approval_needed', 'approved_at', 'not_before', 'pending_at',
|
|
144
|
+
'dispatch_generation', 'paused', 'approval_needed', 'approved_at', 'not_before', 'pending_at',
|
|
145
|
+
'completed_at', 'completed_note',
|
|
138
146
|
'origin_session_id', 'origin_channel', 'origin_thread_id',
|
|
139
147
|
];
|
|
140
148
|
function isDefault(key, value) {
|
|
@@ -177,6 +185,29 @@ function serializeTasksFileWithLock({ tasks, lock }) {
|
|
|
177
185
|
function getTasksYamlPath(project) {
|
|
178
186
|
return path.join(PROJECTS_DIR, project, 'TASKS.yaml');
|
|
179
187
|
}
|
|
188
|
+
/** Content-keyed parse cache. YAML parsing dominates scan cost (seconds across projects on the
|
|
189
|
+
* dispatch hot path); the raw read is cheap. Keyed by exact file content, so edits from ANY
|
|
190
|
+
* process (CLI, git pull, other threads) invalidate naturally — no mtime-granularity races.
|
|
191
|
+
* Results are structuredClone'd on the way out so callers can never mutate the cached copy. */
|
|
192
|
+
const tasksFileCache = new Map();
|
|
193
|
+
let tasksCacheHits = 0;
|
|
194
|
+
let tasksCacheMisses = 0;
|
|
195
|
+
function parseTasksFileCached(tasksPath, project) {
|
|
196
|
+
const content = fs.readFileSync(tasksPath, 'utf8');
|
|
197
|
+
const hit = tasksFileCache.get(tasksPath);
|
|
198
|
+
if (hit && hit.content === content) {
|
|
199
|
+
tasksCacheHits++;
|
|
200
|
+
return structuredClone(hit.tasks);
|
|
201
|
+
}
|
|
202
|
+
tasksCacheMisses++;
|
|
203
|
+
const tasks = parseTasksFile(content, project);
|
|
204
|
+
tasksFileCache.set(tasksPath, { content, tasks });
|
|
205
|
+
return structuredClone(tasks);
|
|
206
|
+
}
|
|
207
|
+
/** Test seam: cumulative cache hit/miss counters for the scanAllTasks content cache. */
|
|
208
|
+
function _tasksFileCacheStats() {
|
|
209
|
+
return { hits: tasksCacheHits, misses: tasksCacheMisses };
|
|
210
|
+
}
|
|
180
211
|
function scanAllTasks(project = null) {
|
|
181
212
|
if (!fs.existsSync(PROJECTS_DIR))
|
|
182
213
|
return [];
|
|
@@ -187,7 +218,7 @@ function scanAllTasks(project = null) {
|
|
|
187
218
|
const tasksPath = getTasksYamlPath(projectName);
|
|
188
219
|
if (!fs.existsSync(tasksPath))
|
|
189
220
|
continue;
|
|
190
|
-
tasks.push(...
|
|
221
|
+
tasks.push(...parseTasksFileCached(tasksPath, projectName));
|
|
191
222
|
}
|
|
192
223
|
return tasks;
|
|
193
224
|
}
|
|
@@ -439,4 +470,4 @@ function depsPayload(task, tasks) {
|
|
|
439
470
|
payload.dependents = depMap[task.id] || [];
|
|
440
471
|
return payload;
|
|
441
472
|
}
|
|
442
|
-
export { PRIORITY_ORDER, VALID_STATUSES, completedHashSet, depsPayload, filterTasks, getTaskStats, getTaskStatsFromTasks, getTasksYamlPath, isActionable, parseTasksFile, parseTasksFileWithLock, printStatsText, printTaskListToString, rawToTask, scanAllTasks, scanAvailableTasks, serializeTasksFile, serializeTasksFileWithLock, showPayload, taskToYamlObj, taskStatuses, taskTags, };
|
|
473
|
+
export { PRIORITY_ORDER, VALID_STATUSES, completedHashSet, depsPayload, filterTasks, getTaskStats, getTaskStatsFromTasks, getTasksYamlPath, isActionable, parseTasksFile, parseTasksFileWithLock, printStatsText, printTaskListToString, rawToTask, scanAllTasks, scanAvailableTasks, _tasksFileCacheStats, serializeTasksFile, serializeTasksFileWithLock, showPayload, taskToYamlObj, taskStatuses, taskTags, };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export type ChatNoticeLevel = 'info' | 'warning' | 'error';
|
|
2
|
+
export interface AuthNoticeAction {
|
|
3
|
+
kind: 'auth-login';
|
|
4
|
+
noticeId: string;
|
|
5
|
+
backend: 'claude' | 'pi';
|
|
6
|
+
provider: string;
|
|
7
|
+
authType: 'oauth' | 'api_key';
|
|
8
|
+
}
|
|
2
9
|
/** Backend-neutral snapshot of the tokens currently occupying an agent's context window. */
|
|
3
10
|
export interface ContextUsage {
|
|
4
11
|
usedTokens: number | null;
|
|
@@ -15,9 +22,21 @@ export interface AskUserQuestionInfo {
|
|
|
15
22
|
questions: string[];
|
|
16
23
|
sessionId: string;
|
|
17
24
|
}
|
|
25
|
+
export interface ReportedAccountingSnapshot {
|
|
26
|
+
readonly usageReported: boolean;
|
|
27
|
+
readonly inputTokens: number | null;
|
|
28
|
+
readonly outputTokens: number | null;
|
|
29
|
+
readonly promptTokens: number | null;
|
|
30
|
+
readonly cachedTokens: number | null;
|
|
31
|
+
readonly model: string | null;
|
|
32
|
+
}
|
|
18
33
|
export interface AgentResult {
|
|
19
34
|
sessionId: string | null;
|
|
20
35
|
total_cost_usd: number | null;
|
|
36
|
+
/** Present only when a provenance-sensitive caller needs reported zero distinguished from absent cost. */
|
|
37
|
+
costReported?: boolean;
|
|
38
|
+
/** Immutable result-event accounting used by provenance-sensitive event serialization. */
|
|
39
|
+
reportedAccounting?: ReportedAccountingSnapshot;
|
|
21
40
|
num_turns: number | null;
|
|
22
41
|
rateLimited: boolean;
|
|
23
42
|
rateLimitMessage: string | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// input: nothing (leaf type-only module)
|
|
2
|
-
// output: Agent results
|
|
2
|
+
// output: Agent results, auth actions, and exact usage types
|
|
3
3
|
// pos: Shared type definitions for agent execution and messages
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { NormalizedEvent } from '../../agent-adapter/normalize/event-types.js';
|
|
2
|
+
import type { AgentProcessSpawner, McpComposition } from '../../agent-adapter/types.js';
|
|
1
3
|
export type ThreadId = string;
|
|
2
4
|
export type AgentSlotId = string;
|
|
3
5
|
export type ThreadStatus = 'running' | 'waiting' | 'rate_limited' | 'completed' | 'failed' | 'cancelled' | 'aborted';
|
|
@@ -24,6 +26,7 @@ export interface AgentDefinition {
|
|
|
24
26
|
outputStyle?: string;
|
|
25
27
|
tools?: string;
|
|
26
28
|
pluginDirs?: string[];
|
|
29
|
+
mcpComposition?: McpComposition;
|
|
27
30
|
/** Optional per-stage prompt map. When set, `promptTemplate` is ignored and the engine
|
|
28
31
|
* selects one stage per step based on the transition target (`"agent:stage"` syntax). */
|
|
29
32
|
stages?: Record<string, StageDefinition>;
|
|
@@ -55,6 +58,7 @@ export interface AgentSlotConfig {
|
|
|
55
58
|
outputStyle?: string;
|
|
56
59
|
tools?: string;
|
|
57
60
|
pluginDirs?: string[];
|
|
61
|
+
mcpComposition?: McpComposition;
|
|
58
62
|
/** Per-stage prompts (merged from AgentDefinition; templates currently don't override per stage). */
|
|
59
63
|
stages?: Record<string, StageDefinition>;
|
|
60
64
|
/** Default stage when a transition target omits the `:stage` suffix. */
|
|
@@ -142,6 +146,8 @@ export interface ThreadTemplate {
|
|
|
142
146
|
entryStage?: string;
|
|
143
147
|
maxTotalSteps: number;
|
|
144
148
|
maxTotalCostUsd?: number;
|
|
149
|
+
/** Suppress registry, scoped lifecycle, and backend hooks for isolated templates. */
|
|
150
|
+
disableHooks?: boolean;
|
|
145
151
|
hooks?: ThreadHooks;
|
|
146
152
|
}
|
|
147
153
|
/** A compact template that inherits a named "shell" (a parameterized transition-graph
|
|
@@ -228,6 +234,11 @@ export interface AgentSlot {
|
|
|
228
234
|
status: 'idle' | 'running' | 'completed';
|
|
229
235
|
lastOutput: string | null;
|
|
230
236
|
persistSession: boolean;
|
|
237
|
+
/** Backend session of a step interrupted mid-flight by a provider error/rate limit, set only
|
|
238
|
+
* when the attempt streamed real activity. One-shot: the rerun consumes it (beginStepSession)
|
|
239
|
+
* to resume the interrupted session with a continuation reminder instead of restarting the
|
|
240
|
+
* step from the original prompt. */
|
|
241
|
+
interruptedBackendSessionId?: string | null;
|
|
231
242
|
}
|
|
232
243
|
export interface ThreadRecord {
|
|
233
244
|
id: ThreadId;
|
|
@@ -266,6 +277,11 @@ export interface ThreadContract {
|
|
|
266
277
|
deliverablePath?: string | null;
|
|
267
278
|
budgetUsd?: number | null;
|
|
268
279
|
}
|
|
280
|
+
/** User input reserved while a thread step prepares any attached platform files. */
|
|
281
|
+
export interface BufferedThreadUserInput {
|
|
282
|
+
id: string;
|
|
283
|
+
text: string;
|
|
284
|
+
}
|
|
269
285
|
/** Caller-provided metadata stored on ThreadRecord, used by thread-runner for execution registry etc. */
|
|
270
286
|
export interface ThreadMetadata {
|
|
271
287
|
scheduleTaskId?: string | null;
|
|
@@ -284,8 +300,10 @@ export interface ThreadMetadata {
|
|
|
284
300
|
* parent (interactive parent → resume its channel session) or address a notice to it. */
|
|
285
301
|
parentChannel?: string | null;
|
|
286
302
|
parentProfile?: string | null;
|
|
287
|
-
/**
|
|
303
|
+
/** Control/callback notices buffered for the next step. */
|
|
288
304
|
pendingMessages?: string[];
|
|
305
|
+
/** Ordered user inputs buffered while their platform files are prepared. */
|
|
306
|
+
pendingUserInputs?: BufferedThreadUserInput[];
|
|
289
307
|
/** Root of the thread tree this thread belongs to. Unset on root threads —
|
|
290
308
|
* use tree.getRootThreadId() which falls back to the thread's own id. */
|
|
291
309
|
rootThreadId?: string | null;
|
|
@@ -334,11 +352,11 @@ export interface ThreadMetadata {
|
|
|
334
352
|
/** Task association persisted for lifecycle payloads and resumed dispatch work. */
|
|
335
353
|
taskId?: string | null;
|
|
336
354
|
taskProject?: string | null;
|
|
355
|
+
/** Opaque TASKS.yaml dispatch incarnation used to fence completion and terminal callbacks. */
|
|
356
|
+
dispatchGeneration?: string | null;
|
|
337
357
|
/** Task text (TASKS.yaml `text`) at dispatch time, for the thread step status line so a glance
|
|
338
358
|
* shows what is running. Persisted because status updates outlive the in-memory selected task. */
|
|
339
359
|
taskText?: string | null;
|
|
340
|
-
/** Followup created when a failed dispatch left completed-task review unresolved. */
|
|
341
|
-
reviewLeakFollowupTaskId?: string | null;
|
|
342
360
|
/** Set when the thread was paused (status==='rate_limited') by an API rate limit, so the
|
|
343
361
|
* resume path and startup recovery can tell a rate-limit pause apart from a real failure. */
|
|
344
362
|
interruptedByRateLimit?: boolean;
|
|
@@ -380,6 +398,31 @@ export interface TransitionResult {
|
|
|
380
398
|
reason: 'transition' | 'converged' | 'max_iterations' | 'cost_limit' | 'no_matching_transition';
|
|
381
399
|
}
|
|
382
400
|
import type { PlatformAdapter, MessageRef, Destination } from '../../platform/index.js';
|
|
401
|
+
export interface BenchmarkThreadEvent {
|
|
402
|
+
step: number;
|
|
403
|
+
agentSlotId: AgentSlotId;
|
|
404
|
+
event: NormalizedEvent;
|
|
405
|
+
}
|
|
406
|
+
export interface BenchmarkThreadRunOptions {
|
|
407
|
+
/** Absolute grader workspace used by every benchmark step's backend process. */
|
|
408
|
+
workspaceCwd: string;
|
|
409
|
+
/** Frozen trial profile; benchmark templates cannot select a different identity. */
|
|
410
|
+
resolvedProfileName: string;
|
|
411
|
+
expectedBackend: 'claude';
|
|
412
|
+
expectedModel: string;
|
|
413
|
+
disableHooks: true;
|
|
414
|
+
disableControlPlane: true;
|
|
415
|
+
failFastOnRateLimit: true;
|
|
416
|
+
/** Optional containment-aware process boundary forwarded to every step. */
|
|
417
|
+
spawner?: AgentProcessSpawner;
|
|
418
|
+
/** Required trajectory sink invoked synchronously for every normalized event. */
|
|
419
|
+
requiredEventSink?: (input: BenchmarkThreadEvent) => void;
|
|
420
|
+
limits?: {
|
|
421
|
+
maxSteps: number;
|
|
422
|
+
maxCostUsd?: number;
|
|
423
|
+
deadlineMs?: number;
|
|
424
|
+
};
|
|
425
|
+
}
|
|
383
426
|
export interface RunThreadOptions {
|
|
384
427
|
adapter: PlatformAdapter;
|
|
385
428
|
channel: string;
|
|
@@ -421,4 +464,6 @@ export interface RunThreadOptions {
|
|
|
421
464
|
onTransition?: ThreadHookConfig;
|
|
422
465
|
onEnd?: ThreadHookConfig;
|
|
423
466
|
};
|
|
467
|
+
/** Presence selects the isolated benchmark runtime; absence preserves daemon behavior. */
|
|
468
|
+
benchmark?: BenchmarkThreadRunOptions;
|
|
424
469
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// input: thread
|
|
2
|
-
// output: thread state,
|
|
1
|
+
// input: thread config, benchmark events, process spawning
|
|
2
|
+
// output: thread state, buffered-input, runtime lifecycle types
|
|
3
3
|
// pos: Shared type definitions for the thread system
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
export {};
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -26,6 +26,26 @@ declare function todayISO(): string;
|
|
|
26
26
|
* `cortex-task lock-status`, `stats`, id-assignment, etc.).
|
|
27
27
|
*/
|
|
28
28
|
declare function listProjectDirs(projectsDir?: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the npm global prefix that an installed CLI actually lives under.
|
|
31
|
+
*
|
|
32
|
+
* `npm install/update -g` targets npm's *configured* prefix. When Cortex was installed
|
|
33
|
+
* with an explicit `--prefix ~/.npm-global` but no `prefix=` line was written to .npmrc,
|
|
34
|
+
* npm falls back to the system prefix (/usr/lib/node_modules), which is root-owned:
|
|
35
|
+
* self-update then dies with EACCES, and version probes report the package as missing.
|
|
36
|
+
*
|
|
37
|
+
* The installed binary is the ground truth — npm places it at `<prefix>/bin/<binName>`
|
|
38
|
+
* next to `<prefix>/lib/node_modules`. Walk PATH, find the binary, derive the prefix.
|
|
39
|
+
* `CORTEX_NPM_PREFIX` overrides. Returns null when nothing matches, so callers fall
|
|
40
|
+
* back to a plain `-g` (npm's own resolution).
|
|
41
|
+
*/
|
|
42
|
+
declare function resolveNpmGlobalPrefix(binName: string, opts?: {
|
|
43
|
+
pathEnv?: string;
|
|
44
|
+
override?: string;
|
|
45
|
+
exists?: (p: string) => boolean;
|
|
46
|
+
}): string | null;
|
|
47
|
+
/** Append `--prefix <resolved>` to an npm argv when a prefix could be resolved. */
|
|
48
|
+
declare function withNpmPrefix(args: string[], binName: string): string[];
|
|
29
49
|
/**
|
|
30
50
|
* Sentinel ANTHROPIC_API_KEY value set when the gateway is healthy but no real key exists.
|
|
31
51
|
* Its only purpose is to satisfy Claude Code's startup credential check on machines without
|
|
@@ -34,4 +54,4 @@ declare function listProjectDirs(projectsDir?: string): string[];
|
|
|
34
54
|
* snapshots) must ignore this value.
|
|
35
55
|
*/
|
|
36
56
|
declare const GATEWAY_MANAGED_KEY_PLACEHOLDER = "cortex-gateway-managed";
|
|
37
|
-
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
|
|
57
|
+
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs, resolveNpmGlobalPrefix, withNpmPrefix };
|
package/dist/core/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// input: nothing (leaf module)
|
|
2
2
|
// output: INSTALL_ROOT / DEFAULTS_DIR / DATA_DIR / CONFIG_DIR / STORE_DIR / CONTEXT_DIR / PROJECTS_DIR / WORKSPACE_DIR / resolveWorkspaceRelPath / PLUGINS_DIR / PROMPTS_DIR / HOOKS_DIR
|
|
3
3
|
// (deprecated re-exports: PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT) + moduleDir + utility helpers
|
|
4
|
+
// + resolveNpmGlobalPrefix / withNpmPrefix (npm global prefix for self-update)
|
|
4
5
|
// pos: cross-module shared constants and ESM/time/path utilities
|
|
5
6
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
7
|
import * as fs from 'fs';
|
|
@@ -95,6 +96,41 @@ function listProjectDirs(projectsDir = PROJECTS_DIR) {
|
|
|
95
96
|
return [];
|
|
96
97
|
}
|
|
97
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolve the npm global prefix that an installed CLI actually lives under.
|
|
101
|
+
*
|
|
102
|
+
* `npm install/update -g` targets npm's *configured* prefix. When Cortex was installed
|
|
103
|
+
* with an explicit `--prefix ~/.npm-global` but no `prefix=` line was written to .npmrc,
|
|
104
|
+
* npm falls back to the system prefix (/usr/lib/node_modules), which is root-owned:
|
|
105
|
+
* self-update then dies with EACCES, and version probes report the package as missing.
|
|
106
|
+
*
|
|
107
|
+
* The installed binary is the ground truth — npm places it at `<prefix>/bin/<binName>`
|
|
108
|
+
* next to `<prefix>/lib/node_modules`. Walk PATH, find the binary, derive the prefix.
|
|
109
|
+
* `CORTEX_NPM_PREFIX` overrides. Returns null when nothing matches, so callers fall
|
|
110
|
+
* back to a plain `-g` (npm's own resolution).
|
|
111
|
+
*/
|
|
112
|
+
function resolveNpmGlobalPrefix(binName, opts = {}) {
|
|
113
|
+
const override = (opts.override ?? process.env.CORTEX_NPM_PREFIX)?.trim();
|
|
114
|
+
if (override)
|
|
115
|
+
return override;
|
|
116
|
+
const exists = opts.exists ?? fs.existsSync;
|
|
117
|
+
const pathEnv = opts.pathEnv ?? process.env.PATH ?? '';
|
|
118
|
+
for (const dir of pathEnv.split(path.delimiter)) {
|
|
119
|
+
if (!dir)
|
|
120
|
+
continue;
|
|
121
|
+
if (!exists(path.join(dir, binName)))
|
|
122
|
+
continue;
|
|
123
|
+
const prefix = path.dirname(dir); // <prefix>/bin/<binName> → <prefix>
|
|
124
|
+
if (exists(path.join(prefix, 'lib', 'node_modules')))
|
|
125
|
+
return prefix;
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
/** Append `--prefix <resolved>` to an npm argv when a prefix could be resolved. */
|
|
130
|
+
function withNpmPrefix(args, binName) {
|
|
131
|
+
const prefix = resolveNpmGlobalPrefix(binName);
|
|
132
|
+
return prefix ? [...args, '--prefix', prefix] : args;
|
|
133
|
+
}
|
|
98
134
|
/**
|
|
99
135
|
* Sentinel ANTHROPIC_API_KEY value set when the gateway is healthy but no real key exists.
|
|
100
136
|
* Its only purpose is to satisfy Claude Code's startup credential check on machines without
|
|
@@ -103,4 +139,4 @@ function listProjectDirs(projectsDir = PROJECTS_DIR) {
|
|
|
103
139
|
* snapshots) must ignore this value.
|
|
104
140
|
*/
|
|
105
141
|
const GATEWAY_MANAGED_KEY_PLACEHOLDER = 'cortex-gateway-managed';
|
|
106
|
-
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
|
|
142
|
+
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, resolveWorkspaceRelPath, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, GATEWAY_MANAGED_KEY_PLACEHOLDER, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs, resolveNpmGlobalPrefix, withNpmPrefix };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface ProbeCliIo {
|
|
2
|
+
stdout: NodeJS.WritableStream;
|
|
3
|
+
stderr: NodeJS.WritableStream;
|
|
4
|
+
}
|
|
5
|
+
export declare function runAccessProbeCli(args: string[], io?: ProbeCliIo, env?: NodeJS.ProcessEnv): Promise<number>;
|
|
6
|
+
export declare function getAccessProbeHelp(): string;
|
|
7
|
+
export {};
|