BizCity Twin Plugin Standard v2.0

πŸ“– Canonical guide for developing plugins that integrate with BizCity Twin Core ecosystem.

Unified architecture for Intent Providers, Automation, Studio integration, SSE streaming, and API gateway contracts.

πŸ“‹ Quick Navigation

BizCity Twin Plugin Standard β€” v2.0


> **TiΓͺu chuαΊ©n chung cho tαΊ₯t cαΊ£ plugin tΓ­ch hợp BizCity Twin Core**
> **PhiΓͺn bαΊ£n**: 2.0 | **Thời gian**: 2026-03-27
> **Scope**: Plugin architecture, Provider contracts, API standardization, SSE streaming, UI/UX patterns
> **Áp dα»₯ng cho**: bizcity-tool-* | bizcity-automation-* | bizcity-studio-* | legacy integration

---

1. Overview β€” 3 Layer Plugin Architecture


<br />
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”<br />
β”‚            TWIN PLUGIN ARCHITECTURE (3 LAYER)                β”‚<br />
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€<br />
β”‚                                                               β”‚<br />
β”‚  🎨 LAYER 1: UI/UX β€” Touch Bar + Agent Profile              β”‚<br />
β”‚     β”œβ”€ Touch Bar iframe β†’ guided commands (/slash notation)  β”‚<br />
β”‚     β”œβ”€ Quick Chat shortcuts β†’ payload standardization        β”‚<br />
β”‚     └─ Welcome shortcuts (React) β†’ mention @tool reference   β”‚<br />
β”‚                                                               β”‚<br />
β”‚  βš™οΈ  LAYER 2: Intent &amp; Automation Provider                   β”‚<br />
β”‚     β”œβ”€ Intent mapping (chat/execution/planning modes)        β”‚<br />
β”‚     β”œβ”€ Tool registration in Twin Core registry               β”‚<br />
β”‚     β”œβ”€ Slot collection + Planner hooks                       β”‚<br />
β”‚     └─ Job Trace for step-by-step execution                 β”‚<br />
β”‚                                                               β”‚<br />
β”‚  🎬 LAYER 3: Studio Provider &amp; Output Embedding              β”‚<br />
β”‚     β”œβ”€ Output formatter (markdown/rich HTML)                 β”‚<br />
β”‚     β”œβ”€ Studio component (React) for preview/edit             β”‚<br />
β”‚     β”œβ”€ Persistence to Notebook                               β”‚<br />
β”‚     └─ Export &amp; Share integration                            β”‚<br />
β”‚                                                               β”‚<br />
β”‚  πŸ“‘ SSE MODE: Real-time Streaming                            β”‚<br />
β”‚     β”œβ”€ Job events (&quot;step_complete&quot;, &quot;tool_executed&quot;, etc)   β”‚<br />
β”‚     β”œβ”€ Frontend listens &amp; renders live progress              β”‚<br />
β”‚     └─ Error recovery &amp; state sync                          β”‚<br />
β”‚                                                               β”‚<br />
β”‚  πŸ”Œ API GATEWAY: Plugin Registry &amp; Bridge                    β”‚<br />
β”‚     β”œβ”€ Plugin discovery (featured/automation/studio flags)   β”‚<br />
β”‚     β”œβ”€ API method extraction (WordPress REST / custom RPC)   β”‚<br />
β”‚     └─ Tool contract validation (inputs/outputs schemas)     β”‚<br />
β”‚                                                               β”‚<br />
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜<br />


---

2. Core Principles


βœ… **Slash Command Standard**: All quick prompts and shortcuts MUST resolve to `/tool_name base_text` format

βœ… **Capability Declaration**: Every plugin MUST declare machine-readable metadata (featured, automation_ready, studio_ready, sse_streaming, api_version)

βœ… **Unified Output Envelope**: Tool execution MUST follow ONE output structure + ONE SSE event contract

βœ… **Mode-Aware Context**: Context injection MUST use Twin resolver contracts (chat/knowledge/execution/planning/emotion)

βœ… **Contract-First APIs**: All plugin APIs MUST be discoverable via Gateway + standardized inspection

