Before the one-gateway runtime each classic CLI loaded its own plugins, so
ctx.inject_message(text) without a session key meant that CLI's own chat.
On a gateway session the classic CLI now loads no plugin code (PLG-7): the
only copy of a plugin is the gateway's (or its plugin host's), which serves
every session of its profile, so a key-less inject had no chat to target
and was refused.
The gateway now picks the target, in order:
1. The plugin is handling a local session's own call (its slash command, a
hook fired for that session, a tool or hook in its turn): the message
goes to that session. The key is read from the calling context, so this
never guesses, however many sessions are open. pre_command deliveries
now bind the session they fire for. Under plugins.isolation: host the
forwarded ctx call already runs in its caller's context.
2. No session in the calling context (a timer, the plugin's own thread):
the one local session of the plugin's profile launched by the classic
CLI (frozen policy source "cli") with a viewer attached. TUI, Desktop,
messaging and other profiles' sessions are never picked this way.
3. Otherwise (none, or several): refused. inject_message returns False,
nothing is injected, and one warning per plugin and reason (rate
limited) names the plugin and says to pass a session key.
A resolved target is committed through the keyed path's producer
admission: a queued input in that session's FIFO, run once and in order.
A key-less call made for a messaging chat keeps main's refusal; a keyed
inject is unchanged; allow_gateway_injection is still required.
The classic chat view's client-side inject slot (gateway_chat_inject) is
removed: nothing in that process calls it any more. Off the gateway the
in-process _cli_ref path is unchanged. The plugin guide describes the three
rules and recommends passing a session key.
Refs #134889 (PLG-7)
Refs #139523
Refs #139847
Since the one-gateway runtime, plugin hooks and tools of classic CLI,
TUI and Desktop sessions run in the gateway process. Plugins written for
the CLI broke there:
- inject_message() with neither session_key nor origin was refused. A
hook or tool running for a classic CLI session now resolves that
session's key from the turn context, and the text is committed to its
FIFO through the local session's own source and adapter (local
sessions have no messaging allowlist). allow_gateway_injection is
still required. Keyed injection into a local session is refused unless
the session authority registered for the calling plugin's own profile
holds that live session; ownership is never resolved through the
ambient profile scope.
- Approval hooks and transports saw surface='gateway' for CLI sessions.
They now report 'cli' again for a classic CLI session's turn. TUI,
Desktop and messaging keep 'gateway', as documented.
- os.getcwd() is the gateway's install root. ctx.session_cwd() and
ctx.session_surface() read the calling session's recorded workspace
and client from the turn's task-local policy. The gateway process is
never chdir-ed.
print() going to gateway-stdio.log and input() getting EOF are intended
differences, now documented in the plugin guide.
Refs #134889 (LC-5)
Refs #139523
`ctx.inject_message` could only reach an existing gateway session (`session_key`), so an
orchestrator plugin that opens a chat/thread itself (a bot-authored Discord forum post never
comes back as an inbound message) had no way to get an agent turn there.
`origin` takes the SessionSource.to_dict() shape. The gateway creates (or continues) that chat's
session through the adapter's normal message path, in the profile whose plugin manager loaded the
plugin, and the reply goes back to the origin chat:
- Profile: resolved from the manager's immutable home, never an ambient one. The origin may not
name another profile, the gateway's own routing for that chat through that profile's adapter
must land in the plugin's profile, and the profile needs its own connected adapter for the
platform (another profile's bot is never borrowed). Refusals are synchronous False + one log line.
- Authorization: same current-allowlist check as the session_key path (no bypass for host code).
- Multiplex: handle_message runs inside the profile's runtime scope so the spawned turn AND the
reply send after it inherit that profile's home and secrets (applies to the session_key path too,
which used to send from the default loop context).
- allow_gateway_injection is read from the plugin's own profile config.
- Plugin/system turns (event.internal) skip the human first-contact notes (onboarding intro and
the "no home channel" nudge), which were posted into the plugin's fresh thread.
Requested by canonicle-desk in #132609.
Closes#132609