Files
e48591bd82 feat: bot message policy, message lifecycle hooks, command routing and Chat rename (supersedes #2831, #2833) (#2966)
* feat(bot): support direct binding of plugin commands (LANG-240)

Co-authored-by: multica-agent <github@multica.ai>

* fix(bot): address review feedback on command routing and migration (LANG-240)

- Remove redundant cmd_mgr.is_admin call in routing layer
- Move legacy YAML command config migration to startup build_app stage with idempotency flag
- Validate that command_settings.plugins are installed in current workspace
- Cache bot command_settings in memory via platform_mgr helper
- Wrap command matching and execution inside _run_event_delivery for cloud tenant scope
- Preserve original launcher_id type in session resolution

Co-authored-by: multica-agent <github@multica.ai>

* style(bot): apply ruff format to command routing changes (LANG-240)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* wip(command): command processor instances and per-command config (LANG-238)

Work in progress handed off for completion; backend and tests are done,
web pieces are partially written and not yet type-checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(command): complete command processor configuration UI

Co-authored-by: multica-agent <github@multica.ai>

* fix(command): retain saved bot command settings when editing

Co-authored-by: multica-agent <github@multica.ai>

* test(command): exclude command instances from runner operations

Co-authored-by: multica-agent <github@multica.ai>

* test(command): verify bot prefixes and manage async test lifecycle

Co-authored-by: multica-agent <github@multica.ai>

* feat(platform): register Telegram and Discord plugin commands

Co-authored-by: multica-agent <github@multica.ai>

* fix(platform): align registration metadata and selected command diagnostics

Co-authored-by: multica-agent <github@multica.ai>

* fix(plugin): keep platform command refresh best-effort after runner refresh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* refactor(web): simplify bot event routing card with tabs

Split routes, plugin commands and plugin processors into tabs, collapse
the supported events panel into a dialog, keep rule rows on a stable
two-line grid, and show bound commands as compact chips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* refactor(web): move command prefixes behind a small popover button

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* refactor(web): show commands, routes and plugin processors as separate routing layers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(command): record command processor runs and support debugging

Bot command executions and debug runs are written to the run ledger as
command_processor runs, so processors get run history and traces. Debug
runs a command line once with admin privilege without platform delivery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): command processor logs, debug and plugin marketplace select

Group plugin processors and command processors under a From plugin option
on the processor creation page, redraw the processor type diagrams, add
logs and debugging to the command processor detail page, list installed
and marketplace command plugins with one-click install, and use a Remix
icon for command processors in the sidebar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* test(web): count new command processor locale keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): illustrate processor types with animated scenes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* revert(web): restore original processor line diagrams and add a command one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* test(web): count command diagram locale keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): progressive plugin options and a code-bearing plugin processor diagram

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(web): command plugin wording in the plugin selector

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* test(web): count command plugin selector locale keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* test(pipeline): pin outer-stage behaviour before moving it to the message policy

Baseline cases state a legacy pipeline config and the behaviour it must
produce (group respond rules, access control, ignore rules, content filter,
rate limit, long text, sending, user notices, aggregation). They reach the
stages only through outer_stage_harness, so the same cases keep guarding
behaviour once the configuration moves to the bot.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(message-policy): add the bot message policy schema, runtime and manager

A message policy says which messages a bot answers (trigger), what is checked
on the way in and out (safety) and how replies are sent (output). It keeps the
key names these settings had inside a Messaging (pipeline) config.

- schema: neutral and default policies, bot + route merge, validation, and the
  single legacy conversion (split_legacy_config / restore_legacy_config).
- runtime: the logic of the outer stages, compiled per effective policy
  (admission, group rules, rate limit, content filter, long text, sending).
- manager: resolves the policy of a bot route and caches the compiled runtime
  per bot and route; the debug chat and unknown bots get the neutral policy.

Group respond rules and the rate limit gain an explicit enabled switch so a
policy can express "do nothing"; converted legacy settings state it as on.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(message-policy): store policies on bots and migrate them out of Messaging

- bots.message_policy (JSON) and an optional policy override on each route in
  event_bindings; BotService validates both. A route resubmitted without the
  policy key keeps its stored override, so older clients cannot drop it.
- Migration 0049: existing bots get the neutral policy and every route to a
  Messaging processor receives that processor's former settings as its
  override; the moved keys are kept verbatim in
  legacy_pipelines.message_policy_backup and restored on downgrade.
