@cortex-agent/server 2026.6.24 → 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/gitignore +3 -0
- package/defaults/hooks/CORTEX.md +18 -0
- package/defaults/hooks/cortex-hook-api.mjs +84 -0
- package/defaults/hooks/cortex-md-injector.mjs +99 -49
- package/defaults/hooks/session-activity-tracker.mjs +8 -101
- package/defaults/hooks/task-status-check.mjs +10 -11
- 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-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.md +7 -31
- 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 +2 -0
- package/dist/agent-adapter/claude/adapter-tui.js +1 -0
- package/dist/agent-adapter/claude/adapter.d.ts +89 -5
- package/dist/agent-adapter/claude/adapter.js +404 -38
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +22 -15
- package/dist/agent-adapter/claude/bg-task-tracker.js +48 -32
- 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 +5 -10
- 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 +24 -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/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/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 +87 -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 +61 -10
- package/dist/domain/agents/facade.js +309 -61
- 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 +3 -8
- package/dist/domain/mcp/feishu-server.d.ts +0 -1
- package/dist/domain/mcp/feishu-server.js +4 -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/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.js +4 -3
- 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 +39 -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 +7 -14
- package/dist/domain/sessions/session-hooks.js +66 -112
- 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.js +4 -7
- 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 +30 -3
- package/dist/domain/tasks/system/task-completion.js +148 -42
- package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -0
- 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 +7 -0
- package/dist/domain/threads/prompt-builder.js +30 -13
- package/dist/domain/threads/runner.d.ts +19 -5
- package/dist/domain/threads/runner.js +211 -78
- 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 +281 -34
- 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/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/cortex-hook-api.mjs +84 -0
- package/dist/hooks/cortex-md-injector.mjs +99 -49
- package/dist/hooks/session-activity-tracker.mjs +8 -101
- package/dist/hooks/task-status-check.mjs +10 -11
- 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 +365 -53
- 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 +70 -15
- 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 +8 -3
- package/dist/orchestration/lifecycle.js +143 -62
- package/dist/orchestration/manager-qa.d.ts +12 -2
- package/dist/orchestration/manager-qa.js +34 -33
- 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 +21 -4
- package/dist/orchestration/resume-dispatcher.js +67 -37
- 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 -7
- package/dist/orchestration/thread-callback.js +300 -49
- 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/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 +2 -0
- package/dist/store/version-migrations.js +186 -9
- package/dist/tui/App.js +208 -20
- package/dist/tui/components/Dashboard.d.ts +3 -1
- package/dist/tui/components/Dashboard.js +5 -1
- 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 +237 -21
- 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 -600
- 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/block-types.d.ts +0 -44
- package/dist/domain/mcp/feishu/block-types.js +0 -127
- 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
package/dist/tui/logic.js
CHANGED
|
@@ -2,6 +2,51 @@
|
|
|
2
2
|
// output: Pure UI logic helpers for the M5 Ink client — focus zone, response-frame
|
|
3
3
|
// detection, stream-text collection, visible-window computation
|
|
4
4
|
// pos: Testable logic extracted out of React components/hooks
|
|
5
|
+
import stringWidth from 'string-width';
|
|
6
|
+
// ── Display-width helpers (CJK / full-width aware) ──
|
|
7
|
+
// Terminal columns are display CELLS, but JS strings are code units: a CJK char is 1 char / 2
|
|
8
|
+
// cells. Every layout step (wrap, pad, mouse-selection mapping) must measure in display columns,
|
|
9
|
+
// or Chinese/full-width text drifts (wrong wrap point, phantom grey row, mis-aligned selection).
|
|
10
|
+
/** Display width (terminal columns) of a string — CJK/full-width chars count as 2. */
|
|
11
|
+
export function displayWidth(s) {
|
|
12
|
+
return stringWidth(s);
|
|
13
|
+
}
|
|
14
|
+
/** Pad a string with spaces up to `width` DISPLAY columns (no-op if already ≥ width). */
|
|
15
|
+
export function padToWidth(s, width) {
|
|
16
|
+
const w = stringWidth(s);
|
|
17
|
+
return w >= width ? s : s + ' '.repeat(width - w);
|
|
18
|
+
}
|
|
19
|
+
/** Take the longest prefix of `s` fitting within `width` display columns; return [head, rest]. */
|
|
20
|
+
function sliceHeadToWidth(s, width) {
|
|
21
|
+
const chars = [...s]; // iterate by code point so surrogate pairs stay intact
|
|
22
|
+
let col = 0;
|
|
23
|
+
let i = 0;
|
|
24
|
+
for (; i < chars.length; i++) {
|
|
25
|
+
const cw = stringWidth(chars[i]);
|
|
26
|
+
if (col + cw > width)
|
|
27
|
+
break;
|
|
28
|
+
col += cw;
|
|
29
|
+
}
|
|
30
|
+
return [chars.slice(0, i).join(''), chars.slice(i).join('')];
|
|
31
|
+
}
|
|
32
|
+
/** Split a line into before/selected/after by DISPLAY-column range [startCol, endCol). Each char
|
|
33
|
+
* is classified by its starting column (a wide char straddling a boundary goes with its start). */
|
|
34
|
+
export function splitByDisplayCols(text, startCol, endCol) {
|
|
35
|
+
let col = 0;
|
|
36
|
+
let before = '';
|
|
37
|
+
let selected = '';
|
|
38
|
+
let after = '';
|
|
39
|
+
for (const ch of [...text]) {
|
|
40
|
+
if (col < startCol)
|
|
41
|
+
before += ch;
|
|
42
|
+
else if (col < endCol)
|
|
43
|
+
selected += ch;
|
|
44
|
+
else
|
|
45
|
+
after += ch;
|
|
46
|
+
col += stringWidth(ch);
|
|
47
|
+
}
|
|
48
|
+
return { before, selected, after };
|
|
49
|
+
}
|
|
5
50
|
export function computeFocusZone(opts) {
|
|
6
51
|
if (opts.modalOpen)
|
|
7
52
|
return 'modal';
|
|
@@ -25,15 +70,15 @@ const AGENT_RESPONSE_TYPES = new Set([
|
|
|
25
70
|
export function isAgentResponseFrame(frame) {
|
|
26
71
|
return AGENT_RESPONSE_TYPES.has(frame.type);
|
|
27
72
|
}
|
|
73
|
+
/** Join a message's stream blocks into display text — one block per line, in order, so distinct
|
|
74
|
+
* assistant messages and interleaved tool traces appear as separate lines (not one merged blob). */
|
|
28
75
|
export function collectStreamText(streams) {
|
|
29
|
-
|
|
76
|
+
const parts = [];
|
|
30
77
|
for (const [, stream] of streams) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
out += regionText;
|
|
34
|
-
}
|
|
78
|
+
for (const b of stream.blocks)
|
|
79
|
+
parts.push(b.text);
|
|
35
80
|
}
|
|
36
|
-
return
|
|
81
|
+
return parts.join('\n');
|
|
37
82
|
}
|
|
38
83
|
// ── Visible window ──
|
|
39
84
|
// Bottom-anchored viewport over the transcript id list. scrollOffset counts
|
|
@@ -47,3 +92,363 @@ export function computeVisibleWindow(idsLength, visibleCount, scrollOffset) {
|
|
|
47
92
|
const start = Math.max(0, end - Math.max(1, visibleCount));
|
|
48
93
|
return { start, end };
|
|
49
94
|
}
|
|
95
|
+
// ── Line-aware transcript window ──
|
|
96
|
+
// The transcript holds variable-height messages (a replayed history can have long,
|
|
97
|
+
// multi-line entries). A message-count window overflows the terminal — Ink can't clear
|
|
98
|
+
// rows that scrolled off, so borders/text garble. Estimate each message's rendered line
|
|
99
|
+
// count and pick, from the bottom up, as many as fit the line budget.
|
|
100
|
+
/** Estimate how many terminal rows a block of text occupies at the given width. */
|
|
101
|
+
export function estimateLines(text, width) {
|
|
102
|
+
if (!text)
|
|
103
|
+
return 0;
|
|
104
|
+
const w = Math.max(1, width);
|
|
105
|
+
let lines = 0;
|
|
106
|
+
for (const line of text.split('\n')) {
|
|
107
|
+
lines += Math.max(1, Math.ceil(line.length / w));
|
|
108
|
+
}
|
|
109
|
+
return lines;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Bottom-anchored window over variable-height rows. `lineCounts[i]` is the estimated
|
|
113
|
+
* height of row i. Returns absolute [start, end) including as many rows from the bottom
|
|
114
|
+
* (offset by `scrollOffset` rows) as fit `budget` lines — always at least one row.
|
|
115
|
+
*/
|
|
116
|
+
export function computeLineWindow(lineCounts, budget, scrollOffset = 0) {
|
|
117
|
+
const n = lineCounts.length;
|
|
118
|
+
if (n === 0)
|
|
119
|
+
return { start: 0, end: 0 };
|
|
120
|
+
const maxOffset = Math.max(0, n - 1);
|
|
121
|
+
const off = Math.min(Math.max(0, scrollOffset), maxOffset);
|
|
122
|
+
const end = n - off;
|
|
123
|
+
const cap = Math.max(1, budget);
|
|
124
|
+
let used = 0;
|
|
125
|
+
let start = end; // exclusive lower bound walked downward
|
|
126
|
+
for (let i = end - 1; i >= 0; i--) {
|
|
127
|
+
const h = Math.max(1, lineCounts[i]);
|
|
128
|
+
if (used + h > cap && start < end)
|
|
129
|
+
break; // would overflow, and we already have ≥1 row
|
|
130
|
+
used += h;
|
|
131
|
+
start = i;
|
|
132
|
+
}
|
|
133
|
+
return { start, end };
|
|
134
|
+
}
|
|
135
|
+
// ── Focus-centered window ──
|
|
136
|
+
// A bounded viewport over a navigable list that always keeps the focused row visible.
|
|
137
|
+
// Dashboard tabs render every item by default, so a long list (schedules / executions)
|
|
138
|
+
// overflows the terminal — and Ink cannot clear lines that scrolled past the top, leaving
|
|
139
|
+
// permanent ghost rows. Capping the rendered slice fixes both the overflow and the
|
|
140
|
+
// corruption. Returns absolute [start, end) indices plus how many rows are hidden on each
|
|
141
|
+
// side (for "↑ N more" / "↓ N more" affordances).
|
|
142
|
+
export function computeFocusWindow(total, focusedIndex, maxVisible) {
|
|
143
|
+
if (total <= 0)
|
|
144
|
+
return { start: 0, end: 0, hiddenAbove: 0, hiddenBelow: 0 };
|
|
145
|
+
const cap = Math.max(1, maxVisible);
|
|
146
|
+
if (total <= cap)
|
|
147
|
+
return { start: 0, end: total, hiddenAbove: 0, hiddenBelow: 0 };
|
|
148
|
+
const focus = Math.min(Math.max(0, focusedIndex), total - 1);
|
|
149
|
+
// Center the focused row in the window, then clamp to the list bounds.
|
|
150
|
+
let start = focus - Math.floor(cap / 2);
|
|
151
|
+
start = Math.max(0, Math.min(start, total - cap));
|
|
152
|
+
const end = start + cap;
|
|
153
|
+
return { start, end, hiddenAbove: start, hiddenBelow: total - end };
|
|
154
|
+
}
|
|
155
|
+
/** Step to an OLDER history entry (Up arrow). Returns the value to show + the next state. */
|
|
156
|
+
export function historyPrev(history, state, current) {
|
|
157
|
+
if (history.length === 0)
|
|
158
|
+
return { value: current, state };
|
|
159
|
+
if (state.index === null) {
|
|
160
|
+
const index = history.length - 1;
|
|
161
|
+
return { value: history[index], state: { index, draft: current } };
|
|
162
|
+
}
|
|
163
|
+
const index = Math.max(0, state.index - 1);
|
|
164
|
+
return { value: history[index], state: { index, draft: state.draft } };
|
|
165
|
+
}
|
|
166
|
+
/** Step to a NEWER history entry (Down arrow). Past the newest entry, restores the draft. */
|
|
167
|
+
export function historyNext(history, state, current) {
|
|
168
|
+
if (state.index === null)
|
|
169
|
+
return { value: current, state };
|
|
170
|
+
if (state.index >= history.length - 1) {
|
|
171
|
+
return { value: state.draft, state: { index: null, draft: '' } };
|
|
172
|
+
}
|
|
173
|
+
const index = state.index + 1;
|
|
174
|
+
return { value: history[index], state: { index, draft: state.draft } };
|
|
175
|
+
}
|
|
176
|
+
/** Append a submitted entry to history, collapsing consecutive duplicates. */
|
|
177
|
+
export function pushHistory(history, entry) {
|
|
178
|
+
if (entry.trim().length === 0)
|
|
179
|
+
return history;
|
|
180
|
+
if (history[history.length - 1] === entry)
|
|
181
|
+
return history;
|
|
182
|
+
return [...history, entry];
|
|
183
|
+
}
|
|
184
|
+
// ── /resume target resolution ──
|
|
185
|
+
// `/resume <id>` lets the user jump straight to a session without the picker. The arg may be
|
|
186
|
+
// an internal sessionId, a short name (cortex-XXXX), the bare suffix (8cdfbe), or a unique
|
|
187
|
+
// sessionId prefix. Resolve it against the known session list to the internal sessionId.
|
|
188
|
+
export function matchResumeTarget(sessions, target) {
|
|
189
|
+
const t = target.trim();
|
|
190
|
+
if (!t)
|
|
191
|
+
return null;
|
|
192
|
+
const byId = sessions.find(s => s.sessionId === t);
|
|
193
|
+
if (byId)
|
|
194
|
+
return byId.sessionId;
|
|
195
|
+
const byName = sessions.find(s => s.name === t);
|
|
196
|
+
if (byName)
|
|
197
|
+
return byName.sessionId;
|
|
198
|
+
const bySuffix = sessions.find(s => s.name && (s.name.endsWith(t) || s.name.replace(/^cortex-/, '') === t));
|
|
199
|
+
if (bySuffix)
|
|
200
|
+
return bySuffix.sessionId;
|
|
201
|
+
const byIdPrefix = sessions.find(s => s.sessionId.startsWith(t));
|
|
202
|
+
return byIdPrefix ? byIdPrefix.sessionId : null;
|
|
203
|
+
}
|
|
204
|
+
// ── Mouse-sequence guard ──
|
|
205
|
+
// With SGR mouse tracking enabled (for wheel scrolling), Ink still forwards the raw escape
|
|
206
|
+
// residue (e.g. "[<64;30;10M" after it strips the leading ESC) to useInput as printable text.
|
|
207
|
+
// This predicate lets the input box drop that residue so it never lands in the message buffer.
|
|
208
|
+
export function isMouseSequence(input) {
|
|
209
|
+
if (!input)
|
|
210
|
+
return false;
|
|
211
|
+
// eslint-disable-next-line no-control-regex
|
|
212
|
+
if (/\x1b/.test(input))
|
|
213
|
+
return true;
|
|
214
|
+
return /\[?<\d+;\d+;\d+[Mm]/.test(input);
|
|
215
|
+
}
|
|
216
|
+
// ── Multi-line cursor geometry ──
|
|
217
|
+
// The input box holds a single string that may contain '\n' (multi-line entry). The cursor is a
|
|
218
|
+
// flat character index; these pure helpers map it to a (row, col) grid and back so vertical
|
|
219
|
+
// arrow navigation can move between wrapped logical lines.
|
|
220
|
+
/** Map a flat cursor index to its zero-based (row, col) within a newline-delimited value. */
|
|
221
|
+
export function cursorToRowCol(value, cursor) {
|
|
222
|
+
const c = Math.max(0, Math.min(cursor, value.length));
|
|
223
|
+
const before = value.slice(0, c);
|
|
224
|
+
const lastNl = before.lastIndexOf('\n');
|
|
225
|
+
const row = before.length === 0 ? 0 : (before.match(/\n/g)?.length ?? 0);
|
|
226
|
+
const col = c - (lastNl + 1);
|
|
227
|
+
return { row, col };
|
|
228
|
+
}
|
|
229
|
+
/** Map a (row, col) back to a flat cursor index, clamping row to the line count and col to that line. */
|
|
230
|
+
export function rowColToCursor(value, row, col) {
|
|
231
|
+
const lines = value.split('\n');
|
|
232
|
+
const r = Math.max(0, Math.min(row, lines.length - 1));
|
|
233
|
+
const c = Math.max(0, Math.min(col, lines[r].length));
|
|
234
|
+
let idx = 0;
|
|
235
|
+
for (let i = 0; i < r; i++)
|
|
236
|
+
idx += lines[i].length + 1;
|
|
237
|
+
return idx + c;
|
|
238
|
+
}
|
|
239
|
+
/** Move the cursor one logical line up (dir -1) or down (dir +1), preserving the column. */
|
|
240
|
+
export function moveCursorVertical(value, cursor, dir) {
|
|
241
|
+
const { row, col } = cursorToRowCol(value, cursor);
|
|
242
|
+
return rowColToCursor(value, row + dir, col);
|
|
243
|
+
}
|
|
244
|
+
// ── Paste sanitization ──
|
|
245
|
+
// With bracketed-paste mode on (?2004h, enabled in index.tsx) a paste arrives wrapped in
|
|
246
|
+
// ESC[200~ … ESC[201~. These helpers strip the markers and any escape residue and normalize
|
|
247
|
+
// line endings so multi-line pastes insert literally instead of submitting per Enter.
|
|
248
|
+
/** Remove bracketed-paste begin/end markers — both ESC[200~/ESC[201~ and the BARE [200~/[201~
|
|
249
|
+
* form (Ink consumes the leading ESC and forwards the remainder as text, so the markers arrive
|
|
250
|
+
* without their escape and otherwise leak into the buffer). */
|
|
251
|
+
export function stripPasteMarkers(s) {
|
|
252
|
+
// eslint-disable-next-line no-control-regex
|
|
253
|
+
return s.replace(/(?:\x1b)?\[20[01]~/g, '');
|
|
254
|
+
}
|
|
255
|
+
/** Collapse CRLF and bare CR to LF so pasted line endings are uniform. */
|
|
256
|
+
export function normalizeNewlines(s) {
|
|
257
|
+
return s.replace(/\r\n?/g, '\n');
|
|
258
|
+
}
|
|
259
|
+
/** Clean a pasted chunk for literal insertion: drop paste markers + escape sequences, normalize newlines. */
|
|
260
|
+
export function sanitizePastedText(s) {
|
|
261
|
+
let t = stripPasteMarkers(s);
|
|
262
|
+
// Strip CSI / SGR / mouse escape sequences (cursor reports etc.) but keep printable text + newlines.
|
|
263
|
+
// eslint-disable-next-line no-control-regex
|
|
264
|
+
t = t.replace(/\x1b\[[0-9;?<>]*[ -/]*[@-~]/g, '');
|
|
265
|
+
// eslint-disable-next-line no-control-regex
|
|
266
|
+
t = t.replace(/\x1b[@-_]?/g, '');
|
|
267
|
+
return normalizeNewlines(t);
|
|
268
|
+
}
|
|
269
|
+
// ── Backspace vs forward-Delete classification ──
|
|
270
|
+
// Ink's keypress parser maps BOTH the Backspace key (\x7f) and the forward-Delete key (\x1b[3~)
|
|
271
|
+
// to `key.delete` with an empty `input`, so they're indistinguishable in useInput. The raw stdin
|
|
272
|
+
// chunk is the only way to tell them apart — this classifier inspects it so the input box can
|
|
273
|
+
// delete the char BEFORE the cursor (backspace) vs AFTER it (forward delete).
|
|
274
|
+
export function classifyDeleteChunk(s) {
|
|
275
|
+
// Forward Delete key: ESC[3~ (optionally with a modifier, e.g. ESC[3;5~ for Ctrl+Delete).
|
|
276
|
+
// eslint-disable-next-line no-control-regex
|
|
277
|
+
if (s === '\x1b[3~' || /^\x1b\[3;\d+~$/.test(s))
|
|
278
|
+
return 'forward-delete';
|
|
279
|
+
// Backspace key: DEL (\x7f), BS (\x08), or Alt+Backspace (ESC + DEL).
|
|
280
|
+
if (s === '\x7f' || s === '\x08' || s === '\x1b\x7f')
|
|
281
|
+
return 'backspace';
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
/** Parse ALL SGR mouse events from a raw stdin chunk (press, release, drag, wheel). */
|
|
285
|
+
export function parseAllMouseEvents(chunk) {
|
|
286
|
+
const out = [];
|
|
287
|
+
// eslint-disable-next-line no-control-regex
|
|
288
|
+
const re = /\x1b\[<(\d+);(\d+);(\d+)([Mm])/g;
|
|
289
|
+
let m;
|
|
290
|
+
while ((m = re.exec(chunk)) !== null) {
|
|
291
|
+
const b = parseInt(m[1], 10);
|
|
292
|
+
const col = parseInt(m[2], 10) - 1; // 1-based → 0-based
|
|
293
|
+
const row = parseInt(m[3], 10) - 1;
|
|
294
|
+
const isRelease = m[4] === 'm';
|
|
295
|
+
if ((b & 0x40) !== 0) {
|
|
296
|
+
// Wheel event
|
|
297
|
+
out.push({ type: 'wheel', button: b, col, row });
|
|
298
|
+
}
|
|
299
|
+
else if (isRelease) {
|
|
300
|
+
out.push({ type: 'release', button: b & 0x03, col, row });
|
|
301
|
+
}
|
|
302
|
+
else if ((b & 0x20) !== 0) {
|
|
303
|
+
// Motion (drag) — button is in lower 2 bits
|
|
304
|
+
out.push({ type: 'drag', button: b & 0x03, col, row });
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
out.push({ type: 'press', button: b & 0x03, col, row });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return out;
|
|
311
|
+
}
|
|
312
|
+
/** Normalize a selection so start is always before end (top-left to bottom-right). */
|
|
313
|
+
export function normalizeSelection(startLine, startCol, endLine, endCol) {
|
|
314
|
+
if (startLine > endLine || (startLine === endLine && startCol > endCol)) {
|
|
315
|
+
return { startLine: endLine, startCol: endCol, endLine: startLine, endCol: startCol };
|
|
316
|
+
}
|
|
317
|
+
return { startLine, startCol, endLine, endCol };
|
|
318
|
+
}
|
|
319
|
+
/** Extract selected text from flat display lines given a normalized selection range. Columns are
|
|
320
|
+
* DISPLAY columns (from the mouse), so slicing is width-aware (CJK safe). */
|
|
321
|
+
export function extractSelectionText(lines, sel) {
|
|
322
|
+
if (sel.startLine < 0 || sel.startLine >= lines.length)
|
|
323
|
+
return '';
|
|
324
|
+
if (sel.startLine === sel.endLine) {
|
|
325
|
+
return splitByDisplayCols(lines[sel.startLine].text, sel.startCol, sel.endCol).selected;
|
|
326
|
+
}
|
|
327
|
+
const parts = [];
|
|
328
|
+
// First line: from startCol to end (use a huge endCol to take the remainder).
|
|
329
|
+
parts.push(splitByDisplayCols(lines[sel.startLine].text, sel.startCol, Number.MAX_SAFE_INTEGER).selected);
|
|
330
|
+
// Middle lines: full text
|
|
331
|
+
for (let i = sel.startLine + 1; i < Math.min(sel.endLine, lines.length); i++) {
|
|
332
|
+
parts.push(lines[i].text);
|
|
333
|
+
}
|
|
334
|
+
// Last line: from start to endCol
|
|
335
|
+
if (sel.endLine < lines.length) {
|
|
336
|
+
parts.push(splitByDisplayCols(lines[sel.endLine].text, 0, sel.endCol).selected);
|
|
337
|
+
}
|
|
338
|
+
return parts.join('\n');
|
|
339
|
+
}
|
|
340
|
+
/** Copy text to the system clipboard via the OSC 52 terminal escape (BEL terminator). */
|
|
341
|
+
export function osc52Copy(text) {
|
|
342
|
+
const b64 = Buffer.from(text).toString('base64');
|
|
343
|
+
try {
|
|
344
|
+
process.stdout.write(`\x1b]52;c;${b64}\x07`);
|
|
345
|
+
}
|
|
346
|
+
catch { /* best effort */ }
|
|
347
|
+
}
|
|
348
|
+
/** Parse SGR mouse wheel events from a raw stdin chunk. 64=up, 65=down (low bit = direction). */
|
|
349
|
+
export function parseWheelEvents(chunk) {
|
|
350
|
+
const out = [];
|
|
351
|
+
// eslint-disable-next-line no-control-regex
|
|
352
|
+
const re = /\x1b\[<(\d+);\d+;\d+[Mm]/g;
|
|
353
|
+
let m;
|
|
354
|
+
while ((m = re.exec(chunk)) !== null) {
|
|
355
|
+
const b = parseInt(m[1], 10);
|
|
356
|
+
if ((b & 0x40) !== 0)
|
|
357
|
+
out.push((b & 1) === 0 ? 'up' : 'down');
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
/** The prefix the server/echo uses to encode a user-role message in plain text. */
|
|
362
|
+
export const USER_PREFIX = '**You:** ';
|
|
363
|
+
/** Detect a user message (by the isUser flag OR the `**You:** ` prefix) and strip the prefix. */
|
|
364
|
+
export function detectUserMessage(text, isUserFlag) {
|
|
365
|
+
if (text.startsWith(USER_PREFIX))
|
|
366
|
+
return { text: text.slice(USER_PREFIX.length), user: true };
|
|
367
|
+
return { text, user: !!isUserFlag };
|
|
368
|
+
}
|
|
369
|
+
/** Word-wrap a single logical line to `width` DISPLAY columns, hard-splitting over-wide words.
|
|
370
|
+
* Measured in terminal columns (CJK aware) so Chinese/full-width text wraps where it actually
|
|
371
|
+
* reaches the edge — matching what the terminal renders, which the selection mapping relies on. */
|
|
372
|
+
export function wrapToWidth(text, width) {
|
|
373
|
+
const w = Math.max(1, width);
|
|
374
|
+
if (text.length === 0)
|
|
375
|
+
return [''];
|
|
376
|
+
const lines = [];
|
|
377
|
+
let cur = '';
|
|
378
|
+
let curW = 0;
|
|
379
|
+
for (const word of text.split(' ')) {
|
|
380
|
+
const wordW = stringWidth(word);
|
|
381
|
+
if (wordW > w) {
|
|
382
|
+
// A single word wider than the line: flush, then hard-split it by display width.
|
|
383
|
+
if (cur) {
|
|
384
|
+
lines.push(cur);
|
|
385
|
+
cur = '';
|
|
386
|
+
curW = 0;
|
|
387
|
+
}
|
|
388
|
+
let rest = word;
|
|
389
|
+
while (stringWidth(rest) > w) {
|
|
390
|
+
let [head, tail] = sliceHeadToWidth(rest, w);
|
|
391
|
+
if (head.length === 0) { // a lone char wider than w — force-take it so we make progress
|
|
392
|
+
const chars = [...rest];
|
|
393
|
+
head = chars[0];
|
|
394
|
+
tail = chars.slice(1).join('');
|
|
395
|
+
}
|
|
396
|
+
lines.push(head);
|
|
397
|
+
rest = tail;
|
|
398
|
+
}
|
|
399
|
+
cur = rest;
|
|
400
|
+
curW = stringWidth(rest);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
const sep = cur ? 1 : 0;
|
|
404
|
+
if (curW + sep + wordW > w) {
|
|
405
|
+
lines.push(cur);
|
|
406
|
+
cur = word;
|
|
407
|
+
curW = wordW;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
411
|
+
curW += sep + wordW;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (cur || lines.length === 0)
|
|
415
|
+
lines.push(cur);
|
|
416
|
+
return lines;
|
|
417
|
+
}
|
|
418
|
+
/** Flatten one message into wrapped display lines. */
|
|
419
|
+
export function flattenMessageLines(msg, cols) {
|
|
420
|
+
const out = [];
|
|
421
|
+
const isUser = !!msg.user;
|
|
422
|
+
const push = (text, dim, markdown, user = false) => {
|
|
423
|
+
for (const logical of text.split('\n')) {
|
|
424
|
+
for (const wrapped of wrapToWidth(logical, cols))
|
|
425
|
+
out.push({ text: wrapped, dim, markdown, user });
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const hasRich = !!(msg.richBlocks && msg.richBlocks.length > 0);
|
|
429
|
+
// Slack Block-Kit semantics: when richBlocks exist they ARE the content; `text` is only a
|
|
430
|
+
// fallback (rendering both double-prints the sealed status line).
|
|
431
|
+
if (msg.text && !hasRich)
|
|
432
|
+
push(msg.text, false, !isUser, isUser); // user lines render plain on grey
|
|
433
|
+
if (hasRich) {
|
|
434
|
+
for (const b of msg.richBlocks) {
|
|
435
|
+
if (b.text)
|
|
436
|
+
push(String(b.text), b.type === 'context', b.type !== 'context');
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (msg.streamText)
|
|
440
|
+
push(msg.streamText, true, true);
|
|
441
|
+
if (msg.queued)
|
|
442
|
+
out.push({ text: '⏳ queued', dim: true, markdown: false, user: false });
|
|
443
|
+
return out;
|
|
444
|
+
}
|
|
445
|
+
/** Flatten the whole transcript to display lines, with a blank separator between messages. */
|
|
446
|
+
export function flattenTranscript(messages, cols) {
|
|
447
|
+
const out = [];
|
|
448
|
+
messages.forEach((m, i) => {
|
|
449
|
+
if (i > 0)
|
|
450
|
+
out.push({ text: '', dim: false, markdown: false, user: false });
|
|
451
|
+
out.push(...flattenMessageLines(m, cols));
|
|
452
|
+
});
|
|
453
|
+
return out;
|
|
454
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Accumulates numeric deltas and applies their sum once per scheduled flush. */
|
|
2
|
+
export interface NumericBatcher {
|
|
3
|
+
/** Add a signed delta; schedules a flush if one is not already pending. */
|
|
4
|
+
add(delta: number): void;
|
|
5
|
+
/** Apply the accumulated sum immediately (if non-zero) and clear any pending flush. */
|
|
6
|
+
flushNow(): void;
|
|
7
|
+
/** Drop any accumulated delta and pending flush without applying. */
|
|
8
|
+
cancel(): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Coalesce numeric deltas. Multiple `add()` calls within one event-loop turn (e.g. several wheel
|
|
12
|
+
* notches in a single stdin chunk, or across chunks in the same tick) are summed and `apply`d once.
|
|
13
|
+
* `schedule`/`cancelSchedule` are injectable for testing; default is setImmediate (flushes after
|
|
14
|
+
* the current I/O callbacks, so a burst of stdin events collapses into one apply).
|
|
15
|
+
*/
|
|
16
|
+
export declare function createNumericBatcher(apply: (sum: number) => void, schedule?: (cb: () => void) => unknown, cancelSchedule?: (handle: unknown) => void): NumericBatcher;
|
|
17
|
+
/** A throttled function wrapper: leading call fires immediately, trailing call is deferred. */
|
|
18
|
+
export interface Throttled<A extends unknown[]> {
|
|
19
|
+
call(...args: A): void;
|
|
20
|
+
/** Cancel a pending trailing call. */
|
|
21
|
+
cancel(): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Leading + trailing throttle. The first call in an idle period runs immediately; subsequent calls
|
|
25
|
+
* within `intervalMs` are coalesced into a single trailing call fired at the end of the window with
|
|
26
|
+
* the latest arguments. Used to cap drag-selection re-renders at ~one per frame while still landing
|
|
27
|
+
* the final cursor position. `now`/`schedule`/`cancelSchedule` are injectable for tests.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createThrottle<A extends unknown[]>(fn: (...args: A) => void, intervalMs: number, deps?: {
|
|
30
|
+
now?: () => number;
|
|
31
|
+
schedule?: (cb: () => void, ms: number) => unknown;
|
|
32
|
+
cancelSchedule?: (handle: unknown) => void;
|
|
33
|
+
}): Throttled<A>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// input: high-frequency interaction deltas (mouse wheel) / state updates (drag selection)
|
|
2
|
+
// output: a numeric coalescer + a leading/trailing throttle
|
|
3
|
+
// pos: Stage 2 of the TUI render-perf plan — collapse event storms into fewer React updates
|
|
4
|
+
//
|
|
5
|
+
// Why: each mouse-wheel notch and each drag motion event currently triggers its own setState →
|
|
6
|
+
// full React reconciliation of the transcript (which re-flattens every message). Ink already
|
|
7
|
+
// throttles the PAINT to ~32ms, but the reconciliation work is not throttled, so a fast scroll or
|
|
8
|
+
// drag spends CPU re-flattening on every event and adds latency. Coalescing wheel notches into a
|
|
9
|
+
// single net scroll, and throttling drag-selection updates, cuts that reconciliation count.
|
|
10
|
+
/**
|
|
11
|
+
* Coalesce numeric deltas. Multiple `add()` calls within one event-loop turn (e.g. several wheel
|
|
12
|
+
* notches in a single stdin chunk, or across chunks in the same tick) are summed and `apply`d once.
|
|
13
|
+
* `schedule`/`cancelSchedule` are injectable for testing; default is setImmediate (flushes after
|
|
14
|
+
* the current I/O callbacks, so a burst of stdin events collapses into one apply).
|
|
15
|
+
*/
|
|
16
|
+
export function createNumericBatcher(apply, schedule = (cb) => setImmediate(cb), cancelSchedule = (h) => clearImmediate(h)) {
|
|
17
|
+
let sum = 0;
|
|
18
|
+
let handle = null;
|
|
19
|
+
const flush = () => {
|
|
20
|
+
handle = null;
|
|
21
|
+
if (sum !== 0) {
|
|
22
|
+
const s = sum;
|
|
23
|
+
sum = 0;
|
|
24
|
+
apply(s);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
add(delta) {
|
|
29
|
+
sum += delta;
|
|
30
|
+
if (handle === null)
|
|
31
|
+
handle = schedule(flush);
|
|
32
|
+
},
|
|
33
|
+
flushNow() {
|
|
34
|
+
if (handle !== null) {
|
|
35
|
+
cancelSchedule(handle);
|
|
36
|
+
handle = null;
|
|
37
|
+
}
|
|
38
|
+
if (sum !== 0) {
|
|
39
|
+
const s = sum;
|
|
40
|
+
sum = 0;
|
|
41
|
+
apply(s);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
cancel() {
|
|
45
|
+
if (handle !== null) {
|
|
46
|
+
cancelSchedule(handle);
|
|
47
|
+
handle = null;
|
|
48
|
+
}
|
|
49
|
+
sum = 0;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Leading + trailing throttle. The first call in an idle period runs immediately; subsequent calls
|
|
55
|
+
* within `intervalMs` are coalesced into a single trailing call fired at the end of the window with
|
|
56
|
+
* the latest arguments. Used to cap drag-selection re-renders at ~one per frame while still landing
|
|
57
|
+
* the final cursor position. `now`/`schedule`/`cancelSchedule` are injectable for tests.
|
|
58
|
+
*/
|
|
59
|
+
export function createThrottle(fn, intervalMs, deps = {}) {
|
|
60
|
+
const now = deps.now ?? Date.now;
|
|
61
|
+
const schedule = deps.schedule ?? ((cb, ms) => setTimeout(cb, ms));
|
|
62
|
+
const cancelSchedule = deps.cancelSchedule ?? ((h) => clearTimeout(h));
|
|
63
|
+
let lastRun = -Infinity;
|
|
64
|
+
let handle = null;
|
|
65
|
+
let pendingArgs = null;
|
|
66
|
+
const runTrailing = () => {
|
|
67
|
+
handle = null;
|
|
68
|
+
lastRun = now();
|
|
69
|
+
if (pendingArgs) {
|
|
70
|
+
const a = pendingArgs;
|
|
71
|
+
pendingArgs = null;
|
|
72
|
+
fn(...a);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
call(...args) {
|
|
77
|
+
const elapsed = now() - lastRun;
|
|
78
|
+
if (elapsed >= intervalMs) {
|
|
79
|
+
// Leading edge: run now, clear any stale trailing.
|
|
80
|
+
if (handle !== null) {
|
|
81
|
+
cancelSchedule(handle);
|
|
82
|
+
handle = null;
|
|
83
|
+
}
|
|
84
|
+
pendingArgs = null;
|
|
85
|
+
lastRun = now();
|
|
86
|
+
fn(...args);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Within the window: remember the latest args, schedule a single trailing run.
|
|
90
|
+
pendingArgs = args;
|
|
91
|
+
if (handle === null)
|
|
92
|
+
handle = schedule(runTrailing, intervalMs - elapsed);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
cancel() {
|
|
96
|
+
if (handle !== null) {
|
|
97
|
+
cancelSchedule(handle);
|
|
98
|
+
handle = null;
|
|
99
|
+
}
|
|
100
|
+
pendingArgs = null;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface InlineMarkdownProps {
|
|
3
|
+
text: string;
|
|
4
|
+
/** Dim the whole run (used for context/secondary lines). Inner styles still apply. */
|
|
5
|
+
dimColor?: boolean;
|
|
6
|
+
/** Optional display-column range [selStart, selEnd) to highlight with a blue background.
|
|
7
|
+
* Columns are measured in the RENDERED text (markers stripped), not the raw markdown source. */
|
|
8
|
+
selStart?: number;
|
|
9
|
+
selEnd?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Render inline markdown into an Ink <Text>. Multi-line text is preserved (parseMarkdown
|
|
13
|
+
* keeps newlines inside plain-text segments; bold/italic/code spans never cross a line).
|
|
14
|
+
* A string with no markers renders as a single plain run.
|
|
15
|
+
*
|
|
16
|
+
* When `selStart`/`selEnd` are provided, the display-column range [selStart, selEnd) is
|
|
17
|
+
* highlighted with a blue background. The columns are measured in the RENDERED text (markers
|
|
18
|
+
* stripped), so the split never exposes raw `**`/`*`/`` ` `` markers — each segment keeps its
|
|
19
|
+
* original styling on both sides of the boundary.
|
|
20
|
+
*/
|
|
21
|
+
export declare function InlineMarkdown({ text, dimColor, selStart, selEnd }: InlineMarkdownProps): React.JSX.Element;
|
|
22
|
+
export {};
|