βœ… **Payload Standardization**: postMessage from profile MUST include: type, source, plugin_slug, tool_name, text

---

3. Quick Prompt Standard β€” Slash + Mention


All clickable shortcut elements MUST build and send slash commands:

HTML Markup (page-agent-profile.php)


html<br />
&lt;div data-msg=&quot;Viết bài về dinh dưống&quot; data-tool=&quot;tool_content&quot; data-plugin=&quot;bizcity-tool-content&quot;&gt;&lt;/div&gt;<br />


Client send payload standard:

js<br />
window.parent.postMessage({<br />
  type: 'bizcity_agent_command',<br />
  source: 'bizcity-tool-content',<br />
  plugin_slug: 'bizcity-tool-content',<br />
  tool_name: 'write_article',<br />
  text: '/write_article Viết bài về dinh dưống'<br />
}, '*');<br />


Normalization rule:

- If text does not start with / and tool_name exists, prepend `/{tool_name}`.
- If source exists but tool_name missing, receiver may infer main_tool from plugin metadata.

---

4) Intent Provider Standard


Intent provider must define:

- id, name, patterns, plans, tools
- capabilities block (section 2)
- context() for mode-aware context enrichment
- optional gateway contract mapping (section 9)

Minimal tools schema requirement:

php<br />
'tools' =&gt; [<br />
  'write_article' =&gt; [<br />
    'label' =&gt; 'Write and publish article',<br />
    'schema' =&gt; [<br />
      'description' =&gt; 'Generate article and publish to WordPress',<br />
      'input_fields' =&gt; [<br />
        'topic' =&gt; [ 'required' =&gt; true, 'type' =&gt; 'text' ],<br />
      ],<br />
    ],<br />
    'callback' =&gt; [ 'BizCity_Tool_Content', 'write_article' ],<br />
  ],<br />
],<br />


---

5) Automation Provider Standard


Automation provider must expose:

- node catalog entry with stable node_id
- input/output schema
- deterministic tool binding to main_tool and secondary tools
- compensation strategy for retry/failure

Required fields:

php<br />
[<br />
  'node_id' =&gt; 'tool-content.write_article',<br />
  'tool_name' =&gt; 'write_article',<br />
  'provider_id' =&gt; 'tool-content',<br />
  'supports_retry' =&gt; true,<br />
  'supports_idempotency' =&gt; true,<br />
]<br />


---

6) Studio Provider Standard


Studio integration must declare:

- available actions
- input panel schema
- preview renderer
- output artifact type

Required metadata:

php<br />
[<br />
  'studio_action' =&gt; 'content.write',<br />
  'artifact_type' =&gt; 'article',<br />
  'editable' =&gt; true,<br />
  'stream_mode' =&gt; 'step+delta',<br />
]<br />


---

7) BizChat Menu Registration Standard


Use centralized hook:

php<br />
add_action('bizchat_register_menus', function($menu) {<br />
  $menu-&gt;add([<br />
    'id' =&gt; 'tool-content',<br />
    'title' =&gt; 'Tool Content',<br />
    'parent' =&gt; 'bizchat',<br />
    'capability' =&gt; 'read',<br />
    'position' =&gt; 80,<br />
  ]);<br />
});<br />


Rules:

- Do not register direct top-level menu for BizChat tools.
- Keep menu IDs stable and slug-safe.

---

8) SSE Stream Mode Standard


Tool pipelines should emit stream events in this order:

1. trace_begin
2. step events (pending/running/done or failed)
3. optional partial delta events
4. trace_end

Common event payload:

json<br />
{<br />
  &quot;event&quot;: &quot;tool_trace&quot;,<br />
  &quot;tool_name&quot;: &quot;write_article&quot;,<br />
  &quot;step&quot;: &quot;T2&quot;,<br />
  &quot;status&quot;: &quot;running&quot;,<br />
  &quot;message&quot;: &quot;Generating outline&quot;<br />
}<br />


Requirements:

- send `tool_name` and stable `trace_id`
- include status transitions, not only done state
- send fail event before terminating stream on error

---

9) Context Contract (Twin Resolver)


All AI-calling tool callbacks must consume `_meta`:

php<br />
$meta       = $slots['_meta'] ?? [];<br />
$ai_context = $meta['_context'] ?? '';<br />


Context usage policy:

- append ai_context to system prompt when non-empty
- do not mutate or return `_meta` in tool output
- use mode-aware behavior (emotion/knowledge/planning/execution/studio)

---

10) API Integration Contract (Gateway Bridge)


Every tool should optionally define an API contract block to support gateway orchestration:

php<br />
'gateway_contract' =&gt; [<br />
  'contract_version' =&gt; '1.0',<br />
  'endpoint' =&gt; '/tool-content/v1/write-article',<br />
  'method' =&gt; 'POST',<br />
  'input_schema_ref' =&gt; 'tool-content.write-article.input',<br />
  'output_schema_ref' =&gt; 'tool-content.write-article.output',<br />
  'hil_points' =&gt; [ 'before_publish' ],<br />
],<br />


Benefits:

- API-first wrappers for legacy WordPress handlers
- deterministic registry map from contract
- HIL and slot collection inferred from schema

---

11) Loader Information Standard


Plugin loader should expose normalized info object:

php<br />
[<br />
  'slug' =&gt; 'bizcity-tool-content',<br />
  'role' =&gt; 'tool',<br />
  'featured' =&gt; true,<br />
  'supports_studio' =&gt; true,<br />
  'supports_automation' =&gt; true,<br />
  'main_tool' =&gt; 'write_article',<br />
  'template_page' =&gt; 'tool-content',<br />
]<br />


---

12) Legacy Wrapper Standard


For old plugins in WordPress legacy:

- keep old callback intact
- wrap with contract adapter
- map old args to schema input
- map old result to output envelope

Wrapper naming:

- `Legacy_{Plugin}_Gateway_Adapter`
- `Legacy_{Plugin}_Contract_Map`

---

13) Compliance Checklist


- Shortcut click sends slash-prefixed message
- Shortcut payload includes tool_name + plugin_slug
- Provider declares capabilities
- main_tool declared and valid in tools map
- SSE emits trace begin/step/end
- Tool callback reads `_meta` and `_context`
- Tool output envelope contract satisfied
- Menu registered via bizchat_register_menus
- Optional API contract block added

---

14) Migration Plan for Existing Plugins


1. Add capabilities and main_tool metadata
2. Add shortcut payload normalization in profile pages
3. Add tool_name/plugin_slug to postMessage payloads
4. Add gateway_contract block for each main tool
5. Add automation/studio metadata
6. Verify SSE event compliance
7. Register BizChat menu entry

---

15) References


- core/intent/PLUGIN-STANDARD.md
- plugins/bizcity-tool-content/PLUGIN-STANDARD.md
- scaffold/views/page-agent-profile.php
- IMPLEMENTATION-ROADMAP.md
?> Plugin Twin Standard

Plugin Twin Standard

Unified contract for BizCity plugin ecosystem: slash shortcuts, provider metadata, SSE, studio/automation, and API gateway bridge.

Shortcut Contract

All quick prompt clicks must produce slash command with tool_name and plugin_slug.

Provider Contract

Providers must declare featured, supports_studio, supports_automation, and main_tool.

Gateway Ready

Each tool should expose optional gateway_contract to map API bridge and HIL points.

1. postMessage Standard

window.parent.postMessage({
  type: 'bizcity_agent_command',
  source: 'bizcity-tool-content',
  plugin_slug: 'bizcity-tool-content',
  tool_name: 'write_article',
  text: '/write_article Viết bài về dinh dưống'
}, '*');
Rule: if text has no leading slash and tool_name exists, receiver prepends /{tool_name}.

2. Capability Metadata

'capabilities' => [
  'featured' => true,
  'supports_studio' => true,
  'supports_automation' => true,
  'supports_sse' => true,
  'main_tool' => 'write_article',
  'hil_required' => false,
],

3. Required Coverage

Intent Provider Automation Provider Studio Provider BizChat Menu SSE Trace Context Resolver Gateway Contract

4. Canonical Source

Detailed specification is maintained in bizcity-twin-ai/PLUGIN-TWIN-STANDARD.md.