- Messaging writes accept and ignore trigger / safety / general output keys;
  its template and form metadata keep only AI, speech and AI-specific output.
- New bots start with the defaults new Messaging processors used to get.
- GET /api/v1/platform/bots/_/message-policy/metadata serves the form metadata;
  MCP bot tools describe message_policy and route overrides.
- The group-filter migration helper reads and updates the route policy.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* refactor(pipeline): run the outer stages through the message policy runtime

Stage order and position are unchanged. The group rule, access control,
content filter, rate limit, long text and send stages become thin shells over
the policy runtime of the route a message matched; user notices and the
scheduler's steering gate use it too. The effective policy is laid over
query.pipeline_config under the legacy key names, so plugins reading those
keys keep working. Message aggregation reads the policy as well.

The matched route id travels from routing through the aggregator to the query
(_message_route_id, host-reserved). Messages that reach Messaging without one
(web page widget, form callbacks) use the bot's first route to that processor.

The baseline cases now run on legacy configs converted the way the migration
converts them.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* chore(persistence): renumber message policy migrations after master (0054-0056)

Master added 0047-0053, so the bot command settings, platform command sync
and bot message policy migrations now follow 0053_knowledge_artifact_sources.
Also bind a message policy in the agent run recovery test, whose replayed
output stages now read output and safety settings from the bot route.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(sdk): expose command processor configuration in execution contexts

Co-authored-by: multica-agent <github@multica.ai>

* feat(bot): dispatch plugin lifecycle hooks with route-scoped query and policy

Co-authored-by: multica-agent <github@multica.ai>

* fix(messaging): dispatch received hooks for direct pipeline queries

Co-authored-by: multica-agent <github@multica.ai>

* fix(messaging): tolerate queries without bound plugins in the received-hook fallback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(messaging): apply bot policies to agent delivery

Co-authored-by: multica-agent <github@multica.ai>

* feat(web): bot plugins and message policy tabs, Chat rename

- Bot event routing becomes three tabs: Routes, Plugins, Message policy.
- Plugins tab: message lifecycle strip (received → command → admission →
  before reply → process → after reply → send) with the enabled plugins
  acting at each step; one row per plugin with its switch, command tags and
  hook tags. Hooks a route cannot use are struck through with the reason
  (prompt hooks on Agent routes, observe-only after-reply hook when
  streaming). Enable-all switch plus manual selection, as on Chat. Command
  settings and plugin processors live in the same tab.
- Message policy tab: entry / safety / reply forms from the policy metadata,
  bot default or per-route override (use default / custom), route overview,
  "make bot default" which also clears routes left identical to it.
- New routes show a hint that they inherit the bot policy.
- Chat editor drops Trigger and Safety; Output keeps AI-only options with a
  pointer to the bot policy; the plugin list is "Tools the AI can call".
- Installing a plugin with commands or listeners reports on how many bots it
  is enabled, or offers to go enable it.
- User-visible "Pipeline/流水线" renamed to "Chat/聊天" in all eight WebUI
  locales (identifiers, paths and keys unchanged).
- plugin-registrations (HTTP and MCP) accepts include_disabled to list every
  installed plugin for the editor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(i18n): call the pipeline Chat in backend user-facing text

Default name, runner authorization notice, operation catalog labels and
summaries, alert email rule label, adapter streaming descriptions and
MCP tool descriptions say Chat (pipeline). Identifiers keep pipeline.
The group filter migration tools describe the message-policy at-bot rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): finish the Chat rename in locales and the migration dialog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* chore(sdk): regenerate workspace proxy for monitoring.sessions launcher_id

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* docs: message lifecycle events, bot message policy and the Chat rename

- Plugin docs: 'Pipeline events' become message lifecycle events with
  the lifecycle order, where plugins are enabled, which processors each
  hook applies to, known limits and platform notifications.
- Command docs: matching before routes, route policy, *CommandSent.
- Bots page: event routing tabs, plugin enablement, message policy.
- Chat page and the rest of docs/ (zh/en/ja, regenerated recipes) use
  Chat instead of Pipeline; URLs and identifiers are unchanged.
- langbot-mcp-ops skill, ARCHITECTURE.md and dev-docs/architecture/
  message-policy.md describe the new contracts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(bot): keep the platform command clear in update_bot after the master merge

