Commit Graph

28266 Commits

Author SHA1 Message Date
Teknium 276685766e refactor(run_agent): repoint file-mutation helper test imports to agent.tool_dispatch_helpers 2026-09-02 13:29:40 -07:00
Teknium 0ab2e9672c refactor(run_agent): extract VisionMessagePrepMixin and ReasoningParamsMixin 2026-09-02 13:29:40 -07:00
Teknium 9576b49c0b refactor(run_agent): extract TurnFacadeMixin (run_conversation/chat admission wrapper) 2026-09-02 13:29:40 -07:00
Teknium f0526e6d74 refactor(run_agent): extract CompressionFacadeMixin; collapse 10 more lazy forwarders 2026-09-02 13:29:40 -07:00
Teknium 53161ba6f4 refactor(run_agent): unify _emit_status/_emit_warning and _buffer_status/_buffer_vprint pairs 2026-09-02 13:29:40 -07:00
Teknium 45e88aff38 refactor(run_agent): re-wrap comment blocks left with dangling fragments 2026-09-02 13:29:40 -07:00
Teknium 1e778ae7c6 refactor(run_agent): re-wrap compacted docstrings, restore lost issue-ref rationale 2026-09-02 13:29:40 -07:00
Teknium e564e60a3d refactor(run_agent): extract SessionPersistenceMixin (agent/session_persistence.py); _DB_PERSISTED_MARKER sourced from context_compressor 2026-09-02 13:29:40 -07:00
Teknium 81abe4799a refactor(run_agent): extract InterruptControl/TurnExplainers/ActivityTracking/RateLimitCredits mixins 2026-09-02 13:29:40 -07:00
Teknium ce6b4d1e16 refactor(run_agent): extract ApiErrorSummaryMixin (agent/api_error_summary.py) 2026-09-02 13:29:40 -07:00
Teknium d69afde2d3 refactor(run_agent): drop unused logger in api_request_hooks 2026-09-02 13:29:40 -07:00
Teknium 64cc8cf0d3 refactor(run_agent): extract ApiRequestHooksMixin (agent/api_request_hooks.py) 2026-09-02 13:29:40 -07:00
Teknium c274125690 refactor(run_agent): extract StreamDeliveryMixin and StatusOutputMixin 2026-09-02 13:29:40 -07:00
Teknium fd54e7faec refactor(run_agent): extract ClientLifecycleMixin (agent/client_lifecycle.py) + agent/lazy_forward.py 2026-09-02 13:29:40 -07:00
Teknium 5423336e8c refactor(run_agent): collapse 39 lazy forwarder methods into _forward() descriptors; __init__ forwards via locals() 2026-09-02 13:29:40 -07:00
Teknium 1c21f09558 refactor(run_agent): route default-header chain -> _ROUTE_DEFAULT_HEADERS dispatch table 2026-09-02 13:29:40 -07:00
Teknium 7048763e99 refactor(run_agent): unify non-vision message preprocessors, drop dead forwarders 2026-09-02 13:29:40 -07:00
Teknium 30e060211c refactor(run_agent): compact verbose comments and docstrings in AIAgent facade
Hand-reviewed compaction only; code is AST-identical. Rationale-bearing
sentences kept (issue-ref rationale restored in a follow-up commit).
2026-09-02 13:29:40 -07:00
Teknium c5452be851 refactor(agent): tests — drop unused imports in test_model_tools 2026-09-02 13:29:39 -07:00
Teknium bdf9ebf92c refactor(agent): model_tools — lift _active_model_config out of _resolve_active_context_length 2026-09-02 13:29:39 -07:00
Teknium 531eb9b561 refactor(agent): model_tools — _CallIds dataclass carries tool-call identity through guards, execution and hooks 2026-09-02 13:29:39 -07:00
Teknium 7afd702505 refactor(agent): toolsets — flatten get_toolset alias branch, extract _plugin_platform_bundle, share _display_alias 2026-09-02 13:29:39 -07:00
Teknium 57615ca981 refactor(agent): toolsets — derive coding and hermes-api-server tool lists from core via _core_without 2026-09-02 13:29:39 -07:00
Teknium d533aaaf2d refactor(agent): model_tools — split get_tool_definitions memo key into _tool_defs_cache_key; single return path 2026-09-02 13:29:39 -07:00
Teknium aab7a9b9b0 refactor(agent): model_tools — extract _execute_tool and _apply_transform_tool_result_hook; handle_function_call is now a linear pipeline 2026-09-02 13:29:39 -07:00
Teknium 2c783c8782 refactor(agent): model_tools — extract _pre_dispatch_guards (plugin pre_tool_call + ACP edit approval) from handle_function_call 2026-09-02 13:29:39 -07:00
Teknium fcb5c64101 refactor(agent): model_tools — extract argument type coercion into tools/arg_coercion.py (re-exported; logger name preserved) 2026-09-02 13:29:39 -07:00
Teknium 73163e3acb refactor(agent): model_tools — extract _dispatch_bridge_tool from handle_function_call; pin bridge dispatch with tests 2026-09-02 13:29:39 -07:00
Teknium 4666479e70 refactor(agent): model_tools — toolset enable/disable via one _apply_toolset_selection; dynamic schema rewrites as a dispatch table 2026-09-02 13:29:39 -07:00
Teknium cf1ecfde1d refactor(agent): toolsets — build TOOLSETS via _ts/_bundle helpers; share _CODING_TOOLS with hermes-acp 2026-09-02 13:29:39 -07:00
Teknium 6f9af97117 refactor(agent): toolsets — drop __main__ demo and test-only resolve_multiple_toolsets 2026-09-02 13:29:39 -07:00
Teknium b3e41128ff refactor(agent): share predicates, truncation and the timeout ladder
- User-turn predicates reuse _is_context_summary_message (single detection path).
- _serialize_for_summary hoists the shared head/tail truncation.
- __init__ initialises per-session state via _reset_session_compaction_state.
- Timeout cooldown ladder (60/300/900s) is one module helper used by both
  record_timeout_failure and the summary failure path; module-level so a real
  method bound onto a stub compressor still exercises it.
