morpheus-cli 0.4.15 → 0.5.1

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.
Files changed (51) hide show
  1. package/README.md +293 -1115
  2. package/dist/channels/telegram.js +379 -74
  3. package/dist/cli/commands/doctor.js +34 -0
  4. package/dist/cli/commands/init.js +128 -0
  5. package/dist/cli/commands/restart.js +32 -14
  6. package/dist/cli/commands/start.js +28 -12
  7. package/dist/config/manager.js +82 -0
  8. package/dist/config/mcp-manager.js +19 -1
  9. package/dist/config/schemas.js +9 -0
  10. package/dist/devkit/tools/network.js +1 -1
  11. package/dist/http/api.js +399 -10
  12. package/dist/runtime/apoc.js +25 -17
  13. package/dist/runtime/memory/sati/repository.js +30 -2
  14. package/dist/runtime/memory/sati/service.js +46 -15
  15. package/dist/runtime/memory/sati/system-prompts.js +71 -29
  16. package/dist/runtime/memory/session-embedding-worker.js +3 -3
  17. package/dist/runtime/memory/sqlite.js +24 -0
  18. package/dist/runtime/memory/trinity-db.js +203 -0
  19. package/dist/runtime/neo.js +124 -0
  20. package/dist/runtime/oracle.js +252 -205
  21. package/dist/runtime/providers/factory.js +1 -12
  22. package/dist/runtime/session-embedding-scheduler.js +1 -1
  23. package/dist/runtime/tasks/context.js +53 -0
  24. package/dist/runtime/tasks/dispatcher.js +91 -0
  25. package/dist/runtime/tasks/notifier.js +68 -0
  26. package/dist/runtime/tasks/repository.js +370 -0
  27. package/dist/runtime/tasks/types.js +1 -0
  28. package/dist/runtime/tasks/worker.js +99 -0
  29. package/dist/runtime/tools/__tests__/tools.test.js +1 -3
  30. package/dist/runtime/tools/apoc-tool.js +61 -8
  31. package/dist/runtime/tools/delegation-guard.js +29 -0
  32. package/dist/runtime/tools/factory.js +1 -1
  33. package/dist/runtime/tools/index.js +2 -3
  34. package/dist/runtime/tools/morpheus-tools.js +742 -0
  35. package/dist/runtime/tools/neo-tool.js +109 -0
  36. package/dist/runtime/tools/trinity-tool.js +98 -0
  37. package/dist/runtime/trinity-connector.js +611 -0
  38. package/dist/runtime/trinity-crypto.js +52 -0
  39. package/dist/runtime/trinity.js +246 -0
  40. package/dist/runtime/webhooks/dispatcher.js +10 -19
  41. package/dist/types/config.js +10 -0
  42. package/dist/ui/assets/index-DP2V4kRd.js +112 -0
  43. package/dist/ui/assets/index-mglRG5Zw.css +1 -0
  44. package/dist/ui/index.html +2 -2
  45. package/dist/ui/sw.js +1 -1
  46. package/package.json +6 -1
  47. package/dist/runtime/tools/analytics-tools.js +0 -139
  48. package/dist/runtime/tools/config-tools.js +0 -64
  49. package/dist/runtime/tools/diagnostic-tools.js +0 -153
  50. package/dist/ui/assets/index-LemKVRjC.js +0 -112
  51. package/dist/ui/assets/index-TCQ7VNYO.css +0 -1
package/README.md CHANGED
@@ -1,16 +1,26 @@
1
- <div align="center">
1
+ <div align="center">
2
2
  <img src="./assets/logo.png" alt="Morpheus Logo" width="220" />
3
3
  </div>
4
4
 
5
5
  # Morpheus
6
6
 
7
- > **Morpheus is a local-first AI operator that bridges developers and machines.**
7
+ Morpheus is a local-first AI operator for developers.
8
+ It runs as a daemon and orchestrates LLMs, MCP tools, DevKit tools, memory, and channels (Web UI, Telegram, API, webhooks).
8
9
 
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
+ ## Why Morpheus
11
+ - Local-first persistence (sessions, messages, usage, tasks).
12
+ - Multi-agent architecture (Oracle, Neo, Apoc, Sati).
13
+ - Async task execution with queue + worker + notifier.
14
+ - Rich operational visibility in UI (chat traces, tasks, usage, logs).
10
15
 
11
- ## Installation
16
+ ## Multi-Agent Roles
17
+ - `Oracle`: orchestration and routing. Decides direct answer vs async delegation.
18
+ - `Neo`: MCP and internal operational tools (config, diagnostics, analytics).
19
+ - `Apoc`: DevTools/browser execution (filesystem, shell, git, network, packages, processes, system, browser automation).
20
+ - `Sati`: long-term memory retrieval/evaluation.
21
+ - `Trinity`: database specialist. Executes queries, introspects schemas, and manages registered databases (PostgreSQL, MySQL, SQLite, MongoDB).
12
22
 
13
- Install Morpheus globally via npm:
23
+ ## Installation
14
24
 
15
25
  ```bash
16
26
  npm install -g morpheus-cli
@@ -20,1206 +30,374 @@ npm install -g morpheus-cli
20
30
 
21
31
  ### 1. Initialize
22
32
 
23
- Set up your configuration (API keys, preferences):
24
-
25
33
  ```bash
26
34
  morpheus init
27
35
  ```
28
36
 
29
- ### 2. Start the Agent
37
+ Creates:
38
+ - `~/.morpheus/zaion.yaml`
39
+ - `~/.morpheus/mcps.json`
40
+ - local memory/log folders
30
41
 
31
- Run the background daemon and Web UI:
42
+ ### 2. Start
32
43
 
33
44
  ```bash
34
45
  morpheus start
35
46
  ```
36
47
 
37
- This will:
38
- - Start the agent process
39
- - Launch the Web UI at http://localhost:3333
40
- - If an instance is already running, prompt whether to stop it and start a new one
41
-
42
- #### Auto-approve restart
43
-
44
- If you want to automatically stop any running instance and start a new one without prompting:
48
+ Useful flags:
45
49
 
46
50
  ```bash
47
- morpheus start -y
48
- # or
49
- morpheus start --yes
51
+ morpheus start -y # auto-restart if another instance is running
52
+ morpheus start --no-ui # disable web UI
53
+ morpheus start --port 3333 # override UI port
50
54
  ```
51
55
 
52
- ### Other Commands
56
+ ### 3. Control Commands
53
57
 
54
58
  ```bash
55
- # Check if Morpheus is running
56
59
  morpheus status
57
-
58
- # Stop the agent
59
60
  morpheus stop
60
-
61
- # Restart the agent
62
61
  morpheus restart
63
-
64
- # Diagnose issues
65
62
  morpheus doctor
66
-
67
- # Manage sessions
68
- morpheus session new # Archive current and start new
69
- morpheus session status # Check current session info
63
+ morpheus session new
64
+ morpheus session status
70
65
  ```
71
66
 
72
- ## Troubleshooting
73
-
74
- ### Command not found
75
-
76
- If you installed successfully but can't run the `morpheus` command:
77
-
78
- 1. **Check your PATH**: Ensure your global npm bin directory is in your system PATH.
79
- - Run `npm bin -g` to see the folder.
80
- - On Windows, this is usually `%APPDATA%\npm`.
81
- - On Linux/Mac, verify `echo $PATH`.
82
- 2. **Restart Terminal**: New installations might not be visible until you restart your shell.
67
+ ## Async Task Execution
83
68
 
84
- ## Using NPX
85
- You can run Morpheus without installing it globally using `npx`:
69
+ Morpheus uses asynchronous delegation by default:
86
70
 
87
- ```bash
88
-
89
- npx morpheus-cli init
71
+ 1. Oracle receives user request.
72
+ 2. If execution is needed, Oracle calls `neo_delegate`, `apoc_delegate`, or `trinity_delegate`.
73
+ 3. Delegate tool creates a row in `tasks` table with origin metadata (`channel`, `session`, `message`, `user`).
74
+ 4. Oracle immediately acknowledges task creation.
75
+ 5. `TaskWorker` executes pending tasks (routes `trinit` tasks to Trinity agent).
76
+ 6. `TaskNotifier` sends completion/failure through `TaskDispatcher`.
90
77
 