The merge carried the branch's platform-command check into master's new
_apply_bot_configuration, where update_data does not exist, so every
runtime-affecting bot update returned 500. Run the check in update_bot
before applying. Command admin checks now pass the sender ID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* test(persistence): register all entities in the startup command migration test

The test created bots without the tables its foreign keys reference and
only passed when other tests had imported those entities first. Also
apply prettier to AgentCreateContent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(messaging): use one listener list per query when no bot policy applies

Queries entering a Chat without a bot (debug chat, pipeline.run) bound
the neutral policy, so later hooks went to every plugin while the
fallback *MessageReceived used the Chat's plugin list. Use the Chat's
list for all hooks there. The contract test now carries the plugin
selection the way migration 0060 stores it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): move plugin command settings into the plugin list

Drop the separate plugin command binding section from the bot's Plugins tab.
The command switch and prefixes now sit in the plugin list header, per-bot
command settings open from a plugin's row (only when its commands declare
spec.config), and platform command registration follows the enabled plugins.

Duplicate command names now resolve in the order of the bot's effective plugin
list, the same order lifecycle hooks run in; the WebUI keeps that list in
display order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): mark plugin hook badges with the event listener icon

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): explain AI routes versus plugin handling on the bot tabs

Routes now say they send events to configurable LangBot processors that use
AI, and that a plugin-only bot can delete or disable its routes. The Plugins
tab explains that plugins handle their lifecycle steps as each plugin defines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): optional route notes and auto-described routes

Routes get an optional note, edited in the route's expanded panel and shown
under the route. Wherever routes are listed (scope picker, policy route list)
a second line now says when the route applies, derived from its conditions,
plus its target when the name is a note, so routes stay distinguishable
without any user input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): compact route cards and labelled message template routes

Saved routes collapse to a two-line summary (note or processor, then event,
conditions and target); event, conditions, processor and note are edited in
the expanded card. Unsaved routes open expanded. The "Reply to messages"
template and the setup wizard now label their routes as private messages and
group messages that mention the bot.

Also move the plugin processor compatibility e2e onto the Plugins tab, where
plugin processors live since the message policy refactor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): keep bot-wide command settings read-only on route scope

The plugin command switch, prefixes and per-plugin command settings apply to
the whole bot, so they are read-only (with a hint) while a route is selected.
Turning commands off crosses out every command badge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* style(bots): make the crossed-out command badges easier to see

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(agents): stop offering command processors on the create page

Command settings are created from a plugin's row on the bot's Plugins tab.
The "From plugin" card now selects plugin processors directly; existing
command processors keep their detail page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): install plugin processors from the marketplace in place

The add-plugin-processor dialog's new-configuration tab keeps the installed
processor list (with event compatibility) and adds a marketplace picker for
plugins that declare processor support; installing one selects it. Bound and
existing processors show their plugin icon, and the empty state points to the
marketplace. Plugin-subscription e2e now opens the Plugins tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(plugins): point command and listener plugins to bots after install

Commands and event listeners are enabled on a bot's Plugins tab now, so the
post-install next step for them links to bots; tools still lead to a Chat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(bots): pick plugin processors from a single picker

The new-configuration tab drops the separate installed-processor list: one
picker lists installed processors and marketplace plugins (installable in
place), and the chosen processor's events and compatibility show below it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(plugins): show next steps on first visit and reload after confirming permissions

- The plugin detail page opens a next-steps dialog the first time a ready
  plugin is visited (remembered per plugin).
- After permissions are confirmed, the page polls until the plugin is mounted
  and remounts its settings, readme and log panels, so no manual refresh is
  needed.
- The install dialog shows next steps under the permission-review link
  instead of hiding them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(plugins): say why plugin settings and docs are unavailable

While a plugin waits for permission confirmation its settings and docs cannot
load; show a dedicated notice pointing to Plugin permissions (or a starting
indicator while it boots) instead of the generic load error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(plugins): confirm permissions inside the install dialog

A plugin awaiting permission review now shows the permission card in the
install dialog; granting there opens the usual confirmation, and the dialog
then switches to the success banner with its next steps. The first-visit
next-steps popup on the plugin page is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(plugins): show next steps right after granting in the install dialog