2026-09-02 13:29:38 -07:00
Teknium 16308d32b9 refactor(agent): model_tools — compact handle_function_call (shared _emit for post_tool_call, single dispatch closure) and coercion/context-gate docs 2026-09-02 13:29:38 -07:00
Teknium b2717f4f4c refactor(agent): restore rationale comments lost in the docstring compaction
Hunk-by-hunk audit of the compaction commit found 14 dropped WHY/invariant
statements (route-pin scope, persistence-marker sweep failure mode, stamp
asymmetry, reasoning-replay boundary, size-class parity with preflight,
small-context floor cap, tail-anchor ordering rules, defer-baseline backstops).
Each is restored as a compact 1-3 line comment at its anchor.
2026-09-02 13:29:38 -07:00
Teknium 2cc0d85bdc refactor(agent): model_tools — shared _find_tool/_drop_tool for dynamic-schema rewrites; compact async-bridge and cache docs 2026-09-02 13:29:38 -07:00
Teknium ea090ccb62 refactor(agent): unify durable-state helpers, session reset and tail-cut walks
- Nine near-identical durable-row getters/setters -> _durable_read/_durable_write
  (also used for parent-lineage lookups in on_session_start).
- on_session_reset/on_session_end share _reset_session_compaction_state.
- _find_tail_cut_by_tokens: the two backward token walks become one _walk_back
  (randomized parity vs. the previous version: 1500 transcripts identical).
- _strip_context_summary_handoff_message: one _unwrapped() helper for all paths
  (parity: 1296 content shapes identical).
- ruff SIM102/SIM108/SIM114 collapses.
2026-09-02 13:29:38 -07:00
Teknium 7c780631f9 refactor(agent): compact toolsets.py helpers — shared registry accessor, unified alias display-name walk, tightened docs 2026-09-02 13:29:38 -07:00
Teknium 4a64d42f9b refactor(agent): extract micro-compaction into agent/micro_compaction.py
The 15 rolling micro-compaction methods (cursor resolution, exchange
serialization, one-exchange summarization, defrag, splice, DB sync, telemetry)
move verbatim into MicroCompactionMixin, mixed into ContextCompressor
(MRO: ContextCompressor -> MicroCompactionMixin -> ContextEngine). Origin
constants and call_llm are imported lazily so tests patching
agent.context_compressor.X still apply; logger name parity is kept.
2026-09-02 13:29:38 -07:00
Teknium 64576a34f8 refactor(agent): decompose _generate_summary and the compress() abort path
- _generate_summary(): prompt assembly lifted into _build_summary_prompt, the
  exception path into _on_summary_failure; the two identical main-model retry
  branches are merged behind a reason lookup.
- compress(): terminal summary-failure abort classes are table-driven via
  _TERMINAL_SUMMARY_FAILURES (same precedence, log text and telemetry class;
  flag reads stay lazy so __new__-built test doubles keep working).
