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

7.9 KiB
Raw Permalink Blame History

共享契约 usage-telemetry-v1(三个子任务都必须严格遵守,改动须先在父 issue LANG-492 提出)

背景和决策见父 issue LANG-492 的设计评论。Rock 已确认:

  • 自部署实例按天汇总即可;
  • lbctl 要做到命令级;
  • 不做任何纯前端漏斗/前端埋点;
  • 用量明细保留 180 天。

原则:不新增上报请求,也不新增原始上报行。用量计数放在进程内存里,作为差值随现有 instance_heartbeat 一起发送。不采集任何用户内容:KB、文件、prompt 的名称,query,文件名,URL 和错误 message 都不发。

1. heartbeat 新增字段(features 内)

{
  "usage": {
    "v": 1,
    "batch_id": "<uuid4,每个待发批次一个;重发同一批次时沿用原 id>",
    "since": 1731628800,           // 这批计数的起始 unix 秒
    "c": [["kb.file.ingest", {"engine":"langbot/rag-engine","parser":"builtin","ext":"pdf","outcome":"ok","err":"","dur":"<60s"}, 12]]
  },
  "kb_engines": ["author/name", ...],   // 当前已加载 KB 用到的引擎插件 ID,去重,最多 16 个
  "kb_file_count": 123,                 // 无法得到时为 -1(Cloud runtime 和其他资源计数一样给 -1)
  "deploy_source": "lbctl",             // 取环境变量 LANGBOT_DEPLOY_SOURCE,只接受 ^[a-z0-9_-]{1,32}$,否则省略
  "deploy_tool_version": "0.4.1",       // 取 LANGBOT_DEPLOY_TOOL_VERSION,只接受 ^[0-9A-Za-z.+_-]{1,32}$,否则省略
  "lbctl_versions": ["0.4.1"]           // 本批次内见过的 lbctl UA 版本,最多 5 个
}
  • c 是 [metric, dims, count] 三元组列表。每个 Workspace 每批最多 256 条。
  • dims 的 key 和 value 都只能取下表白名单。value 是不超过 64 字符的字符串,空值用 ""。
  • count 是 1..1000000 的整数。
  • 只有一个周期内没有任何计数时才省略 usage。

2. metric 白名单(Core 只发这些,Space 只收这些,其余丢弃)

metric dims(全部必填,按此顺序) 取值
api.call group, method, client, status group = RouterGroup.name;method = GET/POST/PUT/PATCH/DELETE;client = webui / lbctl / mcp / api_other;status = 2xx/3xx/4xx/5xx
lbctl.cmd cmd, status cmd 取 X-LangBot-Client-Command,须匹配 ^[a-z0-9-]+(\.[a-z0-9-]+){0,5}$ 且 ≤64 字符,否则记为 other;status 同上
lbctl.client version, os 解析自 User-Agent: lbctl/<version> (<os>/<arch>);version 规则同 deploy_tool_version;os = linux/darwin/windows/other
kb.create / kb.update / kb.delete engine engine = knowledge_engine_plugin_id(author/name),截断到 64 字符
kb.file.upload engine, ext, size ext = pdf/docx/doc/md/txt/html/xlsx/csv/pptx/json/zip/other;size = <1M / <10M / <50M / >=50M
kb.file.ingest engine, parser, outcome, err, dur parser = builtin/plugin;outcome = ok/failed/cancelled;err = 异常类名(匹配 ^[A-Za-z0-9_.]{0,64}$,成功时为 "");dur = <10s / <60s / <5m / >=5m
kb.file.delete engine
kb.retrieve engine, origin, outcome, hit, dur origin = pipeline/agent/plugin/webui_test/api;outcome = ok/failed;hit = empty/nonempty;dur = <500ms / <2s / <10s / >=10s
kb.migration.run outcome ok/failed
ugc.share.preview type prompt/skill/mcp/plugin
ugc.share.submit type, mode, outcome, err mode = new/update;outcome = ok/failed;err 同上
ugc.library.browse kind messaging/agent/other
ugc.prompt.apply kind 同上
ugc.install type, source, outcome, unfilled type = plugin/mcp/skill;source = market/community/local/github/other;outcome = ok/failed;unfilled = yes/no(仅 MCP 有意义,其他填 no)
alert.state enabled, channel enabled = yes/no;channel = auto/instance/space/off
alert.settings.update enabled, channel 同上
alert.incident rule, event rule = pipeline_failures/model_failures/bot_offline/other;event = opened/resolved
alert.delivery notice, via, outcome notice = fired/reminder/resolved/test;via = email/space/webhook;outcome = ok/failed/rate_limited