The plugin restarts after a grant, so re-reading it could fail or still report
pending, leaving the dialog on the review banner. Trust the successful grant,
keep the already loaded manifest, and retry loading it if it was missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(plugins): treat initialized plugins as running on the detail page

The runtime moves plugins unmounted -> mounted -> initialized; initialized is
the ready state. The detail page only accepted mounted, so running plugins
showed "starting" forever. Also fix the misspelled status in the type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(plugins): re-read the plugin until it lists components before showing install next steps

A plugin awaiting permissions is not started and reports no components, so
the post-grant guide stayed empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): add bot plugins from a list and the Marketplace; rename event listeners to chat event hooks

The bot Plugins tab now lists added plugins as cards (all of them when
'enable all' is on) instead of per-plugin switches, with an Add plugin
dialog for installed plugins and Marketplace plugins that provide commands
or chat event hooks. EventListener is shown as 'Chat event hook' in the UI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): with all plugins enabled, the bot plugin list offers installing new plugins only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): bot plugin Marketplace tab lists only uninstalled or updatable plugins

Installed plugins with a newer Marketplace version get an inline Update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(web): no 'not enabled on any bot' toast for plugins installed from a bot's plugin list

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): move plugin dev docs link from the routing help popover to the Plugins tab

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): open a plugin's settings page from its card in the bot plugin list

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): describe commands, chat event hooks and plugin processors by how each handles events

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): drop the route overview list from the bot message policy tab

The scope selector already marks which routes are customised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): regroup bot message policy settings by what the owner decides

The policy tab now groups settings into who gets replies, how messages are
read, safety and rate limits, how the bot replies, and what happens on
errors. Each setting shows a plain-language summary and expands to purpose-
built controls; stored trigger/safety/output keys are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* refactor(web): use shadcn Button and Label for this branch's new UI

Replace raw button, link and label elements added on this branch with
shadcn Button (ghost / link / asChild) and Label.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(commands): add bot system commands and sender permissions

Co-authored-by: multica-agent <github@multica.ai>

* fix(commands): honor session model, replay text turns and gate denial replies

Co-authored-by: multica-agent <github@multica.ai>

* feat(web): one-page Chat settings with prompt, tools and knowledge up front

Replace the Chat editor's section tabs with a single page: the runner,
then primary blocks for model, prompt, tools (summary + side sheet) and
knowledge, then folded rows with one-line summaries for context, run
limits, sandbox, speech, reply content, notices, advanced and manage.
Runner fields are placed by type and name, so any runner works; values and
stored keys are unchanged. Folded rows stay mounted so invalid drafts still
block saving. SettingRow/SettingGroup are shared with the bot policy tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(web): keep folded setting rows mounted but hidden

Radix forceMount forces content open; render the row body ourselves with
the hidden attribute so folded rows stay collapsed while their fields keep
validating.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): system commands and command permissions in the bot Plugins tab

A small 'System commands · n/m' entry in the command bar opens a sheet with
the admin list (person_ IDs, /whoami hint), the no-permission reply, every
built-in command's switch and permission grouped by session/info/admin,
and per-command permissions for enabled plugins' commands. Admin-only plugin
commands show a lock on their chips; the lifecycle Command step marks the
system commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): one-page Agent settings matching the Chat layout

Replace the Agent editor's Runner / Events & tools tabs with one page: the
runner, then model and prompt, the events the Agent handles, a tool access
summary (editing in a side sheet), knowledge and runner settings, then
folded rows for context, run limits, sandbox and advanced fields. The
runner field layout is shared with Chat (runner-layout/RunnerConfigLayout).
Loading fills the active runner's schema defaults before the clean snapshot,
so required-field status and revert-to-clean keep working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): 'Plugins & commands' tab with its own Commands section

Rename the bot tab to Plugins & commands. Commands get their own section
above plugins: one global switch, the shared prefixes (with an example, as
they apply to system and plugin commands alike), the system commands entry
and the plugin command list. Admins are no longer edited in the system
commands sheet; it shows the bot admin count and links to the session
monitor where admins are managed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): give system and plugin commands their own sheets

The System commands sheet now lists only built-in commands; plugin command
access moves to a 'Set access' sheet on the plugin commands row. Admins and
the no-permission reply apply to both kinds, so they become rows of the
Commands section instead of living in the system sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(web): keep dividers between command access rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): link plugin processor dev docs from the processors section

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(commands): use session monitoring admins for command permissions