91
- npx morpheus-cli start
92
-
93
- ```
78
+ Important behavior:
79
+ - Oracle stays responsive while tasks run.
80
+ - Delegations must be atomic (single objective per task).
81
+ - Duplicate/fabricated task acknowledgements are blocked by validation against DB.
82
+ - Status follow-ups are handled by Oracle through `task_query` (no delegation required).
94
83
 
95
- ## Technical Overview
96
-
97
- 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).
98
-
99
- ### Core Components
100
-
101
- - **Runtime (`src/runtime/`)**: The heart of the application. Manages the Oracle (agent) lifecycle, provider instantiation, and command execution.
102
- - **CLI (`src/cli/`)**: Built with `commander`, handles user interaction, configuration, and daemon control (`start`, `stop`, `status`).
103
- - **Configuration (`src/config/`)**: Singleton-based configuration manager using `zod` for validation and `js-yaml` for persistence (`~/.morpheus/zaion.yaml`).
104
- - **Channels (`src/channels/`)**: Adapters for external communication. Currently supports Telegram (`telegraf`) with strict user whitelisting.
105
-
106
- ## Features
107
-
108
- ### 🖥️ Web Dashboard
109
- Local React-based UI to manage recordings, chat history, and system status across your agent instances.
110
-
111
- **New: Interactive Web Chat**
112
- - Full-featured chat interface accessible from the browser
113
- - Session management: create, archive, delete, and rename sessions
114
- - Cross-channel visibility: view and interact with sessions started on any channel (Telegram, Web, etc.)
115
- - Real-time messaging with the Oracle agent
116
- - Responsive design with collapsible sidebar
117
- - Full support for Light and Dark (Matrix) themes
118
-
119
- #### 🔒 UI Authentication
120
- To protect your Web UI, use the `THE_ARCHITECT_PASS` environment variable. This ensures only authorized users can access the dashboard and API.
121
-
122
- Additionally, you can use environment variables for API keys instead of storing them in the configuration file:
123
-
124
- | Variable | Description | Required |
125
- |----------|-------------|----------|
126
- | `OPENAI_API_KEY` | OpenAI API key (if using GPT) | No |
127
- | `ANTHROPIC_API_KEY` | Anthropic API key (if using Claude) | No |
128
- | `GOOGLE_API_KEY` | Google AI key (for Gemini LLM/Audio) | No |
129
- | `OPENROUTER_API_KEY` | OpenRouter API key (if using OpenRouter) | No |
130
- | `THE_ARCHITECT_PASS` | Web Dashboard access password | Recommended |
131
- | `TELEGRAM_BOT_TOKEN` | Telegram BotFather token | No |
132
-
133
- If these environment variables are set, they will take precedence over values stored in the configuration file.
134
-
135
- The system also supports generic environment variables that apply to all providers:
136
-
137
- | Variable | Description | Applies To |
138
- |----------|-------------|------------|
139
- | `MORPHEUS_AGENT_NAME` | Name of the agent | agent.name |
140
- | `MORPHEUS_AGENT_PERSONALITY` | Personality of the agent | agent.personality |
141
- | `MORPHEUS_LLM_PROVIDER` | LLM provider to use | llm.provider |
142
- | `MORPHEUS_LLM_MODEL` | Model name for LLM | llm.model |
143
- | `MORPHEUS_LLM_TEMPERATURE` | Temperature setting for LLM | llm.temperature |
144
- | `MORPHEUS_LLM_MAX_TOKENS` | Maximum tokens for LLM | llm.max_tokens |
145
- | `MORPHEUS_LLM_CONTEXT_WINDOW` | Context window size for LLM | llm.context_window |
146
- | `MORPHEUS_LLM_API_KEY` | Generic API key for LLM (lower precedence than provider-specific keys) | llm.api_key |
147
- | `MORPHEUS_SATI_PROVIDER` | Sati provider to use | santi.provider |
148
- | `MORPHEUS_SATI_MODEL` | Model name for Sati | santi.model |
149
- | `MORPHEUS_SATI_TEMPERATURE` | Temperature setting for Sati | santi.temperature |
150
- | `MORPHEUS_SATI_MAX_TOKENS` | Maximum tokens for Sati | santi.max_tokens |
151
- | `MORPHEUS_SATI_CONTEXT_WINDOW` | Context window size for Sati | santi.context_window |
152
- | `MORPHEUS_SATI_API_KEY` | Generic API key for Sati (lower precedence than provider-specific keys) | santi.api_key |
153
- | `MORPHEUS_SATI_MEMORY_LIMIT` | Memory retrieval limit for Sati | santi.memory_limit |
154
- | `MORPHEUS_SATI_MEMORY_LIMIT` | Memory retrieval limit for Sati | santi.memory_limit |
155
- | `MORPHEUS_SATI_ENABLED_ARCHIVED_SESSIONS`| Enable/disable retrieval of archived sessions in Sati | santi.enableArchivedSessions |
156
- | `MORPHEUS_APOC_PROVIDER` | Apoc LLM provider | apoc.provider |
157
- | `MORPHEUS_APOC_MODEL` | Model name for Apoc | apoc.model |
158
- | `MORPHEUS_APOC_TEMPERATURE` | Temperature for Apoc | apoc.temperature |
159
- | `MORPHEUS_APOC_MAX_TOKENS` | Maximum tokens for Apoc | apoc.max_tokens |
160
- | `MORPHEUS_APOC_API_KEY` | API key for Apoc (falls back to provider-specific key) | apoc.api_key |
161
- | `MORPHEUS_APOC_WORKING_DIR` | Working directory for Apoc file/shell operations | apoc.working_dir |
162
- | `MORPHEUS_APOC_TIMEOUT_MS` | Timeout in ms for Apoc shell operations (default: 30000) | apoc.timeout_ms |
163
- | `MORPHEUS_AUDIO_MODEL` | Model name for audio processing | audio.model |
164
- | `MORPHEUS_AUDIO_ENABLED` | Enable/disable audio processing | audio.enabled |
165
- | `MORPHEUS_AUDIO_API_KEY` | Generic API key for audio (lower precedence than provider-specific keys) | audio.apiKey |
166
- | `MORPHEUS_AUDIO_MAX_DURATION` | Max duration for audio processing | audio.maxDurationSeconds |
167
- | `MORPHEUS_TELEGRAM_ENABLED` | Enable/disable Telegram channel | channels.telegram.enabled |
168
- | `MORPHEUS_TELEGRAM_TOKEN` | Telegram bot token | channels.telegram.token |
169
- | `MORPHEUS_TELEGRAM_ALLOWED_USERS` | Comma-separated list of allowed Telegram user IDs | channels.telegram.allowedUsers |
170
- | `MORPHEUS_UI_ENABLED` | Enable/disable Web UI | ui.enabled |
171
- | `MORPHEUS_UI_PORT` | Port for Web UI | ui.port |
172
- | `MORPHEUS_LOGGING_ENABLED` | Enable/disable logging | logging.enabled |
173
- | `MORPHEUS_LOGGING_LEVEL` | Logging level | logging.level |
174
- | `MORPHEUS_LOGGING_RETENTION` | Log retention period | logging.retention |
175
-
176
- **Precedence Order**: The system follows this order of precedence when resolving configuration values:
177
- 1. Provider-specific environment variable (e.g., `OPENAI_API_KEY`) - Highest priority
178
- 2. Generic environment variable (e.g., `MORPHEUS_LLM_API_KEY`) - Medium priority
179
- 3. Configuration file value (e.g., `config.llm.api_key`) - Lower priority
180
- 4. Default value - Lowest priority
181
-
182
- > **Note**: If `THE_ARCHITECT_PASS` is not set, the system will use the default password `iamthearchitect`. This is less secure and it's recommended to set your own password in production environments.
183
-
184
- **Option 1: Using a `.env` file**
185
- Create a `.env` file in the root of your project:
186
-
187
- ```env
188
- OPENAI_API_KEY="your-openai-api-key"
189
- ANTHROPIC_API_KEY="your-anthropic-api-key"
190
- GOOGLE_API_KEY="your-google-api-key"
191
- THE_ARCHITECT_PASS="your-secure-password"
192
- TELEGRAM_BOT_TOKEN="your-telegram-bot-token"
193
- OPENROUTER_API_KEY="your-openrouter-api-key"
194
- ```
84
+ ## Telegram Experience
195
85
 
196
- **Option 2: Using Shell export**
86
+ Telegram responses use rich HTML formatting conversion with:
87
+ - bold/italic/list rendering from markdown-like text
88
+ - inline code and fenced code blocks
89
+ - auto-wrapped UUIDs in `<code>` for easier copy
197
90
 
198
- ```bash
199
- export OPENAI_API_KEY="your-openai-api-key"
200
- export ANTHROPIC_API_KEY="your-anthropic-api-key"
201
- export GOOGLE_API_KEY="your-google-api-key"
202
- export OPENROUTER_API_KEY="your-openrouter-api-key"
203
- export THE_ARCHITECT_PASS="your-secure-password"
204
- export TELEGRAM_BOT_TOKEN="your-telegram-bot-token"
205
- morpheus start
206
- ```
91
+ Task results are delivered proactively with metadata (task id, agent, status) and output/error body.
207
92
 
208
- When enabled:
209
- - The Web UI will redirect to a Login page.
210
- - API requests require the `x-architect-pass` header.
211
- - The session is persisted locally in your browser.
93
+ ## Web UI
212
94
 
213
- ### 🧩 MCP Support (Model Context Protocol)
214
- Full integration with [Model Context Protocol](https://modelcontextprotocol.io/), allowing Morpheus to use standardized tools from any MCP-compatible server.
95
+ The dashboard includes:
96
+ - Chat with session management
97
+ - Tasks page (stats, filters, details, retry)
98
+ - Agent settings (Oracle/Sati/Neo/Apoc/Trinity)
99
+ - MCP manager (add/edit/delete/toggle/reload)
100
+ - Sati memories (search, bulk delete)
101
+ - Usage stats and model pricing
102
+ - Trinity databases (register/test/refresh schema)
103
+ - Webhooks and notification inbox
104
+ - Logs viewer
215
105
 
216
- ### 🛠️ Apoc (DevTools Subagent)
106
+ Chat-specific rendering:
107
+ - AI messages rendered as markdown
108
+ - Tool payloads shown in collapsible blocks
109
+ - SATI-related tool content grouped under `SATI Memory`
110
+ - per-message token badge (`input/output`)
217
111
 
218
- Morpheus includes **Apoc**, a specialized subagent invoked by Oracle whenever the user requests developer-level operations. Apoc runs with access to the **DevKit** tool set:
112
+ ## Configuration (`~/.morpheus/zaion.yaml`)
219
113
 
220
- | Tool Group | Capabilities |
221
- |---|---|
222
- | **Filesystem** | Read, write, append, delete files and directories |
223
- | **Shell** | Execute shell commands and scripts with timeout control |
224
- | **Git** | status, log, diff, commit, push, pull, clone, branch |
225
- | **Packages** | npm/yarn install, update, audit, package.json inspection |
226
- | **Processes** | List running processes, check ports, terminate processes |
227
- | **Network** | curl, ping, DNS lookups, HTTP requests |
228
- | **System** | Environment variables, OS info, disk space, memory usage |
229
-
230
- Oracle delegates to Apoc via the `apoc_delegate` tool when you ask things like:
231
- - *"Run npm install and show me any errors"*
232
- - *"What's the git status of this repo?"*
233
- - *"Read the contents of config.json"*
234
- - *"Execute the build script and tell me what happened"*
235
-
236
- Apoc is independently configurable — use a different (e.g., faster, cheaper) model than Oracle for tool execution tasks.
237
-
238
- ### 🧠 Sati (Long-Term Memory)
239
- Morpheus features a dedicated middleware system called **Sati** (Mindfulness) that provides long-term memory capabilities.
240
- - **Automated Storage**: Automatically extracts and saves preferences, project details, and facts from conversations.
241
- - **Contextual Retrieval**: Injects relevant memories into the context based on your current query.
242
- - **Data Privacy**: Stored in a local, independent SQLite database (`santi-memory.db`), ensuring sensitive data is handled securely and reducing context window usage.
243
- - **Memory Management**: View and manage your long-term memories through the Web UI or via API endpoints.
244
-
245
- ### 🪝 Webhooks & Notifications
246
-
247
- Morpheus includes a **Webhook System** that lets any external service (GitHub Actions, CI/CD pipelines, monitoring tools, etc.) trigger Oracle and receive the result asynchronously.
248
-
249
- **How it works:**
250
- 1. Create a webhook via the Web UI or API — give it a name (slug) and a prompt.
251
- 2. You receive a unique `api_key` for that webhook.
252
- 3. Trigger it from anywhere by posting JSON to `POST /api/webhooks/trigger/<name>` with the `x-api-key` header.
253
- 4. Morpheus runs Oracle with your prompt + the received payload in the background.
254
- 5. The result is saved as a **Notification** and optionally pushed to Telegram.
255
-
256
- **Example — trigger from GitHub Actions:**
257
114
  ```yaml
