11 Commits

Author SHA1 Message Date
686f6c61
b986aabcce fix(desktop): render /new sessions as siblings not branches (#99648)
Salvage of PR #99679 by 686f6c61, rebased onto current main.

/new and idle/daily resets keep parent_session_id for durable lineage,
and the sidebar's flattenSessionsWithBranches nested on that field
alone — so a platform's chats collapsed into one growing nested chain
of branches even though none of them were /branch forks. The backend
records the distinction on disk already (model_config._reset_from vs
_branched_from, gateway/session_recovery.py:433) but list payloads
strip model_config before any UI can read it.

- forkParentId(): nest only genuine forks — _branched_from wins, a
  _reset_from parent means top-level sibling, legacy/optimistic rows
  with only parent_session_id keep nesting.
- _session_row_dict lifts _reset_from/_branched_from out of
  model_config so compact list rows (which strip that heavy field)
  carry the distinction; tui_gateway project-tree rows project the two
  markers too.
- Optimistic desktop /branch rows stamp _branched_from so the flat
  render stays correct before the authoritative row arrives.

Disk lineage is unchanged. Tests: a _reset_from chain renders flat,
a genuine fork still nests beside a reset sharing the same parent,
and list_sessions_rich promotes both markers (also under
compact_rows=True).

Closes #99648.
2026-09-26 17:25:51 -05:00
teknium1
ae1b5d79b2 fix(sessions): one-shot runs get a distinct oneshot source that pickers hide
`hermes chat -q`/`--oneshot`/`-Q` and `hermes -z` (both set HERMES_SINGLE_QUERY_SESSION=1)
persisted their session as `cli` — and, before the first pass, as the inherited
`tui`/`desktop` transport label — so finite automation runs sat in the TUI, Desktop and
dashboard session pickers next to real conversations (#112550).

- run_agent._session_source_for_agent: a single-query run whose source is empty (or an
  inherited UI transport label without an explicit --source) resolves to `oneshot`; the
  platform gate keeps delegate children (`subagent`) untouched; an explicit `--source`
  (HERMES_SESSION_SOURCE_EXPLICIT=1 from main.py) still wins.
- hermes_state_sessions.INTERNAL_LISTING_SOURCES = (kanban, tool, oneshot) replaces the
  three copied `["kanban", "tool"]` literals (tui_gateway session.list, console
  `sessions list`/`stats`, in-chat /sessions), and the Desktop project tree / sidebar
  recents and the dashboard automation set exclude `oneshot` too.
- `hermes -c` / `--resume latest` still chain on the previous one-shot (PR #105957's
  documented flow): the CLI MRU lookup matches the cli family {cli, oneshot} and
  search_sessions accepts several sources; one-shots keep stamping their launch cwd so the
  workspace-scoped lookup keeps working.
- Compression child: the rotated child is published with the PARENT ROW's persisted source
  instead of bare agent.platform, so a `--source tool` / `oneshot` / inherited `kanban`
  session does not degrade to a picker-visible `cli` row after compaction.
- Docs: sessions source table (+ oneshot/kanban/tool rows, compression note) and the
  `--source` flag reference (explicit flag always stored as given).
2026-09-17 09:06:59 -07:00
yoniebans
a30ccdbeab fix(tui_gateway): keep opportunistic writes off read-only foreign handles
Two write paths were still reachable through the now read-only foreign-profile
handle (reported by @ehz0ah on #110718): the repo-root backfill in
_discover_repos_payload raised and was swallowed per RPC, silently dropping the
persistence; the Bot Chat unarchive in session.list's exact-title lookup failed
the RPC with error 5006. Backfill now skips on read-only handles (that
profile's own gateway backfills on its refreshes); the unarchive escalates to a
short-lived registry writer for the rare recoverable-archive case.

Reported-by: ehz0ah
2026-09-14 05:28:46 -07:00
Teknium
eeb7671e69 simplify(compat): hermes_cli small facades — drop 7 re-exports/aliases (+relay_runtime alias module), repoint 12 callers/tests 2026-09-03 13:05:57 -07:00
Teknium
e83816a4d1 review-fix(comments): restore lost #NNNN rationale comments across non-test source (mechanical sweep, condensed, code unchanged)
For each issue anchor present in BASE 63279301bc non-test .py and absent on HEAD, the BASE comment/docstring block was re-attached at the HEAD location of the code it explained (matched by the distinctive code line / enclosing def). Sentences already covered by an existing HEAD comment were deduped; the issue number always survives. Insert-only: no code lines changed.
2026-09-03 09:44:26 -07:00
Teknium
fd1a0594c1 refactor(tui_gateway): X2 wave3 — compute_host guarded frame handlers + session-build split, groups profile/kwargs folds, project_tree placement/auto-bucket compaction, projects row/policy folds, entry+oauth plumbing trims (2653->2437 LOC) 2026-09-03 04:15:06 -07:00
Teknium
b279e45d7c refactor(tui_gateway): entry discovery spawn helper, row/kwargs table tightening
- entry: _spawn_discovery + logged _mcp_startup_call replace the two duplicated
  start_background_mcp_discovery try/except blocks (same log levels + messages);
  docstrings/comments compacted keeping every signal/thread WHY.
- methods_projects/agent_callbacks: _project_tree_row and preview kwargs tightened.
Goldens identical; WIRE-PARITY-OK.
2026-09-03 00:05:29 -07:00
Teknium
de227bdc34 refactor(tui_gateway): final compaction pass on r3-36 group G
- mcp_oauth_sessions: lift the probe+rollback block out of _worker (_probe_with_rollback).
- project_tree: lane group built from a field table; stamp_profile/_lane_key/_disambiguate
  flattening. methods_projects: policy loader + scan loop tightened. agent_callbacks:
  preview-history filter via _PREVIEW_HISTORY_ROLES. Blank-line squeeze after in-body
  lazy imports (AST-identical). All goldens identical; WIRE-PARITY-OK.
2026-09-02 23:54:51 -07:00
Teknium
aef127ad46 refactor(tui_gateway): projects mutator table, mcp_startup call helper, kwargs table in agent_callbacks
- methods_projects: update/add_folder/remove_folder/set_primary handlers registered from a
  _PROJECT_MUTATORS table (same @method names, same 5062/5063/5061 mapping); _pick() for
  params->kwargs; old-vs-new RPC golden (27 calls incl. error paths) identical.
- entry: _mcp_startup_call() replaces 5 lazy import+try/except ladders on hermes_cli.mcp_startup
  (tests monkeypatch mcp_startup module attrs — still resolved at call time).
- agent_callbacks: _background_agent_kwargs built from key tables; drop unused _registry.
- docstring compaction (module docstrings <= 8 lines, WHYs kept).
WIRE-PARITY-OK.
2026-09-02 23:44:18 -07:00
Teknium
79d0d3b600 refactor(tui_gateway): compact project_tree/methods_projects/agent_callbacks/entry/mcp_oauth_sessions (-16%)
- project_tree: split build_tree (207 LOC) into _auto_buckets/_home_project phase helpers;
  _field() replaces 9 '(x.get(k) or "").strip()' ladders; _project_node takes wire-shaped
  **flags; drop unused placement 'repo_path' and _strip_trailing_sep; _FolderIndex/
  _project_for_session collapsed. Old-vs-new golden (67 synthetic build_tree runs) identical.
- methods_projects: _project_ok/_path_param unify 4 handler tails; _project_tree_row via
  dict comprehensions; discovered-cache read via contextlib.nullcontext; policy loader
  helpers. Golden over rows/policy/junk predicates identical.
- agent_callbacks: subagent mirror dispatch on a delta table; drop _render_personality_prompt
  (single caller); getattr shorthand in _background_agent_kwargs.
- entry: _write_or_exit unifies 3 write-fail exits; suppress(); heartbeat/sweep start loop.
- mcp_oauth_sessions: suppress(), gc/listener/redirect compaction, docstrings.
WIRE-PARITY-OK; tests green.
2026-09-02 23:24:24 -07:00
Teknium
646aae4ba6 refactor(tui): move the projects RPC surface (workspaces, repo discovery, sidebar tree) out of server.py into methods_projects.py 2026-09-02 14:09:13 -07:00