Scope: this file applies to the apps/mewbo_api/ package. It captures runtime behavior, hidden dependencies, and testing notes so changes stay safe and predictable.
Subsystem docs (read the deepest one that applies):
apps/mewbo_api/src/mewbo_api/wiki/CLAUDE.md— MewboWiki BE: phase model, snapshot-vs-stream parity, capability gating, embedder→litellm decision, SSE proxy primer, clone-token cache, prune_pages, KG endpoint.
- Entry point:
apps/mewbo_api/src/mewbo_api/backend.py(HTTP API framework). - Session endpoints:
POST /api/sessionscreate sessionGET /api/sessionslist sessionsPOST /api/sessions/{session_id}/queryenqueue run or core commandGET /api/sessions/{session_id}/events?after=...poll eventsPOST /api/sessions/{session_id}/messageenqueue a user steering message into a running sessionPOST /api/sessions/{session_id}/interruptinterrupt the current tool execution stepGET /api/sessions/{session_id}/agentsreturn sub-agent tree with lifecycle state (status, steps_completed) and total_stepsGET /api/sessions/{session_id}/streamSSE stream for real-time session events (sub_agent, permission, tool_result, etc.)GET /api/projectslist configured projects for multi-project supportGET /api/tools?project=namelist tools scoped to a project's CWDGET /api/skills?project=namelist skills scoped to a project's CWDPOST /api/sessions/{session_id}/archive/DELETE ...archive/unarchivePOST /api/sessions/{session_id}/attachmentsupload attachmentsPOST /api/sessions/{session_id}/sharecreate share linkGET /api/sessions/{session_id}/exportexport session payloadGET /api/share/{token}fetch shared session dataPOST /api/querysynchronous endpoint (simple/CLI-compatible)GET /api/toolslist tool registry entriesGET /api/skillslist available skillsGET /api/pluginslist installed plugins and their componentsGET /api/plugins/marketplacelist available plugins from configured marketplacesPOST /api/plugins/marketplaceinstall a plugin from a marketplaceDELETE /api/plugins/<name>uninstall a pluginPOST /api/sessions/{session_id}/idelaunch a Web IDE (code-server) containerDELETE /api/sessions/{session_id}/idestop the Web IDE containerPOST /api/sessions/{session_id}/ide/extendextend Web IDE session TTLGET /api/notificationslist notificationsPOST /api/notifications/dismissdismiss notificationsPOST /api/notifications/clearclear notifications
- Channel webhook endpoints (HMAC auth, not API key):
POST /api/webhooks/<platform>receive inbound message from a chat platform (e.g.nextcloud-talk). Delegates to the appropriateChannelAdapterfor verification and parsing. Creates/continues sessions using existing session tags.
- Auth: requires
X-API-KEYheader (except webhook endpoints which use platform-specific HMAC verification). Token defaults toapi.master_tokenfromconfigs/app.json(default:msk-strong-password). Also acceptsapi_keyquery parameter for SSE endpoints (EventSource does not support custom headers). - CORS:
after_requesthook setsAccess-Control-Allow-Origin: *for cross-origin console access. - Hooks:
HookManager.load_from_config(_config.hooks)at startup;hook_managerpassed to allstart_async()call sites. Supportstype: "command"andtype: "http"hooks. - Channel adapters:
init_channels(app, runtime, _hook_manager, _config)registers the webhook Blueprint and instantiates adapters fromconfig.channels. Completion callback appended tohook_manager.on_session_end. Channel sessions are standard sessions (MongoDB-backed, visible in console). Session tags:nextcloud-talk:room:<token>,email:thread:<channel_id>:<root-msg-id>. Shared_process_inbound()pipeline used by both webhook endpoint and email IMAP poller. Email adapter:EmailAdapter(IMAP parse, SMTP send, markdown→HTML via mistune) +EmailPoller(daemon thread, configurablepoll_interval_seconds). Email access control:allowed_sendersallowlist +@Mewbomention required in multi-party threads, no mention for 1-to-1. - Channel slash commands: decorator-based
@commandregistry inchannels/routes.py./help,/usage,/new,/switch-project <name>. Adding a command = one decorator + one function;/helpauto-generates from the registry. Commands run without LLM invocation. - Client-aware system prompt: each
ChannelAdapterprovides asystem_contextproperty (brief string) injected viaskill_instructionsparameter tostart_async. The LLM knows which chat interface the conversation flows through. - Plugins:
GET/POST /api/plugins,GET/POST /api/plugins/marketplace,DELETE /api/plugins/<name>. Usesmewbo_core.pluginsfor discovery, install, uninstall. Plugin components (skills, hooks, agent definitions, MCP tools) are loaded during session init viaload_all_plugin_components(). - Web IDE: opt-in per-session code-server containers via
agent.web_ideconfig.IdeManager+IdeStore(MongoDB-backed) inide.py. Routes inide_routes.py. Requires MongoDB. Console shows "Open in Web IDE" button when enabled. - Orchestration: uses
mewbo_core.session_runtime.SessionRuntimeto run sync/async sessions. Passesallowed_toolsfromcontext.mcp_toolsto scope tool binding per query. - Core commands:
/compact,/status,/terminate(shared runtime). - Sessions: supports
session_id,session_tag, andfork_from(tag or id). Tags are resolved viaSessionStore. - Event payloads:
action_plansteps are{title, description}; tool events usetool_id,operation,tool_input.
Hidden dependencies / assumptions
- Uses core logging (
mewbo_core.common.get_logger); log level controlled byruntime.log_level. - Relies on core LLM config (
llm.api_base,llm.api_key,llm.default_model,llm.action_plan_model). - No rate limiting or auth hardening beyond the header token (webhook endpoints use HMAC instead).
- Channel system module-level globals (
_runtime,_hook_manager,_registry,_dedup) inchannels/routes.pyare set byinit_channels()at startup.
api.master_tokendefault is insecure; production should override it inconfigs/app.json.- No heartbeat or health endpoint; external deployments must handle liveness checks.
- The API returns the whole
TaskQueueincluding action steps; ensure tool results are safe to expose. - Treat language models as black-box APIs with non-deterministic output; avoid anthropomorphic language in docs/changes.
apps/mewbo_api/testsmockSessionRuntime.run_syncand focus on response schema.- Avoid mocking too much of core: keep at least one integration test that exercises
SessionStorebehavior.
- Explicit tool allowlists and permission gates reduce unsafe actions; keep API calls explicit and auditable.
- Clear turn boundaries help keep outputs stable; avoid mixing raw tool output with the final response.
- Keep the API surface small and obvious; avoid hidden behaviors.