258
- - name: Notify Morpheus of deployment
259
- run: |
260
- curl -s -X POST https://your-morpheus-host/api/webhooks/trigger/deploy-done \
261
- -H "x-api-key: ${{ secrets.MORPHEUS_WEBHOOK_KEY }}" \
262
- -H "Content-Type: application/json" \
263
- -d '{"workflow":"${{ github.workflow }}","status":"success","ref":"${{ github.ref }}"}'
264
- ```
265
-
266
- **Security:** Each webhook has its own `api_key` (UUID). The key is sent in the `x-api-key` header — never in the URL — to prevent leakage in server logs. Management endpoints remain protected by `THE_ARCHITECT_PASS`.
267
-
268
- **Notification channels:** `ui` (Web UI inbox with unread badge) and/or `telegram` (proactive push message).
269
-
270
- ### 📊 Usage Analytics
271
- 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.
272
-
273
- ### 🎙️ Audio Transcription (Telegram)
274
- Send voice messages directly to the Telegram bot. Morpheus will:
275
- 1. Transcribe the audio using the configured provider.
276
- 2. Process the text as a standard prompt.
277
- 3. Reply with the answer.
278
-
279
- Supported audio providers:
280
-
281
- | Provider | Method | Model example |
282
- |---|---|---|
283
- | **Google Gemini** | Native audio file upload | `gemini-2.5-flash-lite` |
284
- | **OpenAI** | Whisper API (`/audio/transcriptions`) | `whisper-1` |
285
- | **OpenRouter** | `input_audio` via `@openrouter/sdk` (multimodal models) | `google/gemini-2.5-flash` |
286
- | **Ollama** | Whisper local via OpenAI-compatible endpoint | `whisper` |
287
-
288
- > Ollama requires a Whisper model loaded: `ollama pull whisper`
289
-
290
- *Configure `audio.provider` and `audio.apiKey` in Settings or `config.yaml`.*
291
-
292
- ### 🤖 Telegram Commands
293
- The Morpheus Telegram bot supports several commands for interacting with the agent:
294
-
295
- - `/start` - Show welcome message and available commands
296
- - `/status` - Check the status of the Morpheus agent
297
- - `/doctor` - Diagnose environment and configuration issues
298
- - `/stats` - Show token usage statistics
299
- - `/help` - Show available commands
300
- - `/zaion` - Show system configurations
301
- - `/sati <qnt>` - Show specific memories
302
- - `/newsession` - Archive current session and start fresh
303
- - `/sessions` - List all sessions with options to switch, archive, or delete
304
- - `/restart` - Restart the Morpheus agent
305
- - `/mcp` or `/mcps` - List registered MCP servers
306
-
307
- ## Development Setup
308
-
309
- This guide is for developers contributing to the Morpheus codebase.
310
-
311
- ### Prerequisites
312
-
313
- - **Node.js**: >= 18.x
314
- - **npm**: >= 9.x
315
- - **TypeScript**: >= 5.x
316
-
317
- ### 1. Clone & Install
318
-
319
- ```bash
320
- git clone https://github.com/your-org/morpheus.git
321
- cd morpheus
322
- npm install
323
- ```
324
-
325
- ### 2. Build
326
-
327
- Compile TypeScript source to `dist/` and build the Web UI.
328
-
329
- ```bash
330
- npm run build
331
- ```
332
-
333
- ### 3. Run the CLI
334
-
335
- You can run the CLI directly from the source using `npm start`.
336
-
337
- ```bash
338
- # Initialize configuration (creates ~/.morpheus)
339
- npm start -- init
115
+ agent:
116
+ name: morpheus
117
+ personality: helpful_dev
340
118
 
