Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# STDIO Transition Plan

## Goal
Finish migrating the MEW CLI, space lifecycle, and test suite to a pure STDIO transport so developers can start, inspect, and interact with local spaces without WebSocket or PM2 dependencies.

## ✅ Completed
- Transport abstraction and FIFO-based gateway (`cli/src/gateway/*`, `cli/src/commands/gateway.js`).
- Adapter shim for STDIO participants (`cli/bin/mew-stdio-adapter.js`).
- `mew space up/down/status/clean` rewritten to spawn/manage gateway + adapters directly (`cli/src/commands/space.js`).
- All regression scenarios (1–12) converted to STDIO drivers and agents; `tests/run-all-tests.sh` passes end-to-end.
- `mew` command defaults updated to auto-run `space up` and reuse `.mew/space.yaml` in new spaces.
- Human interactive CLI wired via `mew space connect` and `mew --interactive` defaults, using an Ink-powered terminal UI (with `/simple` fallback) on top of STDIO FIFOs.
- Configurable transports so spaces can mix local STDIO adapters with WebSocket participants (`space.transport`, per-participant overrides, optional gateway listener).
- TypeScript SDK `@mew-protocol/client` refactored with pluggable transports (STDIO + WebSocket) enabling agents to run under the new CLI adapter.

## 🚧 In Progress / Next
1. **Interactive UX polish** – Upgrade the terminal experience (slash commands, better message formatting, optional TUI/Ink front-end) and capture transcripts/logging options.
2. **Template polish** – Ensure `mew init` templates install cleanly (package name templating, dependency bootstrap) and document the STDIO workflow in generated READMEs.
3. **Gateway lifecycle UX** – Surface `space status` summaries and logs (e.g., `mew space status --follow`) to make it easy to observe running adapters.
4. **Remote participant docs/tooling** – Document WebSocket setup, token distribution, ship helper scripts for remote participants, and update agent scaffolding to nudge remote configuration.

## 📌 Stretch Ideas
- Space inspector TUI driven by the new STDIO channel.
- Scriptable hooks for adapters (auto-tail logs, health summaries).
- Capability-grant UX built on the STDIO approval flow once the human client exists.

---
*Last updated: 2025-09-19*
164 changes: 24 additions & 140 deletions PROGRESS.md
Original file line number Diff line number Diff line change
@@ -1,148 +1,32 @@
# MEW Protocol Development Progress
# MEW Protocol Progress Log

## Current Status (2025-01-15)
_Last updated: 2025-09-19_

### 🎉 Recent Achievements
## Current Status
The CLI, gateway, and regression suite now run entirely over the new STDIO transport. All scenarios (1–12) succeed under `tests/run-all-tests.sh`, the `mew` command boots a fresh space using `.mew/space.yaml` without PM2 or WebSockets, `mew space connect` launches an Ink-based interactive terminal (with `/simple` fallback), spaces can optionally expose a WebSocket listener for remote participants via `space.transport` overrides, and the TypeScript SDK/agent now speak STDIO by default while retaining optional WebSocket support.

#### v0.2.0 Released to npm
- Successfully published `@mew-protocol/cli` version 0.2.0
- Package available at: https://www.npmjs.com/package/@mew-protocol/cli
- Install with: `npm install -g @mew-protocol/cli`
## Recent Highlights
- **STDIO Gateway & CLI lifecycle**: Gateway core + FIFO transport landed, with adapters spawned by `mew space up`. State is persisted via `.mew/run/state.json`.
- **Scenario conversions**: Every regression scenario now uses STDIO drivers (`multi-*`, `streaming-*`, `batch-*`, etc.), eliminating HTTP hacks and PM2 wrappers.
- **`mew` UX fixes**: `mew` auto-starts a stopped space, warns if already running, and now launches the interactive session automatically (or via `mew space connect`). Template package names are templated correctly, avoiding npm errors.
- **Interactive CLI**: Human participants attach with `mew space connect`, defaulting to the Ink experience (history, proposals, commands) with a `/simple` readline fallback for debugging.
- **Hybrid transports**: `space.yaml` now supports per-participant `transport` selection, spinning up STDIO adapters locally while offering optional WebSocket endpoints for remote processes with the same token model.
- **SDK parity**: `@mew-protocol/client` exposes pluggable STDIO/WebSocket transports; `@mew-protocol/agent` defaults to STDIO so template agents run under the new adapter out of the box.