Co-authored-by: multica-agent <github@multica.ai>

* chore(web): drop retired command_settings.admins from the bot command type

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* Record message policy decisions and add workspace upgrade checks

Co-authored-by: multica-agent <github@multica.ai>

* fix(message-policy): queue EssentialCommands uninstall through plugin.delete task

The upgrade-check action called the plugin connector directly, skipping the
tenant-scoped fence and task tracking used by the regular uninstall path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* feat(web): message policy monitoring badges, timeline, route counts and upgrade checks

- Monitoring: handling badges (system/plugin command, denied, policy drop,
  plugin interception), a handling filter (AI / command / plugin / policy)
  and a message policy timeline in the execution detail.
- Backend: executions accept handling= (HTTP + MCP, not plugin-visible) and
  rows carry handling, policy_layer/item, command and hook facts.
- Bot routes show last-24h handling counts.
- Upgrade check banner + Sheet on bot and Chat pages with one-click
  actions, per-item and acknowledge-all; eight locales.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(monitoring): name layer and rule for policy drops recorded before structured fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(web): name command/policy/plugin ingress rows and dedupe output actions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(message-policy): preserve drop notices, Windows fallback, 0060 enabled filter, and ignore-rules hint

Co-authored-by: multica-agent <github@multica.ai>

* docs(message-policy): update trilingual user, upgrade, telemetry and command docs

Co-authored-by: multica-agent <github@multica.ai>

* Document bot command permissions and Chat event hooks in skills

Co-authored-by: multica-agent <github@multica.ai>

* Distinguish Chat debugging from bot admission tests

Co-authored-by: multica-agent <github@multica.ai>

* Navigate to Chats from Processors in skills and QA flows

Co-authored-by: multica-agent <github@multica.ai>

* Restore bot ingress tracing and align CI with route-owned message policies

Co-authored-by: multica-agent <github@multica.ai>

* fix(web): stop the bot plugins tab crashing without runtime registrations; align e2e with the Chat UI

pluginCommandList read descriptorMap before its declaration, so the Plugins &
commands tab threw a TDZ error whenever an enabled plugin had no Runtime
registration (older Runtimes). Compute it after the map.

Update stale Playwright specs to the current UI: Chat migration labels,
one-page Chat editor (no AI tab, Runner field), 'Create processor' heading,
and the in-dialog permission review after plugin installation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(telemetry): count builtin_disabled_bots only for built-ins turned off from their default

/model is off by default, so counting any disabled built-in counted every
bot and the heartbeat field carried no signal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(migration): preserve empty legacy chat settings on downgrade

Co-authored-by: multica-agent <github@multica.ai>

* fix(migration): initialize bot policies when resuming 0059

Co-authored-by: multica-agent <github@multica.ai>

* test(commands): exercise LocalAgent over signed HTTP ingress

Co-authored-by: multica-agent <github@multica.ai>

* fix(api): report ignored legacy settings in chat copy requests

Co-authored-by: multica-agent <github@multica.ai>

* test(commands): cover alternate prefixes and unrouted group commands

Co-authored-by: multica-agent <github@multica.ai>

* fix(web): policy timeline says MessageReceived already ran when admission blocks

MessageReceived fires at the bot entry before admission, so a policy drop
still ran it. The hooks step now says so instead of 'not run'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* fix(commands): consume silently denied commands before primary routing

Co-authored-by: multica-agent <github@multica.ai>

* Test upgrade assistant actions and command telemetry against a local Core

Co-authored-by: multica-agent <github@multica.ai>

* Verify lifecycle hooks and command bypass during message aggregation

Co-authored-by: multica-agent <github@multica.ai>

* Verify native Agent reply chunks and proactive delivery through signed callbacks

Co-authored-by: multica-agent <github@multica.ai>

* Cover subscriber replies on denied ingress and concurrent command rate limits

Co-authored-by: multica-agent <github@multica.ai>

* Verify LocalAgent records missing model failures for signed messages

Co-authored-by: multica-agent <github@multica.ai>

* Skip runtime synchronization for empty event selections after validating workspace scope

Co-authored-by: multica-agent <github@multica.ai>

* Verify route access overrides, removal and telemetry using signed bot messages

Co-authored-by: multica-agent <github@multica.ai>

* Exercise signed command admission and reply policies in a running Core

Co-authored-by: multica-agent <github@multica.ai>