341
- # Start the daemon
342
- npm start -- start
119
+ llm: # Oracle
120
+ provider: openai
121
+ model: gpt-4o
122
+ temperature: 0.7
123
+ context_window: 100
124
+ api_key: env:OPENAI_API_KEY
125
+
126
+ sati:
127
+ provider: openai
128
+ model: gpt-4o-mini
129
+ temperature: 0.3
130
+ memory_limit: 100
131
+ enabled_archived_sessions: true
132
+
133
+ neo:
134
+ provider: openai
135
+ model: gpt-4o-mini
136
+ temperature: 0.2
137
+ context_window: 100
343
138
 
344
- # Check status
345
- npm start -- status
346
- ```
139
+ apoc:
140
+ provider: openai
141
+ model: gpt-4o-mini
142
+ temperature: 0.2
143
+ working_dir: /home/user/projects
144
+ timeout_ms: 30000
347
145
 
348
- ### 4. Configuration
146
+ trinity:
147
+ provider: openai
148
+ model: gpt-4o-mini
149
+ temperature: 0.2
349
150
 
350
- The configuration file is located at `~/.morpheus/zaion.yaml`. You can edit it manually or use the `morpheus config` command.
151
+ runtime:
152
+ async_tasks:
153
+ enabled: true
351
154
 
352
- ```yaml
353
- agent:
354
- name: "Morpheus"
355
- personality: "stoic, wise, and helpful"
356
- llm:
357
- provider: "openai" # options: openai, anthropic, ollama, gemini
358
- model: "gpt-4-turbo"
359
- temperature: 0.7
360
- context_window: 100 # Number of messages to load into LLM context
361
- api_key: "sk-..."
362
- santi: # Optional: Sati (Long-Term Memory) specific settings
363
- provider: "openai" # defaults to llm.provider
364
- model: "gpt-4o"
365
- memory_limit: 1000 # Number of messages/items to retrieve
366
- apoc: # Optional: Apoc DevTools subagent settings
367
- provider: "openai" # defaults to llm.provider (can use a cheaper/faster model)
368
- model: "gpt-4o-mini"
369
- temperature: 0.2
370
- working_dir: "/home/user/projects" # root dir for file/shell ops (defaults to process cwd)
371
- timeout_ms: 30000 # shell command timeout in ms
372
155
  channels:
373
156
  telegram:
374
- enabled: true
375
- token: "YOUR_TELEGRAM_BOT_TOKEN"
376
- allowedUsers: ["123456789"] # Your Telegram User ID
157
+ enabled: false
158
+ token: env:TELEGRAM_BOT_TOKEN
159
+ allowedUsers: ["123456789"]
377
160
  discord:
378
- enabled: false # Coming soon
161
+ enabled: false
379
162
 
380
- # Web UI Dashboard
381
163
  ui:
382
164
  enabled: true
383
165
  port: 3333
384
166
 
385
- # Audio Transcription Support
386
167
  audio:
387
168
  enabled: true
388
- provider: "google" # google | openai | openrouter | anthropic | ollama
389
- model: "gemini-2.5-flash-lite"
390
- apiKey: "YOUR_API_KEY" # Optional if using same provider as LLM
391
- base_url: "" # Required for openrouter/ollama
169
+ provider: google
170
+ model: gemini-2.5-flash-lite
392
171
  maxDurationSeconds: 300
172
+
173
+ logging:
174
+ enabled: true
175
+ level: info
176
+ retention: 14d
393
177
  ```
394
178
 
395
- ### 5. MCP Configuration
179
+ ## Environment Variables
180
+
181
+ Provider-specific keys:
182
+ - `OPENAI_API_KEY`
183
+ - `ANTHROPIC_API_KEY`
184
+ - `GOOGLE_API_KEY`
185
+ - `OPENROUTER_API_KEY`
186
+ - `TELEGRAM_BOT_TOKEN`
187
+ - `THE_ARCHITECT_PASS`
188
+
189
+ Security:
190
+ - `MORPHEUS_SECRET` — AES-256-GCM key for encrypting Trinity database passwords (required when using Trinity)
191
+
192
+ Generic Morpheus overrides (selected):
396
193
 
397
- Morpheus supports external tools via **MCP (Model Context Protocol)**. Configure your MCP servers in `~/.morpheus/mcps.json`:
194
+ | Variable | Target |
195
+ |---|---|
196
+ | `MORPHEUS_AGENT_NAME` | `agent.name` |
197
+ | `MORPHEUS_AGENT_PERSONALITY` | `agent.personality` |
198
+ | `MORPHEUS_LLM_PROVIDER` | `llm.provider` |
199
+ | `MORPHEUS_LLM_MODEL` | `llm.model` |
200
+ | `MORPHEUS_LLM_TEMPERATURE` | `llm.temperature` |
201
+ | `MORPHEUS_LLM_MAX_TOKENS` | `llm.max_tokens` |
202
+ | `MORPHEUS_LLM_CONTEXT_WINDOW` | `llm.context_window` |
203
+ | `MORPHEUS_LLM_API_KEY` | `llm.api_key` |
204
+ | `MORPHEUS_SATI_PROVIDER` | `sati.provider` |
205
+ | `MORPHEUS_SATI_MODEL` | `sati.model` |
206
+ | `MORPHEUS_SATI_TEMPERATURE` | `sati.temperature` |
207
+ | `MORPHEUS_SATI_MAX_TOKENS` | `sati.max_tokens` |
208
+ | `MORPHEUS_SATI_CONTEXT_WINDOW` | `sati.context_window` |
209
+ | `MORPHEUS_SATI_API_KEY` | `sati.api_key` |
210
+ | `MORPHEUS_SATI_MEMORY_LIMIT` | `sati.memory_limit` |
211
+ | `MORPHEUS_SATI_ENABLED_ARCHIVED_SESSIONS` | `sati.enabled_archived_sessions` |
212
+ | `MORPHEUS_NEO_PROVIDER` | `neo.provider` |
213
+ | `MORPHEUS_NEO_MODEL` | `neo.model` |
214
+ | `MORPHEUS_NEO_TEMPERATURE` | `neo.temperature` |
215
+ | `MORPHEUS_NEO_MAX_TOKENS` | `neo.max_tokens` |
216
+ | `MORPHEUS_NEO_CONTEXT_WINDOW` | `neo.context_window` |
217
+ | `MORPHEUS_NEO_API_KEY` | `neo.api_key` |
218
+ | `MORPHEUS_NEO_BASE_URL` | `neo.base_url` |
219
+ | `MORPHEUS_APOC_PROVIDER` | `apoc.provider` |
220
+ | `MORPHEUS_APOC_MODEL` | `apoc.model` |
221
+ | `MORPHEUS_APOC_TEMPERATURE` | `apoc.temperature` |
222
+ | `MORPHEUS_APOC_MAX_TOKENS` | `apoc.max_tokens` |
223
+ | `MORPHEUS_APOC_CONTEXT_WINDOW` | `apoc.context_window` |
224
+ | `MORPHEUS_APOC_API_KEY` | `apoc.api_key` |
225
+ | `MORPHEUS_APOC_WORKING_DIR` | `apoc.working_dir` |
226
+ | `MORPHEUS_APOC_TIMEOUT_MS` | `apoc.timeout_ms` |
227
+ | `MORPHEUS_TRINITY_PROVIDER` | `trinity.provider` |
228
+ | `MORPHEUS_TRINITY_MODEL` | `trinity.model` |
229
+ | `MORPHEUS_TRINITY_TEMPERATURE` | `trinity.temperature` |
230
+ | `MORPHEUS_TRINITY_API_KEY` | `trinity.api_key` |
231
+ | `MORPHEUS_AUDIO_PROVIDER` | `audio.provider` |
232
+ | `MORPHEUS_AUDIO_MODEL` | `audio.model` |
233
+ | `MORPHEUS_AUDIO_ENABLED` | `audio.enabled` |
234
+ | `MORPHEUS_AUDIO_API_KEY` | `audio.apiKey` |
235
+ | `MORPHEUS_AUDIO_MAX_DURATION` | `audio.maxDurationSeconds` |
236
+ | `MORPHEUS_TELEGRAM_ENABLED` | `channels.telegram.enabled` |
237
+ | `MORPHEUS_TELEGRAM_TOKEN` | `channels.telegram.token` |
238
+ | `MORPHEUS_TELEGRAM_ALLOWED_USERS` | `channels.telegram.allowedUsers` |
239
+ | `MORPHEUS_UI_ENABLED` | `ui.enabled` |
240
+ | `MORPHEUS_UI_PORT` | `ui.port` |
241
+ | `MORPHEUS_LOGGING_ENABLED` | `logging.enabled` |
242
+ | `MORPHEUS_LOGGING_LEVEL` | `logging.level` |
243
+ | `MORPHEUS_LOGGING_RETENTION` | `logging.retention` |
244
+
245
+ Precedence order:
246
+ 1. Provider-specific environment variable
247
+ 2. Generic `MORPHEUS_*` variable
248
+ 3. `zaion.yaml`
249
+ 4. Defaults
250
+
251
+ ## MCP Configuration
252
+
253
+ Configure MCP servers in `~/.morpheus/mcps.json`.
398
254
 
399
255
  ```json
