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
11 changes: 9 additions & 2 deletions cli/bin/mew.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
* - mew agent start - Start a built-in agent
* - mew token create - Create a test token
*/

require('../src/index.js');
try {
require('../dist/index.js');
} catch (error) {
if (error && error.code === 'MODULE_NOT_FOUND') {
console.error('The MEW CLI has not been built yet. Run "npm run build --workspace @mew-protocol/cli" to compile.');
process.exit(1);
}
throw error;
}

18 changes: 16 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
"bin": {
"mew": "bin/mew.js"
},
"main": "src/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist",
"test": "node tests/run-tests.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand Down Expand Up @@ -39,6 +44,7 @@
"ws": "^8.18.0"
},
"files": [
"dist",
"src",
"bin",
"templates",
Expand All @@ -58,10 +64,18 @@
},
"devDependencies": {
"@eslint/js": "^9.35.0",
"@types/body-parser": "^1.19.5",
"@types/express": "^4.17.21",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.16.11",
"@types/react": "^18.3.12",
"@types/uuid": "^9.0.8",
"@types/ws": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^8.43.0",
"@typescript-eslint/parser": "^8.43.0",
"eslint": "^9.35.0",
"eslint-config-prettier": "^10.1.8",
"prettier": "^3.6.2"
"prettier": "^3.6.2",
"typescript": "^5.6.3"
}
}
8 changes: 5 additions & 3 deletions cli/src/commands/agent.js → cli/src/commands/agent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { Command } = require('commander');
const WebSocket = require('ws');
// @ts-nocheck

import { Command } from 'commander';
import WebSocket from 'ws';

const agent = new Command('agent').description('Agent management');

Expand Down Expand Up @@ -232,4 +234,4 @@ function handleFulfillerAgent(ws, message) {
}
}

module.exports = agent;
export default agent;
14 changes: 8 additions & 6 deletions cli/src/commands/client.js → cli/src/commands/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const { Command } = require('commander');
const WebSocket = require('ws');
const fs = require('fs');
const readline = require('readline');
// @ts-nocheck

import { Command } from 'commander';
import WebSocket from 'ws';
import fs from 'fs';
import readline from 'readline';
import { spawn } from 'child_process';

const client = new Command('client').description('Client connection management');

Expand Down Expand Up @@ -81,7 +84,6 @@ client
console.log(`Reading from FIFO: ${options.fifoIn}`);

// Use tail -F to read from FIFO continuously
const { spawn } = require('child_process');
const tail = spawn('tail', ['-F', options.fifoIn]);

const rl = readline.createInterface({
Expand Down Expand Up @@ -149,4 +151,4 @@ client
});
});

module.exports = client;
export default client;
25 changes: 12 additions & 13 deletions cli/src/commands/gateway.js → cli/src/commands/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { Command } = require('commander');
const WebSocket = require('ws');
const express = require('express');
const http = require('http');
const fs = require('fs');
const yaml = require('js-yaml');
const path = require('path');
const { spawn } = require('child_process');
const crypto = require('crypto');
// @ts-nocheck

import { Command } from 'commander';
import WebSocket from 'ws';
import express from 'express';
import http from 'http';
import fs from 'fs';
import yaml from 'js-yaml';
import path from 'path';
import { spawn } from 'child_process';
import crypto from 'crypto';

const gateway = new Command('gateway').description('Gateway server management');

Expand All @@ -28,7 +30,6 @@ gateway

// If we're running as a detached process, redirect console output to a log file
if (process.env.GATEWAY_LOG_FILE) {
const fs = require('fs');
const logStream = fs.createWriteStream(process.env.GATEWAY_LOG_FILE, { flags: 'a' });
const originalLog = console.log;
const originalError = console.error;
Expand Down Expand Up @@ -597,8 +598,6 @@ gateway

// Auto-connect a participant that writes to output_log
function autoConnectOutputLogParticipant(participantId, config) {
const fs = require('fs');
const path = require('path');

// Resolve output log path
const outputPath = path.resolve(process.cwd(), config.output_log);
Expand Down Expand Up @@ -1484,7 +1483,7 @@ gateway
});
});

module.exports = gateway;
export default gateway;

