Commit Graph

28271 Commits

Author SHA1 Message Date
Teknium 3e38ef2126 refactor(cli): drop unused browser_connect imports; unify Alt+Enter/Ctrl+J newline handlers; collapse 8 trivial if/else forms
Also restores the reload-mcp auto-reload rationale in _confirm_and_reload_mcp's docstring.
2026-09-02 13:29:43 -07:00
Teknium 0ccf6714be refactor(cli): drop zero-ref startup-fast wrappers and _build_provider_choices from main.py 2026-09-02 13:29:43 -07:00
Teknium 57b2dfdf0e refactor(cli): decompose HermesCLI.run() (3433 -> 384 LOC) into _tui_* methods
70 nested closures (every prompt_toolkit key handler and handler factory, the
clarify/sudo/secret/approval/model-picker/command-palette/stash display
renderers, hint/placeholder/spinner callables, process_loop, spinner_loop,
_signal_handler, wake-startup) become HermesCLI._tui_* methods; run() only
binds them (kb.add(...)(self._tui_x)). The run() locals they closed over are
published on self at their original binding sites (_tui_multiline_shortcuts,
the four paste list-cells; process_loop reads self._app). Then four zero-
back-ref prologue regions become _tui_print_startup, _tui_init_run_state,
_tui_build_key_bindings -> kb and _tui_build_layout(kb) -> (layout, style).

All moved bodies verified AST-identical modulo cli_ref->self and the free-var
rewrites; unresolved-free-name check on every new method is empty. Source-
inspection tests repointed: getsource(run) -> _tui_process_loop, AST lookup of
handle_enter -> _tui_handle_enter.
2026-09-02 13:29:43 -07:00
Teknium 0227cf7d9c refactor(cli): unify the 3 copies of the TUI panel helpers into module-level functions
_panel_box_width/_wrap_panel_text/_append_panel_line/_append_blank_panel_line
were defined identically inside run(), _get_approval_display_fragments and
_get_slash_confirm_display_fragments (the latter two with whitespace-preserving
wrap and different width defaults). One module-level set; the two fragment
renderers alias _wrap_panel_text_keep_ws and pass their width defaults explicitly.
2026-09-02 13:29:42 -07:00
Teknium 9d745e3162 refactor(cli): replace the 93-branch slash-command if/elif chain with convention-based dispatch
process_command resolves the canonical command (hermes_cli/commands.py registry)
to a handler via _slash_handler(): a 44-entry _SLASH_DISPATCH table for the
irregular cases (no-arg handlers, differently named methods, /exit and /update
return-value adapters) and the _handle_<name>_command(cmd) naming convention for
the other 47. Inline branch bodies became small _cmd_<name> methods; the
else-fallthrough (quick_commands -> plugins -> bundles -> skills -> prefix
expansion -> unknown) became _process_unregistered_slash. Pre-dispatch side
effects (pre_command hook, pending-resume disarm) and the False-exits-REPL
contract are unchanged. Also unifies the three random-tip blocks into
_print_random_tip and the repeated arg parsing into _slash_args; removes two
zero-reference helpers (_run_curses_picker, _try_launch_chrome_debug).

Parity guard: tests/cli/test_slash_dispatch_table.py asserts every command of
the old chain resolves and that no other registry command silently gained a
handler.
2026-09-02 13:29:41 -07:00
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