turn_internal() read execution trust, so a restart's resume of a person's
interrupted turn, automations, plugin injections and Bot Chat deliveries
all looked Hermes-started. Replace it with turn_origin() (and
ctx.turn_origin()), which names the producer only where Hermes knows it:
- "process_notification": a background process's completion, watch match
or liveness tick (_inject_watch_notification).
- "delegation_result": an async delegation's result re-entering its parent.
Every other turn reads None. The producer sets the origin on its event; the
committed automation row records it as turn_origin and restore reads it
back, so a row without one (any other producer, or one an older build
queued) restores as None and its fingerprint is unchanged. A late steer or
interrupt text run as the next turn reads None. The started_by_hermes
bookkeeping in the Bot Chat and API admission paths is removed. Trust,
authorization, allow_gateway_control and model-facing text are unchanged.
turn_client() is None both for a turn Hermes started itself (a
background-process notification, a delegation result, an automation
wake) and for a person's turn sent over a connection that announced no
client, so a plugin cannot tell a wake from a typed message by it.
hermes_cli.plugin_session.turn_internal() (also ctx.turn_internal(),
which answers through the gateway under plugins.isolation: host) reads
the running turn's own event: True when Hermes produced its input,
False for a message someone sent (typed in a client, announced or not,
on a messaging chat, or an API request), None outside a turn, in a
delegated child, in a managed worker, in a plugin's own slash command
and for a synthetic turn Hermes does not mark internal (a goal
continuation).
An API turn is marked internal for trust when it executes, so admission
now records what the event was before that mark; an API event with no
record reads None rather than True.
It only reads the turn context at hook time: no system prompt, tool
list, message or model request changes.
Capture a delivery-relevant snapshot of the firing job inside
cron.execution_identity.enter_cron_execution so delivery_platforms() with
job_id=None answers from the run that is actually firing even when the
saved job is edited or deleted mid-run, while explicit job_id lookups
remain previews of the stored job.
Add PluginContext.cron_delivery_platforms(job_id=None) (and tuple
preservation in RemotePluginContext) so hooks running under
plugins.isolation: host read the firing run's delivery platforms in the
gateway in the calling hook's context. Re-export
CronSchedulerRegistrationError from cron.plugin_api so plugins can catch
it without a private core import, and update the plugin guide example
and tests accordingly.
Addresses Greptile review feedback on PR #159657.
A notification plugin uses these to alert only for the user's own turn,
without importing gateway, agent or tools internals.
`hermes_cli.plugin_session.session_source()` (and `ctx.session_source()`)
returns the label the calling session was created with, its launch policy's
`source`: cli, tui, gui, acp, tool or oneshot for a chat a person started; any
other non-empty value is the label of a session Hermes started itself. "" says
only that no launch policy is bound: outside a session, for a person's
messaging chat turn and for a cron run. It reads only the running turn's
policy, never `os.environ`.
`in_delegated_child(*, include_subprocesses=False)` (and the ctx method) is
True while the code runs for a `delegate_task` child; with
`include_subprocesses=True` also in a process such a child started.
`fork_origin()` (and the ctx method) is "" for a session's own agent and
every other regular agent, and the fork's label inside a detached fork:
"background_review", "side_question" or "plugin_fork:<plugin id>".
The ctx forms answer under `plugins.isolation: host` the same way
`ctx.turn_client()` does: the call runs in the gateway, in the calling hook's
context. Listed in plugin_api.json (public-api.md regenerated) and the
plugin guide.
Under plugins.isolation: host the two documented forms of turn_client() and
session_viewers() answer differently. The module-level functions run in the
plugin's own process, which has no gateway and no turn, so they always return
None and []. ctx.turn_client() and ctx.session_viewers() call back into the
gateway in the calling hook's context and answer as they do in-process.
The plugins guide and the docstrings now say so and point a plugin that may
run hosted at the ctx form. The hosted-plugin test covers both forms: ctx
answers for the calling turn (and for no session when the caller has none
bound), and the module level answers None and [].
A notification plugin uses these to skip a phone alert while the user is
active at the client that sent the turn.
`hermes_cli.plugin_session.turn_client()` (and `ctx.turn_client()`) returns
the label the submitting connection announced, from the turn's own admission
stamp, or None outside a turn, in a delegated child, and for unannounced,
messaging and cron turns.
`session_viewers()` (and `ctx.session_viewers()`) lists the connections
attached to the calling session with their idle data
(`gateway.session_presence.viewers`). The session comes only from what the
calling task-local context bound (never `os.environ`): a turn's, or the
one a plugin's own slash command was typed in, which the gateway binds the
same way (no turn runs there, so `turn_client()` is None). A context with
only a route bound names no session and reads []. The live session must
answer to the bound route, so another session's id is never borrowed. A delegated child, which runs in a
copy of its parent's context, reads []. The authority is the one `TurnRunner`
binds its owner with: the active runtime scope's, so a routed profile's turn
reads its own authority, never the launch profile's. No gateway in the
process (CLI, managed worker, plugin host): [].
Both are labels and reports clients chose: attribution only. Listed in
plugin_api.json (public-api.md regenerated) and the plugin guide.
The guard that turns registrars into no-ops after a plugin's load times out
wrapped only the names defined directly on PluginContext. register_idle_task
lives on a mixin, so a plugin whose register() overran the load timeout could
still register an idle task from its abandoned worker after the failure path
had swept its other registrations, and the host would later run it.
The guard now walks PluginContext's MRO, so every register_*, subscribe and
on_unload that PluginContext defines or inherits is a no-op once the load is
abandoned. A contract test calls every registrar on an abandoned context and
expects nothing to run.
The guard lives in hermes_cli.plugins_load_guard, so the hermes_cli.plugins
facade does not grow with it; plugins.py applies it to PluginContext once,
after its last registrar is defined.
Co-authored-by: xue xinglong <257216957+chaos-xxl@users.noreply.github.com>
A plugin task could inherit_from any core auxiliary block and resolve to its provider,
model, endpoint and key, so a plugin without allow_task_override could still spend
through an operator-configured built-in route (background_review, curator, ...) by
naming its own inheriting task. Read-time resolution now carries a core base's route
fields (provider, model, base_url, api_key, api_mode, key env, reasoning_effort,
extra_body, fallback_chain) only when the owning plugin holds allow_task_override,
including through a chain of plugin tasks rooted in a core block; non-route policy
such as timeout still inherits. inherit_from accepts the picker tasks plus an explicit
list (background_review, curator) instead of every current and future core block.
register_auxiliary_task only accepted picker tasks (main_provider_setup._AUX_TASKS) or
plugin-registered keys as an inherit_from base, so inherit_from="background_review" was
silently dropped and a plugin fork's task= lane ran on the session model instead of
following auxiliary.background_review. Any dict block under DEFAULT_CONFIG["auxiliary"] is
now a valid base, resolved at read time like the others.
A plugin with session-less background work (re-scoring its own data,
suggesting a cleanup) had to run its own timer. register_idle_task(name, fn,
*, interval_hours, min_idle_hours=2, first_run="defer") puts it on the skill
curator's scheduler instead:
- polled from every site that drives the curator (gateway housekeeping per
served profile, CLI/TUI startup maintenance, the hermes serve maintenance
tick) through one run_idle_jobs(): the curator, then the active profile's
plugin tasks;
- the curator's gates via agent/idle_schedule: the min-idle check, the
interval (floored to 1 h) whose first observation seeds last_run_at and
defers one interval (first_run="immediate" opts out), and the O_EXCL claim
file so a task never overlaps itself across threads or processes;
- state per (profile, plugin, task) in <plugin data dir>/idle-tasks/<name>.json
(last_run_at, run_count, paused, last_summary, last_status, last_error);
a manager polled outside its own home runs nothing;
- exceptions are logged and recorded, never raised into housekeeping;
- the registration is a PluginRegistration, so unload stops the polling;
- `hermes plugins idle-tasks [plugin] [--pause TASK | --resume TASK]`.
fn receives plain data (name, idle_for_seconds, last_run_at, run_count) and
reaches its ctx through its closure, so the payload also crosses the isolated
plugin host. No capability: the scheduler only calls the plugin's own
function; model calls inside it go through ctx.llm's existing gate.
plugins.py and gateway/run.py are over the file-size cap, so the mixin lives
in hermes_cli/plugins_idle_tasks.py and neither file grows.
A plugin storing or uploading a link like /resume?token=<secret> kept a
working credential, because redact_sensitive_text leaves opaque URL
query credentials alone unless redact_url_credentials=True. Text a
plugin scrubs is exactly the "leaves the machine" case that every
core egress caller already passes it for.
Plugins that store or upload text (session sharing, edit capture) need Hermes's
own scrubber at its strongest setting, and today the only way is a private
import of agent.redact, which the catalog flags. Add a thin PluginContext
method: non-reusable sentinels for prefixed keys, masked credential
assignments, plugin-registered patterns included, security.redact_secrets
honoured unless force=True.
The duplicate check refused any overlapping registration in a profile, so a
plugin calling ctx.register_session_env twice for the same name now failed
to load, where it used to load with the later registration's value winning.
Registrations now record their owning plugin (PluginContext passes its
plugin id). Only another plugin claiming a held name is refused, naming the
holder. One plugin's overlapping registrations stack as before: the later
live one's value wins, and disposing either leaves the other's value.
Registrations are keyed by a token again, as before.
The eleven register_<category>_provider methods (register_image_gen_provider,
register_web_search_provider, register_secret_source, ...) were attached to
PluginContext by a setattr loop at import time, so text search, IDE completion
and type checkers could not find them.
Each one is now a def in the class body that calls register_scoped_provider()
with its row of the existing table. The scoped_provider_registrar decorator
gives it the row's docstring and the same replacement transaction the
generated method had, and the abandoned-load guard loop still wraps it, so
name, qualname, signature, docstring, wrapper chain and behaviour match main.
make_scoped_provider_registrar and _SCOPED_PROVIDER_REGISTRARS keep working
and stay importable from hermes_cli.plugins and hermes_cli.plugins_registrars.
Rename hermes_cli/plugin_context.py to hermes_cli/plugins_context.py (and its
test to tests/hermes_cli/test_plugins_context.py) so it sits in the
plugins_<topic>.py sibling family that the facade grep convention covers.
Regenerate the plugin_api.json source label and public-api.md.
Stop re-exporting _ignore_after_abandoned_load from hermes_cli.plugins:
nothing reads it through the facade, and internal moves do not get shims.