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,290 @@
|
|
|
1
|
+
"""Repair malformed tool-call history before every model call.
|
|
2
|
+
|
|
3
|
+
Two failure shapes kill a strict provider, and only some providers tolerate
|
|
4
|
+
them, so they surface only after a model/provider switch hands one provider's
|
|
5
|
+
history to another:
|
|
6
|
+
|
|
7
|
+
1. **An unanswered call** — an assistant message's ``tool_calls`` are not each
|
|
8
|
+
followed by a matching tool message:
|
|
9
|
+
|
|
10
|
+
400 invalid_request_error — An assistant message with 'tool_calls' must
|
|
11
|
+
be followed by tool messages responding to each 'tool_call_id'.
|
|
12
|
+
|
|
13
|
+
deepagents already ships that repair — ``PatchToolCallsMiddleware`` gives each
|
|
14
|
+
unanswered call a synthetic "cancelled" result — but runs it in
|
|
15
|
+
``before_agent``, i.e. once per invocation, so a call left unanswered *during*
|
|
16
|
+
a turn reaches the next model call unrepaired.
|
|
17
|
+
|
|
18
|
+
2. **An orphaned result** — a ``tool`` message with no preceding assistant
|
|
19
|
+
``tool_calls``. Reformatting history across providers can drop the typed
|
|
20
|
+
call while the result survives:
|
|
21
|
+
|
|
22
|
+
400 invalid_request_error — Messages with role 'tool' must be a response
|
|
23
|
+
to a preceding message with 'tool_calls'.
|
|
24
|
+
|
|
25
|
+
``PatchToolCallsMiddleware`` only *adds* missing results; it never removes an
|
|
26
|
+
orphan, so this shape reached the provider as-is. Prompt-cache compaction, a
|
|
27
|
+
session-continuation window trim, or a provider whose converter stores calls
|
|
28
|
+
in a non-standard place can all drop the call and leave the result behind.
|
|
29
|
+
|
|
30
|
+
This runs the upstream repair plus :func:`sanitize_history` in ``before_model``,
|
|
31
|
+
so it holds at the point that actually matters: what is about to be sent.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
import json
|
|
37
|
+
import re
|
|
38
|
+
from typing import TYPE_CHECKING, Any
|
|
39
|
+
|
|
40
|
+
from deepagents.middleware.patch_tool_calls import PatchToolCallsMiddleware
|
|
41
|
+
from langchain_core.messages import AIMessage, AnyMessage, RemoveMessage, ToolMessage
|
|
42
|
+
from langgraph.graph.message import REMOVE_ALL_MESSAGES
|
|
43
|
+
|
|
44
|
+
if TYPE_CHECKING:
|
|
45
|
+
from langchain.agents.middleware.types import AgentState
|
|
46
|
+
from langgraph.runtime import Runtime
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#: Thinking-model fields that live in ``additional_kwargs`` and are echoed back
|
|
50
|
+
#: on later requests (see ``utils/backend_patches``). They belong to the model
|
|
51
|
+
#: that produced them; a different provider must not be sent them.
|
|
52
|
+
_REASONING_FIELDS = ("reasoning_content", "reasoning")
|
|
53
|
+
|
|
54
|
+
#: Provider-specific content-block types (Anthropic extended thinking). They are
|
|
55
|
+
#: signed for the model that produced them and are not portable across providers.
|
|
56
|
+
_THINKING_BLOCK_TYPES = ("thinking", "redacted_thinking")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _call_ids(message: AnyMessage) -> list[str]:
|
|
60
|
+
"""The tool-call ids carried by *message*, if it is an assistant message.
|
|
61
|
+
|
|
62
|
+
Includes ``invalid_tool_calls`` (malformed arguments): the upstream patcher
|
|
63
|
+
synthesizes results for those too, so their result must not look orphaned.
|
|
64
|
+
"""
|
|
65
|
+
if not isinstance(message, AIMessage):
|
|
66
|
+
return []
|
|
67
|
+
ids: list[str] = []
|
|
68
|
+
for call in (
|
|
69
|
+
*(getattr(message, "tool_calls", None) or ()),
|
|
70
|
+
*(getattr(message, "invalid_tool_calls", None) or ()),
|
|
71
|
+
):
|
|
72
|
+
cid = call.get("id") if isinstance(call, dict) else getattr(call, "id", None)
|
|
73
|
+
if cid:
|
|
74
|
+
ids.append(cid)
|
|
75
|
+
return ids
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _promote_raw_tool_calls(message: AnyMessage) -> AnyMessage:
|
|
79
|
+
"""Move OpenAI-style raw ``tool_calls`` into typed ``AIMessage.tool_calls``.
|
|
80
|
+
|
|
81
|
+
Some providers populate only ``additional_kwargs["tool_calls"]`` (the raw
|
|
82
|
+
wire form) and leave the typed field empty. The next provider's converter
|
|
83
|
+
reads the typed field, so it emits an assistant turn with no calls while the
|
|
84
|
+
tool results that answered them remain — producing the orphaned result above.
|
|
85
|
+
Promoting the raw calls restores the pairing.
|
|
86
|
+
"""
|
|
87
|
+
if not isinstance(message, AIMessage) or getattr(message, "tool_calls", None):
|
|
88
|
+
return message
|
|
89
|
+
raw = (getattr(message, "additional_kwargs", None) or {}).get("tool_calls")
|
|
90
|
+
if not raw:
|
|
91
|
+
return message
|
|
92
|
+
promoted: list[dict[str, Any]] = []
|
|
93
|
+
for entry in raw:
|
|
94
|
+
if not isinstance(entry, dict):
|
|
95
|
+
continue
|
|
96
|
+
function = entry.get("function") or {}
|
|
97
|
+
arguments = function.get("arguments")
|
|
98
|
+
if isinstance(arguments, str):
|
|
99
|
+
try:
|
|
100
|
+
arguments = json.loads(arguments)
|
|
101
|
+
except (TypeError, ValueError):
|
|
102
|
+
arguments = {"_raw": arguments}
|
|
103
|
+
elif arguments is None and isinstance(function.get("args"), dict):
|
|
104
|
+
arguments = function["args"]
|
|
105
|
+
promoted.append(
|
|
106
|
+
{
|
|
107
|
+
"name": function.get("name") or entry.get("name") or "",
|
|
108
|
+
"args": arguments if isinstance(arguments, dict) else {},
|
|
109
|
+
"id": entry.get("id") or "",
|
|
110
|
+
"type": "tool_call",
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
if not promoted:
|
|
114
|
+
return message
|
|
115
|
+
return message.model_copy(update={"tool_calls": promoted})
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _origin_model(message: AnyMessage) -> str | None:
|
|
119
|
+
"""The model that produced *message*, from its response metadata, if known."""
|
|
120
|
+
metadata = getattr(message, "response_metadata", None) or {}
|
|
121
|
+
if not isinstance(metadata, dict):
|
|
122
|
+
return None
|
|
123
|
+
return metadata.get("model_name") or metadata.get("model")
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _model_base(name: str) -> str:
|
|
127
|
+
"""``ollama:deepseek-v4.1-flash:cloud`` -> ``deepseek-v4.1-flash``.
|
|
128
|
+
|
|
129
|
+
Providers report a model without the provider prefix or Ollama tag Nova
|
|
130
|
+
names it by. ponytail: sizes of one family (``qwen3:8b``/``qwen3:32b``)
|
|
131
|
+
compare equal; their reasoning is kept, which those providers accept.
|
|
132
|
+
"""
|
|
133
|
+
parts = name.lower().rsplit("/", 1)[-1].split(":")
|
|
134
|
+
# gpt-4o-2024-08-06 / claude-sonnet-4-5-20250929: a dated snapshot of gpt-4o.
|
|
135
|
+
return re.sub(r"-\d{4}-?\d{2}-?\d{2}$", "", max(parts, key=len))
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _strip_foreign_reasoning(message: AnyMessage, current_model: str | None) -> AnyMessage:
|
|
139
|
+
"""Drop provider-specific reasoning produced by a *different* model.
|
|
140
|
+
|
|
141
|
+
Covers both places it can live: ``reasoning_content``/``reasoning`` in
|
|
142
|
+
``additional_kwargs`` (OpenAI-compatible thinking models, re-attached by the
|
|
143
|
+
backend patch) and ``thinking`` content blocks (Anthropic extended thinking,
|
|
144
|
+
which are signed for the model that produced them). After a switch that is
|
|
145
|
+
wrong: the new provider never asked for it and some reject unknown fields or
|
|
146
|
+
block types. Only strips when provenance is known and differs, so a thinking
|
|
147
|
+
model that stays in use keeps its own chain of thought.
|
|
148
|
+
"""
|
|
149
|
+
if not current_model or not isinstance(message, AIMessage):
|
|
150
|
+
return message
|
|
151
|
+
origin = _origin_model(message)
|
|
152
|
+
# Stripping the model's own reasoning rewrote the whole history before
|
|
153
|
+
# every call (see RepairToolCallsEachStep.before_model).
|
|
154
|
+
if origin is None or _model_base(origin) == _model_base(current_model):
|
|
155
|
+
return message
|
|
156
|
+
|
|
157
|
+
updates: dict[str, Any] = {}
|
|
158
|
+
extra = getattr(message, "additional_kwargs", None)
|
|
159
|
+
if isinstance(extra, dict) and any(k in extra for k in _REASONING_FIELDS):
|
|
160
|
+
updates["additional_kwargs"] = {
|
|
161
|
+
k: v for k, v in extra.items() if k not in _REASONING_FIELDS
|
|
162
|
+
}
|
|
163
|
+
content = getattr(message, "content", None)
|
|
164
|
+
if isinstance(content, list) and any(
|
|
165
|
+
isinstance(block, dict) and block.get("type") in _THINKING_BLOCK_TYPES
|
|
166
|
+
for block in content
|
|
167
|
+
):
|
|
168
|
+
filtered = [
|
|
169
|
+
block
|
|
170
|
+
for block in content
|
|
171
|
+
if not (isinstance(block, dict) and block.get("type") in _THINKING_BLOCK_TYPES)
|
|
172
|
+
]
|
|
173
|
+
updates["content"] = filtered or ""
|
|
174
|
+
if not updates:
|
|
175
|
+
return message
|
|
176
|
+
return message.model_copy(update=updates)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def sanitize_history(
|
|
180
|
+
messages: list[AnyMessage], current_model: str | None = None
|
|
181
|
+
) -> list[AnyMessage]:
|
|
182
|
+
"""Make *messages* a well-formed sequence for any provider.
|
|
183
|
+
|
|
184
|
+
- Promotes raw tool calls so the assistant turn and its results stay paired.
|
|
185
|
+
- Drops a ``tool`` message that no preceding assistant message issued.
|
|
186
|
+
- Strips reasoning echoed from a different model (see
|
|
187
|
+
:func:`_strip_foreign_reasoning`).
|
|
188
|
+
|
|
189
|
+
Returns the original list object when nothing changed, so callers can use
|
|
190
|
+
identity to decide whether a rewrite is needed.
|
|
191
|
+
"""
|
|
192
|
+
promoted = [_promote_raw_tool_calls(m) for m in messages]
|
|
193
|
+
|
|
194
|
+
issued: set[str] = set()
|
|
195
|
+
kept: list[AnyMessage] = []
|
|
196
|
+
for message in promoted:
|
|
197
|
+
issued.update(_call_ids(message))
|
|
198
|
+
if isinstance(message, ToolMessage):
|
|
199
|
+
if getattr(message, "tool_call_id", None) in issued:
|
|
200
|
+
kept.append(message)
|
|
201
|
+
# else: orphaned result → drop, or a strict provider rejects the whole request
|
|
202
|
+
else:
|
|
203
|
+
kept.append(message)
|
|
204
|
+
|
|
205
|
+
if current_model:
|
|
206
|
+
kept = [_strip_foreign_reasoning(m, current_model) for m in kept]
|
|
207
|
+
|
|
208
|
+
if len(kept) == len(messages) and all(a is b for a, b in zip(kept, messages)):
|
|
209
|
+
return messages
|
|
210
|
+
return kept
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class RepairToolCallsEachStep(PatchToolCallsMiddleware):
|
|
214
|
+
"""``PatchToolCallsMiddleware`` + history sanitation before every model call.
|
|
215
|
+
|
|
216
|
+
A subclass rather than a reimplementation: the pairing logic (including the
|
|
217
|
+
handling of ``invalid_tool_calls``) stays exactly upstream's, and inherits
|
|
218
|
+
any fix to it. The distinct class name also keeps it from colliding with the
|
|
219
|
+
instance deepagents already installs.
|
|
220
|
+
|
|
221
|
+
Pairing repairs are written back to the thread (once; they then hold).
|
|
222
|
+
Another model's reasoning is only dropped from the request: written back,
|
|
223
|
+
any mismatch between Nova's model name and the provider's re-stripped every
|
|
224
|
+
new reply, and each strip rewrote the whole history into the checkpoint --
|
|
225
|
+
quadratic disk writes over a long task, which froze the machine.
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
def __init__(self, *, current_model: str | None = None) -> None:
|
|
229
|
+
"""``current_model``: the model about to be called; enables cross-provider
|
|
230
|
+
reasoning stripping (see :func:`sanitize_history`)."""
|
|
231
|
+
super().__init__()
|
|
232
|
+
self._current_model = current_model
|
|
233
|
+
|
|
234
|
+
def before_model(
|
|
235
|
+
self, state: AgentState, runtime: Runtime[Any]
|
|
236
|
+
) -> dict[str, Any] | None:
|
|
237
|
+
patched = self.before_agent(state, runtime)
|
|
238
|
+
messages = patched["messages"][1:] if patched else list(state["messages"])
|
|
239
|
+
filled = [_fill_empty_result(m) for m in messages]
|
|
240
|
+
sanitized = sanitize_history(filled)
|
|
241
|
+
if patched is None and len(sanitized) == len(messages) and all(
|
|
242
|
+
a is b for a, b in zip(sanitized, messages)
|
|
243
|
+
):
|
|
244
|
+
return None
|
|
245
|
+
return {"messages": [RemoveMessage(id=REMOVE_ALL_MESSAGES), *sanitized]}
|
|
246
|
+
|
|
247
|
+
async def abefore_model(
|
|
248
|
+
self, state: AgentState, runtime: Runtime[Any]
|
|
249
|
+
) -> dict[str, Any] | None:
|
|
250
|
+
return self.before_model(state, runtime)
|
|
251
|
+
|
|
252
|
+
def _for_request(self, request: Any) -> Any: # noqa: ANN401 - a ModelRequest
|
|
253
|
+
"""``request`` without another model's reasoning; itself when there is none."""
|
|
254
|
+
if not self._current_model:
|
|
255
|
+
return request
|
|
256
|
+
messages = list(request.messages)
|
|
257
|
+
stripped = [_strip_foreign_reasoning(m, self._current_model) for m in messages]
|
|
258
|
+
if all(a is b for a, b in zip(stripped, messages)):
|
|
259
|
+
return request
|
|
260
|
+
return request.override(messages=stripped)
|
|
261
|
+
|
|
262
|
+
def wrap_model_call(self, request: Any, handler: Any) -> Any: # noqa: ANN401
|
|
263
|
+
return handler(self._for_request(request))
|
|
264
|
+
|
|
265
|
+
async def awrap_model_call(self, request: Any, handler: Any) -> Any: # noqa: ANN401
|
|
266
|
+
return await handler(self._for_request(request))
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
# DeepSeek rejects an empty tool result outright:
|
|
270
|
+
# Message {'role': 'tool', 'content': None, ...} has no content.
|
|
271
|
+
# Tools return one legitimately — Serena's read_file on an empty file returns a
|
|
272
|
+
# single empty text block — and once it is in history every later request of
|
|
273
|
+
# the session fails. The repair is persisted, so saved sessions heal too.
|
|
274
|
+
EMPTY_TOOL_RESULT = "(no output)"
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def _fill_empty_result(msg: AnyMessage) -> AnyMessage:
|
|
278
|
+
if not isinstance(msg, ToolMessage):
|
|
279
|
+
return msg
|
|
280
|
+
content = msg.content
|
|
281
|
+
if isinstance(content, str):
|
|
282
|
+
empty = not content.strip()
|
|
283
|
+
else:
|
|
284
|
+
empty = all(
|
|
285
|
+
isinstance(block, dict)
|
|
286
|
+
and block.get("type") == "text"
|
|
287
|
+
and not str(block.get("text", "")).strip()
|
|
288
|
+
for block in content
|
|
289
|
+
)
|
|
290
|
+
return msg.model_copy(update={"content": EMPTY_TOOL_RESULT}) if empty else msg
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"""Restorable clearing of old tool results.
|
|
2
|
+
|
|
3
|
+
``ClearToolUsesEdit`` replaces an old tool result with a fixed placeholder that
|
|
4
|
+
tells the model to run the tool again. That is only true for a *repeatable*
|
|
5
|
+
tool: a 4-minute test run, a shell command with side effects, a web search or a
|
|
6
|
+
one-shot MCP call cannot be re-run to get the same bytes back, so the
|
|
7
|
+
information is simply gone.
|
|
8
|
+
|
|
9
|
+
Manus calls the safe version **restorable compaction**: strip from the context
|
|
10
|
+
only what an external store can reconstruct — drop a page's body, keep its URL;
|
|
11
|
+
drop a file's content, keep its path. Claude Code does the same thing under the
|
|
12
|
+
name microcompaction (large tool outputs go to disk, a path stays inline).
|
|
13
|
+
|
|
14
|
+
This module is that disk tier. The payload is written to the agent's ``cleared``
|
|
15
|
+
directory, which is mounted read-only-in-practice at :data:`VIRTUAL_PREFIX`, and
|
|
16
|
+
the placeholder names the file so ``read_file`` can bring it back.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import hashlib
|
|
22
|
+
import logging
|
|
23
|
+
import re
|
|
24
|
+
import time
|
|
25
|
+
from dataclasses import dataclass
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
from langchain.agents.middleware import ClearToolUsesEdit
|
|
30
|
+
from langchain_core.messages import AnyMessage, ToolMessage
|
|
31
|
+
|
|
32
|
+
logger = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
#: Virtual path the offload directory is mounted at (a CompositeBackend route).
|
|
35
|
+
VIRTUAL_PREFIX = "/cleared/"
|
|
36
|
+
|
|
37
|
+
#: Offloaded payloads older than this are deleted on the next offload. They only
|
|
38
|
+
#: matter to the conversation that produced them, and an unbounded directory of
|
|
39
|
+
#: tool output is its own bug.
|
|
40
|
+
MAX_AGE_SECONDS = 7 * 24 * 3600
|
|
41
|
+
|
|
42
|
+
#: Shown when the payload could not be written (disk full, read-only home): the
|
|
43
|
+
#: old behaviour, which is honest about what was lost.
|
|
44
|
+
UNSAVED = "[Old tool result cleared to save context. Re-run the tool if you need it again.]"
|
|
45
|
+
|
|
46
|
+
_SAFE = re.compile(r"[^A-Za-z0-9._-]+")
|
|
47
|
+
_pruned = False
|
|
48
|
+
# Stems already on disk. The edit runs on every model call and re-clears every
|
|
49
|
+
# old result each time, so without this each call paid a mkdir and two stats
|
|
50
|
+
# per cleared result: 190 ms of a 230 ms pass over a 600-step conversation.
|
|
51
|
+
_written: set[str] = set()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _offload_stem(name: str | None, call_id: str, text: str) -> str:
|
|
55
|
+
"""Filename stem for an offloaded payload. The digest is the uniqueness claim.
|
|
56
|
+
|
|
57
|
+
``name`` + ``call_id`` is not an identity: a resumed session reuses
|
|
58
|
+
``tool_call_id`` values -- one archive had 444 results under 122 distinct ids
|
|
59
|
+
(see :func:`novacode_cli.agents.tool_verdicts.result_key`) -- so two results
|
|
60
|
+
with the same id would name the same file and the second would silently
|
|
61
|
+
overwrite the first, while the first result's placeholder still points at
|
|
62
|
+
it. Recovery would then hand back the wrong bytes with no sign anything went
|
|
63
|
+
wrong. Hashing the payload into the name gives distinct bytes distinct
|
|
64
|
+
files; identical bytes sharing one file is harmless.
|
|
65
|
+
|
|
66
|
+
The digest is appended *after* truncation, so a long tool name or id can
|
|
67
|
+
never cut it off -- which would put the collision straight back.
|
|
68
|
+
"""
|
|
69
|
+
prefix = _SAFE.sub("-", f"{name or 'tool'}-{call_id}")[:64]
|
|
70
|
+
digest = hashlib.sha256(text.encode("utf-8", "replace")).hexdigest()[:8]
|
|
71
|
+
return f"{prefix}-{digest}"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def cleared_dir(agent_dir: Path) -> Path:
|
|
75
|
+
"""Directory backing :data:`VIRTUAL_PREFIX` for *agent_dir*."""
|
|
76
|
+
return agent_dir / "cleared"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _prune(directory: Path) -> None:
|
|
80
|
+
"""Delete offloads older than :data:`MAX_AGE_SECONDS`. Once per process."""
|
|
81
|
+
global _pruned
|
|
82
|
+
if _pruned:
|
|
83
|
+
return
|
|
84
|
+
_pruned = True
|
|
85
|
+
cutoff = time.time() - MAX_AGE_SECONDS
|
|
86
|
+
try:
|
|
87
|
+
for path in directory.glob("*.txt"):
|
|
88
|
+
if path.stat().st_mtime < cutoff:
|
|
89
|
+
path.unlink(missing_ok=True)
|
|
90
|
+
except OSError: # housekeeping never blocks the turn
|
|
91
|
+
logger.debug("Could not prune %s", directory, exc_info=True)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# No slots=True: it rebuilds the class, which breaks the zero-arg `super()`
|
|
95
|
+
# below (the __class__ cell still points at the pre-slots class).
|
|
96
|
+
@dataclass
|
|
97
|
+
class OffloadingToolUsesEdit(ClearToolUsesEdit):
|
|
98
|
+
"""``ClearToolUsesEdit`` that writes the payload out instead of dropping it."""
|
|
99
|
+
|
|
100
|
+
offload_dir: Path | None = None
|
|
101
|
+
|
|
102
|
+
def apply(self, messages: list[AnyMessage], *, count_tokens) -> None: # noqa: ANN001
|
|
103
|
+
"""Clear old tool results, keeping their payloads on disk."""
|
|
104
|
+
# The payloads have to be captured BEFORE the base class overwrites
|
|
105
|
+
# them; it rewrites `messages[idx]` in place with a copy carrying the
|
|
106
|
+
# placeholder, so afterwards the original content is unreachable.
|
|
107
|
+
# Keyed by position rather than by tool_call_id, which is NOT unique:
|
|
108
|
+
# a resumed session reuses ids, and an id-keyed map would keep only the
|
|
109
|
+
# last payload for that id and hand it back for every result sharing it.
|
|
110
|
+
before = {
|
|
111
|
+
idx: (msg.name, msg.content)
|
|
112
|
+
for idx, msg in enumerate(messages)
|
|
113
|
+
if isinstance(msg, ToolMessage)
|
|
114
|
+
}
|
|
115
|
+
super().apply(messages, count_tokens=count_tokens)
|
|
116
|
+
if self.offload_dir is None:
|
|
117
|
+
return
|
|
118
|
+
for idx, msg in enumerate(messages):
|
|
119
|
+
# The base class sets content to exactly `self.placeholder` on the
|
|
120
|
+
# messages it just cleared — that is the marker for "this one".
|
|
121
|
+
if not isinstance(msg, ToolMessage) or msg.content != self.placeholder:
|
|
122
|
+
continue
|
|
123
|
+
name, payload = before.get(idx, (None, None))
|
|
124
|
+
# A failed save still leaves the result cleared — the context
|
|
125
|
+
# pressure is real either way — but then it must say so, not leave
|
|
126
|
+
# the bare marker for the model to interpret.
|
|
127
|
+
saved = self._save(msg.tool_call_id, name, payload) or UNSAVED
|
|
128
|
+
messages[idx] = msg.model_copy(update={"content": saved})
|
|
129
|
+
|
|
130
|
+
def _save(self, call_id: str, name: str | None, payload: object) -> str | None:
|
|
131
|
+
"""Write *payload* out; return the replacement placeholder, or None.
|
|
132
|
+
|
|
133
|
+
The placeholder names the file so ``read_file`` can bring the payload
|
|
134
|
+
back, so the name has to be unique per payload -- see
|
|
135
|
+
:func:`_offload_stem`.
|
|
136
|
+
"""
|
|
137
|
+
text = payload if isinstance(payload, str) else str(payload or "")
|
|
138
|
+
if not text.strip() or self.offload_dir is None:
|
|
139
|
+
return None
|
|
140
|
+
stem = _offload_stem(name, call_id, text)
|
|
141
|
+
path = self.offload_dir / f"{stem}.txt"
|
|
142
|
+
key = str(path)
|
|
143
|
+
if key not in _written:
|
|
144
|
+
try:
|
|
145
|
+
self.offload_dir.mkdir(parents=True, exist_ok=True)
|
|
146
|
+
_prune(self.offload_dir)
|
|
147
|
+
# The name is a digest of the payload, so an existing file
|
|
148
|
+
# already holds exactly these bytes.
|
|
149
|
+
if not path.exists():
|
|
150
|
+
path.write_text(text, encoding="utf-8", errors="replace")
|
|
151
|
+
except OSError:
|
|
152
|
+
logger.debug("Could not offload tool result %s", call_id, exc_info=True)
|
|
153
|
+
return None
|
|
154
|
+
_written.add(key)
|
|
155
|
+
return (
|
|
156
|
+
f"[Old {name or 'tool'} result moved out of context to save space. "
|
|
157
|
+
f"The full output is saved at {VIRTUAL_PREFIX}{path.name} — "
|
|
158
|
+
f"read_file it if you need it again.]"
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# No slots=True, for the same reason as the base class above.
|
|
163
|
+
@dataclass
|
|
164
|
+
class VerdictToolUsesEdit(OffloadingToolUsesEdit):
|
|
165
|
+
"""Clear only the results a decision model scored stale.
|
|
166
|
+
|
|
167
|
+
Identical to :class:`OffloadingToolUsesEdit` in every other respect — same
|
|
168
|
+
offload, same recovery, same placeholder — but the *selection* is not "every
|
|
169
|
+
result older than the trigger except the last few". A result is cleared only
|
|
170
|
+
when its cached verdict says it is no longer needed:
|
|
171
|
+
|
|
172
|
+
* no verdict (never scored, or scored under a different value) → **keep**.
|
|
173
|
+
A cold cache keeps results while scoring is healthy. When ``scorer``
|
|
174
|
+
reports a failed or overdue request, the normal age-based edit takes over.
|
|
175
|
+
* verdict at or above ``keep_threshold`` → keep.
|
|
176
|
+
|
|
177
|
+
The ``trigger`` still gates the whole edit, so nothing is cleared before the
|
|
178
|
+
same context pressure the heuristic waits for, and the newest ``keep``
|
|
179
|
+
results stay verbatim either way. Verdicts arrive from
|
|
180
|
+
:mod:`novacode_cli.agents.tool_verdicts`; this class only reads them, which
|
|
181
|
+
keeps the hot path (``apply`` runs on every model call) free of I/O.
|
|
182
|
+
"""
|
|
183
|
+
|
|
184
|
+
verdicts: Any = None
|
|
185
|
+
keep_threshold: float = 0.5
|
|
186
|
+
scorer: Any = None
|
|
187
|
+
|
|
188
|
+
def apply(self, messages: list[AnyMessage], *, count_tokens) -> None: # noqa: ANN001
|
|
189
|
+
"""Clear only judged-stale results; capture payloads before they vanish."""
|
|
190
|
+
if self.scorer is not None and self.scorer.fallback_required:
|
|
191
|
+
super().apply(messages, count_tokens=count_tokens)
|
|
192
|
+
return
|
|
193
|
+
if self.verdicts is None:
|
|
194
|
+
return
|
|
195
|
+
# As in the base class: the payloads must be read before super() rewrites
|
|
196
|
+
# them in place, and the same marker identifies what it cleared. Keyed by
|
|
197
|
+
# position, because tool_call_id is not unique across a resumed session
|
|
198
|
+
# and an id-keyed map would restore the same payload for every result
|
|
199
|
+
# sharing that id.
|
|
200
|
+
before = {
|
|
201
|
+
idx: msg
|
|
202
|
+
for idx, msg in enumerate(messages)
|
|
203
|
+
if isinstance(msg, ToolMessage)
|
|
204
|
+
}
|
|
205
|
+
judged = self._judged_stale_ids(messages)
|
|
206
|
+
super().apply(messages, count_tokens=count_tokens)
|
|
207
|
+
self._restore_unjudged(messages, before, judged)
|
|
208
|
+
|
|
209
|
+
def _judged_stale_ids(self, messages: list[AnyMessage]) -> set[int]:
|
|
210
|
+
"""Positions of the results the model scored stale and this edit may clear.
|
|
211
|
+
|
|
212
|
+
Positions, not ``tool_call_id`` values: the id is not unique across a resumed
|
|
213
|
+
session, so an id-keyed set would mark every result sharing an id as
|
|
214
|
+
judged once any one of them scored stale, and the others would be cleared
|
|
215
|
+
without ever being judged.
|
|
216
|
+
"""
|
|
217
|
+
cleared = {
|
|
218
|
+
index
|
|
219
|
+
for index, message in enumerate(messages)
|
|
220
|
+
if isinstance(message, ToolMessage)
|
|
221
|
+
and message.response_metadata.get("context_editing", {}).get("cleared")
|
|
222
|
+
}
|
|
223
|
+
# The base class clears everything but the last `keep` results (and only
|
|
224
|
+
# when the pool exceeds `keep` at all), before any verdict is consulted.
|
|
225
|
+
#
|
|
226
|
+
# `cleared` marks a result the base class has already reached. Previously
|
|
227
|
+
# retained results are restored including their original metadata, so
|
|
228
|
+
# they remain eligible for a later verdict or the default fallback.
|
|
229
|
+
results = [
|
|
230
|
+
(index, message)
|
|
231
|
+
for index, message in enumerate(messages)
|
|
232
|
+
if isinstance(message, ToolMessage)
|
|
233
|
+
]
|
|
234
|
+
if self.keep >= len(results):
|
|
235
|
+
return set()
|
|
236
|
+
window = results[: len(results) - self.keep]
|
|
237
|
+
excluded = set(self.exclude_tools)
|
|
238
|
+
|
|
239
|
+
judged: set[int] = set()
|
|
240
|
+
for index, message in window:
|
|
241
|
+
if index in cleared:
|
|
242
|
+
continue
|
|
243
|
+
if (message.name or "") in excluded:
|
|
244
|
+
continue
|
|
245
|
+
try:
|
|
246
|
+
stale = self.verdicts.stale(
|
|
247
|
+
message, keep_threshold=self.keep_threshold
|
|
248
|
+
)
|
|
249
|
+
except Exception: # noqa: BLE001 — an unreadable cache must never clear
|
|
250
|
+
logger.debug("Could not read a verdict", exc_info=True)
|
|
251
|
+
stale = None
|
|
252
|
+
if stale:
|
|
253
|
+
judged.add(index)
|
|
254
|
+
return judged
|
|
255
|
+
|
|
256
|
+
def _restore_unjudged(
|
|
257
|
+
self,
|
|
258
|
+
messages: list[AnyMessage],
|
|
259
|
+
before: dict[int, ToolMessage],
|
|
260
|
+
judged: set[int],
|
|
261
|
+
) -> None:
|
|
262
|
+
"""Put back every result the base class touched without a stale verdict.
|
|
263
|
+
|
|
264
|
+
The base class decides what to touch; this method is the veto. A result
|
|
265
|
+
is restored byte-for-byte, so a message the model never judged is
|
|
266
|
+
indistinguishable from one it scored as still needed.
|
|
267
|
+
|
|
268
|
+
Identity here is *position*, not ``tool_call_id``: the base class rewrites
|
|
269
|
+
``messages[idx]`` in place, so the index is the only handle that survives
|
|
270
|
+
its edit, and the id is not unique across a resumed session. Restoring is
|
|
271
|
+
a no-op when the bytes are already right.
|
|
272
|
+
"""
|
|
273
|
+
for index, msg in enumerate(messages):
|
|
274
|
+
if not isinstance(msg, ToolMessage):
|
|
275
|
+
continue
|
|
276
|
+
if index in judged:
|
|
277
|
+
continue
|
|
278
|
+
if index in before:
|
|
279
|
+
# Restore the clearing metadata too: a retained result must be
|
|
280
|
+
# eligible for a later verdict or the default fallback.
|
|
281
|
+
messages[index] = before[index]
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
__all__ = [
|
|
285
|
+
"MAX_AGE_SECONDS",
|
|
286
|
+
"UNSAVED",
|
|
287
|
+
"VIRTUAL_PREFIX",
|
|
288
|
+
"OffloadingToolUsesEdit",
|
|
289
|
+
"VerdictToolUsesEdit",
|
|
290
|
+
"cleared_dir",
|
|
291
|
+
]
|