Commit Graph

5219 Commits

Author SHA1 Message Date
Siddharth Balyan
3e00a356a4 fix(mcp): one reader for mcp_servers.<name>.enabled (#119567)
The `enabled` key had four parsers. The MCP client (`_parse_boolish`) read
`enabled: 0` as on; the toolset resolver and editor (`_parse_enabled_flag`)
read it as off. The server list (`summarize_server`, `/api/mcp/servers`) read
any non-`False` value as on, so `enabled: "false"` showed on while the agent
skipped it. The catalog and `hermes mcp list` accepted only true/1/yes, so
`enabled: on` showed off while the server ran.

`tools/mcp_tool_common.py::mcp_server_enabled` is now the only reader, and
every surface calls it. `_parse_boolish` treats YAML numbers by truthiness
(0 off, other numbers on). Everything else keeps the client's semantics:
the off words are off, absent / null / junk stay on, with the existing
warning for junk.

The desktop MCP page mirrors the rule in `serverEnabled`
(`apps/desktop/src/lib/mcp-servers.ts`). One case table
(`mcp-enabled-cases.json`) drives the Python invariant test and the vitest
test, so the page and the runtime cannot drift apart again.
2026-09-22 22:00:24 +00:00
Siddharth Balyan
eb5d735e9a Application-backed MCP servers: live endpoint per attempt, tools follow app liveness, errors and the tool catalog say why (NS-943) (#119050)
* feat: expose interactive and live endpoint facts

* feat: hydrate application-backed MCP liveness

* feat: export interactive session fact

* fix: classify unsupported declared hosts

* test(mcp): a runtime file without a token connects without an Authorization header

* fix(mcp): server_json liveness fields default to http/token/pid; an invalid declaration degrades to static instead of failing the server task

* fix(mcp): a connected server is offerable regardless of the interactive-session rule; the rule only shapes the not-connected sentence

* test(mcp): follow main's ToolSearchConfig fields and patch _bump_server_error at its origin module
2026-09-22 17:54:42 +05:30
Siddharth Balyan
4094ab610d hermes_platform.resolver: locate/inspect/probe tiers, AppResolver, gh lookup migrated (NS-921) (#118065)
* feat(platform): resolver core with locate/inspect/probe tiers and ordered candidates

Every resource lookup needs one result shape and one cost contract. `locate` reads
metadata only, `inspect` may open files and call OS APIs in-process, `probe` is fresh
and the only tier that may spawn or connect. `Resolution.candidates` keeps probe order
so fan-out consumers can try every present binary.
Linear NS-921.

* feat(platform): AppResolver over AppDef with plist, PE, registry, and server.json sources

Desktop apps need presence, version, and liveness as separate observations. The runtime
file's bearer token is parsed, used for one request, and discarded inside the probe;
no public type carries it. Endpoints are accepted only when loopback with a numeric port.

* refactor(copilot): gh candidates through locate_command and the Homebrew table

First consumer of the resolver. The gh token probe still tries every present binary in
order; the allowlist loses its two copilot_auth rows.

* feat(platform): availability() over an application declaration

locate() + inspect() only, never probes; the fail-closed _version in
app.py treats a vendor's plist/PE/registry entry as untrusted input.
Salvaged from PR #118122; reads any object with requires_app,
min_version, app_for(os) — nothing here imports the MCP catalog.

* feat(platform): application declarations parsed into AppDef per OS

The parser slice of PR #118122's catalog manifest, re-homed as a
catalog-free module: whoever owns an MCP server declares the app it
fronts per OS and what it needs, and registers it here. Stdlib +
hermes_platform.resolver only. register/lookup/clear are the one seam
the MCP check_fn and the skill gate both read.

* feat(mcp): check_fn honours a registered application declaration

_make_check_fn ANDs the declared app's availability into the
connection-alive check; with nothing registered for the server the
behaviour is the pre-PR3 connection check. Provenance is explicit
registration, not endpoint matching. Returns a plain bool: the registry
caches bool(fn()).

* feat(skills): requires_apps gate through registered declarations

Offer-time filter beside environments:; names resolve through
hermes_platform.declaration, an unknown name hides the skill (fail
closed). The disk snapshot carries requires_apps and the fast path
re-evaluates it (snapshot version bumped to 3): app presence is a host
fact that changes without SKILL.md changing.

* docs: application declarations page

The plugin-facing schema reference: app: and requires: blocks,
availability() states, and the two gates that read the registry.
Registered under Extending > Plugins in the docs sidebar.

* test(platform): declaration parser, availability, gates

The PR3 app-block tests re-homed off the catalog: fixtures are dicts
passed to parse_declaration, the check_fn gate keys on explicit
registration (not endpoint matching), and the import-hygiene probe now
covers hermes_platform.declaration and resolver.availability.
2026-09-22 17:08:30 +05:30
Siddharth Balyan
de5bb5cf13 Merge pull request #117863 from NousResearch/sid/ns-920-hermes-platform-host
hermes_platform.host: one machine-facts package, WSL/container predicates, NVIDIA ARM64 SoC recognizer (NS-920)
2026-09-22 16:49:01 +05:30
kshitijk4poor
058f817aad fix(computer_use): _computer_use_cfg reads config through load_config again
b5a9f44829 switched the shared computer_use config reader to
load_config_readonly. That reader also serves the daemon-launch paths
(overlay flag, Wayland child env), and tests/computer_use pins
hermes_cli.config.load_config as the seam at 13 sites; the deepcopy it
saves is noise next to an 80-500 ms capture. The ledger half of that
commit stays.

PROOF: tests/computer_use/test_cua_wayland_env.py and
test_cua_no_overlay.py::test_linux_x11_explicit_false_overrides_auto_detect
red on the previous head, green now (macOS-only
test_serve_process_disables_overlay fails identically on origin/main).
2026-09-22 16:16:30 +05:30
kshitijk4poor
ed6b55d1d8 fix(skill_ledger): blob GC keeps unreferenced blobs younger than an hour
`snapshot_paths` / `_store_blob` write blobs OUTSIDE `_ledger_lock`, seconds
before the row that references them is appended. Since `_maintain_size` now
runs `gc_blobs()` on any append that trims, a sweep in another process during
that window deleted the in-flight capture: its row then landed with sha256
values `read_blob` cannot resolve and `rollback_entry` failed.

`_gc_blobs_locked` now skips any unreferenced blob file (incl. `.tmp-*`) whose
st_mtime is newer than `_BLOB_GC_GRACE_SECS = 3600`; no new config key.
Docs (curator.md) and the `gc_blobs` docstring say so.

PROOF: probes/s5_final_inflight_blob.py before -> `P1 blob survives P2's
sweep: False ... read_blob: None`; after -> `True ... read_blob: b'P1
in-flight skill file'`. test_concurrent_appends_never_lose_a_middle_row gained
a fresh + 2h-aged unreferenced blob pair: red with the grace set to 0 (fresh
blob deleted), green at 3600 (aged deleted, fresh kept). ruff clean,
check-windows-footguns --all clean, run_tests.sh ledger + AX files 29 passed.
2026-09-22 16:16:30 +05:30
kshitijk4poor
2866bc6dff perf(skill_ledger): skip the compaction rewrite when nothing changed
Append-time `_delta` already strips unchanged paths, so on any ledger written
since it landed `compact_ledger` parsed every row and then `_rewrite_ledger`
wrote the identical file (up to 5 MB) on every maintenance sweep. Compare the
compacted payload with the raw bytes and return `(kept, len(raw), len(raw))`
without touching the file when they are equal; return semantics are unchanged.

PROOF: probe (probes/S5_compact_noop.py) with `os.replace` wrapped in a counter —
first sweep over 5 legacy fat rows: (5, 1545, 585), 1 os.replace; second sweep on
the now-compact file: (5, 585, 585), 0 os.replace. Existing ledger tests green
(29 passed in tests/tools/test_skill_ledger.py + test_computer_use_ax_walk_bound.py).
2026-09-22 16:16:30 +05:30
kshitijk4poor
c86607124f fix(skill_ledger): hold .locks/ledger.lock across append + sweep and the CLI compact/GC path
`_maintain_size()` now runs inside every `append_entry`, and `compact_ledger`/
`_trim_oldest` do read-bytes -> `os.replace` over the ledger with no cross-writer
lock, so a concurrent appender's O_APPEND write landing on the replaced inode was
silently lost — and `gc_blobs` then deleted that row's blobs. `_ledger_lock()`
(same `skill_file_lock` idiom as `_skill_mutation_lock`; fcntl/msvcrt, re-entrant,
no-op where neither exists) is held across the append AND the sweep, and inside
`compact_ledger`/`_trim_oldest`/`gc_blobs` for the `curator ledger --compact` path.

PROOF: tests/tools/test_skill_ledger.py::test_concurrent_appends_never_lose_a_middle_row
forces writer B to append between writer A's sweep read and its os.replace; every
row must be present or counted as trimmed. Green 2/2 (3.5 s). With `_ledger_lock`
made `contextlib.nullcontext()`: red 4/4 ("none silently lost").
2026-09-22 16:16:30 +05:30
kshitijk4poor
99ced8117c refactor(skill_ledger): name the 5 MB ledger default and drop the dead <= 0 branch
Hoist the sole remaining `5 * 1024 * 1024` literal to `_DEFAULT_LEDGER_MAX_BYTES`
(fold-3 already collapsed the docstring/except copies into `_skills_cfg`), and
spell `_trim_oldest`'s early return as `if not dropped` — `dropped` is a length
difference and can never be negative. The `if lines else b""` payload guard now
lives in the shared `_rewrite_ledger` and stays: `compact_ledger` can legitimately
reach it with an empty row list.

PROOF: scripts/run_tests.sh tests/tools/test_skill_ledger.py
tests/tools/test_computer_use_ax_walk_bound.py green, no assertion changes;
`_max_ledger_bytes()` returns 5242880 via real import; ruff + footguns clean.
2026-09-22 16:16:30 +05:30
kshitijk4poor
8b41224bfc refactor(computer_use): capture() derives the AX-walk bound from the args it sends
Drop the `_ax_max_elements_sent` side channel, its `getattr` default and the
`contextlib.suppress(Exception)` around the lazy `cua_backend` import:
`_cua_configured_ax_max_elements()` already swallows config errors, and the
same lazy import is bare in `_resolve_capture_windows`. `capture()` now reads
`_gws_args().get("max_elements", 0)` directly (one more cached
`load_config_readonly` hit); the vision lane still reports 0.

PROOF: tests/tools/test_computer_use_ax_walk_bound.py 5 passed; hardcoding
`ax_max_elements=0` in capture() turns `stub.capture("ax").ax_max_elements == 350`
red (observed), restored green. ruff clean; check-windows-footguns clean; real import ok.
2026-09-22 16:16:30 +05:30
kshitijk4poor
8268fc7810 refactor(skill_ledger): one _skills_cfg reader behind ledger_enabled and _max_ledger_bytes
Both gates repeated the try / lazy-import / cfg_get(load_config_readonly(), "skills",
…) / debug-log / default shape. `_skills_cfg(key, default)` owns it; the callers keep
their bool()/int() coercion and defaults. Still a lazy import of the module attribute,
so tests that monkeypatch `hermes_cli.config.load_config_readonly` keep taking effect.

PROOF: tests/tools/test_skill_ledger.py 23 passed unchanged (incl.
test_config_gate_off_no_ledger_writes); mutation — `_skills_cfg` returns the default
without reading config → test_config_gate_off_no_ledger_writes,
test_auto_compact_triggers_at_threshold, test_trim_oldest_when_still_over_cap fail.
2026-09-22 16:16:30 +05:30
kshitijk4poor
7b35a5a6b2 refactor(skill_ledger): one _rewrite_ledger tail for trim and compact
`_trim_oldest` and `compact_ledger` each carried the same join → `.<op>.tmp`
→ write_bytes → os.replace tail. Factor it into `_rewrite_ledger(path, lines:
List[bytes], op) -> bytes` at the bytes boundary (compact encodes its str rows
before the call and keeps returning `len(data)`); tmp naming per op is preserved.

PROOF: tests/tools/test_skill_ledger.py 23 passed unchanged; mutation — helper
skips `os.replace` → test_auto_compact_triggers_at_threshold and
test_trim_oldest_when_still_over_cap fail, 21 pass.
2026-09-22 16:16:30 +05:30
kshitijk4poor
25d240da11 perf(config): ledger_enabled() reads the config read-only too
`ledger_enabled()` is the first call on every `append_entry`, and it still
paid `load_config()` (a deepcopy of the cached config) after the rest of the
append path had moved to `load_config_readonly()`. It only reads one key via
`cfg_get`, so the read-only load is safe. The one test that patches
`load_config` to turn the ledger off now patches `load_config_readonly` too.

PROOF: PYTHONPATH=<wt> import + `ledger_enabled()` → True;
scripts/run_tests.sh tests/tools/test_skill_ledger.py
tests/tools/test_computer_use_ax_walk_bound.py → 28 passed, 0 failed.
2026-09-22 16:16:30 +05:30
kshitijk4poor
dd6229fe11 fix(curator): ledger trim splits rows on the physical newline only
`_trim_oldest` used `str.splitlines()`, which also breaks on U+2028/U+2029/
U+0085. `append_entry` writes rows with `ensure_ascii=False`, so a row whose
evidence contains one of those code points was counted as two lines and
rewritten as two malformed physical lines — contradicting "lines in the
retained tail are never rewritten". Split on b"\n" (dropping the trailing
empty element), re-join with b"\n", and account sizes in bytes.

Sibling readers (`compact_ledger`, `gc_blobs`, `list_entries`) use the same
idiom pre-existing on main and are left for a follow-up.

PROOF: tests/tools/test_skill_ledger.py::test_trim_oldest_when_still_over_cap
gains one assertion (a U+2028 row survives a trim byte-for-byte); it fails
with the old `splitlines()` body ("At index 85 diff: b'\n' != b'\xe2'") and
passes with this change. 23 passed.
2026-09-22 16:16:30 +05:30
kshitijk4poor
76c3b0c735 fix(computer_use): the backend reports the AX-walk bound it actually sent
tool.py inferred 'walk capped' by re-reading cua's private config through
_cua_configured_ax_max_elements() — a leaky abstraction that also cost a
config load per capture. The backend now records the max_elements it put on
the get_window_state call and returns it on CaptureResult.ax_max_elements
(defaulted field, 0 = unbounded / vision); _capture_view compares
len(cap.elements) >= cap.ax_max_elements > 0 and the getattr guards go
since the field is always set. Hint text and line order unchanged.

PROOF: tests/tools/test_computer_use_ax_walk_bound.py 5 passed (hint tests
now build CaptureResult(ax_max_elements=bound)); the new
_ax_max_elements_sent assertion is red with cua_backend_capture.py
reverted to HEAD~1 ('AttributeError: ... no attribute _ax_max_elements_sent',
1 failed 4 passed). Probe: 200/200 -> capped hint + 'full ' dropped;
199/200 and 8/0 -> full tree promised. check-windows-footguns --all clean.
2026-09-22 16:16:30 +05:30
kshitijk4poor
559f7d170f perf(config): read-only config loads on the ledger append and capture hot paths
_max_ledger_bytes() runs on every ledger append (right after ledger_enabled()
already deep-copied the config) and _computer_use_cfg() now runs twice per
computer-use capture; neither mutates the result, so use
load_config_readonly() as hermes_cli/config.py documents for read-only hot
paths (skips the deepcopy, ~half the cache-hit cost). Tests that patched
load_config now patch load_config_readonly as well (test-only edit).

PROOF: real import under PYTHONSAFEPATH shows load_config() ==
load_config_readonly() (same dict shape; defaults 5242880 / 200 resolve);
tests/tools/test_skill_ledger.py + test_computer_use_ax_walk_bound.py +
test_skill_ledger_delta.py -> 39 passed, 0 failed.
2026-09-22 16:16:30 +05:30
kshitijk4poor
72ac9d2d1b refactor(curator): drop the unreachable newest-line fallback in _trim_oldest
The loop keeps lines[-1] unconditionally on its first iteration and
compact_ledger() (always run first by _maintain_size) strips blank lines,
so 'newest_json not in kept' could never be true; the size=2 slack was
also spurious since the join is exactly sum(len+1). Move _TRIM_LOW_WATER
above its first user.

PROOF: tests/tools/test_skill_ledger.py all green before and after (the
newest-survives assertion in test_trim_oldest_when_still_over_cap still
holds); probes/s5_trim_probe.py output unchanged.
2026-09-22 16:16:30 +05:30
kshitijk4poor
d2e492da66 docs(curator): trim drops the oldest lines regardless of shape
_trim_oldest never parses lines: it drops the OLDEST ones whatever they
are, so 'malformed lines always survive' was false. Reword docstring,
curator.md and the kept test's docstring to the true guarantee: lines in
the retained tail are never rewritten or parsed, so a malformed line there
survives verbatim. No behaviour change.

PROOF: probes/s5_trim_probe.py (cap 4096, malformed first line, 4 fat
appends) -> old malformed survived: False, contradicting the old wording;
the kept test asserts a LAST-line malformed row, which is what the new
wording promises.
2026-09-22 16:16:30 +05:30
kshitijk4poor
87276637ed fix(computer_use): a capped accessibility walk says so in the capture hint
`_capture_view`'s hint promised a "full element tree saved to elements_file",
but once `computer_use.ax_max_elements` bounds the driver's walk the spill
holds only the first N nodes. When the capture returned at least the bound
(bound > 0), drop "full" and add "accessibility walk capped at N elements;
pass app= to narrow" so the model knows how to reach the rest.
2026-09-22 16:16:30 +05:30
kshitijk4poor
74069eb428 fix(curator): ledger trim stops at a low-water mark
At the cap every append ran compact + trim + gc_blobs: trimming to exactly
`skills.ledger_max_bytes` leaves the file over the cap again on the very next
append. Trim to 80% of the cap instead (one rule derived from the cap, no
second config key), and run `gc_blobs()` only when the trim actually dropped
rows — the only path that can orphan a blob. `_trim_oldest` now reports the
dropped-line count and reuses `_read_ledger`, so an unreadable/undecodable
ledger skips the trim the same way it aborts compaction and blob GC.
Malformed lines are still kept verbatim.

The low-water-mark idea credits @fangliquanflq (#118690).
2026-09-22 16:16:30 +05:30
vgarlu
a85b6f9cdd perf(computer_use): bound the driver's accessibility-tree walk per capture
`capture()` sent `get_window_state` with only `pid`, `window_id` and `session`, so the driver
walked the target's entire accessibility tree before Hermes trimmed the surfaced element list
to `_DEFAULT_MAX_ELEMENTS` (100) and spilled the rest to a cache file. Every node past the
first ~100 was paid for and discarded.

Measured on macOS (cua-driver 0.28.2, M-series), same window, bound fixed at 200:

| Target | Unbounded walk | Bounded |
|---|---|---|
| 1,444-node Chrome window | 540 ms | 83 ms |
| 456-node Finder window (pathologically slow AX surface) | 6.9 s | 0.6 s |

The bound is lossless for the response: the bounded element list is a *prefix* of the
unbounded walk (checked by role/label/depth at 200/400/600/1000), so nothing the model sees
changes.

The bound is internal and config-driven — `computer_use.ax_max_elements`, default 200,
`0` disables (driver default) — and deliberately NOT a model-facing schema parameter:
`max_elements` was removed from the tool schema on purpose, so a capture's surfaced window
stays at its fixed default.

(cherry picked from commit 9f07ff428bd1fcfbcc0e5089d834e1f33d8d1b76)
2026-09-22 16:16:30 +05:30
Konstantin Khlopkov
71932b150b fix(curator): keep the skill ledger size-bounded (dedup rewrite + oldest-entry trim)
(cherry picked from commit 42572ebf207d411edd534055b1d750d91efcd4f7)
2026-09-22 16:16:30 +05:30
carlotestor
3e88c8032d perf(gateway): enter each profile scope once per heartbeat-restore scan; signature-cache profile config.yaml parses
restore_heartbeat_watches entered _profile_scope_for_source for every routed
session on every poll. Each entry hydrated the profile secret scope and rebuilt
the terminal policy, and both re-parsed the profile config.yaml from disk, so N
routed sessions cost 2N YAML parses per poll even though nothing changed.

- Group entries by resolved profile home and enter the scope once per group.
- Add utils.load_yaml_file_readonly (file_signature-keyed cache) and use it in
  env_loader._load_secrets_config and terminal_scope.build_profile_terminal_scope,
  which were both open()+fast_safe_load per scope entry. Present-but-unparseable
  still fails closed: parse errors propagate and are never cached.

Measured on a 3-profile host: one _profile_runtime_scope enter/exit 1.80 ms -> 0.11 ms.

(cherry picked from commit c6b16629bd38799bbf166206c73a6140a9559a61)
2026-09-22 16:15:34 +05:30
kshitijk4poor
c06aca3fcf refactor(skills): read the hub client ContextVar through skills_hub_http_session only
_ssrf_safe_http_get re-implemented the pool lookup (nullcontext(active)
else create_ssrf_safe_client(timeout=..., follow_redirects=False)), so it
knew the pool's storage and construction kwargs. It now enters
skills_hub_http_session() — a no-op inside an active session, otherwise a
one-shot create/teardown of the same follow_redirects=False client — and
reads the ContextVar once. The unused nullcontext import goes with it.

PROOF: probes/S6-timeout.py — one-shot path constructs the client with
timeout=20/follow_redirects=False, forwards the per-request timeout=7 and
headers to .get(), and resets the ContextVar afterwards; pooled path makes
one client for two GETs with per-call timeouts [3, 20]. ruff clean,
check-windows-footguns clean, real import ok, run_tests.sh on
tests/hermes_cli/test_skills_hub*.py tests/tools/test_skills_hub*.py:
163 passed / 0 failed / 1 skipped.
2026-09-22 15:59:17 +05:30
kshitijk4poor
7110613021 refactor(skills): use _DEFAULT_HTTP_TIMEOUT for the same-module guarded GET defaults
`_DEFAULT_HTTP_TIMEOUT = 20` documents "the default every one-shot hub
GET used", yet `_guarded_http_get` and `_guarded_http_stream` in the
same module still spelled the literal. Reference the constant so the
pooled client and the guarded one-shot helpers cannot drift apart.
Sibling modules' literals are intentionally left alone.

PROOF: no `timeout=20` / `timeout: int = 20` remains in
tools/skills_hub.py; a signature probe confirms both defaults equal
`_DEFAULT_HTTP_TIMEOUT == 20`; 170 tests across the 4 skills_hub test
files pass, 0 failed.
2026-09-22 15:59:17 +05:30
kshitijk4poor
8f4db9396f refactor(skills): collapse the pooled-else-fresh branches of _ssrf_safe_http_get
`_ssrf_safe_http_get` re-implemented the "active pool client else fresh
client" split that `_skills_hub_http_get` introduced, with two separate
`.get(...)` calls. Pick the context manager once (`nullcontext(pooled)`
or a fresh `create_ssrf_safe_client(...)`) and issue a single GET. The
fallbacks stay distinct on purpose: this helper builds a guarded client,
`_skills_hub_http_get` falls back to bare `httpx.get`.

PROOF: behaviour-preserving; 345 tests across the 21 hub/skills test
files (tests/hermes_cli + tests/tools matching skills_hub /
_ssrf_safe_http_get) pass, 0 failed, including the pool-reuse test that
asserts exactly one client is created during inspect.
2026-09-22 15:59:17 +05:30
kshitijk4poor
4036ba8c17 fix(skills): route the ClawHub owner lookup through the hub connection pool
`ClawHubSource._fetch_owner_handle` was the last one-shot GET in
tools/skills_hub*.py still calling bare `httpx.get`, so an inspect
opened a fresh connection for the owner lookup even inside
`skills_hub_http_session()`. Route it through
`hub()._skills_hub_http_get` like the models/search/github siblings;
behaviour is identical outside a session.

PROOF: the existing pool test now also calls `_fetch_owner_handle`
inside the fake `Source.inspect`; reverting the clawhub change makes it
fail with "index fetch bypassed the pool" (httpx.get is patched to
pytest.fail). grep shows no bare `httpx.get(` left in
tools/skills_hub*.py besides `_skills_hub_http_get`'s own fallback.
tests/hermes_cli/test_skills_hub.py: 12 passed.
2026-09-22 15:59:17 +05:30
kshitijk4poor
ee340ad29b fix(skills): the pooled hub client carries a default timeout
skills_hub_http_session built its httpx.Client without a timeout, so any
pooled GET that omitted an explicit timeout fell back to httpx's 5 s
default instead of the 20 s every one-shot hub GET used. Name that
default once and hand it to the pooled client and _ssrf_safe_http_get.
2026-09-22 15:59:17 +05:30
kshitijk4poor
485e05d118 fix(skills): hoist the hub import out of the index retry loop
_load_hermes_index re-imported tools.skills_hub_models.hub on every
iteration of the Accept-Encoding retry loop. skills_hub_models is a leaf
already imported at module top, so there is no cycle to dodge; import
hub once alongside the other names.
2026-09-22 15:59:17 +05:30
KoNit-K
7d793348e8 fix(skills): reuse HTTP connections during inspect
(cherry picked from commit d2e7e95b213a3610319fe9af920e34e28648f14d)
2026-09-22 15:59:17 +05:30
kshitijk4poor
a6af404122 docs(bot-mode): note that the capability epoch follows the skills walker's org gating
iter_skill_index_files is org-token-gated, so the epoch also moves on an
org switch. That is correct behaviour (a different org sees a different
skills index and needs a different prompt) but was undocumented.
2026-09-22 15:55:09 +05:30
John Paul Soliva
6df4571177 perf(bot-mode): the capability epoch counts the skills the model can invoke, not archived ones
`capability_fingerprint`'s skills component globbed `**/SKILL.md` raw, while every other reader of
that tree — `skills_list`/`skill_view`, the prompt's own `<available_skills>` index, `skill_count`,
`prompt_size` — walks it through `iter_skill_index_files`, which prunes EXCLUDED_SKILL_DIRS
(`.archive`, `.curator_backups`, `node_modules`, `.venv`, …) and each package's support dirs.

So the fingerprint was the only place counting an archived skill as a skill. Since a changed digest
rebuilds the stored Bot Chat system prompt, archiving a skill — or the curator writing a backup, or
a skill vendoring node_modules — re-prefilled the whole prompt cache for a prompt whose skills
section had not changed.

Measured on a 120-skill profile: 11.42ms -> 6.26ms, and it runs twice per turn (turn start and the
prompt-restore path). The surface drops 120 -> 89 entries, and all 31 dropped sit under a pruned
dir — none of them appear in the prompt index, skills_list or skill_count.

One-time effect: the digest changes once on upgrade, so each Bot Chat rebuilds and re-prefills once.
After that the epoch stops moving for churn it should never have tracked.

Regressions: installing a real skill still moves the epoch; archiving one settles and further
archived packages never move it again; no EXCLUDED_SKILL_DIRS entry can move it (parametrised over
the whole set); a curator backup and a skill's `references/` dir are both inert; and the epoch
tracks exactly what the skills walker reports. Restoring the raw glob fails 20 of the 21.

Fixes #117788

(cherry picked from commit a6b50a40e117f8afca28208541be714578bbc568)
2026-09-22 15:55:09 +05:30
Siddharth Balyan
70f5dc5f46 feat(connectors): the backend API for the desktop Connectors page; connect an app without a chat session (#115191)
* feat(connectors): the backend serves a connector's tool list, cached for 24 hours

The Connectors page opens one app and shows every tool it has. The backend
had no way to read that list.

- `tools/connectors/portal/`: a client for the portal's tool-list route and a
  JSON cache under the Hermes home, one file per portal origin and connector.
  An entry is fresh for 24 hours. After that the read revalidates with the
  stored ETag: 304 keeps the list, 404 deletes the entry, an upstream failure
  serves the stored list marked stale, and a 401 never serves the cache.
- `connectors.tools {slug, refresh}`: account-level, routed by `profile`, no
  chat session. Errors carry a fixed `reason` from one closed set on the rail.
- Every connector model that is not operation state moves into
  `tui_gateway/contracts/connectors.py`. Handlers that no chat session owns
  live in `tui_gateway/methods_connectors_account.py`.

The wire model is tolerant: an unknown facet reads as unclassified and one odd
tool never blanks a connector.

* feat(connectors): catalog, accounts and member tool rules by RPC

The Connectors page needs the app catalog, the connected account of one app,
a way to disconnect it, and the member's own on/off rules. None had an RPC.

- `connectors.catalog`: name, description, category and logo of each app.
- `connectors.accounts`, `connectors.accounts.remove`: read the accounts at
  the tool gateway and remove one by id.
- `connectors.policy.get`: the rule layers that apply to the member, widest
  first. The body is a union on `mode`, so a reader can name who turned a
  tool off.
- `connectors.policy.set`: one change, a union on `type` (the tools of one
  connector, or one connector on or off), with the revision the user saw. A
  stale revision answers `POLICY_CONFLICT`. The backend composes the upstream
  write in one pure function, so no renderer learns the upstream rules.
- Bundled MCP manifests can name their hosted twin with `connector:`, so the
  page can show one card per app.

* feat(connectors): connect an app without a chat session

Every connector RPC took a `session_id`, and a connect that did not come from
the model's tool call minted a link with no watcher. The Connectors page has
no chat session, and its card must flip to connected by itself.

- `connectors.list`, `connectors.connect`, `connectors.operation.status`,
  `connectors.operation.wake` and `connection.respond` take `owner`, a union
  on `type`: `session` (today's behaviour and authorization) or `account`
  (routed by `profile`, authorized by the live transport like `mcp.*`).
  `session_id` is gone from these params; every desktop caller sends `owner`.
- An account connect runs the same operation lifecycle on a background
  thread, under the profile's scope, so the watcher reads the account and
  settles the operation. A second connect for an app that is already
  connecting returns the open operation and mints nothing.
- `connection.update` carries `owner`. An account operation has no session to
  address, so its updates go out on the session-less broadcast path.

* feat(mcp-catalog): eighteen more bundled entries name their hosted connector

A bundled MCP entry and a hosted connector for the same app are one card
on the Connectors page only when the manifest names its hosted twin.
Linear and Notion had the field. These entries get it too: airtable,
asana, attio, calendly, dropbox, figma, railway, supabase, todoist,
betterstack, canva, cloudflare, datadog, intercom, neon, sentry, stripe
and vercel. Atlassian maps to two hosted connectors and Prisma Postgres
is not clearly the same app, so both stay without one.

* refactor(connectors): the account handlers share one gate, one params model and one write table

The six account-level handlers each repeated the availability gate, the
auth catch and the catch-all reply. One decorator now owns that, and each
handler validates its params with its contract model instead of a ladder
of isinstance checks. The five connection RPCs share one guard for the
unexpected-failure reply.

The four write composers for the member rules were the same function
with a different list key and polarity. They are one table now.

The owner union lives in contracts/common.py, so the params side and the
event side stop declaring it twice and the import cycle is gone.

An account operation start carries one event and a flag, so the wait for
the sign-in link blocks instead of polling every 50 ms. run_operation
loses its two account-only parameters; drive_operation is the second
entry point.

Tests: four deleted (they exercised pydantic or the mock), three merged
into tables, two added (a client that still sends the old top-level
session_id is refused; all six account RPCs run off the server loop).
The shared reply helper and the HTTP and managed-client fakes move to
one place each. Comments are one line or gone.

* fix(connectors): a missing tool-list route reads as "unavailable", not "connector gone"

The tool-list read treated every 404 as the portal's "this connector is
not in the catalog" answer. It deleted the cache entry and answered
CONNECTOR_NOT_FOUND, so a page would offer to remove an app that is
connected and works. A portal that does not serve the route yet answers
a bare 404 for every app.

Only the portal's own {"error": "connector_not_found"} means the
connector is gone. Any other 404 is now a tool-list outage: the cached
list is served as stale, or the RPC answers TOOLS_UNAVAILABLE.

* fix(connectors): a connect from the page returns to the app after sign-in

The sign-in link carries a return target only when the session's surface
is the desktop. A chat session binds that surface. An account-owned call
has no chat session, so nothing bound it: the link was minted without a
return target and the browser ended on the portal's done page instead of
coming back to Hermes.

Every account-owned call now runs with the process's own surface bound,
next to its profile scope. The operation thread copies that context, so
the first link and every reissued link carry the return target and the
operation id.

* test(connectors): defer the new connector RPC coverage

The tests for the new account RPCs, the portal client, the tool-list cache
and the rule composer leave this PR and come back in one later change, after
the API is settled. The same was done for #111008.

Kept: the edits that existing tests need because the five connection RPCs
now take `owner` instead of `session_id`, and the rename of the managed
client seam.

Removed: six new test files, their two fakes and the gateway conftest, and
the new cases in test_mcp_catalog.py, test_connectors_gateway_client.py,
gateway-rpc.test.ts and notifications.test.ts. Reverting this commit restores
all of them.

* fix(cli): the connection panel hands the tool thread back at once

The classic CLI's connection callback waited on a queue for the user's first
decision. The operation's watcher starts only after the callback returns, and
the watcher is what polls a hosted account, runs the 300-second deadline and
sees Ctrl+C.

For a hosted connector the panel opens on the sign-in link, where the only
key that filled the queue was Cancel. The account was never polled: the user
signed in, the panel never changed, and Esc reported the app as skipped.
Ctrl+C set the interrupt flag but left the thread parked on the queue, so the
turn never ended.

The callback now opens the panel and returns, as the gateway's callback does
for the desktop and the Ink TUI. The panel's actions already reach the
operation through apply_answer on the UI thread, so the queue is removed. An
install with a form still waits for Connect, because the backend starts no
work for a pending row. Ctrl+C now settles the operation as `interrupt`, and
open rows become `not_connected`.

Checked on the e2e rig with the fake tool gateway: hosted connect completes on
the third status read; Ctrl+C ends the turn and the polling stops; an MCP
install with a plain and a secret field still saves config and both values.

* fix(connectors): "run it again" lives in the library, so the classic CLI can use it

Making a new sign-in link for a failed or expired hosted connector was
implemented only in the JSON-RPC layer (`_reissue`). The classic CLI does not
go through JSON-RPC: its Connect button on a failed row called apply_answer,
which does nothing for a hosted operation because it has no MCP runner. The
panel showed "Waiting…" until the deadline.

`tools.connectors.run.reissue(operation, names)` now holds the checks and the
per-kind action, and returns a refusal reason or None. The gateway maps each
reason to the same JSON-RPC error as before. The CLI calls it for a hosted
row; a refusal is shown on the row. MCP rows keep their path, because Connect
on a failed MCP row re-sends the form values.

Checked on the e2e rig: a scripted failed sign-in, then Connect: a second mint
with `reinitiate: true`, a new link with a new connection id, then connected.

* feat(connectors): the account list and disconnect go through the portal

`connectors.accounts` and `connectors.accounts.remove` called the tool
gateway. They now call the portal's account-management routes
(`GET /api/v1/connectors/accounts`, `DELETE /api/v1/connectors/accounts/{id}`),
which apply the organisation membership checks and write the disconnect audit
row. There is no fallback to the gateway when the portal is unavailable, and a
removal is never retried.

The read of ONE account stays on the gateway (`GET v1/connectors/accounts/{id}`):
the portal has no such route, and the operation watcher polls it once per second.

`ConnectorClient.list_accounts` and `delete_account` are removed. The removed
account's reply model carries `connector`, which both services send.

* fix(connectors): the account RPCs answer what the portal really sends

Checked against the portal source and against the staging and production
services.

- Errors are read from the upstream error code, not the HTTP status. A rule
  write answered 409 for a stale revision and for a user with no organisation;
  both read as "the policy changed". `org_required` is now `ORG_REQUIRED` and
  403 `no_access` is `ORG_ACCESS_DENIED` on every account RPC; only a rejected
  sign-in is `NEEDS_NOUS_AUTH`. `connectors.list` and `connectors.connect` with
  the account owner map these too.
- `connectors.policy.get` and `connectors.policy.set` carry `effective`: the
  portal's own result for this user, with its stamp and without provider or
  subject ids. Nothing is recomputed locally.
- A rule write needs the revision the user saw: `expected_revision` is required
  and must be a revision string; a bad one is refused before any HTTP call.
- A tool row carries `no_auth`; a list without the upstream flag is an invalid
  answer, not `false`.
- `connectors.accounts.remove` returns the app of the removed account. An
  invalid id is `INVALID_PARAMS`.
- The tool-list cache is per signed-in member (a hash of the token's `sub`),
  so two Nous accounts on one profile do not share entries.
- A malformed slug is a local error, not a 404 from a server nobody called.

Live, staging: no revision and a malformed revision refused locally; a good
revision wrote one disabled Gmail tool and returned it in `effective`; the
same revision again answered `POLICY_CONFLICT`; the list row showed the tool;
the restore brought the member rules back to the start. Live, staging and
production, read-only: all 60 tool lists (5483 tools) parse.

* fix(connectors): the operation RPCs match their contract; a settled card cannot start a new link

Found by two adversarial reviews of the RPC layer and its types.

- `connectors.connect` from a chat session with no open operation is refused
  (`UNKNOWN_OPERATION`). It used to call `manage_connections` through the tool
  registry with no card: it made a link nobody watched, returned a reply
  without the required `settled` field, and named an operation that was never
  registered. There is one way into an operation: the agent's call, or the
  account owner's `connectors.connect`. "Run it again" inside an open
  operation is unchanged.
- `connection.update` for a session is routed by session key AND profile; two
  profiles with the same key no longer cross-deliver a sign-in link. The event
  payload gets the same redaction as the RPC replies.
- `connection.respond` runs on the long-handler pool: an approval can start MCP
  OAuth discovery, which blocked every RPC of the gateway while it ran.
- `connectors.list` rows are a closed snake_case model: `connector`, `enabled`,
  `connected`, `connection_status`, `status_reason`, `gateway_disabled_tools`.
  The last one is display data: the gateway enforces the rules, the backend
  only passes the list on. The phantom `name` and `description` are gone, and
  the desktop uses the generated types instead of hand-written copies.
- `tools_listing` (model-only data) no longer rides on `connectors.operation.status`.
- `unavailable` is removed from the target states and settle reasons: nothing
  produces it. The contract generator now fails when a contract enum and its
  domain enum differ.
- `ConnectorErrorReason` is part of the generated TypeScript and OpenRPC.
- The desktop sends `connection.respond` on the socket that holds the session,
  as wake and reissue already did.
- Contract violations are logged every time, at error level.
- An account connect whose prepare step is slow returns the live operation
  instead of an error while the operation keeps running.
- The MCP-manifest `connector` field leaves this PR (it moves to a later one
  on top of the catalog-reader change). `hermes_cli/mcp_catalog.py` and
  `optional-mcps/` are untouched by this PR again.

anti-slop: no net-new findings (15 touched files).

* fix(connectors): the model gets no sign-in link wherever a card exists; side agents cannot connect

The flag that tells the model "a connection card exists" was the session
platform (`== "desktop"`). The Ink TUI and the classic CLI also draw a card,
so there a connector call on an unconnected app handed the model the raw
`connect_url` and told it to pass the link to the user.

- The agent turn now declares how a link can reach the user
  (`tools/connectors/turn.py`): CARD when the agent was built with a
  connection callback, SIDE for a subagent or a background turn, LINK for a
  headless run (`-q`, cron, ACP, api_server, messaging). It is set once per
  tool batch in the agent loop and read by the connector dispatch path, which
  never sees the agent. The session platform decides return-to-app only.
- CARD: the result carries `connect_card_available` and our hint, never the
  link and never the gateway's own hint.
- SIDE: subagents (`delegate_tool`), gateway background turns and the classic
  CLI `/bg` are built with `side_agent=True`. They hold no `manage_connections`
  tool on any path that derives the tool list, and a connector call on an
  unconnected app gets no link, only "report this to the main agent".
- LINK is unchanged.
- The hosted path with no card builds a detached operation, as the MCP path
  does, so no `connection.update` is emitted for an operation no client asked
  for. Names and docstrings that said "off desktop" now say "no card".
- A settled card is dead on the desktop: `reissueConnectionTarget` and
  `respondToConnectionRequest` share one guard and send nothing for a settled
  or unknown operation.
- The model-facing settled result no longer carries `connection_id`; the model
  repeated it to the user.

Shown on the real clients with a real model (rig, fake tool gateway): Ink TUI
and classic CLI get `connect_card_available` and no link, the model opens the
card, the account connects, the retried call succeeds; `-q` still gets the
link; a subagent and a background turn have no `manage_connections` and get
the no-link hint; on the desktop a card settled with Continue has no enabled
control and sends no RPC.

* feat(tools): every call made through tool_search + tool_call shows a real label on all three clients

A bridged call showed as a generic `tool_call` row in the Ink TUI and as
`⚡ tool_call` in the classic CLI, because the display looked the name up in
the tool registry and bridged names are made at run time. The desktop labelled
only batches that were all hosted connector calls, by parsing names itself.

- `tools/tool_labels.py` is the one place that turns a bridged call into a
  label: kind, app, action, emoji and text. Hosted: `connectors__gmail__GMAIL_SEND_EMAIL`
  → "Gmail · send email". MCP: "Linear · list issues". A local deferred tool
  keeps its own emoji, verb and primary-argument preview. A batch gets exactly
  one label per entry, always; an entry with no name gets a generic label.
- Classic CLI: one row per inner call; the duration on the last row; the
  failure text on the row of the call that failed. With friendly labels off
  it prints what it printed before.
- Gateway: tool start, progress and complete events and stored transcript rows
  carry a typed `labels` field. It does not depend on the classic CLI's
  display setting. Clients no longer parse tool names.
- Ink TUI: rows from the labels; the verbose trail keeps Args and Result.
- Desktop: `ConnectorExecution` renders hosted, MCP and mixed turns from the
  labels, one row per call. The labels reach the row under a key no tool
  argument can use. The connect card it drew under a failed tool result is
  gone: after `CONNECTION_REQUIRED` the one way in is the agent's own
  `manage_connections` call.
- `tool_search` and `tool_describe` rows read "Searching tools · <query>" and
  "Reading tool details · N tools".

Shown on the real desktop (video and screenshots), the Ink TUI and the classic
CLI with the rig: hosted rows, MCP rows, a two-entry batch, a failed entry, a
`CONNECTION_REQUIRED` row with no card under it, labels after a reload, and the
desktop rows with the classic CLI setting off.

* fix(connectors): the model can tell "hosted tools unavailable" from "no such tool"; manage_connections routes MCP names correctly

- A failed hosted search or describe used to return nothing, by design, so the
  model saw only local tools and told the user that a connected app was
  missing. The local results are unchanged; when the hosted leg failed, the
  `tool_search` and `tool_describe` results carry
  `connectors: {status: "unavailable", reason: "unreachable" | "sign_in_expired"}`
  and one hint line. A rejected token is `sign_in_expired`; an entitlement
  refusal or a shut gate adds nothing. `tool_describe` no longer lists those
  names under `not_found` next to "search again".
- NS-932. The description now says which side a name belongs to: a bare name
  is a hosted connector account; `mcp: true` only when the user asks for an MCP
  server, a local server or an install, or when the name exists only in the
  catalog; connect and reconnect are hosted verbs, install, enable and
  authorize are MCP verbs. It names the three clients that draw a card.
- A misrouted target is refused with the call that works. Only when the
  gateway does not know the connector (confirmed on that failure path) and the
  name is a catalog entry does the target fail with "X is a local MCP server.
  Call manage_connections with action install ...". It is a per-target
  outcome: other targets of the same call keep their links and their card. A
  vendor failure on a name both sides know stays an ordinary failed row. The
  MCP side mirrors it, and never for an entry that is only not installed.
- "Do not re-ask after a skip or a timeout" no longer stops the model when the
  USER asks for that app again; the description and the settled-result notes
  say so. A builder saw the model refuse a direct user request.

Shown on the Ink TUI and the classic CLI with a real model: a dead gateway and
a 401; "connect fxmail" goes hosted; "install the fx-noauth MCP server" goes
MCP; "connect fx-noauth" reaches the MCP install card in one corrective round
with no hosted mint; a two-target call where one is misrouted still connects
the other with exactly one mint.

* fix(tui): the connection card answers every key, shows what is happening, and is dead once settled

Reproduced on the real Ink TUI with the rig, then fixed:

- The keyboard was dead during the sign-in wait: the card kept a `submitting`
  flag that the normal OAuth path never cleared, and Esc went through the same
  guard. The in-flight state now belongs to the answered row and clears when
  that row moves, when any later frame of the operation arrives, or after
  five seconds. Esc skips the row in every phase; Ctrl+C interrupts the turn
  (the input handler had no branch for this overlay); Shift+arrows scroll the
  transcript and the card ignores them; arrow keys no longer move the text
  cursor and the field focus at once.
- The card was lost at turn idle: the overlay flag was cleared while the
  operation stayed in the store, and a resume dropped the pending card. The
  flag survives idle, a resume shows the pending card again, a session switch
  clears it.
- States with no branch: `not_connected` and a row with no link fell into the
  credential form; `expired` vanished with no note. The title and the row text
  now name the action (connect, reconnect, install, enable, authorize); a
  failed or expired row with no fields offers Try again / Skip; a failed row
  WITH fields reopens the form over the typed draft, with the failure above it.
- A settled card is dead: at settle the overlay closes and one transcript line
  per app states the outcome. A settled or dismissed operation id is
  remembered, so no replay or resume can reopen its card. Esc in the last
  "Finishing…" moment hides the card and still writes the outcome lines.
- A failed `connection.respond` and a browser that did not open are shown on
  the card in one sentence.

Also: `tui_gateway/connector_payload.py` redacted the BOOLEAN `secret` flag of
a credential field to the string "[REDACTED]". On the desktop every credential
field therefore rendered as a password and lost its prefilled default. A
boolean is no longer redacted.

* chore(connectors): remove the comments and docstrings this branch added

Deletions only. Kept: tool directives (`# noqa`, `// eslint-disable`, ...),
`// SAFETY:` lines, and the docstrings of the contract models under
`tui_gateway/contracts/`, which become the descriptions in the generated
OpenRPC and TypeScript.

Checked that no code changed: every Python file has the same AST as before
once docstrings and `pass` are ignored (62 files), and every TypeScript file
prints the same with comments stripped by the TypeScript printer (32 files).
The generated contract files are unchanged.

* fix(connectors): a card restored after a reload answers again; every account RPC names auth and org failures

Found by the end-to-end runs on the pushed head.

- Desktop: after a window reload, Continue on the restored card sent nothing.
  The answer looked up the backend that holds the session with the runtime
  session id, the lookup wants the stored id, and a failed lookup returned
  silently. When the lookup gives no owner the answer now goes out on the
  window's active socket, which is what main does.
- `connectors.policy.get` answered `POLICY_UNAVAILABLE` for a rejected sign-in,
  a refused scope, a non-member and a missing organisation alike: the handler
  runs with the gateway's globals and did not import the reason enum, so its
  own error mapping raised. `connectors.accounts.remove` caught auth failures
  in its generic branch. `org_required` was mapped on `policy.set` only. All
  six account RPCs now answer `NEEDS_NOUS_AUTH`, `FORBIDDEN_SCOPE`,
  `ORG_ACCESS_DENIED` and `ORG_REQUIRED` for those four upstream answers.
2026-09-22 13:57:51 +05:30
alt-glitch
62aa4b7d0d refactor(voice): WSL detection through hermes_platform.host.runtime.is_wsl
One runtime predicate keeps WSL detection from diverging between call sites.
The shared result is cached per process.
2026-09-22 01:13:23 -07:00
alt-glitch
724783a675 refactor(cua): WSL detection through hermes_platform.host.runtime.is_wsl
One runtime predicate keeps computer-use overlay policy from holding a separate WSL result.
The shared result is cached per process.
2026-09-22 01:13:23 -07:00
kshitijk4poor
14b29a4207 refactor(skills): abort blob GC from a single malformed-row guard
gc_blobs carried two byte-identical `warning("malformed ledger line; blob
GC skipped"); return 0, 0` blocks — one under `except json.JSONDecodeError`,
one under `if not isinstance(row, dict)` (tools/skill_ledger.py:350-357;
simplify reuse #2, efficiency note, re-gate G2 S2). Funnel the decode
failure into the type guard (`row = None`) so the abort exists once.
Behaviour is unchanged for both the [malformed-json] and [non-dict-row]
parametrizations: any line that is not a JSON object still aborts the
sweep with the same warning.
2026-09-22 13:40:40 +05:30
kshitijk4poor
5194561cc2 refactor(skills): share one _read_ledger() helper across compact/gc/list
compact_ledger, gc_blobs and list_entries each stamped the same prelude:
read the ledger, catch (OSError, UnicodeError), warn "skill_ledger: ledger
unreadable (%s); <what>", bail (tools/skill_ledger.py:305-310, :341-346,
:412-417 — simplify reuse #1). Fold them into a private sibling
_read_ledger(what, *, quiet_missing=False) -> Optional[bytes] that reads
bytes, validates the UTF-8 decode and warns once unless quiet_missing and
the ledger is merely absent (list_entries: a fresh install has no ledger).

Returns bytes rather than str so compact_ledger keeps reporting the on-disk
size in bytes_before instead of re-encoding. Warning texts ("compaction
skipped", "blob GC skipped", "listing empty") are unchanged, so the
existing invariant tests pass verbatim.
2026-09-22 13:40:40 +05:30
kshitijk4poor
dd309d046f fix(skills): warn when list_entries() hits a corrupt ledger, and pin the UnicodeError guard
list_entries() (tools/skill_ledger.py:414) caught (OSError, UnicodeError) but
returned [] silently, so a ledger that EXISTS but cannot be decoded made
`hermes curator ledger` print "ledger is empty" and `hermes curator rollback`
report "no ledger entry with id" with no hint that the file is damaged — while
gc_blobs()/compact_ledger() already warn on the same condition (:309, :345).
Now warn for any read failure except FileNotFoundError (a missing ledger is the
normal empty state). `%s`-lazy logger call, same "ledger unreadable" prefix.

Also adds the regression test the UnicodeError widening (2213062284) lacked:
re-gate mutation M8 reverted the except clause to `except OSError:` and the
whole suite stayed green. New tests write b"\xff" to ledger_path() and assert
list_entries() == [], get_entry() is None and "listing empty" in caplog; a
second test pins that a merely missing ledger stays silent.

Red/green: `except OSError:` -> UnicodeDecodeError (1 red); warning dropped ->
caplog assert red; warning made unconditional -> missing-ledger test red.
2026-09-22 13:40:40 +05:30
kshitijk4poor
69002c9211 docs(skills): document that an unreadable ledger also aborts blob GC
The gc_blobs() docstring (tools/skill_ledger.py:334) only mentioned malformed lines as a
reason to abort the sweep; this branch added the unreadable/undecodable-ledger abort
without updating it. State both conditions and the invariant (blobs are kept).
2026-09-22 13:40:40 +05:30
kshitijk4poor
83cf0ef801 fix(skills): treat an undecodable ledger as empty in list_entries()
list_entries() caught only OSError (tools/skill_ledger.py:409), so a ledger whose bytes
are not valid UTF-8 raised UnicodeDecodeError out of `hermes curator ledger`, get_entry()
and rollback_entry() — the very corrupt state gc_blobs() and compact_ledger() now
tolerate on this branch. Widen to (OSError, UnicodeError) and return [], matching the
existing "unreadable ledger == empty" contract; the read path is read-only, so nothing
is lost by treating the file as having no entries.

Manual probe (HERMES_HOME=<tmp>, ledger bytes b"\xff"):
  before: list_entries() -> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff
  after:  list_entries() -> []; get_entry('abc') -> None;
          rollback_entry('abc') -> (False, "no ledger entry with id 'abc'")
2026-09-22 13:40:40 +05:30
kshitijk4poor
2a9c27f1de fix(skills): warn when compaction is skipped because the ledger is unreadable
compact_ledger() returns (0, 0, 0) when the ledger cannot be read or decoded
(tools/skill_ledger.py:308-309) but did so silently, so `hermes curator ledger --compact`
reported a no-op compaction as if the ledger were simply empty. gc_blobs() already logs
"ledger unreadable (...); blob GC skipped" for the identical condition; emit the
symmetric warning here so the operator sees the ledger needs attention.

Manual probe (HERMES_HOME=<tmp>, ledger bytes b"\xff"):
  WARNING skill_ledger: ledger unreadable ('utf-8' codec can't decode byte 0xff in
  position 0: invalid start byte); compaction skipped
  compact_ledger() -> (0, 0, 0); ledger bytes still b"\xff".
The regression test that pins this arrives in the following commit.
2026-09-22 13:40:40 +05:30
kshitijk4poor
1d6c1c2f8f fix(skills): abort blob GC on a non-dict ledger row instead of raising
After json.loads() succeeds, gc_blobs() called row.get(...) unconditionally
(tools/skill_ledger.py:353). A syntactically valid but non-object line such as `[]`
or `"x"` raised AttributeError out of gc_blobs() and up through
`hermes curator ledger --compact`. list_entries() already tolerates such rows with an
isinstance(row, dict) check (~L414); mirror it here and abort the sweep with the same
"malformed ledger line; blob GC skipped" warning — a row we cannot interpret may still
hold blob references, so nothing may be deleted.

Test: `non-dict-row` param on the kept invariant test (ledger + b"[]\n"). RED with the
guard removed (AttributeError: 'list' object has no attribute 'get'), GREEN at head.
2026-09-22 13:40:40 +05:30
kshitijk4poor
49aa7215e8 fix(skills): warn when blob GC is skipped over a malformed ledger line
gc_blobs() aborts the sweep on a json.JSONDecodeError (tools/skill_ledger.py:351-352)
but did so silently, while the sibling read-failure abort a few lines above logs
"ledger unreadable (...); blob GC skipped". `hermes curator ledger --compact` therefore
printed "0 blobs removed" as if the sweep had run and found nothing. Emit the same
warning family so the operator learns the ledger needs repair before blobs can be GC'd.

Test: `malformed-json` param on the kept invariant test — (0, 0), blobs intact, and
"blob GC skipped" in caplog. RED with the warning removed
(assert 'blob GC skipped' in ''), GREEN at head.
2026-09-22 13:40:40 +05:30
kshitijk4poor
25f1f6fc47 fix(skills): guard compact_ledger() against undecodable ledger bytes
compact_ledger() caught OSError on the read but decoded the bytes outside
the guard, so a ledger with invalid UTF-8 raised UnicodeDecodeError out of
`hermes curator ledger --compact`. Same escape class the gc_blobs() fix
closes; treat it identically (no-op, ledger left untouched).
2026-09-22 13:40:40 +05:30
kshitijk4poor
b9183820b0 fix(skills): warn when blob GC is skipped because the ledger is unreadable
The new read-failure branch in gc_blobs() returned (0, 0) silently, so
`hermes curator ledger --compact` printed "0 unreferenced blob(s) removed"
as if the sweep had run. Log a warning with the underlying error so an
operator can tell "nothing to reap" from "could not look".

The kept invariant test now also asserts the warning via caplog.
2026-09-22 13:40:40 +05:30
Muhammed Furkan Akıncı
9e1a92c87f fix(skills): preserve rollback blobs when ledger reads fail
(cherry picked from commit e88e7cbbacbc9f00b0260c1c42b05086a7414d45)
2026-09-22 13:40:40 +05:30
kshitijk4poor
43833ed9f8 fix(stt): tolerate CAF work-dir cleanup errors
Pass ignore_cleanup_errors=True to the TemporaryDirectory that holds the
converted CAF->WAV file (tools/transcription_tools.py:420).

WHY: the sibling trim-dir cleanup a few lines below already swallows
errors (shutil.rmtree(..., ignore_errors=True)), but the CAF work dir did
not. On Windows an AV scanner or the search indexer briefly holding the
freshly written WAV makes rmtree raise out of TemporaryDirectory.__exit__,
turning an otherwise successful transcription into an exception. The
kwarg is available since 3.10; pyproject requires-python >= 3.11, and
plugins/teams_pipeline/meetings.py:199 already uses it.

No new test: the behaviour is stdlib.
2026-09-22 13:40:29 +05:30
Muhammed Furkan Akıncı
c17dafee29 fix(stt): isolate CAF conversions from source recordings
(cherry picked from commit 5a87336db193740ebf4911262370a5ce0dbb2b4e)
2026-09-22 13:40:29 +05:30
kshitijk4poor
9a7b54accf feat(skills): oversized-body lint rule, surfaced on the SKILL.md patch that crosses it
skill_view loads SKILL.md whole and the content then rides in context for
every later call of the session, so body size is paid per turn. The only
size signal was the 100k hard cap in skill_manage, and agent-authored skills
grew by small patches until they sat right under it (31 of 432 local skills
over 40k chars, 7 at 100-115k; skill_view results averaging 32k chars).

- skill_linter: advisory `oversized-body` past _BODY_SOFT_BUDGET_CHARS (24k,
  ~3x the ~200-line standard; bundled skills average ~20k) naming the size,
  the token estimate and the references/ split.
- skill_manage patch: attach lint findings the write INTRODUCED (diff of
  rules before/after), so the crossing patch reports it once and a clean
  patch on an already-large skill stays quiet. Create keeps reporting all.
- curator prompt: a body over the budget is itself a consolidation target.
- docs: skills.md linter paragraph.
2026-09-22 12:52:49 +05:30
kshitijk4poor
54a867a6e9 fix(skill_manage): batch success rows carry the linter findings and org-sharing note
Since operations[] became the only call shape (#97295) the batch's success
path rebuilt each row as {name, action, file_path, success} and dropped every
advisory key the per-op handler attached — lint_warnings/lint_hint from the
create linter and the org_sharing note. The model never saw a finding.
Carry those keys onto the row, mirroring what the failure path already does
for teaching payloads.
2026-09-22 12:52:49 +05:30