@causyne/agent 1.20.121 → 1.20.124
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 +3 -3
- package/bin/causyne.js +38 -15
- package/docs/SECURITY_REVIEW.md +42 -6
- package/package.json +5 -5
- package/src/acp/agentCatalog.js +141 -62
- package/src/acp/agentCatalog.ts +142 -65
- package/src/acp/client.js +489 -109
- package/src/acp/client.ts +465 -108
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +181 -8
- package/src/acp/protocol.ts +189 -8
- package/src/acp/server.js +250 -53
- package/src/acp/server.ts +234 -53
- package/src/agent/errorClassifier.js +48 -8
- package/src/agent/errorClassifier.ts +50 -7
- package/src/agent/providerFailure.js +1 -1
- package/src/agent/providerFailure.ts +7 -1
- package/src/agent/toolArgValidator.js +38 -4
- package/src/agent/toolArgValidator.ts +39 -4
- package/src/agent/toolTurnIntegrity.js +28 -7
- package/src/agent/toolTurnIntegrity.ts +25 -6
- package/src/agent/workspaceBoundary.js +30 -4
- package/src/agent/workspaceBoundary.ts +32 -4
- package/src/agentLoop.js +609 -222
- package/src/agentLoop.ts +632 -220
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +76 -16
- package/src/approvalPolicy.ts +74 -16
- package/src/auditLog.js +641 -48
- package/src/auditLog.ts +661 -0
- package/src/autoUpdate.js +37 -7
- package/src/autoUpdate.ts +32 -7
- package/src/backgroundTasks.js +328 -0
- package/src/backgroundTasks.ts +339 -0
- package/src/benchmarks/codingEval.js +558 -0
- package/src/benchmarks/codingEval.ts +628 -0
- package/src/benchmarks/planCache.js +115 -134
- package/src/benchmarks/planCache.ts +163 -0
- package/src/browser/browserRuntime.js +52 -0
- package/src/browser/browserRuntime.ts +55 -0
- package/src/browser/causyneBrowser.js +887 -12
- package/src/browser/causyneBrowser.ts +1045 -34
- package/src/browser/searchProviders.js +95 -7
- package/src/browser/searchProviders.ts +90 -7
- package/src/browser/urlPolicy.js +8 -1
- package/src/browser/urlPolicy.ts +7 -1
- package/src/browser/workspacePathSafety.js +6 -4
- package/src/browser/workspacePathSafety.ts +7 -4
- package/src/capabilities.js +18 -17
- package/src/capabilities.ts +38 -0
- package/src/checkpoints.js +1241 -1127
- package/src/checkpoints.ts +1377 -0
- package/src/cliMode.js +707 -755
- package/src/cliMode.ts +780 -0
- package/src/codebase/repoMap.js +656 -0
- package/src/codebase/repoMap.ts +664 -0
- package/src/commands.js +3651 -2514
- package/src/commands.ts +3985 -0
- package/src/compiledSkills.js +8052 -8054
- package/src/compiledSkills.ts +8078 -0
- package/src/config.js +389 -250
- package/src/config.ts +451 -0
- package/src/configVault.js +113 -19
- package/src/configVault.ts +103 -19
- package/src/contextManager.js +473 -557
- package/src/contextManager.ts +599 -0
- package/src/continuum/adapters/antigravity.js +8 -3
- package/src/continuum/adapters/antigravity.ts +8 -3
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +33 -4
- package/src/continuum/sanitizer.ts +32 -4
- package/src/continuum/ui/continuumPicker.js +0 -2
- package/src/continuum/ui/continuumPicker.ts +0 -2
- package/src/continuum/ui/continuumPickerView.js +3 -4
- package/src/continuum/ui/continuumPickerView.ts +7 -22
- package/src/core/contextCompactor.js +88 -7
- package/src/core/contextCompactor.ts +87 -8
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +10 -7
- package/src/creative/liveBridge.ts +11 -7
- package/src/creative/studioScripts.js +17 -6
- package/src/creative/studioScripts.ts +15 -6
- package/src/decideTools.js +7 -2
- package/src/decideTools.ts +7 -2
- package/src/decisionPolicy.js +26 -6
- package/src/decisionPolicy.ts +24 -6
- package/src/designPalettes.js +72 -84
- package/src/designPalettes.ts +111 -0
- package/src/devMode.js +2 -2
- package/src/devMode.ts +6 -0
- package/src/diffReview.js +370 -0
- package/src/diffReview.ts +407 -0
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +311 -11
- package/src/dynamicCatalogue.ts +331 -11
- package/src/embodimentSession.js +143 -154
- package/src/embodimentSession.ts +173 -0
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/installer.js +60 -29
- package/src/engines/installer.ts +73 -22
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/enterprisePolicy.js +660 -0
- package/src/enterprisePolicy.ts +728 -0
- package/src/entrypoint.js +514 -268
- package/src/entrypoint.ts +607 -0
- package/src/gitSnapshot.js +417 -312
- package/src/gitSnapshot.ts +500 -0
- package/src/headlessCli.js +326 -14
- package/src/headlessCli.ts +323 -13
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +250 -26
- package/src/hooks.ts +239 -26
- package/src/ignoreRules.js +297 -0
- package/src/ignoreRules.ts +308 -0
- package/src/implementationPlan.js +28 -17
- package/src/implementationPlan.ts +29 -17
- package/src/infra/atomicWriter.js +96 -20
- package/src/infra/atomicWriter.ts +112 -20
- package/src/launchIntent.js +14 -3
- package/src/launchIntent.ts +14 -3
- package/src/licensing/entitlements.js +553 -237
- package/src/licensing/entitlements.ts +590 -0
- package/src/licensing/policy.js +17 -1
- package/src/licensing/policy.ts +31 -0
- package/src/lsp/lspCatalog.js +398 -0
- package/src/lsp/lspCatalog.ts +452 -0
- package/src/lsp/lspClient.js +699 -0
- package/src/lsp/lspClient.ts +799 -0
- package/src/lsp/lspProtocol.js +121 -0
- package/src/lsp/lspProtocol.ts +140 -0
- package/src/mcp/mcpClient.js +69 -8
- package/src/mcp/mcpClient.ts +66 -9
- package/src/mcp/mcpRegistry.js +180 -7
- package/src/mcp/mcpRegistry.ts +171 -7
- package/src/mcp/mcpSecurity.js +6 -7
- package/src/mcp/mcpSecurity.ts +7 -6
- package/src/memory/episodicStore.js +2 -5
- package/src/memory/episodicStore.ts +2 -5
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/memory.js +80 -32
- package/src/memory.ts +111 -0
- package/src/memoryManager.js +151 -143
- package/src/memoryManager.ts +182 -0
- package/src/modelCatalogue.js +172 -195
- package/src/modelCatalogue.ts +201 -0
- package/src/modelIds.js +8 -27
- package/src/modelIds.ts +33 -0
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/modelVariants.js +600 -0
- package/src/modelVariants.ts +663 -0
- package/src/observer/evidence.js +15 -5
- package/src/observer/evidence.ts +15 -5
- package/src/osKeychain.js +79 -17
- package/src/osKeychain.ts +64 -17
- package/src/outputStore.js +210 -156
- package/src/outputStore.ts +321 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +5 -8
- package/src/planCache.ts +5 -8
- package/src/plugins/pluginManager.js +689 -461
- package/src/plugins/pluginManager.ts +807 -0
- package/src/plugins/pluginRunner.js +82 -37
- package/src/plugins/pluginRunner.ts +98 -0
- package/src/plugins/pluginSkills.js +47 -9
- package/src/plugins/pluginSkills.ts +46 -8
- package/src/pluginsFactory/discovery.js +0 -1
- package/src/pluginsFactory/discovery.ts +0 -1
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/pluginsFactory/templates.js +17 -4
- package/src/pluginsFactory/templates.ts +17 -4
- package/src/prWorkflow.js +337 -0
- package/src/prWorkflow.ts +376 -0
- package/src/procSignal.js +1 -2
- package/src/procSignal.ts +1 -3
- package/src/projectInstructions.js +319 -0
- package/src/projectInstructions.ts +361 -0
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +235 -50
- package/src/providers/acp.ts +241 -51
- package/src/providers/anthropic.js +431 -400
- package/src/providers/anthropic.ts +493 -0
- package/src/providers/antigravity.js +575 -358
- package/src/providers/antigravity.ts +565 -359
- package/src/providers/base.js +229 -320
- package/src/providers/base.ts +348 -0
- package/src/providers/byokHttp.js +183 -30
- package/src/providers/byokHttp.ts +232 -32
- package/src/providers/byokStream.js +287 -70
- package/src/providers/byokStream.ts +282 -71
- package/src/providers/dashscope-byok.js +123 -89
- package/src/providers/dashscope-byok.ts +142 -0
- package/src/providers/deepseek.js +82 -72
- package/src/providers/deepseek.ts +108 -0
- package/src/providers/factory.js +76 -28
- package/src/providers/factory.ts +82 -0
- package/src/providers/gemini.js +279 -278
- package/src/providers/gemini.ts +313 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +103 -72
- package/src/providers/moonshot.ts +122 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +360 -106
- package/src/providers/ollama.ts +408 -0
- package/src/providers/openai-compatible.js +168 -95
- package/src/providers/openai-compatible.ts +200 -0
- package/src/providers/openai.js +45 -15
- package/src/providers/openai.ts +52 -0
- package/src/providers/openrouter.js +342 -113
- package/src/providers/openrouter.ts +333 -116
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +122 -87
- package/src/providers/qwen-byok.ts +141 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +144 -11
- package/src/providers/wireNormalizer.ts +132 -12
- package/src/providers/xai.js +80 -72
- package/src/providers/xai.ts +103 -0
- package/src/provisioning/capabilityConsent.js +29 -11
- package/src/provisioning/capabilityConsent.ts +42 -0
- package/src/provisioning/capabilityProvisioner.js +309 -197
- package/src/provisioning/capabilityProvisioner.ts +413 -0
- package/src/provisioning/capabilityTools.js +31 -17
- package/src/provisioning/capabilityTools.ts +43 -0
- package/src/provisioning/npmInstall.js +33 -5
- package/src/provisioning/npmInstall.ts +33 -5
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/reporting.js +328 -326
- package/src/reporting.ts +482 -0
- package/src/sandbox.js +526 -554
- package/src/sandbox.ts +590 -0
- package/src/sandboxPolicy.js +95 -16
- package/src/sandboxPolicy.ts +97 -16
- package/src/sessionJournal.js +32 -6
- package/src/sessionJournal.ts +27 -6
- package/src/sessionStore.js +1 -2
- package/src/sessionStore.ts +2 -0
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/slopDetector.js +202 -265
- package/src/slopDetector.ts +279 -0
- package/src/smartToolsUse.js +38 -8
- package/src/smartToolsUse.ts +39 -11
- package/src/stallGuard.js +53 -23
- package/src/stallGuard.ts +53 -23
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/taskBuffer.js +91 -40
- package/src/taskBuffer.ts +94 -0
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +120 -38
- package/src/tokenTracker.ts +110 -38
- package/src/toolPacks.js +8 -1
- package/src/toolPacks.ts +8 -1
- package/src/tools/applyPatch.js +610 -0
- package/src/tools/applyPatch.ts +661 -0
- package/src/tools/archive.js +372 -48
- package/src/tools/archive.ts +372 -48
- package/src/tools/astryxOracle.js +77 -72
- package/src/tools/astryxOracle.ts +95 -0
- package/src/tools/axSnapshot.js +127 -147
- package/src/tools/axSnapshot.ts +174 -0
- package/src/tools/backgroundTask.js +86 -0
- package/src/tools/backgroundTask.ts +121 -0
- package/src/tools/blenderAutomator.js +434 -390
- package/src/tools/blenderAutomator.ts +623 -0
- package/src/tools/checkSystemSpecs.js +54 -61
- package/src/tools/checkSystemSpecs.ts +73 -0
- package/src/tools/clipboard.js +42 -31
- package/src/tools/clipboard.ts +61 -0
- package/src/tools/codeSearchAst.js +359 -91
- package/src/tools/codeSearchAst.ts +399 -0
- package/src/tools/codeSearcher.js +179 -37
- package/src/tools/codeSearcher.ts +188 -33
- package/src/tools/codeTools.js +208 -245
- package/src/tools/codeTools.ts +271 -0
- package/src/tools/codebaseSearch.js +5 -0
- package/src/tools/codebaseSearch.ts +5 -0
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopAct.js +185 -197
- package/src/tools/desktopAct.ts +257 -0
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/dynamicLoader.js +4 -40
- package/src/tools/dynamicLoader.ts +13 -0
- package/src/tools/executeProceduralMedia.js +117 -86
- package/src/tools/executeProceduralMedia.ts +135 -0
- package/src/tools/fileTracker.js +74 -0
- package/src/tools/fileTracker.ts +94 -0
- package/src/tools/fsDelete.js +57 -47
- package/src/tools/fsDelete.ts +80 -0
- package/src/tools/fsEdit.js +250 -61
- package/src/tools/fsEdit.ts +265 -63
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsMove.js +79 -52
- package/src/tools/fsMove.ts +108 -0
- package/src/tools/fsRead.js +163 -18
- package/src/tools/fsRead.ts +169 -18
- package/src/tools/fsSearch.js +5 -0
- package/src/tools/fsSearch.ts +5 -0
- package/src/tools/fsWrite.js +31 -11
- package/src/tools/fsWrite.ts +31 -13
- package/src/tools/gameAiBehaviorTree.js +74 -91
- package/src/tools/gameAiBehaviorTree.ts +219 -0
- package/src/tools/gameAnimationRig.js +128 -147
- package/src/tools/gameAnimationRig.ts +215 -0
- package/src/tools/gameAssetFetcher.js +403 -441
- package/src/tools/gameAssetFetcher.ts +477 -0
- package/src/tools/gameAssetHarvester.js +171 -200
- package/src/tools/gameAssetHarvester.ts +261 -0
- package/src/tools/gameAudioSynth.js +223 -259
- package/src/tools/gameAudioSynth.ts +255 -0
- package/src/tools/gameBuilder.js +100 -91
- package/src/tools/gameBuilder.ts +913 -0
- package/src/tools/gameCanvasAudit.js +138 -96
- package/src/tools/gameCanvasAudit.ts +157 -0
- package/src/tools/gameCinematicSequencer.js +93 -111
- package/src/tools/gameCinematicSequencer.ts +165 -0
- package/src/tools/gameDataForge.js +115 -118
- package/src/tools/gameDataForge.ts +151 -0
- package/src/tools/gameDialogueTreeGen.js +125 -156
- package/src/tools/gameDialogueTreeGen.ts +159 -0
- package/src/tools/gameEconomyBalancer.js +150 -153
- package/src/tools/gameEconomyBalancer.ts +186 -0
- package/src/tools/gameEntitySpawner.js +91 -108
- package/src/tools/gameEntitySpawner.ts +209 -0
- package/src/tools/gameLoreForge.js +125 -147
- package/src/tools/gameLoreForge.ts +162 -0
- package/src/tools/gameQuestArcBuilder.js +105 -144
- package/src/tools/gameQuestArcBuilder.ts +147 -0
- package/src/tools/gameSceneBuilder.js +143 -149
- package/src/tools/gameSceneBuilder.ts +196 -0
- package/src/tools/gameShaderForge.js +83 -101
- package/src/tools/gameShaderForge.ts +181 -0
- package/src/tools/gameTilemapGenerator.js +99 -129
- package/src/tools/gameTilemapGenerator.ts +158 -0
- package/src/tools/gameUiHudBuilder.js +109 -129
- package/src/tools/gameUiHudBuilder.ts +300 -0
- package/src/tools/gameVfxEmitterGen.js +86 -89
- package/src/tools/gameVfxEmitterGen.ts +133 -0
- package/src/tools/gameWebRuntimeInspector.js +153 -86
- package/src/tools/gameWebRuntimeInspector.ts +167 -0
- package/src/tools/generateMediaViaApi.js +126 -22
- package/src/tools/generateMediaViaApi.ts +123 -22
- package/src/tools/gitExec.js +133 -86
- package/src/tools/gitExec.ts +146 -0
- package/src/tools/gitWorktree.js +115 -0
- package/src/tools/gitWorktree.ts +150 -0
- package/src/tools/godotAutomator.js +417 -394
- package/src/tools/godotAutomator.ts +530 -0
- package/src/tools/lspCodeIntel.js +217 -0
- package/src/tools/lspCodeIntel.ts +260 -0
- package/src/tools/manageLocalAiDependencies.js +242 -206
- package/src/tools/manageLocalAiDependencies.ts +288 -0
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +73 -63
- package/src/tools/multiEdit.ts +80 -65
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +202 -25
- package/src/tools/osSandbox.ts +192 -25
- package/src/tools/palmierAutomator.js +147 -95
- package/src/tools/palmierAutomator.ts +171 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/pdfReader.js +95 -104
- package/src/tools/pdfReader.ts +125 -0
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +267 -144
- package/src/tools/persistentShell.ts +314 -0
- package/src/tools/pluginManager.js +84 -72
- package/src/tools/pluginManager.ts +109 -0
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/printer.js +278 -296
- package/src/tools/printer.ts +326 -0
- package/src/tools/procTerm.js +96 -83
- package/src/tools/procTerm.ts +127 -0
- package/src/tools/processList.js +45 -48
- package/src/tools/processList.ts +73 -0
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/registry.js +298 -286
- package/src/tools/registry.ts +486 -0
- package/src/tools/repoMap.js +46 -0
- package/src/tools/repoMap.ts +66 -0
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subagentOrchestrator.js +404 -348
- package/src/tools/subagentOrchestrator.ts +457 -0
- package/src/tools/sysRun.js +148 -51
- package/src/tools/sysRun.ts +142 -46
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolForge.js +84 -67
- package/src/tools/toolForge.ts +102 -0
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolPathSafety.js +262 -0
- package/src/tools/toolPathSafety.ts +308 -0
- package/src/tools/toolScanner.js +41 -10
- package/src/tools/toolScanner.ts +42 -10
- package/src/tools/toolSelfRepair.js +115 -34
- package/src/tools/toolSelfRepair.ts +122 -34
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +2 -0
- package/src/tools/webFetch.js +110 -12
- package/src/tools/webFetch.ts +110 -13
- package/src/toolsList.js +5 -0
- package/src/toolsList.ts +5 -0
- package/src/tui/ask.js +159 -168
- package/src/tui/ask.ts +259 -0
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/block.js +0 -1
- package/src/tui/block.ts +0 -1
- package/src/tui/chatRenderer.js +1193 -1441
- package/src/tui/chatRenderer.ts +1336 -0
- package/src/tui/clipboardImage.js +36 -12
- package/src/tui/clipboardImage.ts +39 -13
- package/src/tui/clipboardSync.js +34 -9
- package/src/tui/clipboardSync.ts +38 -9
- package/src/tui/codeProgress.js +0 -1
- package/src/tui/codeProgress.ts +0 -1
- package/src/tui/completion.js +395 -371
- package/src/tui/completion.ts +574 -0
- package/src/tui/composerControls.js +113 -19
- package/src/tui/composerControls.ts +124 -19
- package/src/tui/consoleGuard.js +39 -11
- package/src/tui/consoleGuard.ts +38 -11
- package/src/tui/dialogs.js +864 -717
- package/src/tui/dialogs.ts +984 -0
- package/src/tui/diff.js +205 -195
- package/src/tui/diff.ts +336 -0
- package/src/tui/history.js +143 -108
- package/src/tui/history.ts +167 -0
- package/src/tui/home.js +165 -161
- package/src/tui/home.ts +251 -0
- package/src/tui/invocation.js +58 -65
- package/src/tui/invocation.ts +117 -0
- package/src/tui/keys.js +437 -420
- package/src/tui/keys.ts +597 -0
- package/src/tui/lineEditor.js +477 -432
- package/src/tui/lineEditor.ts +542 -0
- package/src/tui/messageActionPlacement.js +0 -1
- package/src/tui/messageActionPlacement.ts +0 -1
- package/src/tui/messageInteraction.js +2 -5
- package/src/tui/messageInteraction.ts +2 -5
- package/src/tui/modelPicker.js +1 -3
- package/src/tui/modelPicker.ts +4 -6
- package/src/tui/observerPicker.js +0 -2
- package/src/tui/observerPicker.ts +0 -2
- package/src/tui/overlay.js +3 -2
- package/src/tui/overlay.ts +3 -2
- package/src/tui/prompt.js +1816 -2151
- package/src/tui/prompt.ts +1870 -0
- package/src/tui/runningLight.js +0 -1
- package/src/tui/runningLight.ts +0 -1
- package/src/tui/selectList.js +365 -337
- package/src/tui/selectList.ts +441 -0
- package/src/tui/sessionPicker.js +3 -3
- package/src/tui/sessionPicker.ts +3 -3
- package/src/tui/sessionPickerView.js +7 -3
- package/src/tui/sessionPickerView.ts +10 -22
- package/src/tui/sessionSidebar.js +3 -1
- package/src/tui/sessionSidebar.ts +4 -1
- package/src/tui/setup.js +17 -5
- package/src/tui/setup.ts +19 -5
- package/src/tui/skillAuthoring.js +0 -2
- package/src/tui/skillAuthoring.ts +0 -3
- package/src/tui/stageSurface.js +829 -909
- package/src/tui/stageSurface.ts +1003 -0
- package/src/tui/statusLine.js +7 -4
- package/src/tui/statusLine.ts +7 -3
- package/src/tui/terminalInputFramer.js +82 -69
- package/src/tui/terminalInputFramer.ts +116 -0
- package/src/tui/text.js +25 -10
- package/src/tui/text.ts +24 -10
- package/src/tui/textLayout.js +0 -1
- package/src/tui/textLayout.ts +0 -1
- package/src/tui/theme.js +245 -250
- package/src/tui/theme.ts +441 -0
- package/src/tui/thinkingBox.js +0 -1
- package/src/tui/thinkingBox.ts +0 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/transcript.js +239 -216
- package/src/tui/transcript.ts +324 -0
- package/src/tui/turnRail.js +53 -54
- package/src/tui/turnRail.ts +51 -49
- package/src/tui/usageCard.js +0 -2
- package/src/tui/usageCard.ts +0 -2
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/tui/workspaceSwitch.js +4 -2
- package/src/tui/workspaceSwitch.ts +5 -2
- package/src/types/contracts.ts +4 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/browserOpen.js +107 -0
- package/src/utils/browserOpen.ts +129 -0
- package/src/utils/cli_ui.js +0 -0
- package/src/utils/cli_ui.ts +158 -0
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/utils/winSpawn.js +248 -0
- package/src/utils/winSpawn.ts +275 -0
- package/src/verification/boundedExplorer.js +138 -107
- package/src/verification/boundedExplorer.ts +154 -0
- package/src/verification/byokSmokeProbe.js +193 -0
- package/src/verification/byokSmokeProbe.ts +234 -0
- package/src/verification/cliProbe.js +144 -110
- package/src/verification/cliProbe.ts +170 -0
- package/src/verification/featureMap.js +105 -75
- package/src/verification/featureMap.ts +124 -0
- package/src/verification/interactivePty.js +195 -100
- package/src/verification/interactivePty.ts +333 -0
- package/src/verification/propertyProbe.js +109 -101
- package/src/verification/propertyProbe.ts +159 -0
- package/src/verification/ptyProbe.js +168 -73
- package/src/verification/ptyProbe.ts +254 -0
- package/src/verification/skillCatalog.js +25 -25
- package/src/verification/skillCatalog.ts +66 -0
- package/src/verification/statechart.js +140 -127
- package/src/verification/statechart.ts +196 -0
- package/src/verification/uiRuntime.js +80 -49
- package/src/verification/uiRuntime.ts +88 -0
- package/src/version.js +37 -32
- package/src/version.ts +45 -0
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/web/guiLauncher.js +89 -0
- package/src/web/guiLauncher.ts +119 -0
- package/src/web/skybridgeBrowserBridge.js +256 -0
- package/src/web/skybridgeBrowserBridge.ts +285 -0
- package/src/web/skybridgeBrowserMcp.js +730 -0
- package/src/web/skybridgeBrowserMcp.ts +813 -0
- package/src/web/skybridgeClientScript.js +3951 -0
- package/src/web/skybridgeClientScript.ts +3952 -0
- package/src/web/skybridgeServer.js +2622 -0
- package/src/web/skybridgeServer.ts +2787 -0
- package/src/web/skybridgeStyles.js +827 -0
- package/src/web/skybridgeStyles.ts +828 -0
- package/src/web/skybridgeUi.js +472 -0
- package/src/web/skybridgeUi.ts +485 -0
- package/src/worktreeManager.js +511 -0
- package/src/worktreeManager.ts +546 -0
- package/src/zeroCostFailover.js +168 -0
- package/src/zeroCostFailover.ts +198 -0
- package/src/zeroCostRouting.js +391 -0
- package/src/zeroCostRouting.ts +437 -0
- package/src/agentLoop.d.ts +0 -65
- package/src/auditLog.d.ts +0 -3
- package/src/checkpoints.d.ts +0 -4
- package/src/compiledSkills.d.ts +0 -5
- package/src/config.d.ts +0 -2
- package/src/contextManager.d.ts +0 -14
- package/src/designPalettes.d.ts +0 -2
- package/src/devMode.d.ts +0 -1
- package/src/embodimentSession.d.ts +0 -2
- package/src/licensing/entitlements.d.ts +0 -14
- package/src/memory.d.ts +0 -13
- package/src/memoryManager.d.ts +0 -1
- package/src/modelCatalogue.d.ts +0 -6
- package/src/modelIds.d.ts +0 -2
- package/src/outputStore.d.ts +0 -4
- package/src/plugins/pluginManager.d.ts +0 -7
- package/src/providers/antigravity.d.ts +0 -19
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/provisioning/capabilityProvisioner.d.ts +0 -12
- package/src/sandbox.d.ts +0 -1
- package/src/slopDetector.d.ts +0 -3
- package/src/taskBuffer.d.ts +0 -1
- package/src/tools/desktopAct.d.ts +0 -10
- package/src/tools/registry.d.ts +0 -5
- package/src/tui/chatRenderer.d.ts +0 -27
- package/src/tui/diff.d.ts +0 -3
- package/src/utils/cli_ui.d.ts +0 -19
- package/src/utils/paths.d.ts +0 -3
- package/src/verification/skillCatalog.d.ts +0 -1
- package/src/version.d.ts +0 -1
package/src/tui/stageSurface.js
CHANGED
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
// everything but cannot scroll; doing both is the entire point.
|
|
21
21
|
//
|
|
22
22
|
// Pure Node: no dependency, no shell.
|
|
23
|
-
|
|
24
23
|
import { Stage, stageHeight } from './stage.js';
|
|
25
24
|
import { Transcript } from './transcript.js';
|
|
26
25
|
import { Viewport, ScrollAcceleration, DEFAULT_SCROLL_SPEED } from './viewport.js';
|
|
@@ -29,22 +28,19 @@ import { markHoveredMessage } from './messageInteraction.js';
|
|
|
29
28
|
import { placeMessageActionPanel } from './messageActionPlacement.js';
|
|
30
29
|
import { mouseTracking } from './keys.js';
|
|
31
30
|
import { mouseHoverTracking } from './mouseHover.js';
|
|
32
|
-
import { truncate, padEnd, visibleWidth, stripAnsi } from './text.js';
|
|
31
|
+
import { truncate, padEnd, visibleWidth, stripAnsi, safeDisplay } from './text.js';
|
|
33
32
|
import { composerWidth } from './layout.js';
|
|
34
33
|
import { placeHome, placeDialog } from './homeView.js';
|
|
35
34
|
import { sidebarVisible, sessionSidebarWidth, sessionMainWidth, sessionComposerWidth, sessionSidebarRows, joinSessionSidebar } from './sessionSidebar.js';
|
|
36
35
|
import { sessionStageHeight, alignTranscriptRows } from './sessionLayout.js';
|
|
37
36
|
import { hasSessionTurns, collectSessionTurns, buildTurnRailCells, renderTurnPreviewCard, overlayTurnPreviewCard, resolveActiveTurnIndex, formatPreviewCardMarkdown } from './turnRail.js';
|
|
38
37
|
import { registerStageConsoleGuard, setStageConsoleGuardActive, runWithStageWrite } from './consoleGuard.js';
|
|
39
|
-
|
|
40
38
|
// Rows of evicted transcript held for the exit log. Eviction only happens after
|
|
41
39
|
// MAX_FRAMES, so this is a bound on a pathological session, not a working limit.
|
|
42
40
|
const MAX_EVICTED_ROWS = 40000;
|
|
43
|
-
|
|
44
41
|
// Below this the prompt block gets the whole band and the transcript is not
|
|
45
42
|
// shown at all — which is a broken screen, so the prompt is trimmed instead.
|
|
46
43
|
const MIN_VIEWPORT_ROWS = 2;
|
|
47
|
-
|
|
48
44
|
// The rail costs a column plus a column of air. On a narrow terminal those two
|
|
49
45
|
// are worth more as text, so it turns itself off rather than crowding the
|
|
50
46
|
// transcript it exists to help you navigate.
|
|
@@ -59,983 +55,907 @@ const RAIL_WIDTH = 2;
|
|
|
59
55
|
const RAIL_BUDGET = RAIL_WIDTH + 1;
|
|
60
56
|
// The interactive turn rail takes three columns at the left of each row.
|
|
61
57
|
const TURN_RAIL_BUDGET = 3;
|
|
62
|
-
|
|
63
58
|
// Count a prefix of terminal control sequences with a deterministic scan.
|
|
64
59
|
// This preserves CSI, OSC (BEL/ST), and two-byte ESC codes without regex
|
|
65
60
|
// backtracking on long or malformed terminal output.
|
|
66
61
|
export function leadingAnsiControlEnd(row) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
62
|
+
if (typeof row !== 'string')
|
|
63
|
+
return 0;
|
|
64
|
+
let index = 0;
|
|
65
|
+
while (row.charCodeAt(index) === 27) {
|
|
66
|
+
let cursor = index + 1;
|
|
67
|
+
const kind = row.charCodeAt(cursor);
|
|
68
|
+
if (kind === 91) { // ESC [
|
|
69
|
+
cursor++;
|
|
70
|
+
while (row.charCodeAt(cursor) >= 48 && row.charCodeAt(cursor) <= 63)
|
|
71
|
+
cursor++;
|
|
72
|
+
while (row.charCodeAt(cursor) >= 32 && row.charCodeAt(cursor) <= 47)
|
|
73
|
+
cursor++;
|
|
74
|
+
const final = row.charCodeAt(cursor);
|
|
75
|
+
if (final >= 64 && final <= 126) {
|
|
76
|
+
index = cursor + 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (kind === 93) { // ESC ] ... BEL or ESC backslash
|
|
81
|
+
cursor++;
|
|
82
|
+
while (cursor < row.length && row.charCodeAt(cursor) !== 7 && row.charCodeAt(cursor) !== 27)
|
|
83
|
+
cursor++;
|
|
84
|
+
if (row.charCodeAt(cursor) === 7) {
|
|
85
|
+
index = cursor + 1;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (row.charCodeAt(cursor) === 27 && row.charCodeAt(cursor + 1) === 92) {
|
|
89
|
+
index = cursor + 2;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if ((kind >= 64 && kind <= 90) || (kind >= 92 && kind <= 95)) {
|
|
94
|
+
index = cursor + 1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
95
98
|
}
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
return index;
|
|
99
|
+
return index;
|
|
99
100
|
}
|
|
100
|
-
|
|
101
101
|
// Which marker wins when several frames fall in the same rail row. A proportional
|
|
102
102
|
// rail on a long session compresses dozens of frames per row, and what you want
|
|
103
103
|
// to see at a glance is the thing that went wrong or the thing you can roll back
|
|
104
104
|
// to — not the forty step rows around them.
|
|
105
105
|
// Inside the thumb, only a marker this loud overrides the position indicator.
|
|
106
|
-
//
|
|
107
|
-
// Two passes to get this right. The first draft let ANY marker win, and a dense
|
|
108
|
-
// session put a marker in every slot — so the thumb, the one thing on the rail
|
|
109
|
-
// that says WHERE YOU ARE, was invisible exactly when the rail mattered most.
|
|
110
|
-
// The second draft set the bar at checkpoints, and a real session on a pty
|
|
111
|
-
// showed why that is still wrong: a restore point is taken on every file write,
|
|
112
|
-
// so the thumb came out as `▌▌▪▪▪▌` — shredded by the most routine event there
|
|
113
|
-
// is. Only what is rare AND urgent is worth a row of position: an error, or an
|
|
114
|
-
// approval waiting on the user.
|
|
115
106
|
const RAIL_THUMB_YIELD = 80;
|
|
116
|
-
|
|
117
107
|
const RAIL_PRIORITY = {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
error: 90, approval: 80, checkpoint: 70, turn: 60, user: 50,
|
|
109
|
+
assistant: 40, reasoning: 30, skill: 25, plan: 20,
|
|
110
|
+
session: 15, step: 10, result: 5, notice: 1
|
|
111
|
+
};
|
|
112
|
+
const SIGNAL_EXIT_CODES = {
|
|
113
|
+
SIGINT: 2,
|
|
114
|
+
SIGTERM: 15,
|
|
115
|
+
SIGHUP: 1
|
|
121
116
|
};
|
|
122
|
-
|
|
117
|
+
function railPriority(kind) {
|
|
118
|
+
if (!kind || !Object.hasOwn(RAIL_PRIORITY, kind))
|
|
119
|
+
return 0;
|
|
120
|
+
return RAIL_PRIORITY[kind] ?? 0;
|
|
121
|
+
}
|
|
123
122
|
/**
|
|
124
123
|
* One row of the position indicator: a continuous rule with ONE dot at its
|
|
125
124
|
* middle. Line, dot, line — the same motif the input box carries.
|
|
126
125
|
*
|
|
127
|
-
* Alternating every other row was the first attempt and it was wrong: over a
|
|
128
|
-
* thumb of any length it reads as a long dashed line, which is the thing it was
|
|
129
|
-
* supposed to stop looking like. One dot at the centre makes even a full-track
|
|
130
|
-
* thumb read as a single object rather than as a run of broken marks.
|
|
131
|
-
*
|
|
132
126
|
* `│` is used by no marker, which is what lets a test find the thumb at all.
|
|
133
127
|
*/
|
|
134
128
|
function thumbGlyph(offsetInThumb, thumbLength) {
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
const middle = thumbLength >= 3 ? Math.floor(thumbLength / 2) : -1;
|
|
130
|
+
return offsetInThumb === middle ? GLYPHS.dot : GLYPHS.vLine;
|
|
137
131
|
}
|
|
138
|
-
|
|
139
132
|
/**
|
|
140
133
|
* One rail cell. Every glyph is an existing GLYPH — the ambiguous-width set is
|
|
141
134
|
* already accounted for by visibleWidth(), and a new character here would be a
|
|
142
135
|
* new way for a row to measure one column and render two.
|
|
143
136
|
*/
|
|
144
137
|
function railGlyph(kind) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
138
|
+
switch (kind) {
|
|
139
|
+
case 'error': return paint('danger', GLYPHS.cross);
|
|
140
|
+
case 'approval': return paint('warn', GLYPHS.step);
|
|
141
|
+
case 'checkpoint': return paint('success', GLYPHS.step);
|
|
142
|
+
case 'turn': return paint('rule', GLYPHS.hLine);
|
|
143
|
+
case 'user': return paint('user', GLYPHS.arrow);
|
|
144
|
+
case 'assistant': return paint('agent', GLYPHS.arrow);
|
|
145
|
+
case 'reasoning': return paint('muted', GLYPHS.dot);
|
|
146
|
+
default: return paint('rule', GLYPHS.dot);
|
|
147
|
+
}
|
|
155
148
|
}
|
|
156
|
-
|
|
157
149
|
/**
|
|
158
150
|
* Wheel tuning, from the environment first and the saved config second.
|
|
159
|
-
*
|
|
160
|
-
* Env wins because every other Stage switch is an env var (CAUSYNE_STAGE,
|
|
161
|
-
* CAUSYNE_MOUSE, CAUSYNE_RAIL) and a user debugging a terminal wants one place to
|
|
162
|
-
* turn things off. The config file is where a preference lives once it is
|
|
163
|
-
* settled.
|
|
164
151
|
*/
|
|
165
152
|
export function scrollSettings(env = process.env, config = null) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return { speed, accelerate };
|
|
153
|
+
const safeEnv = env && typeof env === 'object' ? env : {};
|
|
154
|
+
const tui = (config && typeof config === 'object' && config.tui) || {};
|
|
155
|
+
let speed = Number(safeEnv.CAUSYNE_SCROLL_SPEED);
|
|
156
|
+
if (!Number.isFinite(speed) || speed <= 0)
|
|
157
|
+
speed = Number(tui.scrollSpeed);
|
|
158
|
+
if (!Number.isFinite(speed) || speed <= 0)
|
|
159
|
+
speed = DEFAULT_SCROLL_SPEED;
|
|
160
|
+
// A wheel that moves half the screen per notch is not a preference, it is a
|
|
161
|
+
// misconfiguration; clamp rather than obey it.
|
|
162
|
+
speed = Math.min(speed, 20);
|
|
163
|
+
const raw = safeEnv.CAUSYNE_SCROLL_ACCEL;
|
|
164
|
+
const accelerate = raw !== undefined && raw !== ''
|
|
165
|
+
? raw === '1' || raw === 'true'
|
|
166
|
+
: Boolean(tui.scrollAcceleration);
|
|
167
|
+
return { speed, accelerate };
|
|
182
168
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
169
|
/**
|
|
186
170
|
* A rail dot represents a *time-ordered group* when a long conversation is
|
|
187
|
-
* compressed into fewer terminal rows.
|
|
188
|
-
* history list with timestamps, not a single-turn assistant-summary card.
|
|
189
|
-
* This function never changes transcript geometry or user content.
|
|
171
|
+
* compressed into fewer terminal rows.
|
|
190
172
|
*/
|
|
191
173
|
export function renderTurnTimelineCard(turns, maxCardWidth = 52, maxHeight = 16, offset = 0) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
174
|
+
if (!Array.isArray(turns) || turns.length === 0) {
|
|
175
|
+
return { rows: [], entries: [], entryStart: 4, maxOffset: 0 };
|
|
176
|
+
}
|
|
177
|
+
const width = Number.isFinite(maxCardWidth) ? Math.max(24, Math.min(52, Math.floor(maxCardWidth))) : 52;
|
|
178
|
+
const inner = width - 4;
|
|
179
|
+
const viewHeight = Number.isFinite(maxHeight) ? Math.max(6, Math.floor(maxHeight)) : 16;
|
|
180
|
+
const count = Math.max(1, Math.min(10, turns.length, viewHeight - 5));
|
|
181
|
+
const maxOffset = Math.max(0, turns.length - count);
|
|
182
|
+
const start = Number.isFinite(offset) ? Math.max(0, Math.min(maxOffset, Math.floor(offset))) : 0;
|
|
183
|
+
const entries = turns.slice(start, start + count);
|
|
184
|
+
const bg = '\x1b[48;2;28;28;32m';
|
|
185
|
+
const border = bg + '\x1b[38;2;75;75;82m';
|
|
186
|
+
const reset = '\x1b[0m';
|
|
187
|
+
const top = border + '╭' + '─'.repeat(width - 2) + '╮' + reset;
|
|
188
|
+
const bottom = border + '╰' + '─'.repeat(width - 2) + '╯' + reset;
|
|
189
|
+
const blank = border + '│' + bg + ' '.repeat(inner + 2) + border + '│' + reset;
|
|
190
|
+
const line = (value, style = '') => {
|
|
191
|
+
const text = truncate(formatPreviewCardMarkdown(safeDisplay(String(value || ''))), inner, '…');
|
|
192
|
+
return border + '│' + bg + ' ' + style + padEnd(text, inner) + border + ' │' + reset;
|
|
193
|
+
};
|
|
194
|
+
const shortTime = (turn) => {
|
|
195
|
+
const ts = Number(turn?.timestamp);
|
|
196
|
+
return Number.isFinite(ts) && ts > 0
|
|
197
|
+
? new Date(ts).toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' })
|
|
198
|
+
: '';
|
|
199
|
+
};
|
|
200
|
+
const first = turns[0];
|
|
201
|
+
const last = turns[turns.length - 1];
|
|
202
|
+
const title = first?.userPrompt || 'Conversation history';
|
|
203
|
+
const range = shortTime(first) + (turns.length > 1 ? ' – ' + shortTime(last) : '');
|
|
204
|
+
const header = range.trim() + ' · ' + turns.length + (turns.length === 1 ? ' turn' : ' turns');
|
|
205
|
+
const rows = [
|
|
206
|
+
top,
|
|
207
|
+
line(title, '\x1b[1m\x1b[38;2;235;235;242m'),
|
|
208
|
+
line(header, '\x1b[38;2;145;145;155m'),
|
|
209
|
+
blank
|
|
210
|
+
];
|
|
211
|
+
for (const turn of entries) {
|
|
212
|
+
const when = shortTime(turn);
|
|
213
|
+
const prompt = turn?.userPrompt || 'Turn ' + String(turn?.turnIndex ?? '');
|
|
214
|
+
rows.push(line((when ? when + ' ' : '') + prompt, '\x1b[38;2;185;185;193m'));
|
|
215
|
+
}
|
|
216
|
+
rows.push(bottom);
|
|
217
|
+
return { rows, entries, entryStart: 4, maxOffset };
|
|
236
218
|
}
|
|
237
|
-
|
|
238
219
|
export class StageSurface {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
setSessionInfo(info) {
|
|
334
|
-
const changedSession = info?.id && this.sessionInfo?.id && info.id !== this.sessionInfo.id;
|
|
335
|
-
if (changedSession) {
|
|
336
|
-
// Sidebar plans and turn hover coordinates belong to the previous chat.
|
|
337
|
-
this.sidebarPlan = [];
|
|
338
|
-
this.hoveredTurnIndex = null;
|
|
339
|
-
this.hoveredTurnAnchorY = null;
|
|
340
|
-
this.activeTurnIndex = null;
|
|
341
|
-
this.hoveredMessageFrameId = null;
|
|
342
|
-
this.turnRailLayout = null;
|
|
220
|
+
out;
|
|
221
|
+
env;
|
|
222
|
+
stage;
|
|
223
|
+
lastColumns;
|
|
224
|
+
transcript;
|
|
225
|
+
viewport;
|
|
226
|
+
evicted;
|
|
227
|
+
lastHeight;
|
|
228
|
+
onDirty;
|
|
229
|
+
exitHook;
|
|
230
|
+
signalHooks;
|
|
231
|
+
mouseWanted;
|
|
232
|
+
mouseOn;
|
|
233
|
+
mouseCaptured;
|
|
234
|
+
mouseMotionOn;
|
|
235
|
+
detached;
|
|
236
|
+
openingWidth;
|
|
237
|
+
opened;
|
|
238
|
+
homeInfo;
|
|
239
|
+
homeSessionSelected;
|
|
240
|
+
sessionInfo;
|
|
241
|
+
sidebarStatus;
|
|
242
|
+
sidebarPlan;
|
|
243
|
+
fullSession;
|
|
244
|
+
lastPromptRows;
|
|
245
|
+
lastPromptCaret;
|
|
246
|
+
messageActionOverlay;
|
|
247
|
+
unregisterConsoleGuard;
|
|
248
|
+
wasModal;
|
|
249
|
+
lastBlockLength;
|
|
250
|
+
lastUserTurnCount;
|
|
251
|
+
hoveredTurnIndex;
|
|
252
|
+
hoveredTurnAnchorY;
|
|
253
|
+
activeTurnIndex;
|
|
254
|
+
hoveredMessageFrameId;
|
|
255
|
+
turnRailLayout;
|
|
256
|
+
turnRailCardOffset;
|
|
257
|
+
turnRailHoverSuppressed;
|
|
258
|
+
constructor({ out = process.stdout, env = process.env, config = null, speed, accelerate, openingWidth = 0 } = {}) {
|
|
259
|
+
this.out = out;
|
|
260
|
+
this.env = env && typeof env === 'object' ? env : {};
|
|
261
|
+
this.stage = new Stage({ out, env: this.env });
|
|
262
|
+
this.lastColumns = this.stage.width();
|
|
263
|
+
this.transcript = new Transcript({
|
|
264
|
+
onEvict: (rows) => this.absorbEvicted(rows),
|
|
265
|
+
onChange: () => this.handleChange()
|
|
266
|
+
});
|
|
267
|
+
this.transcript.surface = this;
|
|
268
|
+
const tuning = scrollSettings(this.env, config);
|
|
269
|
+
this.viewport = new Viewport({
|
|
270
|
+
transcript: this.transcript,
|
|
271
|
+
height: Math.max(MIN_VIEWPORT_ROWS, this.stage.height - 2),
|
|
272
|
+
width: this.stage.width(),
|
|
273
|
+
speed: speed !== undefined ? speed : tuning.speed,
|
|
274
|
+
acceleration: (accelerate !== undefined ? accelerate : tuning.accelerate)
|
|
275
|
+
? new ScrollAcceleration()
|
|
276
|
+
: null
|
|
277
|
+
});
|
|
278
|
+
// Rows that fell out of the model. Not shown, not lost: they are printed
|
|
279
|
+
// ahead of the transcript on the way out.
|
|
280
|
+
this.evicted = [];
|
|
281
|
+
this.lastHeight = 0;
|
|
282
|
+
// Set by ChatPrompt.attachSurface.
|
|
283
|
+
this.onDirty = null;
|
|
284
|
+
this.exitHook = null;
|
|
285
|
+
this.signalHooks = [];
|
|
286
|
+
// UX-02: opt out entirely, for anyone whose terminal or workflow this gets
|
|
287
|
+
// in the way of.
|
|
288
|
+
this.mouseWanted = String(this.env.CAUSYNE_MOUSE ?? '1') !== '0';
|
|
289
|
+
this.mouseOn = false;
|
|
290
|
+
this.mouseCaptured = false;
|
|
291
|
+
this.mouseMotionOn = false;
|
|
292
|
+
this.detached = false;
|
|
293
|
+
// Retained for callers that pass a measured header width. The composer now
|
|
294
|
+
// uses a stable readable width even after the first transcript entry.
|
|
295
|
+
this.openingWidth = Number.isFinite(openingWidth) && openingWidth > 0
|
|
296
|
+
? Math.floor(openingWidth)
|
|
297
|
+
: 0;
|
|
298
|
+
// Tracks whether this session has ever received transcript content.
|
|
299
|
+
this.opened = false;
|
|
300
|
+
this.homeInfo = null;
|
|
301
|
+
this.homeSessionSelected = false;
|
|
302
|
+
this.sessionInfo = null;
|
|
303
|
+
this.sidebarStatus = null;
|
|
304
|
+
this.sidebarPlan = [];
|
|
305
|
+
this.fullSession = false;
|
|
306
|
+
this.lastPromptRows = [];
|
|
307
|
+
this.lastPromptCaret = null;
|
|
308
|
+
this.messageActionOverlay = null;
|
|
309
|
+
this.unregisterConsoleGuard = null;
|
|
310
|
+
this.wasModal = false;
|
|
311
|
+
this.lastBlockLength = 0;
|
|
312
|
+
this.lastUserTurnCount = 0;
|
|
343
313
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
: { ...this.sessionInfo, ...info };
|
|
347
|
-
this.stage.invalidate();
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Claim the band and arm the exit safety net.
|
|
352
|
-
*
|
|
353
|
-
* The hook matters: if the process dies without going through stop(), the
|
|
354
|
-
* band's rows are ordinary terminal text and nothing is corrupted, but the
|
|
355
|
-
* session would not reach scrollback. A synchronous exit handler is enough
|
|
356
|
-
* because collapse and print-through are plain writes.
|
|
357
|
-
*/
|
|
358
|
-
open() {
|
|
359
|
-
// ONE row, not the whole screen.
|
|
360
|
-
//
|
|
361
|
-
// The band used to be born at `rows - 1` regardless of what it had to show.
|
|
362
|
-
// Measured at 156x78: the banner's 12 rows plus a 77-row band came to 89 on
|
|
363
|
-
// a 78-row screen, so the wordmark was scrolled 11 rows out of sight before
|
|
364
|
-
// the user had typed anything, and 73 of the 77 claimed rows were empty.
|
|
365
|
-
// present() grows it to fit what there actually is.
|
|
366
|
-
if (!this.stage.reserve(1)) return false;
|
|
367
|
-
this.unregisterConsoleGuard?.();
|
|
368
|
-
this.unregisterConsoleGuard = registerStageConsoleGuard(this);
|
|
369
|
-
if (this.out === process.stdout) setStageConsoleGuardActive(true);
|
|
370
|
-
if (!this.homeInfo) this.enableMouse();
|
|
371
|
-
this.armTeardown();
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
writeModeControl(sequence) {
|
|
376
|
-
if (!sequence) return;
|
|
377
|
-
runWithStageWrite(() => {
|
|
378
|
-
this.out.write(sequence);
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
syncTurnRailMotion(railHasTurns) {
|
|
383
|
-
if (!this.mouseOn || !this.mouseCaptured || !this.stage.reserved) return;
|
|
384
|
-
const preference = String(this.env?.CAUSYNE_MOUSE_HOVER ?? '').trim();
|
|
385
|
-
// Hover needs 1003, not just 1000. Limit default motion tracking to
|
|
386
|
-
// visible turn rails; preserve explicit opt-in and opt-out preferences.
|
|
387
|
-
const wantMotion = preference === '1' || (preference !== '0' && railHasTurns);
|
|
388
|
-
if (this.mouseMotionOn === wantMotion) return;
|
|
389
|
-
this.writeModeControl(mouseHoverTracking(wantMotion, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
390
|
-
this.mouseMotionOn = wantMotion;
|
|
391
|
-
if (!wantMotion) {
|
|
392
|
-
// 1003 can replace 1000 in terminal tracking-mode state. When it is
|
|
393
|
-
// removed, explicitly restore 1000 or the wheel scrolls the shell.
|
|
394
|
-
this.writeModeControl(mouseTracking(true));
|
|
314
|
+
get width() {
|
|
315
|
+
return this.stage.width();
|
|
395
316
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
this.writeModeControl(mouseTracking(true));
|
|
401
|
-
this.writeModeControl(mouseHoverTracking(true, this.env));
|
|
402
|
-
this.mouseCaptured = true;
|
|
403
|
-
this.mouseOn = true;
|
|
404
|
-
this.mouseMotionOn = String(this.env?.CAUSYNE_MOUSE_HOVER ?? '') === '1';
|
|
405
|
-
return true;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
disableMouse(force = false) {
|
|
409
|
-
if (!force && !this.mouseOn && !this.mouseCaptured) return false;
|
|
410
|
-
// Restore terminal motion modes, including stale tracking from an interrupted turn.
|
|
411
|
-
this.writeModeControl(mouseHoverTracking(false, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
412
|
-
this.writeModeControl(mouseTracking(false));
|
|
413
|
-
this.mouseCaptured = false;
|
|
414
|
-
this.mouseOn = false;
|
|
415
|
-
this.mouseMotionOn = false;
|
|
416
|
-
this.detached = false;
|
|
417
|
-
return true;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
armTeardown() {
|
|
422
|
-
if (this.signalHooks.length > 0 || this.exitHook) this.disarmTeardown();
|
|
423
|
-
this.exitHook = () => { try { this.close(); } catch { /* nothing left to do */ } };
|
|
424
|
-
process.once('exit', this.exitHook);
|
|
425
|
-
|
|
426
|
-
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
427
|
-
const handler = () => {
|
|
428
|
-
try { this.close(); } catch { /* keep going: the exit matters more */ }
|
|
429
|
-
// Re-raise the conventional status so a caller waiting on us still sees
|
|
430
|
-
// that we were signalled rather than that we exited cleanly.
|
|
431
|
-
process.exit(128 + { SIGINT: 2, SIGTERM: 15, SIGHUP: 1 }[signal]);
|
|
432
|
-
};
|
|
433
|
-
process.on(signal, handler);
|
|
434
|
-
this.signalHooks.push([signal, handler]);
|
|
317
|
+
composeAvailableWidth() {
|
|
318
|
+
if (this.homeInfo)
|
|
319
|
+
return this.width;
|
|
320
|
+
return sessionMainWidth(this.width, false, this.env);
|
|
435
321
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
322
|
+
/** Home is compact; a session uses its full conversation column. */
|
|
323
|
+
composeWidth() {
|
|
324
|
+
if (this.homeInfo)
|
|
325
|
+
return composerWidth(this.width);
|
|
326
|
+
const mainWidth = sessionMainWidth(this.width, false, this.env);
|
|
327
|
+
return sessionComposerWidth(mainWidth);
|
|
442
328
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
this.unregisterConsoleGuard();
|
|
452
|
-
this.unregisterConsoleGuard = null;
|
|
453
|
-
if (this.out === process.stdout) setStageConsoleGuardActive(false);
|
|
329
|
+
/** Keep Home distinct from a selected or newly started conversation. */
|
|
330
|
+
enterHome(info) {
|
|
331
|
+
this.homeInfo = info;
|
|
332
|
+
this.disableMouse();
|
|
333
|
+
this.homeSessionSelected = false;
|
|
334
|
+
this.sessionInfo = { title: 'Untitled', cwd: info?.cwd, provider: info?.provider, model: info?.model };
|
|
335
|
+
this.fullSession = true;
|
|
336
|
+
this.stage.invalidate();
|
|
454
337
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Hand the terminal back to something that is about to write to it directly,
|
|
465
|
-
* then take it again.
|
|
466
|
-
*
|
|
467
|
-
* Anything spawned with stdio: 'inherit' writes straight into the band and
|
|
468
|
-
* the diff has no idea it happened. Causyne has four such call sites today
|
|
469
|
-
* (autoUpdate's two npm installs, the cortex provisioner, the capability
|
|
470
|
-
* provisioner); none of them is wired to this yet, and that is recorded as an
|
|
471
|
-
* open item rather than left to be discovered.
|
|
472
|
-
*/
|
|
473
|
-
suspend() {
|
|
474
|
-
if (!this.stage.reserved) return false;
|
|
475
|
-
this.disableMouse();
|
|
476
|
-
if (this.unregisterConsoleGuard) {
|
|
477
|
-
this.unregisterConsoleGuard();
|
|
478
|
-
this.unregisterConsoleGuard = null;
|
|
479
|
-
if (this.out === process.stdout) setStageConsoleGuardActive(false);
|
|
338
|
+
leaveHome(sessionSelected = false) {
|
|
339
|
+
if (this.homeInfo)
|
|
340
|
+
this.stage.invalidate();
|
|
341
|
+
this.homeInfo = null;
|
|
342
|
+
this.enableMouse();
|
|
343
|
+
if (sessionSelected)
|
|
344
|
+
this.homeSessionSelected = true;
|
|
480
345
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
/** Everything the session produced, oldest first. */
|
|
497
|
-
snapshot() {
|
|
498
|
-
return this.evicted.concat(this.transcript.snapshot(this.width));
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
absorbEvicted(rows) {
|
|
502
|
-
for (const row of rows) this.evicted.push(row);
|
|
503
|
-
if (this.evicted.length > MAX_EVICTED_ROWS) {
|
|
504
|
-
this.evicted.splice(0, this.evicted.length - MAX_EVICTED_ROWS);
|
|
346
|
+
setSessionInfo(info) {
|
|
347
|
+
const changedSession = Boolean(info?.id && this.sessionInfo?.id && info.id !== this.sessionInfo.id);
|
|
348
|
+
if (changedSession) {
|
|
349
|
+
// Sidebar plans and turn hover coordinates belong to the previous chat.
|
|
350
|
+
this.sidebarPlan = [];
|
|
351
|
+
this.hoveredTurnIndex = null;
|
|
352
|
+
this.hoveredTurnAnchorY = null;
|
|
353
|
+
this.activeTurnIndex = null;
|
|
354
|
+
this.hoveredMessageFrameId = null;
|
|
355
|
+
this.turnRailLayout = null;
|
|
356
|
+
}
|
|
357
|
+
this.sessionInfo = changedSession
|
|
358
|
+
? { ...this.sessionInfo, activeSkill: null, contextChars: 0, ...info }
|
|
359
|
+
: { ...this.sessionInfo, ...info };
|
|
360
|
+
this.stage.invalidate();
|
|
505
361
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Claim the band and arm the exit safety net.
|
|
364
|
+
*/
|
|
365
|
+
open() {
|
|
366
|
+
if (!this.stage.reserve(1))
|
|
367
|
+
return false;
|
|
368
|
+
this.unregisterConsoleGuard?.();
|
|
369
|
+
this.unregisterConsoleGuard = registerStageConsoleGuard(this);
|
|
370
|
+
if (this.out === process.stdout)
|
|
371
|
+
setStageConsoleGuardActive(true);
|
|
372
|
+
if (!this.homeInfo)
|
|
373
|
+
this.enableMouse();
|
|
374
|
+
this.armTeardown();
|
|
375
|
+
return true;
|
|
513
376
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
377
|
+
writeModeControl(sequence) {
|
|
378
|
+
if (!sequence || !this.out || typeof this.out.write !== 'function')
|
|
379
|
+
return;
|
|
380
|
+
runWithStageWrite(() => {
|
|
381
|
+
this.out.write(sequence);
|
|
382
|
+
});
|
|
518
383
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
// The interface ChatPrompt calls
|
|
536
|
-
// -------------------------------------------------------------------------
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Append a permanent frame. `produce` must be a pure function of width — see
|
|
540
|
-
* the contract in transcript.js.
|
|
541
|
-
*/
|
|
542
|
-
commit(kind, produce, meta = null) {
|
|
543
|
-
return this.transcript.append({ kind, produce, meta });
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Paint the band: viewport on top, the prompt's own rows underneath.
|
|
548
|
-
*/
|
|
549
|
-
present(promptRows, caret = null) {
|
|
550
|
-
if (!this.stage.reserved) return 0;
|
|
551
|
-
|
|
552
|
-
if (!this.messageActionOverlay) {
|
|
553
|
-
this.lastPromptRows = promptRows;
|
|
554
|
-
this.lastPromptCaret = caret;
|
|
384
|
+
syncTurnRailMotion(railHasTurns) {
|
|
385
|
+
if (!this.mouseOn || !this.mouseCaptured || !this.stage.reserved)
|
|
386
|
+
return;
|
|
387
|
+
const preference = String(this.env?.CAUSYNE_MOUSE_HOVER ?? '').trim();
|
|
388
|
+
// Hover needs 1003, not just 1000. Limit default motion tracking to
|
|
389
|
+
// visible turn rails; preserve explicit opt-in and opt-out preferences.
|
|
390
|
+
const wantMotion = preference === '1' || (preference !== '0' && railHasTurns);
|
|
391
|
+
if (this.mouseMotionOn === wantMotion)
|
|
392
|
+
return;
|
|
393
|
+
this.writeModeControl(mouseHoverTracking(wantMotion, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
394
|
+
this.mouseMotionOn = wantMotion;
|
|
395
|
+
if (!wantMotion) {
|
|
396
|
+
// 1003 can replace 1000 in terminal tracking-mode state. When it is
|
|
397
|
+
// removed, explicitly restore 1000 or the wheel scrolls the shell.
|
|
398
|
+
this.writeModeControl(mouseTracking(true));
|
|
399
|
+
}
|
|
555
400
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
this.stage.invalidate();
|
|
401
|
+
enableMouse() {
|
|
402
|
+
if (this.homeInfo || !this.mouseWanted || this.mouseOn || !this.stage.reserved)
|
|
403
|
+
return false;
|
|
404
|
+
this.writeModeControl(mouseTracking(true));
|
|
405
|
+
this.writeModeControl(mouseHoverTracking(true, this.env));
|
|
406
|
+
this.mouseCaptured = true;
|
|
407
|
+
this.mouseOn = true;
|
|
408
|
+
this.mouseMotionOn = String(this.env?.CAUSYNE_MOUSE_HOVER ?? '') === '1';
|
|
409
|
+
return true;
|
|
566
410
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
this.
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
: placeHome(this.homeInfo, promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0);
|
|
579
|
-
return this.stage.paint(view.rows, { row: view.caretRow, col: view.caretCol, hideCursor: caret?.hideCursor });
|
|
411
|
+
disableMouse(force = false) {
|
|
412
|
+
if (!force && !this.mouseOn && !this.mouseCaptured)
|
|
413
|
+
return false;
|
|
414
|
+
// Restore terminal motion modes, including stale tracking from an interrupted turn.
|
|
415
|
+
this.writeModeControl(mouseHoverTracking(false, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
416
|
+
this.writeModeControl(mouseTracking(false));
|
|
417
|
+
this.mouseCaptured = false;
|
|
418
|
+
this.mouseOn = false;
|
|
419
|
+
this.mouseMotionOn = false;
|
|
420
|
+
this.detached = false;
|
|
421
|
+
return true;
|
|
580
422
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
const desired = Math.max(
|
|
603
|
-
sessionStageHeight(this.stage.maxHeight, block.length, contentRows, this.fullSession || caret?.inline),
|
|
604
|
-
neededWithFloor
|
|
605
|
-
);
|
|
606
|
-
if (desired > this.stage.height) this.stage.grow(desired - this.stage.height);
|
|
607
|
-
|
|
608
|
-
const height = this.stage.height;
|
|
609
|
-
|
|
610
|
-
// The prompt may not eat the whole band — but only once there is a
|
|
611
|
-
// transcript for it to eat. Trim from the TOP when it would: the status
|
|
612
|
-
// footer and the caret row are the last rows and the ones worth keeping,
|
|
613
|
-
// and an input box that has scrolled its own oldest row off is a smaller lie
|
|
614
|
-
// than a transcript that has vanished.
|
|
615
|
-
const floor = contentRows > 0 ? MIN_VIEWPORT_ROWS : 0;
|
|
616
|
-
const maxBlock = Math.max(1, height - floor);
|
|
617
|
-
if (block.length > maxBlock) {
|
|
618
|
-
const cut = block.length - maxBlock;
|
|
619
|
-
block = block.slice(cut);
|
|
620
|
-
caretRow = Math.max(0, caretRow - cut);
|
|
423
|
+
armTeardown() {
|
|
424
|
+
if (this.signalHooks.length > 0 || this.exitHook)
|
|
425
|
+
this.disarmTeardown();
|
|
426
|
+
this.exitHook = () => { try {
|
|
427
|
+
this.close();
|
|
428
|
+
}
|
|
429
|
+
catch { /* nothing left to do */ } };
|
|
430
|
+
process.once('exit', this.exitHook);
|
|
431
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
432
|
+
const handler = () => {
|
|
433
|
+
try {
|
|
434
|
+
this.close();
|
|
435
|
+
}
|
|
436
|
+
catch { /* keep going: the exit matters more */ }
|
|
437
|
+
// Re-raise the conventional status so a caller waiting on us still sees
|
|
438
|
+
// that we were signalled rather than that we exited cleanly.
|
|
439
|
+
process.exit(128 + SIGNAL_EXIT_CODES[signal]);
|
|
440
|
+
};
|
|
441
|
+
process.on(signal, handler);
|
|
442
|
+
this.signalHooks.push([signal, handler]);
|
|
443
|
+
}
|
|
621
444
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
445
|
+
disarmTeardown() {
|
|
446
|
+
if (this.exitHook) {
|
|
447
|
+
process.removeListener('exit', this.exitHook);
|
|
448
|
+
this.exitHook = null;
|
|
449
|
+
}
|
|
450
|
+
for (const [signal, handler] of this.signalHooks)
|
|
451
|
+
process.removeListener(signal, handler);
|
|
452
|
+
this.signalHooks = [];
|
|
626
453
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
// In follow mode, the viewport can land on the blank separator between
|
|
636
|
-
// two assistant frames after enough replies to fill the band. Show a
|
|
637
|
-
// subtle boundary marker in that same row instead of a visible void.
|
|
638
|
-
// Do not shift row indices: rails, hover targets and reading anchors
|
|
639
|
-
// are keyed to the original transcript row positions.
|
|
640
|
-
if (this.viewport.following && this.viewport.maxScrollTop() > 0
|
|
641
|
-
&& rows.length > 0 && stripAnsi(rows[0] || '').trim() === ''
|
|
642
|
-
&& rows.some(row => stripAnsi(row).trim() !== '')) {
|
|
643
|
-
rows[0] = paint('rule', ` ${GLYPHS.dot} `);
|
|
644
|
-
}
|
|
645
|
-
this.decorate(rows, contentWidth);
|
|
646
|
-
markHoveredMessage(rows, this, contentWidth);
|
|
647
|
-
if (rail) {
|
|
648
|
-
this.attachRail(rows, contentWidth);
|
|
649
|
-
} else {
|
|
650
|
-
this.turnRailLayout = null;
|
|
651
|
-
this.hoveredTurnIndex = null;
|
|
652
|
-
this.hoveredTurnAnchorY = null;
|
|
653
|
-
}
|
|
654
|
-
if (this.hoveredTurnIndex && this.turnRailLayout?.turns?.length) {
|
|
655
|
-
const hoveredTurn = this.turnRailLayout.turns.find(t => t.turnIndex === this.hoveredTurnIndex);
|
|
656
|
-
if (hoveredTurn) {
|
|
657
|
-
const groupRow = this.turnRailLayout?.dotRows?.get(hoveredTurn.turnIndex);
|
|
658
|
-
const group = this.turnRailLayout?.rowToTurns?.get(groupRow) || [hoveredTurn];
|
|
659
|
-
const timeline = group.length > 1
|
|
660
|
-
? renderTurnTimelineCard(group, Math.min(52, mainWidth - 5), rows.length, this.turnRailCardOffset || 0)
|
|
661
|
-
: null;
|
|
662
|
-
const card = timeline?.rows || renderTurnPreviewCard(hoveredTurn, 52);
|
|
663
|
-
const anchorY = this.hoveredTurnAnchorY ?? Math.floor(rows.length / 2);
|
|
664
|
-
rows = overlayTurnPreviewCard(rows, card, anchorY, this.turnRailLayout?.railX ?? 1, mainWidth);
|
|
665
|
-
if (this.turnRailLayout) {
|
|
666
|
-
const cardWidth = visibleWidth(card[0] || '') || 52;
|
|
667
|
-
const railX = this.turnRailLayout.railX ?? 1;
|
|
668
|
-
const safeAnchorY = Number.isFinite(anchorY) ? Math.floor(anchorY) : Math.floor(rows.length / 2);
|
|
669
|
-
let cardX = railX - cardWidth - 1;
|
|
670
|
-
if (railX <= 4 && railX + 2 < mainWidth) {
|
|
671
|
-
cardX = railX + 2;
|
|
672
|
-
} else if (cardX < 0) {
|
|
673
|
-
cardX = Math.max(0, Math.min(mainWidth - cardWidth - 1, railX + 2));
|
|
674
|
-
}
|
|
675
|
-
const effectiveCardWidth = Math.max(1, Math.min(cardWidth, Math.max(1, mainWidth - cardX)));
|
|
676
|
-
const startY = Math.max(0, Math.min(rows.length - card.length, safeAnchorY - Math.floor(card.length / 2)));
|
|
677
|
-
const visibleCardHeight = Math.min(card.length, Math.max(0, rows.length - startY));
|
|
678
|
-
this.turnRailLayout.cardRect = {
|
|
679
|
-
x: cardX, y: startY, width: effectiveCardWidth, height: visibleCardHeight,
|
|
680
|
-
turnIndex: hoveredTurn.turnIndex,
|
|
681
|
-
entries: timeline?.entries || null,
|
|
682
|
-
entryStart: timeline?.entryStart ?? null,
|
|
683
|
-
groupTurns: group.length > 1 ? group : null,
|
|
684
|
-
maxOffset: timeline?.maxOffset || 0
|
|
685
|
-
};
|
|
686
|
-
}
|
|
454
|
+
close() {
|
|
455
|
+
// Force the terminal to release tracking, even if internal flags were stale.
|
|
456
|
+
this.disableMouse(true);
|
|
457
|
+
if (this.unregisterConsoleGuard) {
|
|
458
|
+
this.unregisterConsoleGuard();
|
|
459
|
+
this.unregisterConsoleGuard = null;
|
|
460
|
+
if (this.out === process.stdout)
|
|
461
|
+
setStageConsoleGuardActive(false);
|
|
687
462
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
messageBounds: overlay.layer.messageBounds,
|
|
698
|
-
dimBackdrop: true
|
|
699
|
-
});
|
|
700
|
-
rows = placed.rows;
|
|
701
|
-
overlay.layer.actionLayout = placed.layout;
|
|
702
|
-
}
|
|
703
|
-
} else {
|
|
704
|
-
this.turnRailLayout = null;
|
|
705
|
-
this.hoveredTurnIndex = null;
|
|
706
|
-
this.hoveredTurnAnchorY = null;
|
|
463
|
+
if (!this.stage.reserved) {
|
|
464
|
+
this.disarmTeardown();
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
const rows = this.snapshot();
|
|
468
|
+
this.stage.collapse();
|
|
469
|
+
this.stage.printThrough(rows);
|
|
470
|
+
this.disarmTeardown();
|
|
471
|
+
return true;
|
|
707
472
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}, mainRows.length, panelWidth) : [];
|
|
721
|
-
const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth, panelWidth) : mainRows;
|
|
722
|
-
return this.stage.paint(painted, {
|
|
723
|
-
row: rows.length + caretRow,
|
|
724
|
-
// The composer may never put its caret into the sidebar or the reserved
|
|
725
|
-
// right margin, even if layout measurements differ after a resize.
|
|
726
|
-
col: Math.max(0, Math.min(mainWidth - 2, Number.isFinite(caretCol) ? Math.floor(caretCol) : 0)),
|
|
727
|
-
hideCursor: caret?.hideCursor
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/** Draw message actions over the transcript while retaining the live composer. */
|
|
732
|
-
presentMessageActions(panel, layer) {
|
|
733
|
-
this.messageActionOverlay = { panel, layer };
|
|
734
|
-
try {
|
|
735
|
-
return this.present(this.lastPromptRows, this.lastPromptCaret);
|
|
736
|
-
} finally {
|
|
737
|
-
this.messageActionOverlay = null;
|
|
473
|
+
suspend() {
|
|
474
|
+
if (!this.stage.reserved)
|
|
475
|
+
return false;
|
|
476
|
+
this.disableMouse();
|
|
477
|
+
if (this.unregisterConsoleGuard) {
|
|
478
|
+
this.unregisterConsoleGuard();
|
|
479
|
+
this.unregisterConsoleGuard = null;
|
|
480
|
+
if (this.out === process.stdout)
|
|
481
|
+
setStageConsoleGuardActive(false);
|
|
482
|
+
}
|
|
483
|
+
this.stage.collapse();
|
|
484
|
+
return true;
|
|
738
485
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
const count = state.unseen;
|
|
753
|
-
const label = count > 0
|
|
754
|
-
? `${GLYPHS.arrow} ${count} new below`
|
|
755
|
-
: `${GLYPHS.arrow} scrolled up`;
|
|
756
|
-
const hint = `${label} ${GLYPHS.dot} shift+pgdn to follow`;
|
|
757
|
-
rows[rows.length - 1] = paint('accent', truncate(hint, Math.max(8, width - 1), GLYPHS.ellipsis));
|
|
758
|
-
return rows;
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Ctrl+L: flush what is on the stage into real scrollback, then start clean.
|
|
763
|
-
*
|
|
764
|
-
* In a terminal, ctrl+L clears the screen and your history is still in
|
|
765
|
-
* scrollback. Clearing the transcript alone would destroy the session record,
|
|
766
|
-
* which is not what the key means — so print it through first. This is also
|
|
767
|
-
* the escape hatch for getting a transcript into the terminal without exiting.
|
|
768
|
-
*/
|
|
769
|
-
flushAndClear() {
|
|
770
|
-
const rows = this.snapshot();
|
|
771
|
-
this.stage.collapse();
|
|
772
|
-
this.stage.printThrough(rows);
|
|
773
|
-
this.evicted = [];
|
|
774
|
-
this.transcript.clear();
|
|
775
|
-
this.lastHeight = 0;
|
|
776
|
-
this.stage.reserve();
|
|
777
|
-
this.stage.invalidate();
|
|
778
|
-
this.viewport.toBottom();
|
|
779
|
-
return rows.length;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
/** Clear the transcript without printing through to scrollback (for session switching). */
|
|
783
|
-
clearTranscript() {
|
|
784
|
-
this.evicted = [];
|
|
785
|
-
this.transcript.clear();
|
|
786
|
-
this.lastHeight = 0;
|
|
787
|
-
this.lastUserTurnCount = 0;
|
|
788
|
-
this.activeTurnIndex = null;
|
|
789
|
-
this.hoveredTurnIndex = null;
|
|
790
|
-
this.hoveredTurnAnchorY = null;
|
|
791
|
-
this.turnRailLayout = null;
|
|
792
|
-
this.stage.invalidate();
|
|
793
|
-
if (this.viewport) {
|
|
794
|
-
this.viewport.manual = false;
|
|
795
|
-
this.viewport.unseen = 0;
|
|
796
|
-
this.viewport.toBottom();
|
|
486
|
+
resume() {
|
|
487
|
+
if (this.stage.reserved)
|
|
488
|
+
return false;
|
|
489
|
+
if (!this.stage.reserve())
|
|
490
|
+
return false;
|
|
491
|
+
this.unregisterConsoleGuard?.();
|
|
492
|
+
this.unregisterConsoleGuard = registerStageConsoleGuard(this);
|
|
493
|
+
if (this.out === process.stdout)
|
|
494
|
+
setStageConsoleGuardActive(true);
|
|
495
|
+
this.stage.invalidate();
|
|
496
|
+
this.enableMouse();
|
|
497
|
+
return true;
|
|
797
498
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
* The terminal changed size. Callers must debounce — ChatPrompt already
|
|
802
|
-
* settles resize at RESIZE_SETTLE_MS.
|
|
803
|
-
*/
|
|
804
|
-
resize() {
|
|
805
|
-
const next = stageHeight(this.out, this.env);
|
|
806
|
-
if (next < 1) {
|
|
807
|
-
// The terminal became too short to hold a stage. Give the band back and
|
|
808
|
-
// let the caller fall through to the scrollback renderer rather than
|
|
809
|
-
// painting into a region that cannot hold a viewport.
|
|
810
|
-
this.close();
|
|
811
|
-
return false;
|
|
499
|
+
/** Everything the session produced, oldest first. */
|
|
500
|
+
snapshot() {
|
|
501
|
+
return this.evicted.concat(this.transcript.snapshot(this.width));
|
|
812
502
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
if (columns !== this.lastColumns || next !== this.stage.maxHeight) {
|
|
820
|
-
this.hoveredTurnIndex = null;
|
|
821
|
-
this.hoveredTurnAnchorY = null;
|
|
503
|
+
absorbEvicted(rows) {
|
|
504
|
+
for (const row of rows)
|
|
505
|
+
this.evicted.push(row);
|
|
506
|
+
if (this.evicted.length > MAX_EVICTED_ROWS) {
|
|
507
|
+
this.evicted.splice(0, this.evicted.length - MAX_EVICTED_ROWS);
|
|
508
|
+
}
|
|
822
509
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
510
|
+
handleChange() {
|
|
511
|
+
if (!this.transcript.isEmpty())
|
|
512
|
+
this.opened = true;
|
|
513
|
+
let userTurns = 0;
|
|
514
|
+
for (const frame of this.transcript.frames) {
|
|
515
|
+
if (frame && frame.kind === 'user')
|
|
516
|
+
userTurns++;
|
|
517
|
+
}
|
|
518
|
+
if (userTurns > this.lastUserTurnCount) {
|
|
519
|
+
this.activeTurnIndex = null;
|
|
520
|
+
this.hoveredTurnIndex = null;
|
|
521
|
+
this.hoveredTurnAnchorY = null;
|
|
522
|
+
}
|
|
523
|
+
this.lastUserTurnCount = userTurns;
|
|
524
|
+
const before = this.lastHeight;
|
|
525
|
+
const mainWidth = sessionMainWidth(this.width, false, this.env);
|
|
526
|
+
const contentWidth = this.railEnabled(mainWidth)
|
|
527
|
+
? Math.max(20, mainWidth - RAIL_BUDGET - (hasSessionTurns(this.transcript) ? TURN_RAIL_BUDGET : 0))
|
|
528
|
+
: mainWidth;
|
|
529
|
+
const after = this.transcript.height(contentWidth);
|
|
530
|
+
this.lastHeight = after;
|
|
531
|
+
// Growth is what drives auto-scroll. Handing the delta over is also what
|
|
532
|
+
// lets the "N new below" affordance count only what arrived while the user
|
|
533
|
+
// was reading somewhere else.
|
|
534
|
+
this.viewport.refresh(Math.max(0, after - before));
|
|
535
|
+
if (this.onDirty)
|
|
536
|
+
this.onDirty();
|
|
829
537
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
//
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
// Checkpoints, user turns, approvals, and errors remain discoverable.
|
|
879
|
-
if ((RAIL_PRIORITY[marker.kind] || 0) < 50) continue;
|
|
880
|
-
let markerRow = marker.row;
|
|
881
|
-
if (marker.kind === 'user' && flatRows.length > 0) {
|
|
882
|
-
const nextRow = mIdx + 1 < markers.length ? markers[mIdx + 1].row : flatRows.length;
|
|
883
|
-
if (markerRow + 1 < nextRow && markerRow + 1 < flatRows.length) {
|
|
884
|
-
const firstLine = stripAnsi(String(flatRows[markerRow] ?? '')).trim();
|
|
885
|
-
const secondLine = stripAnsi(String(flatRows[markerRow + 1] ?? '')).trim();
|
|
886
|
-
if (firstLine === '' && secondLine !== '') markerRow += 1;
|
|
538
|
+
// -------------------------------------------------------------------------
|
|
539
|
+
// The interface ChatPrompt calls
|
|
540
|
+
// -------------------------------------------------------------------------
|
|
541
|
+
/**
|
|
542
|
+
* Append a permanent frame. `produce` must be a pure function of width — see
|
|
543
|
+
* the contract in transcript.js.
|
|
544
|
+
*/
|
|
545
|
+
commit(kind, produce, meta = null) {
|
|
546
|
+
return this.transcript.append({ kind, produce, meta });
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Paint the band: viewport on top, the prompt's own rows underneath.
|
|
550
|
+
*/
|
|
551
|
+
present(promptRows, caret = null) {
|
|
552
|
+
if (!this.stage.reserved)
|
|
553
|
+
return 0;
|
|
554
|
+
const safePromptRows = Array.isArray(promptRows) ? promptRows : [];
|
|
555
|
+
promptRows = safePromptRows;
|
|
556
|
+
if (!this.messageActionOverlay) {
|
|
557
|
+
this.lastPromptRows = promptRows;
|
|
558
|
+
this.lastPromptCaret = caret;
|
|
559
|
+
}
|
|
560
|
+
// Do not grow, resize, or invalidate the band while the terminal owns
|
|
561
|
+
// scrollback; otherwise stage.grow emits newlines that shift the user's
|
|
562
|
+
// scroll position before the detached repaint guard below.
|
|
563
|
+
if (this.detached)
|
|
564
|
+
return false;
|
|
565
|
+
const isModal = Boolean(caret?.modal);
|
|
566
|
+
if (isModal !== this.wasModal) {
|
|
567
|
+
this.wasModal = isModal;
|
|
568
|
+
this.stage.invalidate();
|
|
569
|
+
}
|
|
570
|
+
if (this.homeInfo || (caret?.modal && !caret?.inline)) {
|
|
571
|
+
this.syncTurnRailMotion(false);
|
|
572
|
+
this.turnRailLayout = null;
|
|
573
|
+
this.hoveredTurnIndex = null;
|
|
574
|
+
this.hoveredTurnAnchorY = null;
|
|
575
|
+
if (this.stage.height < this.stage.maxHeight) {
|
|
576
|
+
this.stage.grow(this.stage.maxHeight - this.stage.height);
|
|
577
|
+
}
|
|
578
|
+
const view = caret?.modal
|
|
579
|
+
? placeDialog(promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0)
|
|
580
|
+
: placeHome(this.homeInfo || {}, promptRows, this.width, this.stage.height, caret?.row ?? 0, caret?.col ?? 0);
|
|
581
|
+
return this.stage.paint(view.rows, {
|
|
582
|
+
row: view.caretRow,
|
|
583
|
+
col: view.caretCol,
|
|
584
|
+
...(caret?.hideCursor !== undefined ? { hideCursor: caret.hideCursor } : {})
|
|
585
|
+
});
|
|
887
586
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
587
|
+
const width = this.width;
|
|
588
|
+
const sidebar = sidebarVisible(width, false, this.env);
|
|
589
|
+
const mainWidth = sessionMainWidth(width, false, this.env);
|
|
590
|
+
const rail = this.railEnabled(mainWidth);
|
|
591
|
+
const contentWidth = rail
|
|
592
|
+
? Math.max(20, mainWidth - RAIL_BUDGET - (hasSessionTurns(this.transcript) ? TURN_RAIL_BUDGET : 0))
|
|
593
|
+
: mainWidth;
|
|
594
|
+
let block = Array.isArray(promptRows) && promptRows.length > 0 ? promptRows : [''];
|
|
595
|
+
let caretRow = caret && typeof caret.row === 'number' && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
|
|
596
|
+
const caretCol = caret && typeof caret.col === 'number' ? caret.col : 0;
|
|
597
|
+
const contentRows = this.transcript.height(contentWidth);
|
|
598
|
+
const minFloor = contentRows > 0 ? MIN_VIEWPORT_ROWS : 0;
|
|
599
|
+
const neededWithFloor = Math.min(this.stage.maxHeight, block.length + minFloor);
|
|
600
|
+
const desired = Math.max(sessionStageHeight(this.stage.maxHeight, block.length, contentRows, Boolean(this.fullSession || caret?.inline)), neededWithFloor);
|
|
601
|
+
if (desired > this.stage.height)
|
|
602
|
+
this.stage.grow(desired - this.stage.height);
|
|
603
|
+
const height = this.stage.height;
|
|
604
|
+
const floor = contentRows > 0 ? MIN_VIEWPORT_ROWS : 0;
|
|
605
|
+
const maxBlock = Math.max(1, height - floor);
|
|
606
|
+
if (block.length > maxBlock) {
|
|
607
|
+
const cut = block.length - maxBlock;
|
|
608
|
+
block = block.slice(cut);
|
|
609
|
+
caretRow = Math.max(0, caretRow - cut);
|
|
610
|
+
}
|
|
611
|
+
caretRow = Math.max(0, Math.min(block.length - 1, Math.floor(caretRow)));
|
|
612
|
+
if (this.lastBlockLength > 0 && this.lastBlockLength !== block.length) {
|
|
613
|
+
this.stage.invalidate();
|
|
614
|
+
}
|
|
615
|
+
this.lastBlockLength = block.length;
|
|
616
|
+
const budget = Math.max(0, height - block.length);
|
|
617
|
+
this.syncTurnRailMotion(rail && budget > 0 && hasSessionTurns(this.transcript));
|
|
618
|
+
let rows = [];
|
|
619
|
+
if (budget > 0) {
|
|
620
|
+
this.viewport.resize({ height: budget, width: contentWidth });
|
|
621
|
+
rows = alignTranscriptRows(this.viewport.rows(), contentRows);
|
|
622
|
+
if (this.viewport.following && this.viewport.maxScrollTop() > 0
|
|
623
|
+
&& rows.length > 0 && stripAnsi(rows[0] || '').trim() === ''
|
|
624
|
+
&& rows.some(row => stripAnsi(row).trim() !== '')) {
|
|
625
|
+
rows[0] = paint('rule', ` ${GLYPHS.dot} `);
|
|
626
|
+
}
|
|
627
|
+
this.decorate(rows, contentWidth);
|
|
628
|
+
markHoveredMessage(rows, this, contentWidth);
|
|
629
|
+
if (rail) {
|
|
630
|
+
this.attachRail(rows, contentWidth);
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
this.turnRailLayout = null;
|
|
634
|
+
this.hoveredTurnIndex = null;
|
|
635
|
+
this.hoveredTurnAnchorY = null;
|
|
636
|
+
}
|
|
637
|
+
if (this.hoveredTurnIndex && this.turnRailLayout?.turns?.length) {
|
|
638
|
+
const hoveredTurn = this.turnRailLayout.turns.find((t) => t.turnIndex === this.hoveredTurnIndex);
|
|
639
|
+
if (hoveredTurn) {
|
|
640
|
+
const groupRow = this.turnRailLayout?.dotRows?.get(hoveredTurn.turnIndex);
|
|
641
|
+
const group = this.turnRailLayout?.rowToTurns?.get(groupRow) || [hoveredTurn];
|
|
642
|
+
const timeline = group.length > 1
|
|
643
|
+
? renderTurnTimelineCard(group, Math.min(52, mainWidth - 5), rows.length, this.turnRailCardOffset || 0)
|
|
644
|
+
: null;
|
|
645
|
+
const card = timeline?.rows || renderTurnPreviewCard(hoveredTurn, 52);
|
|
646
|
+
const anchorY = this.hoveredTurnAnchorY ?? Math.floor(rows.length / 2);
|
|
647
|
+
rows = overlayTurnPreviewCard(rows, card, anchorY, this.turnRailLayout?.railX ?? 1, mainWidth);
|
|
648
|
+
if (this.turnRailLayout) {
|
|
649
|
+
const cardWidth = visibleWidth(card[0] || '') || 52;
|
|
650
|
+
const railX = this.turnRailLayout.railX ?? 1;
|
|
651
|
+
const safeAnchorY = Number.isFinite(anchorY) ? Math.floor(anchorY) : Math.floor(rows.length / 2);
|
|
652
|
+
let cardX = railX - cardWidth - 1;
|
|
653
|
+
if (railX <= 4 && railX + 2 < mainWidth) {
|
|
654
|
+
cardX = railX + 2;
|
|
655
|
+
}
|
|
656
|
+
else if (cardX < 0) {
|
|
657
|
+
cardX = Math.max(0, Math.min(mainWidth - cardWidth - 1, railX + 2));
|
|
658
|
+
}
|
|
659
|
+
const effectiveCardWidth = Math.max(1, Math.min(cardWidth, Math.max(1, mainWidth - cardX)));
|
|
660
|
+
const startY = Math.max(0, Math.min(rows.length - card.length, safeAnchorY - Math.floor(card.length / 2)));
|
|
661
|
+
const visibleCardHeight = Math.min(card.length, Math.max(0, rows.length - startY));
|
|
662
|
+
this.turnRailLayout.cardRect = {
|
|
663
|
+
x: cardX, y: startY, width: effectiveCardWidth, height: visibleCardHeight,
|
|
664
|
+
turnIndex: hoveredTurn.turnIndex,
|
|
665
|
+
entries: timeline?.entries || null,
|
|
666
|
+
entryStart: timeline?.entryStart ?? null,
|
|
667
|
+
groupTurns: group.length > 1 ? group : null,
|
|
668
|
+
maxOffset: timeline?.maxOffset || 0
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
else if (this.turnRailLayout) {
|
|
674
|
+
this.turnRailLayout.cardRect = null;
|
|
675
|
+
}
|
|
676
|
+
if (this.messageActionOverlay) {
|
|
677
|
+
const overlay = this.messageActionOverlay;
|
|
678
|
+
const overlayWidth = rail ? Math.max(contentWidth, mainWidth - RAIL_BUDGET) : contentWidth;
|
|
679
|
+
const placed = placeMessageActionPanel(rows, overlay.panel, overlayWidth, Math.max(0, (this.out.rows || height) - height), overlay.layer.anchorY, overlay.layer.items.length, {
|
|
680
|
+
messageBounds: overlay.layer.messageBounds,
|
|
681
|
+
dimBackdrop: true
|
|
682
|
+
});
|
|
683
|
+
rows = placed.rows;
|
|
684
|
+
overlay.layer.actionLayout = placed.layout;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
this.turnRailLayout = null;
|
|
689
|
+
this.hoveredTurnIndex = null;
|
|
690
|
+
this.hoveredTurnAnchorY = null;
|
|
691
|
+
}
|
|
692
|
+
const mainRows = rows.concat(block);
|
|
693
|
+
const panelWidth = sidebar ? sessionSidebarWidth(width, false, this.env) : 0;
|
|
694
|
+
const panelRows = sidebar ? sessionSidebarRows({
|
|
695
|
+
...this.sessionInfo,
|
|
696
|
+
cwd: this.sidebarStatus?.cwd || this.sessionInfo?.cwd,
|
|
697
|
+
provider: this.sidebarStatus?.provider || this.sessionInfo?.provider,
|
|
698
|
+
model: this.sidebarStatus?.model || this.sessionInfo?.model,
|
|
699
|
+
contextChars: this.sidebarStatus?.contextChars ?? this.sessionInfo?.contextChars,
|
|
700
|
+
contextLimit: this.sidebarStatus?.contextLimit ?? this.sessionInfo?.contextLimit,
|
|
701
|
+
plan: this.sidebarPlan,
|
|
702
|
+
activeSkill: this.sessionInfo?.activeSkill
|
|
703
|
+
}, mainRows.length, panelWidth) : [];
|
|
704
|
+
const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth, panelWidth) : mainRows;
|
|
705
|
+
return this.stage.paint(painted, {
|
|
706
|
+
row: rows.length + caretRow,
|
|
707
|
+
// The composer may never put its caret into the sidebar or the reserved
|
|
708
|
+
// right margin, even if layout measurements differ after a resize.
|
|
709
|
+
col: Math.max(0, Math.min(mainWidth - 2, Number.isFinite(caretCol) ? Math.floor(caretCol) : 0)),
|
|
710
|
+
...(caret?.hideCursor !== undefined ? { hideCursor: caret.hideCursor } : {})
|
|
711
|
+
});
|
|
894
712
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
const cells = new Array(height);
|
|
906
|
-
for (let i = 0; i < height; i++) {
|
|
907
|
-
const inThumb = i >= from && i <= to;
|
|
908
|
-
const kind = kinds[i];
|
|
909
|
-
const loud = kind && (RAIL_PRIORITY[kind] || 0) >= RAIL_THUMB_YIELD;
|
|
910
|
-
if (kind && (!inThumb || loud)) cells[i] = railGlyph(kind);
|
|
911
|
-
else if (inThumb) cells[i] = paint('scroll', thumbGlyph(i - from, to - from + 1));
|
|
912
|
-
else cells[i] = ' ';
|
|
713
|
+
/** Draw message actions over the transcript while retaining the live composer. */
|
|
714
|
+
presentMessageActions(panel, layer) {
|
|
715
|
+
this.messageActionOverlay = { panel, layer };
|
|
716
|
+
try {
|
|
717
|
+
return this.present(this.lastPromptRows, this.lastPromptCaret);
|
|
718
|
+
}
|
|
719
|
+
finally {
|
|
720
|
+
this.messageActionOverlay = null;
|
|
721
|
+
}
|
|
913
722
|
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
const hasTurns = turns.length > 0;
|
|
926
|
-
const isAtBottom = typeof this.viewport?.atBottom === 'function' ? this.viewport.atBottom() : false;
|
|
927
|
-
const scrollTop = this.viewport.state().scrollTop;
|
|
928
|
-
const activeTurn = this.activeTurnIndex || resolveActiveTurnIndex(turns, scrollTop, rows.length, isAtBottom);
|
|
929
|
-
const railResult = hasTurns
|
|
930
|
-
? buildTurnRailCells(turns, rows.length, activeTurn, this.hoveredTurnIndex, scrollTop)
|
|
931
|
-
: null;
|
|
932
|
-
|
|
933
|
-
// Keep the original sparse rail. Cluster every turn behind the nearest
|
|
934
|
-
// *visible* dot so no unseen history becomes impossible to reach.
|
|
935
|
-
const rowToTurns = new Map();
|
|
936
|
-
const dotRows = [...(railResult?.layout?.rowToTurn?.keys() || [])].sort((a, b) => a - b);
|
|
937
|
-
for (const turn of turns) {
|
|
938
|
-
const rawRow = railResult?.layout?.dotRows?.get(turn.turnIndex);
|
|
939
|
-
if (!Number.isFinite(rawRow) || dotRows.length === 0) continue;
|
|
940
|
-
let nearest = dotRows[0];
|
|
941
|
-
let distance = Math.abs(rawRow - nearest);
|
|
942
|
-
for (const dotRow of dotRows) {
|
|
943
|
-
const delta = Math.abs(rawRow - dotRow);
|
|
944
|
-
if (delta < distance) {
|
|
945
|
-
nearest = dotRow;
|
|
946
|
-
distance = delta;
|
|
723
|
+
decorate(rows, width) {
|
|
724
|
+
const state = this.viewport.state();
|
|
725
|
+
if (state.following)
|
|
726
|
+
return rows;
|
|
727
|
+
const count = state.unseen;
|
|
728
|
+
const label = count > 0
|
|
729
|
+
? `${GLYPHS.arrow} ${count} new below`
|
|
730
|
+
: `${GLYPHS.arrow} scrolled up`;
|
|
731
|
+
const hint = `${label} ${GLYPHS.dot} shift+pgdn to follow`;
|
|
732
|
+
if (rows.length > 0) {
|
|
733
|
+
rows[rows.length - 1] = paint('accent', truncate(hint, Math.max(8, width - 1), GLYPHS.ellipsis));
|
|
947
734
|
}
|
|
948
|
-
|
|
949
|
-
if (!rowToTurns.has(nearest)) rowToTurns.set(nearest, []);
|
|
950
|
-
rowToTurns.get(nearest).push(turn);
|
|
735
|
+
return rows;
|
|
951
736
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
737
|
+
flushAndClear() {
|
|
738
|
+
const rows = this.snapshot();
|
|
739
|
+
this.stage.collapse();
|
|
740
|
+
this.stage.printThrough(rows);
|
|
741
|
+
this.evicted = [];
|
|
742
|
+
this.transcript.clear();
|
|
743
|
+
this.lastHeight = 0;
|
|
744
|
+
this.stage.reserve();
|
|
745
|
+
this.stage.invalidate();
|
|
746
|
+
this.viewport.toBottom();
|
|
747
|
+
return rows.length;
|
|
748
|
+
}
|
|
749
|
+
/** Clear the transcript without printing through to scrollback (for session switching). */
|
|
750
|
+
clearTranscript() {
|
|
751
|
+
this.evicted = [];
|
|
752
|
+
this.transcript.clear();
|
|
753
|
+
this.lastHeight = 0;
|
|
754
|
+
this.lastUserTurnCount = 0;
|
|
755
|
+
this.activeTurnIndex = null;
|
|
756
|
+
this.hoveredTurnIndex = null;
|
|
757
|
+
this.hoveredTurnAnchorY = null;
|
|
758
|
+
this.turnRailLayout = null;
|
|
759
|
+
this.stage.invalidate();
|
|
760
|
+
if (this.viewport) {
|
|
761
|
+
this.viewport.manual = false;
|
|
762
|
+
this.viewport.unseen = 0;
|
|
763
|
+
this.viewport.toBottom();
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
resize() {
|
|
767
|
+
const next = stageHeight(this.out, this.env);
|
|
768
|
+
if (next < 1) {
|
|
769
|
+
this.close();
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
const columns = this.stage.width();
|
|
773
|
+
if (columns !== this.lastColumns || next !== this.stage.maxHeight) {
|
|
774
|
+
this.hoveredTurnIndex = null;
|
|
775
|
+
this.hoveredTurnAnchorY = null;
|
|
776
|
+
}
|
|
777
|
+
if (!this.stage.reserved || next !== this.stage.maxHeight) {
|
|
778
|
+
this.stage.resize(next, 1);
|
|
779
|
+
}
|
|
780
|
+
else if (columns !== this.lastColumns && !this.detached) {
|
|
781
|
+
this.stage.reanchor();
|
|
782
|
+
}
|
|
783
|
+
this.lastColumns = columns;
|
|
784
|
+
this.stage.invalidate();
|
|
785
|
+
const mainWidth = sessionMainWidth(this.width, false, this.env);
|
|
786
|
+
const contentWidth = this.railEnabled(mainWidth)
|
|
787
|
+
? Math.max(20, mainWidth - RAIL_BUDGET - (hasSessionTurns(this.transcript) ? TURN_RAIL_BUDGET : 0))
|
|
788
|
+
: mainWidth;
|
|
789
|
+
this.viewport.resize({ height: Math.max(MIN_VIEWPORT_ROWS, this.stage.height - 2), width: contentWidth });
|
|
790
|
+
this.lastHeight = this.transcript.height(contentWidth);
|
|
791
|
+
return this.stage.reserved;
|
|
792
|
+
}
|
|
793
|
+
railEnabled(width) {
|
|
794
|
+
if (String(this.env.CAUSYNE_RAIL ?? '1') === '0')
|
|
795
|
+
return false;
|
|
796
|
+
return width >= RAIL_MIN_WIDTH;
|
|
797
|
+
}
|
|
798
|
+
buildRail(height, contentWidth) {
|
|
799
|
+
const flat = typeof this.transcript.flatten === 'function' ? this.transcript.flatten(contentWidth) : null;
|
|
800
|
+
const flatRows = Array.isArray(flat?.rows) ? flat.rows : [];
|
|
801
|
+
const markers = Array.isArray(flat?.markers) ? flat.markers : this.transcript.markers(contentWidth);
|
|
802
|
+
const rawTotal = Math.max(0, flat ? flatRows.length : this.transcript.height(contentWidth));
|
|
803
|
+
const total = Math.max(1, rawTotal);
|
|
804
|
+
const padding = rawTotal <= height ? Math.max(0, height - rawTotal) : 0;
|
|
805
|
+
const slotOf = (row) => (rawTotal <= height
|
|
806
|
+
? Math.max(0, Math.min(height - 1, padding + row))
|
|
807
|
+
: Math.max(0, Math.min(height - 1, Math.floor((row / total) * height))));
|
|
808
|
+
const kinds = new Array(height).fill(null);
|
|
809
|
+
for (let mIdx = 0; mIdx < markers.length; mIdx++) {
|
|
810
|
+
const marker = markers[mIdx];
|
|
811
|
+
if (!marker)
|
|
812
|
+
continue;
|
|
813
|
+
if (railPriority(marker.kind) < 50)
|
|
814
|
+
continue;
|
|
815
|
+
let markerRow = marker.row;
|
|
816
|
+
if (marker.kind === 'user' && flatRows.length > 0) {
|
|
817
|
+
const nextRow = mIdx + 1 < markers.length ? (markers[mIdx + 1]?.row ?? flatRows.length) : flatRows.length;
|
|
818
|
+
if (markerRow + 1 < nextRow && markerRow + 1 < flatRows.length) {
|
|
819
|
+
const firstLine = stripAnsi(String(flatRows[markerRow] ?? '')).trim();
|
|
820
|
+
const secondLine = stripAnsi(String(flatRows[markerRow + 1] ?? '')).trim();
|
|
821
|
+
if (firstLine === '' && secondLine !== '')
|
|
822
|
+
markerRow += 1;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
const slot = slotOf(markerRow);
|
|
826
|
+
const held = kinds[slot];
|
|
827
|
+
if (!held || railPriority(marker.kind) > railPriority(held)) {
|
|
828
|
+
kinds[slot] = marker.kind;
|
|
829
|
+
}
|
|
976
830
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
831
|
+
const state = this.viewport.state();
|
|
832
|
+
const scrollable = state.max > 0;
|
|
833
|
+
const from = scrollable ? slotOf(state.scrollTop) : -1;
|
|
834
|
+
const to = scrollable ? slotOf(Math.max(state.scrollTop, state.scrollTop + state.height - 1)) : -2;
|
|
835
|
+
const cells = new Array(height);
|
|
836
|
+
for (let i = 0; i < height; i++) {
|
|
837
|
+
const inThumb = i >= from && i <= to;
|
|
838
|
+
const kind = kinds[i];
|
|
839
|
+
const loud = Boolean(kind) && railPriority(kind) >= RAIL_THUMB_YIELD;
|
|
840
|
+
if (kind && (!inThumb || loud))
|
|
841
|
+
cells[i] = railGlyph(kind);
|
|
842
|
+
else if (inThumb)
|
|
843
|
+
cells[i] = paint('scroll', thumbGlyph(i - from, to - from + 1));
|
|
844
|
+
else
|
|
845
|
+
cells[i] = ' ';
|
|
846
|
+
}
|
|
847
|
+
return cells;
|
|
848
|
+
}
|
|
849
|
+
attachRail(rows, contentWidth) {
|
|
850
|
+
const turns = collectSessionTurns(this.transcript, contentWidth);
|
|
851
|
+
const hasTurns = turns.length > 0;
|
|
852
|
+
const isAtBottom = typeof this.viewport?.atBottom === 'function' ? this.viewport.atBottom() : false;
|
|
853
|
+
const scrollTop = this.viewport.state().scrollTop;
|
|
854
|
+
const activeTurn = this.activeTurnIndex || resolveActiveTurnIndex(turns, scrollTop, rows.length, isAtBottom);
|
|
855
|
+
const railResult = hasTurns
|
|
856
|
+
? buildTurnRailCells(turns, rows.length, activeTurn, this.hoveredTurnIndex ?? null, scrollTop)
|
|
857
|
+
: null;
|
|
858
|
+
const rowToTurns = new Map();
|
|
859
|
+
const dotRows = [...(railResult?.layout?.rowToTurn?.keys() || [])].sort((a, b) => a - b);
|
|
860
|
+
for (const turn of turns) {
|
|
861
|
+
const rawRow = railResult?.layout?.dotRows?.get(turn.turnIndex);
|
|
862
|
+
if (rawRow === undefined || !Number.isFinite(rawRow) || dotRows.length === 0)
|
|
863
|
+
continue;
|
|
864
|
+
let nearest = dotRows[0] ?? 0;
|
|
865
|
+
let distance = Math.abs(rawRow - nearest);
|
|
866
|
+
for (const dotRow of dotRows) {
|
|
867
|
+
const delta = Math.abs(rawRow - dotRow);
|
|
868
|
+
if (delta < distance) {
|
|
869
|
+
nearest = dotRow;
|
|
870
|
+
distance = delta;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
const bucket = rowToTurns.get(nearest) ?? [];
|
|
874
|
+
bucket.push(turn);
|
|
875
|
+
rowToTurns.set(nearest, bucket);
|
|
876
|
+
}
|
|
877
|
+
this.turnRailLayout = {
|
|
878
|
+
railX: hasTurns ? 1 : contentWidth + 1,
|
|
879
|
+
rowToTurns,
|
|
880
|
+
stageTop: Math.max(0, (this.out.rows || this.stage.height) - this.stage.height),
|
|
881
|
+
viewportHeight: rows.length,
|
|
882
|
+
dotRows: railResult?.layout?.dotRows || new Map(),
|
|
883
|
+
rowToTurn: railResult?.layout?.rowToTurn || new Map(),
|
|
884
|
+
turns
|
|
885
|
+
};
|
|
886
|
+
const rail = this.buildRail(rows.length, contentWidth);
|
|
887
|
+
for (let i = 0; i < rows.length; i++) {
|
|
888
|
+
const rightCell = rail[i] || ' ';
|
|
889
|
+
let row = rows[i] || '';
|
|
890
|
+
if (hasTurns && railResult) {
|
|
891
|
+
const leftCell = railResult.cells[i] || ' ';
|
|
892
|
+
const leadEnd = leadingAnsiControlEnd(row);
|
|
893
|
+
if (row.slice(leadEnd, leadEnd + 3) === ' ') {
|
|
894
|
+
const leadEscapes = row.slice(0, leadEnd);
|
|
895
|
+
row = `${leadEscapes} ${leftCell} ${row.slice(leadEnd + 3)}`;
|
|
896
|
+
}
|
|
897
|
+
else if (stripAnsi(row).length === 0) {
|
|
898
|
+
row = leftCell !== ' ' ? ` ${leftCell} ` : '';
|
|
899
|
+
}
|
|
900
|
+
else {
|
|
901
|
+
row = ` ${leftCell} ${row}`;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
const rowWidth = contentWidth + (hasTurns ? TURN_RAIL_BUDGET : 0);
|
|
905
|
+
const paddedRow = padEnd(truncate(row, rowWidth, ''), rowWidth);
|
|
906
|
+
const railReset = paddedRow.includes('\x1b[') ? '\x1b[0m' : '';
|
|
907
|
+
rows[i] = `${paddedRow}${railReset} ${rightCell}`;
|
|
908
|
+
}
|
|
909
|
+
return rows;
|
|
910
|
+
}
|
|
911
|
+
releaseMouse() {
|
|
912
|
+
if (!this.mouseCaptured)
|
|
913
|
+
return false;
|
|
914
|
+
// Auto-enabled rail hover must be disarmed even without env opt-in.
|
|
915
|
+
this.writeModeControl(mouseHoverTracking(false, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
916
|
+
this.writeModeControl(mouseTracking(false));
|
|
917
|
+
this.mouseCaptured = false;
|
|
918
|
+
this.mouseMotionOn = false;
|
|
919
|
+
this.detached = true;
|
|
920
|
+
return true;
|
|
921
|
+
}
|
|
922
|
+
/** Take it back, once the user is driving the band again. */
|
|
923
|
+
captureMouse() {
|
|
924
|
+
// Home and suspended stages must not arm modes their teardown cannot observe.
|
|
925
|
+
if (!this.mouseWanted || !this.mouseOn || !this.stage.reserved || this.mouseCaptured)
|
|
926
|
+
return false;
|
|
927
|
+
this.writeModeControl(mouseTracking(true));
|
|
928
|
+
this.writeModeControl(mouseHoverTracking(true, this.env));
|
|
929
|
+
this.mouseCaptured = true;
|
|
930
|
+
this.mouseMotionOn = String(this.env?.CAUSYNE_MOUSE_HOVER ?? '') === '1';
|
|
931
|
+
this.detached = false;
|
|
932
|
+
// After native scrollback, the former physical cursor location is unknown.
|
|
933
|
+
// Return to the screen bottom before repainting any transcript rows.
|
|
934
|
+
this.stage.reanchor();
|
|
935
|
+
return true;
|
|
984
936
|
}
|
|
985
|
-
return rows;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
/**
|
|
989
|
-
* Hand the wheel back to the terminal.
|
|
990
|
-
*
|
|
991
|
-
* THE SEAM THIS EXISTS FOR. Two things scroll: this band's viewport, and the
|
|
992
|
-
* terminal's own scrollback above it, which holds everything already flushed.
|
|
993
|
-
* With ?1000 on, the app receives every wheel report and the terminal receives
|
|
994
|
-
* none — so once the viewport reached its top, scrolling further did nothing
|
|
995
|
-
* at all and the earlier conversation was unreachable by wheel. Releasing at
|
|
996
|
-
* the boundary is what makes the two halves feel like one scroll.
|
|
997
|
-
*/
|
|
998
|
-
releaseMouse() {
|
|
999
|
-
if (!this.mouseCaptured) return false;
|
|
1000
|
-
// Auto-enabled rail hover must be disarmed even without env opt-in.
|
|
1001
|
-
this.writeModeControl(mouseHoverTracking(false, { ...this.env, CAUSYNE_MOUSE_HOVER: '1' }));
|
|
1002
|
-
this.writeModeControl(mouseTracking(false));
|
|
1003
|
-
this.mouseCaptured = false;
|
|
1004
|
-
this.mouseMotionOn = false;
|
|
1005
|
-
this.detached = true;
|
|
1006
|
-
return true;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
/** Take it back, once the user is driving the band again. */
|
|
1010
|
-
captureMouse() {
|
|
1011
|
-
// Home and suspended stages must not arm modes their teardown cannot observe.
|
|
1012
|
-
if (!this.mouseWanted || !this.mouseOn || !this.stage.reserved || this.mouseCaptured) return false;
|
|
1013
|
-
this.writeModeControl(mouseTracking(true));
|
|
1014
|
-
this.writeModeControl(mouseHoverTracking(true, this.env));
|
|
1015
|
-
this.mouseCaptured = true;
|
|
1016
|
-
this.mouseMotionOn = String(this.env?.CAUSYNE_MOUSE_HOVER ?? '') === '1';
|
|
1017
|
-
this.detached = false;
|
|
1018
|
-
// After native scrollback, the former physical cursor location is unknown.
|
|
1019
|
-
// Return to the screen bottom before repainting any transcript rows.
|
|
1020
|
-
this.stage.reanchor();
|
|
1021
|
-
return true;
|
|
1022
|
-
}
|
|
1023
937
|
}
|
|
1024
|
-
|
|
1025
938
|
/**
|
|
1026
939
|
* Build a surface, or null when this terminal should keep the scrollback
|
|
1027
940
|
* renderer. Every null here is a reason the region could not be repainted
|
|
1028
941
|
* safely, and the fallback is the behaviour Causyne has always had.
|
|
1029
942
|
*/
|
|
1030
943
|
export function createStageSurface({ out = process.stdout, env = process.env, config = null, speed, openingWidth = 0 } = {}) {
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
944
|
+
const safeEnv = env && typeof env === 'object' ? env : {};
|
|
945
|
+
if (!out || !out.isTTY)
|
|
946
|
+
return null;
|
|
947
|
+
if (String(safeEnv.TERM || '') === 'dumb')
|
|
948
|
+
return null;
|
|
949
|
+
if (safeEnv.CAUSYNE_SIMPLE_INPUT === '1')
|
|
950
|
+
return null;
|
|
951
|
+
if (stageHeight(out, safeEnv) < 1)
|
|
952
|
+
return null;
|
|
953
|
+
// Terminal-wide motion tracking is opt-in, never silently enabled by the TUI.
|
|
954
|
+
const opts = { out, env: safeEnv, config, openingWidth };
|
|
955
|
+
if (speed !== undefined)
|
|
956
|
+
opts.speed = speed;
|
|
957
|
+
const surface = new StageSurface(opts);
|
|
958
|
+
if (!surface.open())
|
|
959
|
+
return null;
|
|
960
|
+
return surface;
|
|
1040
961
|
}
|
|
1041
|
-
|