---
name: codemode-how-to-brain
description: See which services, slots and plugins this scope has and how they connect, in Help mode. Use before building a plugin (to find the service to inject or the slot to fill) and when a plugin does not mount or wire up.
---

# Brain in code mode

Use `discover({ namespace: 'brain' })` for types, then call it through exec. Every method is read-only, takes no session argument and needs Help mode. Never inspect another session through a borrowed binding.

## Orient with the graph first

`brain.graph({ kind })` returns the same essential map the Brain page draws, so answers match what the person sees:

- `backend`: plugins and the services they consume. Only public services and services a code-mode contributor can call are kept. Fibers are folded into their owning plugin, and scope plumbing (`po/server-scope`, `po/server-host`, `po/headless-host`, `po/host-services`) is hidden.
- `web` and `native`: plugins and the slots they fill or declare, from each host's own build metadata.

`brain.node({ id })` returns one node and its direct links in every graph that has it. Ids look like `plugin:@agimon-ai/po-git`, `service:po/fs`, `slot:page`. Use it for "what does this plugin use and where does it render" or "who provides and uses this service". Answer from these results instead of dumping a whole graph to the person.

## Before you build a plugin

1. Find a plugin that already does something similar with `brain.node({ id: 'plugin:...' })` and copy its shape, not its code.
2. Pick services from `graph({ kind: 'backend' })`. Inject only public services with a description. A code-mode service that is private is reachable by its owner's namespace, not a contract for you.
3. Pick a slot from `graph({ kind: 'web' })` or `graph({ kind: 'native' })` whose description fits and whose host matches. A slot missing from native has no native fill yet; it is not proof the native app lacks the surface.
4. Then follow the build guide: `help-how-to-codemode-plugin` for a code-mode namespace, `help-how-to-dashboard-extension` for web UI, `help-how-to-native-extension` for the native app. Build, then reload with `selfImprove` (`codemode-how-to-self-improve`) and check the plugin appears in `brain.node`.

## Debug with the raw snapshots

When a plugin does not mount or wire up, drop to the raw data, which keeps what the graph hides:

- `brain.services()`: ownership, public flags, every declared injection with `resolved` or `waiting` status, fibers, and diagnostics. A `waiting` injection names a contract nothing in this scope provides. A declared injection is evidence; absence is not proof that code never reads a service. Public means the core snapshot recognizes a contract, not permission to bypass authorization. A missing description is a documentation gap, not a contract to invent.
- `brain.slots()`: web slot declarations, explicit parent links and verified fill placements. Do not infer hierarchy from dots or claim a fill is currently rendered. Null metadata means unavailable, not an empty inventory. Older hosts fall back to matching server installations and report the browser-inventory coverage gap.
- `selfImprove.plugins()` lists packages that failed to install, with reasons. Read it alongside diagnostics.

Unknown origins stay unknown, never classify them as Po or personal. Scope ids are opaque and describe the current session and its ancestry, never siblings or descendants. Do not supply session ids, execute browser plugins, read configuration or scan files to manufacture missing inventory. Diagnose first and ask before proposing repairs.