### ✅ Completed Features
## Remaining Focus Areas
1. **Interactive UX polish** – refine the Ink interface (history search, transcript export, richer capability dialogs) and keep `/simple` parity.
2. **Template bootstrap polish** – smooth out `npm install` failures by templating names earlier or bundling dependencies; document the STDIO workflow in generated projects.
3. **Observability** – richer `space status` output (pid/log summary, follow mode) plus remote participant visibility.

#### Seamless Init-to-Connect Flow (Fixed)
- **Problem Solved**: After `mew init`, the command now automatically continues to start and connect
- **Implementation**: Spawns new process to run `mew space up -i` after initialization
- **Flow**: `mew` → init → start → connect all in one command
## Key Metrics
- Regression scenarios passing: **12 / 12**
- Templates supported: `coder-agent`, `note-taker` (both STDIO-ready)
- STDIO adapters provided: **17** shared drivers/participants under `tests/agents/`

#### MCP Operation Approval Dialog (Phase 1 Complete)
- **Problem Solved**: Fixed input focus issues where keystrokes appeared in input field during approval
- **Implementation**: Option 2 from ADR-009 (Simple Numbered List MVP)
- **Features Added**:
- Arrow key navigation (↑↓) with visual selection indicator
- Enter key to confirm selection
- Number key shortcuts (1/2) for quick approval/denial
- Escape key to cancel
- Proper focus management with input composer disabled during dialogs
- Generic template that works for all operation types

#### Enhanced `mew` Command Behavior
- **Smart Default Actions**:
- First run (no space): `mew` → init → start & connect
- Space exists but stopped: `mew` → start & connect
- Space running: `mew` → connect
- **Port Conflict Resolution**:
- Automatically finds next available port when default is in use
- Prevents duplicate gateways for the same space
- Updates all references to use the selected port

#### Template System for `mew init`
- Built-in templates: `coder-agent` and `note-taker`
- Interactive template selection
- Isolated dependencies in `.mew/` directory
- Keeps project root clean

#### Improved Interactive UI
- Better formatting for reasoning messages
- Visual reasoning status with spinner animation
- Context-aware message display
- Enhanced message formatting for all types

### 🚧 Known Issues to Address

1. **UI Layout Issue**: After approval dialog, input box position is incorrect with whitespace below
2. **Race Condition**: When MCP filesystem joins before coder agent, tools aren't discovered properly
- Coder agent should request tools before reasoning
- Need to clear tool cache when participants rejoin

### 📋 Upcoming Work

#### Phase 2: Tool-Specific Templates (Next Priority)
- Detect operation type from method and tool name
- Create optimized templates for:
- File operations (read/write/delete with previews)
- Command execution (npm/shell/git with risk assessment)
- Network requests (URL/method/headers display)
- Database operations (query preview)
- Maintain consistent interaction pattern across all templates

#### Phase 3: Capability Grants (Future)
- Add "Yes, allow X to Y" option (3rd choice in dialog)
- Send MEW Protocol `capability/grant` messages
- Track granted capabilities per participant
- Skip approval prompts for granted operations
- Session-scoped permissions (not persistent)

### 📦 Repository Structure

```
mew-protocol/
├── cli/ # CLI package (v0.2.0 published)
│ ├── src/
│ │ ├── commands/ # Command implementations
│ │ └── utils/ # Including advanced-interactive-ui.js
│ ├── templates/ # Space templates
│ └── spec/
│ └── draft/
│ └── decisions/
│ └── accepted/
│ └── 009-aud-approval-dialog-ux.md
├── sdk/ # SDK packages
├── bridge/ # Bridge implementation
├── gateway/ # Gateway server
└── TODO.md # Task tracking

```

### 🔧 Development Setup

```bash
# Install latest CLI globally
npm install -g @mew-protocol/cli@0.2.0

# Test the new features
mkdir test-space && cd test-space
mew # Will trigger init → start → connect flow

# For development
cd mew-protocol/cli
npm install
npm run lint
```

### 📈 Metrics

- **Package Size**: 45.2 KB compressed
- **Files**: 27 files in npm package
- **Dependencies**: Managed locally in workspaces
- **Test Coverage**: Basic functional testing in place

### 🎯 Success Indicators

✅ Approval dialog no longer has input focus issues
✅ Users can navigate intuitively with arrows or numbers
✅ `mew` command provides smart defaults
✅ Port conflicts handled automatically
✅ Templates make initialization easy