2026-09-02 13:29:38 -07:00
Teknium 8b84f8debe refactor(agent): dispatch-table the tool-result summarizer
_summarize_tool_result_unguarded routed on tool_name through ~20 if-branches; each
branch is now a small _sum_* function in _TOOL_RESULT_SUMMARIZERS with the generic
fallback unchanged. Output verified byte-identical against the previous version
across 1288 name/args/content combinations.
2026-09-02 13:29:38 -07:00
Teknium cfb234c54c refactor(agent): extract _scan_window_handoffs from compress(); drop unused imports
The in-transcript handoff rehydration scan (previous-summary rebuild, zero-user
provenance, merged-handoff unwrap, tail_start advance) moves into
ContextCompressor._scan_window_handoffs returning a _HandoffScan dataclass;
compress() keeps the rollback snapshot semantics unchanged.
2026-09-02 13:29:38 -07:00
Teknium 3a2eceabc8 refactor(agent/compression): remove dead memory-containment helpers; fold codex skip-log ladder
- delete _cached_prompt_reflects_builtin_memory + _builtin_memory_prompt_snapshot
  (zero callers since the commit site moved to byte-equality; the only test
  reference asserts their ABSENCE from the commit window)
- delete CompressionExecutorSaturatedError (never raised or caught anywhere)
- _compress_context_via_codex_app_server: three near-identical skip branches
  collapse into one skip_reason + single log line (same message text)
2026-09-02 13:29:37 -07:00
Teknium 12be763de0 refactor(agent): compact context_compressor comments/docstrings to invariants
Hand-reviewed compaction: non-obvious rules, ordering constraints, invariants,
failure modes and WHY are kept in 1-3 line form; narrative, issue-number history
and code restatements are dropped.
2026-09-02 13:29:37 -07:00
Teknium 7e3cef7d87 refactor(agent/compression): extract candidate rejection ladder from compress_context
_candidate_rejected(): compressor abort, no-progress, empty transcript and
superseded-attempt checks in their original order; caller handles the
shared release + unchanged-return. Aborted-branch try/finally collapsed
(the finally only released the lease, which the caller now does).
2026-09-02 13:29:37 -07:00
Teknium 0ea4c7963a refactor(agent/compression): extract post-commit boundary tail of compress_context
- _finish_compaction_boundary(): parent label clear, context-engine + memory
  provider notifications, compression-count warning, session:compress hook,
  usage re-arm, file/skill dedup reset (zero back-refs; returns rough estimate)
- _warn_summary_or_aux_fallback(): once-only summary/aux-model warnings
compress_context 794 -> 653 lines; bodies moved verbatim.
2026-09-02 13:29:37 -07:00
Teknium 01d16451f7 refactor(agent/compression): extract commit-phase helpers out of compress_context
- _fold_todo_snapshot(): stale-snapshot strip + live todo fold into the tail
- _rebuild_system_prompt_at_boundary(): tool refresh + byte-equal keep-prompt
- _salvage_or_refuse_grown_transcript(): commit-site anti-growth guard
- _publish_rotated_compaction(): parent flush, child publish, id re-point,
  goal/heartbeat/loop/title carry-over
- old_session_id is now an explicit Optional local instead of locals().get()
compress_context 1181 -> 794 lines; bodies moved verbatim.
2026-09-02 13:29:37 -07:00
Teknium cbd709124f refactor(agent/compression): extract pre-summary phases of compress_context
- _adopt_grown_durable_parent(): rotation-only durable-snapshot adoption
- _pre_compress_memory_context(): provider on_pre_compress / checkpoint gate
- _resolve_compress_call(): compress() + signature-filtered kwargs
- _run_summary_dispatch(): progress hook, stream deadline, interrupt guard
compress_context 1359 -> 1181 lines; bodies moved verbatim.
2026-09-02 13:29:37 -07:00
Teknium 42c41dfcff refactor(agent/compression): extract lease acquisition and lifecycle out of compress_context
- _CompactionLifecycle: the one-shot terminal status edge (was a nonlocal closure)
- _CompressionLease: holder/watermark/ttl + refresher, holder-only release,
  fence lock-setup bracket, release() (was 4 nested closures + 9 locals)
- _acquire_compression_lease(): the 190-line lock acquisition ladder
- _adopt_if_parent_rotated(): late-contender adoption check
compress_context 1767 -> 1359 lines; bodies moved verbatim.
2026-09-02 13:29:37 -07:00
Teknium 852f2a02d8 refactor(agent/compression): unify repeated abort-path snippets in compress_context
- _existing_system_prompt: 21 copies of cached-or-rebuild prompt
- _emit_aborted_attempt_telemetry: 11 copies of aborted/aborted telemetry
- _restore_messages_snapshot: 4 copies of deepcopy rollback
- _restore_prune_rearm_tokens: 3 copies of prune-runway restore
2026-09-02 13:29:37 -07:00
Teknium 682d48c48a refactor(agent/compression): compact comments and docstrings in conversation_compression (AST-identical) 2026-09-02 13:29:37 -07:00