400
256
  {
401
- "coolify": {
402
- "transport": "stdio",
403
- "command": "npx",
404
- "args": ["-y", "@coolify/mcp-server"],
405
- "env": {
406
- "COOLIFY_URL": "https://app.coolify.io",
407
- "COOLIFY_TOKEN": "your-token"
408
- }
409
- },
410
257
  "coingecko": {
411
258
  "transport": "http",
412
- "url": "https://mcps.mnunes.xyz/coingecko/mcp"
259
+ "url": "https://mcps.example.com/coingecko/mcp"
260
+ },
261
+ "filesystem": {
262
+ "transport": "stdio",
263
+ "command": "npx",
264
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "./"]
413
265
  }
414
266
  }
415
267
  ```
416
268
 
417
- ## API Endpoints
418
-
419
- Morpheus exposes several API endpoints for programmatic access to its features:
420
-
421
- ### Health Check Endpoints
422
-
423
- #### GET `/health`
424
- Public health check endpoint without authentication.
425
-
426
- * **Response:**
427
- ```json
428
- {
429
- "status": "healthy",
430
- "timestamp": "2026-02-05T21:30:00.000Z",
431
- "uptime": 123.45
432
- }
433
- ```
434
-
435
- #### GET `/api/health`
436
- Health check endpoint for the API (requires authentication).
437
-
438
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
439
- * **Response:**
440
- ```json
441
- {
442
- "status": "healthy",
443
- "timestamp": "2026-02-05T21:30:00.000Z",
444
- "uptime": 123.45
445
- }
446
- ```
447
-
448
- ### Status Endpoint
449
-
450
- #### GET `/api/status`
451
- Get the current status of the Morpheus agent.
452
-
453
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
454
- * **Response:**
455
- ```json
456
- {
457
- "status": "online",
458
- "uptimeSeconds": 1234.56,
459
- "pid": 12345,
460
- "projectVersion": "1.0.0",
461
- "nodeVersion": "v18.17.0",
462
- "agentName": "Morpheus",
463
- "llmProvider": "openai",
464
- "llmModel": "gpt-4-turbo"
465
- }
466
- ```
467
-
468
- ### Session Endpoints
469
-
470
- #### POST `/api/session/reset`
471
- Archive the current session and start a new one.
472
-
473
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
474
- * **Response:**
475
- ```json
476
- {
477
- "success": true,
478
- "message": "New session started"
479
- }
480
- ```
481
-
482
- #### POST `/api/session/status`
483
- Get the status of the current session.
484
-
485
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
486
- * **Response:**
487
- ```json
488
- {
489
- "id": "uuid-...",
490
- "messageCount": 42,
491
- "embedding_status": "pending"
492
- }
493
- ```
494
-
495
- ### Configuration Endpoints
496
-
497
- #### GET `/api/config`
498
- Retrieve the current configuration.
499
-
500
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
501
- * **Response:**
502
- ```json
503
- {
504
- "agent": {
505
- "name": "Morpheus",
506
- "personality": "stoic, wise, and helpful"
507
- },
508
- "llm": {
509
- "provider": "openai",
510
- "model": "gpt-4-turbo",
511
- "temperature": 0.7,
512
- "context_window": 100,
513
- "api_key": "***"
514
- },
515
- "santi": {
516
- "provider": "openai",
517
- "model": "gpt-4o",
518
- "memory_limit": 1000
519
- },
520
- "channels": {
521
- "telegram": {
522
- "enabled": true,
523
- "token": "***",
524
- "allowedUsers": ["123456789"]
525
- },
526
- "discord": {
527
- "enabled": false
528
- }
529
- },
530
- "ui": {
531
- "enabled": true,
532
- "port": 3333
533
- },
534
- "audio": {
535
- "enabled": true,
536
- "apiKey": "***",
537
- "maxDurationSeconds": 300
538
- }
539
- }
540
- ```
541
-
542
- #### POST `/api/config`
543
- Update the configuration.
544
-
545
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
546
- * **Body:** Complete configuration object (same structure as GET response).
547
- * **Response:**
548
- ```json
549
- {
550
- "agent": {
551
- "name": "Morpheus",
552
- "personality": "stoic, wise, and helpful"
553
- },
554
- "llm": {
555
- "provider": "openai",
556
- "model": "gpt-4-turbo",
557
- "temperature": 0.7,
558
- "context_window": 100,
559
- "api_key": "***"
560
- },
561
- "santi": {
562
- "provider": "openai",
563
- "model": "gpt-4o",
564
- "memory_limit": 1000
565
- },
566
- "channels": {
567
- "telegram": {
568
- "enabled": true,
569
- "token": "***",
570
- "allowedUsers": ["123456789"]
571
- },
572
- "discord": {
573
- "enabled": false
574
- }
575
- },
576
- "ui": {
577
- "enabled": true,
578
- "port": 3333
579
- },
580
- "audio": {
581
- "enabled": true,
582
- "apiKey": "***",
583
- "maxDurationSeconds": 300
584
- }
585
- }
586
- ```
587
-
588
- #### GET `/api/config/sati`
589
- Retrieve the Sati (long-term memory) configuration.
590
-
591
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
592
- * **Response:**
593
- ```json
594
- {
595
- "provider": "openai",
596
- "model": "gpt-4o",
597
- "memory_limit": 1000
598
- }
599
- ```
600
-
601
- #### POST `/api/config/sati`
602
- Update the Sati (long-term memory) configuration.
603
-
604
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
605
- * **Body:**
606
- ```json
607
- {
608
- "provider": "openai",
609
- "model": "gpt-4o",
610
- "memory_limit": 1000
611
- }
612
- ```
613
- * **Response:**
614
- ```json
615
- {
616
- "success": true
617
- }
618
- ```
619
-
620
- #### DELETE `/api/config/sati`
621
- Remove the Sati (long-term memory) configuration (falls back to Oracle config).
622
-
623
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
624
- * **Response:**
625
- ```json
626
- {
627
- "success": true
628
- }
629
- ```
630
-
631
-
632
- #### GET `/api/config/apoc`
633
- Retrieve the Apoc (DevTools subagent) configuration. Falls back to Oracle (LLM) config if not explicitly set.
634
-
635
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
636
- * **Response:**
637
- ```json
638
- {
639
- "provider": "openai",
640
- "model": "gpt-4o-mini",
641
- "temperature": 0.2,
642
- "api_key": "***",
643
- "working_dir": "/home/user/projects",
644
- "timeout_ms": 30000
645
- }
646
- ```
647
-
648
- #### POST `/api/config/apoc`
649
- Update the Apoc (DevTools subagent) configuration.
650
-
651
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
652
- * **Body:**
653
- ```json
654
- {
655
- "provider": "openai",
656
- "model": "gpt-4o-mini",
657
- "temperature": 0.2,
658
- "working_dir": "/home/user/projects",
659
- "timeout_ms": 30000
660
- }
661
- ```
662
- * **Response:**
663
- ```json
664
- {
665
- "success": true
666
- }
667
- ```
668
-
669
- #### DELETE `/api/config/apoc`
670
- Remove the Apoc configuration (falls back to Oracle config).
671
-
672
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
673
- * **Response:**
674
- ```json
675
- {
676
- "success": true
677
- }
678
- ```
679
-
680
- ### Statistics Endpoints
681
-
682
- #### GET `/api/stats/usage`
683
- Get global token usage statistics.
684
-
685
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
686
- * **Response:**
687
- ```json
688
- {
689
- "totalInputTokens": 12345,
690
- "totalOutputTokens": 6789,
691
- "totalTokens": 19134
692
- }
693
- ```
694
-
695
- #### GET `/api/stats/usage/grouped`
696
- Get token usage statistics grouped by provider and model.
697
-
698
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
699
- * **Response:**
700
- ```json
701
- [
702
- {
703
- "provider": "openai",
704
- "model": "gpt-4-turbo",
705
- "totalTokens": 12345,
706
- "inputTokens": 10000,
707
- "outputTokens": 2345,
708
- "messageCount": 100
709
- },
710
- {
711
- "provider": "anthropic",
712
- "model": "claude-3-opus",
713
- "totalTokens": 6789,
714
- "inputTokens": 5000,
715
- "outputTokens": 1789,
716
- "messageCount": 50
717
- }
718
- ]
719
- ```
720
-
721
- ### Sati Memories Endpoints
722
-
723
- #### GET `/api/sati/memories`
724
- Retrieve all memories stored by the Sati agent (long-term memory).
725
-
726
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
727
- * **Response:**
728
- ```json
729
- [
730
- {
731
- "id": "unique-id",
732
- "category": "work",
733
- "importance": "high",
734
- "summary": "Memory summary",
735
- "details": "Additional details of the memory",
736
- "hash": "unique-hash",
737
- "source": "source",
738
- "created_at": "2023-01-01T00:00:00.000Z",
739
- "updated_at": "2023-01-01T00:00:00.000Z",
740
- "last_accessed_at": "2023-01-01T00:00:00.000Z",
741
- "access_count": 5,
742
- "version": 1,
743
- "archived": false
744
- }
745
- ]
746
- ```
747
-
748
- #### DELETE `/api/sati/memories/:id`
749
- Archive (soft delete) a specific memory from the Sati agent.
750
-
751
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
752
- * **Parameters:** `id` - ID of the memory to archive.
753
- * **Response:**
754
- ```json
755
- {
756
- "success": true,
757
- "message": "Memory archived successfully"
758
- }
759
- ```
760
-
761
- #### POST `/api/sati/memories/bulk-delete`
762
- Archive (soft delete) multiple memories from the Sati agent at once.
763
-
764
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
765
- * **Body:**
766
- ```json
767
- {
768
- "ids": ["id1", "id2", "id3"]
769
- }
770
- ```
771
- * **Response:**
772
- ```json
773
- {
774
- "success": true,
775
- "message": "X memories archived successfully",
776
- "deletedCount": X
777
- }
778
- ```
779
-
780
- ### MCP Server Endpoints
781
-
782
- #### GET `/api/mcp/servers`
783
- List all registered MCP servers.
784
-
785
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
786
- * **Response:**
787
- ```json
788
- {
789
- "servers": [
790
- {
791
- "name": "coolify",
792
- "config": {
793
- "transport": "stdio",
794
- "command": "npx",
795
- "args": ["-y", "@coolify/mcp-server"],
796
- "env": {
797
- "COOLIFY_URL": "https://app.coolify.io",
798
- "COOLIFY_TOKEN": "your-token"
799
- }
800
- },
801
- "enabled": true
802
- },
803
- {
804
- "name": "coingecko",
805
- "config": {
806
- "transport": "http",
807
- "url": "https://mcps.mnunes.xyz/coingecko/mcp"
808
- },
809
- "enabled": false
810
- }
811
- ]
812
- }
813
- ```
814
-
815
- #### POST `/api/mcp/servers`
816
- Add a new MCP server.
817
-
818
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
819
- * **Body:**
820
- ```json
821
- {
822
- "name": "new-server",
823
- "config": {
824
- "transport": "stdio",
825
- "command": "npx",
826
- "args": ["-y", "@new-mcp-server"],
827
- "env": {
828
- "NEW_SERVER_URL": "https://example.com",
829
- "NEW_SERVER_TOKEN": "your-token"
830
- }
831
- }
832
- }
833
- ```
834
- * **Response:**
835
- ```json
836
- {
837
- "ok": true
838
- }
839
- ```
840
-
841
- #### PUT `/api/mcp/servers/:name`
842
- Update an existing MCP server.
843
-
844
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
845
- * **Parameters:** `name` - Name of the server to update.
846
- * **Body:**
847
- ```json
848
- {
849
- "transport": "stdio",
850
- "command": "npx",
851
- "args": ["-y", "@updated-mcp-server"],
852
- "env": {
853
- "UPDATED_SERVER_URL": "https://example.com",
854
- "UPDATED_SERVER_TOKEN": "your-updated-token"
855
- }
856
- }
857
- ```
858
- * **Response:**
859
- ```json
860
- {
861
- "ok": true
862
- }
863
- ```
864
-
865
- #### DELETE `/api/mcp/servers/:name`
866
- Delete an MCP server.
867
-
868
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
869
- * **Parameters:** `name` - Name of the server to delete.
870
- * **Response:**
871
- ```json
872
- {
873
- "ok": true
874
- }
875
- ```
876
-
877
- #### PATCH `/api/mcp/servers/:name/toggle`
878
- Enable or disable an MCP server.
879
-
880
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
881
- * **Parameters:** `name` - Name of the server to toggle.
882
- * **Body:**
883
- ```json
884
- {
885
- "enabled": true
886
- }
887
- ```
888
- * **Response:**
889
- ```json
890
- {
891
- "ok": true
892
- }
893
- ```
894
-
895
- ### Logging Endpoints
896
-
897
- #### GET `/api/logs`
898
- List all log files.
899
-
900
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
901
- * **Response:**
902
- ```json
903
- [
904
- {
905
- "name": "morpheus.log",
906
- "size": 10240,
907
- "modified": "2026-02-05T21:30:00.000Z"
908
- },
909
- {
910
- "name": "morpheus-2026-02-04.log",
911
- "size": 20480,
912
- "modified": "2026-02-04T21:30:00.000Z"
913
- }
914
- ]
915
- ```
916
-
917
- #### GET `/api/logs/:filename`
918
- Get the last lines of a specific log file.
919
-
920
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
921
- * **Parameters:** `filename` - Name of the log file to read.
922
- * **Query Parameters:** `limit` - Number of lines to return (default: 50).
923
- * **Response:**
924
- ```json
925
- {
926
- "lines": [
927
- "2026-02-05T21:30:00.000Z INFO: Starting Morpheus agent...",
928
- "2026-02-05T21:30:01.000Z DEBUG: Connected to OpenAI API",
929
- "2026-02-05T21:30:02.000Z INFO: Telegram bot initialized"
930
- ]
931
- }
932
- ```
933
-
934
- ### Control Endpoints
935
-
936
- #### POST `/api/restart`
937
- Restart the Morpheus agent.
938
-
939
- * **Authentication:** Requires `Authorization` header with the password set in `THE_ARCHITECT_PASS`.
940
- * **Response:**
941
- ```json
942
- {
943
- "success": true,
944
- "message": "Restart initiated. Process will shut down and restart shortly."
945
- }
946
- ```
947
-
948
- ### Webhook Endpoints
949
-
950
- All management endpoints require `x-architect-pass` authentication. The trigger endpoint is **public** — authenticated only by the per-webhook `x-api-key` header.
951
-
952
- #### POST `/api/webhooks/trigger/:webhook_name`
953
- Trigger a webhook and queue an Oracle agent execution in the background.
954
-
955
- * **Authentication:** `x-api-key: <webhook_api_key>` header (no `x-architect-pass` required).
956
- * **Parameters:** `webhook_name` — the slug of the webhook to trigger.
957
- * **Body:** Any JSON payload (forwarded to the agent as context).
958
- * **Response (202 Accepted):**
959
- ```json
960
- {
961
- "accepted": true,
962
- "notification_id": "uuid-..."
963
- }
964
- ```
965
- * **Errors:** `401` for missing/invalid api_key; `404` for webhook not found or disabled.
966
-
967
- #### GET `/api/webhooks`
968
- List all configured webhooks.
969
-
970
- * **Authentication:** `x-architect-pass` header.
971
- * **Response:**
972
- ```json
973
- [
974
- {
975
- "id": "uuid",
976
- "name": "deploy-done",
977
- "api_key": "uuid",
978
- "prompt": "Analyze the deployment result...",
979
- "enabled": true,
980
- "notification_channels": ["ui", "telegram"],
981
- "created_at": 1700000000000,
982
- "last_triggered_at": 1700001000000,
983
- "trigger_count": 42
984
- }
985
- ]
986
- ```
987
-
988
- #### POST `/api/webhooks`
989
- Create a new webhook.
990
-
991
- * **Authentication:** `x-architect-pass` header.
992
- * **Body:**
993
- ```json
994
- {
995
- "name": "deploy-done",
996
- "prompt": "A deployment just finished. Analyze the payload and summarize what happened.",
997
- "notification_channels": ["ui", "telegram"],
998
- "enabled": true
999
- }
1000
- ```
1001
- * **Response (201):** The created webhook object including the generated `api_key`.
1002
-
1003
- #### PUT `/api/webhooks/:id`
1004
- Update an existing webhook (prompt, channels, enabled status).
1005
-
1006
- * **Authentication:** `x-architect-pass` header.
1007
- * **Note:** The `name` (slug) and `api_key` fields are immutable via this endpoint.
1008
-
1009
- #### DELETE `/api/webhooks/:id`
1010
- Delete a webhook and all its associated notifications.
1011
-
1012
- * **Authentication:** `x-architect-pass` header.
1013
-
1014
- #### GET `/api/webhooks/notifications`
1015
- List webhook execution notifications.
1016
-
1017
- * **Authentication:** `x-architect-pass` header.
1018
- * **Query Parameters:** `unreadOnly=true` to filter unread notifications.
1019
- * **Response:**
1020
- ```json
1021
- [
1022
- {
1023
- "id": "uuid",
1024
- "webhook_id": "uuid",
1025
- "webhook_name": "deploy-done",
1026
- "status": "completed",
1027
- "payload": "{\"ref\":\"main\"}",
1028
- "result": "Deployment of main to production succeeded...",
1029
- "read": false,
1030
- "created_at": 1700001000000,
1031
- "completed_at": 1700001005000
1032
- }
1033
- ]
1034
- ```
1035
-
1036
- #### POST `/api/webhooks/notifications/read`
1037
- Mark notifications as read.
1038
-
1039
- * **Authentication:** `x-architect-pass` header.
1040
- * **Body:** `{ "ids": ["uuid1", "uuid2"] }`
1041
-
1042
- #### GET `/api/webhooks/notifications/unread-count`
1043
- Get the count of unread notifications (used by the sidebar badge).
1044
-
1045
- * **Authentication:** `x-architect-pass` header.
1046
- * **Response:** `{ "count": 3 }`
1047
-
1048
- ## Testing
1049
-
1050
- We use **Vitest** for testing.
1051
-
1052
- ```bash
1053
- # Run unit tests
1054
- npm test
1055
-
1056
- # Run tests in watch mode
1057
- npm run test:watch
1058
- ```
1059
-
1060
- ## Project Structure
1061
-
1062
- ```text
1063
- .
1064
- ├── assets/ # Static assets
1065
- ├── bin/ # CLI entry point (morpheus.js)
1066
- ├── specs/ # Technical specifications & documentation
1067
- ├── src/
1068
- │ ├── channels/ # Communication adapters (Telegram, etc.)
1069
- │ ├── cli/ # CLI commands and logic
1070
- │ ├── config/ # Configuration management
1071
- │ ├── runtime/ # Core agent logic, lifecycle, and providers
1072
- │ ├── apoc.ts # Apoc DevTools subagent (filesystem, shell, git, etc.)
1073
- │ ├── oracle.ts # Oracle main agent (LangChain ReactAgent)
1074
- │ └── providers/ # LLM provider factory (createBare for subagents)
1075
- ├── devkit/ # DevKit tool factories (filesystem, shell, git, network, packages, processes, system)
1076
- │ ├── types/ # Shared TypeScript definitions
1077
- │ └── ui/ # React Web UI Dashboard
1078
- └── package.json
1079
- ```
1080
-
1081
- ## Roadmap
1082
-
1083
- - [x] **Web Dashboard**: Local UI for management and logs.
1084
- - [x] **MCP Support**: Full integration with Model Context Protocol.
1085
- - [x] **Webhook System**: External triggers with Oracle execution and multi-channel notifications.
1086
- - [ ] **Discord Adapter**: Support for Discord interactions.
1087
- - [ ] **Plugin System**: Extend functionality via external modules.
1088
- - [ ] **Webhook Retry Logic**: Exponential backoff for failed Oracle executions.
1089
-
1090
- ## 🕵️ Privacy Protection
269
+ ## API Highlights
1091
270
 
1092
- The Web UI includes privacy protection headers to prevent indexing by search engines:
1093
- - HTML meta tags: `<meta name="robots" content="noindex, nofollow">`
1094
- - HTTP header: `X-Robots-Tag: noindex, nofollow`
271
+ Public endpoints:
272
+ - `GET /health`
273
+ - `GET /api/health`
274
+ - `POST /api/webhooks/trigger/:webhook_name` (auth via `x-api-key`)
1095
275
 
1096
- This ensures that your private agent dashboard remains private and is not discoverable by search engines.
276
+ Authenticated endpoints (`x-architect-pass`):
277
+ - Sessions: `/api/sessions*`
278
+ - Chat: `POST /api/chat`
279
+ - Tasks: `GET /api/tasks`, `GET /api/tasks/stats`, `GET /api/tasks/:id`, `POST /api/tasks/:id/retry`
280
+ - Config: `/api/config`, `/api/config/sati`, `/api/config/neo`, `/api/config/apoc`, `/api/config/trinity`
281
+ - MCP: `/api/mcp/*` (servers CRUD + reload + status)
282
+ - Sati memories: `/api/sati/memories*`
283
+ - Trinity databases: `GET/POST/PUT/DELETE /api/trinity/databases`, `POST /api/trinity/databases/:id/test`, `POST /api/trinity/databases/:id/refresh-schema`
284
+ - Usage/model pricing/logs/restart
285
+ - Webhook management and webhook notifications
1097
286
 
1098
- ## 🐳 Running with Docker
287
+ ## API Payload/Response Examples
1099
288
 
1100
- Morpheus can be easily deployed using Docker and Docker Compose. The container supports all environment variables for configuration.
1101
- The Docker image is publicly available at [Docker Hub](https://hub.docker.com/r/marcosnunesmbs/morpheus).
289
+ Auth header for protected endpoints:
1102
290
 
1103
- ### Prerequisites
1104
-
1105
- - Docker Engine
1106
- - Docker Compose
1107
-
1108
- ### Quick Start
1109
-
1110
- 1. Create a `.env` file with your configuration:
1111
-
1112
- ```bash
1113
- cp .env.example .env
1114
- # Edit .env with your actual API keys and settings
291
+ ```http
292
+ x-architect-pass: <THE_ARCHITECT_PASS>
1115
293
  ```
1116
294
 
1117
- 2. Build and start the container:
295
+ Example `POST /api/chat` payload:
1118
296
 
1119
- ```bash
1120
- docker-compose up -d
297
+ ```json
298
+ {
299
+ "sessionId": "d18e23e6-67db-4ec1-b614-95eeaf399827",
300
+ "message": "faça um ping em 8.8.8.8"
301
+ }
1121
302
  ```
1122
303
 
1123
- 3. Access the Web UI at `http://localhost:3333`
1124
-
1125
- ### Docker Compose Example
304
+ Example `POST /api/chat` response:
1126
305
 
1127
- Here's a complete example of how to run Morpheus using Docker Compose:
1128
-
1129
- ```yaml
1130
- version: '3.8'
1131
-
1132
- services:
1133
- morpheus:
1134
- image: marcosnunesmbs/morpheus:latest
1135
- container_name: morpheus-agent
1136
- ports:
1137
- - "3333:3333"
1138
- volumes:
1139
- - morpheus_data:/root/.morpheus
1140
- environment:
1141
- # LLM Configuration
1142
- - MORPHEUS_LLM_PROVIDER=openai
1143
- - MORPHEUS_LLM_MODEL=gpt-4o
1144
- - MORPHEUS_LLM_TEMPERATURE=0.7
1145
-
1146
- # API Keys
1147
- - OPENAI_API_KEY=your-openai-api-key
1148
- - ANTHROPIC_API_KEY=your-anthropic-api-key
1149
- - GOOGLE_API_KEY=your-google-api-key
1150
- - OPENROUTER_API_KEY=your-openrouter-api-key
1151
-
1152
- # Security
1153
- - THE_ARCHITECT_PASS=your-secure-password
1154
-
1155
- # Agent Configuration
1156
- - MORPHEUS_AGENT_NAME=morpheus
1157
- - MORPHEUS_AGENT_PERSONALITY=helpful_dev
1158
-
1159
- # UI Configuration
1160
- - MORPHEUS_UI_ENABLED=true
1161
- - MORPHEUS_UI_PORT=3333
1162
- restart: unless-stopped
306
+ ```json
307
+ {
308
+ "response": "Task created: 477fddfc-fab8-49e8-ac00-84b110e7f4ba (apoc)."
309
+ }
1163
310
  ```
1164
311
 
1165
- ### Using Docker Directly
312
+ Example `GET /api/tasks/:id` response:
1166
313
 
1167
- ```bash
1168
- # Build the image
1169
- docker build -t morpheus .
1170
-
1171
- # Run with environment variables
1172
- docker run -d \
1173
- --name morpheus-agent \
1174
- -p 3333:3333 \
1175
- -v morpheus_data:/root/.morpheus \
1176
- -e MORPHEUS_LLM_PROVIDER=openai \
1177
- -e OPENAI_API_KEY=your-api-key-here \
1178
- -e THE_ARCHITECT_PASS=your-password \
1179
- morpheus
314
+ ```json
315
+ {
316
+ "id": "477fddfc-fab8-49e8-ac00-84b110e7f4ba",
317
+ "agent": "apoc",
318
+ "status": "completed",
319
+ "input": "Ping 8.8.8.8 and report packet stats",
320
+ "context": "User asked from Telegram",
321
+ "output": "Host reachable. 0% loss.",
322
+ "error": null,
323
+ "origin_channel": "telegram",
324
+ "session_id": "d18e23e6-67db-4ec1-b614-95eeaf399827",
325
+ "origin_message_id": "727",
326
+ "origin_user_id": "5852279085",
327
+ "attempt_count": 1,
328
+ "max_attempts": 3,
329
+ "available_at": 1771558600000,
330
+ "created_at": 1771558600000,
331
+ "started_at": 1771558601050,
332
+ "finished_at": 1771558603030,
333
+ "updated_at": 1771558603030,
334
+ "worker_id": "task-worker-b16cb906",
335
+ "notify_status": "sent",
336
+ "notify_attempts": 0,
337
+ "notify_last_error": null,
338
+ "notified_at": 1771558604210
339
+ }
1180
340
  ```
1181
341
 
1182
- ### Environment Variables in Docker
1183
-
1184
- All environment variables described above work in Docker. The precedence order remains the same:
1185
- 1. Container environment variables
1186
- 2. Configuration file values
1187
- 3. Default values
342
+ Example webhook trigger payload (`POST /api/webhooks/trigger/:webhook_name`):
1188
343
 
1189
- ### Persistent Data
344
+ ```json
345
+ {
346
+ "event": "deploy_finished",
347
+ "environment": "production",
348
+ "status": "success",
349
+ "sha": "b8a6d4f"
350
+ }
351
+ ```
1190
352
 
1191
- The container stores configuration and data in `/root/.morpheus`. Mount a volume to persist data between container restarts:
353
+ Example webhook trigger response:
1192
354
 
1193
- ```yaml
1194
- volumes:
1195
- - morpheus_data:/root/.morpheus # Recommended for persistence
355
+ ```json
356
+ {
357
+ "accepted": true,
358
+ "notification_id": "17ce970d-cde0-4f06-9c9f-5ef92c48aa48"
359
+ }
1196
360
  ```
1197
361
 
1198
- ### Health Check
362
+ Complete payload and response examples for **all** endpoints are in `DOCUMENTATION.md` (Section `8. API Reference (Complete Payloads and Response Examples)`).
1199
363
 
1200
- The container includes a health check that verifies the health endpoint is accessible. The application exposes a public `/health` endpoint that doesn't require authentication:
364
+ ## Development
1201
365
 
1202
366
  ```bash
1203
- curl http://localhost:3333/health
367
+ npm install
368
+ npm run build
369
+ npm run dev:cli
370
+ npm run dev:ui
371
+ npm test
1204
372
  ```
1205
373
 
1206
- Response:
1207
- ```json
1208
- {
1209
- "status": "healthy",
1210
- "timestamp": "2026-02-05T21:30:00.000Z",
1211
- "uptime": 123.45
1212
- }
1213
- ```
374
+ ## Project Structure
1214
375
 
1215
- ## Contributing
376
+ ```text
377
+ src/
378
+ channels/ # Telegram adapter
379
+ cli/ # start/stop/restart/status/doctor
380
+ config/ # config loading, precedence, schemas
381
+ devkit/ # Apoc tool factories
382
+ http/ # API, auth, webhooks, server
383
+ runtime/
384
+ apoc.ts
385
+ neo.ts
386
+ oracle.ts
387
+ trinity.ts
388
+ trinity-connector.ts # PostgreSQL/MySQL/SQLite/MongoDB drivers
389
+ trinity-crypto.ts # AES-256-GCM encryption for DB passwords
390
+ memory/
391
+ tasks/
392
+ tools/
393
+ webhooks/
394
+ ui/ # React dashboard
395
+ ```
1216
396
 
1217
- 1. Fork the repository.
1218
- 2. Create a feature branch (`git checkout -b feature/amazing-feature`).
1219
- 3. Commit your changes (`git commit -m 'feat: Add amazing feature'`).
1220
- 4. Push to the branch (`git push origin feature/amazing-feature`).
1221
- 5. Open a Pull Request.
397
+ ## Related Docs
398
+ - `ARCHITECTURE.md`
399
+ - `PRODUCT.md`
400
+ - `DOCUMENTATION.md`
1222
401
 
1223
402
  ## License
1224
-
1225
403
  MIT