### 🔮 Vision

The MEW Protocol is evolving toward a sophisticated multi-agent coordination system where:
1. **Transparency**: All agent interactions visible in shared workspace
2. **Control**: Humans approve operations through intuitive dialogs
3. **Progressive Trust**: Capabilities expand as agents prove reliable
4. **Tool Interoperability**: Agents discover and use each other's tools dynamically

### 📝 Notes for Contributors

- Lint errors exist in legacy files but don't affect new features
- Focus on Phase 2 (tool-specific templates) for next iteration
- Consider ADR for handling the race condition with tool discovery
- UI layout issue needs investigation in Ink components
## Next Steps
- Layer richer CLI affordances (history search, transcript export, capability approvals) on top of the new Ink default.
- Tidy template package metadata and retry logic for dependency install.
- Capture the STDIO design decisions in finalized ADRs and document remote/WebSocket configuration patterns.

---

*Last Updated: 2025-01-15*
*Version: 0.2.0*
*Status: Active Development*
Contributions welcome! Prioritize the human-interaction tooling and template polish to round out the STDIO experience.
22 changes: 19 additions & 3 deletions bridge/bin/mew-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { program } = require('commander');

program
.description('MEW-MCP Bridge - Connect MCP servers to MEW spaces')
.requiredOption('--gateway <url>', 'Gateway WebSocket URL')
.option('--gateway <url>', 'Gateway WebSocket URL (required for websocket transport)')
.requiredOption('--space <id>', 'Space ID to join')
.requiredOption('--participant-id <id>', 'Participant ID for this bridge')
.requiredOption('--token <token>', 'Authentication token')
Expand All @@ -16,10 +16,22 @@ program
.option('--init-timeout <ms>', 'Initialization timeout in ms', '30000')
.option('--reconnect <bool>', 'Auto-reconnect on disconnect', 'true')
.option('--max-reconnects <n>', 'Maximum reconnect attempts', '3')
.option('--transport <mode>', 'Transport to use: stdio | websocket', 'stdio')
.parse(process.argv);

const options = program.opts();

const transport = (options.transport || 'stdio').toLowerCase();
if (transport !== 'stdio' && transport !== 'websocket') {
console.error(`Unsupported transport: ${options.transport}`);
process.exit(1);
}

if (transport === 'websocket' && !options.gateway) {
console.error('Gateway URL is required when transport is websocket');
process.exit(1);
}

// Parse MCP args
const mcpArgs = options.mcpArgs ? options.mcpArgs.split(',') : [];

Expand Down Expand Up @@ -50,13 +62,18 @@ const bridge = new MCPBridge({
token: options.token,
initTimeout: parseInt(options.initTimeout),
mcpServer: mcpConfig,
transport: transport,
});

// Start the bridge
async function start() {
try {
console.log(`Starting MCP bridge for ${options.participantId}...`);
console.log(`Connecting to gateway: ${options.gateway}`);
if (transport === 'websocket') {
console.log(`Connecting to gateway: ${options.gateway}`);
} else {
console.log('Connecting via STDIO transport');
}
console.log(`Space: ${options.space}`);
console.log(`MCP server: ${options.mcpCommand} ${mcpArgs.join(' ')}`);

Expand Down Expand Up @@ -97,4 +114,3 @@ async function start() {

// Start the bridge
start();

7 changes: 5 additions & 2 deletions bridge/src/mcp-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import Debug from 'debug';
import { MEWParticipant } from '@mew-protocol/participant';
import { TransportKind } from '@mew-protocol/client';
import { MCPClient, MCPServerConfig } from './mcp-client';

const debug = Debug('mew:bridge');

export interface MCPBridgeOptions {
gateway: string;
gateway?: string;
space: string;
participantId?: string;
token: string;
mcpServer: MCPServerConfig;
initTimeout?: number;
transport?: TransportKind;
}

/**
Expand All @@ -28,10 +30,11 @@ export class MCPBridge extends MEWParticipant {
constructor(options: MCPBridgeOptions) {
// Initialize parent with connection options
super({
gateway: options.gateway,
space: options.space,
participant_id: options.participantId || 'mcp-bridge',
token: options.token,
transport: options.transport,
gateway: options.transport === 'websocket' ? options.gateway : undefined,
});

this.initTimeout = options.initTimeout || 30000;
Expand Down
Loading
Loading