novacode-cli 1.2.0__py3-none-any.whl
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.
- novacode_cli/__init__.py +29 -0
- novacode_cli/__main__.py +6 -0
- novacode_cli/_lazy_heavy.py +99 -0
- novacode_cli/_version.py +3 -0
- novacode_cli/agent_stream.py +178 -0
- novacode_cli/agents/agent_file.py +250 -0
- novacode_cli/agents/agent_mailbox.py +120 -0
- novacode_cli/agents/approval_decisions.py +146 -0
- novacode_cli/agents/arg_repair.py +196 -0
- novacode_cli/agents/async_agents/__init__.py +6 -0
- novacode_cli/agents/async_agents/_config.py +213 -0
- novacode_cli/agents/async_agents/_mcp_tools.py +192 -0
- novacode_cli/agents/async_agents/_specialist.py +84 -0
- novacode_cli/agents/async_agents/_test_commands.py +89 -0
- novacode_cli/agents/async_agents/_tools.py +432 -0
- novacode_cli/agents/async_agents/general_purpose.py +42 -0
- novacode_cli/agents/async_agents/langgraph.json +9 -0
- novacode_cli/agents/async_agents/research.py +22 -0
- novacode_cli/agents/async_context.py +303 -0
- novacode_cli/agents/async_on_demand.py +52 -0
- novacode_cli/agents/async_task_errors.py +75 -0
- novacode_cli/agents/async_workspace.py +27 -0
- novacode_cli/agents/attribution.py +165 -0
- novacode_cli/agents/browser_mode.py +119 -0
- novacode_cli/agents/btw_agent.py +71 -0
- novacode_cli/agents/caveman.py +352 -0
- novacode_cli/agents/caveman_support.py +370 -0
- novacode_cli/agents/code_mode.py +774 -0
- novacode_cli/agents/code_runtime.py +160 -0
- novacode_cli/agents/context_compaction.py +1339 -0
- novacode_cli/agents/core_agent.py +2710 -0
- novacode_cli/agents/default_subagents/__init__.py +24 -0
- novacode_cli/agents/default_subagents/async_subagents.py +296 -0
- novacode_cli/agents/default_subagents/builtin/browser-automation-agent.md +110 -0
- novacode_cli/agents/default_subagents/builtin/bug-fix-agent.md +22 -0
- novacode_cli/agents/default_subagents/builtin/bug-investigation-agent.md +42 -0
- novacode_cli/agents/default_subagents/builtin/code-explorer.md +37 -0
- novacode_cli/agents/default_subagents/builtin/code-review-agent.md +33 -0
- novacode_cli/agents/default_subagents/builtin/dependency-audit-agent.md +34 -0
- novacode_cli/agents/default_subagents/builtin/documentation-update-agent.md +46 -0
- novacode_cli/agents/default_subagents/builtin/performance-audit-agent.md +41 -0
- novacode_cli/agents/default_subagents/builtin/plan-scout-agent.md +64 -0
- novacode_cli/agents/default_subagents/builtin/refactoring-agent.md +35 -0
- novacode_cli/agents/default_subagents/builtin/refactoring-specialist-agent.md +175 -0
- novacode_cli/agents/default_subagents/builtin/security-audit-agent.md +96 -0
- novacode_cli/agents/default_subagents/builtin/test-generation-agent.md +33 -0
- novacode_cli/agents/default_subagents/builtin/test-runner-agent.md +55 -0
- novacode_cli/agents/default_subagents/prompt.py +88 -0
- novacode_cli/agents/default_subagents/subagents.py +138 -0
- novacode_cli/agents/dream_agent.py +93 -0
- novacode_cli/agents/edit_diagnostics.py +362 -0
- novacode_cli/agents/edit_fallback.py +62 -0
- novacode_cli/agents/handoff.py +166 -0
- novacode_cli/agents/invocation.py +152 -0
- novacode_cli/agents/model_budget.py +42 -0
- novacode_cli/agents/model_retry.py +113 -0
- novacode_cli/agents/model_router.py +420 -0
- novacode_cli/agents/openai_decisions.py +186 -0
- novacode_cli/agents/plan_agent/__init__.py +12 -0
- novacode_cli/agents/plan_agent/plan_agent.py +357 -0
- novacode_cli/agents/plan_agent/plan_mode_middleware.py +64 -0
- novacode_cli/agents/plan_execution.py +237 -0
- novacode_cli/agents/ponytail.py +66 -0
- novacode_cli/agents/prime.py +274 -0
- novacode_cli/agents/provider_caching.py +99 -0
- novacode_cli/agents/server_launcher.py +904 -0
- novacode_cli/agents/strict_tools.py +384 -0
- novacode_cli/agents/task_discipline.py +294 -0
- novacode_cli/agents/tool_call_repair.py +290 -0
- novacode_cli/agents/tool_offload.py +291 -0
- novacode_cli/agents/tool_search.py +806 -0
- novacode_cli/agents/tool_search_variants.py +106 -0
- novacode_cli/agents/tool_verdicts.py +1194 -0
- novacode_cli/agents/user_async_agents.py +312 -0
- novacode_cli/artifacts/__init__.py +10 -0
- novacode_cli/artifacts/registry.py +278 -0
- novacode_cli/artifacts/server.py +426 -0
- novacode_cli/assets/Nova.png +0 -0
- novacode_cli/assets/nova-avatar.png +0 -0
- novacode_cli/audio/__init__.py +301 -0
- novacode_cli/audio/capture.py +137 -0
- novacode_cli/audio/downloads.py +273 -0
- novacode_cli/audio/pipeline.py +391 -0
- novacode_cli/audio/playback.py +87 -0
- novacode_cli/audio/providers.py +208 -0
- novacode_cli/audio/speakable.py +78 -0
- novacode_cli/audio/stt.py +132 -0
- novacode_cli/audio/stt_deepgram.py +69 -0
- novacode_cli/audio/stt_elevenlabs.py +89 -0
- novacode_cli/audio/stt_parakeet.py +94 -0
- novacode_cli/audio/stt_whistle.py +61 -0
- novacode_cli/audio/summarize.py +92 -0
- novacode_cli/audio/tts.py +85 -0
- novacode_cli/audio/tts_kokoro.py +73 -0
- novacode_cli/audio/tts_orpheus.py +180 -0
- novacode_cli/audio/tts_pocket.py +131 -0
- novacode_cli/audio/tts_sano.py +69 -0
- novacode_cli/audio/vad.py +145 -0
- novacode_cli/backends/__init__.py +17 -0
- novacode_cli/backends/filesystem.py +894 -0
- novacode_cli/backends/native_search.py +92 -0
- novacode_cli/bootstrap/__init__.py +9 -0
- novacode_cli/bootstrap/env_snapshot.py +240 -0
- novacode_cli/bootstrap/steering.py +464 -0
- novacode_cli/bootstrap/vision_router.py +604 -0
- novacode_cli/brand.py +362 -0
- novacode_cli/cli_args.py +718 -0
- novacode_cli/commands/__init__.py +237 -0
- novacode_cli/commands/agents_commands.py +231 -0
- novacode_cli/commands/auth_handler.py +40 -0
- novacode_cli/commands/browser_use_handler.py +75 -0
- novacode_cli/commands/cache_handler.py +32 -0
- novacode_cli/commands/chat_handler.py +1357 -0
- novacode_cli/commands/ci_fix.py +171 -0
- novacode_cli/commands/claude_plan.py +331 -0
- novacode_cli/commands/codex_plan.py +195 -0
- novacode_cli/commands/commands.py +1113 -0
- novacode_cli/commands/create_handler.py +124 -0
- novacode_cli/commands/create_server.py +1887 -0
- novacode_cli/commands/cron_handler.py +119 -0
- novacode_cli/commands/dream_handler.py +203 -0
- novacode_cli/commands/effort_handler.py +65 -0
- novacode_cli/commands/evolution_handler.py +214 -0
- novacode_cli/commands/file_commands.py +381 -0
- novacode_cli/commands/handoff_handler.py +68 -0
- novacode_cli/commands/hooks_handler.py +269 -0
- novacode_cli/commands/init_handler.py +146 -0
- novacode_cli/commands/learning_handler.py +160 -0
- novacode_cli/commands/lite_mode_handler.py +76 -0
- novacode_cli/commands/log_commands.py +363 -0
- novacode_cli/commands/mcp_handler.py +29 -0
- novacode_cli/commands/model_handler.py +29 -0
- novacode_cli/commands/notifications_handler.py +158 -0
- novacode_cli/commands/onboard_handler.py +121 -0
- novacode_cli/commands/plan_handler.py +440 -0
- novacode_cli/commands/planner_usage.py +250 -0
- novacode_cli/commands/plugin_install_handler.py +38 -0
- novacode_cli/commands/plugins_handler.py +35 -0
- novacode_cli/commands/prime_handler.py +455 -0
- novacode_cli/commands/prompt_handler.py +149 -0
- novacode_cli/commands/provider_usage.py +160 -0
- novacode_cli/commands/ralph_events.py +106 -0
- novacode_cli/commands/ralph_handler.py +1293 -0
- novacode_cli/commands/refine_handler.py +213 -0
- novacode_cli/commands/research_handler.py +202 -0
- novacode_cli/commands/rootapp_remote.py +83 -0
- novacode_cli/commands/router_handler.py +36 -0
- novacode_cli/commands/server_commands.py +249 -0
- novacode_cli/commands/session_commands.py +203 -0
- novacode_cli/commands/share_handler.py +450 -0
- novacode_cli/commands/side_commands.py +366 -0
- novacode_cli/commands/skill_invoke.py +420 -0
- novacode_cli/commands/skills_commands.py +48 -0
- novacode_cli/commands/trace_handler.py +322 -0
- novacode_cli/commands/trello_handler.py +226 -0
- novacode_cli/commands/trello_remote.py +177 -0
- novacode_cli/commands/trello_server.py +1214 -0
- novacode_cli/commands/vision_handler.py +127 -0
- novacode_cli/commands/voice_handler.py +447 -0
- novacode_cli/commands/webhook_handler.py +134 -0
- novacode_cli/commands/wiki_commands.py +227 -0
- novacode_cli/compaction.py +753 -0
- novacode_cli/computation_cache.py +159 -0
- novacode_cli/computer/__init__.py +1 -0
- novacode_cli/computer/persistent.py +234 -0
- novacode_cli/computer/preview.py +253 -0
- novacode_cli/computer/runtime.py +474 -0
- novacode_cli/computer/windows_console.py +152 -0
- novacode_cli/computer/windows_qemu.py +211 -0
- novacode_cli/config/browser_mode.py +159 -0
- novacode_cli/config/catalog_models.py +95 -0
- novacode_cli/config/config.py +1388 -0
- novacode_cli/config/credentials.py +540 -0
- novacode_cli/config/google_oauth_auth.py +281 -0
- novacode_cli/config/model_capabilities.py +343 -0
- novacode_cli/config/model_catalog.py +275 -0
- novacode_cli/config/model_create.py +1325 -0
- novacode_cli/config/model_manager.py +695 -0
- novacode_cli/config/nova_config.py +1283 -0
- novacode_cli/config/openai_chatgpt_auth.py +384 -0
- novacode_cli/config/opencode_gateway.py +25 -0
- novacode_cli/config/plan_mode.py +188 -0
- novacode_cli/config/provider_auth.py +438 -0
- novacode_cli/config/provider_catalog.json +5127 -0
- novacode_cli/config/provider_registry.py +38 -0
- novacode_cli/config/provider_transports.py +258 -0
- novacode_cli/config/role_models.py +175 -0
- novacode_cli/context/__init__.py +50 -0
- novacode_cli/context/_analysis.py +799 -0
- novacode_cli/context/_budget.py +116 -0
- novacode_cli/context/_conversation.py +73 -0
- novacode_cli/context/_dynamic.py +264 -0
- novacode_cli/context/_model_config.py +380 -0
- novacode_cli/context/_models_dev.py +99 -0
- novacode_cli/context/archives.py +248 -0
- novacode_cli/context/estimates.py +65 -0
- novacode_cli/context/history.py +17 -0
- novacode_cli/context/knowledge_cache.py +292 -0
- novacode_cli/context/manager.py +101 -0
- novacode_cli/context/observations.py +65 -0
- novacode_cli/context/pressure.py +168 -0
- novacode_cli/context/provider_accounting.py +109 -0
- novacode_cli/context/snapshot.py +493 -0
- novacode_cli/context/strategies.py +279 -0
- novacode_cli/context/task_progress.py +122 -0
- novacode_cli/core/__init__.py +0 -0
- novacode_cli/core/agent_loop.py +1821 -0
- novacode_cli/core/autonomous_loop.py +277 -0
- novacode_cli/core/code_approvals.py +57 -0
- novacode_cli/core/input_preparation.py +276 -0
- novacode_cli/core/reasoning.py +67 -0
- novacode_cli/core/streaming.py +326 -0
- novacode_cli/core/subagent_tasks.py +696 -0
- novacode_cli/core/subagent_tracking.py +235 -0
- novacode_cli/core/tool_results.py +116 -0
- novacode_cli/core/verification_loop.py +272 -0
- novacode_cli/council.py +595 -0
- novacode_cli/council_consensus.py +115 -0
- novacode_cli/council_decision.py +157 -0
- novacode_cli/council_planner.py +1421 -0
- novacode_cli/council_settings.py +208 -0
- novacode_cli/council_web_settings.py +41 -0
- novacode_cli/council_workspace.py +56 -0
- novacode_cli/cowork/__init__.py +10 -0
- novacode_cli/cowork/broker_middleware.py +162 -0
- novacode_cli/cowork/launcher.py +102 -0
- novacode_cli/cowork/policy.py +284 -0
- novacode_cli/cowork/ui.py +826 -0
- novacode_cli/daemons/__init__.py +1 -0
- novacode_cli/daemons/registry.py +342 -0
- novacode_cli/desktop_notifications.py +302 -0
- novacode_cli/doctor.py +251 -0
- novacode_cli/embeddings.py +109 -0
- novacode_cli/entrypoint.py +56 -0
- novacode_cli/errors/__init__.py +19 -0
- novacode_cli/errors/handlers.py +648 -0
- novacode_cli/errors/provider_errors.py +249 -0
- novacode_cli/errors/taxonomy.py +80 -0
- novacode_cli/events.py +179 -0
- novacode_cli/file_ops.py +714 -0
- novacode_cli/git_safety.py +281 -0
- novacode_cli/handoff.py +383 -0
- novacode_cli/headless/__init__.py +18 -0
- novacode_cli/headless/input.py +58 -0
- novacode_cli/headless/output.py +224 -0
- novacode_cli/headless/pipe.py +532 -0
- novacode_cli/headless/runner.py +461 -0
- novacode_cli/hermes/__init__.py +39 -0
- novacode_cli/hermes/activation.py +297 -0
- novacode_cli/hermes/config.py +129 -0
- novacode_cli/hermes/curator.py +199 -0
- novacode_cli/hermes/evolution.py +374 -0
- novacode_cli/hermes/ledger.py +364 -0
- novacode_cli/hermes/memory_tiers.py +969 -0
- novacode_cli/hermes/middleware.py +678 -0
- novacode_cli/hermes/overview.py +174 -0
- novacode_cli/hermes/prompt_evolution.py +503 -0
- novacode_cli/hermes/refine_loop.py +643 -0
- novacode_cli/hermes/refinement_log.py +190 -0
- novacode_cli/hermes/review.py +674 -0
- novacode_cli/hermes/skill_debate.py +135 -0
- novacode_cli/hermes/skill_discovery.py +450 -0
- novacode_cli/hermes/skill_manager.py +335 -0
- novacode_cli/hermes/skill_proposals.py +43 -0
- novacode_cli/hermes/test_gaming.py +119 -0
- novacode_cli/hermes/tracker.py +435 -0
- novacode_cli/hermes/tuner.py +206 -0
- novacode_cli/hermes/verification_memory.py +134 -0
- novacode_cli/hermes/verifier.py +277 -0
- novacode_cli/hitl/__init__.py +22 -0
- novacode_cli/hitl/interrupts.py +493 -0
- novacode_cli/hooks.py +359 -0
- novacode_cli/image_utils.py +517 -0
- novacode_cli/init/__init__.py +7 -0
- novacode_cli/init/events.py +43 -0
- novacode_cli/input_utils.py +526 -0
- novacode_cli/install_commands.py +87 -0
- novacode_cli/integrations/__init__.py +82 -0
- novacode_cli/integrations/daytona.py +122 -0
- novacode_cli/integrations/docker.py +309 -0
- novacode_cli/integrations/host_path.py +111 -0
- novacode_cli/integrations/langsmith.py +151 -0
- novacode_cli/integrations/modal.py +134 -0
- novacode_cli/integrations/runloop.py +130 -0
- novacode_cli/integrations/sandbox_factory.py +1388 -0
- novacode_cli/integrations/sandbox_registry.py +312 -0
- novacode_cli/integrations/workdir_backend.py +589 -0
- novacode_cli/main.py +2078 -0
- novacode_cli/mcp/__init__.py +73 -0
- novacode_cli/mcp/auth.py +189 -0
- novacode_cli/mcp/client.py +571 -0
- novacode_cli/mcp/code_mode.py +5 -0
- novacode_cli/mcp/code_runtime.py +5 -0
- novacode_cli/mcp/commands.py +902 -0
- novacode_cli/mcp/config.py +406 -0
- novacode_cli/mcp/generic.py +128 -0
- novacode_cli/mcp/middleware.py +993 -0
- novacode_cli/mcp/presets.py +367 -0
- novacode_cli/memory/__init__.py +1 -0
- novacode_cli/memory/agent_memory.py +1312 -0
- novacode_cli/memory/builtin_lessons.py +60 -0
- novacode_cli/memory/dream_gates.py +192 -0
- novacode_cli/memory/limits.py +59 -0
- novacode_cli/memory/parsed_cache.py +106 -0
- novacode_cli/memory/recall_stats.py +97 -0
- novacode_cli/memory/semantic.py +116 -0
- novacode_cli/memory/store.py +335 -0
- novacode_cli/memory/wiki.py +274 -0
- novacode_cli/migrate.py +185 -0
- novacode_cli/onboarding.py +649 -0
- novacode_cli/onboarding_check.py +119 -0
- novacode_cli/path_approval.py +297 -0
- novacode_cli/plan_archive.py +148 -0
- novacode_cli/plugins/__init__.py +121 -0
- novacode_cli/plugins/claude_plugins.py +538 -0
- novacode_cli/plugins/cli.py +168 -0
- novacode_cli/plugins/components.py +413 -0
- novacode_cli/plugins/hooks.py +356 -0
- novacode_cli/plugins/loader.py +317 -0
- novacode_cli/plugins/marketplaces.py +199 -0
- novacode_cli/plugins/storage.py +70 -0
- novacode_cli/prime.py +759 -0
- novacode_cli/prime_factory/__init__.py +15 -0
- novacode_cli/prime_factory/container.py +198 -0
- novacode_cli/prime_factory/controller.py +565 -0
- novacode_cli/prime_factory/knowledge.py +261 -0
- novacode_cli/prime_factory/publication.py +218 -0
- novacode_cli/prime_factory/recovery.py +50 -0
- novacode_cli/prime_factory/research.py +370 -0
- novacode_cli/prime_factory/runner.py +608 -0
- novacode_cli/prime_factory/runtime.py +261 -0
- novacode_cli/prime_factory/state.py +201 -0
- novacode_cli/prime_factory/store.py +128 -0
- novacode_cli/prime_factory/worker.py +129 -0
- novacode_cli/prime_factory/workflow.py +899 -0
- novacode_cli/prime_factory/workspace.py +317 -0
- novacode_cli/prime_memory.py +290 -0
- novacode_cli/process_manager.py +585 -0
- novacode_cli/project_onboard.py +537 -0
- novacode_cli/prompts/System_Prompt_Nova.jinja +23 -0
- novacode_cli/prompts/__init__.py +168 -0
- novacode_cli/prompts/agent_definitions.jinja +11 -0
- novacode_cli/prompts/agent_generation.jinja +125 -0
- novacode_cli/prompts/async_agents/general_purpose.jinja +22 -0
- novacode_cli/prompts/claude_plan_mode.jinja +12 -0
- novacode_cli/prompts/coding_workflow.jinja +18 -0
- novacode_cli/prompts/computer_use.jinja +17 -0
- novacode_cli/prompts/core_agent_system.jinja +81 -0
- novacode_cli/prompts/delegation.jinja +15 -0
- novacode_cli/prompts/desktop_power.jinja +4 -0
- novacode_cli/prompts/file_paths.jinja +15 -0
- novacode_cli/prompts/file_tracker.jinja +23 -0
- novacode_cli/prompts/init_agents_md.jinja +56 -0
- novacode_cli/prompts/init_exploration.jinja +174 -0
- novacode_cli/prompts/init_semantic_orchestrate.jinja +37 -0
- novacode_cli/prompts/instruction_scope.jinja +5 -0
- novacode_cli/prompts/learnings_extraction.jinja +45 -0
- novacode_cli/prompts/longterm_memory.jinja +54 -0
- novacode_cli/prompts/mcp.jinja +84 -0
- novacode_cli/prompts/memory_consolidation.jinja +40 -0
- novacode_cli/prompts/nova_evolution.jinja +73 -0
- novacode_cli/prompts/nova_review.jinja +158 -0
- novacode_cli/prompts/nova_skill_debate.jinja +36 -0
- novacode_cli/prompts/nova_standing_instructions.jinja +26 -0
- novacode_cli/prompts/nova_verify.jinja +100 -0
- novacode_cli/prompts/onboard_dashboard.jinja +378 -0
- novacode_cli/prompts/plan_agent.jinja +87 -0
- novacode_cli/prompts/plan_scouts.jinja +5 -0
- novacode_cli/prompts/plan_storage.jinja +8 -0
- novacode_cli/prompts/planning.jinja +82 -0
- novacode_cli/prompts/ponytail/LICENSE +21 -0
- novacode_cli/prompts/ponytail/UPSTREAM.json +15 -0
- novacode_cli/prompts/ponytail/hooks/ponytail-config.js +175 -0
- novacode_cli/prompts/ponytail/hooks/ponytail-instructions.js +98 -0
- novacode_cli/prompts/ponytail/skills/ponytail/SKILL.md +52 -0
- novacode_cli/prompts/ponytail/skills/ponytail-audit/SKILL.md +103 -0
- novacode_cli/prompts/ponytail/skills/ponytail-debt/SKILL.md +44 -0
- novacode_cli/prompts/ponytail/skills/ponytail-gain/SKILL.md +52 -0
- novacode_cli/prompts/ponytail/skills/ponytail-help/SKILL.md +76 -0
- novacode_cli/prompts/ponytail/skills/ponytail-review/SKILL.md +101 -0
- novacode_cli/prompts/prompt_evolution.jinja +27 -0
- novacode_cli/prompts/ralph_iteration.jinja +75 -0
- novacode_cli/prompts/refine_gate.jinja +31 -0
- novacode_cli/prompts/refine_plan.jinja +64 -0
- novacode_cli/prompts/refine_review.jinja +34 -0
- novacode_cli/prompts/research_delivery.jinja +9 -0
- novacode_cli/prompts/research_swarm.jinja +130 -0
- novacode_cli/prompts/response_style.jinja +5 -0
- novacode_cli/prompts/session_summarization.jinja +86 -0
- novacode_cli/prompts/skill_creation.jinja +85 -0
- novacode_cli/prompts/subagents/fact_checker.jinja +48 -0
- novacode_cli/prompts/subagents/financial_analyst.jinja +50 -0
- novacode_cli/prompts/subagents/literature_reviewer.jinja +52 -0
- novacode_cli/prompts/subagents/market_analyst.jinja +48 -0
- novacode_cli/prompts/subagents/research_synthesizer.jinja +57 -0
- novacode_cli/prompts/subagents/technical_researcher.jinja +56 -0
- novacode_cli/prompts/subagents/web_researcher.jinja +46 -0
- novacode_cli/prompts/summarization.jinja +107 -0
- novacode_cli/prompts/summarization_answers.jinja +23 -0
- novacode_cli/prompts/summarization_questions.jinja +32 -0
- novacode_cli/prompts/vision_caption.jinja +21 -0
- novacode_cli/prompts/voice_summary.jinja +65 -0
- novacode_cli/prompts/wiki_file.jinja +57 -0
- novacode_cli/prompts/wiki_ingest.jinja +87 -0
- novacode_cli/recovery.py +383 -0
- novacode_cli/remote/__init__.py +45 -0
- novacode_cli/remote/approvals.py +282 -0
- novacode_cli/remote/async_task_clients.py +97 -0
- novacode_cli/remote/async_task_watcher.py +240 -0
- novacode_cli/remote/bridge.py +905 -0
- novacode_cli/remote/command_menu.py +26 -0
- novacode_cli/remote/command_ui.py +243 -0
- novacode_cli/remote/config.py +199 -0
- novacode_cli/remote/discord_bridge.py +530 -0
- novacode_cli/remote/discord_format.py +31 -0
- novacode_cli/remote/discord_threads.py +225 -0
- novacode_cli/remote/images.py +97 -0
- novacode_cli/remote/processor.py +601 -0
- novacode_cli/remote/rootapp_bot/bot.cjs +16 -0
- novacode_cli/remote/rootapp_bot/package-lock.json +2683 -0
- novacode_cli/remote/rootapp_bot/package.json +18 -0
- novacode_cli/remote/rootapp_bot/transport.cjs +80 -0
- novacode_cli/remote/rootapp_bridge.py +370 -0
- novacode_cli/remote/rootapp_setup.py +89 -0
- novacode_cli/remote/routing.py +103 -0
- novacode_cli/remote/scheduler.py +302 -0
- novacode_cli/remote/session.py +164 -0
- novacode_cli/remote/status.py +411 -0
- novacode_cli/remote/streaming.py +188 -0
- novacode_cli/remote/telegram_bridge.py +1118 -0
- novacode_cli/remote/telegram_format.py +215 -0
- novacode_cli/remote/telegram_hub.py +256 -0
- novacode_cli/remote/voice_notes.py +120 -0
- novacode_cli/remote/webhook_adapters.py +167 -0
- novacode_cli/remote/webhook_server.py +154 -0
- novacode_cli/rewind.py +150 -0
- novacode_cli/rooms/__init__.py +1 -0
- novacode_cli/rooms/bridge.py +86 -0
- novacode_cli/rooms/cli.py +231 -0
- novacode_cli/rooms/nova.py +227 -0
- novacode_cli/rooms/runtime.py +299 -0
- novacode_cli/rooms/store.py +538 -0
- novacode_cli/rooms/workspace.py +94 -0
- novacode_cli/security/__init__.py +29 -0
- novacode_cli/security/approval_context.py +45 -0
- novacode_cli/security/delegated_approval.py +68 -0
- novacode_cli/security/local_http.py +85 -0
- novacode_cli/security/middleware.py +87 -0
- novacode_cli/security/paths.py +35 -0
- novacode_cli/security/policy.py +535 -0
- novacode_cli/security/policy_writer.py +90 -0
- novacode_cli/security/prompt_injection.py +203 -0
- novacode_cli/security/remember.py +81 -0
- novacode_cli/security/rule_synthesis.py +116 -0
- novacode_cli/security/secret_files.py +61 -0
- novacode_cli/security/session_allow.py +114 -0
- novacode_cli/security/unicode_security.py +516 -0
- novacode_cli/security/validator.py +173 -0
- novacode_cli/server/__init__.py +9 -0
- novacode_cli/server/app.py +632 -0
- novacode_cli/server/event_adapter.py +189 -0
- novacode_cli/server/session_manager.py +90 -0
- novacode_cli/server_main.py +64 -0
- novacode_cli/server_runner/dev_server.py +530 -0
- novacode_cli/server_runner/test_runner.py +470 -0
- novacode_cli/session/__init__.py +1 -0
- novacode_cli/session/adapters/__init__.py +240 -0
- novacode_cli/session/adapters/claude_code.py +102 -0
- novacode_cli/session/adapters/codex.py +77 -0
- novacode_cli/session/adapters/harness_native.py +75 -0
- novacode_cli/session/checkpoint_coordinator.py +448 -0
- novacode_cli/session/context_restore.py +25 -0
- novacode_cli/session/history_export.py +228 -0
- novacode_cli/session/history_tree.py +174 -0
- novacode_cli/session/imported_context.py +267 -0
- novacode_cli/session/runtime_identity.py +32 -0
- novacode_cli/session/session_persistence.py +1168 -0
- novacode_cli/session/session_prompt_builder.py +279 -0
- novacode_cli/session/session_restore.py +351 -0
- novacode_cli/session/session_summarization.py +20 -0
- novacode_cli/session/transcript_journal.py +153 -0
- novacode_cli/sessions/__init__.py +11 -0
- novacode_cli/sessions/gateway.py +84 -0
- novacode_cli/sessions/launch.py +51 -0
- novacode_cli/sessions/lease.py +213 -0
- novacode_cli/sessions/messaging.py +255 -0
- novacode_cli/sessions/protocol.py +216 -0
- novacode_cli/sessions/resume.py +31 -0
- novacode_cli/sessions/supervisor.py +498 -0
- novacode_cli/sessions/tasks.py +73 -0
- novacode_cli/sessions/tui_messaging.py +413 -0
- novacode_cli/sessions/worker.py +652 -0
- novacode_cli/sessions/worktree.py +262 -0
- novacode_cli/shell/__init__.py +27 -0
- novacode_cli/shell/jobs.py +475 -0
- novacode_cli/shell/middleware.py +1568 -0
- novacode_cli/shell/os_sandbox.py +205 -0
- novacode_cli/shell/output.py +181 -0
- novacode_cli/shell/patterns.py +275 -0
- novacode_cli/shell/processes.py +87 -0
- novacode_cli/shell/utils.py +236 -0
- novacode_cli/skills/__init__.py +26 -0
- novacode_cli/skills/builtin/handoff/SKILL.md +15 -0
- novacode_cli/skills/curation_middleware.py +69 -0
- novacode_cli/skills/executable.py +161 -0
- novacode_cli/skills/libraries.py +102 -0
- novacode_cli/skills/load.py +248 -0
- novacode_cli/skills/prune.py +215 -0
- novacode_cli/skills/refreshing_middleware.py +896 -0
- novacode_cli/skills/retrieval.py +248 -0
- novacode_cli/skills/runtime.py +118 -0
- novacode_cli/skills/schema.py +254 -0
- novacode_cli/skills/skill_creation.py +1549 -0
- novacode_cli/skills/skill_lock.py +75 -0
- novacode_cli/skills/skill_system_prompt.py +16 -0
- novacode_cli/skills/skills_prefs.py +126 -0
- novacode_cli/skills/tool_resolver.py +31 -0
- novacode_cli/skills/upstream.py +50 -0
- novacode_cli/skills/versioning.py +291 -0
- novacode_cli/states/Session.py +847 -0
- novacode_cli/states/__init__.py +31 -0
- novacode_cli/states/slices/__init__.py +17 -0
- novacode_cli/states/slices/agent_runtime.py +249 -0
- novacode_cli/states/slices/background_tasks.py +21 -0
- novacode_cli/states/slices/notifications.py +74 -0
- novacode_cli/states/slices/remote_bridge.py +56 -0
- novacode_cli/states/slices/ui_settings.py +49 -0
- novacode_cli/states/slices/wiki.py +25 -0
- novacode_cli/teammates/__init__.py +1 -0
- novacode_cli/teammates/controller.py +557 -0
- novacode_cli/teammates/graph.py +104 -0
- novacode_cli/teammates/registry.py +175 -0
- novacode_cli/teammates/service.py +254 -0
- novacode_cli/teammates/worker.py +19 -0
- novacode_cli/teams/__init__.py +1 -0
- novacode_cli/teams/adapters/__init__.py +1 -0
- novacode_cli/teams/adapters/container.py +316 -0
- novacode_cli/teams/adapters/inprocess.py +206 -0
- novacode_cli/teams/adapters/process.py +364 -0
- novacode_cli/teams/bootstrap.py +246 -0
- novacode_cli/teams/container_git.py +67 -0
- novacode_cli/teams/context.py +34 -0
- novacode_cli/teams/coordinator.py +815 -0
- novacode_cli/teams/gateway.py +200 -0
- novacode_cli/teams/host.py +64 -0
- novacode_cli/teams/legacy.py +52 -0
- novacode_cli/teams/middleware.py +176 -0
- novacode_cli/teams/models.py +104 -0
- novacode_cli/teams/output.py +47 -0
- novacode_cli/teams/protocol.py +50 -0
- novacode_cli/teams/recovery.py +80 -0
- novacode_cli/teams/scheduler.py +44 -0
- novacode_cli/teams/store.py +631 -0
- novacode_cli/teams/worker.py +251 -0
- novacode_cli/teams/workspace.py +100 -0
- novacode_cli/token_utils.py +256 -0
- novacode_cli/tools/__init__.py +104 -0
- novacode_cli/tools/_shared.py +97 -0
- novacode_cli/tools/_types.py +24 -0
- novacode_cli/tools/artifact_tools.py +137 -0
- novacode_cli/tools/code_search_tools.py +330 -0
- novacode_cli/tools/computer_tools.py +77 -0
- novacode_cli/tools/cron_tools.py +65 -0
- novacode_cli/tools/daemon_tool.py +290 -0
- novacode_cli/tools/desktop_tools.py +161 -0
- novacode_cli/tools/fetch_tools.py +530 -0
- novacode_cli/tools/http_tools.py +279 -0
- novacode_cli/tools/inspection_tools.py +107 -0
- novacode_cli/tools/job_tools.py +143 -0
- novacode_cli/tools/knowledge_tools.py +427 -0
- novacode_cli/tools/memory_tools.py +461 -0
- novacode_cli/tools/memory_wiki_tools.py +40 -0
- novacode_cli/tools/notebook_tools.py +238 -0
- novacode_cli/tools/oracle_tool.py +83 -0
- novacode_cli/tools/plan_archive_tools.py +80 -0
- novacode_cli/tools/plan_mode_tools.py +315 -0
- novacode_cli/tools/python_kernel_loop.py +165 -0
- novacode_cli/tools/python_kernel_tool.py +222 -0
- novacode_cli/tools/reflection_tools.py +34 -0
- novacode_cli/tools/scraper_tools.py +377 -0
- novacode_cli/tools/skill_tools.py +275 -0
- novacode_cli/tools/speak_tool.py +51 -0
- novacode_cli/tools/store_memory_tools.py +227 -0
- novacode_cli/tools/ui_tools.py +62 -0
- novacode_cli/tools/waiter_tools.py +408 -0
- novacode_cli/tools/web_tools.py +349 -0
- novacode_cli/tools/wiki_tools.py +152 -0
- novacode_cli/tools/worktree_tools.py +219 -0
- novacode_cli/tracking/__init__.py +10 -0
- novacode_cli/tracking/file_tracker.py +826 -0
- novacode_cli/tracking/local_metrics.py +170 -0
- novacode_cli/tracking/loop_guard.py +507 -0
- novacode_cli/tracking/request_metrics.py +60 -0
- novacode_cli/tracking/tracing.py +692 -0
- novacode_cli/tracking/usage_tree.py +677 -0
- novacode_cli/tracking/workspace_anchoring.py +231 -0
- novacode_cli/tui/__init__.py +11 -0
- novacode_cli/tui/animation_rate.py +9 -0
- novacode_cli/tui/animations.py +332 -0
- novacode_cli/tui/app.py +19315 -0
- novacode_cli/tui/auth_display.py +87 -0
- novacode_cli/tui/auth_screens.py +826 -0
- novacode_cli/tui/avatar.py +294 -0
- novacode_cli/tui/avatar_frames.py +21 -0
- novacode_cli/tui/background_tasks.py +35 -0
- novacode_cli/tui/browser_settings_screen.py +70 -0
- novacode_cli/tui/caveman_screen.py +185 -0
- novacode_cli/tui/council_settings_screen.py +182 -0
- novacode_cli/tui/council_view.py +535 -0
- novacode_cli/tui/decision_settings.py +268 -0
- novacode_cli/tui/diff_preview.py +199 -0
- novacode_cli/tui/gc_tuning.py +63 -0
- novacode_cli/tui/handoff_screen.py +206 -0
- novacode_cli/tui/harness.py +244 -0
- novacode_cli/tui/history_tree_screen.py +179 -0
- novacode_cli/tui/home.py +328 -0
- novacode_cli/tui/home_scene.py +94 -0
- novacode_cli/tui/icons.py +81 -0
- novacode_cli/tui/interface_styles.tcss +327 -0
- novacode_cli/tui/matrix3.py +108 -0
- novacode_cli/tui/mcp_tools_screen.py +131 -0
- novacode_cli/tui/motion.py +178 -0
- novacode_cli/tui/output_body.py +136 -0
- novacode_cli/tui/output_buffer.py +59 -0
- novacode_cli/tui/palette.py +334 -0
- novacode_cli/tui/pickers.py +237 -0
- novacode_cli/tui/prime_panel.py +506 -0
- novacode_cli/tui/provider_signin.py +213 -0
- novacode_cli/tui/pty_shell.py +159 -0
- novacode_cli/tui/reference_screens.py +444 -0
- novacode_cli/tui/resume_picker.py +346 -0
- novacode_cli/tui/rooms.py +597 -0
- novacode_cli/tui/screens.py +7088 -0
- novacode_cli/tui/session_import.py +333 -0
- novacode_cli/tui/session_pane.py +242 -0
- novacode_cli/tui/session_tab.py +42 -0
- novacode_cli/tui/session_transcript.py +118 -0
- novacode_cli/tui/shell_output.py +7 -0
- novacode_cli/tui/stall_watch.py +174 -0
- novacode_cli/tui/statusline.py +40 -0
- novacode_cli/tui/statusline_screen.py +91 -0
- novacode_cli/tui/teammate_updates.py +162 -0
- novacode_cli/tui/teammates.py +548 -0
- novacode_cli/tui/terminal.py +289 -0
- novacode_cli/tui/terminal_view.py +235 -0
- novacode_cli/tui/themes.py +118 -0
- novacode_cli/tui/update_notice.py +84 -0
- novacode_cli/tui/voice_downloads.py +113 -0
- novacode_cli/tui/widgets.py +2038 -0
- novacode_cli/tui/windows_input.py +38 -0
- novacode_cli/tui/workspace_approval.py +165 -0
- novacode_cli/ui/council_web.py +113 -0
- novacode_cli/ui/council_workspace.py +72 -0
- novacode_cli/ui/cowork_web.py +41 -0
- novacode_cli/ui/diff_highlight.py +160 -0
- novacode_cli/ui/execution.py +1396 -0
- novacode_cli/ui/exit_summary.py +65 -0
- novacode_cli/ui/hitl_approval.py +196 -0
- novacode_cli/ui/input_preparation.py +2 -0
- novacode_cli/ui/interrupt_handlers.py +215 -0
- novacode_cli/ui/question_prompt.py +151 -0
- novacode_cli/ui/status_phrases.py +157 -0
- novacode_cli/ui/stream_preview.py +66 -0
- novacode_cli/ui/streaming.py +2 -0
- novacode_cli/ui/subagent_tracking.py +2 -0
- novacode_cli/ui/ui_elements.py +1585 -0
- novacode_cli/ui/web_workspace.py +244 -0
- novacode_cli/ui_events.py +299 -0
- novacode_cli/update_ui.py +243 -0
- novacode_cli/updates.py +489 -0
- novacode_cli/utils/backend_patches.py +399 -0
- novacode_cli/utils/backend_paths.py +467 -0
- novacode_cli/utils/lazy_providers.py +51 -0
- novacode_cli/utils/model_info.py +223 -0
- novacode_cli/utils/pdf_extraction.py +183 -0
- novacode_cli/utils/startup.py +29 -0
- novacode_cli/utils/tasks.py +42 -0
- novacode_cli/utils/windows.py +9 -0
- novacode_cli/vixie/hook_adapter.py +127 -0
- novacode_cli/vixie/server.py +375 -0
- novacode_cli/wiki/__init__.py +15 -0
- novacode_cli/wiki/ask.py +56 -0
- novacode_cli/wiki/file.py +71 -0
- novacode_cli/wiki/ingest.py +184 -0
- novacode_cli/wiki/manager.py +261 -0
- novacode_cli-1.2.0.dist-info/METADATA +271 -0
- novacode_cli-1.2.0.dist-info/RECORD +691 -0
- novacode_cli-1.2.0.dist-info/WHEEL +5 -0
- novacode_cli-1.2.0.dist-info/entry_points.txt +2 -0
- novacode_cli-1.2.0.dist-info/licenses/LICENSE +21 -0
- novacode_cli-1.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2038 @@
|
|
|
1
|
+
"""Widgets for the Nova TUI.
|
|
2
|
+
|
|
3
|
+
Extracted verbatim from :mod:`novacode_cli.tui.app` (which re-exports these
|
|
4
|
+
names for backward compatibility). This module must not import from app.py.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import contextlib
|
|
11
|
+
import random
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import TYPE_CHECKING, Any, ClassVar, cast
|
|
14
|
+
|
|
15
|
+
from rich.cells import cell_len
|
|
16
|
+
from rich.markdown import Markdown
|
|
17
|
+
from rich.segment import Segment
|
|
18
|
+
from rich.style import Style
|
|
19
|
+
from rich.text import Text
|
|
20
|
+
from textual import events
|
|
21
|
+
from textual.app import ComposeResult
|
|
22
|
+
from textual.binding import Binding
|
|
23
|
+
from textual.containers import Horizontal, Vertical, VerticalScroll
|
|
24
|
+
from textual.content import Content
|
|
25
|
+
from textual.css.query import NoMatches
|
|
26
|
+
from textual.strip import Strip
|
|
27
|
+
from textual.selection import Selection
|
|
28
|
+
from textual.theme import Theme
|
|
29
|
+
from textual.widget import Widget
|
|
30
|
+
from textual.message import Message
|
|
31
|
+
from textual.widgets import Input, Static, TextArea
|
|
32
|
+
|
|
33
|
+
if TYPE_CHECKING:
|
|
34
|
+
from collections.abc import Iterable
|
|
35
|
+
|
|
36
|
+
from novacode_cli.tui.app import NovaApp
|
|
37
|
+
|
|
38
|
+
from novacode_cli.image_utils import ImageData
|
|
39
|
+
from novacode_cli.input_utils import (
|
|
40
|
+
PASTE_MIN_CHARS,
|
|
41
|
+
PASTE_MIN_NEWLINES,
|
|
42
|
+
PasteTracker,
|
|
43
|
+
format_paste_placeholder,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _UncachedMarkdown:
|
|
48
|
+
"""Renders a Markdown through rich's own implementation (see CachedMarkdown)."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, markdown: Markdown) -> None:
|
|
51
|
+
self._markdown = markdown
|
|
52
|
+
|
|
53
|
+
def __rich_console__(self, console: Any, options: Any) -> Any:
|
|
54
|
+
return Markdown.__rich_console__(self._markdown, console, options)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class CachedMarkdown(Markdown):
|
|
58
|
+
"""A ``rich`` Markdown that renders once per width and theme.
|
|
59
|
+
|
|
60
|
+
Textual renders a Static's content to *measure* its height and then again to
|
|
61
|
+
*paint* it, and repaints it whenever a neighbour mounts or the layout moves.
|
|
62
|
+
For Markdown each of those is a full parse-highlight-wrap: measured on six
|
|
63
|
+
long answers, 2.1 s went on height measurement (352 ms each) and 1.6 s on
|
|
64
|
+
fifteen paints (104 ms each) — over half a second of the UI loop per answer,
|
|
65
|
+
for output that is identical every time at a given width.
|
|
66
|
+
|
|
67
|
+
The segments are kept for the last width only: a resize re-renders, as it
|
|
68
|
+
must, and an old width is never asked for again.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
_cache_key: Any = None
|
|
72
|
+
_cache_segments: list | None = None
|
|
73
|
+
_style_names = tuple("markdown." + name for name in (
|
|
74
|
+
"h1", "h2", "h3", "h4", "h5", "h6", "h7", "code", "code_block",
|
|
75
|
+
"block_quote", "item.bullet", "item.number", "list", "link", "link_url",
|
|
76
|
+
"table.border", "table.header", "kbd",
|
|
77
|
+
))
|
|
78
|
+
|
|
79
|
+
def __rich_console__(self, console: Any, options: Any) -> Any:
|
|
80
|
+
# Rich segments contain resolved colours. Reuse them only while those
|
|
81
|
+
# styles still match, including when a restored reply changes theme.
|
|
82
|
+
styles = tuple(console.get_style(name, default="") for name in self._style_names)
|
|
83
|
+
key = (options.max_width, options.no_wrap, options.overflow, options.justify, styles)
|
|
84
|
+
if self._cache_segments is None or self._cache_key != key:
|
|
85
|
+
self._cache_segments = list(console.render(_UncachedMarkdown(self), options))
|
|
86
|
+
self._cache_key = key
|
|
87
|
+
return iter(self._cache_segments)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# ---------------------------------------------------------------------------
|
|
92
|
+
# Matrix rain — animated home screen banner
|
|
93
|
+
# ---------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class MatrixRain(Static):
|
|
97
|
+
"""A matrix-style digital rain with the NOVA ASCII logo composited on top.
|
|
98
|
+
|
|
99
|
+
Columns of falling half-width katakana/hex characters cascade down with a
|
|
100
|
+
fading trail (bright head, dimmer green tail). The ASCII banner is stamped
|
|
101
|
+
over the rain each frame: its solid cells occlude the rain (logo in front),
|
|
102
|
+
while regular-space gaps stay transparent so the rain shows *through* the
|
|
103
|
+
art — "rain behind the banner". The logo is tinted with the active TUI
|
|
104
|
+
theme's primary color, so it recolors live when the theme changes.
|
|
105
|
+
|
|
106
|
+
Half-width katakana (U+FF66–FF9D) are single-cell, so they align exactly
|
|
107
|
+
with the width-1 ASCII art — full-width katakana would drift the columns.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
KATAKANA = "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンアイウエオカキクケコサシスセソタチツテトナ"
|
|
111
|
+
|
|
112
|
+
def __init__(
|
|
113
|
+
self,
|
|
114
|
+
art: str = "",
|
|
115
|
+
width: int | None = None,
|
|
116
|
+
*,
|
|
117
|
+
animate: bool | None = None,
|
|
118
|
+
fps: int = 30,
|
|
119
|
+
compact: bool = False,
|
|
120
|
+
viewport_height: int | None = None,
|
|
121
|
+
matrix3: bool = False,
|
|
122
|
+
) -> None:
|
|
123
|
+
super().__init__("", id="matrix-rain")
|
|
124
|
+
self._matrix3 = matrix3
|
|
125
|
+
self._animation_enabled = animate
|
|
126
|
+
self._compact = compact
|
|
127
|
+
self._viewport_height = viewport_height
|
|
128
|
+
self._canvas_size: tuple[int, int] | None = None
|
|
129
|
+
from novacode_cli.tui.animation_rate import animation_fps
|
|
130
|
+
|
|
131
|
+
self._animation_fps = animation_fps(fps)
|
|
132
|
+
self._columns: list[dict] = []
|
|
133
|
+
self._chars = list(MatrixRain.KATAKANA)
|
|
134
|
+
self._width: int | None = None
|
|
135
|
+
self._timer: Any = None # set_interval handle for pause/resume
|
|
136
|
+
self._needs_layout = True # one layout pass after mount/reflow
|
|
137
|
+
# Theme-derived render values, recomputed only when the theme changes
|
|
138
|
+
# (keyed by _theme_key) instead of every frame.
|
|
139
|
+
self._palette: tuple[str, str, str, str] | None = None
|
|
140
|
+
self._art_style_str: str = ""
|
|
141
|
+
self._palette_key: str | None = None
|
|
142
|
+
# Rich Style objects for the palette, built once per theme. Segments
|
|
143
|
+
# take a Style, and the buffers hold these objects directly so a frame
|
|
144
|
+
# never parses a color string.
|
|
145
|
+
self._styles: tuple[Style, Style, Style, Style] | None = None
|
|
146
|
+
self._art_style_obj: Style | None = None
|
|
147
|
+
# The rendered frame, as one Strip per row. render_line() serves from
|
|
148
|
+
# here; _tick() replaces it.
|
|
149
|
+
self._strips: list[Strip] = []
|
|
150
|
+
self._configure(art, width)
|
|
151
|
+
|
|
152
|
+
def _configure(self, art: str, width: int | None) -> None:
|
|
153
|
+
"""(Re)compute the grid + logo placement for the given art and width."""
|
|
154
|
+
self._art_source = art
|
|
155
|
+
# Trim blank top/bottom lines so the logo sits tightly in the rain.
|
|
156
|
+
art_lines = art.splitlines() if art else []
|
|
157
|
+
while art_lines and not art_lines[0].strip():
|
|
158
|
+
art_lines.pop(0)
|
|
159
|
+
while art_lines and not art_lines[-1].strip():
|
|
160
|
+
art_lines.pop()
|
|
161
|
+
if self._viewport_height is not None and len(art_lines) + 2 > self._viewport_height:
|
|
162
|
+
from novacode_cli._version import __version__
|
|
163
|
+
from novacode_cli.brand import art_for, compact_mark
|
|
164
|
+
|
|
165
|
+
fallback = art_for(
|
|
166
|
+
width=(width or 80) - 1, version=__version__, height=0, lower_wordmark=True
|
|
167
|
+
)
|
|
168
|
+
art_lines = fallback.strip("\n").splitlines()
|
|
169
|
+
if len(art_lines) + 2 > self._viewport_height:
|
|
170
|
+
art_lines = [compact_mark()]
|
|
171
|
+
self._art_lines = art_lines
|
|
172
|
+
|
|
173
|
+
art_w = max((cell_len(ln) for ln in art_lines), default=0)
|
|
174
|
+
art_h = len(art_lines)
|
|
175
|
+
# Fill the content width and centre the lockup within it. Subtract the
|
|
176
|
+
# transcript's horizontal padding (2 cells each side, see
|
|
177
|
+
# `#transcript { padding: 1 2 }`); the scrollbar reserves no column (it is
|
|
178
|
+
# hidden and the gutter is `auto`), so the content width is exactly
|
|
179
|
+
# ``width - 4`` and the art is centred across all of it.
|
|
180
|
+
#
|
|
181
|
+
# The grid is *exactly* the content width -- no clamp in either
|
|
182
|
+
# direction. It used to be ``min(max(usable, art_w, 60), 200)``, and both
|
|
183
|
+
# ends of that were wrong:
|
|
184
|
+
#
|
|
185
|
+
# * the 200 ceiling left a blank band down the right-hand side of the
|
|
186
|
+
# backdrop on any terminal wider than ~204 columns. Measured in the real
|
|
187
|
+
# app: at 200 columns the grid filled the content width exactly, but at
|
|
188
|
+
# 260 it pinned at 200 against 256 available, and at 320 it was 200
|
|
189
|
+
# against 316 -- a 116-column empty stripe, which is the "rain does not
|
|
190
|
+
# go across the window" report.
|
|
191
|
+
# * the 60 floor made the grid *wider* than the content area on a narrow
|
|
192
|
+
# terminal (at 50 columns the grid was 60 against 46 available), so
|
|
193
|
+
# every row wrapped.
|
|
194
|
+
#
|
|
195
|
+
# The ceiling's stated justification was per-frame cost, but measurement
|
|
196
|
+
# does not support it: a frame build is ~2 ms at 320 columns and ~7 ms at
|
|
197
|
+
# 640 (15 fps leaves a 66 ms budget), the cost is dominated by the strip
|
|
198
|
+
# build rather than the simulation, and the p99 spikes at wide grids are
|
|
199
|
+
# GC, not the grid. No real terminal reaches a width where this bites.
|
|
200
|
+
#
|
|
201
|
+
# `art_w` stays in the max() as a floor: the art must never be wider
|
|
202
|
+
# than the grid, or the composite would clip its right edge. (`art_for`
|
|
203
|
+
# keeps the art within the content width already, so in practice this
|
|
204
|
+
# guards art handed in from elsewhere.)
|
|
205
|
+
usable = (width or 80) - 4
|
|
206
|
+
self._col_count = max(usable, art_w)
|
|
207
|
+
self._row_count = max(art_h + 2, 10) if self._compact else max(art_h + 6, 18)
|
|
208
|
+
self._art_left = max(0, (self._col_count - art_w) // 2)
|
|
209
|
+
self._art_top = 1 if self._compact else 2
|
|
210
|
+
if self._viewport_height is not None:
|
|
211
|
+
self._row_count = max(1, self._viewport_height)
|
|
212
|
+
self._art_left = 1
|
|
213
|
+
self._art_top = max(0, self._row_count - art_h - 2)
|
|
214
|
+
self._art_w = art_w # the art's bounding box, measured with cell_len
|
|
215
|
+
self._width = width
|
|
216
|
+
|
|
217
|
+
def reflow(
|
|
218
|
+
self,
|
|
219
|
+
art: str,
|
|
220
|
+
width: int | None,
|
|
221
|
+
*,
|
|
222
|
+
compact: bool | None = None,
|
|
223
|
+
viewport_height: int | None = None,
|
|
224
|
+
matrix3: bool | None = None,
|
|
225
|
+
) -> None:
|
|
226
|
+
"""Re-grid when the terminal width or banner layout changes."""
|
|
227
|
+
if viewport_height is not None and self.is_mounted:
|
|
228
|
+
# Once laid out, the canvas owns the grid dimensions. Reopening
|
|
229
|
+
# home in another session does not resize this shared widget, so
|
|
230
|
+
# replacing them with terminal estimates would never be corrected
|
|
231
|
+
# by on_resize and would push the logo below its original position.
|
|
232
|
+
canvas = (self.size.width, self.size.height) if self.size.area else self._canvas_size
|
|
233
|
+
if canvas is not None:
|
|
234
|
+
width, viewport_height = canvas[0] + 4, canvas[1]
|
|
235
|
+
if (
|
|
236
|
+
width == self._width
|
|
237
|
+
and (compact is None or compact == self._compact)
|
|
238
|
+
and art == getattr(self, "_art_source", art)
|
|
239
|
+
and viewport_height == self._viewport_height
|
|
240
|
+
and (matrix3 is None or matrix3 == self._matrix3)
|
|
241
|
+
):
|
|
242
|
+
return
|
|
243
|
+
self._art_source = art
|
|
244
|
+
self._viewport_height = viewport_height
|
|
245
|
+
if matrix3 is not None and matrix3 != self._matrix3:
|
|
246
|
+
self._palette_key = None
|
|
247
|
+
self._matrix3 = matrix3
|
|
248
|
+
if compact is not None:
|
|
249
|
+
self._compact = compact
|
|
250
|
+
self._configure(art, width)
|
|
251
|
+
if self.is_mounted:
|
|
252
|
+
self._init_columns() # rebuild rain columns for the new width
|
|
253
|
+
self._apply_size() # the grid changed, so the widget box must too
|
|
254
|
+
self._needs_layout = True # next frame must re-layout (size changed)
|
|
255
|
+
self.redraw_frame()
|
|
256
|
+
|
|
257
|
+
def redraw_frame(self, _theme: Theme | None = None) -> None:
|
|
258
|
+
"""Refresh the logo on resize/theme changes, even with animation off."""
|
|
259
|
+
self._strips = self._build_strips()
|
|
260
|
+
self.refresh(layout=self._needs_layout)
|
|
261
|
+
self._needs_layout = False
|
|
262
|
+
|
|
263
|
+
def _theme_base_color(self):
|
|
264
|
+
"""The active theme's primary color as a Textual ``Color`` object.
|
|
265
|
+
|
|
266
|
+
Handles ANSI theme names (``ansi_blue`` → ``blue``). A theme colour that
|
|
267
|
+
cannot be read or parsed falls back to :data:`brand.FALLBACK_ACCENT` —
|
|
268
|
+
the same accent the pre-TUI boot screen uses — rather than the old
|
|
269
|
+
hardcoded green, which was a third brand colour disagreeing with both
|
|
270
|
+
the red boot splash and the blue TUI.
|
|
271
|
+
"""
|
|
272
|
+
from textual.color import Color
|
|
273
|
+
|
|
274
|
+
from novacode_cli.brand import FALLBACK_ACCENT
|
|
275
|
+
|
|
276
|
+
raw = None
|
|
277
|
+
try:
|
|
278
|
+
raw = self.app.current_theme.primary
|
|
279
|
+
except Exception: # noqa: BLE001
|
|
280
|
+
try:
|
|
281
|
+
raw = self.app.theme_variables.get("primary")
|
|
282
|
+
except Exception: # noqa: BLE001
|
|
283
|
+
raw = None
|
|
284
|
+
raw = (raw or FALLBACK_ACCENT).strip()
|
|
285
|
+
if raw.startswith("ansi_"):
|
|
286
|
+
raw = raw[len("ansi_") :]
|
|
287
|
+
try:
|
|
288
|
+
return Color.parse(raw)
|
|
289
|
+
except Exception: # noqa: BLE001
|
|
290
|
+
return Color.parse(FALLBACK_ACCENT)
|
|
291
|
+
|
|
292
|
+
def _art_style(self) -> str:
|
|
293
|
+
"""Bold style for the logo — the theme's primary color at full strength."""
|
|
294
|
+
return f"bold {self._theme_base_color().hex}"
|
|
295
|
+
|
|
296
|
+
def _theme_key(self) -> str:
|
|
297
|
+
"""The active theme's primary color string — the palette cache key."""
|
|
298
|
+
from novacode_cli.brand import FALLBACK_ACCENT
|
|
299
|
+
|
|
300
|
+
raw = None
|
|
301
|
+
try:
|
|
302
|
+
raw = self.app.current_theme.primary
|
|
303
|
+
except Exception: # noqa: BLE001
|
|
304
|
+
try:
|
|
305
|
+
raw = self.app.theme_variables.get("primary")
|
|
306
|
+
except Exception: # noqa: BLE001
|
|
307
|
+
raw = None
|
|
308
|
+
return (raw or FALLBACK_ACCENT).strip()
|
|
309
|
+
|
|
310
|
+
def _ensure_theme_cache(self) -> None:
|
|
311
|
+
"""Recompute the palette + art style only when the theme color changes."""
|
|
312
|
+
key = self._theme_key()
|
|
313
|
+
if self._matrix3:
|
|
314
|
+
variables = self.app.theme_variables
|
|
315
|
+
key = f"{key}:{variables['background']}:{variables['foreground']}"
|
|
316
|
+
if key != self._palette_key:
|
|
317
|
+
self._palette = self._rain_palette()
|
|
318
|
+
self._art_style_str = self._art_style()
|
|
319
|
+
# Parsed once per theme, then stored in the frame buffers directly.
|
|
320
|
+
# These are the identity-comparable singletons the run-length scan
|
|
321
|
+
# in _build_strips relies on.
|
|
322
|
+
self._styles = tuple(Style.parse(c) for c in self._palette)
|
|
323
|
+
self._art_style_obj = Style.parse(self._art_style_str)
|
|
324
|
+
self._palette_key = key
|
|
325
|
+
if self._matrix3:
|
|
326
|
+
from textual.color import Color
|
|
327
|
+
|
|
328
|
+
from novacode_cli.tui.palette import cached_palette
|
|
329
|
+
|
|
330
|
+
base = self._theme_base_color()
|
|
331
|
+
resolved = cached_palette(self.app.current_theme)
|
|
332
|
+
background = Color.parse(variables["background"])
|
|
333
|
+
if background.ansi is not None:
|
|
334
|
+
background = Color.parse(resolved.surface)
|
|
335
|
+
foreground = resolved.text
|
|
336
|
+
self._matrix3_styles = (
|
|
337
|
+
Style(color=foreground, bold=True),
|
|
338
|
+
*(Style(color=base.blend(background, level / 16).hex) for level in range(16)),
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
def _rain_palette(self) -> tuple[str, str, str, str]:
|
|
342
|
+
"""(head, near, mid, tail) hex colors — a *dimmed* theme-tinted gradient.
|
|
343
|
+
|
|
344
|
+
Derived from the theme color and darkened progressively so the rain reads
|
|
345
|
+
as a subtle backdrop (no bright white head) and recolors with the theme.
|
|
346
|
+
"""
|
|
347
|
+
base = self._theme_base_color()
|
|
348
|
+
return (
|
|
349
|
+
base.darken(0.15).hex, # head — muted, not white
|
|
350
|
+
base.darken(0.40).hex, # near head
|
|
351
|
+
base.darken(0.60).hex, # mid trail
|
|
352
|
+
base.darken(0.78).hex, # tail — barely there
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
def _apply_size(self) -> None:
|
|
356
|
+
"""Pin the widget to the grid it renders.
|
|
357
|
+
|
|
358
|
+
``render_line`` produces no renderable for Textual to measure, so the
|
|
359
|
+
auto-sizing a ``Static`` used to get from its content is gone and the
|
|
360
|
+
box would collapse to zero height. The grid dimensions are the size.
|
|
361
|
+
"""
|
|
362
|
+
self.styles.width = "1fr" if self._viewport_height is not None else self._col_count
|
|
363
|
+
self.styles.height = "1fr" if self._viewport_height is not None else self._row_count
|
|
364
|
+
|
|
365
|
+
def on_resize(self, event: events.Resize) -> None:
|
|
366
|
+
"""Fit Classic's rain to its canvas, including multiline composer growth."""
|
|
367
|
+
if self._viewport_height is None or not event.size.area:
|
|
368
|
+
return
|
|
369
|
+
self._canvas_size = (event.size.width, event.size.height)
|
|
370
|
+
self._viewport_height = event.size.height
|
|
371
|
+
self._configure(self._art_source, event.size.width + 4)
|
|
372
|
+
self._init_columns()
|
|
373
|
+
self.redraw_frame()
|
|
374
|
+
|
|
375
|
+
def on_mount(self) -> None:
|
|
376
|
+
self._init_columns()
|
|
377
|
+
self._apply_size()
|
|
378
|
+
self._strips = self._build_strips() # paint something on the first frame
|
|
379
|
+
self._needs_layout = True # first frame must establish the widget size
|
|
380
|
+
self.app.theme_changed_signal.subscribe(self, self.redraw_frame)
|
|
381
|
+
# Frame rate is configurable; scale movement to keep the fall rate
|
|
382
|
+
# stable rather than making a higher refresh rate accelerate the rain.
|
|
383
|
+
# An idle terminal should not continuously repaint a decorative banner.
|
|
384
|
+
# Keep its first themed frame, with the original rain available opt-in.
|
|
385
|
+
if self._animation_enabled is None:
|
|
386
|
+
import os
|
|
387
|
+
|
|
388
|
+
self._animation_enabled = (
|
|
389
|
+
os.environ.get("NOVA_ANIMATIONS", "").strip().lower()
|
|
390
|
+
in {"1", "true", "yes"}
|
|
391
|
+
)
|
|
392
|
+
# Start the timer directly: ``is_mounted`` is still False inside
|
|
393
|
+
# ``on_mount``, so ``set_animation_enabled`` would return early and the
|
|
394
|
+
# rain would never run even when it was asked for.
|
|
395
|
+
if self._animation_enabled:
|
|
396
|
+
self._start_timer()
|
|
397
|
+
|
|
398
|
+
def set_animation_enabled(self, enabled: bool) -> None:
|
|
399
|
+
"""Start or stop the rain timer without rebuilding the banner."""
|
|
400
|
+
self._animation_enabled = enabled
|
|
401
|
+
if not self.is_mounted:
|
|
402
|
+
return
|
|
403
|
+
if enabled and self._timer is None:
|
|
404
|
+
self._start_timer()
|
|
405
|
+
elif not enabled and self._timer is not None:
|
|
406
|
+
self._timer.stop()
|
|
407
|
+
self._timer = None
|
|
408
|
+
|
|
409
|
+
def _start_timer(self) -> None:
|
|
410
|
+
"""Create the rain timer, honouring the current OS-focus state."""
|
|
411
|
+
if self._timer is not None:
|
|
412
|
+
return
|
|
413
|
+
self._timer = self.set_interval(1 / self._animation_fps, self._tick)
|
|
414
|
+
if not getattr(self.app, "_os_focused", True):
|
|
415
|
+
self._timer.pause()
|
|
416
|
+
|
|
417
|
+
def set_frame_rate(self, fps: int) -> None:
|
|
418
|
+
"""Change the active rain cadence without starting disabled animation."""
|
|
419
|
+
from novacode_cli.tui.animation_rate import animation_fps
|
|
420
|
+
|
|
421
|
+
fps = animation_fps(fps)
|
|
422
|
+
if fps == self._animation_fps:
|
|
423
|
+
return
|
|
424
|
+
self._animation_fps = fps
|
|
425
|
+
if self._timer is not None:
|
|
426
|
+
self._timer.stop()
|
|
427
|
+
self._timer = None
|
|
428
|
+
self._start_timer()
|
|
429
|
+
|
|
430
|
+
def pause(self) -> None:
|
|
431
|
+
"""Pause the rain timer (called when the app loses OS focus or rain is
|
|
432
|
+
scrolled out of view)."""
|
|
433
|
+
if self._timer is not None:
|
|
434
|
+
self._timer.pause()
|
|
435
|
+
|
|
436
|
+
def resume(self) -> None:
|
|
437
|
+
"""Resume the rain timer (called when the app regains OS focus)."""
|
|
438
|
+
if self._timer is not None:
|
|
439
|
+
self._timer.resume()
|
|
440
|
+
|
|
441
|
+
def _init_columns(self) -> None:
|
|
442
|
+
"""Seed a column per grid column, already in flight.
|
|
443
|
+
|
|
444
|
+
Heads are spread across the whole grid (and just above it) rather than
|
|
445
|
+
stacked above row 0. The old seeding used ``uniform(-span, 0)``, which
|
|
446
|
+
put every head off-screen, so the banner opened empty and the rain only
|
|
447
|
+
filled in over the next ~10-20 seconds -- the "rain does not cover the
|
|
448
|
+
window" complaint. Recycling a column still restarts it above the top
|
|
449
|
+
(see ``_fill_buffers``), which is what keeps the fall continuous.
|
|
450
|
+
"""
|
|
451
|
+
self._chars = list("0123456789" if self._viewport_height is not None else self.KATAKANA)
|
|
452
|
+
self._columns = []
|
|
453
|
+
for column_index in range(self._col_count):
|
|
454
|
+
trail = random.randint(5, 14)
|
|
455
|
+
if self._viewport_height is not None:
|
|
456
|
+
trail = (
|
|
457
|
+
random.randint(10, max(14, self._row_count)) # noqa: S311 — decorative rain
|
|
458
|
+
if column_index % 3
|
|
459
|
+
else 0
|
|
460
|
+
)
|
|
461
|
+
self._columns.append(
|
|
462
|
+
{
|
|
463
|
+
"pos": random.uniform(-trail, self._row_count),
|
|
464
|
+
"speed": random.uniform(0.07, 0.18), # adjusted for 15fps
|
|
465
|
+
"trail": trail,
|
|
466
|
+
}
|
|
467
|
+
)
|
|
468
|
+
# Pre-allocate frame buffers (reused per frame to avoid GC churn).
|
|
469
|
+
# The style buffer holds Rich ``Style`` objects (None = blank cell), not
|
|
470
|
+
# color strings: they go straight into Segments, so a frame does no
|
|
471
|
+
# style parsing at all.
|
|
472
|
+
self._frame_lines = [[" "] * self._col_count for _ in range(self._row_count)]
|
|
473
|
+
self._frame_styles = [[None] * self._col_count for _ in range(self._row_count)]
|
|
474
|
+
# Prebuilt blank rows copied in (slice-assign) to clear buffers at C speed.
|
|
475
|
+
self._blank_line = [" "] * self._col_count
|
|
476
|
+
self._blank_style = [None] * self._col_count
|
|
477
|
+
# Precomputed random-char pool: strided per frame from a random offset so
|
|
478
|
+
# the look stays random without a random.choice() call per cell.
|
|
479
|
+
self._char_pool = [random.choice(self._chars) for _ in range(512)]
|
|
480
|
+
if self._matrix3:
|
|
481
|
+
from novacode_cli.tui.matrix3 import Matrix3
|
|
482
|
+
|
|
483
|
+
self._matrix3_engine = Matrix3(self._col_count, self._row_count)
|
|
484
|
+
|
|
485
|
+
def _tick(self) -> None:
|
|
486
|
+
"""Advance one frame of the rain, then stamp the logo over it.
|
|
487
|
+
|
|
488
|
+
Early-returns (no work) when the widget is scrolled out of the visible
|
|
489
|
+
viewport, so transcript messages push the rain off-screen cheaply.
|
|
490
|
+
"""
|
|
491
|
+
# Pause animation updates while TTS is playing to prevent audio stuttering
|
|
492
|
+
# due to thread / GIL contention on the main loop.
|
|
493
|
+
try:
|
|
494
|
+
vp = getattr(self.app, "_voice_pipeline", None)
|
|
495
|
+
if vp is not None and vp.tts_active:
|
|
496
|
+
return
|
|
497
|
+
except Exception: # noqa: BLE001
|
|
498
|
+
pass
|
|
499
|
+
|
|
500
|
+
# Skip the (expensive) frame build when the banner is scrolled out of the
|
|
501
|
+
# transcript viewport. Both regions are in SCREEN coordinates, so they're
|
|
502
|
+
# directly comparable: if the widget sits entirely above or below the
|
|
503
|
+
# parent scroll-container's visible area, there's nothing to draw.
|
|
504
|
+
import sys
|
|
505
|
+
|
|
506
|
+
is_testing = "pytest" in sys.modules or getattr(self.app, "_driving", False)
|
|
507
|
+
try:
|
|
508
|
+
# The compositor's visible set, NOT `self.region`. `region` goes
|
|
509
|
+
# through `screen.find_widget` -> `compositor.full_map`, which any
|
|
510
|
+
# scroll invalidates — so asking "am I on screen?" re-arranged every
|
|
511
|
+
# widget in the app, 15 times a second, for as long as the banner
|
|
512
|
+
# existed (measured: 96 full arranges in 97 ticks, ~17 ms each).
|
|
513
|
+
# `visible_widgets` is what the renderer already keeps current.
|
|
514
|
+
if not is_testing and self not in self.screen._compositor.visible_widgets:
|
|
515
|
+
return
|
|
516
|
+
except Exception: # noqa: BLE001
|
|
517
|
+
pass
|
|
518
|
+
|
|
519
|
+
# layout=False: the frame's row/col count is constant between reflows,
|
|
520
|
+
# so a repaint suffices. The default layout=True re-laid-out the WHOLE
|
|
521
|
+
# screen DOM (up to ~400 transcript widgets) on every frame — the
|
|
522
|
+
# single biggest source of TUI jank while the rain was visible. A
|
|
523
|
+
# one-shot layout pass still runs after mount/reflow (size changes).
|
|
524
|
+
needs_layout = self._needs_layout
|
|
525
|
+
self._needs_layout = False
|
|
526
|
+
self._strips = self._build_strips()
|
|
527
|
+
self.refresh(layout=needs_layout)
|
|
528
|
+
|
|
529
|
+
def render_line(self, y: int) -> Strip:
|
|
530
|
+
"""Serve row *y* from the frame built by :meth:`_tick`.
|
|
531
|
+
|
|
532
|
+
Rendering through ``render_line`` rather than ``Static.update()`` is the
|
|
533
|
+
whole performance story of this widget. Handing Textual a Rich ``Text``
|
|
534
|
+
of ~1000 style spans cost **14.7 ms per frame** on a 194-column grid —
|
|
535
|
+
four times the cost of simulating the rain itself — so at 15 fps the
|
|
536
|
+
banner burned 220 ms of every second on the main thread. That is what
|
|
537
|
+
made typing feel laggy. Building Segments straight into Strips costs
|
|
538
|
+
**1.6 ms** (9x), and measured event-loop p99 went 66 ms -> 16 ms, which
|
|
539
|
+
is the same as with no rain at all.
|
|
540
|
+
|
|
541
|
+
Note the fix is NOT "avoid re-parsing style strings" — that was the
|
|
542
|
+
obvious guess and it is wrong. Passing pre-parsed ``Style`` objects into
|
|
543
|
+
a ``Text`` measured *worse* (28 ms); the cost is ``Text``'s own span
|
|
544
|
+
resolution and line division, so the only real fix is to not build one.
|
|
545
|
+
"""
|
|
546
|
+
if 0 <= y < len(self._strips):
|
|
547
|
+
return self._strips[y]
|
|
548
|
+
return Strip.blank(self.size.width or self._col_count, self.rich_style)
|
|
549
|
+
|
|
550
|
+
def _build_strips(self) -> list[Strip]:
|
|
551
|
+
"""Advance one frame and render it as one ``Strip`` per row."""
|
|
552
|
+
self._fill_buffers()
|
|
553
|
+
background = Style(bgcolor=self.rich_style.bgcolor)
|
|
554
|
+
cols = self._col_count
|
|
555
|
+
lines = self._frame_lines
|
|
556
|
+
styles = self._frame_styles
|
|
557
|
+
strips: list[Strip] = []
|
|
558
|
+
for y in range(self._row_count):
|
|
559
|
+
line = lines[y]
|
|
560
|
+
st = styles[y]
|
|
561
|
+
segments: list[Segment] = []
|
|
562
|
+
x = 0
|
|
563
|
+
while x < cols:
|
|
564
|
+
s = st[x]
|
|
565
|
+
j = x + 1
|
|
566
|
+
# Identity, not equality: every style in the buffer is one of
|
|
567
|
+
# the cached per-theme singletons (or None), so `is` is both
|
|
568
|
+
# correct here and cheaper than Style.__eq__ per cell.
|
|
569
|
+
while j < cols and st[j] is s:
|
|
570
|
+
j += 1
|
|
571
|
+
segments.append(
|
|
572
|
+
Segment("".join(line[x:j]) if s else " " * (j - x), s or Style.null())
|
|
573
|
+
)
|
|
574
|
+
x = j
|
|
575
|
+
strips.append(Strip(segments, cols).apply_style(background))
|
|
576
|
+
return strips
|
|
577
|
+
|
|
578
|
+
def render(self) -> Text:
|
|
579
|
+
"""The current frame as text.
|
|
580
|
+
|
|
581
|
+
Textual never calls this — :meth:`render_line` is overridden, which
|
|
582
|
+
takes precedence — but ``Static.render`` would otherwise return the
|
|
583
|
+
empty renderable this widget no longer sets, which reads as "the banner
|
|
584
|
+
is blank" to anything that inspects it. Returning the live frame keeps
|
|
585
|
+
that honest. It does NOT advance the rain.
|
|
586
|
+
"""
|
|
587
|
+
return self._frame_text()
|
|
588
|
+
|
|
589
|
+
def _build_frame(self) -> Text:
|
|
590
|
+
"""Advance one frame and return it as a Rich ``Text``.
|
|
591
|
+
|
|
592
|
+
NOT the render path — :meth:`render_line` is. Kept because plain text is
|
|
593
|
+
the readable form to assert against (grid width, which glyphs may
|
|
594
|
+
appear), and those checks are worth keeping.
|
|
595
|
+
"""
|
|
596
|
+
self._fill_buffers()
|
|
597
|
+
return self._frame_text()
|
|
598
|
+
|
|
599
|
+
def _frame_text(self) -> Text:
|
|
600
|
+
"""Render the buffers as text, without advancing the simulation."""
|
|
601
|
+
if not hasattr(self, "_frame_lines"):
|
|
602
|
+
# Textual may measure content before on_mount allocates the grid.
|
|
603
|
+
return Text("\n".join(self._art_lines), style=self._art_style())
|
|
604
|
+
cols = self._col_count
|
|
605
|
+
text = Text()
|
|
606
|
+
for y in range(self._row_count):
|
|
607
|
+
line = self._frame_lines[y]
|
|
608
|
+
st = self._frame_styles[y]
|
|
609
|
+
x = 0
|
|
610
|
+
while x < cols:
|
|
611
|
+
s = st[x]
|
|
612
|
+
j = x + 1
|
|
613
|
+
while j < cols and st[j] is s:
|
|
614
|
+
j += 1
|
|
615
|
+
text.append("".join(line[x:j]) if s else " " * (j - x), s)
|
|
616
|
+
x = j
|
|
617
|
+
if y < self._row_count - 1:
|
|
618
|
+
text.append("\n")
|
|
619
|
+
return text
|
|
620
|
+
|
|
621
|
+
def _fill_buffers(self) -> None:
|
|
622
|
+
"""Advance the simulation one frame into the reusable cell buffers."""
|
|
623
|
+
if self._matrix3:
|
|
624
|
+
self._ensure_theme_cache()
|
|
625
|
+
self._matrix3_engine.draw(
|
|
626
|
+
self._frame_lines, self._frame_styles, self._matrix3_styles, self._animation_fps,
|
|
627
|
+
)
|
|
628
|
+
self._composite_art()
|
|
629
|
+
return
|
|
630
|
+
rows = self._row_count
|
|
631
|
+
lines = self._frame_lines
|
|
632
|
+
styles = self._frame_styles
|
|
633
|
+
|
|
634
|
+
# Clear buffers for the new frame (C-level slice copy of prebuilt rows).
|
|
635
|
+
blank_l = self._blank_line
|
|
636
|
+
blank_s = self._blank_style
|
|
637
|
+
for y in range(rows):
|
|
638
|
+
lines[y][:] = blank_l
|
|
639
|
+
styles[y][:] = blank_s
|
|
640
|
+
|
|
641
|
+
self._ensure_theme_cache()
|
|
642
|
+
head_c, near_c, mid_c, tail_c = self._styles
|
|
643
|
+
pool = self._char_pool
|
|
644
|
+
pool_len = len(pool)
|
|
645
|
+
idx = random.randrange(pool_len) # one RNG call per frame
|
|
646
|
+
|
|
647
|
+
# The rain is drawn on every column, including the ones the art covers.
|
|
648
|
+
# Confining it was tried and removed: the art is stamped *after* the
|
|
649
|
+
# rain, so it overwrites every inked cell anyway -- masking those cells
|
|
650
|
+
# changed nothing observable (measured 0 katakana visible on inked cells
|
|
651
|
+
# with the confinement removed). Skipping the art's *bounding box* was
|
|
652
|
+
# worse than useless: it is ~74 of the 76 columns an 80-column terminal
|
|
653
|
+
# draws, so skipping it on every row carved a full-height dead stripe and
|
|
654
|
+
# the rain looked like it stopped at the portrait.
|
|
655
|
+
for col, d in enumerate(self._columns):
|
|
656
|
+
d["pos"] += d["speed"] * 15 / self._animation_fps
|
|
657
|
+
if d["pos"] > rows + d["trail"]: # reset when fully off-screen
|
|
658
|
+
d["pos"] = random.uniform(-rows, -3)
|
|
659
|
+
d["speed"] = random.uniform(0.08, 0.23) # adjusted for 15fps
|
|
660
|
+
d["trail"] = random.randint(5, 14)
|
|
661
|
+
|
|
662
|
+
tail_start = max(0, int(d["pos"]) - d["trail"])
|
|
663
|
+
head = min(rows - 1, int(d["pos"]))
|
|
664
|
+
for y in range(tail_start, head + 1):
|
|
665
|
+
dist = head - y
|
|
666
|
+
lines[y][col] = pool[idx]
|
|
667
|
+
idx += 1
|
|
668
|
+
if idx == pool_len:
|
|
669
|
+
idx = 0
|
|
670
|
+
if dist == 0:
|
|
671
|
+
styles[y][col] = head_c
|
|
672
|
+
elif dist <= 2:
|
|
673
|
+
styles[y][col] = near_c
|
|
674
|
+
elif dist <= 5:
|
|
675
|
+
styles[y][col] = mid_c
|
|
676
|
+
else:
|
|
677
|
+
styles[y][col] = tail_c
|
|
678
|
+
|
|
679
|
+
self._composite_art()
|
|
680
|
+
|
|
681
|
+
def _composite_art(self) -> None:
|
|
682
|
+
"""Stamp the shared brand over either rain simulation."""
|
|
683
|
+
rows, cols = self._row_count, self._col_count
|
|
684
|
+
lines, styles = self._frame_lines, self._frame_styles
|
|
685
|
+
# Composite the logo on top. Solid art cells occlude the rain; regular
|
|
686
|
+
# spaces stay transparent so the rain shows through the gaps.
|
|
687
|
+
if self._art_lines:
|
|
688
|
+
art_style = self._art_style_obj
|
|
689
|
+
for ay, art_line in enumerate(self._art_lines):
|
|
690
|
+
gy = self._art_top + ay
|
|
691
|
+
if not 0 <= gy < rows:
|
|
692
|
+
continue
|
|
693
|
+
row_l = lines[gy]
|
|
694
|
+
row_s = styles[gy]
|
|
695
|
+
left = self._art_left
|
|
696
|
+
# Advance by CELL, not by codepoint. Rich gives a zero-width
|
|
697
|
+
# variation selector (U+FE0E/U+FE0F) no cell of its own, so
|
|
698
|
+
# indexing a per-codepoint loop by that number would shift every
|
|
699
|
+
# cell after it one column right. brand.py keeps such pairs out
|
|
700
|
+
# of the art; this makes the compositor agree with cell_len
|
|
701
|
+
# regardless.
|
|
702
|
+
ax = 0
|
|
703
|
+
for ch in art_line:
|
|
704
|
+
if ch in ("\ufe0e", "\ufe0f"):
|
|
705
|
+
continue # zero-width: shares the previous char's cell
|
|
706
|
+
if ch != " ":
|
|
707
|
+
gx = left + ax
|
|
708
|
+
if 0 <= gx < cols:
|
|
709
|
+
# Matrix3 uses two-cell Japanese glyphs. Occluding either
|
|
710
|
+
# half must erase the whole glyph before stamping the logo.
|
|
711
|
+
if row_l[gx] == "" and gx > 0:
|
|
712
|
+
row_l[gx - 1] = " "
|
|
713
|
+
row_s[gx - 1] = None
|
|
714
|
+
if gx + 1 < cols and row_l[gx + 1] == "":
|
|
715
|
+
row_l[gx + 1] = " "
|
|
716
|
+
row_s[gx + 1] = None
|
|
717
|
+
row_l[gx] = ch
|
|
718
|
+
row_s[gx] = art_style
|
|
719
|
+
ax += cell_len(ch)
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
# Nova's default palette, registered as a real Textual theme so /theme can swap
|
|
724
|
+
# it for any other theme. Previously these colors were hardcoded as CSS
|
|
725
|
+
# variables ($primary: …) at the top of NovaApp.CSS, which *overrode* the active
|
|
726
|
+
# theme and made theme switching a no-op. Defining them here instead lets the
|
|
727
|
+
# active theme drive every $variable, so /theme actually changes the UI.
|
|
728
|
+
NOVA_TOKYO_NIGHT = Theme(
|
|
729
|
+
name="tokyo-night",
|
|
730
|
+
primary="#7aa2f7",
|
|
731
|
+
secondary="#9ece6a",
|
|
732
|
+
accent="#bb9af7",
|
|
733
|
+
success="#73daca",
|
|
734
|
+
warning="#e0af68",
|
|
735
|
+
error="#f7768e",
|
|
736
|
+
surface="#1a1b26",
|
|
737
|
+
panel="#24283b",
|
|
738
|
+
background="#13141d",
|
|
739
|
+
foreground="#c0caf5",
|
|
740
|
+
boost="#2f3346",
|
|
741
|
+
dark=True,
|
|
742
|
+
variables={
|
|
743
|
+
"text-muted": "#565f89",
|
|
744
|
+
"border": "#3b4261",
|
|
745
|
+
},
|
|
746
|
+
)
|
|
747
|
+
# The Matrix theme: phosphor green on near-black, the palette of the film's
|
|
748
|
+
# terminal. Registered alongside tokyo-night so /theme can select it. Kept
|
|
749
|
+
# deliberately monochrome-green — the accent/secondary/success hues are all
|
|
750
|
+
# shades of the same phosphor so the UI reads as one CRT, with `error` the only
|
|
751
|
+
# non-green (a red alert must still stand out on a green screen).
|
|
752
|
+
NOVA_MATRIX = Theme(
|
|
753
|
+
name="matrix",
|
|
754
|
+
primary="#00ff41", # the classic Matrix green
|
|
755
|
+
secondary="#00b32d", # dimmer phosphor
|
|
756
|
+
accent="#39ff14", # neon green, for highlights
|
|
757
|
+
success="#00ff41",
|
|
758
|
+
warning="#c8ff00", # acid yellow-green
|
|
759
|
+
error="#ff3b30", # the one non-green: alerts must not blend in
|
|
760
|
+
surface="#0a0f0a",
|
|
761
|
+
panel="#0d140d",
|
|
762
|
+
background="#000600",
|
|
763
|
+
foreground="#b6ffb6",
|
|
764
|
+
boost="#12200f",
|
|
765
|
+
dark=True,
|
|
766
|
+
variables={
|
|
767
|
+
"text-muted": "#3f7a3f",
|
|
768
|
+
"border": "#1f4d1f",
|
|
769
|
+
},
|
|
770
|
+
)
|
|
771
|
+
DEFAULT_THEME = "tokyo-night"
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
class SessionHeader(Horizontal):
|
|
775
|
+
"""A structured header showing session metadata as pills.
|
|
776
|
+
|
|
777
|
+
Pills include: Model, Sandbox, Memory, and CWD breadcrumbs.
|
|
778
|
+
"""
|
|
779
|
+
|
|
780
|
+
DEFAULT_CSS = """
|
|
781
|
+
SessionHeader {
|
|
782
|
+
classes: "session-header";
|
|
783
|
+
}
|
|
784
|
+
"""
|
|
785
|
+
|
|
786
|
+
def __init__(self, model: str, sandbox: str, cwd: str, memory: str) -> None:
|
|
787
|
+
super().__init__()
|
|
788
|
+
self.model = model
|
|
789
|
+
self.sandbox = sandbox
|
|
790
|
+
self.cwd = cwd
|
|
791
|
+
self.memory = memory
|
|
792
|
+
|
|
793
|
+
def compose(self) -> ComposeResult:
|
|
794
|
+
yield Static(f"◇ {self.model}", classes="session-pill pill-model")
|
|
795
|
+
yield Static(f"▣ {self.sandbox}", classes="session-pill pill-sandbox")
|
|
796
|
+
yield Static(f"◈ {self.memory}", classes="session-pill pill-memory")
|
|
797
|
+
yield Static(f"▸ {self.cwd}", classes="breadcrumb")
|
|
798
|
+
|
|
799
|
+
def update_info(self, model: str, sandbox: str, cwd: str, memory: str) -> None:
|
|
800
|
+
self.model = model
|
|
801
|
+
self.sandbox = sandbox
|
|
802
|
+
self.cwd = cwd
|
|
803
|
+
self.memory = memory
|
|
804
|
+
self.refresh()
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
class NovaStatusBar:
|
|
808
|
+
"""Legacy dummy class preserved for tests compatibility."""
|
|
809
|
+
|
|
810
|
+
pass
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
def _selectable_line(widget: Widget, strip: Strip, x: int, y: int) -> Strip:
|
|
814
|
+
"""Make one rendered line selectable: tag it with offsets, paint the selection.
|
|
815
|
+
|
|
816
|
+
Textual maps a mouse position to a character through an ``offset`` in each
|
|
817
|
+
segment's style meta. It writes that only for its own ``Content`` visuals; a
|
|
818
|
+
Rich renderable (Markdown or a table) has none, so a
|
|
819
|
+
drag could not tell where it started and selected from the top of the widget
|
|
820
|
+
instead, which read as the whole message being one block.
|
|
821
|
+
|
|
822
|
+
``(x, y)`` is where the strip's first cell sits in the widget's content: the
|
|
823
|
+
same coordinates ``get_selection`` extracts with.
|
|
824
|
+
"""
|
|
825
|
+
selection = widget.text_selection
|
|
826
|
+
if selection is not None and (span := selection.get_span(y)) is not None:
|
|
827
|
+
start, end = span
|
|
828
|
+
width = strip.cell_length
|
|
829
|
+
start = max(0, start - x)
|
|
830
|
+
end = width if end == -1 else min(width, end - x)
|
|
831
|
+
if end > start:
|
|
832
|
+
strip = Strip.join(
|
|
833
|
+
[
|
|
834
|
+
strip.crop(0, start),
|
|
835
|
+
# Post style: the selection has to win over the text's own
|
|
836
|
+
# background, or the highlight is painted and then hidden.
|
|
837
|
+
# Background only: the theme's selection foreground is
|
|
838
|
+
# "transparent", which resolves to the background colour
|
|
839
|
+
# here and would make the selected text invisible.
|
|
840
|
+
Strip(
|
|
841
|
+
list(
|
|
842
|
+
Segment.apply_style(
|
|
843
|
+
strip.crop(start, end),
|
|
844
|
+
post_style=Style(bgcolor=widget.selection_style.bgcolor),
|
|
845
|
+
)
|
|
846
|
+
),
|
|
847
|
+
end - start,
|
|
848
|
+
),
|
|
849
|
+
strip.crop(end, width),
|
|
850
|
+
]
|
|
851
|
+
)
|
|
852
|
+
return strip.apply_offsets(x, y)
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
class SelectableStatic(Static):
|
|
856
|
+
"""A ``Static`` whose Rich-rendered content can be text-selected.
|
|
857
|
+
|
|
858
|
+
Textual's default ``Widget.get_selection`` reads ``self._render()`` and only
|
|
859
|
+
handles a ``Text``/``Content`` visual. A ``Static`` holding a Rich renderable
|
|
860
|
+
(``Markdown``, ``Table``, ``Group``, …) renders to a ``RichVisual`` instead,
|
|
861
|
+
so ``get_selection`` returns ``None`` and drag-selecting the widget yields
|
|
862
|
+
nothing — the text is visible but not selectable.
|
|
863
|
+
|
|
864
|
+
This subclass falls back to the *rendered* text (the strips the compositor
|
|
865
|
+
actually paints) so selection works for any Rich renderable, and the offsets
|
|
866
|
+
line up with what the user sees. Plain ``Text``/``Content`` bodies keep the
|
|
867
|
+
base implementation, which is already correct and cheaper.
|
|
868
|
+
"""
|
|
869
|
+
|
|
870
|
+
def render_line(self, y: int) -> Strip:
|
|
871
|
+
strip = super().render_line(y)
|
|
872
|
+
from textual.visual import RichVisual
|
|
873
|
+
|
|
874
|
+
# Text/Content visuals already carry offsets; adding more would
|
|
875
|
+
# double-paint the selection.
|
|
876
|
+
if isinstance(self._render(), RichVisual):
|
|
877
|
+
strip = _selectable_line(self, strip, 0, y)
|
|
878
|
+
return strip
|
|
879
|
+
|
|
880
|
+
def on_unmount(self) -> None:
|
|
881
|
+
# Parent layout/query caches may briefly retain removed widgets. Release
|
|
882
|
+
# their expensive markdown/text visuals immediately rather than waiting
|
|
883
|
+
# for that parent to be laid out again.
|
|
884
|
+
self.update("", layout=False)
|
|
885
|
+
self._styles_cache.clear()
|
|
886
|
+
|
|
887
|
+
def get_selection(self, selection: Selection) -> tuple[str, str] | None:
|
|
888
|
+
"""Extract the selected text, falling back to the rendered strips.
|
|
889
|
+
|
|
890
|
+
Args:
|
|
891
|
+
selection: The selection range, in cell offsets.
|
|
892
|
+
|
|
893
|
+
Returns:
|
|
894
|
+
A ``(text, ending)`` tuple, or ``None`` if nothing could be extracted.
|
|
895
|
+
"""
|
|
896
|
+
visual = self._render()
|
|
897
|
+
# Text/Content visuals are handled correctly by the base class.
|
|
898
|
+
from textual.content import Content
|
|
899
|
+
|
|
900
|
+
if isinstance(visual, (Text, Content)):
|
|
901
|
+
return super().get_selection(selection)
|
|
902
|
+
|
|
903
|
+
# Rich renderable → RichVisual. Re-render it to strips and join the
|
|
904
|
+
# visible line text, which is what the selection offsets index into.
|
|
905
|
+
try:
|
|
906
|
+
from textual.visual import RichVisual, Visual
|
|
907
|
+
|
|
908
|
+
if not isinstance(visual, RichVisual):
|
|
909
|
+
return super().get_selection(selection)
|
|
910
|
+
width = max(1, self.size.width or self.content_size.width or 1)
|
|
911
|
+
strips = Visual.to_strips(self, visual, width, None, self.visual_style)
|
|
912
|
+
# rstrip each line: the compositor pads every strip to the widget
|
|
913
|
+
# width, so a copied selection would otherwise carry a screenful of
|
|
914
|
+
# trailing spaces per line.
|
|
915
|
+
text = "\n".join(strip.text.rstrip() for strip in strips)
|
|
916
|
+
except Exception: # noqa: BLE001 — selection must never break rendering
|
|
917
|
+
return super().get_selection(selection)
|
|
918
|
+
return selection.extract(text), "\n"
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
class OutputLog(VerticalScroll):
|
|
922
|
+
"""Bounded, selectable output built from Textual scroll and Static widgets.
|
|
923
|
+
|
|
924
|
+
Store logical lines immediately, even when hidden. Coalesce paints instead
|
|
925
|
+
of retaining width-dependent rendered strips for every historical write.
|
|
926
|
+
"""
|
|
927
|
+
|
|
928
|
+
DEFAULT_CSS = """
|
|
929
|
+
OutputLog { height: auto; max-height: 20; }
|
|
930
|
+
OutputLog > .output-text { height: auto; width: 1fr; }
|
|
931
|
+
"""
|
|
932
|
+
|
|
933
|
+
def __init__(self, *, max_lines: int = 1000, max_chars: int = 200000,
|
|
934
|
+
highlight: bool = False, markup: bool = False, wrap: bool = True,
|
|
935
|
+
auto_scroll: bool = True, **kwargs: Any) -> None:
|
|
936
|
+
super().__init__(**kwargs)
|
|
937
|
+
from collections import deque
|
|
938
|
+
|
|
939
|
+
self.max_lines = max(1, max_lines)
|
|
940
|
+
self.max_chars = max(2, max_chars)
|
|
941
|
+
self.markup = markup
|
|
942
|
+
if highlight:
|
|
943
|
+
from rich.highlighter import ReprHighlighter
|
|
944
|
+
self._highlighter = ReprHighlighter()
|
|
945
|
+
else:
|
|
946
|
+
self._highlighter = None
|
|
947
|
+
self.auto_scroll = auto_scroll
|
|
948
|
+
self._output_lines: Any = deque()
|
|
949
|
+
self._output_chars = 0
|
|
950
|
+
self._paint_timer: Any = None
|
|
951
|
+
from novacode_cli.tui.output_body import OutputBody
|
|
952
|
+
|
|
953
|
+
self._output_body = OutputBody(wrap=wrap, highlighter=self._highlighter)
|
|
954
|
+
|
|
955
|
+
def compose(self) -> ComposeResult:
|
|
956
|
+
yield self._output_body
|
|
957
|
+
|
|
958
|
+
@property
|
|
959
|
+
def lines(self) -> list[Strip]:
|
|
960
|
+
"""Logical output lines, independent of visibility and terminal width."""
|
|
961
|
+
return [Strip([Segment(line.plain)]) for line in self._output_lines]
|
|
962
|
+
|
|
963
|
+
def write(self, content: Any) -> OutputLog:
|
|
964
|
+
# A background producer can outlive its pruned transcript card. Textual
|
|
965
|
+
# keeps is_mounted true after removal; never re-arm timers or retain new
|
|
966
|
+
# output on a closed message pump.
|
|
967
|
+
if self._closing or self._pruning:
|
|
968
|
+
return self
|
|
969
|
+
if isinstance(content, Text):
|
|
970
|
+
text = content[-(self.max_chars - 1):]
|
|
971
|
+
elif isinstance(content, str):
|
|
972
|
+
# Bound decoding too: a multi-megabyte result must not be parsed in
|
|
973
|
+
# full on the UI loop just to discard its beginning afterwards.
|
|
974
|
+
content = content[-(self.max_chars - 1):]
|
|
975
|
+
if not self.markup and all(c not in content for c in ("\x1b", "\r", "\t")):
|
|
976
|
+
self._store_lines(Text(line) for line in content.split("\n"))
|
|
977
|
+
return self
|
|
978
|
+
try:
|
|
979
|
+
if self.markup:
|
|
980
|
+
text = Text.from_markup(content)
|
|
981
|
+
else:
|
|
982
|
+
text = Text.from_ansi(content)
|
|
983
|
+
except Exception: # noqa: BLE001 — malformed output stays visible
|
|
984
|
+
text = Text(content)
|
|
985
|
+
else:
|
|
986
|
+
from rich.console import Console
|
|
987
|
+
console = Console(width=max(20, self.size.width or 80), record=True)
|
|
988
|
+
with console.capture() as capture:
|
|
989
|
+
console.print(content)
|
|
990
|
+
text = Text.from_ansi(capture.get())
|
|
991
|
+
text = text[-(self.max_chars - 1):]
|
|
992
|
+
text.expand_tabs()
|
|
993
|
+
text = text[-(self.max_chars - 1):]
|
|
994
|
+
self._store_lines(text.split("\n"))
|
|
995
|
+
return self
|
|
996
|
+
|
|
997
|
+
def _store_lines(self, lines: Iterable[Text]) -> None:
|
|
998
|
+
"""Retain bounded logical lines and schedule one coalesced repaint."""
|
|
999
|
+
for line in lines:
|
|
1000
|
+
self._output_lines.append(line)
|
|
1001
|
+
self._output_chars += len(line) + 1
|
|
1002
|
+
while len(self._output_lines) > self.max_lines or self._output_chars > self.max_chars:
|
|
1003
|
+
self._output_chars -= len(self._output_lines.popleft()) + 1
|
|
1004
|
+
if self.is_mounted and self._paint_timer is None:
|
|
1005
|
+
self._paint_timer = self.set_timer(0.05, self._flush_output)
|
|
1006
|
+
|
|
1007
|
+
def on_mount(self) -> None:
|
|
1008
|
+
self._flush_output()
|
|
1009
|
+
|
|
1010
|
+
def _flush_output(self) -> None:
|
|
1011
|
+
self._paint_timer = None
|
|
1012
|
+
if self._closing or self._pruning:
|
|
1013
|
+
return
|
|
1014
|
+
follow = self.auto_scroll and (self.is_vertical_scroll_end or not self._output_body._lines)
|
|
1015
|
+
self._output_body.replace_lines(self._output_lines)
|
|
1016
|
+
if follow:
|
|
1017
|
+
self.call_after_refresh(self.scroll_end, animate=False)
|
|
1018
|
+
|
|
1019
|
+
def clear(self) -> OutputLog:
|
|
1020
|
+
self._output_lines.clear()
|
|
1021
|
+
self._output_chars = 0
|
|
1022
|
+
if self._paint_timer is not None:
|
|
1023
|
+
self._paint_timer.stop()
|
|
1024
|
+
self._paint_timer = None
|
|
1025
|
+
self._output_body.replace_lines(())
|
|
1026
|
+
return self
|
|
1027
|
+
|
|
1028
|
+
def on_unmount(self) -> None:
|
|
1029
|
+
if self._paint_timer is not None:
|
|
1030
|
+
self._paint_timer.stop()
|
|
1031
|
+
self._paint_timer = None
|
|
1032
|
+
self._output_lines.clear()
|
|
1033
|
+
self._output_chars = 0
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
class TranscriptScroll(VerticalScroll):
|
|
1037
|
+
"""A scroll region that announces when it is (or stops being) at the bottom.
|
|
1038
|
+
|
|
1039
|
+
Textual posts no message when a widget scrolls — the only hook is the
|
|
1040
|
+
``scroll_y`` reactive watcher — so the "jump to latest" affordance had no
|
|
1041
|
+
way to know the user had scrolled up. This subclass posts
|
|
1042
|
+
:class:`TranscriptScroll.AtEndChanged` whenever the at-the-bottom state
|
|
1043
|
+
flips, which is exactly when the button must appear or hide.
|
|
1044
|
+
"""
|
|
1045
|
+
|
|
1046
|
+
class AtEndChanged(Message):
|
|
1047
|
+
"""Posted when the scroll region reaches or leaves the bottom."""
|
|
1048
|
+
|
|
1049
|
+
def __init__(self, scroll: TranscriptScroll, *, at_end: bool) -> None:
|
|
1050
|
+
"""Record the scroll region and its new at-the-bottom state."""
|
|
1051
|
+
self.scroll = scroll
|
|
1052
|
+
self.at_end = at_end
|
|
1053
|
+
super().__init__()
|
|
1054
|
+
|
|
1055
|
+
class Scrolled(Message):
|
|
1056
|
+
"""Posted on every scroll position change (for the distance readout)."""
|
|
1057
|
+
|
|
1058
|
+
def __init__(
|
|
1059
|
+
self, scroll: TranscriptScroll, *, old_y: float, new_y: float
|
|
1060
|
+
) -> None:
|
|
1061
|
+
"""Record the scroll region that moved and its before/after offset.
|
|
1062
|
+
|
|
1063
|
+
The delta is carried on the message rather than compared against a
|
|
1064
|
+
global "last position" in the app: with several session panes, a
|
|
1065
|
+
global would be stale after a pane switch and misread a downward
|
|
1066
|
+
scroll as an upward one.
|
|
1067
|
+
"""
|
|
1068
|
+
self.scroll = scroll
|
|
1069
|
+
self.old_y = old_y
|
|
1070
|
+
self.new_y = new_y
|
|
1071
|
+
super().__init__()
|
|
1072
|
+
|
|
1073
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
1074
|
+
"""Build the scroll region and seed the at-the-bottom state."""
|
|
1075
|
+
super().__init__(*args, **kwargs)
|
|
1076
|
+
self._at_end: bool | None = None
|
|
1077
|
+
self._styled_classes: frozenset[str] | None = None
|
|
1078
|
+
|
|
1079
|
+
def update_node_styles(self, animate: bool = True) -> None:
|
|
1080
|
+
"""Restyle this container alone when only its focus or hover changed.
|
|
1081
|
+
|
|
1082
|
+
Textual restyles a node *and every descendant* on any pseudo-class
|
|
1083
|
+
change. For the transcript that is every widget of the chat, each time
|
|
1084
|
+
the mouse crosses a gap between messages or the chat takes focus: 3-9 s
|
|
1085
|
+
frozen on a long session (freeze.log, 2026-10-15), long enough to stall
|
|
1086
|
+
the checkpoint-lease heartbeat. No rule styles a descendant by the
|
|
1087
|
+
transcript's own focus or hover, so only a change of its classes (which
|
|
1088
|
+
rules could key on) still restyles the whole subtree.
|
|
1089
|
+
"""
|
|
1090
|
+
classes = frozenset(self.classes)
|
|
1091
|
+
if classes != self._styled_classes:
|
|
1092
|
+
self._styled_classes = classes
|
|
1093
|
+
super().update_node_styles(animate)
|
|
1094
|
+
return
|
|
1095
|
+
with contextlib.suppress(Exception): # no active app (tests, teardown)
|
|
1096
|
+
self.app.stylesheet.update_nodes([self], animate=animate)
|
|
1097
|
+
|
|
1098
|
+
def watch_scroll_y(self, old_value: float, new_value: float) -> None:
|
|
1099
|
+
"""Announce scroll changes so the jump-to-latest affordance can react."""
|
|
1100
|
+
super().watch_scroll_y(old_value, new_value)
|
|
1101
|
+
# Record intent before queued layout callbacks can auto-scroll again.
|
|
1102
|
+
# A posted message alone arrives too late when both run in one refresh.
|
|
1103
|
+
track = getattr(self.app, "_track_transcript_scroll", None)
|
|
1104
|
+
if track is not None:
|
|
1105
|
+
track(self, old_value, new_value)
|
|
1106
|
+
# Post on every change so the "N lines below" readout stays current;
|
|
1107
|
+
# AtEndChanged only on a flip, so the show/hide work is not repeated.
|
|
1108
|
+
self.post_message(self.Scrolled(self, old_y=old_value, new_y=new_value))
|
|
1109
|
+
at_end = self.is_vertical_scroll_end or (self.max_scroll_y - self.scroll_y) <= 1
|
|
1110
|
+
if at_end != self._at_end:
|
|
1111
|
+
self._at_end = at_end
|
|
1112
|
+
self.post_message(self.AtEndChanged(self, at_end=at_end))
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
class _CollapsibleMessageHeader(Static, can_focus=True):
|
|
1116
|
+
"""Focusable fold control for a transcript message."""
|
|
1117
|
+
|
|
1118
|
+
ALLOW_SELECT = False
|
|
1119
|
+
BINDINGS: ClassVar[list[Binding]] = [
|
|
1120
|
+
Binding("enter,space", "toggle", "Toggle reasoning", show=False)
|
|
1121
|
+
]
|
|
1122
|
+
DEFAULT_CSS = """
|
|
1123
|
+
_CollapsibleMessageHeader { pointer: pointer; }
|
|
1124
|
+
_CollapsibleMessageHeader:hover { background: $boost; }
|
|
1125
|
+
_CollapsibleMessageHeader:focus { background: $boost; text-style: bold underline; }
|
|
1126
|
+
"""
|
|
1127
|
+
|
|
1128
|
+
def action_toggle(self) -> None:
|
|
1129
|
+
"""Toggle the owning message without copying its body."""
|
|
1130
|
+
if isinstance(self.parent, ChatMessage):
|
|
1131
|
+
self.parent.toggle_collapsed()
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
class ChatMessage(Vertical):
|
|
1135
|
+
"""A single transcript entry with a role header and a body.
|
|
1136
|
+
|
|
1137
|
+
role_class selects the message styling (user / nova / reason). The body is set
|
|
1138
|
+
via :meth:`update_body` with any rich renderable (plain Text while streaming,
|
|
1139
|
+
Markdown once committed)."""
|
|
1140
|
+
|
|
1141
|
+
DEFAULT_CSS = """
|
|
1142
|
+
/* Even, consistent cards use padding and role headers.
|
|
1143
|
+
The base background matches the app's own, so the agent's replies read as
|
|
1144
|
+
plain transcript rather than a raised card. */
|
|
1145
|
+
ChatMessage {
|
|
1146
|
+
height: auto;
|
|
1147
|
+
margin: 1 0;
|
|
1148
|
+
padding: 1 2;
|
|
1149
|
+
background: $background;
|
|
1150
|
+
}
|
|
1151
|
+
ChatMessage > .role { text-style: bold; }
|
|
1152
|
+
ChatMessage > .body { height: auto; }
|
|
1153
|
+
ChatMessage.user { border-left: none; }
|
|
1154
|
+
ChatMessage.reason { border-left: none; color: $text-muted; }
|
|
1155
|
+
/* Collapsed reasoning: only the header row remains, so a long thinking
|
|
1156
|
+
trace stays in the transcript as a one-line affordance. */
|
|
1157
|
+
ChatMessage.collapsed > .body { display: none; }
|
|
1158
|
+
ChatMessage.collapsed { height: auto; }
|
|
1159
|
+
/* User turns stand out from the agent's: a raised panel behind the text and
|
|
1160
|
+
full-brightness foreground, so what YOU typed is easy to find when
|
|
1161
|
+
scrolling back through a long transcript. */
|
|
1162
|
+
ChatMessage.user { background: $panel; color: $foreground; }
|
|
1163
|
+
ChatMessage.user > .role { color: $primary; }
|
|
1164
|
+
"""
|
|
1165
|
+
|
|
1166
|
+
def __init__(
|
|
1167
|
+
self, header: Text, role_class: str, *, collapsible: bool = False
|
|
1168
|
+
) -> None:
|
|
1169
|
+
super().__init__(classes=role_class)
|
|
1170
|
+
self._header = header
|
|
1171
|
+
# Plain-text form of the body, kept in sync by update_body so the message
|
|
1172
|
+
# can be copied verbatim (click-to-copy / the /copy command) without
|
|
1173
|
+
# re-deriving it from the rendered markdown.
|
|
1174
|
+
self.raw_text: str = ""
|
|
1175
|
+
# Body renderable received before compose() finished mounting the `.body`
|
|
1176
|
+
# child. Applied in on_mount so a fast first stream chunk isn't lost.
|
|
1177
|
+
self._pending_body: Any = None
|
|
1178
|
+
# Collapsible messages (reasoning traces) keep their body but can be
|
|
1179
|
+
# folded to a one-line header, so a long thinking trace stays in the
|
|
1180
|
+
# transcript without dominating it.
|
|
1181
|
+
self._collapsible = collapsible
|
|
1182
|
+
self._collapsed = False
|
|
1183
|
+
# Store the header's identity color for theme changes.
|
|
1184
|
+
self._custom_color = None
|
|
1185
|
+
if header.style:
|
|
1186
|
+
from rich.style import Style
|
|
1187
|
+
|
|
1188
|
+
if isinstance(header.style, Style) and header.style.color:
|
|
1189
|
+
self._custom_color = header.style.color.name
|
|
1190
|
+
else:
|
|
1191
|
+
style_str = str(header.style)
|
|
1192
|
+
import re
|
|
1193
|
+
|
|
1194
|
+
m = re.search(r"#(?:[0-9a-fA-F]{3}){1,2}\b", style_str)
|
|
1195
|
+
if m:
|
|
1196
|
+
self._custom_color = m.group(0)
|
|
1197
|
+
elif "green" in style_str:
|
|
1198
|
+
self._custom_color = "#10b981"
|
|
1199
|
+
|
|
1200
|
+
def compose(self) -> ComposeResult:
|
|
1201
|
+
header_type = _CollapsibleMessageHeader if self._collapsible else Static
|
|
1202
|
+
yield header_type(self._header, classes="role")
|
|
1203
|
+
if isinstance(self._pending_body, Widget):
|
|
1204
|
+
self._pending_body.add_class("body")
|
|
1205
|
+
yield self._pending_body
|
|
1206
|
+
else:
|
|
1207
|
+
yield SelectableStatic(self._pending_body or "", classes="body")
|
|
1208
|
+
|
|
1209
|
+
def on_mount(self) -> None:
|
|
1210
|
+
self._refresh_header_affordance()
|
|
1211
|
+
# If update_body ran before the `.body` child existed, apply the stashed
|
|
1212
|
+
# renderable now that the children are mounted.
|
|
1213
|
+
if self._pending_body is not None:
|
|
1214
|
+
if not isinstance(self._pending_body, Widget):
|
|
1215
|
+
try:
|
|
1216
|
+
self.query_one(".body", Static).update(self._pending_body)
|
|
1217
|
+
except NoMatches:
|
|
1218
|
+
pass
|
|
1219
|
+
self._pending_body = None
|
|
1220
|
+
|
|
1221
|
+
def on_unmount(self) -> None:
|
|
1222
|
+
self.raw_text = ""
|
|
1223
|
+
self._pending_body = None
|
|
1224
|
+
|
|
1225
|
+
def set_collapsed(self, *, collapsed: bool) -> None:
|
|
1226
|
+
"""Fold/unfold a collapsible message's body (no-op for normal messages).
|
|
1227
|
+
|
|
1228
|
+
Args:
|
|
1229
|
+
collapsed: True to hide the body, False to show it.
|
|
1230
|
+
"""
|
|
1231
|
+
if not self._collapsible:
|
|
1232
|
+
return
|
|
1233
|
+
self._collapsed = collapsed
|
|
1234
|
+
self.set_class(collapsed, "collapsed")
|
|
1235
|
+
self._refresh_header_affordance()
|
|
1236
|
+
|
|
1237
|
+
def toggle_collapsed(self) -> None:
|
|
1238
|
+
"""Flip the collapsed state of a collapsible message."""
|
|
1239
|
+
self.set_collapsed(collapsed=not self._collapsed)
|
|
1240
|
+
|
|
1241
|
+
def _refresh_header_affordance(self) -> None:
|
|
1242
|
+
"""Append a ▸/▾ caret to the header so the fold state is visible."""
|
|
1243
|
+
if not self._collapsible:
|
|
1244
|
+
return
|
|
1245
|
+
caret = "▸" if self._collapsed else "▾"
|
|
1246
|
+
header = self._header.copy()
|
|
1247
|
+
header.append(f" {caret}", style="dim")
|
|
1248
|
+
try:
|
|
1249
|
+
self.query_one(".role", Static).update(header)
|
|
1250
|
+
except Exception: # noqa: BLE001 — header refresh must never break render
|
|
1251
|
+
pass
|
|
1252
|
+
|
|
1253
|
+
def update_header(self, header: Text) -> None:
|
|
1254
|
+
self._header = header
|
|
1255
|
+
try:
|
|
1256
|
+
role_static = self.query_one(".role", Static)
|
|
1257
|
+
role_static.update(header)
|
|
1258
|
+
except Exception:
|
|
1259
|
+
pass
|
|
1260
|
+
self._refresh_header_affordance()
|
|
1261
|
+
|
|
1262
|
+
# Store the header's identity color for theme changes.
|
|
1263
|
+
self._custom_color = None
|
|
1264
|
+
if header.style:
|
|
1265
|
+
from rich.style import Style
|
|
1266
|
+
|
|
1267
|
+
if isinstance(header.style, Style) and header.style.color:
|
|
1268
|
+
self._custom_color = header.style.color.name
|
|
1269
|
+
else:
|
|
1270
|
+
style_str = str(header.style)
|
|
1271
|
+
import re
|
|
1272
|
+
|
|
1273
|
+
m = re.search(r"#(?:[0-9a-fA-F]{3}){1,2}\b", style_str)
|
|
1274
|
+
if m:
|
|
1275
|
+
self._custom_color = m.group(0)
|
|
1276
|
+
elif "green" in style_str:
|
|
1277
|
+
self._custom_color = "#10b981"
|
|
1278
|
+
|
|
1279
|
+
def update_body(self, renderable: Any) -> None:
|
|
1280
|
+
if self._closing or self._pruning:
|
|
1281
|
+
return
|
|
1282
|
+
self.raw_text = self._renderable_text(renderable)
|
|
1283
|
+
try:
|
|
1284
|
+
body = self.query_one(".body")
|
|
1285
|
+
except NoMatches:
|
|
1286
|
+
# Children not mounted yet (Textual composes asynchronously). Stash
|
|
1287
|
+
# the renderable; on_mount/compose will apply it. Prevents the
|
|
1288
|
+
# "No nodes match '.body'" crash on a fast first stream chunk.
|
|
1289
|
+
self._pending_body = renderable
|
|
1290
|
+
return
|
|
1291
|
+
|
|
1292
|
+
if isinstance(renderable, Widget):
|
|
1293
|
+
if body is not renderable:
|
|
1294
|
+
body.remove()
|
|
1295
|
+
renderable.add_class("body")
|
|
1296
|
+
self.mount(renderable)
|
|
1297
|
+
else:
|
|
1298
|
+
if isinstance(body, SelectableStatic):
|
|
1299
|
+
body.update(renderable)
|
|
1300
|
+
else:
|
|
1301
|
+
body.remove()
|
|
1302
|
+
new_body = SelectableStatic(renderable, classes="body")
|
|
1303
|
+
self.mount(new_body)
|
|
1304
|
+
|
|
1305
|
+
@staticmethod
|
|
1306
|
+
def _renderable_text(renderable: Any) -> str:
|
|
1307
|
+
"""Best-effort plain text for a body renderable (Markdown/Text/other)."""
|
|
1308
|
+
if isinstance(renderable, Markdown):
|
|
1309
|
+
return renderable.markup
|
|
1310
|
+
if isinstance(renderable, Text):
|
|
1311
|
+
return renderable.plain
|
|
1312
|
+
if hasattr(renderable, "initial_cmd"):
|
|
1313
|
+
return f"$ {renderable.initial_cmd}"
|
|
1314
|
+
return str(renderable)
|
|
1315
|
+
|
|
1316
|
+
def on_click(self, event: events.Click) -> None:
|
|
1317
|
+
"""Toggle a fold header, or copy the message's full text on other clicks.
|
|
1318
|
+
|
|
1319
|
+
This is deterministic and terminal-independent — unlike mouse
|
|
1320
|
+
drag-selection, which a captured-mouse TUI can't reliably support.
|
|
1321
|
+
Drag-selection still works: Textual only fires Click when there was no
|
|
1322
|
+
drag, and an explicit selection takes precedence here.
|
|
1323
|
+
"""
|
|
1324
|
+
if self._collapsible and event.widget is self.query_one(".role"):
|
|
1325
|
+
self.toggle_collapsed()
|
|
1326
|
+
event.stop()
|
|
1327
|
+
return
|
|
1328
|
+
body = (self.raw_text or "").strip()
|
|
1329
|
+
if not body:
|
|
1330
|
+
return
|
|
1331
|
+
app = self.app
|
|
1332
|
+
try:
|
|
1333
|
+
if app.screen.get_selected_text():
|
|
1334
|
+
return # honor an explicit selection — ctrl+c will copy it
|
|
1335
|
+
except Exception: # noqa: BLE001
|
|
1336
|
+
pass
|
|
1337
|
+
try:
|
|
1338
|
+
app.copy_to_clipboard(body)
|
|
1339
|
+
app._log( # type: ignore[attr-defined]
|
|
1340
|
+
Text(f"≡ Copied message ({len(body):,} chars)", style="dim")
|
|
1341
|
+
)
|
|
1342
|
+
event.stop()
|
|
1343
|
+
except Exception: # noqa: BLE001
|
|
1344
|
+
pass
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
class PromptInput(TextArea):
|
|
1349
|
+
"""Main prompt input that collapses large pastes into a compact placeholder.
|
|
1350
|
+
|
|
1351
|
+
Textual's single-line ``Input`` keeps only the *first line* of a paste, so a
|
|
1352
|
+
multi-line paste would silently lose everything after the first newline.
|
|
1353
|
+
Instead, a large paste (>= ``PASTE_MIN_CHARS`` chars or ``PASTE_MIN_NEWLINES``
|
|
1354
|
+
newlines) is stored in the app's :class:`PasteTracker` and shown inline as
|
|
1355
|
+
``[paste #N +M lines]``; the placeholder is resolved back to the full text on
|
|
1356
|
+
submit (see :meth:`NovaApp.on_input_submitted`). Small pastes fall through to
|
|
1357
|
+
Textual's default behaviour.
|
|
1358
|
+
|
|
1359
|
+
Reuses the same tracker/threshold/format helpers as the legacy prompt_toolkit
|
|
1360
|
+
input (:mod:`novacode_cli.input`) so both UIs behave identically.
|
|
1361
|
+
"""
|
|
1362
|
+
|
|
1363
|
+
# After the last Paste fragment, how long an in-progress paste stays "open"
|
|
1364
|
+
# for more fragments to merge into it. A single large paste is often split
|
|
1365
|
+
# by the terminal into several Paste events that can arrive hundreds of ms
|
|
1366
|
+
# apart, so this is generous — it does NOT block typing (that's the separate
|
|
1367
|
+
# key-drop window below) and is also ended early by any real keystroke.
|
|
1368
|
+
PASTE_MERGE_WINDOW = 1.5
|
|
1369
|
+
# How long stray per-character key events are dropped after a Paste fragment
|
|
1370
|
+
# (Windows terminals echo a paste as queued keystrokes). Short, so real
|
|
1371
|
+
# typing right after a paste is never swallowed.
|
|
1372
|
+
PASTE_KEYDROP_WINDOW = 0.05
|
|
1373
|
+
|
|
1374
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
1375
|
+
self._paste_tracker: PasteTracker | None = kwargs.pop("paste_tracker", None)
|
|
1376
|
+
self._on_large_paste = kwargs.pop("on_large_paste", None)
|
|
1377
|
+
# Called with the new ImageData when Ctrl+V finds an image on the
|
|
1378
|
+
# clipboard; returns the id to insert as a placeholder, or "" to
|
|
1379
|
+
# decline. Left unset, Ctrl+V is a plain text paste.
|
|
1380
|
+
self._on_clipboard_image = kwargs.pop("on_clipboard_image", None)
|
|
1381
|
+
super().__init__(*args, **kwargs)
|
|
1382
|
+
# On Windows terminals, pasting fires BOTH a Paste event AND individual
|
|
1383
|
+
# key events for each character. We stop the Paste event, but the
|
|
1384
|
+
# keystrokes are already queued. This flag drops them until the key-drop
|
|
1385
|
+
# window expires.
|
|
1386
|
+
self._paste_active = False
|
|
1387
|
+
self._keydrop_timer: Any = None
|
|
1388
|
+
# Identity-merge state for coalescing a fragmented paste: while a paste
|
|
1389
|
+
# is "open", later fragments are appended to this SAME paste id (one
|
|
1390
|
+
# block, one placeholder) instead of each becoming its own [paste #N].
|
|
1391
|
+
self._active_paste_id: str | None = None
|
|
1392
|
+
self._active_paste_ph: str = ""
|
|
1393
|
+
self._merge_timer: Any = None
|
|
1394
|
+
|
|
1395
|
+
class Submitted(Message):
|
|
1396
|
+
"""Posted when the user presses enter to send the prompt.
|
|
1397
|
+
|
|
1398
|
+
``TextArea`` has no Submitted message of its own (enter inserts a
|
|
1399
|
+
newline there), so the prompt defines one to keep the app-side
|
|
1400
|
+
contract identical to the old ``Input``-based widget.
|
|
1401
|
+
"""
|
|
1402
|
+
|
|
1403
|
+
def __init__(self, prompt_input: "PromptInput", value: str) -> None:
|
|
1404
|
+
self.input = prompt_input
|
|
1405
|
+
self.value = value
|
|
1406
|
+
super().__init__()
|
|
1407
|
+
|
|
1408
|
+
@property
|
|
1409
|
+
def value(self) -> str:
|
|
1410
|
+
"""Alias of ``text`` so callers written against ``Input`` still work."""
|
|
1411
|
+
return self.text
|
|
1412
|
+
|
|
1413
|
+
@value.setter
|
|
1414
|
+
def value(self, new: str) -> None:
|
|
1415
|
+
self.text = new
|
|
1416
|
+
|
|
1417
|
+
@property
|
|
1418
|
+
def cursor_position(self) -> int:
|
|
1419
|
+
"""Cursor offset into ``text`` (``Input``-compatible).
|
|
1420
|
+
|
|
1421
|
+
``TextArea`` exposes a (row, column) ``cursor_location``; the palette
|
|
1422
|
+
and @-completion were written against a flat offset, so translate.
|
|
1423
|
+
"""
|
|
1424
|
+
try:
|
|
1425
|
+
row, col = self.cursor_location
|
|
1426
|
+
except Exception: # noqa: BLE001
|
|
1427
|
+
return len(self.text)
|
|
1428
|
+
lines = self.text.split("\n")[:row]
|
|
1429
|
+
return sum(len(line) + 1 for line in lines) + col
|
|
1430
|
+
|
|
1431
|
+
@cursor_position.setter
|
|
1432
|
+
def cursor_position(self, offset: int) -> None:
|
|
1433
|
+
text = self.text
|
|
1434
|
+
offset = max(0, min(offset, len(text)))
|
|
1435
|
+
before = text[:offset]
|
|
1436
|
+
row = before.count("\n")
|
|
1437
|
+
col = offset - (before.rfind("\n") + 1)
|
|
1438
|
+
self.move_cursor((row, col))
|
|
1439
|
+
|
|
1440
|
+
#: Earlier inputs kept for Up/Down (see :meth:`remember`).
|
|
1441
|
+
HISTORY_MAX = 500
|
|
1442
|
+
|
|
1443
|
+
def remember(self, text: str) -> None:
|
|
1444
|
+
"""Add a sent input to the Up/Down history (a repeat of the last is skipped)."""
|
|
1445
|
+
text = text.strip()
|
|
1446
|
+
history = self.__dict__.setdefault("_history", [])
|
|
1447
|
+
if text and (not history or history[-1] != text):
|
|
1448
|
+
history.append(text)
|
|
1449
|
+
del history[: -self.HISTORY_MAX]
|
|
1450
|
+
self._history_pos = None
|
|
1451
|
+
|
|
1452
|
+
def load_history(self, entries: list[str]) -> None:
|
|
1453
|
+
"""Seed the history with earlier sessions' inputs, oldest first."""
|
|
1454
|
+
self._history = [e for e in entries if e.strip()][-self.HISTORY_MAX :]
|
|
1455
|
+
self._history_pos = None
|
|
1456
|
+
|
|
1457
|
+
def _show(self, text: str) -> None:
|
|
1458
|
+
self.text = text
|
|
1459
|
+
self.move_cursor(self.document.end)
|
|
1460
|
+
|
|
1461
|
+
def _recall(self, step: int) -> bool:
|
|
1462
|
+
"""Up (-1) / Down (+1): a queued message first, then earlier inputs.
|
|
1463
|
+
|
|
1464
|
+
Up in an empty box while the agent works takes back the newest message
|
|
1465
|
+
it has not picked up yet (the app decides; Claude Code does the same).
|
|
1466
|
+
Otherwise Up steps back through earlier inputs, and Down steps forward to
|
|
1467
|
+
the text that was being typed. True when the key was used.
|
|
1468
|
+
"""
|
|
1469
|
+
history = self.__dict__.setdefault("_history", [])
|
|
1470
|
+
position = getattr(self, "_history_pos", None)
|
|
1471
|
+
if step < 0:
|
|
1472
|
+
if position is None and not self.text.strip():
|
|
1473
|
+
pull = getattr(self.app, "_pull_queued_message", None)
|
|
1474
|
+
queued = pull() if pull is not None else None
|
|
1475
|
+
if queued:
|
|
1476
|
+
self._show(queued)
|
|
1477
|
+
return True
|
|
1478
|
+
if not history:
|
|
1479
|
+
return False
|
|
1480
|
+
if position is None:
|
|
1481
|
+
self._history_draft = self.text
|
|
1482
|
+
position = len(history)
|
|
1483
|
+
position = max(0, position - 1)
|
|
1484
|
+
else:
|
|
1485
|
+
if position is None:
|
|
1486
|
+
return False
|
|
1487
|
+
position += 1
|
|
1488
|
+
if position >= len(history):
|
|
1489
|
+
self._history_pos = None
|
|
1490
|
+
self._show(getattr(self, "_history_draft", ""))
|
|
1491
|
+
return True
|
|
1492
|
+
self._history_pos = position
|
|
1493
|
+
self._show(history[position])
|
|
1494
|
+
return True
|
|
1495
|
+
|
|
1496
|
+
def _palette_open(self) -> bool:
|
|
1497
|
+
try:
|
|
1498
|
+
return bool(self.app.query_one("#cmdpalette").display)
|
|
1499
|
+
except Exception: # noqa: BLE001 - no palette: no conflict
|
|
1500
|
+
return False
|
|
1501
|
+
|
|
1502
|
+
async def _on_key(self, event: events.Key) -> None:
|
|
1503
|
+
# Up on the first line / Down on the last: input history (and queued
|
|
1504
|
+
# messages). Inside multi-line text the arrows still move the cursor,
|
|
1505
|
+
# and the command palette keeps them while it is open.
|
|
1506
|
+
if event.key in ("up", "down") and not self._palette_open():
|
|
1507
|
+
row = self.cursor_location[0]
|
|
1508
|
+
edge = row == 0 if event.key == "up" else row == self.document.line_count - 1
|
|
1509
|
+
if edge and self._recall(-1 if event.key == "up" else 1):
|
|
1510
|
+
event.prevent_default()
|
|
1511
|
+
event.stop()
|
|
1512
|
+
return
|
|
1513
|
+
# Enter sends by default; the app preference can switch to multiline
|
|
1514
|
+
# Enter with Ctrl+Enter to send. Shift+Enter always inserts a newline.
|
|
1515
|
+
submit_on_enter = getattr(self.app, "_submit_on_enter", True)
|
|
1516
|
+
if event.key == "ctrl+enter" or (event.key == "enter" and submit_on_enter):
|
|
1517
|
+
event.prevent_default()
|
|
1518
|
+
event.stop()
|
|
1519
|
+
self._end_paste_merge()
|
|
1520
|
+
self.post_message(self.Submitted(self, self.text))
|
|
1521
|
+
return
|
|
1522
|
+
if event.key in ("shift+enter", "ctrl+j") or (
|
|
1523
|
+
event.key == "enter" and not submit_on_enter
|
|
1524
|
+
):
|
|
1525
|
+
event.prevent_default()
|
|
1526
|
+
event.stop()
|
|
1527
|
+
self._end_paste_merge()
|
|
1528
|
+
self.insert("\n")
|
|
1529
|
+
return
|
|
1530
|
+
# ctrl+v: prefer a clipboard IMAGE, else fall back to a text paste.
|
|
1531
|
+
#
|
|
1532
|
+
# Intercepting here is necessary rather than optional: when this
|
|
1533
|
+
# ``_on_key`` does not stop the event, Textual never runs the ctrl+v
|
|
1534
|
+
# binding, so the built-in ``action_paste`` is unreachable either way.
|
|
1535
|
+
# Reading the clipboard is blocking, so it runs in a worker.
|
|
1536
|
+
if event.key == "ctrl+v":
|
|
1537
|
+
event.prevent_default()
|
|
1538
|
+
event.stop()
|
|
1539
|
+
self._end_paste_merge()
|
|
1540
|
+
self.run_worker(self._paste_clipboard(), group="clipboard")
|
|
1541
|
+
return
|
|
1542
|
+
# Drop ALL key events during the key-drop window. On Windows terminals,
|
|
1543
|
+
# pasting fires per-character keystrokes after the Paste event — the old
|
|
1544
|
+
# `len(event.key) == 1` filter was too narrow because some terminals send
|
|
1545
|
+
# the *entire pasted text* as a single key event (e.g. event.key == "use"),
|
|
1546
|
+
# which has len > 1 and was let through, duplicating the paste.
|
|
1547
|
+
if self._paste_active:
|
|
1548
|
+
return
|
|
1549
|
+
# A real keystroke means the paste burst is over — stop merging further
|
|
1550
|
+
# fragments into it so the next paste starts fresh.
|
|
1551
|
+
self._end_paste_merge()
|
|
1552
|
+
await super()._on_key(event)
|
|
1553
|
+
|
|
1554
|
+
async def _paste_clipboard(self) -> None:
|
|
1555
|
+
"""Paste a clipboard image if there is one, else the clipboard text.
|
|
1556
|
+
|
|
1557
|
+
The image read is platform-specific and blocking (PIL / a subprocess),
|
|
1558
|
+
so it happens on a worker thread; the widget stays responsive for the
|
|
1559
|
+
fraction of a second that takes.
|
|
1560
|
+
"""
|
|
1561
|
+
if self._on_clipboard_image is not None:
|
|
1562
|
+
try:
|
|
1563
|
+
image = await asyncio.to_thread(self._read_clipboard_image)
|
|
1564
|
+
except Exception: # noqa: BLE001 — never break input over this
|
|
1565
|
+
image = None
|
|
1566
|
+
if image is not None:
|
|
1567
|
+
try:
|
|
1568
|
+
image_id = self._on_clipboard_image(image)
|
|
1569
|
+
except Exception: # noqa: BLE001
|
|
1570
|
+
image_id = ""
|
|
1571
|
+
if image_id:
|
|
1572
|
+
# Trailing space so typing continues after the placeholder.
|
|
1573
|
+
self.insert(f"[{image_id}] ")
|
|
1574
|
+
return
|
|
1575
|
+
# No image (or the app declined it): plain text paste.
|
|
1576
|
+
self.action_paste()
|
|
1577
|
+
|
|
1578
|
+
@staticmethod
|
|
1579
|
+
def _read_clipboard_image() -> ImageData | None:
|
|
1580
|
+
"""Read an image off the system clipboard, or ``None``.
|
|
1581
|
+
|
|
1582
|
+
Imported lazily so Pillow is only pulled in when a paste actually asks
|
|
1583
|
+
for it — it is not needed on the import path of the TUI.
|
|
1584
|
+
"""
|
|
1585
|
+
from novacode_cli.image_utils import get_clipboard_image
|
|
1586
|
+
|
|
1587
|
+
return get_clipboard_image()
|
|
1588
|
+
|
|
1589
|
+
def _on_paste(self, event: events.Paste) -> None:
|
|
1590
|
+
text = event.text
|
|
1591
|
+
# Blank this out before Input._on_paste runs (Textual calls _on_* handlers
|
|
1592
|
+
# for every class in the MRO). Without this, the parent inserts the text a
|
|
1593
|
+
# second time, producing duplicates like "useuse".
|
|
1594
|
+
event.text = ""
|
|
1595
|
+
event.stop()
|
|
1596
|
+
|
|
1597
|
+
if not text:
|
|
1598
|
+
# An EMPTY paste is how a terminal reports Ctrl+V on an image: the
|
|
1599
|
+
# terminal owns ctrl+v, so the key never reaches ``_on_key``, and
|
|
1600
|
+
# with no text for it to paste it delivers an empty bracketed paste
|
|
1601
|
+
# (verified on Windows Terminal). Treat it as "look at the clipboard
|
|
1602
|
+
# for an image" — the only signal available on this path.
|
|
1603
|
+
# Guarded on the callback so a plain empty paste stays a no-op.
|
|
1604
|
+
if self._on_clipboard_image is not None:
|
|
1605
|
+
self.run_worker(self._paste_clipboard(), group="clipboard")
|
|
1606
|
+
return
|
|
1607
|
+
normalized = text.replace("\r\n", "\n").replace("\r", "\n")
|
|
1608
|
+
tracker = self._paste_tracker
|
|
1609
|
+
|
|
1610
|
+
if self._active_paste_id is not None and tracker is not None:
|
|
1611
|
+
# Continuation of a fragmented paste: append to the SAME paste so the
|
|
1612
|
+
# whole thing stays one block for the agent, and refresh the inline
|
|
1613
|
+
# placeholder's line count in place (same id, updated count).
|
|
1614
|
+
old_ph = self._active_paste_ph
|
|
1615
|
+
tracker.extend_paste(self._active_paste_id, normalized)
|
|
1616
|
+
full = tracker.get_paste(self._active_paste_id) or normalized
|
|
1617
|
+
new_ph = format_paste_placeholder(self._active_paste_id, full)
|
|
1618
|
+
if new_ph != old_ph and old_ph in self.text:
|
|
1619
|
+
self.text = self.text.replace(old_ph, new_ph, 1)
|
|
1620
|
+
self.move_cursor(self.document.end)
|
|
1621
|
+
self._active_paste_ph = new_ph
|
|
1622
|
+
elif tracker is not None and (
|
|
1623
|
+
len(normalized) >= PASTE_MIN_CHARS or normalized.count("\n") >= PASTE_MIN_NEWLINES
|
|
1624
|
+
):
|
|
1625
|
+
# First fragment of a large paste: create the placeholder and open
|
|
1626
|
+
# the merge window so any trailing fragments fold into this one.
|
|
1627
|
+
paste_id = tracker.add_paste(normalized)
|
|
1628
|
+
placeholder = format_paste_placeholder(paste_id, normalized)
|
|
1629
|
+
self.insert(placeholder + " ")
|
|
1630
|
+
self._active_paste_id = paste_id
|
|
1631
|
+
self._active_paste_ph = placeholder
|
|
1632
|
+
else:
|
|
1633
|
+
# Small paste — won't fragment; insert literally, no merge needed.
|
|
1634
|
+
self.insert(normalized)
|
|
1635
|
+
|
|
1636
|
+
# Drop the echo keystrokes for a short moment after each fragment.
|
|
1637
|
+
self._paste_active = True
|
|
1638
|
+
if self._keydrop_timer is not None:
|
|
1639
|
+
self._keydrop_timer.stop()
|
|
1640
|
+
self._keydrop_timer = self.set_timer(
|
|
1641
|
+
self.PASTE_KEYDROP_WINDOW, lambda: setattr(self, "_paste_active", False)
|
|
1642
|
+
)
|
|
1643
|
+
# Keep the paste "open" for more fragments; close it after a quiet gap.
|
|
1644
|
+
if self._merge_timer is not None:
|
|
1645
|
+
self._merge_timer.stop()
|
|
1646
|
+
self._merge_timer = self.set_timer(self.PASTE_MERGE_WINDOW, self._end_paste_merge)
|
|
1647
|
+
|
|
1648
|
+
def _end_paste_merge(self) -> None:
|
|
1649
|
+
"""Close the current paste so the next paste/fragment starts fresh.
|
|
1650
|
+
|
|
1651
|
+
Logs the collapsed-paste note to the transcript once, with the FINAL
|
|
1652
|
+
merged size, so a fragmented paste shows a single accurate notice.
|
|
1653
|
+
"""
|
|
1654
|
+
if self._merge_timer is not None:
|
|
1655
|
+
self._merge_timer.stop()
|
|
1656
|
+
self._merge_timer = None
|
|
1657
|
+
if self._active_paste_id is None:
|
|
1658
|
+
return
|
|
1659
|
+
if self._on_large_paste is not None and self._paste_tracker is not None:
|
|
1660
|
+
full = self._paste_tracker.get_paste(self._active_paste_id)
|
|
1661
|
+
if full is not None:
|
|
1662
|
+
self._on_large_paste(self._active_paste_ph, len(full))
|
|
1663
|
+
self._active_paste_id = None
|
|
1664
|
+
self._active_paste_ph = ""
|
|
1665
|
+
|
|
1666
|
+
|
|
1667
|
+
# ---------------------------------------------------------------------------
|
|
1668
|
+
# Question dock — keyboard-first answer picker for ask_user_question
|
|
1669
|
+
# ---------------------------------------------------------------------------
|
|
1670
|
+
|
|
1671
|
+
#: Label of the always-present final row: answer in free text instead.
|
|
1672
|
+
CUSTOM_ANSWER_LABEL = "Type your own answer"
|
|
1673
|
+
|
|
1674
|
+
#: Keyboard legend: the key names brighter than their explanations, matching the
|
|
1675
|
+
#: footer style. Assembled as ``Content`` rather than a markup string because a
|
|
1676
|
+
#: plain ``str`` handed to ``Static`` is parsed as markup, and markup rejects a
|
|
1677
|
+
#: ``$variable`` style value (it raised "Expected markup value"). No user text is
|
|
1678
|
+
#: interpolated, so this stays a literal.
|
|
1679
|
+
_HINTS = Content.assemble(
|
|
1680
|
+
("↑↓", "$text"),
|
|
1681
|
+
(" select ", "$text-muted"),
|
|
1682
|
+
("enter", "$text"),
|
|
1683
|
+
(" confirm ", "$text-muted"),
|
|
1684
|
+
("esc", "$text"),
|
|
1685
|
+
(" dismiss", "$text-muted"),
|
|
1686
|
+
)
|
|
1687
|
+
|
|
1688
|
+
|
|
1689
|
+
def _choices_from(payload: dict[str, Any]) -> list[dict[str, str]]:
|
|
1690
|
+
"""Answer rows from an ``ask_user_question`` interrupt payload.
|
|
1691
|
+
|
|
1692
|
+
Prefers the structured ``choices`` list and falls back to the flat
|
|
1693
|
+
``options`` strings, which is all the remote bridges, the cowork server and
|
|
1694
|
+
any older caller send. ``display`` is the answer to hand back: it is the
|
|
1695
|
+
exact string the flat form carries, so the tool's ``value_map`` resolves a
|
|
1696
|
+
selection from any surface the same way.
|
|
1697
|
+
"""
|
|
1698
|
+
raw = payload.get("choices")
|
|
1699
|
+
if isinstance(raw, list) and raw:
|
|
1700
|
+
rows: list[dict[str, str]] = []
|
|
1701
|
+
for item in raw:
|
|
1702
|
+
if not isinstance(item, dict):
|
|
1703
|
+
continue
|
|
1704
|
+
label = str(item.get("label") or item.get("value") or "")
|
|
1705
|
+
if not label:
|
|
1706
|
+
continue
|
|
1707
|
+
rows.append(
|
|
1708
|
+
{
|
|
1709
|
+
"label": label,
|
|
1710
|
+
"description": str(item.get("description") or ""),
|
|
1711
|
+
"display": str(item.get("display") or label),
|
|
1712
|
+
}
|
|
1713
|
+
)
|
|
1714
|
+
if rows:
|
|
1715
|
+
return rows
|
|
1716
|
+
return [
|
|
1717
|
+
{"label": str(opt), "description": "", "display": str(opt)}
|
|
1718
|
+
for opt in (payload.get("options") or [])
|
|
1719
|
+
]
|
|
1720
|
+
|
|
1721
|
+
|
|
1722
|
+
class QuestionDock(Vertical):
|
|
1723
|
+
"""A docked, keyboard-first answer list for an ``ask_user_question`` interrupt.
|
|
1724
|
+
|
|
1725
|
+
Lives inside ``#prompt-dock`` and is revealed by :meth:`activate` instead of
|
|
1726
|
+
being pushed as a screen, so the transcript stays visible and the footer
|
|
1727
|
+
keeps a single layout. The agent keeps running underneath; only the dock
|
|
1728
|
+
takes the keyboard while a question is open.
|
|
1729
|
+
|
|
1730
|
+
Rows are plain ``Static`` children coloured by CSS classes. Nothing is built
|
|
1731
|
+
from a markup string, so an option containing ``[`` cannot be parsed as
|
|
1732
|
+
markup and crash the render — the hazard ``QuestionModal`` had to work
|
|
1733
|
+
around by building a ``Text``.
|
|
1734
|
+
|
|
1735
|
+
The result is announced as an :class:`Answered` or :class:`Dismissed`
|
|
1736
|
+
message rather than returned, because a docked widget is not a screen and
|
|
1737
|
+
has no ``dismiss``.
|
|
1738
|
+
"""
|
|
1739
|
+
|
|
1740
|
+
#: Focus is *dynamic*, not static. A permanently focusable widget inside
|
|
1741
|
+
#: ``#prompt-dock`` competes with ``#prompt`` for the initial focus and
|
|
1742
|
+
#: silently broke the ``/wiki`` path (measured: ``test_tui_wiki_screen``
|
|
1743
|
+
#: passes with this False, fails with it True). So the dock is only a focus
|
|
1744
|
+
#: stop while a question is actually open — see :meth:`activate`.
|
|
1745
|
+
can_focus = False
|
|
1746
|
+
|
|
1747
|
+
class Answered(Message):
|
|
1748
|
+
"""The user confirmed an answer."""
|
|
1749
|
+
|
|
1750
|
+
def __init__(self, answer: str, selected_index: int | None) -> None:
|
|
1751
|
+
"""Record the answer and where it came from.
|
|
1752
|
+
|
|
1753
|
+
Args:
|
|
1754
|
+
answer: The answer to hand back to the tool.
|
|
1755
|
+
selected_index: Position among the listed options, or ``None``
|
|
1756
|
+
for a free-text answer.
|
|
1757
|
+
"""
|
|
1758
|
+
super().__init__()
|
|
1759
|
+
self.answer = answer
|
|
1760
|
+
self.selected_index = selected_index
|
|
1761
|
+
|
|
1762
|
+
class Dismissed(Message):
|
|
1763
|
+
"""The user dismissed the question instead of answering."""
|
|
1764
|
+
|
|
1765
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
1766
|
+
"""Build an inert, empty dock; :meth:`activate` fills it."""
|
|
1767
|
+
# **kwargs so compose() can pass id=/classes= through to Widget.
|
|
1768
|
+
super().__init__(**kwargs)
|
|
1769
|
+
self._choices: list[dict[str, str]] = []
|
|
1770
|
+
self._rows: list[Vertical] = []
|
|
1771
|
+
self._index = 0
|
|
1772
|
+
self._custom = False
|
|
1773
|
+
|
|
1774
|
+
def compose(self) -> ComposeResult:
|
|
1775
|
+
"""Build the dock once; :meth:`populate` fills and rebuilds the rows."""
|
|
1776
|
+
yield Static("", id="question-context")
|
|
1777
|
+
yield Static("", id="question-text")
|
|
1778
|
+
yield Vertical(id="question-options")
|
|
1779
|
+
yield Input(placeholder="Type your answer…", id="question-input")
|
|
1780
|
+
yield Static(_HINTS, id="question-hints")
|
|
1781
|
+
|
|
1782
|
+
# ── show / hide ────────────────────────────────────────────────────────
|
|
1783
|
+
|
|
1784
|
+
def activate(self, payload: dict[str, Any]) -> None:
|
|
1785
|
+
"""Fill the dock, reveal it, and hand it the keyboard."""
|
|
1786
|
+
self.populate(payload)
|
|
1787
|
+
self.can_focus = True
|
|
1788
|
+
self.add_class("active")
|
|
1789
|
+
self.focus()
|
|
1790
|
+
|
|
1791
|
+
def deactivate(self) -> None:
|
|
1792
|
+
"""Hide the dock and stop it competing for focus again."""
|
|
1793
|
+
self.remove_class("active")
|
|
1794
|
+
self.can_focus = False
|
|
1795
|
+
self._custom = False
|
|
1796
|
+
|
|
1797
|
+
# ── populating ─────────────────────────────────────────────────────────
|
|
1798
|
+
|
|
1799
|
+
def populate(self, payload: dict[str, Any]) -> None:
|
|
1800
|
+
"""Fill the dock from an interrupt payload and select the first row."""
|
|
1801
|
+
payload = payload or {}
|
|
1802
|
+
self._choices = _choices_from(payload)
|
|
1803
|
+
self._index = 0
|
|
1804
|
+
self._custom = False
|
|
1805
|
+
|
|
1806
|
+
context = str(payload.get("context") or "")
|
|
1807
|
+
ctx_row = self.query_one("#question-context", Static)
|
|
1808
|
+
ctx_row.display = bool(context)
|
|
1809
|
+
ctx_row.update(Text(context))
|
|
1810
|
+
|
|
1811
|
+
question = str(payload.get("question") or payload.get("prompt") or "")
|
|
1812
|
+
self.query_one("#question-text", Static).update(Text(question))
|
|
1813
|
+
|
|
1814
|
+
self.query_one("#question-options", Vertical).remove_class("hidden")
|
|
1815
|
+
field = self.query_one("#question-input", Input)
|
|
1816
|
+
field.remove_class("active")
|
|
1817
|
+
field.value = ""
|
|
1818
|
+
self._build_rows()
|
|
1819
|
+
|
|
1820
|
+
def _make_row(self, number: int, label: str, description: str) -> Vertical:
|
|
1821
|
+
"""One option: the numbered label, with its description indented below."""
|
|
1822
|
+
children: list[Static] = [Static(Text(f"{number}. {label}"), classes="q-label")]
|
|
1823
|
+
if description:
|
|
1824
|
+
children.append(Static(Text(description), classes="q-desc"))
|
|
1825
|
+
return Vertical(*children, classes="question-option")
|
|
1826
|
+
|
|
1827
|
+
def _build_rows(self) -> None:
|
|
1828
|
+
container = self.query_one("#question-options", Vertical)
|
|
1829
|
+
container.remove_children()
|
|
1830
|
+
rows = [
|
|
1831
|
+
self._make_row(n, choice["label"], choice["description"])
|
|
1832
|
+
for n, choice in enumerate(self._choices, start=1)
|
|
1833
|
+
]
|
|
1834
|
+
# The free-text row lives here, not in the tool: ask_user_question's
|
|
1835
|
+
# docstring promises an automatic "Other" option but never adds one, so
|
|
1836
|
+
# the widget owns it and every surface gets it.
|
|
1837
|
+
rows.append(
|
|
1838
|
+
self._make_row(
|
|
1839
|
+
len(self._choices) + 1,
|
|
1840
|
+
CUSTOM_ANSWER_LABEL,
|
|
1841
|
+
"Skip the list and answer in your own words.",
|
|
1842
|
+
)
|
|
1843
|
+
)
|
|
1844
|
+
self._rows = rows
|
|
1845
|
+
container.mount(*rows)
|
|
1846
|
+
self._sync_selection()
|
|
1847
|
+
|
|
1848
|
+
def _sync_selection(self) -> None:
|
|
1849
|
+
for i, row in enumerate(self._rows):
|
|
1850
|
+
row.set_class(i == self._index, "selected")
|
|
1851
|
+
if 0 <= self._index < len(self._rows):
|
|
1852
|
+
# Keeps the highlighted row visible when the list overflows.
|
|
1853
|
+
self._rows[self._index].scroll_visible()
|
|
1854
|
+
|
|
1855
|
+
@property
|
|
1856
|
+
def _on_custom_row(self) -> bool:
|
|
1857
|
+
return self._index == len(self._choices)
|
|
1858
|
+
|
|
1859
|
+
def _move(self, delta: int) -> None:
|
|
1860
|
+
if not self._rows:
|
|
1861
|
+
return
|
|
1862
|
+
self._index = (self._index + delta) % len(self._rows)
|
|
1863
|
+
self._sync_selection()
|
|
1864
|
+
|
|
1865
|
+
# ── custom answer ──────────────────────────────────────────────────────
|
|
1866
|
+
|
|
1867
|
+
def _begin_custom(self) -> None:
|
|
1868
|
+
"""Swap the list for the inline free-text field.
|
|
1869
|
+
|
|
1870
|
+
No seed character: assigning ``Input.value`` selects the whole string
|
|
1871
|
+
(applied asynchronously, so it lands after any synchronous collapse) and
|
|
1872
|
+
the next keystroke then *replaces* rather than appends — measured,
|
|
1873
|
+
typing "use" one key at a time yielded "se". Typing therefore starts
|
|
1874
|
+
from an empty field, after the user has chosen this row, which is also
|
|
1875
|
+
what the reference interaction describes.
|
|
1876
|
+
"""
|
|
1877
|
+
self._custom = True
|
|
1878
|
+
self.query_one("#question-options", Vertical).add_class("hidden")
|
|
1879
|
+
field = self.query_one("#question-input", Input)
|
|
1880
|
+
field.add_class("active")
|
|
1881
|
+
field.focus()
|
|
1882
|
+
|
|
1883
|
+
def _return_to_list(self) -> None:
|
|
1884
|
+
"""Back out of the free-text field and refocus the list."""
|
|
1885
|
+
self._custom = False
|
|
1886
|
+
field = self.query_one("#question-input", Input)
|
|
1887
|
+
field.remove_class("active")
|
|
1888
|
+
field.value = ""
|
|
1889
|
+
self.query_one("#question-options", Vertical).remove_class("hidden")
|
|
1890
|
+
self.focus()
|
|
1891
|
+
|
|
1892
|
+
def _confirm(self) -> None:
|
|
1893
|
+
if not self._rows:
|
|
1894
|
+
return
|
|
1895
|
+
if self._on_custom_row:
|
|
1896
|
+
self._begin_custom()
|
|
1897
|
+
return
|
|
1898
|
+
self.post_message(self.Answered(self._choices[self._index]["display"], self._index))
|
|
1899
|
+
|
|
1900
|
+
# ── keys ───────────────────────────────────────────────────────────────
|
|
1901
|
+
|
|
1902
|
+
def on_key(self, event: events.Key) -> None:
|
|
1903
|
+
"""Own up/down/enter/escape while the list has focus.
|
|
1904
|
+
|
|
1905
|
+
Every branch stops the event *and* calls ``prevent_default``. The app
|
|
1906
|
+
binds escape to ``cancel_turn`` (see ``NovaApp.BINDINGS``), so without
|
|
1907
|
+
both, dismissing a question would cancel the whole turn.
|
|
1908
|
+
"""
|
|
1909
|
+
key = event.key
|
|
1910
|
+
|
|
1911
|
+
if self._custom:
|
|
1912
|
+
if key == "escape":
|
|
1913
|
+
event.stop()
|
|
1914
|
+
event.prevent_default()
|
|
1915
|
+
self._return_to_list()
|
|
1916
|
+
return
|
|
1917
|
+
|
|
1918
|
+
if key in ("up", "down"):
|
|
1919
|
+
event.stop()
|
|
1920
|
+
event.prevent_default()
|
|
1921
|
+
self._move(-1 if key == "up" else 1)
|
|
1922
|
+
elif key == "enter":
|
|
1923
|
+
event.stop()
|
|
1924
|
+
event.prevent_default()
|
|
1925
|
+
self._confirm()
|
|
1926
|
+
elif key == "escape":
|
|
1927
|
+
event.stop()
|
|
1928
|
+
event.prevent_default()
|
|
1929
|
+
self.post_message(self.Dismissed())
|
|
1930
|
+
elif key.isdigit() and key != "0":
|
|
1931
|
+
# Direct pick, keeping the affordance QuestionModal had. A digit that
|
|
1932
|
+
# lands on the custom row only moves the selection; the next enter
|
|
1933
|
+
# opens the field.
|
|
1934
|
+
index = int(key) - 1
|
|
1935
|
+
if index < len(self._rows):
|
|
1936
|
+
self._index = index
|
|
1937
|
+
self._sync_selection()
|
|
1938
|
+
if not self._on_custom_row:
|
|
1939
|
+
self._confirm()
|
|
1940
|
+
# Printable letters are deliberately ignored here: free text is entered
|
|
1941
|
+
# after choosing the "Type your own answer" row, so a stray keystroke on
|
|
1942
|
+
# the list cannot silently discard the options.
|
|
1943
|
+
|
|
1944
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
1945
|
+
"""Answer with the typed text, or fall back to the list if it is empty."""
|
|
1946
|
+
text = event.value.strip()
|
|
1947
|
+
if not text:
|
|
1948
|
+
self._return_to_list()
|
|
1949
|
+
return
|
|
1950
|
+
self.post_message(self.Answered(text, None))
|
|
1951
|
+
|
|
1952
|
+
|
|
1953
|
+
class TuiInitRenderer:
|
|
1954
|
+
"""Adapter implementing ``InitRenderer`` for the Textual TUI path.
|
|
1955
|
+
|
|
1956
|
+
The exploration prompt streams through the TUI's native chat.
|
|
1957
|
+
"""
|
|
1958
|
+
|
|
1959
|
+
def __init__(self, app: NovaApp) -> None:
|
|
1960
|
+
self._app = app
|
|
1961
|
+
|
|
1962
|
+
def emit(self, event) -> None:
|
|
1963
|
+
"""Pipeline progress event — no-op."""
|
|
1964
|
+
pass
|
|
1965
|
+
|
|
1966
|
+
def result(self, result) -> None:
|
|
1967
|
+
"""Log the final pipeline outcome."""
|
|
1968
|
+
if not result.ok and result.message:
|
|
1969
|
+
self._app._log(Text(result.message, style="yellow"))
|
|
1970
|
+
|
|
1971
|
+
async def run_exploration(
|
|
1972
|
+
self,
|
|
1973
|
+
project_root: Path,
|
|
1974
|
+
nova_md_path: Path,
|
|
1975
|
+
agent,
|
|
1976
|
+
session_state,
|
|
1977
|
+
assistant_id: str,
|
|
1978
|
+
token_tracker, # noqa: ARG002
|
|
1979
|
+
) -> None:
|
|
1980
|
+
"""Stream the exploration prompt through the TUI."""
|
|
1981
|
+
from novacode_cli.prompts import render_template
|
|
1982
|
+
|
|
1983
|
+
prompt = render_template(
|
|
1984
|
+
"init_exploration.jinja",
|
|
1985
|
+
project_root=str(project_root),
|
|
1986
|
+
nova_md_path=str(nova_md_path),
|
|
1987
|
+
)
|
|
1988
|
+
prev = session_state.auto_approve
|
|
1989
|
+
session_state.auto_approve = True
|
|
1990
|
+
try:
|
|
1991
|
+
await self._app._stream_prompt(prompt)
|
|
1992
|
+
finally:
|
|
1993
|
+
session_state.auto_approve = prev
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
|
|
1997
|
+
class SubagentStatus(Static):
|
|
1998
|
+
"""A compact local dispatch row that opens its live activity preview."""
|
|
1999
|
+
|
|
2000
|
+
can_focus = True
|
|
2001
|
+
BINDINGS: ClassVar = [("enter", "preview", "View activity")]
|
|
2002
|
+
DEFAULT_CSS = """
|
|
2003
|
+
SubagentStatus { height: auto; }
|
|
2004
|
+
SubagentStatus:hover, SubagentStatus:focus { background: $surface; }
|
|
2005
|
+
"""
|
|
2006
|
+
|
|
2007
|
+
def __init__(self, task_id: str) -> None:
|
|
2008
|
+
"""Bind the status row to one dispatch's preview."""
|
|
2009
|
+
super().__init__(classes="subagent-inline", markup=False)
|
|
2010
|
+
self.task_id = task_id
|
|
2011
|
+
self.tooltip = "View subagent activity · click or Enter"
|
|
2012
|
+
|
|
2013
|
+
def on_click(self, event: events.Click) -> None:
|
|
2014
|
+
"""Open this dispatch without triggering transcript click handlers."""
|
|
2015
|
+
event.stop()
|
|
2016
|
+
self.action_preview()
|
|
2017
|
+
|
|
2018
|
+
def action_preview(self) -> None:
|
|
2019
|
+
"""Open the same activity screen used by remote subagents."""
|
|
2020
|
+
cast("NovaApp", self.app)._open_subagent_preview(self.task_id)
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
class SubagentsDock(Vertical):
|
|
2024
|
+
"""The dynamic-subagents panel: phases beside their tasks, while they run.
|
|
2025
|
+
|
|
2026
|
+
Owns its own click handling rather than adding branches to the app's global
|
|
2027
|
+
click walk: a click on a phase line folds that phase, a click on a task opens
|
|
2028
|
+
its preview, a click anywhere else folds the whole panel. Row coordinates are
|
|
2029
|
+
the dock's, so the header occupies line 0 and the rendered table starts at
|
|
2030
|
+
line 1.
|
|
2031
|
+
"""
|
|
2032
|
+
|
|
2033
|
+
def on_click(self, event: events.Click) -> None:
|
|
2034
|
+
"""Delegate the click to the app, which owns the row map."""
|
|
2035
|
+
handler = getattr(self.app, "_on_subagents_click", None)
|
|
2036
|
+
if handler is not None:
|
|
2037
|
+
body = self.query_one("#subagents-body")
|
|
2038
|
+
handler(event.screen_y - body.region.y + 1, event.screen_x - body.region.x)
|