* Compare dashboard debug chat with signed messages on the same Chat

Co-authored-by: multica-agent <github@multica.ai>

* Validate unavailable Agent runners and verify native quotes and Agent policy traces

Co-authored-by: multica-agent <github@multica.ai>

* Correlate successful Agent output with telemetry and exercise command hook order

Co-authored-by: multica-agent <github@multica.ai>

* Honor Chat exception policy for Runner failures and verify streaming observers

Co-authored-by: multica-agent <github@multica.ai>

* Verify OneBot membership events bypass message admission and reply policies

Co-authored-by: multica-agent <github@multica.ai>

* Exercise command name precedence and processor instance isolation in runtime

Co-authored-by: multica-agent <github@multica.ai>

* Accept ISO source times in runner events and verify long-text boundaries

Co-authored-by: multica-agent <github@multica.ai>

* Compare Chat output filtering on OneBot and HTTP Bot

Co-authored-by: multica-agent <github@multica.ai>

* Trace matched deliveries intercepted by message listeners

Co-authored-by: multica-agent <github@multica.ai>

* Record Chat execution owner with the first success update

Co-authored-by: multica-agent <github@multica.ai>

* Admit matched commands before recording listener interception

Co-authored-by: multica-agent <github@multica.ai>

* Handle stop on a Chat without a Runner and verify built-in command permissions

Co-authored-by: multica-agent <github@multica.ai>

* Link command processor runs to ingress routes and identify denied plugin commands

Co-authored-by: multica-agent <github@multica.ai>

* Report ignored legacy operation keys and limit Runner error replies to a redacted summary

Co-authored-by: multica-agent <github@multica.ai>

* style(web): wrap long monitoring timeline strings for prettier

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

* Dispatch QA Runner by envelope type and verify remaining command conflicts after uninstall

Co-authored-by: multica-agent <github@multica.ai>

* fix(persistence): chain bot command settings after master's 0057 migration

master added 0057_agent_event_index on top of 0056, which left two Alembic
heads. Run 0057_bot_command_settings after it; revision ids are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>

---------

Co-authored-by: multica-agent <github@multica.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 08:20:44 +08:00

302 lines
10 KiB
Python

