@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
|
@@ -5,13 +5,21 @@ paths:
|
|
|
5
5
|
|
|
6
6
|
# STATUS.md Convention
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
The project's **present tense**: the minimal state a fresh session needs to continue working correctly. A register, not a journal.
|
|
9
|
+
It answers exactly four questions: where are we, what is in flight, what is in the way, what comes next.
|
|
10
|
+
|
|
11
|
+
## Three Admission Tests (apply before every write)
|
|
12
|
+
|
|
13
|
+
1. **Deletion test**: would removing this line cause a future session to decide wrongly or waste time? If not → do not write it.
|
|
14
|
+
2. **Grows with state, not with time**: file size may only track state complexity, never project age. Entries that only get added and never removed = the file has degraded into a journal.
|
|
15
|
+
3. **60-second handoff**: the whole file = what you could tell a new collaborator in 60 seconds. Anything beyond that belongs in its durable home.
|
|
9
16
|
|
|
10
17
|
## Hard Constraints
|
|
11
18
|
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
19
|
+
- **Update mode: overwrite-rewrite the snapshot**. Every "add a line" must be paired with a check for which existing lines it makes stale — delete those.
|
|
20
|
+
- **Length limit: 80 lines AND 6KB, both hard**. Scan before writing: at >=60 lines or >=4KB, warn and trim proactively; over the limit, trim below it before the write is allowed.
|
|
21
|
+
- **Each bullet <= 2 lines**. If it doesn't fit, the detail belongs elsewhere — keep one sentence + a pointer.
|
|
22
|
+
- **Facts with a durable home appear only as pointers**: task-id / EXP-NNN / K-NNN / DR-NNNN / commit SHA / file path. The only content unique to STATUS is the one-sentence synthesis of the current situation.
|
|
15
23
|
|
|
16
24
|
## Required Sections (in order)
|
|
17
25
|
|
|
@@ -20,30 +28,40 @@ Snapshot of the project's current state. **Overwrite mode** — only keep the la
|
|
|
20
28
|
|
|
21
29
|
Updated: YYYY-MM-DD
|
|
22
30
|
|
|
23
|
-
## Current
|
|
24
|
-
<One paragraph
|
|
31
|
+
## Current Situation
|
|
32
|
+
<One paragraph: position on the roadmap + core focus + one-sentence situation call>
|
|
25
33
|
|
|
26
|
-
##
|
|
27
|
-
|
|
34
|
+
## In Flight & New Variables
|
|
35
|
+
<<=5 items, each <=2 lines + pointer. Only events that changed the situation:
|
|
36
|
+
what got unblocked, what new constraint appeared, why the next step changed.
|
|
37
|
+
Delete an item the moment it stops affecting decisions — its content already
|
|
38
|
+
lives in tasks-archive/git/EXP, nothing to migrate. Write "none" if empty.>
|
|
28
39
|
|
|
29
|
-
##
|
|
30
|
-
<
|
|
40
|
+
## Blockers & Pending Decisions
|
|
41
|
+
<External blockers, decisions awaiting the user, traps a fresh session would hit. Write "none" if empty.>
|
|
31
42
|
|
|
32
|
-
## Next
|
|
33
|
-
<
|
|
43
|
+
## Next Step
|
|
44
|
+
<The concrete next action, pointing to a TASKS.yaml task-id or a plan file>
|
|
34
45
|
```
|
|
35
46
|
|
|
47
|
+
## Update Triggers
|
|
48
|
+
|
|
49
|
+
Update on state change, not on task completion: phase advance/pause/pivot, a blocker appearing or clearing, the next step changing, in-flight work landing in a way that affects decisions, session end (per the working-record discipline).
|
|
50
|
+
|
|
51
|
+
"A task finished" is not by itself a reason to write. Write only when the completion **changed the situation** (unblocked something / introduced a blocker / changed the next step), and write only the one-line situation change.
|
|
52
|
+
|
|
36
53
|
## Prohibited Content
|
|
37
54
|
|
|
38
|
-
-
|
|
39
|
-
- Experiment data
|
|
40
|
-
- Settled knowledge/methodology →
|
|
41
|
-
- Design decision trade-offs →
|
|
42
|
-
-
|
|
55
|
+
- Task completion reports (test counts, verification steps, commit lists) → TASKS.yaml completion note / tasks-archive / task artifact
|
|
56
|
+
- Experiment data and conclusions → experiments/EXP-NNN.md
|
|
57
|
+
- Settled knowledge / methodology → knowledge/K-NNN.md
|
|
58
|
+
- Design decision trade-offs → decisions/DR-NNNN.md
|
|
59
|
+
- Change history → git log is the changelog; no file may duplicate it
|
|
60
|
+
- Superseded old phase descriptions → delete directly (their outputs should already be settled into EXP/K/PAT)
|
|
43
61
|
|
|
44
62
|
## Overflow Handling
|
|
45
63
|
|
|
46
|
-
|
|
47
|
-
1.
|
|
48
|
-
2.
|
|
49
|
-
3. Still
|
|
64
|
+
When over the limit, trim in this order:
|
|
65
|
+
1. Delete "In Flight & New Variables" items that no longer affect decisions
|
|
66
|
+
2. Compress any bullet over 2 lines into one sentence + pointer
|
|
67
|
+
3. Still over → the state itself is too complex: consider splitting a sub-project or driving the roadmap to converge, and record that call under "Blockers & Pending Decisions"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentResult, ContextUsage } from '../core/types/agent-types.js';
|
|
2
2
|
import type { ContinuationSink } from './types.js';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import type { NormalizedEvent } from './normalize/event-types.js';
|
|
4
|
+
/** Background-task continuation feature gate. */
|
|
5
5
|
export declare function isBgContinuationEnabled(): boolean;
|
|
6
6
|
/** Grace period for work-done-but-unnotified tasks (CORTEX_BG_GRACE_S, default 90s). */
|
|
7
7
|
export declare function getBgGraceMs(): number;
|
|
@@ -12,9 +12,9 @@ export declare function remainingBg(result: {
|
|
|
12
12
|
pendingBackgroundTasks?: number;
|
|
13
13
|
undeliveredBackgroundTasks?: number;
|
|
14
14
|
} | null | undefined): number;
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** Backend and result prerequisites shared by explicit and legacy inline waiting. */
|
|
16
|
+
export declare function canAwaitBgContinuation(backend: string, result: AgentResult | null | undefined, canRegisterSink: boolean): boolean;
|
|
17
|
+
/** Legacy inline policy: settings-enabled thread turns wait; interactive turns do not. */
|
|
18
18
|
export declare function shouldAwaitBgInline(backend: string, threadId: string | null | undefined, result: AgentResult | null | undefined, canRegisterSink: boolean): boolean;
|
|
19
19
|
export interface WaitForBgOpts {
|
|
20
20
|
proc: {
|
|
@@ -26,19 +26,17 @@ export interface WaitForBgOpts {
|
|
|
26
26
|
onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
|
|
27
27
|
onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
|
|
28
28
|
onContextUsage?: ((usage: ContextUsage) => void | Promise<void>) | null;
|
|
29
|
+
onEvent?: ((event: NormalizedEvent) => void) | null;
|
|
29
30
|
graceMs?: number;
|
|
30
31
|
maxWaitMs?: number;
|
|
32
|
+
/** Wait without ambient release timers until continuation completion or supervised stop. */
|
|
33
|
+
completionOnly?: boolean;
|
|
34
|
+
/** Process termination boundary required by completion-only waits. */
|
|
35
|
+
stopPromise?: Promise<unknown>;
|
|
31
36
|
/** Injectable timers for tests. Production timers are unref'd. */
|
|
32
37
|
timers?: {
|
|
33
38
|
set: (fn: () => void, ms: number) => unknown;
|
|
34
39
|
clear: (h: unknown) => void;
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Wait inline for the spontaneous background-task continuation of a turn that ended with
|
|
39
|
-
* work remaining. Registers a ContinuationSink on the process and resolves with the merged
|
|
40
|
-
* result when the continuation completes (chained continuations keep waiting). Never
|
|
41
|
-
* rejects; bounded by the grace watchdog (undelivered-only) or the max-wait cap (running):
|
|
42
|
-
* on timeout it resolves with what has accumulated so far.
|
|
43
|
-
*/
|
|
44
42
|
export declare function waitForBgContinuation(opts: WaitForBgOpts): Promise<AgentResult>;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
// input: continuation
|
|
2
|
-
// output:
|
|
3
|
-
// pos:
|
|
4
|
-
// >>>
|
|
1
|
+
// input: continuation results, exact accounting, wait policy
|
|
2
|
+
// output: cache-inclusive continuation events and bounded results
|
|
3
|
+
// pos: Background continuation wait policy
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
5
|
//
|
|
6
6
|
// Interactive turns hold their Slack status asynchronously (orchestration/lifecycle +
|
|
7
7
|
// bg-wait-guard). Thread/dispatch turns have no status message to hold — the step's
|
|
8
8
|
// RESULT is the deliverable — so they wait INLINE: the facade keeps the turn promise
|
|
9
9
|
// open until the spontaneous continuation completes, then resolves with the merged
|
|
10
|
-
// result. The thread's own busy bracket covers the wait (no extra track here)
|
|
11
|
-
//
|
|
12
|
-
// cannot
|
|
10
|
+
// result. The thread's own busy bracket covers the wait (no extra track here). Ordinary
|
|
11
|
+
// callers use grace/cap bounds; supervised one-shot runs use completion-only mode and their
|
|
12
|
+
// process-stop boundary so ambient caps cannot publish success while work remains.
|
|
13
13
|
import { createLogger } from '../core/log.js';
|
|
14
|
+
import { getSettings } from '../core/settings.js';
|
|
14
15
|
const log = createLogger('bg-wait');
|
|
15
|
-
/**
|
|
16
|
-
* CORTEX_BG_CONTINUATION to a falsy value (0 / false / off / no). */
|
|
16
|
+
/** Background-task continuation feature gate. */
|
|
17
17
|
export function isBgContinuationEnabled() {
|
|
18
|
-
|
|
19
|
-
if (v === undefined)
|
|
20
|
-
return true;
|
|
21
|
-
return !['0', 'false', 'off', 'no'].includes(v.trim().toLowerCase());
|
|
18
|
+
return getSettings().bgContinuation;
|
|
22
19
|
}
|
|
23
20
|
const DEFAULT_GRACE_MS = 90_000;
|
|
24
21
|
const DEFAULT_MAX_WAIT_MS = 1_800_000;
|
|
@@ -43,22 +40,20 @@ export function remainingBg(result) {
|
|
|
43
40
|
return 0;
|
|
44
41
|
return (result.pendingBackgroundTasks ?? 0) + (result.undeliveredBackgroundTasks ?? 0);
|
|
45
42
|
}
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export function shouldAwaitBgInline(backend, threadId, result, canRegisterSink) {
|
|
50
|
-
if (!isBgContinuationEnabled())
|
|
51
|
-
return false;
|
|
52
|
-
if (backend !== 'claude')
|
|
53
|
-
return false;
|
|
54
|
-
if (!threadId)
|
|
55
|
-
return false;
|
|
56
|
-
if (!canRegisterSink)
|
|
43
|
+
/** Backend and result prerequisites shared by explicit and legacy inline waiting. */
|
|
44
|
+
export function canAwaitBgContinuation(backend, result, canRegisterSink) {
|
|
45
|
+
if (backend !== 'claude' || !canRegisterSink)
|
|
57
46
|
return false;
|
|
58
47
|
if (!result || result.rateLimited)
|
|
59
48
|
return false;
|
|
60
49
|
return remainingBg(result) > 0;
|
|
61
50
|
}
|
|
51
|
+
/** Legacy inline policy: settings-enabled thread turns wait; interactive turns do not. */
|
|
52
|
+
export function shouldAwaitBgInline(backend, threadId, result, canRegisterSink) {
|
|
53
|
+
if (!isBgContinuationEnabled() || !threadId)
|
|
54
|
+
return false;
|
|
55
|
+
return canAwaitBgContinuation(backend, result, canRegisterSink);
|
|
56
|
+
}
|
|
62
57
|
const realTimers = {
|
|
63
58
|
set: (fn, ms) => {
|
|
64
59
|
const h = setTimeout(fn, ms);
|
|
@@ -72,8 +67,12 @@ const realTimers = {
|
|
|
72
67
|
function mergeContinuation(acc, cont) {
|
|
73
68
|
const bothCostNull = acc.total_cost_usd == null && cont.total_cost_usd == null;
|
|
74
69
|
const bothTurnsNull = acc.num_turns == null && cont.num_turns == null;
|
|
70
|
+
const costReported = acc.costReported === undefined && cont.costReported === undefined
|
|
71
|
+
? undefined
|
|
72
|
+
: acc.costReported === true || cont.costReported === true;
|
|
75
73
|
return {
|
|
76
74
|
...acc,
|
|
75
|
+
costReported,
|
|
77
76
|
total_cost_usd: bothCostNull ? null : (acc.total_cost_usd ?? 0) + (cont.total_cost_usd ?? 0),
|
|
78
77
|
num_turns: bothTurnsNull ? null : (acc.num_turns ?? 0) + (cont.num_turns ?? 0),
|
|
79
78
|
finalOutput: cont.finalOutput || acc.finalOutput,
|
|
@@ -83,115 +82,196 @@ function mergeContinuation(acc, cont) {
|
|
|
83
82
|
undeliveredBackgroundTasks: cont.undeliveredBackgroundTasks ?? 0,
|
|
84
83
|
};
|
|
85
84
|
}
|
|
85
|
+
function continuationCostRecord(result) {
|
|
86
|
+
const accounting = result.reportedAccounting;
|
|
87
|
+
if (result.costReported !== true && accounting?.usageReported !== true)
|
|
88
|
+
return null;
|
|
89
|
+
return {
|
|
90
|
+
type: 'cost_record', provider: 'anthropic', model: accounting?.model ?? 'unknown',
|
|
91
|
+
tokens_in: accounting?.promptTokens ?? null,
|
|
92
|
+
tokens_out: accounting?.outputTokens ?? null,
|
|
93
|
+
prompt_tokens: accounting?.promptTokens ?? null,
|
|
94
|
+
cached_tokens: accounting?.cachedTokens ?? null,
|
|
95
|
+
cost_usd: result.costReported === true ? result.total_cost_usd : null,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
86
98
|
/**
|
|
87
99
|
* Wait inline for the spontaneous background-task continuation of a turn that ended with
|
|
88
100
|
* work remaining. Registers a ContinuationSink on the process and resolves with the merged
|
|
89
|
-
* result when the continuation completes (chained continuations keep waiting).
|
|
90
|
-
*
|
|
91
|
-
* on timeout it resolves with what has accumulated so far.
|
|
101
|
+
* result when the continuation completes (chained continuations keep waiting). Observer failures
|
|
102
|
+
* reject; otherwise the grace watchdog or max-wait cap resolves with the accumulated result.
|
|
92
103
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
class BackgroundContinuationWait {
|
|
105
|
+
opts;
|
|
106
|
+
timers;
|
|
107
|
+
graceMs;
|
|
108
|
+
maxWaitMs;
|
|
109
|
+
completionOnly;
|
|
110
|
+
acc;
|
|
111
|
+
settled = false;
|
|
112
|
+
handle = null;
|
|
113
|
+
resolve;
|
|
114
|
+
reject;
|
|
115
|
+
constructor(opts, timers, graceMs, maxWaitMs, completionOnly) {
|
|
116
|
+
this.opts = opts;
|
|
117
|
+
this.timers = timers;
|
|
118
|
+
this.graceMs = graceMs;
|
|
119
|
+
this.maxWaitMs = maxWaitMs;
|
|
120
|
+
this.completionOnly = completionOnly;
|
|
121
|
+
this.acc = opts.baseResult;
|
|
122
|
+
}
|
|
123
|
+
run() {
|
|
124
|
+
const promise = new Promise((resolve, reject) => {
|
|
125
|
+
this.resolve = resolve;
|
|
126
|
+
this.reject = reject;
|
|
127
|
+
this.opts.proc.setContinuationSink?.(this.sink());
|
|
128
|
+
this.arm(this.opts.baseResult.pendingBackgroundTasks ?? 0, this.opts.baseResult.undeliveredBackgroundTasks ?? 0);
|
|
129
|
+
});
|
|
130
|
+
if (this.opts.stopPromise) {
|
|
131
|
+
void this.opts.stopPromise.then(() => this.stop(), error => this.stop(error));
|
|
132
|
+
}
|
|
133
|
+
return promise;
|
|
134
|
+
}
|
|
135
|
+
settle(complete) {
|
|
136
|
+
if (this.settled)
|
|
137
|
+
return;
|
|
138
|
+
this.settled = true;
|
|
139
|
+
if (this.handle !== null)
|
|
140
|
+
this.timers.clear(this.handle);
|
|
141
|
+
this.handle = null;
|
|
142
|
+
complete();
|
|
143
|
+
}
|
|
144
|
+
finish(result) {
|
|
145
|
+
this.settle(() => this.resolve(result));
|
|
146
|
+
}
|
|
147
|
+
stop(error) {
|
|
148
|
+
const failure = error instanceof Error
|
|
149
|
+
? error
|
|
150
|
+
: new Error('Agent process stopped before background continuation completed');
|
|
151
|
+
this.settle(() => this.reject(failure));
|
|
152
|
+
}
|
|
153
|
+
emit(event) {
|
|
154
|
+
try {
|
|
155
|
+
this.opts.onEvent?.(event);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
this.settle(() => this.reject(error));
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
arm(running, undelivered) {
|
|
164
|
+
if (this.handle !== null)
|
|
165
|
+
this.timers.clear(this.handle);
|
|
166
|
+
this.handle = null;
|
|
167
|
+
if (running > 0) {
|
|
168
|
+
if (this.completionOnly)
|
|
103
169
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
else {
|
|
129
|
-
finish(acc);
|
|
130
|
-
}
|
|
170
|
+
this.handle = this.timers.set(() => {
|
|
171
|
+
log.info(`bg-wait cap (${this.maxWaitMs}ms) reached with ${running} task(s) still running — releasing the step`);
|
|
172
|
+
this.finish(this.acc);
|
|
173
|
+
}, this.maxWaitMs);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (undelivered > 0) {
|
|
177
|
+
if (this.completionOnly)
|
|
178
|
+
return;
|
|
179
|
+
this.handle = this.timers.set(() => {
|
|
180
|
+
log.info(`bg-wait grace (${this.graceMs}ms) elapsed with no notification — releasing the step`);
|
|
181
|
+
this.finish(this.acc);
|
|
182
|
+
}, this.graceMs);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this.finish(this.acc);
|
|
186
|
+
}
|
|
187
|
+
sink() {
|
|
188
|
+
return {
|
|
189
|
+
onAssistantText: (text, model) => this.assistantText(text, model),
|
|
190
|
+
onToolUse: (name, input, id) => this.toolUse(name, input, id),
|
|
191
|
+
onToolResult: (id, content, isError) => this.toolResult(id, content, isError),
|
|
192
|
+
onContextUsage: (usage) => this.contextUsage(usage),
|
|
193
|
+
onResult: (result) => this.result(result),
|
|
131
194
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
catch (
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
}
|
|
196
|
+
assistantText(text, model) {
|
|
197
|
+
if (this.settled || !this.emit({ type: 'assistant_text', text, ...(model != null ? { model } : {}) }))
|
|
198
|
+
return;
|
|
199
|
+
try {
|
|
200
|
+
this.opts.onAssistantText?.(text);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
log.warn('bg-wait onAssistantText threw:', error.message);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
toolUse(name, input, toolUseId) {
|
|
207
|
+
const id = toolUseId ?? '';
|
|
208
|
+
if (this.settled || !this.emit({ type: 'tool_use', name, input, toolUseId: id }))
|
|
209
|
+
return;
|
|
210
|
+
try {
|
|
211
|
+
this.opts.onToolUse?.(name, input, id);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
log.warn('bg-wait onToolUse threw:', error.message);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
toolResult(toolUseId, content, isError) {
|
|
218
|
+
if (this.settled || !this.emit({ type: 'tool_result', toolUseId, content, ok: !isError }))
|
|
219
|
+
return;
|
|
220
|
+
try {
|
|
221
|
+
this.opts.onToolResult?.(toolUseId, content, isError);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
log.warn('bg-wait onToolResult threw:', error.message);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
contextUsage(usage) {
|
|
228
|
+
if (this.settled || !this.emit({ type: 'context_usage', ...usage }))
|
|
229
|
+
return;
|
|
230
|
+
try {
|
|
231
|
+
void Promise.resolve(this.opts.onContextUsage?.(usage))
|
|
232
|
+
.catch((error) => log.warn('bg-wait onContextUsage rejected:', error.message));
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
log.warn('bg-wait onContextUsage threw:', error.message);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
result(continuation) {
|
|
239
|
+
if (this.settled)
|
|
240
|
+
return;
|
|
241
|
+
if (continuation.backgroundInterrupted) {
|
|
242
|
+
if (this.completionOnly)
|
|
243
|
+
this.stop();
|
|
244
|
+
else
|
|
245
|
+
this.finish({ ...this.acc, backgroundInterrupted: true });
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const costRecord = continuationCostRecord(continuation);
|
|
249
|
+
if (costRecord && !this.emit(costRecord))
|
|
250
|
+
return;
|
|
251
|
+
const preserveReportedness = continuation.reportedAccounting !== undefined;
|
|
252
|
+
if (!this.emit({
|
|
253
|
+
type: 'turn_complete',
|
|
254
|
+
numTurns: preserveReportedness ? continuation.num_turns : continuation.num_turns ?? 0,
|
|
255
|
+
totalCostUsd: continuation.total_cost_usd ?? null,
|
|
256
|
+
}))
|
|
257
|
+
return;
|
|
258
|
+
this.acc = mergeContinuation(this.acc, continuation);
|
|
259
|
+
if (this.acc.rateLimited) {
|
|
260
|
+
this.finish(this.acc);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const running = continuation.pendingBackgroundTasks ?? 0;
|
|
264
|
+
const undelivered = continuation.undeliveredBackgroundTasks ?? 0;
|
|
265
|
+
if (running + undelivered > 0)
|
|
266
|
+
this.arm(running, undelivered);
|
|
267
|
+
else
|
|
268
|
+
this.finish(this.acc);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export function waitForBgContinuation(opts) {
|
|
272
|
+
const completionOnly = opts.completionOnly === true;
|
|
273
|
+
if (completionOnly && !opts.stopPromise) {
|
|
274
|
+
return Promise.reject(new Error('Completion-only background wait requires a stop promise'));
|
|
275
|
+
}
|
|
276
|
+
return new BackgroundContinuationWait(opts, opts.timers ?? realTimers, completionOnly ? 0 : (opts.graceMs ?? getBgGraceMs()), completionOnly ? 0 : (opts.maxWaitMs ?? getBgMaxWaitMs()), completionOnly).run();
|
|
197
277
|
}
|
|
@@ -2,6 +2,7 @@ import { EventEmitter } from 'node:events';
|
|
|
2
2
|
import { TmuxControl } from './tmux-control.js';
|
|
3
3
|
import { type CortexAgentContext } from './spawn-args.js';
|
|
4
4
|
import type { NormalizedEvent } from '../normalize/event-types.js';
|
|
5
|
+
import { type McpComposition } from '../types.js';
|
|
5
6
|
/** Subset of JsonlTail surface the session depends on — lets tests inject a mock. */
|
|
6
7
|
export interface JsonlTailLike extends EventEmitter {
|
|
7
8
|
start(): Promise<void>;
|
|
@@ -48,7 +49,7 @@ export interface ClaudeTuiSessionConfig {
|
|
|
48
49
|
extraOption?: Record<string, string> | null;
|
|
49
50
|
/** Thinking level from the profile's `thinking` field → `--effort <level>`. Absent → no flag. */
|
|
50
51
|
thinking?: string | null;
|
|
51
|
-
|
|
52
|
+
mcpComposition?: McpComposition;
|
|
52
53
|
callbackSource?: string | null;
|
|
53
54
|
scheduleTaskId?: string | null;
|
|
54
55
|
anthropicBaseUrl?: string;
|
|
@@ -96,6 +97,7 @@ export declare class ClaudeTuiSession {
|
|
|
96
97
|
readonly sessionId: string;
|
|
97
98
|
readonly sessionKey: string;
|
|
98
99
|
readonly cwd: string;
|
|
100
|
+
readonly mcpComposition: McpComposition;
|
|
99
101
|
readonly tmuxName: string;
|
|
100
102
|
readonly jsonlPath: string;
|
|
101
103
|
private readonly tmux;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output:
|
|
3
|
-
// pos:
|
|
4
|
-
// >>>
|
|
1
|
+
// input: cwd, composition, prompts, tools, TUI deps
|
|
2
|
+
// output: interactive Claude session with spawn policy
|
|
3
|
+
// pos: Runs Claude TUI sessions under tmux
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import { createLogger } from '../../core/log.js';
|
|
@@ -9,6 +9,7 @@ import { JsonlTail, JsonlEventNormalizer } from './jsonl-tail.js';
|
|
|
9
9
|
import { CancelledError, TUI_TMUX_NAME_PREFIX, TUI_JSONL_BASE, IDLE_SESSION_TIMEOUT, MAX_TIMEOUT, TURN_IDLE_TIMEOUT, JSONL_FIRST_EVENT_TIMEOUT, PASTE_SUBMIT_DELAY_MS, PANE_READY_TIMEOUT, PANE_READY_POLL_MS, PANE_READY_MARKER, } from './defaults.js';
|
|
10
10
|
import { buildSpawnArgs, buildClaudeEnv } from './spawn-args.js';
|
|
11
11
|
import { buildPrompt, mergeSubstantialOutput } from './event-parser.js';
|
|
12
|
+
import { resolveMcpComposition } from '../types.js';
|
|
12
13
|
const log = createLogger('claude-tui');
|
|
13
14
|
// =====================================================================================
|
|
14
15
|
// ClaudeTuiSession
|
|
@@ -25,6 +26,7 @@ export class ClaudeTuiSession {
|
|
|
25
26
|
sessionId;
|
|
26
27
|
sessionKey;
|
|
27
28
|
cwd;
|
|
29
|
+
mcpComposition;
|
|
28
30
|
tmuxName;
|
|
29
31
|
jsonlPath;
|
|
30
32
|
tmux;
|
|
@@ -49,6 +51,7 @@ export class ClaudeTuiSession {
|
|
|
49
51
|
this.sessionId = config.sessionId;
|
|
50
52
|
this.sessionKey = config.sessionKey;
|
|
51
53
|
this.cwd = config.cwd;
|
|
54
|
+
this.mcpComposition = resolveMcpComposition(config.mcpComposition, config.context?.useCoreMcp);
|
|
52
55
|
this.needsResume = config.needsResume;
|
|
53
56
|
this.tmux = config.deps.tmux;
|
|
54
57
|
this.tailFactory = config.deps.tailFactory;
|
|
@@ -78,7 +81,7 @@ export class ClaudeTuiSession {
|
|
|
78
81
|
outputStyle: this.config.outputStyle ?? null,
|
|
79
82
|
extraOption: this.config.extraOption ?? null,
|
|
80
83
|
thinking: this.config.thinking ?? null,
|
|
81
|
-
|
|
84
|
+
mcpComposition: this.mcpComposition,
|
|
82
85
|
needsResume: this.needsResume,
|
|
83
86
|
sessionId: this.sessionId,
|
|
84
87
|
mode: 'tui',
|