morpheus-cli 0.1.5 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +273 -213
- package/bin/morpheus.js +30 -0
- package/dist/channels/telegram.js +7 -2
- package/dist/cli/commands/config.js +18 -3
- package/dist/cli/commands/init.js +3 -3
- package/dist/cli/index.js +8 -0
- package/dist/config/mcp-loader.js +42 -0
- package/dist/config/schemas.js +22 -0
- package/dist/http/__tests__/auth.test.js +53 -0
- package/dist/http/api.js +23 -0
- package/dist/http/middleware/auth.js +23 -0
- package/dist/http/server.js +2 -1
- package/dist/runtime/__tests__/agent_persistence.test.js +39 -33
- package/dist/runtime/__tests__/manual_start_verify.js +1 -0
- package/dist/runtime/agent.js +93 -8
- package/dist/runtime/audio-agent.js +11 -1
- package/dist/runtime/display.js +12 -0
- package/dist/runtime/memory/sqlite.js +186 -9
- package/dist/runtime/providers/factory.js +28 -2
- package/dist/runtime/scaffold.js +5 -0
- package/dist/runtime/tools/__tests__/tools.test.js +127 -0
- package/dist/runtime/tools/analytics-tools.js +103 -0
- package/dist/runtime/tools/config-tools.js +70 -0
- package/dist/runtime/tools/diagnostic-tools.js +124 -0
- package/dist/runtime/tools/factory.js +62 -18
- package/dist/runtime/tools/index.js +4 -0
- package/dist/types/auth.js +4 -0
- package/dist/types/config.js +1 -0
- package/dist/types/mcp.js +11 -0
- package/dist/types/stats.js +1 -0
- package/dist/types/tools.js +2 -0
- package/dist/types/usage.js +1 -0
- package/dist/ui/assets/index-CMGsLiNG.css +1 -0
- package/dist/ui/assets/index-DpbRiL07.js +50 -0
- package/dist/ui/index.html +2 -2
- package/package.json +5 -1
- package/dist/ui/assets/index-D1kvj0eG.css +0 -1
- package/dist/ui/assets/index-DTh8waF7.js +0 -50
package/README.md
CHANGED
|
@@ -1,213 +1,273 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<img src="./assets/logo.png" alt="Morpheus Logo" width="220" />
|
|
3
|
-
</div>
|
|
4
|
-
|
|
5
|
-
# Morpheus
|
|
6
|
-
|
|
7
|
-
> **Morpheus is a local-first AI operator that bridges developers and machines.**
|
|
8
|
-
|
|
9
|
-
Morpheus is a local AI agent for developers, running as a CLI daemon that connects to **LLMs**, **local tools**, and **MCPs**, enabling interaction via **Terminal, Telegram, and Discord**. Inspired by the character Morpheus from *The Matrix*, the project acts as an **intelligent orchestrator**, bridging the gap between the developer and complex systems.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
Install Morpheus globally via npm:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install -g morpheus-cli
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Quick Start
|
|
20
|
-
|
|
21
|
-
### 1. Initialize
|
|
22
|
-
|
|
23
|
-
Set up your configuration (API keys, preferences):
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
morpheus init
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### 2. Start the Agent
|
|
30
|
-
|
|
31
|
-
Run the background daemon and Web UI:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
morpheus start
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
This will:
|
|
38
|
-
- Start the agent process
|
|
39
|
-
- Launch the Web UI at http://localhost:3333
|
|
40
|
-
|
|
41
|
-
### Other Commands
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
# Check if Morpheus is running
|
|
45
|
-
morpheus status
|
|
46
|
-
|
|
47
|
-
# Stop the agent
|
|
48
|
-
morpheus stop
|
|
49
|
-
|
|
50
|
-
# Diagnose issues
|
|
51
|
-
morpheus doctor
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Troubleshooting
|
|
55
|
-
|
|
56
|
-
### Command not found
|
|
57
|
-
|
|
58
|
-
If you installed successfully but can't run the `morpheus` command:
|
|
59
|
-
|
|
60
|
-
1. **Check your PATH**: Ensure your global npm bin directory is in your system PATH.
|
|
61
|
-
- Run `npm bin -g` to see the folder.
|
|
62
|
-
- On Windows, this is usually `%APPDATA%\npm`.
|
|
63
|
-
- On Linux/Mac, verify `echo $PATH`.
|
|
64
|
-
2. **Restart Terminal**: New installations might not be visible until you restart your shell.
|
|
65
|
-
|
|
66
|
-
## Using NPX
|
|
67
|
-
You can run Morpheus without installing it globally using `npx`:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
|
|
71
|
-
npx morpheus-cli init
|
|
72
|
-
|
|
73
|
-
npx morpheus-cli start
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Technical Overview
|
|
78
|
-
|
|
79
|
-
Morpheus is built with **Node.js** and **TypeScript**, using **LangChain** as the orchestration engine. It runs as a background daemon process, managing connections to LLM providers (OpenAI, Anthropic, Ollama) and external channels (Telegram, Discord).
|
|
80
|
-
|
|
81
|
-
### Core Components
|
|
82
|
-
|
|
83
|
-
- **Runtime (`src/runtime/`)**: The heart of the application. Manages the agent lifecycle, provider instantiation, and command execution.
|
|
84
|
-
- **CLI (`src/cli/`)**: Built with `commander`, handles user interaction, configuration, and daemon control (`start`, `stop`, `status`).
|
|
85
|
-
- **Configuration (`src/config/`)**: Singleton-based configuration manager using `zod` for validation and `js-yaml` for persistence (`~/.morpheus/config.yaml`).
|
|
86
|
-
- **Channels (`src/channels/`)**: Adapters for external communication. Currently supports Telegram (`telegraf`) with strict user whitelisting.
|
|
87
|
-
|
|
88
|
-
## Features
|
|
89
|
-
|
|
90
|
-
###
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
npm
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
###
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
#
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./assets/logo.png" alt="Morpheus Logo" width="220" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# Morpheus
|
|
6
|
+
|
|
7
|
+
> **Morpheus is a local-first AI operator that bridges developers and machines.**
|
|
8
|
+
|
|
9
|
+
Morpheus is a local AI agent for developers, running as a CLI daemon that connects to **LLMs**, **local tools**, and **MCPs**, enabling interaction via **Terminal, Telegram, and Discord**. Inspired by the character Morpheus from *The Matrix*, the project acts as an **intelligent orchestrator**, bridging the gap between the developer and complex systems.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Install Morpheus globally via npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g morpheus-cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### 1. Initialize
|
|
22
|
+
|
|
23
|
+
Set up your configuration (API keys, preferences):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
morpheus init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Start the Agent
|
|
30
|
+
|
|
31
|
+
Run the background daemon and Web UI:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
morpheus start
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This will:
|
|
38
|
+
- Start the agent process
|
|
39
|
+
- Launch the Web UI at http://localhost:3333
|
|
40
|
+
|
|
41
|
+
### Other Commands
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Check if Morpheus is running
|
|
45
|
+
morpheus status
|
|
46
|
+
|
|
47
|
+
# Stop the agent
|
|
48
|
+
morpheus stop
|
|
49
|
+
|
|
50
|
+
# Diagnose issues
|
|
51
|
+
morpheus doctor
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Troubleshooting
|
|
55
|
+
|
|
56
|
+
### Command not found
|
|
57
|
+
|
|
58
|
+
If you installed successfully but can't run the `morpheus` command:
|
|
59
|
+
|
|
60
|
+
1. **Check your PATH**: Ensure your global npm bin directory is in your system PATH.
|
|
61
|
+
- Run `npm bin -g` to see the folder.
|
|
62
|
+
- On Windows, this is usually `%APPDATA%\npm`.
|
|
63
|
+
- On Linux/Mac, verify `echo $PATH`.
|
|
64
|
+
2. **Restart Terminal**: New installations might not be visible until you restart your shell.
|
|
65
|
+
|
|
66
|
+
## Using NPX
|
|
67
|
+
You can run Morpheus without installing it globally using `npx`:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
|
|
71
|
+
npx morpheus-cli init
|
|
72
|
+
|
|
73
|
+
npx morpheus-cli start
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Technical Overview
|
|
78
|
+
|
|
79
|
+
Morpheus is built with **Node.js** and **TypeScript**, using **LangChain** as the orchestration engine. It runs as a background daemon process, managing connections to LLM providers (OpenAI, Anthropic, Ollama) and external channels (Telegram, Discord).
|
|
80
|
+
|
|
81
|
+
### Core Components
|
|
82
|
+
|
|
83
|
+
- **Runtime (`src/runtime/`)**: The heart of the application. Manages the agent lifecycle, provider instantiation, and command execution.
|
|
84
|
+
- **CLI (`src/cli/`)**: Built with `commander`, handles user interaction, configuration, and daemon control (`start`, `stop`, `status`).
|
|
85
|
+
- **Configuration (`src/config/`)**: Singleton-based configuration manager using `zod` for validation and `js-yaml` for persistence (`~/.morpheus/config.yaml`).
|
|
86
|
+
- **Channels (`src/channels/`)**: Adapters for external communication. Currently supports Telegram (`telegraf`) with strict user whitelisting.
|
|
87
|
+
|
|
88
|
+
## Features
|
|
89
|
+
|
|
90
|
+
### 🖥️ Web Dashboard
|
|
91
|
+
Local React-based UI to manage recordings, chat history, and system status across your agent instances.
|
|
92
|
+
|
|
93
|
+
#### 🔒 UI Authentication
|
|
94
|
+
To protect your Web UI, use the `THE_ARCHITECT_PASS` environment variable. This ensures only authorized users can access the dashboard and API.
|
|
95
|
+
|
|
96
|
+
**Option 1: Using a `.env` file**
|
|
97
|
+
Create a `.env` file in the root of your project:
|
|
98
|
+
|
|
99
|
+
```env
|
|
100
|
+
THE_ARCHITECT_PASS="your-secure-password"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Option 2: Using Shell export**
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export THE_ARCHITECT_PASS="your-secure-password"
|
|
107
|
+
morpheus start
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
When enabled:
|
|
111
|
+
- The Web UI will redirect to a Login page.
|
|
112
|
+
- API requests require the `x-architect-pass` header.
|
|
113
|
+
- The session is persisted locally in your browser.
|
|
114
|
+
|
|
115
|
+
### 🧩 MCP Support (Model Context Protocol)
|
|
116
|
+
Full integration with [Model Context Protocol](https://modelcontextprotocol.io/), allowing Morpheus to use standardized tools from any MCP-compatible server.
|
|
117
|
+
|
|
118
|
+
### 📊 Usage Analytics
|
|
119
|
+
Track your token usage across different providers and models directly from the Web UI. View detailed breakdowns of input/output tokens and message counts to monitor costs and activity.
|
|
120
|
+
|
|
121
|
+
### 🎙️ Audio Transcription (Telegram)
|
|
122
|
+
Send voice messages directly to the Telegram bot. Morpheus will:
|
|
123
|
+
1. Transcribe the audio using **Google Gemini**.
|
|
124
|
+
2. Process the text as a standard prompt.
|
|
125
|
+
3. Reply with the answer.
|
|
126
|
+
|
|
127
|
+
*Requires a Google Gemini API Key.*
|
|
128
|
+
|
|
129
|
+
## Development Setup
|
|
130
|
+
|
|
131
|
+
This guide is for developers contributing to the Morpheus codebase.
|
|
132
|
+
|
|
133
|
+
### Prerequisites
|
|
134
|
+
|
|
135
|
+
- **Node.js**: >= 18.x
|
|
136
|
+
- **npm**: >= 9.x
|
|
137
|
+
- **TypeScript**: >= 5.x
|
|
138
|
+
|
|
139
|
+
### 1. Clone & Install
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git clone https://github.com/your-org/morpheus.git
|
|
143
|
+
cd morpheus
|
|
144
|
+
npm install
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 2. Build
|
|
148
|
+
|
|
149
|
+
Compile TypeScript source to `dist/` and build the Web UI.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm run build
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 3. Run the CLI
|
|
156
|
+
|
|
157
|
+
You can run the CLI directly from the source using `npm start`.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Initialize configuration (creates ~/.morpheus)
|
|
161
|
+
npm start -- init
|
|
162
|
+
|
|
163
|
+
# Start the daemon
|
|
164
|
+
npm start -- start
|
|
165
|
+
|
|
166
|
+
# Check status
|
|
167
|
+
npm start -- status
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 4. Configuration
|
|
171
|
+
|
|
172
|
+
The configuration file is located at `~/.morpheus/config.yaml`. You can edit it manually or use the `morpheus config` command.
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
agent:
|
|
176
|
+
name: "Morpheus"
|
|
177
|
+
personality: "stoic, wise, and helpful"
|
|
178
|
+
llm:
|
|
179
|
+
provider: "openai" # options: openai, anthropic, ollama, gemini
|
|
180
|
+
model: "gpt-4-turbo"
|
|
181
|
+
temperature: 0.7
|
|
182
|
+
api_key: "sk-..."
|
|
183
|
+
memory:
|
|
184
|
+
limit: 100 # Number of messages to retain in context
|
|
185
|
+
channels:
|
|
186
|
+
telegram:
|
|
187
|
+
enabled: true
|
|
188
|
+
token: "YOUR_TELEGRAM_BOT_TOKEN"
|
|
189
|
+
allowedUsers: ["123456789"] # Your Telegram User ID
|
|
190
|
+
discord:
|
|
191
|
+
enabled: false # Coming soon
|
|
192
|
+
|
|
193
|
+
# Web UI Dashboard
|
|
194
|
+
ui:
|
|
195
|
+
enabled: true
|
|
196
|
+
port: 3333
|
|
197
|
+
|
|
198
|
+
# Audio Transcription Support
|
|
199
|
+
audio:
|
|
200
|
+
enabled: true
|
|
201
|
+
apiKey: "YOUR_GEMINI_API_KEY" # Optional if llm.provider is 'gemini'
|
|
202
|
+
maxDurationSeconds: 300
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 5. MCP Configuration
|
|
206
|
+
|
|
207
|
+
Morpheus supports external tools via **MCP (Model Context Protocol)**. Configure your MCP servers in `~/.morpheus/mcps.json`:
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"coolify": {
|
|
212
|
+
"transport": "stdio",
|
|
213
|
+
"command": "npx",
|
|
214
|
+
"args": ["-y", "@coolify/mcp-server"],
|
|
215
|
+
"env": {
|
|
216
|
+
"COOLIFY_URL": "https://app.coolify.io",
|
|
217
|
+
"COOLIFY_TOKEN": "your-token"
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
"coingecko": {
|
|
221
|
+
"transport": "http",
|
|
222
|
+
"url": "https://mcps.mnunes.xyz/coingecko/mcp"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Testing
|
|
228
|
+
|
|
229
|
+
We use **Vitest** for testing.
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Run unit tests
|
|
233
|
+
npm test
|
|
234
|
+
|
|
235
|
+
# Run tests in watch mode
|
|
236
|
+
npm run test:watch
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Project Structure
|
|
240
|
+
|
|
241
|
+
```text
|
|
242
|
+
.
|
|
243
|
+
├── assets/ # Static assets
|
|
244
|
+
├── bin/ # CLI entry point (morpheus.js)
|
|
245
|
+
├── specs/ # Technical specifications & documentation
|
|
246
|
+
├── src/
|
|
247
|
+
│ ├── channels/ # Communication adapters (Telegram, etc.)
|
|
248
|
+
│ ├── cli/ # CLI commands and logic
|
|
249
|
+
│ ├── config/ # Configuration management
|
|
250
|
+
│ ├── runtime/ # Core agent logic, lifecycle, and providers
|
|
251
|
+
│ ├── types/ # Shared TypeScript definitions
|
|
252
|
+
│ └── ui/ # React Web UI Dashboard
|
|
253
|
+
└── package.json
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Roadmap
|
|
257
|
+
|
|
258
|
+
- [x] **Web Dashboard**: Local UI for management and logs.
|
|
259
|
+
- [x] **MCP Support**: Full integration with Model Context Protocol.
|
|
260
|
+
- [ ] **Discord Adapter**: Support for Discord interactions.
|
|
261
|
+
- [ ] **Plugin System**: Extend functionality via external modules.
|
|
262
|
+
|
|
263
|
+
## Contributing
|
|
264
|
+
|
|
265
|
+
1. Fork the repository.
|
|
266
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`).
|
|
267
|
+
3. Commit your changes (`git commit -m 'feat: Add amazing feature'`).
|
|
268
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
269
|
+
5. Open a Pull Request.
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
MIT
|
package/bin/morpheus.js
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
// Load .env file if it exists (Simple shim to avoid 'dotenv' dependency issues)
|
|
6
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
7
|
+
if (fs.existsSync(envPath)) {
|
|
8
|
+
try {
|
|
9
|
+
const envConfig = fs.readFileSync(envPath, 'utf-8');
|
|
10
|
+
envConfig.split('\n').forEach(line => {
|
|
11
|
+
const trimmed = line.trim();
|
|
12
|
+
if (!trimmed || trimmed.startsWith('#')) return;
|
|
13
|
+
|
|
14
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
15
|
+
if (match) {
|
|
16
|
+
const key = match[1].trim();
|
|
17
|
+
let value = match[2].trim();
|
|
18
|
+
// Remove quotes if present
|
|
19
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
20
|
+
value = value.slice(1, -1);
|
|
21
|
+
}
|
|
22
|
+
// Don't overwrite existing env vars
|
|
23
|
+
if (!process.env[key]) {
|
|
24
|
+
process.env[key] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
} catch (err) {
|
|
29
|
+
// Ignore .env errors
|
|
30
|
+
}
|
|
31
|
+
}
|
|
2
32
|
|
|
3
33
|
// Suppress experimental warnings for JSON modules
|
|
4
34
|
const originalEmit = process.emit;
|
|
@@ -7,6 +7,7 @@ import os from 'os';
|
|
|
7
7
|
import { ConfigManager } from '../config/manager.js';
|
|
8
8
|
import { DisplayManager } from '../runtime/display.js';
|
|
9
9
|
import { AudioAgent } from '../runtime/audio-agent.js';
|
|
10
|
+
import { convert } from 'telegram-markdown-v2';
|
|
10
11
|
export class TelegramAdapter {
|
|
11
12
|
bot = null;
|
|
12
13
|
isConnected = false;
|
|
@@ -22,6 +23,10 @@ export class TelegramAdapter {
|
|
|
22
23
|
this.display.log('Telegram adapter already connected.', { source: 'Telegram', level: 'warning' });
|
|
23
24
|
return;
|
|
24
25
|
}
|
|
26
|
+
const escapeMarkdownV2 = (text) => {
|
|
27
|
+
// Regex matches all special characters requiring escaping
|
|
28
|
+
return convert(text);
|
|
29
|
+
};
|
|
25
30
|
try {
|
|
26
31
|
this.display.log('Connecting to Telegram...', { source: 'Telegram' });
|
|
27
32
|
this.bot = new Telegraf(token);
|
|
@@ -96,7 +101,7 @@ export class TelegramAdapter {
|
|
|
96
101
|
filePath = await this.downloadToTemp(fileLink);
|
|
97
102
|
// Transcribe
|
|
98
103
|
this.display.log(`Transcribing audio for @${user}...`, { source: 'AgentAudio' });
|
|
99
|
-
const text = await this.audioAgent.transcribe(filePath, 'audio/ogg', apiKey);
|
|
104
|
+
const { text, usage } = await this.audioAgent.transcribe(filePath, 'audio/ogg', apiKey);
|
|
100
105
|
this.display.log(`Transcription success for @${user}: "${text}"`, { source: 'AgentAudio', level: 'success' });
|
|
101
106
|
// Reply with transcription (optional, maybe just process it?)
|
|
102
107
|
// The prompt says "reply with the answer".
|
|
@@ -105,7 +110,7 @@ export class TelegramAdapter {
|
|
|
105
110
|
await ctx.reply(`🎤 *Transcription*: _"${text}"_`, { parse_mode: 'Markdown' });
|
|
106
111
|
await ctx.sendChatAction('typing');
|
|
107
112
|
// Process with Agent
|
|
108
|
-
const response = await this.agent.chat(text);
|
|
113
|
+
const response = await this.agent.chat(text, usage);
|
|
109
114
|
// if (listeningMsg) {
|
|
110
115
|
// try {
|
|
111
116
|
// await ctx.telegram.deleteMessage(ctx.chat.id, listeningMsg.message_id);
|
|
@@ -22,18 +22,33 @@ export const configCommand = new Command('config')
|
|
|
22
22
|
try {
|
|
23
23
|
await scaffold(); // Ensure config exits
|
|
24
24
|
if (options.edit) {
|
|
25
|
-
console.log(chalk.cyan(`Opening
|
|
25
|
+
console.log(chalk.cyan(`Opening configuration files...`));
|
|
26
26
|
await open(PATHS.config);
|
|
27
|
+
if (await fs.pathExists(PATHS.mcps)) {
|
|
28
|
+
await open(PATHS.mcps);
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
31
|
else {
|
|
29
|
-
|
|
32
|
+
// Show config.yaml
|
|
33
|
+
console.log(chalk.bold('Main Configuration:'), chalk.cyan(PATHS.config));
|
|
30
34
|
console.log(chalk.gray('---'));
|
|
31
35
|
if (await fs.pathExists(PATHS.config)) {
|
|
32
36
|
const content = await fs.readFile(PATHS.config, 'utf8');
|
|
33
37
|
console.log(content);
|
|
34
38
|
}
|
|
35
39
|
else {
|
|
36
|
-
console.log(chalk.yellow('Config file not found
|
|
40
|
+
console.log(chalk.yellow('Config file not found.'));
|
|
41
|
+
}
|
|
42
|
+
console.log(chalk.gray('---\n'));
|
|
43
|
+
// Show mcps.json
|
|
44
|
+
console.log(chalk.bold('MCP Configuration:'), chalk.cyan(PATHS.mcps));
|
|
45
|
+
console.log(chalk.gray('---'));
|
|
46
|
+
if (await fs.pathExists(PATHS.mcps)) {
|
|
47
|
+
const content = await fs.readFile(PATHS.mcps, 'utf8');
|
|
48
|
+
console.log(content);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log(chalk.yellow('MCP config file not found (create it to add tools).'));
|
|
37
52
|
}
|
|
38
53
|
console.log(chalk.gray('---'));
|
|
39
54
|
}
|
|
@@ -4,7 +4,7 @@ import chalk from 'chalk';
|
|
|
4
4
|
import { ConfigManager } from '../../config/manager.js';
|
|
5
5
|
import { renderBanner } from '../utils/render.js';
|
|
6
6
|
import { DisplayManager } from '../../runtime/display.js';
|
|
7
|
-
import { scaffold } from '../../runtime/scaffold.js';
|
|
7
|
+
// import { scaffold } from '../../runtime/scaffold.js';
|
|
8
8
|
export const initCommand = new Command('init')
|
|
9
9
|
.description('Initialize Morpheus configuration')
|
|
10
10
|
.action(async () => {
|
|
@@ -12,8 +12,8 @@ export const initCommand = new Command('init')
|
|
|
12
12
|
renderBanner();
|
|
13
13
|
const configManager = ConfigManager.getInstance();
|
|
14
14
|
const currentConfig = await configManager.load();
|
|
15
|
-
// Ensure directory exists
|
|
16
|
-
await scaffold();
|
|
15
|
+
// Ensure directory exists - Handled by preAction hook
|
|
16
|
+
// await scaffold();
|
|
17
17
|
display.log(chalk.blue('Let\'s set up your Morpheus agent!'));
|
|
18
18
|
try {
|
|
19
19
|
const name = await input({
|
package/dist/cli/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { statusCommand } from './commands/status.js';
|
|
|
8
8
|
import { configCommand } from './commands/config.js';
|
|
9
9
|
import { doctorCommand } from './commands/doctor.js';
|
|
10
10
|
import { initCommand } from './commands/init.js';
|
|
11
|
+
import { scaffold } from '../runtime/scaffold.js';
|
|
11
12
|
// Helper to read package.json version
|
|
12
13
|
const getVersion = () => {
|
|
13
14
|
try {
|
|
@@ -28,6 +29,9 @@ export async function cli() {
|
|
|
28
29
|
.name('morpheus')
|
|
29
30
|
.description('Morpheus CLI Agent')
|
|
30
31
|
.version(getVersion());
|
|
32
|
+
program.hook('preAction', async () => {
|
|
33
|
+
await scaffold();
|
|
34
|
+
});
|
|
31
35
|
program.addCommand(initCommand);
|
|
32
36
|
program.addCommand(startCommand);
|
|
33
37
|
program.addCommand(stopCommand);
|
|
@@ -36,3 +40,7 @@ export async function cli() {
|
|
|
36
40
|
program.addCommand(doctorCommand);
|
|
37
41
|
program.parse(process.argv);
|
|
38
42
|
}
|
|
43
|
+
// Support direct execution via tsx
|
|
44
|
+
if (import.meta.url.startsWith('file:') && (process.argv[1]?.endsWith('index.ts') || process.argv[1]?.endsWith('cli/index.js'))) {
|
|
45
|
+
cli();
|
|
46
|
+
}
|