function parseOptionalBoolean(value) {
if (value === undefined || value === null) {
Expand Down
15 changes: 8 additions & 7 deletions cli/src/commands/init.js → cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env node

const fs = require('fs').promises;
const path = require('path');
const readline = require('readline');
const { execSync } = require('child_process');
const crypto = require('crypto');
// @ts-nocheck

import fs from 'fs/promises';
import path from 'path';
import readline from 'readline';
import { execSync } from 'child_process';
import crypto from 'crypto';

/**
* MEW init command - Initialize a new MEW space from templates
Expand Down Expand Up @@ -319,7 +321,6 @@ class InitCommand {

// Make agent files executable
try {
const { execSync } = require('child_process');
execSync(`chmod +x ${agentsDest}/*.js 2>/dev/null || true`);
} catch {
// Ignore errors on Windows
Expand Down Expand Up @@ -874,7 +875,7 @@ class InitCommand {
}

// Export for use in main CLI
module.exports = InitCommand;
export default InitCommand;

// Run if called directly
if (require.main === module) {
Expand Down
66 changes: 20 additions & 46 deletions cli/src/commands/space.js → cli/src/commands/space.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
const { Command } = require('commander');
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const { spawn, execSync } = require('child_process');
const net = require('net');
const http = require('http');
const pm2 = require('pm2');
const crypto = require('crypto');
// @ts-nocheck

import { Command } from 'commander';
import fs from 'fs';
import path from 'path';
import yaml from 'js-yaml';
import { spawn, execSync } from 'child_process';
import net from 'net';
import http from 'http';
import pm2 from 'pm2';
import crypto from 'crypto';
import readline from 'readline';
import WebSocket from 'ws';

import { resolveParticipant, getInteractiveOverrides } from '../utils/participant-resolver';
import { printBanner } from '../utils/banner';
import InteractiveUI from '../utils/interactive-ui';
import { startAdvancedInteractiveUI } from '../utils/advanced-interactive-ui';

function findMonorepoRoot(startDir) {
let dir = startDir;
Expand Down Expand Up @@ -865,24 +874,8 @@ async function spaceUpAction(options) {
if (options.interactive) {
console.log('\nConnecting interactively...\n');

// Import required modules for interactive connection
const WebSocket = require('ws');
const {
resolveParticipant,
getInteractiveOverrides,
} = require('../utils/participant-resolver');
const { printBanner } = require('../utils/banner');

// Determine UI mode
const useDebugUI = options.debug || options.simple || options.noUi;

// Import appropriate UI module
const InteractiveUI = useDebugUI ?
require('../utils/interactive-ui') :
null;
const { startAdvancedInteractiveUI } = useDebugUI ?
{ startAdvancedInteractiveUI: null } :
require('../utils/advanced-interactive-ui');

try {
// Resolve participant
Expand Down Expand Up @@ -1353,7 +1346,6 @@ space
console.log('Warning: This will clean artifacts while space is active.');
console.log('Use "mew space down" first, or use --force to proceed anyway.');

const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
Expand All @@ -1374,7 +1366,6 @@ space
if (cleanMew && !options.force) {
console.log('This will remove ALL space artifacts including configuration.');

const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
Expand Down Expand Up @@ -1524,24 +1515,8 @@ space
console.log(`Space: ${pids.spaceName} (${spaceId})`);
console.log(`Gateway: ${gatewayUrl}`);

// Import required modules
const WebSocket = require('ws');
const {
resolveParticipant,
getInteractiveOverrides,
} = require('../utils/participant-resolver');
const { printBanner } = require('../utils/banner');

// Determine UI mode
const useDebugUI = options.debug || options.simple || options.noUi;

// Import appropriate UI module
const InteractiveUI = useDebugUI ?
require('../utils/interactive-ui') :
null;
const { startAdvancedInteractiveUI } = useDebugUI ?
{ startAdvancedInteractiveUI: null } :
require('../utils/advanced-interactive-ui');

try {
// Resolve participant
Expand Down Expand Up @@ -1616,6 +1591,5 @@ space
});

// Export both the command and the action handlers
module.exports = space;
module.exports.spaceUpAction = spaceUpAction;
module.exports.spaceDownAction = spaceDownAction;
export default space;
export { spaceUpAction, spaceDownAction };
7 changes: 4 additions & 3 deletions cli/src/commands/token.js → cli/src/commands/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Command } = require('commander');
import { Command } from 'commander';

const token = new Command('token').description('Token management');

Expand All @@ -15,7 +15,8 @@ token
try {
capabilities = JSON.parse(options.capabilities);
} catch (error) {
console.error('Invalid capabilities JSON:', error.message);
const message = error instanceof Error ? error.message : String(error);
console.error('Invalid capabilities JSON:', message);
process.exit(1);
}

Expand All @@ -31,4 +32,4 @@ token
console.log(token);
});

module.exports = token;
export default token;
Loading