@cortex-agent/server 2026.6.22 → 2026.7.30
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 +25 -13
- package/defaults/.claude/settings.json +4 -0
- package/defaults/config/CORTEX.md +9 -0
- package/defaults/config/hooks/01-sensitive-file-edit.json +11 -0
- package/defaults/config/hooks/02-tasks-yaml-guard.json +11 -0
- package/defaults/config/hooks/03-ask-user-question-hook.json +19 -0
- package/defaults/config/hooks/04-exit-plan-mode-hook.json +19 -0
- package/defaults/config/hooks/05-memory-ref-tracker.json +10 -0
- package/defaults/config/hooks/06-rules-loader.json +10 -0
- package/defaults/config/hooks/07-session-activity-tracker.json +10 -0
- package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +10 -0
- package/defaults/config/hooks/09-permission-request-auto-allow.json +11 -0
- package/defaults/config/hooks/10-cortex-md-injector-session-start.json +10 -0
- package/defaults/config/hooks/11-task-status-check.json +14 -0
- package/defaults/config/hooks/12-session-new-hook.json +11 -0
- package/defaults/config/hooks/CORTEX.md +18 -0
- package/defaults/config/thread-templates/agents/coder-reviewer.json +25 -0
- package/defaults/config/thread-templates/agents/coder.json +30 -0
- package/defaults/config/thread-templates/agents/direct-review.json +17 -0
- package/defaults/config/thread-templates/agents/direct-web.json +16 -0
- package/defaults/config/thread-templates/agents/direct.json +16 -0
- package/defaults/config/thread-templates/agents/director.json +14 -0
- package/defaults/config/thread-templates/agents/doc-reviewer.json +14 -0
- package/defaults/config/thread-templates/agents/doc-writer.json +25 -0
- package/defaults/config/thread-templates/agents/executor-reviewer.json +14 -0
- package/defaults/config/thread-templates/agents/executor.json +25 -0
- package/defaults/config/thread-templates/agents/main.json +16 -0
- package/defaults/config/thread-templates/agents/manager.json +17 -0
- package/defaults/config/thread-templates/agents/scheduler-main.json +16 -0
- package/defaults/config/thread-templates/shells/worker-review.json +19 -0
- package/defaults/config/thread-templates/templates/coder-review.json +53 -0
- package/defaults/config/thread-templates/templates/default.json +10 -0
- package/defaults/config/thread-templates/templates/doc-review.json +6 -0
- package/defaults/config/thread-templates/templates/execute-review.json +6 -0
- package/defaults/config/thread-templates/templates/manager.json +11 -0
- package/defaults/config/thread-templates/templates/scheduler.json +19 -0
- package/defaults/context/decisions/DR-0012.md +1 -1
- package/defaults/context/user/CORTEX.md +2 -2
- package/defaults/gitignore +3 -0
- package/defaults/hooks/CORTEX.md +18 -0
- package/defaults/hooks/ask-user-question-hook.mjs +1 -0
- package/defaults/hooks/cortex-hook-api.mjs +84 -0
- package/defaults/hooks/cortex-md-injector.mjs +99 -49
- package/defaults/hooks/exit-plan-mode-hook.mjs +1 -0
- package/defaults/hooks/memory-ref-tracker.mjs +1 -0
- package/defaults/hooks/new-session-hook.mjs +1 -0
- package/defaults/hooks/post-task-hook.mjs +1 -0
- package/defaults/hooks/rules-loader.mjs +1 -0
- package/defaults/hooks/sensitive-file-edit.mjs +1 -0
- package/defaults/hooks/session-activity-tracker.mjs +8 -100
- package/defaults/hooks/task-status-check.mjs +10 -10
- package/defaults/hooks/tasks-yaml-guard.mjs +1 -0
- package/defaults/mcp-config-web.json +11 -0
- package/defaults/pi/agents/explore.md +9 -0
- package/defaults/pi/agents/general-purpose.md +6 -0
- package/defaults/pi/agents/plan.md +9 -0
- package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-coder/skills/cli-standards/SKILL.md +2 -2
- package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +33 -0
- package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-common/skills/debug-campaign/SKILL.md +16 -16
- package/defaults/plugins/cortex-common/skills/execute-method/SKILL.md +53 -0
- package/defaults/plugins/cortex-common/skills/execute-review-rubric/SKILL.md +102 -0
- package/defaults/plugins/cortex-common/skills/manager-method/SKILL.md +67 -0
- package/defaults/plugins/cortex-common/skills/solution-design/SKILL.md +3 -3
- package/defaults/plugins/cortex-feishu/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +163 -0
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/scripts/ensure-lark-cli.sh +53 -0
- package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +54 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +132 -112
- package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +17 -10
- package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/orient/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/orient-project/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +66 -17
- package/defaults/prompts/directives/coder-reviewer.md +6 -6
- package/defaults/prompts/directives/coder.md +4 -29
- package/defaults/prompts/directives/director.md +4 -17
- package/defaults/prompts/directives/doc-reviewer.md +2 -35
- package/defaults/prompts/directives/doc-writer.md +2 -7
- package/defaults/prompts/directives/executor-reviewer.md +2 -39
- package/defaults/prompts/directives/executor.md +2 -7
- package/defaults/prompts/directives/manager.md +12 -27
- package/defaults/prompts/systemPrompts/coder.md +1 -1
- package/defaults/prompts/systemPrompts/direct.md +1 -1
- package/defaults/prompts/systemPrompts/web.md +5 -0
- package/defaults/prompts/systemPrompts/worker.md +1 -1
- package/dist/agent-adapter/bg-wait.d.ts +44 -0
- package/dist/agent-adapter/bg-wait.js +197 -0
- package/dist/agent-adapter/capabilities.d.ts +7 -1
- package/dist/agent-adapter/capabilities.js +18 -9
- package/dist/agent-adapter/claude/adapter-tui.d.ts +14 -0
- package/dist/agent-adapter/claude/adapter-tui.js +16 -0
- package/dist/agent-adapter/claude/adapter.d.ts +89 -5
- package/dist/agent-adapter/claude/adapter.js +410 -40
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +23 -8
- package/dist/agent-adapter/claude/bg-task-tracker.js +48 -19
- package/dist/agent-adapter/claude/compact-window.d.ts +9 -0
- package/dist/agent-adapter/claude/compact-window.js +46 -0
- package/dist/agent-adapter/claude/context-usage.d.ts +28 -0
- package/dist/agent-adapter/claude/context-usage.js +177 -0
- package/dist/agent-adapter/claude/defaults.d.ts +17 -3
- package/dist/agent-adapter/claude/defaults.js +25 -9
- package/dist/agent-adapter/claude/event-parser.d.ts +30 -0
- package/dist/agent-adapter/claude/event-parser.js +68 -4
- package/dist/agent-adapter/claude/hooks-builder.d.ts +23 -23
- package/dist/agent-adapter/claude/hooks-builder.js +63 -7
- package/dist/agent-adapter/claude/spawn-args.d.ts +25 -6
- package/dist/agent-adapter/claude/spawn-args.js +62 -22
- package/dist/agent-adapter/index.js +2 -4
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -1
- package/dist/agent-adapter/normalize/event-types.js +1 -1
- package/dist/agent-adapter/normalize/tool-names.js +0 -9
- package/dist/agent-adapter/pi/adapter.d.ts +3 -33
- package/dist/agent-adapter/pi/adapter.js +461 -229
- package/dist/agent-adapter/pi/agent-dir.d.ts +6 -0
- package/dist/agent-adapter/pi/agent-dir.js +24 -14
- package/dist/agent-adapter/pi/defaults.d.ts +4 -0
- package/dist/agent-adapter/pi/defaults.js +11 -0
- package/dist/agent-adapter/pi/discovery.d.ts +4 -0
- package/dist/agent-adapter/pi/discovery.js +63 -0
- package/dist/agent-adapter/pi/event-parser.d.ts +13 -2
- package/dist/agent-adapter/pi/event-parser.js +139 -69
- package/dist/agent-adapter/pi/hook-bridge.d.ts +13 -28
- package/dist/agent-adapter/pi/hook-bridge.js +272 -167
- package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +24 -0
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +39 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -35
- package/dist/agent-adapter/pi/mcp-bridge.js +147 -137
- package/dist/agent-adapter/pi/pi-ext-types.d.ts +30 -0
- package/dist/agent-adapter/pi/pi-ext-types.js +2 -2
- package/dist/agent-adapter/pi/session-support.d.ts +96 -0
- package/dist/agent-adapter/pi/session-support.js +213 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +15 -0
- package/dist/agent-adapter/pi/spawn-args.js +46 -3
- package/dist/agent-adapter/pi/subagent.d.ts +68 -0
- package/dist/agent-adapter/pi/subagent.js +521 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +1 -13
- package/dist/agent-adapter/pi/tool-shims.js +182 -198
- package/dist/agent-adapter/pi/web-fetch.d.ts +13 -0
- package/dist/agent-adapter/pi/web-fetch.js +201 -0
- package/dist/agent-adapter/pi/web-search.d.ts +9 -0
- package/dist/agent-adapter/pi/web-search.js +513 -0
- package/dist/agent-adapter/types.d.ts +61 -10
- package/dist/agent-adapter/types.js +4 -4
- package/dist/core/atomic-write.d.ts +3 -5
- package/dist/core/atomic-write.js +26 -12
- package/dist/core/bg-held-sessions.d.ts +35 -0
- package/dist/core/bg-held-sessions.js +79 -0
- package/dist/core/calver.d.ts +1 -0
- package/dist/core/calver.js +29 -0
- package/dist/core/config-generator.d.ts +13 -2
- package/dist/core/config-generator.js +55 -5
- package/dist/core/debug-mode.d.ts +14 -0
- package/dist/core/debug-mode.js +32 -0
- package/dist/core/gateway-generator.js +15 -11
- package/dist/core/hook-bus.d.ts +23 -0
- package/dist/core/hook-bus.js +111 -0
- package/dist/core/hook-exec.d.ts +15 -0
- package/dist/core/hook-exec.js +90 -0
- package/dist/core/icons.d.ts +2 -0
- package/dist/core/icons.js +2 -0
- package/dist/core/locales/en.d.ts +30 -7
- package/dist/core/locales/en.js +4 -1
- package/dist/core/locales/slices/commands.d.ts +12 -2
- package/dist/core/locales/slices/commands.js +31 -7
- package/dist/core/locales/slices/init.d.ts +1 -1
- package/dist/core/locales/slices/init.js +2 -2
- package/dist/core/locales/slices/interactions.d.ts +6 -0
- package/dist/core/locales/slices/interactions.js +14 -0
- package/dist/core/locales/slices/status.d.ts +7 -3
- package/dist/core/locales/slices/status.js +16 -8
- package/dist/core/log.js +4 -3
- package/dist/core/paths.d.ts +9 -0
- package/dist/core/paths.js +20 -1
- package/dist/core/profile-generator.d.ts +2 -2
- package/dist/core/profile-generator.js +6 -9
- package/dist/core/running-executions.d.ts +10 -1
- package/dist/core/running-executions.js +10 -0
- package/dist/core/status-format.d.ts +14 -0
- package/dist/core/status-format.js +23 -1
- package/dist/core/task-node.d.ts +7 -0
- package/dist/core/task-node.js +29 -0
- package/dist/core/types/agent-types.d.ts +23 -2
- package/dist/core/types/agent-types.js +2 -2
- package/dist/core/types/thread-types.d.ts +90 -15
- package/dist/core/types/thread-types.js +3 -3
- package/dist/core/utils.d.ts +2 -2
- package/dist/core/utils.js +3 -3
- package/dist/domain/agents/config.d.ts +6 -5
- package/dist/domain/agents/config.js +17 -5
- package/dist/domain/agents/facade.d.ts +74 -10
- package/dist/domain/agents/facade.js +333 -62
- package/dist/domain/agents/index.d.ts +1 -0
- package/dist/domain/agents/index.js +1 -0
- package/dist/domain/agents/profile-manager.d.ts +14 -7
- package/dist/domain/agents/profile-manager.js +23 -7
- package/dist/domain/agents/profile-switch.d.ts +53 -0
- package/dist/domain/agents/profile-switch.js +79 -0
- package/dist/domain/costs/cost-tracker.d.ts +21 -1
- package/dist/domain/costs/cost-tracker.js +54 -26
- package/dist/domain/costs/gateway-manager.js +5 -3
- package/dist/domain/costs/rate-limit-throttle.d.ts +44 -19
- package/dist/domain/costs/rate-limit-throttle.js +331 -103
- package/dist/domain/costs/resume-registry.d.ts +17 -9
- package/dist/domain/costs/resume-registry.js +63 -8
- package/dist/domain/executions/log-tailer.d.ts +71 -0
- package/dist/domain/executions/log-tailer.js +195 -0
- package/dist/domain/executions/registry.d.ts +10 -1
- package/dist/domain/executions/registry.js +14 -0
- package/dist/domain/hooks/hook-view.d.ts +22 -0
- package/dist/domain/hooks/hook-view.js +38 -0
- package/dist/domain/mcp/core-server.d.ts +0 -1
- package/dist/domain/mcp/core-server.js +8 -40
- package/dist/domain/mcp/feishu/file.js +1 -11
- package/dist/domain/mcp/feishu/index.d.ts +0 -2
- package/dist/domain/mcp/feishu/index.js +5 -56
- package/dist/domain/mcp/feishu-server.d.ts +0 -1
- package/dist/domain/mcp/feishu-server.js +5 -6
- package/dist/domain/mcp/manager-qa-server.d.ts +1 -0
- package/dist/domain/mcp/manager-qa-server.js +23 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +5 -31
- package/dist/domain/mcp/slack-server.d.ts +0 -1
- package/dist/domain/mcp/slack-server.js +3 -5
- package/dist/domain/mcp/tasks-server.d.ts +1 -0
- package/dist/domain/mcp/tasks-server.js +23 -0
- package/dist/domain/mcp/thread-server.d.ts +1 -0
- package/dist/domain/mcp/thread-server.js +25 -0
- package/dist/domain/mcp/tools/context.d.ts +3 -10
- package/dist/domain/mcp/tools/context.js +13 -29
- package/dist/domain/mcp/tools/manager-qa.d.ts +2 -1
- package/dist/domain/mcp/tools/manager-qa.js +49 -53
- package/dist/domain/mcp/tools/schedule.d.ts +1 -2
- package/dist/domain/mcp/tools/schedule.js +7 -10
- package/dist/domain/mcp/tools/slack.d.ts +0 -1
- package/dist/domain/mcp/tools/slack.js +2 -13
- package/dist/domain/mcp/tools/task-ops.js +10 -137
- package/dist/domain/mcp/tools/thread-ops.js +6 -11
- package/dist/domain/mcp/tools/tui-ask.d.ts +2 -0
- package/dist/domain/mcp/tools/tui-ask.js +8 -0
- package/dist/domain/mcp/tools/ui-file.d.ts +2 -0
- package/dist/domain/mcp/tools/ui-file.js +49 -0
- package/dist/domain/mcp/tui-server.d.ts +0 -1
- package/dist/domain/mcp/tui-server.js +39 -24
- package/dist/domain/mcp/web-server.d.ts +1 -0
- package/dist/domain/mcp/web-server.js +25 -0
- package/dist/domain/memory/cortex-md-injector.d.ts +4 -10
- package/dist/domain/memory/cortex-md-injector.js +113 -77
- package/dist/domain/memory/cortex-md-scanner.d.ts +1 -0
- package/dist/domain/memory/cortex-md-scanner.js +5 -2
- package/dist/domain/memory/skill-scanner.d.ts +3 -1
- package/dist/domain/memory/skill-scanner.js +8 -12
- package/dist/domain/memory/user-context.d.ts +6 -5
- package/dist/domain/memory/user-context.js +12 -7
- package/dist/domain/monitor/disk-monitor.js +2 -3
- package/dist/domain/projects/index.d.ts +1 -0
- package/dist/domain/projects/project-store.d.ts +18 -0
- package/dist/domain/projects/project-store.js +39 -3
- package/dist/domain/remote/client-hot-reload.d.ts +9 -2
- package/dist/domain/remote/client-hot-reload.js +81 -9
- package/dist/domain/remote/client-manager.d.ts +15 -1
- package/dist/domain/remote/client-manager.js +75 -11
- package/dist/domain/remote/cortex-client.js +6 -48
- package/dist/domain/scheduling/job-registry.d.ts +0 -2
- package/dist/domain/scheduling/job-registry.js +2 -6
- package/dist/domain/scheduling/jobs/_shared.d.ts +5 -1
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +1 -0
- package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +78 -0
- package/dist/domain/scheduling/jobs/scheduled-task.js +1 -3
- package/dist/domain/scheduling/jobs/task-dispatch.js +40 -31
- package/dist/domain/scheduling/scheduler.d.ts +0 -10
- package/dist/domain/scheduling/scheduler.js +9 -9
- package/dist/domain/sessions/session-hooks.d.ts +38 -15
- package/dist/domain/sessions/session-hooks.js +128 -122
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -1
- package/dist/domain/sessions/session-lifecycle.js +41 -4
- package/dist/domain/sessions/session-registry.d.ts +3 -1
- package/dist/domain/system/doctor.d.ts +63 -0
- package/dist/domain/system/doctor.js +359 -0
- package/dist/domain/system/server-update-check.d.ts +2 -1
- package/dist/domain/system/server-update-check.js +7 -26
- package/dist/domain/system/system-notice.d.ts +18 -0
- package/dist/domain/system/system-notice.js +34 -0
- package/dist/domain/tasks/acceptance-ledger.d.ts +31 -0
- package/dist/domain/tasks/acceptance-ledger.js +83 -0
- package/dist/domain/tasks/claim-recovery.d.ts +10 -0
- package/dist/domain/tasks/claim-recovery.js +64 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +19 -0
- package/dist/domain/tasks/dispatcher.js +1 -3
- package/dist/domain/tasks/mutator.d.ts +7 -1
- package/dist/domain/tasks/mutator.js +55 -3
- package/dist/domain/tasks/recommendation/extractor.js +3 -3
- package/dist/domain/tasks/system/cortex-run.js +0 -0
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +37 -7
- package/dist/domain/tasks/system/task-completion.js +148 -42
- package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -0
- package/dist/domain/tasks/system/task-state.d.ts +10 -1
- package/dist/domain/tasks/system/task-state.js +31 -1
- package/dist/domain/threads/artifact-io.d.ts +3 -15
- package/dist/domain/threads/artifact-io.js +13 -119
- package/dist/domain/threads/hook-runner.d.ts +7 -2
- package/dist/domain/threads/hook-runner.js +68 -85
- package/dist/domain/threads/index.js +6 -1
- package/dist/domain/threads/prompt-builder.d.ts +14 -4
- package/dist/domain/threads/prompt-builder.js +38 -20
- package/dist/domain/threads/runner.d.ts +19 -5
- package/dist/domain/threads/runner.js +238 -82
- package/dist/domain/threads/shell-templates.d.ts +9 -0
- package/dist/domain/threads/shell-templates.js +117 -0
- package/dist/domain/threads/state-machine.d.ts +35 -7
- package/dist/domain/threads/state-machine.js +170 -29
- package/dist/domain/threads/template-loader.d.ts +15 -7
- package/dist/domain/threads/template-loader.js +204 -87
- package/dist/domain/threads/thread-transcript.d.ts +47 -0
- package/dist/domain/threads/thread-transcript.js +64 -0
- package/dist/domain/threads/utils.d.ts +8 -1
- package/dist/domain/threads/utils.js +17 -1
- package/dist/domain/tui-session/tui-session-service.js +9 -16
- package/dist/domain/tui-session/types.d.ts +12 -0
- package/dist/domain/ui-service/app-router.d.ts +670 -0
- package/dist/domain/ui-service/app-router.js +195 -0
- package/dist/domain/ui-service/index.d.ts +1 -1
- package/dist/domain/ui-service/input-schemas.d.ts +644 -0
- package/dist/domain/ui-service/input-schemas.js +385 -0
- package/dist/domain/ui-service/mutate/approvals.d.ts +31 -0
- package/dist/domain/ui-service/mutate/approvals.js +140 -0
- package/dist/domain/ui-service/mutate/config.d.ts +16 -0
- package/dist/domain/ui-service/mutate/config.js +72 -0
- package/dist/domain/ui-service/mutate/hooks.d.ts +16 -0
- package/dist/domain/ui-service/mutate/hooks.js +138 -0
- package/dist/domain/ui-service/mutate/issues.d.ts +18 -0
- package/dist/domain/ui-service/mutate/issues.js +111 -0
- package/dist/domain/ui-service/mutate/notes.d.ts +6 -0
- package/dist/domain/ui-service/mutate/notes.js +36 -0
- package/dist/domain/ui-service/mutate/projects.d.ts +4 -0
- package/dist/domain/ui-service/mutate/projects.js +10 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
- package/dist/domain/ui-service/mutate/schedules.js +57 -3
- package/dist/domain/ui-service/mutate/sessions.d.ts +11 -0
- package/dist/domain/ui-service/mutate/sessions.js +198 -0
- package/dist/domain/ui-service/mutate/system.d.ts +2 -0
- package/dist/domain/ui-service/mutate/system.js +97 -0
- package/dist/domain/ui-service/query/approvals.d.ts +10 -0
- package/dist/domain/ui-service/query/approvals.js +109 -0
- package/dist/domain/ui-service/query/config.d.ts +8 -0
- package/dist/domain/ui-service/query/config.js +138 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -1
- package/dist/domain/ui-service/query/executions.js +47 -3
- package/dist/domain/ui-service/query/hooks.d.ts +7 -0
- package/dist/domain/ui-service/query/hooks.js +110 -0
- package/dist/domain/ui-service/query/issues.d.ts +14 -0
- package/dist/domain/ui-service/query/issues.js +85 -0
- package/dist/domain/ui-service/query/machines.d.ts +2 -0
- package/dist/domain/ui-service/query/machines.js +39 -0
- package/dist/domain/ui-service/query/memory.d.ts +5 -0
- package/dist/domain/ui-service/query/memory.js +199 -0
- package/dist/domain/ui-service/query/notes.d.ts +3 -0
- package/dist/domain/ui-service/query/notes.js +18 -0
- package/dist/domain/ui-service/query/schedules.js +1 -0
- package/dist/domain/ui-service/query/sessions.d.ts +3 -1
- package/dist/domain/ui-service/query/sessions.js +227 -15
- package/dist/domain/ui-service/query/skills.d.ts +2 -0
- package/dist/domain/ui-service/query/skills.js +14 -0
- package/dist/domain/ui-service/query/system.d.ts +3 -0
- package/dist/domain/ui-service/query/system.js +132 -0
- package/dist/domain/ui-service/query/task-verification.d.ts +2 -0
- package/dist/domain/ui-service/query/task-verification.js +60 -0
- package/dist/domain/ui-service/query/tasks.d.ts +1 -0
- package/dist/domain/ui-service/query/tasks.js +24 -16
- package/dist/domain/ui-service/query/thread-templates.d.ts +8 -0
- package/dist/domain/ui-service/query/thread-templates.js +54 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -1
- package/dist/domain/ui-service/query/threads.js +213 -4
- package/dist/domain/ui-service/subscribe.js +27 -1
- package/dist/domain/ui-service/trpc.d.ts +13 -0
- package/dist/domain/ui-service/trpc.js +12 -0
- package/dist/domain/ui-service/types.d.ts +1266 -4
- package/dist/domain/ui-service/types.js +4 -4
- package/dist/domain/ui-service/ui-service.d.ts +2 -1
- package/dist/domain/ui-service/ui-service.js +112 -10
- package/dist/entry/app.js +307 -36
- package/dist/entry/cli.js +10 -0
- package/dist/entry/daemon-notice.d.ts +17 -0
- package/dist/entry/daemon-notice.js +26 -0
- package/dist/entry/daemon.d.ts +23 -1
- package/dist/entry/daemon.js +126 -41
- package/dist/entry/doctor-cli.d.ts +12 -0
- package/dist/entry/doctor-cli.js +76 -0
- package/dist/entry/hook-cli.d.ts +18 -0
- package/dist/entry/hook-cli.js +468 -0
- package/dist/entry/init.js +22 -18
- package/dist/entry/start-ui-http.d.ts +44 -0
- package/dist/entry/start-ui-http.js +289 -0
- package/dist/entry/startup-notify.js +5 -9
- package/dist/entry/ui-http-gate.d.ts +11 -0
- package/dist/entry/ui-http-gate.js +29 -0
- package/dist/events/event-bus.d.ts +7 -2
- package/dist/events/event-bus.js +5 -2
- package/dist/events/event-logger.js +14 -0
- package/dist/events/event-types.d.ts +110 -0
- package/dist/events/event-types.js +3 -3
- package/dist/hooks/ask-user-question-hook.mjs +1 -0
- package/dist/hooks/cortex-hook-api.mjs +84 -0
- package/dist/hooks/cortex-md-injector.mjs +99 -49
- package/dist/hooks/exit-plan-mode-hook.mjs +1 -0
- package/dist/hooks/memory-ref-tracker.mjs +1 -0
- package/dist/hooks/new-session-hook.mjs +1 -0
- package/dist/hooks/post-task-hook.mjs +1 -0
- package/dist/hooks/rules-loader.mjs +1 -0
- package/dist/hooks/sensitive-file-edit.mjs +1 -0
- package/dist/hooks/session-activity-tracker.mjs +8 -100
- package/dist/hooks/task-status-check.mjs +10 -10
- package/dist/hooks/tasks-yaml-guard.mjs +1 -0
- package/dist/orchestration/agent-file-send.d.ts +54 -0
- package/dist/orchestration/agent-file-send.js +110 -0
- package/dist/orchestration/agent-runner.d.ts +49 -0
- package/dist/orchestration/agent-runner.js +368 -55
- package/dist/orchestration/bg-continuation.d.ts +51 -9
- package/dist/orchestration/bg-continuation.js +53 -15
- package/dist/orchestration/bg-wait-guard.d.ts +28 -0
- package/dist/orchestration/bg-wait-guard.js +73 -0
- package/dist/orchestration/conduit-queue.d.ts +2 -0
- package/dist/orchestration/conduit-queue.js +14 -1
- package/dist/orchestration/conversation-runner.d.ts +37 -5
- package/dist/orchestration/conversation-runner.js +71 -13
- package/dist/orchestration/delta-coalescer.d.ts +69 -0
- package/dist/orchestration/delta-coalescer.js +128 -0
- package/dist/orchestration/interactions/ask-user-question.d.ts +11 -3
- package/dist/orchestration/interactions/ask-user-question.js +27 -3
- package/dist/orchestration/interactions/interaction-handlers.js +11 -36
- package/dist/orchestration/interactions/interaction-records.d.ts +59 -0
- package/dist/orchestration/interactions/interaction-records.js +156 -0
- package/dist/orchestration/interactions/plan-approvals.d.ts +5 -0
- package/dist/orchestration/interactions/plan-approvals.js +8 -0
- package/dist/orchestration/interactions/plan-response.d.ts +8 -0
- package/dist/orchestration/interactions/plan-response.js +37 -0
- package/dist/orchestration/lifecycle.d.ts +10 -4
- package/dist/orchestration/lifecycle.js +155 -60
- package/dist/orchestration/manager-qa.d.ts +15 -4
- package/dist/orchestration/manager-qa.js +43 -37
- package/dist/orchestration/mid-turn-inject.d.ts +105 -0
- package/dist/orchestration/mid-turn-inject.js +298 -0
- package/dist/orchestration/pending-injection-recovery.d.ts +35 -0
- package/dist/orchestration/pending-injection-recovery.js +92 -0
- package/dist/orchestration/resume-dispatcher.d.ts +26 -4
- package/dist/orchestration/resume-dispatcher.js +89 -43
- package/dist/orchestration/routing/commands/cancel.d.ts +26 -0
- package/dist/orchestration/routing/commands/cancel.js +64 -18
- package/dist/orchestration/routing/commands/compact.d.ts +10 -0
- package/dist/orchestration/routing/commands/compact.js +26 -0
- package/dist/orchestration/routing/commands/index.d.ts +2 -0
- package/dist/orchestration/routing/commands/index.js +9 -0
- package/dist/orchestration/routing/commands/mode.js +24 -11
- package/dist/orchestration/routing/commands/restart.d.ts +22 -0
- package/dist/orchestration/routing/commands/restart.js +49 -0
- package/dist/orchestration/routing/commands/session.js +4 -0
- package/dist/orchestration/routing/commands/status.js +5 -0
- package/dist/orchestration/routing/edit-handler.js +1 -1
- package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +2 -1
- package/dist/orchestration/routing/hook-bridge-subscribers.js +45 -4
- package/dist/orchestration/routing/hook-bridge.d.ts +10 -3
- package/dist/orchestration/routing/hook-bridge.js +26 -14
- package/dist/orchestration/routing/webhook.js +110 -19
- package/dist/orchestration/session-compact.d.ts +58 -0
- package/dist/orchestration/session-compact.js +82 -0
- package/dist/orchestration/session-events.d.ts +111 -0
- package/dist/orchestration/session-events.js +113 -0
- package/dist/orchestration/session-rewind.d.ts +72 -0
- package/dist/orchestration/session-rewind.js +104 -0
- package/dist/orchestration/session-send.d.ts +19 -0
- package/dist/orchestration/session-send.js +39 -0
- package/dist/orchestration/status-helpers.d.ts +4 -0
- package/dist/orchestration/status-helpers.js +18 -0
- package/dist/orchestration/thread-callback.d.ts +75 -3
- package/dist/orchestration/thread-callback.js +329 -74
- package/dist/orchestration/thread-executor.d.ts +1 -0
- package/dist/orchestration/thread-executor.js +23 -31
- package/dist/orchestration/web-bg-hold.d.ts +52 -0
- package/dist/orchestration/web-bg-hold.js +105 -0
- package/dist/platform/adapter.d.ts +3 -0
- package/dist/platform/adapter.js +2 -2
- package/dist/platform/adapters/composite-adapter.d.ts +6 -1
- package/dist/platform/adapters/composite-adapter.js +64 -4
- package/dist/platform/adapters/feishu.d.ts +6 -1
- package/dist/platform/adapters/feishu.js +52 -12
- package/dist/platform/adapters/slack.d.ts +2 -1
- package/dist/platform/adapters/slack.js +41 -9
- package/dist/platform/adapters/tui/index.d.ts +1 -1
- package/dist/platform/adapters/tui/ports.d.ts +8 -7
- package/dist/platform/adapters/tui/tui-gateway.d.ts +7 -0
- package/dist/platform/adapters/tui/tui-gateway.js +48 -5
- package/dist/platform/adapters/tui/tui-transcript.js +17 -29
- package/dist/platform/index.d.ts +1 -1
- package/dist/platform/index.js +1 -1
- package/dist/platform/interactive-builder.d.ts +7 -0
- package/dist/platform/interactive-builder.js +22 -2
- package/dist/platform/testing.d.ts +5 -0
- package/dist/platform/testing.js +7 -2
- package/dist/platform/tui/protocol.d.ts +0 -2
- package/dist/platform/tui/protocol.js +4 -53
- package/dist/platform/types.d.ts +12 -0
- package/dist/platform/types.js +5 -0
- package/dist/platform/ui-http/access-jwt.d.ts +28 -0
- package/dist/platform/ui-http/access-jwt.js +67 -0
- package/dist/platform/ui-http/app-update.d.ts +58 -0
- package/dist/platform/ui-http/app-update.js +155 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +56 -0
- package/dist/platform/ui-http/ui-http-server.js +231 -0
- package/dist/platform/ui-http/ui-ota.d.ts +20 -0
- package/dist/platform/ui-http/ui-ota.js +128 -0
- package/dist/platform/ui-http/zip-writer.d.ts +13 -0
- package/dist/platform/ui-http/zip-writer.js +102 -0
- package/dist/platform/utils/reaction-diagnostics.d.ts +4 -0
- package/dist/platform/utils/reaction-diagnostics.js +23 -0
- package/dist/store/conversation-history-repo.d.ts +243 -0
- package/dist/store/conversation-history-repo.js +399 -0
- package/dist/store/execution-repo.d.ts +19 -1
- package/dist/store/execution-repo.js +18 -1
- package/dist/store/hook-registry.d.ts +83 -0
- package/dist/store/hook-registry.js +318 -0
- package/dist/store/hook-sync.d.ts +12 -16
- package/dist/store/hook-sync.js +169 -70
- package/dist/store/hook-writer.d.ts +49 -0
- package/dist/store/hook-writer.js +132 -0
- package/dist/store/outbound-queue.d.ts +8 -0
- package/dist/store/outbound-queue.js +24 -3
- package/dist/store/pending-injection-repo.d.ts +30 -0
- package/dist/store/pending-injection-repo.js +51 -0
- package/dist/store/plugin-sync.d.ts +21 -0
- package/dist/store/plugin-sync.js +119 -0
- package/dist/store/profile-repo.d.ts +2 -1
- package/dist/store/profile-repo.js +6 -11
- package/dist/store/project-notes-repo.d.ts +27 -0
- package/dist/store/project-notes-repo.js +214 -0
- package/dist/store/provider-state-repo.d.ts +18 -0
- package/dist/store/provider-state-repo.js +107 -0
- package/dist/store/schedule-repo.d.ts +0 -21
- package/dist/store/schedule-repo.js +4 -25
- package/dist/store/session-registry-repo.d.ts +47 -1
- package/dist/store/session-registry-repo.js +71 -3
- package/dist/store/version-migrations.d.ts +11 -0
- package/dist/store/version-migrations.js +286 -9
- package/dist/tui/App.js +219 -27
- package/dist/tui/components/Dashboard.d.ts +3 -1
- package/dist/tui/components/Dashboard.js +31 -12
- package/dist/tui/components/DashboardCostTab.js +17 -2
- package/dist/tui/components/DashboardExecutionsTab.js +21 -1
- package/dist/tui/components/DashboardSchedulesTab.js +8 -3
- package/dist/tui/components/DashboardTasksTab.js +11 -6
- package/dist/tui/components/DashboardThreadsTab.js +20 -2
- package/dist/tui/components/InputBox.d.ts +17 -1
- package/dist/tui/components/InputBox.js +263 -8
- package/dist/tui/components/Notifications.js +7 -2
- package/dist/tui/components/ProjectSwitcher.js +7 -2
- package/dist/tui/components/SessionPicker.js +10 -1
- package/dist/tui/components/SidePanel.d.ts +3 -1
- package/dist/tui/components/SidePanel.js +4 -2
- package/dist/tui/components/SlashMenu.d.ts +8 -0
- package/dist/tui/components/SlashMenu.js +14 -0
- package/dist/tui/components/StatusLine.d.ts +12 -3
- package/dist/tui/components/StatusLine.js +29 -10
- package/dist/tui/components/Transcript.d.ts +9 -0
- package/dist/tui/components/Transcript.js +131 -26
- package/dist/tui/components/dashboard-constants.d.ts +1 -0
- package/dist/tui/components/dashboard-constants.js +7 -0
- package/dist/tui/hooks/useKeybindings.d.ts +1 -0
- package/dist/tui/hooks/useKeybindings.js +9 -14
- package/dist/tui/hooks/useMouseHandler.d.ts +17 -0
- package/dist/tui/hooks/useMouseHandler.js +103 -0
- package/dist/tui/hooks/useTranscript.d.ts +7 -2
- package/dist/tui/hooks/useTranscript.js +76 -57
- package/dist/tui/index.js +106 -10
- package/dist/tui/logic.d.ts +146 -2
- package/dist/tui/logic.js +411 -6
- package/dist/tui/raf-batch.d.ts +33 -0
- package/dist/tui/raf-batch.js +103 -0
- package/dist/tui/render/inline-markdown.d.ts +22 -0
- package/dist/tui/render/inline-markdown.js +99 -0
- package/dist/tui/render/rich-blocks.js +10 -8
- package/dist/tui/render-output.d.ts +46 -0
- package/dist/tui/render-output.js +86 -0
- package/dist/tui/slash-commands.d.ts +21 -0
- package/dist/tui/slash-commands.js +73 -0
- package/dist/tui/turn-status.d.ts +10 -0
- package/dist/tui/turn-status.js +53 -0
- package/package.json +17 -7
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/index-B19jLgji.js +138 -0
- package/web/dist/assets/index-BuFyPyRW.css +1 -0
- package/web/dist/assets/index-DCgngTJG.js +1 -0
- package/web/dist/assets/pdf-worker-DIEXcFxP.js +55 -0
- package/web/dist/assets/pdf.worker.min-DqNZU1-t.js +53 -0
- package/web/dist/favicon-32.png +0 -0
- package/web/dist/favicon.svg +7 -0
- package/web/dist/index.html +37 -0
- package/defaults/config/session-hooks.json +0 -7
- package/defaults/config/thread-templates.json +0 -594
- package/defaults/prompts/directives/milestone-executor.md +0 -119
- package/defaults/prompts/directives/milestone-reviewer.md +0 -108
- package/defaults/prompts/directives/plan-executor.md +0 -121
- package/defaults/prompts/directives/plan-reviewer.md +0 -99
- package/dist/agent-adapter/codex/adapter.d.ts +0 -42
- package/dist/agent-adapter/codex/adapter.js +0 -916
- package/dist/agent-adapter/codex/event-parser.d.ts +0 -17
- package/dist/agent-adapter/codex/event-parser.js +0 -41
- package/dist/agent-adapter/codex/spawn-args.d.ts +0 -6
- package/dist/agent-adapter/codex/spawn-args.js +0 -30
- package/dist/domain/costs/codex-event-format.d.ts +0 -4
- package/dist/domain/costs/codex-event-format.js +0 -66
- package/dist/domain/costs/codex-usage-monitor.d.ts +0 -6
- package/dist/domain/costs/codex-usage-monitor.js +0 -73
- package/dist/domain/costs/rate-limit-parser.d.ts +0 -11
- package/dist/domain/costs/rate-limit-parser.js +0 -87
- package/dist/domain/mcp/feishu/bitable.d.ts +0 -3
- package/dist/domain/mcp/feishu/bitable.js +0 -168
- package/dist/domain/mcp/feishu/block-types.d.ts +0 -44
- package/dist/domain/mcp/feishu/block-types.js +0 -127
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +0 -19
- package/dist/domain/mcp/feishu/blocks-to-text.js +0 -43
- package/dist/domain/mcp/feishu/docx.d.ts +0 -3
- package/dist/domain/mcp/feishu/docx.js +0 -163
- package/dist/domain/mcp/feishu/drive.d.ts +0 -23
- package/dist/domain/mcp/feishu/drive.js +0 -66
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +0 -40
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +0 -191
- package/dist/domain/mcp/feishu/sheets.d.ts +0 -3
- package/dist/domain/mcp/feishu/sheets.js +0 -119
- package/dist/domain/mcp/feishu/wiki.d.ts +0 -3
- package/dist/domain/mcp/feishu/wiki.js +0 -77
- package/dist/tui/components/Header.d.ts +0 -11
- package/dist/tui/components/Header.js +0 -5
- package/dist/tui/components/MessageRow.d.ts +0 -7
- package/dist/tui/components/MessageRow.js +0 -10
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AgentResult, ContextUsage } from '../core/types/agent-types.js';
|
|
2
|
+
import type { ContinuationSink } from './types.js';
|
|
3
|
+
/** Feature gate: background-task continuation is ON by default. Opt out by setting
|
|
4
|
+
* CORTEX_BG_CONTINUATION to a falsy value (0 / false / off / no). */
|
|
5
|
+
export declare function isBgContinuationEnabled(): boolean;
|
|
6
|
+
/** Grace period for work-done-but-unnotified tasks (CORTEX_BG_GRACE_S, default 90s). */
|
|
7
|
+
export declare function getBgGraceMs(): number;
|
|
8
|
+
/** Max hold for still-running tasks (CORTEX_BG_WAIT_MAX_S, default 30min). */
|
|
9
|
+
export declare function getBgMaxWaitMs(): number;
|
|
10
|
+
/** Background work remaining on a turn result: running + finished-but-unnotified. */
|
|
11
|
+
export declare function remainingBg(result: {
|
|
12
|
+
pendingBackgroundTasks?: number;
|
|
13
|
+
undeliveredBackgroundTasks?: number;
|
|
14
|
+
} | null | undefined): number;
|
|
15
|
+
/** Gate for the facade's inline wait: thread turns only (threadId set — interactive turns are
|
|
16
|
+
* held asynchronously by lifecycle instead), claude backend, sink capability, work remaining,
|
|
17
|
+
* feature flag on, not rate-limited (that goes to the retry path first). */
|
|
18
|
+
export declare function shouldAwaitBgInline(backend: string, threadId: string | null | undefined, result: AgentResult | null | undefined, canRegisterSink: boolean): boolean;
|
|
19
|
+
export interface WaitForBgOpts {
|
|
20
|
+
proc: {
|
|
21
|
+
setContinuationSink?: (sink: ContinuationSink) => void;
|
|
22
|
+
};
|
|
23
|
+
baseResult: AgentResult;
|
|
24
|
+
/** Continuation assistant text forwarded here (the step's transcript/stream callback). */
|
|
25
|
+
onAssistantText?: ((text: string) => void) | null;
|
|
26
|
+
onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
|
|
27
|
+
onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
|
|
28
|
+
onContextUsage?: ((usage: ContextUsage) => void | Promise<void>) | null;
|
|
29
|
+
graceMs?: number;
|
|
30
|
+
maxWaitMs?: number;
|
|
31
|
+
/** Injectable timers for tests. Production timers are unref'd. */
|
|
32
|
+
timers?: {
|
|
33
|
+
set: (fn: () => void, ms: number) => unknown;
|
|
34
|
+
clear: (h: unknown) => void;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
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
|
+
export declare function waitForBgContinuation(opts: WaitForBgOpts): Promise<AgentResult>;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// input: continuation sink, result, tool/context callbacks, timers
|
|
2
|
+
// output: bounded inline wait forwarding complete tools and context snapshots
|
|
3
|
+
// pos: Thread-session continuation bridge
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
//
|
|
6
|
+
// Interactive turns hold their Slack status asynchronously (orchestration/lifecycle +
|
|
7
|
+
// bg-wait-guard). Thread/dispatch turns have no status message to hold — the step's
|
|
8
|
+
// RESULT is the deliverable — so they wait INLINE: the facade keeps the turn promise
|
|
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); the
|
|
11
|
+
// same grace/cap bounds apply so an undelivered notification or a never-ending task
|
|
12
|
+
// cannot hang a thread step forever.
|
|
13
|
+
import { createLogger } from '../core/log.js';
|
|
14
|
+
const log = createLogger('bg-wait');
|
|
15
|
+
/** Feature gate: background-task continuation is ON by default. Opt out by setting
|
|
16
|
+
* CORTEX_BG_CONTINUATION to a falsy value (0 / false / off / no). */
|
|
17
|
+
export function isBgContinuationEnabled() {
|
|
18
|
+
const v = process.env.CORTEX_BG_CONTINUATION;
|
|
19
|
+
if (v === undefined)
|
|
20
|
+
return true;
|
|
21
|
+
return !['0', 'false', 'off', 'no'].includes(v.trim().toLowerCase());
|
|
22
|
+
}
|
|
23
|
+
const DEFAULT_GRACE_MS = 90_000;
|
|
24
|
+
const DEFAULT_MAX_WAIT_MS = 1_800_000;
|
|
25
|
+
function envMs(name, defMs) {
|
|
26
|
+
const raw = process.env[name];
|
|
27
|
+
if (!raw)
|
|
28
|
+
return defMs;
|
|
29
|
+
const s = Number(raw);
|
|
30
|
+
return Number.isFinite(s) && s > 0 ? s * 1000 : defMs;
|
|
31
|
+
}
|
|
32
|
+
/** Grace period for work-done-but-unnotified tasks (CORTEX_BG_GRACE_S, default 90s). */
|
|
33
|
+
export function getBgGraceMs() {
|
|
34
|
+
return envMs('CORTEX_BG_GRACE_S', DEFAULT_GRACE_MS);
|
|
35
|
+
}
|
|
36
|
+
/** Max hold for still-running tasks (CORTEX_BG_WAIT_MAX_S, default 30min). */
|
|
37
|
+
export function getBgMaxWaitMs() {
|
|
38
|
+
return envMs('CORTEX_BG_WAIT_MAX_S', DEFAULT_MAX_WAIT_MS);
|
|
39
|
+
}
|
|
40
|
+
/** Background work remaining on a turn result: running + finished-but-unnotified. */
|
|
41
|
+
export function remainingBg(result) {
|
|
42
|
+
if (!result)
|
|
43
|
+
return 0;
|
|
44
|
+
return (result.pendingBackgroundTasks ?? 0) + (result.undeliveredBackgroundTasks ?? 0);
|
|
45
|
+
}
|
|
46
|
+
/** Gate for the facade's inline wait: thread turns only (threadId set — interactive turns are
|
|
47
|
+
* held asynchronously by lifecycle instead), claude backend, sink capability, work remaining,
|
|
48
|
+
* feature flag on, not rate-limited (that goes to the retry path first). */
|
|
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)
|
|
57
|
+
return false;
|
|
58
|
+
if (!result || result.rateLimited)
|
|
59
|
+
return false;
|
|
60
|
+
return remainingBg(result) > 0;
|
|
61
|
+
}
|
|
62
|
+
const realTimers = {
|
|
63
|
+
set: (fn, ms) => {
|
|
64
|
+
const h = setTimeout(fn, ms);
|
|
65
|
+
h.unref?.();
|
|
66
|
+
return h;
|
|
67
|
+
},
|
|
68
|
+
clear: (h) => clearTimeout(h),
|
|
69
|
+
};
|
|
70
|
+
/** Merge a continuation turn into the accumulated result: costs/turns summed, latest
|
|
71
|
+
* non-empty output wins, rate-limit and remaining counts taken from the continuation. */
|
|
72
|
+
function mergeContinuation(acc, cont) {
|
|
73
|
+
const bothCostNull = acc.total_cost_usd == null && cont.total_cost_usd == null;
|
|
74
|
+
const bothTurnsNull = acc.num_turns == null && cont.num_turns == null;
|
|
75
|
+
return {
|
|
76
|
+
...acc,
|
|
77
|
+
total_cost_usd: bothCostNull ? null : (acc.total_cost_usd ?? 0) + (cont.total_cost_usd ?? 0),
|
|
78
|
+
num_turns: bothTurnsNull ? null : (acc.num_turns ?? 0) + (cont.num_turns ?? 0),
|
|
79
|
+
finalOutput: cont.finalOutput || acc.finalOutput,
|
|
80
|
+
rateLimited: acc.rateLimited || cont.rateLimited,
|
|
81
|
+
rateLimitMessage: cont.rateLimitMessage ?? acc.rateLimitMessage,
|
|
82
|
+
pendingBackgroundTasks: cont.pendingBackgroundTasks ?? 0,
|
|
83
|
+
undeliveredBackgroundTasks: cont.undeliveredBackgroundTasks ?? 0,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Wait inline for the spontaneous background-task continuation of a turn that ended with
|
|
88
|
+
* work remaining. Registers a ContinuationSink on the process and resolves with the merged
|
|
89
|
+
* result when the continuation completes (chained continuations keep waiting). Never
|
|
90
|
+
* rejects; bounded by the grace watchdog (undelivered-only) or the max-wait cap (running):
|
|
91
|
+
* on timeout it resolves with what has accumulated so far.
|
|
92
|
+
*/
|
|
93
|
+
export function waitForBgContinuation(opts) {
|
|
94
|
+
const timers = opts.timers ?? realTimers;
|
|
95
|
+
const graceMs = opts.graceMs ?? getBgGraceMs();
|
|
96
|
+
const maxWaitMs = opts.maxWaitMs ?? getBgMaxWaitMs();
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
let acc = opts.baseResult;
|
|
99
|
+
let settled = false;
|
|
100
|
+
let handle = null;
|
|
101
|
+
const finish = (result) => {
|
|
102
|
+
if (settled)
|
|
103
|
+
return;
|
|
104
|
+
settled = true;
|
|
105
|
+
if (handle !== null) {
|
|
106
|
+
timers.clear(handle);
|
|
107
|
+
handle = null;
|
|
108
|
+
}
|
|
109
|
+
resolve(result);
|
|
110
|
+
};
|
|
111
|
+
const arm = (running, undelivered) => {
|
|
112
|
+
if (handle !== null) {
|
|
113
|
+
timers.clear(handle);
|
|
114
|
+
handle = null;
|
|
115
|
+
}
|
|
116
|
+
if (running > 0) {
|
|
117
|
+
handle = timers.set(() => {
|
|
118
|
+
log.info(`bg-wait cap (${maxWaitMs}ms) reached with ${running} task(s) still running — releasing the step`);
|
|
119
|
+
finish(acc);
|
|
120
|
+
}, maxWaitMs);
|
|
121
|
+
}
|
|
122
|
+
else if (undelivered > 0) {
|
|
123
|
+
handle = timers.set(() => {
|
|
124
|
+
log.info(`bg-wait grace (${graceMs}ms) elapsed with no notification — releasing the step`);
|
|
125
|
+
finish(acc);
|
|
126
|
+
}, graceMs);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
finish(acc);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
opts.proc.setContinuationSink?.({
|
|
133
|
+
onAssistantText: (text) => {
|
|
134
|
+
if (settled)
|
|
135
|
+
return;
|
|
136
|
+
try {
|
|
137
|
+
opts.onAssistantText?.(text);
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
log.warn('bg-wait onAssistantText threw:', e.message);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
onToolUse: (name, input, toolUseId) => {
|
|
144
|
+
if (settled)
|
|
145
|
+
return;
|
|
146
|
+
try {
|
|
147
|
+
opts.onToolUse?.(name, input, toolUseId ?? '');
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
log.warn('bg-wait onToolUse threw:', e.message);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
onToolResult: (toolUseId, content, isError) => {
|
|
154
|
+
if (settled)
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
opts.onToolResult?.(toolUseId, content, isError);
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
log.warn('bg-wait onToolResult threw:', e.message);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
onContextUsage: (usage) => {
|
|
164
|
+
if (settled)
|
|
165
|
+
return;
|
|
166
|
+
try {
|
|
167
|
+
void Promise.resolve(opts.onContextUsage?.(usage)).catch((e) => log.warn('bg-wait onContextUsage rejected:', e.message));
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
log.warn('bg-wait onContextUsage threw:', e.message);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
onResult: (cont) => {
|
|
174
|
+
if (settled)
|
|
175
|
+
return;
|
|
176
|
+
if (cont.backgroundInterrupted) {
|
|
177
|
+
// Process died mid-wait (restart / crash / kill): release the step with what we
|
|
178
|
+
// have and surface the interruption to the caller.
|
|
179
|
+
finish({ ...acc, backgroundInterrupted: true });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
acc = mergeContinuation(acc, cont);
|
|
183
|
+
if (acc.rateLimited) {
|
|
184
|
+
finish(acc);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const running = cont.pendingBackgroundTasks ?? 0;
|
|
188
|
+
const undelivered = cont.undeliveredBackgroundTasks ?? 0;
|
|
189
|
+
if (running + undelivered > 0)
|
|
190
|
+
arm(running, undelivered);
|
|
191
|
+
else
|
|
192
|
+
finish(acc);
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
arm(opts.baseResult.pendingBackgroundTasks ?? 0, opts.baseResult.undeliveredBackgroundTasks ?? 0);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
@@ -7,6 +7,12 @@ export declare enum Capability {
|
|
|
7
7
|
AskUserQuestion = "ask-user-question",
|
|
8
8
|
SystemPromptOverride = "system-prompt-override",
|
|
9
9
|
SessionResume = "session-resume",
|
|
10
|
-
ToolAllowlist = "tool-allowlist"
|
|
10
|
+
ToolAllowlist = "tool-allowlist",
|
|
11
|
+
/** Backend republishes token-level assistant text as `assistant_delta` events while a block is
|
|
12
|
+
* still being generated. Rendered by the Web UI only. */
|
|
13
|
+
StreamingDeltas = "streaming-deltas",
|
|
14
|
+
/** Backend accepts a user message into a turn already in flight (no new turn opened).
|
|
15
|
+
* Part of the shared capability vocabulary; declared by the backends that implement injection. */
|
|
16
|
+
MidTurnInject = "mid-turn-inject"
|
|
11
17
|
}
|
|
12
18
|
export declare const CAPABILITIES_BY_BACKEND: Record<Backend, Set<Capability>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// input: Backend type from types.ts
|
|
2
|
-
// output: Capability enum
|
|
2
|
+
// output: Capability enum and Claude/PI capability matrix
|
|
3
3
|
// pos: Capability declaration matrix per backend
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
export var Capability;
|
|
@@ -12,8 +12,16 @@ export var Capability;
|
|
|
12
12
|
Capability["SystemPromptOverride"] = "system-prompt-override";
|
|
13
13
|
Capability["SessionResume"] = "session-resume";
|
|
14
14
|
Capability["ToolAllowlist"] = "tool-allowlist";
|
|
15
|
+
/** Backend republishes token-level assistant text as `assistant_delta` events while a block is
|
|
16
|
+
* still being generated. Rendered by the Web UI only. */
|
|
17
|
+
Capability["StreamingDeltas"] = "streaming-deltas";
|
|
18
|
+
/** Backend accepts a user message into a turn already in flight (no new turn opened).
|
|
19
|
+
* Part of the shared capability vocabulary; declared by the backends that implement injection. */
|
|
20
|
+
Capability["MidTurnInject"] = "mid-turn-inject";
|
|
15
21
|
})(Capability || (Capability = {}));
|
|
16
|
-
// Claude: full native support (claude-bridge.ts
|
|
22
|
+
// Claude: full native support (claude-bridge.ts wires all ten shared capabilities).
|
|
23
|
+
// StreamingDeltas: `--include-partial-messages` token-level output.
|
|
24
|
+
// MidTurnInject: print mode accepts a user message on stdin while a turn is in flight.
|
|
17
25
|
const CLAUDE_CAPS = [
|
|
18
26
|
Capability.Hooks,
|
|
19
27
|
Capability.Plugins,
|
|
@@ -23,17 +31,17 @@ const CLAUDE_CAPS = [
|
|
|
23
31
|
Capability.SystemPromptOverride,
|
|
24
32
|
Capability.SessionResume,
|
|
25
33
|
Capability.ToolAllowlist,
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Capability.
|
|
31
|
-
Capability.SessionResume,
|
|
34
|
+
// Print mode requests --include-partial-messages and republishes the resulting text deltas as
|
|
35
|
+
// `assistant_delta` normalized events (Web UI preview only).
|
|
36
|
+
Capability.StreamingDeltas,
|
|
37
|
+
// Print mode accepts a user message written to stdin while a turn is in flight.
|
|
38
|
+
Capability.MidTurnInject,
|
|
32
39
|
];
|
|
33
40
|
// PI: per DR-0008 §5.1 capability matrix — --skill for Plugins, --system-prompt for SystemPromptOverride, tool-allowlist via adapter;
|
|
34
41
|
// MCP enabled by mcp-bridge.ts extension (task 5754): auto-injected via --extension in PIAdapter.spawn();
|
|
35
42
|
// PlanMode/AskUserQuestion: implemented via tool-shims.ts pseudo-tools + extension_ui_response routing (Phase 2 §S3, 2026-04-27);
|
|
36
43
|
// SessionResume: S2 spike confirmed --session <path> resume works (DR-0008 §8 gate ticked, task 7ca9).
|
|
44
|
+
// MidTurnInject: RPC prompt streamingBehavior=steer queues a message at the next agent-loop boundary.
|
|
37
45
|
// Hooks via PI extension bridge per §3.5 — capability declared true because the extension is part of the default PI adapter package.
|
|
38
46
|
const PI_CAPS = [
|
|
39
47
|
Capability.Hooks,
|
|
@@ -44,9 +52,10 @@ const PI_CAPS = [
|
|
|
44
52
|
Capability.SystemPromptOverride,
|
|
45
53
|
Capability.ToolAllowlist,
|
|
46
54
|
Capability.SessionResume,
|
|
55
|
+
Capability.StreamingDeltas,
|
|
56
|
+
Capability.MidTurnInject,
|
|
47
57
|
];
|
|
48
58
|
export const CAPABILITIES_BY_BACKEND = {
|
|
49
59
|
claude: new Set(CLAUDE_CAPS),
|
|
50
|
-
codex: new Set(CODEX_CAPS),
|
|
51
60
|
pi: new Set(PI_CAPS),
|
|
52
61
|
};
|
|
@@ -46,6 +46,8 @@ export interface ClaudeTuiSessionConfig {
|
|
|
46
46
|
pluginDirs?: string[] | null;
|
|
47
47
|
outputStyle?: string | null;
|
|
48
48
|
extraOption?: Record<string, string> | null;
|
|
49
|
+
/** Thinking level from the profile's `thinking` field → `--effort <level>`. Absent → no flag. */
|
|
50
|
+
thinking?: string | null;
|
|
49
51
|
mcpConfigPath?: string;
|
|
50
52
|
callbackSource?: string | null;
|
|
51
53
|
scheduleTaskId?: string | null;
|
|
@@ -165,6 +167,18 @@ export declare class ClaudeTuiSession {
|
|
|
165
167
|
* have JsonlTail watching a non-existent path and timing out on first turn.
|
|
166
168
|
*/
|
|
167
169
|
export declare function computeJsonlPath(cwd: string, sessionId: string): string;
|
|
170
|
+
/**
|
|
171
|
+
* Decide whether a TUI session should spawn with `--resume <id>` (vs `--session-id <id>`).
|
|
172
|
+
*
|
|
173
|
+
* `--resume` only succeeds when a Claude transcript already exists for that id. A *fresh* TUI
|
|
174
|
+
* session pre-registers its channel→sessionId mapping BEFORE the first Claude turn (so transcript
|
|
175
|
+
* replay / session naming work), which makes the orchestrator's generic "a session mapping exists
|
|
176
|
+
* ⇒ resume" heuristic ask to resume an id that has no transcript yet — Claude then exits with
|
|
177
|
+
* "No conversation found with session ID: <id>". Gating the resume request on the transcript
|
|
178
|
+
* actually existing keeps the first turn on `--session-id` (create) and lets only later turns /
|
|
179
|
+
* reconnects use `--resume`. Self-healing: a deleted transcript also correctly falls back to create.
|
|
180
|
+
*/
|
|
181
|
+
export declare function resolveTuiResume(requestedResume: boolean, jsonlPath: string, exists?: (p: string) => boolean): boolean;
|
|
168
182
|
/**
|
|
169
183
|
* Convenience factory: real JsonlTail wired to the path. Used by production code; tests inject
|
|
170
184
|
* a custom factory instead.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// output: ClaudeTuiSession — interactive Claude under tmux with jsonl tail; implements turn lifecycle
|
|
3
3
|
// pos: DR-0012 Phase 2 — parallel adapter to claude/adapter.ts; selects via spawn-args mode='tui'
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
5
6
|
import * as path from 'path';
|
|
6
7
|
import { createLogger } from '../../core/log.js';
|
|
7
8
|
import { JsonlTail, JsonlEventNormalizer } from './jsonl-tail.js';
|
|
@@ -76,6 +77,7 @@ export class ClaudeTuiSession {
|
|
|
76
77
|
pluginDirs: this.config.pluginDirs ?? null,
|
|
77
78
|
outputStyle: this.config.outputStyle ?? null,
|
|
78
79
|
extraOption: this.config.extraOption ?? null,
|
|
80
|
+
thinking: this.config.thinking ?? null,
|
|
79
81
|
mcpConfigPath: this.config.mcpConfigPath,
|
|
80
82
|
needsResume: this.needsResume,
|
|
81
83
|
sessionId: this.sessionId,
|
|
@@ -492,6 +494,20 @@ export function computeJsonlPath(cwd, sessionId) {
|
|
|
492
494
|
const encoded = cwd.replace(/[/.]/g, '-');
|
|
493
495
|
return path.join(TUI_JSONL_BASE, encoded, `${sessionId}.jsonl`);
|
|
494
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Decide whether a TUI session should spawn with `--resume <id>` (vs `--session-id <id>`).
|
|
499
|
+
*
|
|
500
|
+
* `--resume` only succeeds when a Claude transcript already exists for that id. A *fresh* TUI
|
|
501
|
+
* session pre-registers its channel→sessionId mapping BEFORE the first Claude turn (so transcript
|
|
502
|
+
* replay / session naming work), which makes the orchestrator's generic "a session mapping exists
|
|
503
|
+
* ⇒ resume" heuristic ask to resume an id that has no transcript yet — Claude then exits with
|
|
504
|
+
* "No conversation found with session ID: <id>". Gating the resume request on the transcript
|
|
505
|
+
* actually existing keeps the first turn on `--session-id` (create) and lets only later turns /
|
|
506
|
+
* reconnects use `--resume`. Self-healing: a deleted transcript also correctly falls back to create.
|
|
507
|
+
*/
|
|
508
|
+
export function resolveTuiResume(requestedResume, jsonlPath, exists = existsSync) {
|
|
509
|
+
return requestedResume && exists(jsonlPath);
|
|
510
|
+
}
|
|
495
511
|
/**
|
|
496
512
|
* Convenience factory: real JsonlTail wired to the path. Used by production code; tests inject
|
|
497
513
|
* a custom factory instead.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Capability } from '../capabilities.js';
|
|
2
|
-
import type { AgentAdapter, AgentSpawnConfig, AgentProcess, Backend, ContinuationSink } from '../types.js';
|
|
2
|
+
import type { AgentAdapter, AgentCompactResult, AgentSpawnConfig, AgentProcess, Backend, UserMessage, ContinuationSink, InjectionAckSink } from '../types.js';
|
|
3
|
+
import type { ContextUsage } from '../../core/types/agent-types.js';
|
|
3
4
|
import { CancelledError } from './defaults.js';
|
|
4
5
|
import { CortexAgentContext } from './spawn-args.js';
|
|
5
6
|
import { type TmuxExec } from './tmux-control.js';
|
|
@@ -21,10 +22,18 @@ interface ClaudeSessionOptions {
|
|
|
21
22
|
extraEnv?: Record<string, string>;
|
|
22
23
|
/** Extra CLI options from profile (e.g. {"--thinking": "xhigh"}). */
|
|
23
24
|
extraOption?: Record<string, string>;
|
|
25
|
+
/** Thinking level from the profile's `thinking` field → `--effort <level>`. Absent → no flag. */
|
|
26
|
+
thinking?: string | null;
|
|
24
27
|
/** Cortex execution context surfaced to the MCP server child as CORTEX_THREAD_ID/PROFILE/PROJECT/SESSION_NAME env vars.
|
|
25
28
|
* Captured at spawn time; later turns on the same session reuse the original snapshot. */
|
|
26
29
|
context?: CortexAgentContext;
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Extract the prompt text from a `--replay-user-messages` echo. `message.content` arrives either
|
|
33
|
+
* as a bare string or as text blocks. Returns null for anything else — notably the tool_result
|
|
34
|
+
* carriers print mode already emits as `user` lines, which must never be read as a prompt echo.
|
|
35
|
+
*/
|
|
36
|
+
export declare function extractReplayText(data: any): string | null;
|
|
28
37
|
declare class ClaudeSession {
|
|
29
38
|
private proc;
|
|
30
39
|
private rl;
|
|
@@ -45,12 +54,28 @@ declare class ClaudeSession {
|
|
|
45
54
|
private anthropicBaseUrl;
|
|
46
55
|
private extraEnv;
|
|
47
56
|
private extraOption;
|
|
57
|
+
private thinking;
|
|
48
58
|
private context;
|
|
49
59
|
private currentTurn;
|
|
60
|
+
/** Cursor over the `stream_event` sequence (--include-partial-messages). Session-scoped rather
|
|
61
|
+
* than turn-scoped because the stream is a property of the process, and every `message_start`
|
|
62
|
+
* resets it anyway. */
|
|
63
|
+
private streamDeltaState;
|
|
64
|
+
/** Current provider-call usage plus configured/result-reconciled context window. */
|
|
65
|
+
private contextUsageTracker;
|
|
50
66
|
/** Tracks in-flight background tasks (run_in_background) for this session. */
|
|
51
67
|
private bgTracker;
|
|
52
68
|
/** Set by orchestration to receive spontaneous background-task continuation turns. */
|
|
53
69
|
private continuationSink;
|
|
70
|
+
/** Messages injected into an in-flight turn that the CLI has not echoed back yet, in write
|
|
71
|
+
* order. Each is popped by its `--replay-user-messages` echo (the delivery ack). */
|
|
72
|
+
private pendingInjections;
|
|
73
|
+
/** Set by orchestration to receive injection delivery acks. */
|
|
74
|
+
private injectionAck;
|
|
75
|
+
/** Set when an injected message was consumed with NO turn in flight — the CLI is about to start
|
|
76
|
+
* a turn of its own for it. Consumed by the next assistant line, which opens the
|
|
77
|
+
* synthetic turn that captures the reply. */
|
|
78
|
+
private injectionContinuationArmed;
|
|
54
79
|
private alive;
|
|
55
80
|
private needsResume;
|
|
56
81
|
private idleTimer;
|
|
@@ -70,6 +95,10 @@ declare class ClaudeSession {
|
|
|
70
95
|
constructor(channel: string, sessionId: string, options: ClaudeSessionOptions);
|
|
71
96
|
private toSpawnOptions;
|
|
72
97
|
private handleProcessClose;
|
|
98
|
+
/** Deliver a synthetic interrupted result to the continuation sink (single-fire: the sink
|
|
99
|
+
* reference is cleared before invoking). Fires only when background work may still produce
|
|
100
|
+
* a continuation (or `force`, for a dying spontaneous turn); otherwise just clears the sink. */
|
|
101
|
+
private notifyBgInterrupted;
|
|
73
102
|
private spawnProcess;
|
|
74
103
|
private createTurnStreams;
|
|
75
104
|
private registerTurn;
|
|
@@ -77,6 +106,33 @@ declare class ClaudeSession {
|
|
|
77
106
|
* as the pooled session, until close()/kill(). */
|
|
78
107
|
setContinuationSink(sink: ContinuationSink): void;
|
|
79
108
|
clearContinuationSink(): void;
|
|
109
|
+
/** Register/replace the injection delivery-ack sink. Lifetime mirrors continuationSink. */
|
|
110
|
+
setInjectionAckSink(sink: InjectionAckSink): void;
|
|
111
|
+
clearInjectionAckSink(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Deliver a user message into the turn already in flight.
|
|
114
|
+
*
|
|
115
|
+
* Writes the SAME NDJSON user line a normal turn writes, but registers NO turn: the message is
|
|
116
|
+
* absorbed by the run already in progress, so the already-awaited turn promise covers it and no
|
|
117
|
+
* second result is fabricated. Cost/turn accounting stays with the running turn.
|
|
118
|
+
*
|
|
119
|
+
* Where it lands is a race the caller cannot control, so both outcomes are wired here:
|
|
120
|
+
* - tool-result boundary → folds into the running turn, ONE result. Nothing extra
|
|
121
|
+
* to do; the turn's own callbacks carry the reply.
|
|
122
|
+
* - mid-text-generation → the CLI drains its queue only after this turn's result and then
|
|
123
|
+
* starts a turn of its own. The echo handler arms the existing spontaneous-turn
|
|
124
|
+
* path so that reply is captured by continuationSink instead of dropped.
|
|
125
|
+
*
|
|
126
|
+
* Returns false when there is no live process or no active turn — the caller then falls back to
|
|
127
|
+
* the normal queue.
|
|
128
|
+
*/
|
|
129
|
+
injectUserMessage(message: UserMessage): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Handle a `--replay-user-messages` echo. The CLI echoes EVERY user message, so most echoes are
|
|
132
|
+
* the turn's own opening prompt and must be ignored; only an echo matching the head of the
|
|
133
|
+
* pending-injection queue is a delivery ack. Nothing else in the system reads these events.
|
|
134
|
+
*/
|
|
135
|
+
private handleReplayEcho;
|
|
80
136
|
/** Open a synthetic turn to capture the spontaneous continuation the CLI emits after a
|
|
81
137
|
* background task finishes. Its assistant text / result are routed to continuationSink
|
|
82
138
|
* (not to a send() promise — there is no caller awaiting it). */
|
|
@@ -89,16 +145,25 @@ declare class ClaudeSession {
|
|
|
89
145
|
scheduleTaskId?: string | null;
|
|
90
146
|
isUserInitiated?: boolean;
|
|
91
147
|
onProgress?: ((progress: any) => void) | null;
|
|
92
|
-
onAssistantMessage?: ((text: string) => void) | null;
|
|
93
|
-
|
|
148
|
+
onAssistantMessage?: ((text: string, blockId?: string) => void) | null;
|
|
149
|
+
onAssistantDelta?: ((text: string, blockId: string) => void) | null;
|
|
150
|
+
onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
|
|
151
|
+
onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
|
|
94
152
|
onCompact?: ((info: {
|
|
95
153
|
trigger: string;
|
|
96
154
|
preTokens?: number;
|
|
97
155
|
}) => void) | null;
|
|
156
|
+
onContextUsage?: ((usage: ContextUsage) => void) | null;
|
|
98
157
|
}): Promise<any>;
|
|
158
|
+
/** Invoke Claude Code's local slash handler without recording a Cortex user turn. */
|
|
159
|
+
compact(): Promise<AgentCompactResult>;
|
|
160
|
+
private compactUsage;
|
|
99
161
|
private bumpTurnIdleTimer;
|
|
100
162
|
private handleResultEvent;
|
|
163
|
+
/** Preserve the complete result carrier that print mode emits as a `user` content block. */
|
|
164
|
+
private handleToolResultEvent;
|
|
101
165
|
private handleAssistantEvent;
|
|
166
|
+
private emitContextUsage;
|
|
102
167
|
private handleLine;
|
|
103
168
|
private closeTurnLogs;
|
|
104
169
|
private resetIdleTimer;
|
|
@@ -107,6 +172,11 @@ declare class ClaudeSession {
|
|
|
107
172
|
isAlive(): boolean;
|
|
108
173
|
}
|
|
109
174
|
export declare function closeSession(channel: string, sessionKey?: string): void;
|
|
175
|
+
/** Hard-stop the pooled session for a channel (SIGTERM, same path the foreground Stop takes via
|
|
176
|
+
* handle.kill()). Unlike closeSession's graceful stdin-end + 30s grace, this ends the process now
|
|
177
|
+
* — used by the Stop path to actually kill background tasks still running inside it after the
|
|
178
|
+
* foreground turn ended. Returns false when no live session exists for the key. */
|
|
179
|
+
export declare function killSession(channel: string, sessionKey?: string): boolean;
|
|
110
180
|
/** Close all sessions whose key starts with the given prefix (used by Thread cleanup). */
|
|
111
181
|
export declare function closeSessionsByPrefix(prefix: string): void;
|
|
112
182
|
export declare function closeAllSessions(): void;
|
|
@@ -120,7 +190,8 @@ export interface RunClaudeOptions {
|
|
|
120
190
|
isUserInitiated?: boolean;
|
|
121
191
|
onProgress?: any;
|
|
122
192
|
onAssistantMessage?: any;
|
|
123
|
-
onToolUse?: ((name: string, input: any) => void) | null;
|
|
193
|
+
onToolUse?: ((name: string, input: any, toolUseId: string) => void) | null;
|
|
194
|
+
onToolResult?: ((toolUseId: string, content: string, isError: boolean) => void) | null;
|
|
124
195
|
sessionKey?: string | null;
|
|
125
196
|
claudeAgent?: string | null;
|
|
126
197
|
systemPrompt?: string | null;
|
|
@@ -129,6 +200,19 @@ export interface RunClaudeOptions {
|
|
|
129
200
|
pluginDirs?: string[] | null;
|
|
130
201
|
anthropicBaseUrl?: string;
|
|
131
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Decide whether a print-mode ClaudeSession should spawn with `--resume <id>`.
|
|
205
|
+
*
|
|
206
|
+
* Print sessions always run with `cwd: DATA_DIR`, so their Claude transcript lives at
|
|
207
|
+
* `computeJsonlPath(DATA_DIR, sessionId)`. A *fresh* session (notably the `cortex tui`
|
|
208
|
+
* frontend) pre-registers its sessionId BEFORE the first Claude turn, so callers ask to
|
|
209
|
+
* resume an id that has no transcript yet — Claude then exits with
|
|
210
|
+
* "No conversation found with session ID: <id>". Gating the resume request on the
|
|
211
|
+
* transcript actually existing keeps the first turn on `--session-id` (create) and lets
|
|
212
|
+
* only later turns / reconnects use `--resume`. Self-healing: a deleted transcript also
|
|
213
|
+
* correctly falls back to create. Mirrors {@link resolveTuiResume} for the tmux path.
|
|
214
|
+
*/
|
|
215
|
+
export declare function resolveResumeForPrint(requestedResume: boolean, sessionId: string, exists?: (p: string) => boolean): boolean;
|
|
132
216
|
export declare function runClaude(userMessage: string, opts: RunClaudeOptions): {
|
|
133
217
|
promise: Promise<any>;
|
|
134
218
|
kill(): boolean;
|
|
@@ -183,7 +267,7 @@ export declare function recoverTuiOrphans(exec?: TmuxExec): {
|
|
|
183
267
|
* testing handleLine / continuation routing. Initializes only the fields the line
|
|
184
268
|
* handlers touch. Callers should stub createTurnStreams to avoid log file I/O and
|
|
185
269
|
* register cleanup via t.after(() => session.close()) to clear the idle timer. */
|
|
186
|
-
declare function makeSessionForTest(): ClaudeSession;
|
|
270
|
+
declare function makeSessionForTest(modelName?: string | null, autoCompactWindow?: number | null): ClaudeSession;
|
|
187
271
|
export declare const _test: {
|
|
188
272
|
extractAskUserQuestions: typeof extractAskUserQuestions;
|
|
189
273
|
mergeSubstantialOutput: typeof mergeSubstantialOutput;
|