告警扩展(LANG-508):alert.state 在每个 Workspace 的 heartbeat 构建时、取 usage 批次前计一次;只有实例和工作区同时启用时 enabled=yes,无设置行时采用 default_enabled()(默认关闭),channel 为保存的 email_channel。设置读取使用缓存,最多等待一秒;不可用时跳过,不影响心跳。alert.settings.update 在成功保存后使用工作区保存值计一次。

alert.incident 只计成功 INSERT 的 opened,以及 UPDATE 实际从 firing 转为 resolved 的行数(包括静默自动恢复);重复触达、唯一约束冲突、0 行更新不计。多副本各自只计本副本成功的数据库变更。alert.delivery 按 dispatch(含测试发送)保存的每条投递记录计一次,sent 映射为 ok,失败和限流保留对应值。

告警维度非法值仅 rule 归一化为 other,其余丢弃整个计数;rate_limited 只允许用于 alert.delivery。批量增量必须是正整数,单次最多 1000000,仍遵守 256 个 key 上限和原有确认语义。关闭遥测时不记录任何告警计数,也不为心跳读取告警设置。仅上报上述枚举,不包含收件人、目标、错误文本或事件详情。

3. Core → Space 的确认语义

  • Core 只在 telemetry.send() 返回 True 时,从计数器里减去已发送的部分。不能直接清零,因为发送期间可能有新的增量。
  • 发送失败时保留该批次(同一个 batch_id),下一次连同新增量一起发。实现方式:把未确认批次和新增量合并成一个新批次,这时生成新的 batch_id。
  • Space 用 telemetry_usage_batches(batch_id) 去重:已见过的 batch_id 直接忽略 usage,但 heartbeat 本身照常处理并返回成功。
  • Space 对非法条目逐条丢弃,绝不能因为 usage 有问题而拒绝整个 heartbeat。

4. 存储与保留(Space)

  • 新表 telemetry_usage_daily(day date, workspace_uuid text, metric text, dims jsonb, dims_key text, count bigint, reporter_trusted bool, updated_at),主键 (day, workspace_uuid, metric, dims_key),count 用 upsert 累加。
    • dims_key 是按 key 排序后的 dims 规范化 JSON。
    • day 取 Space 接收时间的 UTC 日期。
  • 新表 telemetry_usage_batches(batch_id text pk, created_at),保留 7 天。
  • 新表 content_events_daily(day, content_type, item_key, action, count),主键 (day, content_type, item_key, action)。
    • content_type = plugin/mcp/skill/prompt。
    • item_key = author/name。
    • action = view_detail/use/favorite/unfavorite/install/submit/approve/reject/unlist/relist/delete。
  • 原始 heartbeat 行存入 telemetry_events.features 前必须删掉 usage。其余新字段体积很小,保留在 features 里。
  • telemetry_usage_daily 和 content_events_daily 保留 180 天,telemetry_usage_batches 保留 7 天。都复用现有 retention ticker 分批删除。

5. 测试钩子

Core 新增一个未在文档中公开的环境变量 LANGBOT_TELEMETRY_HEARTBEAT_SECONDS(最小 30),用于覆盖 heartbeat 周期,方便 E2E 测试。不设置时行为不变。

Message policy measurements

command.run counts builtin, plugin and processor outcomes (ok, denied, failed, intercepted). Only built-in command names are reported; other names collapse to plugin. The corresponding execution-node family is command with operation builtin:<name>, plugin or processor.

policy.drop and message_policy execution nodes record the rule, bot|route layer and discarded outcome. Rules: access-control, group-respond-rules, rate-limit, ignore-rules, content-filter, outbound-content-filter. hook.intercept identifies the lifecycle event and output.transform the action kind. Suppressed branches and telemetry-disabled instances send none of these observations.