"""
Unit tests for operator module - REAL imports.
Tests the operator_class decorator and CommandOperator base class.
"""
from __future__ import annotations
import pytest
from langbot.pkg.command import operator
class TestOperatorClassDecorator:
"""Tests for operator_class decorator."""
def setup_method(self):
"""Save and clear preregistered_operators before each test."""
self._saved_operators = operator.preregistered_operators.copy()
operator.preregistered_operators.clear()
def teardown_method(self):
"""Restore preregistered_operators after each test."""
operator.preregistered_operators.clear()
operator.preregistered_operators.extend(self._saved_operators)
def test_decorator_sets_name(self):
"""Decorator sets command name on class."""
@operator.operator_class(name='test_cmd')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.name == 'test_cmd'
def test_decorator_sets_help(self):
"""Decorator sets help text on class."""
@operator.operator_class(name='test', help='Test help message')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.help == 'Test help message'
def test_decorator_sets_usage(self):
"""Decorator sets usage text on class."""
@operator.operator_class(name='test', usage='!test <arg>')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.usage == '!test <arg>'
def test_decorator_sets_alias(self):
"""Decorator sets alias list on class."""
@operator.operator_class(name='test', alias=['t', 'tst'])
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.alias == ['t', 'tst']
def test_decorator_sets_privilege_default(self):
"""Decorator sets default privilege to 1 (normal user)."""
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.lowest_privilege == 1
def test_decorator_sets_privilege_admin(self):
"""Decorator sets privilege to 2 for admin commands."""
@operator.operator_class(name='admin_cmd', privilege=2)
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.lowest_privilege == 2
def test_decorator_sets_parent_class_none(self):
"""Decorator sets parent_class to None for top-level commands."""
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator.parent_class is None
def test_decorator_sets_parent_class(self):
"""Decorator sets parent_class for sub-commands."""
@operator.operator_class(name='parent')
class ParentOperator(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='child', parent_class=ParentOperator)
class ChildOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert ChildOperator.parent_class is ParentOperator
def test_decorator_registers_to_preregistered_list(self):
"""Decorator appends class to preregistered_operators."""
@operator.operator_class(name='test1')
class TestOperator1(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='test2')
class TestOperator2(operator.CommandOperator):
async def execute(self, context):
yield None
assert TestOperator1 in operator.preregistered_operators
assert TestOperator2 in operator.preregistered_operators
def test_decorator_requires_command_operator_subclass(self):
"""Decorator asserts class is subclass of CommandOperator."""
with pytest.raises(AssertionError):
operator.operator_class(name='invalid')(object)
class TestCommandOperatorBase:
"""Tests for CommandOperator base class."""
def setup_method(self):
"""Save and clear preregistered_operators before each test."""
self._saved_operators = operator.preregistered_operators.copy()
operator.preregistered_operators.clear()
def teardown_method(self):
"""Restore preregistered_operators after each test."""
operator.preregistered_operators.clear()
operator.preregistered_operators.extend(self._saved_operators)
def test_init_sets_app(self):
"""__init__ stores application reference."""
class MockApp:
pass
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
app = MockApp()
op = TestOperator(app)
assert op.ap is app
def test_init_sets_empty_children(self):
"""__init__ initializes empty children list."""
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
op = TestOperator(None)
assert op.children == []
def test_class_has_required_attributes(self):
"""CommandOperator has required class attributes."""
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert hasattr(TestOperator, 'name')
assert hasattr(TestOperator, 'alias')
assert hasattr(TestOperator, 'help')
assert hasattr(TestOperator, 'usage')
assert hasattr(TestOperator, 'parent_class')
assert hasattr(TestOperator, 'lowest_privilege')
@pytest.mark.asyncio
async def test_initialize_is_async_noop(self):
"""Default initialize() is async no-op."""
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
op = TestOperator(None)
await op.initialize()
def test_execute_is_abstract(self):
"""execute() must be implemented by subclass."""
# Cannot instantiate abstract class
with pytest.raises(TypeError):
operator.CommandOperator(None)
def test_path_not_set_by_decorator(self):
"""path is not set by decorator, set by CommandManager."""
@operator.operator_class(name='test')
class TestOperator(operator.CommandOperator):
async def execute(self, context):
yield None
# path should not exist initially
assert not hasattr(TestOperator, 'path') or TestOperator.path is None
class TestMultipleOperators:
"""Tests for multiple operator registration and hierarchy."""
def setup_method(self):
"""Save and clear preregistered_operators before each test."""
self._saved_operators = operator.preregistered_operators.copy()
operator.preregistered_operators.clear()
def teardown_method(self):
"""Restore preregistered_operators after each test."""
operator.preregistered_operators.clear()
operator.preregistered_operators.extend(self._saved_operators)
def test_multiple_independent_operators(self):
"""Multiple independent operators can be registered."""
@operator.operator_class(name='help')
class HelpOperator(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='status')
class StatusOperator(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='version')
class VersionOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert len(operator.preregistered_operators) == 3
names = [op.name for op in operator.preregistered_operators]
assert 'help' in names
assert 'status' in names
assert 'version' in names
def test_parent_child_hierarchy(self):
"""Parent-child hierarchy can be established."""
@operator.operator_class(name='plugin')
class PluginOperator(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='list', parent_class=PluginOperator)
class PluginListOperator(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='install', parent_class=PluginOperator)
class PluginInstallOperator(operator.CommandOperator):
async def execute(self, context):
yield None
# Both parent and children are in preregistered list
assert len(operator.preregistered_operators) == 3
# Parent-child relationships are established via parent_class
plugin_op = next(op for op in operator.preregistered_operators if op.name == 'plugin')
list_op = next(op for op in operator.preregistered_operators if op.name == 'list')
install_op = next(op for op in operator.preregistered_operators if op.name == 'install')
assert plugin_op.parent_class is None
assert list_op.parent_class is PluginOperator
assert install_op.parent_class is PluginOperator
def test_privilege_inheritance_not_automatic(self):
"""Child operators do not automatically inherit parent privilege."""
@operator.operator_class(name='admin', privilege=2)
class AdminOperator(operator.CommandOperator):
async def execute(self, context):
yield None
@operator.operator_class(name='sub', parent_class=AdminOperator, privilege=1)
class SubOperator(operator.CommandOperator):
async def execute(self, context):
yield None
assert AdminOperator.lowest_privilege == 2
assert SubOperator.lowest_privilege == 1