@nomad-e/bluma-cli 0.0.41 → 0.0.43

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 (3) hide show
  1. package/README.md +557 -557
  2. package/dist/main.js +29 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,557 +1,557 @@
1
- # BluMa CLI
2
-
3
- [![npm version](https://img.shields.io/npm/v/bluma.svg?style=flat-square)](https://www.npmjs.com/package/bluma)
4
- [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square)](LICENSE)
5
- [![Build Status](https://img.shields.io/badge/build-passing-brightgreen?style=flat-square)](https://shields.io/)
6
-
7
- <p align="center">
8
- <img src="https://github.com/sousaalex/bluma-cli/raw/main/docs/assets/bluma.png" alt="Tela inicial BluMa CLI" width="1000"/>
9
- </p>
10
-
11
- BluMa CLI is an independent agent for automation and advanced software engineering. The project is a conversational assistant that interacts via terminal (CLI), built with React/Ink, supporting smart agents (LLM, OpenAI Azure), tool execution, persistent history, session management, and extensibility through external plugins/tools.
12
-
13
- ---
14
-
15
- ## Table of Contents
16
- - [Overview](#overview)
17
- - [Key Features](#key-features)
18
- - [Requirements](#requirements)
19
- - [Architecture Diagram](#-architecture-diagram)
20
- - [Installation](#installation)
21
- - [Usage](#usage)
22
- - [Examples](#-usage-examples)
23
- - [Configuration and Environment Variables](#configuration-and-environment-variables)
24
- - [Development and Build](#development-and-build)
25
- - [Extensibility: Tools and Plugins](#extensibility-tools-and-plugins)
26
- - [Tests](#tests)
27
- - [Limitations / Next Steps](#️-limitations--next-steps)
28
- - [Security Notes](#-security-notes)
29
- - [Tech Stack Overview](#stack)
30
- - [Contributing](#-contributing)
31
- - [License](#license)
32
-
33
- ---
34
-
35
- ## <a name="overview"></a>Overview
36
- BluMa CLI is a modular conversational agent and task automation framework focused on advanced software engineering workflows. It runs entirely in the terminal using React (via Ink) for a rich interactive UI, and is architected around a **UI layer** (`main.ts` + `App.tsx`) and an **agent layer** (`Agent` orchestrator + `BluMaAgent` core). It enables LLM-powered automation, documentation, refactoring, running complex development tasks, and integrating with both native and external tools. The system features persistent sessions, contextual reasoning, smart feedback, and an interactive confirmation system for controlled execution.
37
-
38
- ---
39
-
40
- ## <a name="key-features"></a>Key Features
41
- - **Rich CLI interface** using React/Ink 5, with interactive prompts and custom components.
42
- - **Session management:** automatic persistence of conversation and tool history via files.
43
- - **Central agent (LLM):** orchestrated by Azure OpenAI (or compatible), enabling natural language-driven automation.
44
- - **Tool invocation:** native and via MCP SDK for running commands, code manipulation, file management, and more.
45
- - **Dynamic prompts:** builds live conversational context, behavioral rules, and technical history.
46
- - **Smart feedback component** with technical suggestions and checks.
47
- - **ConfirmPrompt & Workflow Decision:** confirmations for sensitive operations, edit/code previews, always-accepted tool whitelists.
48
- - **Extensible:** easily add new tools or integrate external SDK/plugins.
49
-
50
- ---
51
-
52
- ## <a name="requirements"></a>Requirements
53
- - Node.js >= 18
54
- - npm >= 9
55
- - Account (with key) for Azure OpenAI (or equivalent variables for OpenAI-compatible endpoints)
56
-
57
- ---
58
-
59
- ## <a name="installation"></a>Installation
60
-
61
- ### Recommended: Global Installation
62
-
63
- > **Important:** It is recommended to install BluMa globally so the `bluma` command works in any terminal.
64
-
65
- ```bash
66
- npm install -g @nomad-e/bluma-cli
67
- ```
68
-
69
- If you get permission errors, EXAMPLES:
70
- - **Linux:** Run as administrator using `sudo`:
71
- ```bash
72
- sudo npm install -g @nomad-e/bluma-cli
73
- ```
74
- - **Windows:** Open Command Prompt/Terminal as Administrator and repeat the command
75
-
76
- > **macOS:** After global installation, **always run the `bluma` command without sudo**:
77
- >
78
- > ```bash
79
- > bluma
80
- > ```
81
- > Running with sudo may cause permission problems, environment variable issues, and npm cache ownership problems.
82
- > Only use sudo to install, never to run the CLI.
83
-
84
- ### Setting Up Environment Variables
85
- For BluMa CLI to operate with OpenAI/Azure, GitHub, and Notion, set the following environment variables globally in your system.
86
-
87
- **Required:**
88
- - `AZURE_OPENAI_ENDPOINT`
89
- - `AZURE_OPENAI_API_KEY`
90
- - `AZURE_OPENAI_API_VERSION`
91
- - `AZURE_OPENAI_DEPLOYMENT`
92
- - `GITHUB_PERSONAL_ACCESS_TOKEN` (if you'll use GitHub)
93
- - `NOTION_API_TOKEN` (if you'll use Notion)
94
-
95
- #### How to set environment variables globally:
96
-
97
- **Linux/macOS:**
98
- Add to your `~/.bashrc`, `~/.zshrc`, or equivalent:
99
- ```sh
100
- export AZURE_OPENAI_ENDPOINT="https://..."
101
- export AZURE_OPENAI_API_KEY="your_key"
102
- export AZURE_OPENAI_API_VERSION="2024-06-01"
103
- export AZURE_OPENAI_DEPLOYMENT="bluma-gpt"
104
- export GITHUB_PERSONAL_ACCESS_TOKEN="..."
105
- export NOTION_API_TOKEN="..."
106
- ```
107
- Then run:
108
- ```sh
109
- source ~/.bashrc # or whichever file you edited
110
- ```
111
-
112
- **Windows (CMD):**
113
- ```cmd
114
- setx AZURE_OPENAI_ENDPOINT "https://..."
115
- setx AZURE_OPENAI_API_KEY "your_key"
116
- setx AZURE_OPENAI_API_VERSION "2024-06-01"
117
- setx AZURE_OPENAI_DEPLOYMENT "bluma-gpt"
118
- setx GITHUB_PERSONAL_ACCESS_TOKEN "..."
119
- setx NOTION_API_TOKEN "..."
120
- ```
121
- (Only needs to be run once per variable. Restart the terminal after.)
122
-
123
- **Windows (PowerShell):**
124
- ```powershell
125
- [Environment]::SetEnvironmentVariable("AZURE_OPENAI_ENDPOINT", "https://...", "Machine")
126
- [Environment]::SetEnvironmentVariable("AZURE_OPENAI_API_KEY", "your_key", "Machine")
127
- [Environment]::SetEnvironmentVariable("AZURE_OPENAI_API_VERSION", "2024-06-01", "Machine")
128
- [Environment]::SetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT", "bluma-gpt", "Machine")
129
- [Environment]::SetEnvironmentVariable("GITHUB_PERSONAL_ACCESS_TOKEN", "...", "Machine")
130
- [Environment]::SetEnvironmentVariable("NOTION_API_TOKEN", "...", "Machine")
131
- ```
132
-
133
- ### ℹ️ Global Installation of npm Packages in PowerShell (Windows)
134
- When installing BluMa (or any npm package globally) in PowerShell, you might see:
135
- ```
136
- Do you want to change the execution policy?
137
- [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
138
- ```
139
- 👉 **Choose `Y` (Yes) or `A` (Yes to All)**. This will change the execution policy to **RemoteSigned** (only scripts from the internet need a digital signature).
140
-
141
- - This is safe for devs: Windows only requires digital signatures for web scripts—local scripts, from npm, work normally.
142
- - Read more: [About Execution Policies (Microsoft Docs)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/about/about_execution_policies)
143
-
144
- **To restore the default policy after installation, run:**
145
- ```powershell
146
- Set-ExecutionPolicy Default
147
- ```
148
-
149
- > **Tip:** Restart your terminal to ensure the variables are loaded globally.
150
-
151
- ---
152
-
153
- ## <a name="how-to-run"></a>How to Run
154
- ```bash
155
- npm start
156
- # Or directly using the built binary
157
- npx bluma
158
- ```
159
- ==> The CLI will open an interactive terminal interface for dialogue, command execution, and engineering workflow automation.
160
-
161
- ---
162
-
163
- ## <a name="project-structure"></a>Project Structure
164
- ```
165
- bluma-engineer/
166
- ├── package.json # npm/project config
167
- ├── tsconfig.json # TypeScript config
168
- ├── scripts/build.js # Build script using esbuild
169
- ├── src/
170
- │ ├── main.ts # Entry point (Ink renderer)
171
- │ └── app/
172
- │ ├── agent/ # Agent core (session mgmt, tools, MCP, prompt, feedback)
173
- │ ├── ui/ # Ink/React CLI interface components
174
- │ └── protocols/ # Protocols & helpers
175
- ```
176
- ---
177
-
178
- ## <a name="development-and-build"></a>Development and Build
179
- - Build is performed using [esbuild](https://esbuild.github.io/) (see scripts/build.js).
180
- - TS source files are in `src/` and compiled to `dist/`.
181
- - Use `npm run build` to compile and get the CLI binary ready.
182
- - Config files are automatically copied to `dist/config`.
183
-
184
- ### Main scripts:
185
- ```bash
186
- npm run build # Compiles project to dist/
187
- npm start # Runs CLI (after build)
188
- npm run dev # (If configured, hot-reload/TS watch)
189
- ```
190
-
191
- ---
192
-
193
- ## <a name="extensibility-tools-and-plugins"></a>Extensibility: Tools and Plugins
194
- - Add native tools in `src/app/agent/tools/natives/`
195
- - Use the MCP SDK for advanced plugins integrating with external APIs
196
- - Create custom Ink components to expand the interface
197
-
198
- ---
199
-
200
- ## <a name="tests"></a>Tests
201
- - The repository ships with Jest 30 configured (babel-jest) and TypeScript support.
202
- - Test files are located under `tests/` and follow `*.spec.ts` naming.
203
- - Run tests:
204
-
205
- ```bash
206
- npm test
207
- npm run test:watch
208
- ```
209
-
210
- ---
211
-
212
- ## Live Dev Overlays (Open Channel During Processing)
213
- BluMa supports a live side-channel that stays active even while the agent is processing. This lets the dev send guidance or constraints in real-time — like pair programming.
214
-
215
- Key points
216
- - Permissive mode enabled: during processing, any free text you type is treated as a [hint] automatically.
217
- - Structured prefixes are also supported at any time:
218
- - [hint] Text for immediate guidance to the agent
219
- - [constraint] Rules/limits (e.g., "não tocar em src/app/agent/**")
220
- - [override] Parameter overrides as key=value pairs (e.g., "file_path=C:/... expected_replacements=2")
221
- - [assume] Register explicit assumptions
222
- - [cancel] Interrupt safely (already supported)
223
-
224
- How it works
225
- - Frontend: the input remains active in read-only (processing) mode and emits a dev_overlay event.
226
- - Agent backend: consumes overlays with precedence (constraint > override > hint). Hints and assumptions are injected into the system context before the next decision; overrides/constraints adjust tool parameters just before execution.
227
- - Logging & history: every overlay is logged and stored in session history for auditability.
228
-
229
- Examples
230
- - During a long task, just type:
231
- - "Prefer do not touch tests yet" → will be treated as [hint]
232
- - "[constraint] não editar src/app/ui/**" → blocks edits under that path
233
- - "[override] expected_replacements=2" → adjusts the next edit_tool call
234
- - "[assume] target=api" → adds an assumption in context
235
-
236
- Notes
237
- - The side-channel does not pause the agent — it adapts on the fly.
238
- - If an overlay conflicts with the current plan: constraint > override > hint.
239
- - All overlays are acknowledged via standard internal messages and persisted.
240
-
241
- ---
242
-
243
- ## <a name="configuration-and-environment-variables"></a>Configuration and Environment Variables
244
- You must create a `.env` file (copy if needed from `.env.example`) with the following variables:
245
- - `AZURE_OPENAI_ENDPOINT`
246
- - `AZURE_OPENAI_API_KEY`
247
- - `AZURE_OPENAI_API_VERSION`
248
- - `AZURE_OPENAI_DEPLOYMENT`
249
- - `GITHUB_PERSONAL_ACCESS_TOKEN` (optional; required for GitHub integrations)
250
- - `NOTION_API_TOKEN` (optional; required for Notion integrations)
251
-
252
- And others required by your agent/context or Azure setup.
253
-
254
- Advanced config files are located in `src/app/agent/config/`.
255
-
256
- ---
257
-
258
- ## <a name="stack"></a>Tech Stack Overview
259
- - Language: TypeScript (ESM)
260
- - Runtime: Node.js >= 18
261
- - CLI UI: React 18 via Ink 5, plus `ink-text-input`, `ink-spinner`, `ink-big-text`
262
- - Bundler: esbuild, with `esbuild-plugin-node-externals`
263
- - Test Runner: Jest 30 + babel-jest
264
- - Transpilers: Babel presets (env, react, typescript)
265
- - LLM/Agent: Azure OpenAI via `openai` SDK; MCP via `@modelcontextprotocol/sdk`
266
- - Config loading: dotenv
267
- - Utilities: uuid, diff, react-devtools-core
268
-
269
- ---
270
-
271
- ## <a name="license"></a>License
272
- Apache-2.0. Made by Alex Fonseca and NomadEngenuity contributors.
273
-
274
- Enjoy, hack, and—if possible—contribute!
275
-
276
- ---
277
-
278
- ## 🏗 Architecture Diagram
279
- Below is a simplified diagram showing BluMa CLI's core architecture:
280
- ```
281
- [ main.ts ] → [ App.tsx (UI Layer) ]
282
-
283
- [ Agent (Orchestrator) ]
284
-
285
- [ BluMaAgent (Core Loop & State) ]
286
-
287
- [ MCPClient / Tools / Native Tools / SubAgents ]
288
-
289
- [ External APIs & System Operations ]
290
- ```
291
- This flow ensures a clean separation between presentation, orchestration, core logic, and integration layers.
292
-
293
- ### Sequence Diagram
294
- ```mermaid
295
- sequenceDiagram
296
- participant UI as UI (main.ts + App.tsx)
297
- participant Agent as Agent (Orchestrator)
298
- participant Core as BluMaAgent (Core Loop)
299
- participant MCP as MCPClient / Tools
300
-
301
- UI->>Agent: Initialize(sessionId, eventBus)
302
- Agent->>Core: initialize()
303
- Core->>MCP: initialize tools
304
- UI->>Agent: processTurn(userInput)
305
- Agent->>Core: processTurn(content)
306
- Core->>MCP: Get available tools & context
307
- MCP-->>Core: Tool list & details
308
- Core-->>Agent: Tool call request or LLM message
309
- Agent-->>UI: backend_message (e.g., confirmation_request)
310
- UI->>Agent: handleToolResponse()
311
- Agent->>Core: handleToolResponse(decision)
312
- Core->>MCP: Execute tool
313
- MCP-->>Core: Tool result
314
- Core-->>Agent: backend_message(done)
315
- Agent-->>UI: Update history & UI state
316
- ```
317
-
318
- ---
319
-
320
- ### Component Diagram
321
- ```mermaid
322
- flowchart TD
323
- subgraph UI["UI Layer"]
324
- M["main.ts"]
325
- A["App.tsx"]
326
- end
327
- subgraph AG["Agent Layer"]
328
- AGN["Agent (Orchestrator)"]
329
- CORE["BluMaAgent (Core Loop)"]
330
- end
331
- subgraph TOOLS["Tools & Integration"]
332
- MCP["MCPClient"]
333
- NT["Native Tools"]
334
- SA["SubAgents"]
335
- end
336
- EXT["External APIs & FS"]
337
-
338
- M --> A --> AGN --> CORE --> MCP --> NT
339
- CORE --> SA
340
- MCP --> EXT
341
- NT --> EXT
342
- ```
343
-
344
- ---
345
-
346
- ### Activity Diagram
347
- ```mermaid
348
- flowchart TD
349
- Start((Start)) --> Input[User Input in UI]
350
- Input --> Processing{Command Type?}
351
- Processing -->|Slash Command| SC[Handle Slash Command]
352
- Processing -->|Normal Input| PT[processTurn]
353
- SC --> Done((End))
354
- PT --> LLM[Send to LLM]
355
- LLM --> ToolCall{Tool Requested?}
356
- ToolCall -->|No| Display[Display Assistant Message]
357
- ToolCall -->|Yes| Confirm[Ask for Confirmation]
358
- Confirm --> Decision{Decision}
359
- Decision -->|Accept| Exec[Execute Tool]
360
- Decision -->|Decline| Skip[Skip Execution]
361
- Exec --> Result[Return Tool Result]
362
- Skip --> Done
363
- Result --> Done
364
- Display --> Done
365
- ```
366
-
367
- ---
368
-
369
- ### State Machine Diagram
370
- ```mermaid
371
- stateDiagram-v2
372
- [*] --> Idle
373
- Idle --> Processing: User Input
374
- Processing --> Awaiting_Confirmation: Tool Call Needs Approval
375
- Awaiting_Confirmation --> Processing: User Accepts
376
- Awaiting_Confirmation --> Idle: User Declines
377
- Processing --> Completed: Task Completed
378
- Processing --> Interrupted: User Interrupt
379
- Completed --> Idle
380
- Interrupted --> Idle
381
- ```
382
-
383
- ---
384
-
385
- ### Deployment Diagram
386
- ```mermaid
387
- graph TD
388
- CLI["CLI (BluMa)"] --> LocalFS[("Local File System")]
389
- CLI --> AzureOpenAI[("Azure OpenAI API")]
390
- CLI --> GitHubAPI[("GitHub API")]
391
- CLI --> NotionAPI[("Notion API")]
392
- CLI --> OtherAPIs[("Other External APIs")]
393
- CLI --> MCPServer[("MCP Server / Plugins")]
394
- ```
395
-
396
- ---
397
-
398
- ### Data Flow Diagram
399
- ```mermaid
400
- flowchart LR
401
- U[User] --> UI[UI Layer]
402
- UI --> Agent[Agent]
403
- Agent --> Core[BluMaAgent]
404
- Core --> MCP[MCPClient]
405
- Core --> Sub[SubAgents]
406
- MCP --> Tools[Native Tools & External APIs]
407
- Sub --> Tools
408
- Tools --> MCP
409
- MCP --> Core
410
- Core --> Agent
411
- Agent --> UI
412
- UI --> U
413
- ```
414
-
415
- ---
416
-
417
- ## 💡 Usage Examples
418
- - **Run Initialization Command**
419
- ```
420
- /init
421
- ```
422
- Executes the `init` subagent to prepare the working environment.
423
-
424
- - **Confirm an Edit Operation**
425
- When the system prompts an `edit_tool` operation, review the preview and choose:
426
- ```
427
- Accept | Decline | Accept Always
428
- ```
429
-
430
- - **Live Overlay**
431
- During a long-running task, you can send hints:
432
- ```
433
- [hint] Prefer small batch edits
434
- [constraint] Avoid editing src/app/ui/**
435
- ```
436
-
437
- ---
438
-
439
- ## 🤝 Contributing
440
- We welcome contributions! For full details, read [CONTRIBUTING.md](CONTRIBUTING.md).
441
-
442
- ### 📋 Prerequisites
443
- - **Node.js** >= 18 and **npm** >= 9 installed
444
- - Dependencies installed via `npm install`
445
- - Required environment variables configured (see *Configuration* section)
446
-
447
- ### 🔄 Contribution Workflow
448
- 1. **Fork** the repository
449
- 2. **Clone** your fork locally
450
- 3. Create a feature branch named according to [Conventional Commits](https://www.conventionalcommits.org/) (e.g., `feat/add-logging`)
451
- 4. Commit changes with meaningful messages
452
- 5. Push to your fork and open a Pull Request
453
-
454
- ### 🛠 Code Standards
455
- - Follow TypeScript strict mode guidelines
456
- - Maintain style via ESLint and Prettier (`npm run lint`)
457
- - Keep functions short, modular, and documented with JSDoc
458
- - All business logic must have unit tests
459
-
460
- ### 🧪 Testing Requirements
461
- - Run `npm test` and ensure all tests pass
462
- - Include new tests for any new functionality or bug fix
463
- - Validate integration tests when adding new tools or APIs
464
-
465
- ### 🔍 Code Review Process
466
- - Minimum of 1 maintainer approval before merge
467
- - Resolve all review comments and passing CI before merge
468
-
469
- ### 📄 Documentation
470
- - Update README.md or relevant Wiki pages when adding/removing features
471
- - Add or update CHANGELOG.md for notable changes
472
-
473
- ---
474
-
475
- ## ⚠️ Limitations / Next Steps
476
- - Current LLM integration optimised for Azure OpenAI; add more providers.
477
- - Logging verbosity could be made configurable.
478
- - Potential for richer plugin lifecycle (install/remove at runtime).
479
- - Improve error reporting in subagents.
480
-
481
- ---
482
-
483
- ## 🔒 Security Notes
484
-
485
- ---
486
-
487
- ## 🛠 Error Handling & Recovery Flows
488
- BluMa handles different classes of errors gracefully:
489
- - **Network/API Errors**: Retry logic with exponential backoff.
490
- - **Authentication Failures**: Immediate notification to user, requires updating environment variables.
491
- - **Tool Execution Errors**: Displayed with detailed message; execution can be retried or skipped.
492
- - **LLM/API Exceptions**: Fall back to safe mode and keep context intact.
493
- - **Session/History Save Failures**: Warn user and continue without losing core functionality.
494
-
495
- ---
496
-
497
- ## 📈 Metrics & Observability
498
- - **Performance Metrics**: Average response time, tokens used per request, tool execution times.
499
- - **Usage Tracking**: Number of commands executed, tool calls, sessions created.
500
- - **Logging**: Structured logs for all events.
501
- - Integration-ready with Prometheus/Grafana or external observability platforms.
502
-
503
- ---
504
-
505
- ## 🔐 Advanced Security Practices
506
- - Use secret management tools (Vault, AWS Secrets Manager) to store environment variables.
507
- - Apply principle of least privilege for API keys.
508
- - Validate and sanitize all user inputs to avoid prompt injection attacks.
509
- - Regularly rotate API keys.
510
-
511
- ---
512
-
513
- ## 🚀 Performance & Scalability
514
- - Optimize context window by pruning irrelevant history.
515
- - Batch related operations to reduce LLM calls.
516
- - Support for distributed execution or remote agent hosting.
517
- - Cache static responses where possible.
518
-
519
- ---
520
-
521
- ## 🔄 Development Cycle & CI/CD
522
- - **Testing**: `npm test` and `npm run test:watch` for development.
523
- - **Linting**: Enforce coding standards with ESLint/Prettier.
524
- - **CI/CD**: Recommended GitHub Actions or similar to run tests/build on push.
525
- - **Deployment**: Automatic packaging to npm or internal registry.
526
-
527
- ---
528
-
529
- ## 🗺 Roadmap & Release Notes
530
- **Upcoming:**
531
- - Multi-LLM provider support.
532
- - Web-based dashboard.
533
- - Richer subagent plugin APIs.
534
-
535
- **Release Notes**:
536
- - Follow [CHANGELOG.md](CHANGELOG.md) for version history.
537
-
538
- ---
539
-
540
- ## 🎯 Advanced Use Cases
541
- - Chain multiple tools with complex decision-making.
542
- - Build custom subagents for domain-specific automation.
543
- - Integrate with CI pipelines for automated code review and refactoring.
544
-
545
- ---
546
-
547
- ## 📏 Code Standards & Contribution Guidelines
548
- - Follow TypeScript strict mode.
549
- - Commit messages must follow Conventional Commits (`feat:`, `fix:`, `chore:`).
550
- - Keep functions short, modular and documented.
551
- - Add unit tests for all business logic.
552
-
553
- ---
554
- - Protect your API keys: never commit `.env` files.
555
- - `edit_tool` can modify files — review previews before accepting.
556
- - Use restricted permissions for API tokens wherever possible.
557
- - If using on shared systems, ensure `.bluma-cli` config is private.
1
+ # BluMa CLI
2
+
3
+ [![npm version](https://img.shields.io/npm/v/bluma.svg?style=flat-square)](https://www.npmjs.com/package/bluma)
4
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square)](LICENSE)
5
+ [![Build Status](https://img.shields.io/badge/build-passing-brightgreen?style=flat-square)](https://shields.io/)
6
+
7
+ <p align="center">
8
+ <img src="docs\assets\bluma.png" alt="Tela inicial BluMa CLI" width="1000"/>
9
+ </p>
10
+
11
+ BluMa CLI is an independent agent for automation and advanced software engineering. The project is a conversational assistant that interacts via terminal (CLI), built with React/Ink, supporting smart agents (LLM, OpenAI Azure), tool execution, persistent history, session management, and extensibility through external plugins/tools.
12
+
13
+ ---
14
+
15
+ ## Table of Contents
16
+ - [Overview](#overview)
17
+ - [Key Features](#key-features)
18
+ - [Requirements](#requirements)
19
+ - [Architecture Diagram](#-architecture-diagram)
20
+ - [Installation](#installation)
21
+ - [Usage](#usage)
22
+ - [Examples](#-usage-examples)
23
+ - [Configuration and Environment Variables](#configuration-and-environment-variables)
24
+ - [Development and Build](#development-and-build)
25
+ - [Extensibility: Tools and Plugins](#extensibility-tools-and-plugins)
26
+ - [Tests](#tests)
27
+ - [Limitations / Next Steps](#️-limitations--next-steps)
28
+ - [Security Notes](#-security-notes)
29
+ - [Tech Stack Overview](#stack)
30
+ - [Contributing](#-contributing)
31
+ - [License](#license)
32
+
33
+ ---
34
+
35
+ ## <a name="overview"></a>Overview
36
+ BluMa CLI is a modular conversational agent and task automation framework focused on advanced software engineering workflows. It runs entirely in the terminal using React (via Ink) for a rich interactive UI, and is architected around a **UI layer** (`main.ts` + `App.tsx`) and an **agent layer** (`Agent` orchestrator + `BluMaAgent` core). It enables LLM-powered automation, documentation, refactoring, running complex development tasks, and integrating with both native and external tools. The system features persistent sessions, contextual reasoning, smart feedback, and an interactive confirmation system for controlled execution.
37
+
38
+ ---
39
+
40
+ ## <a name="key-features"></a>Key Features
41
+ - **Rich CLI interface** using React/Ink 5, with interactive prompts and custom components.
42
+ - **Session management:** automatic persistence of conversation and tool history via files.
43
+ - **Central agent (LLM):** orchestrated by Azure OpenAI (or compatible), enabling natural language-driven automation.
44
+ - **Tool invocation:** native and via MCP SDK for running commands, code manipulation, file management, and more.
45
+ - **Dynamic prompts:** builds live conversational context, behavioral rules, and technical history.
46
+ - **Smart feedback component** with technical suggestions and checks.
47
+ - **ConfirmPrompt & Workflow Decision:** confirmations for sensitive operations, edit/code previews, always-accepted tool whitelists.
48
+ - **Extensible:** easily add new tools or integrate external SDK/plugins.
49
+
50
+ ---
51
+
52
+ ## <a name="requirements"></a>Requirements
53
+ - Node.js >= 18
54
+ - npm >= 9
55
+ - Account (with key) for Azure OpenAI (or equivalent variables for OpenAI-compatible endpoints)
56
+
57
+ ---
58
+
59
+ ## <a name="installation"></a>Installation
60
+
61
+ ### Recommended: Global Installation
62
+
63
+ > **Important:** It is recommended to install BluMa globally so the `bluma` command works in any terminal.
64
+
65
+ ```bash
66
+ npm install -g @nomad-e/bluma-cli
67
+ ```
68
+
69
+ If you get permission errors, EXAMPLES:
70
+ - **Linux:** Run as administrator using `sudo`:
71
+ ```bash
72
+ sudo npm install -g @nomad-e/bluma-cli
73
+ ```
74
+ - **Windows:** Open Command Prompt/Terminal as Administrator and repeat the command
75
+
76
+ > **macOS:** After global installation, **always run the `bluma` command without sudo**:
77
+ >
78
+ > ```bash
79
+ > bluma
80
+ > ```
81
+ > Running with sudo may cause permission problems, environment variable issues, and npm cache ownership problems.
82
+ > Only use sudo to install, never to run the CLI.
83
+
84
+ ### Setting Up Environment Variables
85
+ For BluMa CLI to operate with OpenAI/Azure, GitHub, and Notion, set the following environment variables globally in your system.
86
+
87
+ **Required:**
88
+ - `AZURE_OPENAI_ENDPOINT`
89
+ - `AZURE_OPENAI_API_KEY`
90
+ - `AZURE_OPENAI_API_VERSION`
91
+ - `AZURE_OPENAI_DEPLOYMENT`
92
+ - `GITHUB_PERSONAL_ACCESS_TOKEN` (if you'll use GitHub)
93
+ - `NOTION_API_TOKEN` (if you'll use Notion)
94
+
95
+ #### How to set environment variables globally:
96
+
97
+ **Linux/macOS:**
98
+ Add to your `~/.bashrc`, `~/.zshrc`, or equivalent:
99
+ ```sh
100
+ export AZURE_OPENAI_ENDPOINT="https://..."
101
+ export AZURE_OPENAI_API_KEY="your_key"
102
+ export AZURE_OPENAI_API_VERSION="2024-06-01"
103
+ export AZURE_OPENAI_DEPLOYMENT="bluma-gpt"
104
+ export GITHUB_PERSONAL_ACCESS_TOKEN="..."
105
+ export NOTION_API_TOKEN="..."
106
+ ```
107
+ Then run:
108
+ ```sh
109
+ source ~/.bashrc # or whichever file you edited
110
+ ```
111
+
112
+ **Windows (CMD):**
113
+ ```cmd
114
+ setx AZURE_OPENAI_ENDPOINT "https://..."
115
+ setx AZURE_OPENAI_API_KEY "your_key"
116
+ setx AZURE_OPENAI_API_VERSION "2024-06-01"
117
+ setx AZURE_OPENAI_DEPLOYMENT "bluma-gpt"
118
+ setx GITHUB_PERSONAL_ACCESS_TOKEN "..."
119
+ setx NOTION_API_TOKEN "..."
120
+ ```
121
+ (Only needs to be run once per variable. Restart the terminal after.)
122
+
123
+ **Windows (PowerShell):**
124
+ ```powershell
125
+ [Environment]::SetEnvironmentVariable("AZURE_OPENAI_ENDPOINT", "https://...", "Machine")
126
+ [Environment]::SetEnvironmentVariable("AZURE_OPENAI_API_KEY", "your_key", "Machine")
127
+ [Environment]::SetEnvironmentVariable("AZURE_OPENAI_API_VERSION", "2024-06-01", "Machine")
128
+ [Environment]::SetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT", "bluma-gpt", "Machine")
129
+ [Environment]::SetEnvironmentVariable("GITHUB_PERSONAL_ACCESS_TOKEN", "...", "Machine")
130
+ [Environment]::SetEnvironmentVariable("NOTION_API_TOKEN", "...", "Machine")
131
+ ```
132
+
133
+ ### ℹ️ Global Installation of npm Packages in PowerShell (Windows)
134
+ When installing BluMa (or any npm package globally) in PowerShell, you might see:
135
+ ```
136
+ Do you want to change the execution policy?
137
+ [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
138
+ ```
139
+ 👉 **Choose `Y` (Yes) or `A` (Yes to All)**. This will change the execution policy to **RemoteSigned** (only scripts from the internet need a digital signature).
140
+
141
+ - This is safe for devs: Windows only requires digital signatures for web scripts—local scripts, from npm, work normally.
142
+ - Read more: [About Execution Policies (Microsoft Docs)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/about/about_execution_policies)
143
+
144
+ **To restore the default policy after installation, run:**
145
+ ```powershell
146
+ Set-ExecutionPolicy Default
147
+ ```
148
+
149
+ > **Tip:** Restart your terminal to ensure the variables are loaded globally.
150
+
151
+ ---
152
+
153
+ ## <a name="how-to-run"></a>How to Run
154
+ ```bash
155
+ npm start
156
+ # Or directly using the built binary
157
+ npx bluma
158
+ ```
159
+ ==> The CLI will open an interactive terminal interface for dialogue, command execution, and engineering workflow automation.
160
+
161
+ ---
162
+
163
+ ## <a name="project-structure"></a>Project Structure
164
+ ```
165
+ bluma-engineer/
166
+ ├── package.json # npm/project config
167
+ ├── tsconfig.json # TypeScript config
168
+ ├── scripts/build.js # Build script using esbuild
169
+ ├── src/
170
+ │ ├── main.ts # Entry point (Ink renderer)
171
+ │ └── app/
172
+ │ ├── agent/ # Agent core (session mgmt, tools, MCP, prompt, feedback)
173
+ │ ├── ui/ # Ink/React CLI interface components
174
+ │ └── protocols/ # Protocols & helpers
175
+ ```
176
+ ---
177
+
178
+ ## <a name="development-and-build"></a>Development and Build
179
+ - Build is performed using [esbuild](https://esbuild.github.io/) (see scripts/build.js).
180
+ - TS source files are in `src/` and compiled to `dist/`.
181
+ - Use `npm run build` to compile and get the CLI binary ready.
182
+ - Config files are automatically copied to `dist/config`.
183
+
184
+ ### Main scripts:
185
+ ```bash
186
+ npm run build # Compiles project to dist/
187
+ npm start # Runs CLI (after build)
188
+ npm run dev # (If configured, hot-reload/TS watch)
189
+ ```
190
+
191
+ ---
192
+
193
+ ## <a name="extensibility-tools-and-plugins"></a>Extensibility: Tools and Plugins
194
+ - Add native tools in `src/app/agent/tools/natives/`
195
+ - Use the MCP SDK for advanced plugins integrating with external APIs
196
+ - Create custom Ink components to expand the interface
197
+
198
+ ---
199
+
200
+ ## <a name="tests"></a>Tests
201
+ - The repository ships with Jest 30 configured (babel-jest) and TypeScript support.
202
+ - Test files are located under `tests/` and follow `*.spec.ts` naming.
203
+ - Run tests:
204
+
205
+ ```bash
206
+ npm test
207
+ npm run test:watch
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Live Dev Overlays (Open Channel During Processing)
213
+ BluMa supports a live side-channel that stays active even while the agent is processing. This lets the dev send guidance or constraints in real-time — like pair programming.
214
+
215
+ Key points
216
+ - Permissive mode enabled: during processing, any free text you type is treated as a [hint] automatically.
217
+ - Structured prefixes are also supported at any time:
218
+ - [hint] Text for immediate guidance to the agent
219
+ - [constraint] Rules/limits (e.g., "não tocar em src/app/agent/**")
220
+ - [override] Parameter overrides as key=value pairs (e.g., "file_path=C:/... expected_replacements=2")
221
+ - [assume] Register explicit assumptions
222
+ - [cancel] Interrupt safely (already supported)
223
+
224
+ How it works
225
+ - Frontend: the input remains active in read-only (processing) mode and emits a dev_overlay event.
226
+ - Agent backend: consumes overlays with precedence (constraint > override > hint). Hints and assumptions are injected into the system context before the next decision; overrides/constraints adjust tool parameters just before execution.
227
+ - Logging & history: every overlay is logged and stored in session history for auditability.
228
+
229
+ Examples
230
+ - During a long task, just type:
231
+ - "Prefer do not touch tests yet" → will be treated as [hint]
232
+ - "[constraint] não editar src/app/ui/**" → blocks edits under that path
233
+ - "[override] expected_replacements=2" → adjusts the next edit_tool call
234
+ - "[assume] target=api" → adds an assumption in context
235
+
236
+ Notes
237
+ - The side-channel does not pause the agent — it adapts on the fly.
238
+ - If an overlay conflicts with the current plan: constraint > override > hint.
239
+ - All overlays are acknowledged via standard internal messages and persisted.
240
+
241
+ ---
242
+
243
+ ## <a name="configuration-and-environment-variables"></a>Configuration and Environment Variables
244
+ You must create a `.env` file (copy if needed from `.env.example`) with the following variables:
245
+ - `AZURE_OPENAI_ENDPOINT`
246
+ - `AZURE_OPENAI_API_KEY`
247
+ - `AZURE_OPENAI_API_VERSION`
248
+ - `AZURE_OPENAI_DEPLOYMENT`
249
+ - `GITHUB_PERSONAL_ACCESS_TOKEN` (optional; required for GitHub integrations)
250
+ - `NOTION_API_TOKEN` (optional; required for Notion integrations)
251
+
252
+ And others required by your agent/context or Azure setup.
253
+
254
+ Advanced config files are located in `src/app/agent/config/`.
255
+
256
+ ---
257
+
258
+ ## <a name="stack"></a>Tech Stack Overview
259
+ - Language: TypeScript (ESM)
260
+ - Runtime: Node.js >= 18
261
+ - CLI UI: React 18 via Ink 5, plus `ink-text-input`, `ink-spinner`, `ink-big-text`
262
+ - Bundler: esbuild, with `esbuild-plugin-node-externals`
263
+ - Test Runner: Jest 30 + babel-jest
264
+ - Transpilers: Babel presets (env, react, typescript)
265
+ - LLM/Agent: Azure OpenAI via `openai` SDK; MCP via `@modelcontextprotocol/sdk`
266
+ - Config loading: dotenv
267
+ - Utilities: uuid, diff, react-devtools-core
268
+
269
+ ---
270
+
271
+ ## <a name="license"></a>License
272
+ Apache-2.0. Made by Alex Fonseca and NomadEngenuity contributors.
273
+
274
+ Enjoy, hack, and—if possible—contribute!
275
+
276
+ ---
277
+
278
+ ## 🏗 Architecture Diagram
279
+ Below is a simplified diagram showing BluMa CLI's core architecture:
280
+ ```
281
+ [ main.ts ] → [ App.tsx (UI Layer) ]
282
+
283
+ [ Agent (Orchestrator) ]
284
+
285
+ [ BluMaAgent (Core Loop & State) ]
286
+
287
+ [ MCPClient / Tools / Native Tools / SubAgents ]
288
+
289
+ [ External APIs & System Operations ]
290
+ ```
291
+ This flow ensures a clean separation between presentation, orchestration, core logic, and integration layers.
292
+
293
+ ### Sequence Diagram
294
+ ```mermaid
295
+ sequenceDiagram
296
+ participant UI as UI (main.ts + App.tsx)
297
+ participant Agent as Agent (Orchestrator)
298
+ participant Core as BluMaAgent (Core Loop)
299
+ participant MCP as MCPClient / Tools
300
+
301
+ UI->>Agent: Initialize(sessionId, eventBus)
302
+ Agent->>Core: initialize()
303
+ Core->>MCP: initialize tools
304
+ UI->>Agent: processTurn(userInput)
305
+ Agent->>Core: processTurn(content)
306
+ Core->>MCP: Get available tools & context
307
+ MCP-->>Core: Tool list & details
308
+ Core-->>Agent: Tool call request or LLM message
309
+ Agent-->>UI: backend_message (e.g., confirmation_request)
310
+ UI->>Agent: handleToolResponse()
311
+ Agent->>Core: handleToolResponse(decision)
312
+ Core->>MCP: Execute tool
313
+ MCP-->>Core: Tool result
314
+ Core-->>Agent: backend_message(done)
315
+ Agent-->>UI: Update history & UI state
316
+ ```
317
+
318
+ ---
319
+
320
+ ### Component Diagram
321
+ ```mermaid
322
+ flowchart TD
323
+ subgraph UI["UI Layer"]
324
+ M["main.ts"]
325
+ A["App.tsx"]
326
+ end
327
+ subgraph AG["Agent Layer"]
328
+ AGN["Agent (Orchestrator)"]
329
+ CORE["BluMaAgent (Core Loop)"]
330
+ end
331
+ subgraph TOOLS["Tools & Integration"]
332
+ MCP["MCPClient"]
333
+ NT["Native Tools"]
334
+ SA["SubAgents"]
335
+ end
336
+ EXT["External APIs & FS"]
337
+
338
+ M --> A --> AGN --> CORE --> MCP --> NT
339
+ CORE --> SA
340
+ MCP --> EXT
341
+ NT --> EXT
342
+ ```
343
+
344
+ ---
345
+
346
+ ### Activity Diagram
347
+ ```mermaid
348
+ flowchart TD
349
+ Start((Start)) --> Input[User Input in UI]
350
+ Input --> Processing{Command Type?}
351
+ Processing -->|Slash Command| SC[Handle Slash Command]
352
+ Processing -->|Normal Input| PT[processTurn]
353
+ SC --> Done((End))
354
+ PT --> LLM[Send to LLM]
355
+ LLM --> ToolCall{Tool Requested?}
356
+ ToolCall -->|No| Display[Display Assistant Message]
357
+ ToolCall -->|Yes| Confirm[Ask for Confirmation]
358
+ Confirm --> Decision{Decision}
359
+ Decision -->|Accept| Exec[Execute Tool]
360
+ Decision -->|Decline| Skip[Skip Execution]
361
+ Exec --> Result[Return Tool Result]
362
+ Skip --> Done
363
+ Result --> Done
364
+ Display --> Done
365
+ ```
366
+
367
+ ---
368
+
369
+ ### State Machine Diagram
370
+ ```mermaid
371
+ stateDiagram-v2
372
+ [*] --> Idle
373
+ Idle --> Processing: User Input
374
+ Processing --> Awaiting_Confirmation: Tool Call Needs Approval
375
+ Awaiting_Confirmation --> Processing: User Accepts
376
+ Awaiting_Confirmation --> Idle: User Declines
377
+ Processing --> Completed: Task Completed
378
+ Processing --> Interrupted: User Interrupt
379
+ Completed --> Idle
380
+ Interrupted --> Idle
381
+ ```
382
+
383
+ ---
384
+
385
+ ### Deployment Diagram
386
+ ```mermaid
387
+ graph TD
388
+ CLI["CLI (BluMa)"] --> LocalFS[("Local File System")]
389
+ CLI --> AzureOpenAI[("Azure OpenAI API")]
390
+ CLI --> GitHubAPI[("GitHub API")]
391
+ CLI --> NotionAPI[("Notion API")]
392
+ CLI --> OtherAPIs[("Other External APIs")]
393
+ CLI --> MCPServer[("MCP Server / Plugins")]
394
+ ```
395
+
396
+ ---
397
+
398
+ ### Data Flow Diagram
399
+ ```mermaid
400
+ flowchart LR
401
+ U[User] --> UI[UI Layer]
402
+ UI --> Agent[Agent]
403
+ Agent --> Core[BluMaAgent]
404
+ Core --> MCP[MCPClient]
405
+ Core --> Sub[SubAgents]
406
+ MCP --> Tools[Native Tools & External APIs]
407
+ Sub --> Tools
408
+ Tools --> MCP
409
+ MCP --> Core
410
+ Core --> Agent
411
+ Agent --> UI
412
+ UI --> U
413
+ ```
414
+
415
+ ---
416
+
417
+ ## 💡 Usage Examples
418
+ - **Run Initialization Command**
419
+ ```
420
+ /init
421
+ ```
422
+ Executes the `init` subagent to prepare the working environment.
423
+
424
+ - **Confirm an Edit Operation**
425
+ When the system prompts an `edit_tool` operation, review the preview and choose:
426
+ ```
427
+ Accept | Decline | Accept Always
428
+ ```
429
+
430
+ - **Live Overlay**
431
+ During a long-running task, you can send hints:
432
+ ```
433
+ [hint] Prefer small batch edits
434
+ [constraint] Avoid editing src/app/ui/**
435
+ ```
436
+
437
+ ---
438
+
439
+ ## 🤝 Contributing
440
+ We welcome contributions! For full details, read [CONTRIBUTING.md](CONTRIBUTING.md).
441
+
442
+ ### 📋 Prerequisites
443
+ - **Node.js** >= 18 and **npm** >= 9 installed
444
+ - Dependencies installed via `npm install`
445
+ - Required environment variables configured (see *Configuration* section)
446
+
447
+ ### 🔄 Contribution Workflow
448
+ 1. **Fork** the repository
449
+ 2. **Clone** your fork locally
450
+ 3. Create a feature branch named according to [Conventional Commits](https://www.conventionalcommits.org/) (e.g., `feat/add-logging`)
451
+ 4. Commit changes with meaningful messages
452
+ 5. Push to your fork and open a Pull Request
453
+
454
+ ### 🛠 Code Standards
455
+ - Follow TypeScript strict mode guidelines
456
+ - Maintain style via ESLint and Prettier (`npm run lint`)
457
+ - Keep functions short, modular, and documented with JSDoc
458
+ - All business logic must have unit tests
459
+
460
+ ### 🧪 Testing Requirements
461
+ - Run `npm test` and ensure all tests pass
462
+ - Include new tests for any new functionality or bug fix
463
+ - Validate integration tests when adding new tools or APIs
464
+
465
+ ### 🔍 Code Review Process
466
+ - Minimum of 1 maintainer approval before merge
467
+ - Resolve all review comments and passing CI before merge
468
+
469
+ ### 📄 Documentation
470
+ - Update README.md or relevant Wiki pages when adding/removing features
471
+ - Add or update CHANGELOG.md for notable changes
472
+
473
+ ---
474
+
475
+ ## ⚠️ Limitations / Next Steps
476
+ - Current LLM integration optimised for Azure OpenAI; add more providers.
477
+ - Logging verbosity could be made configurable.
478
+ - Potential for richer plugin lifecycle (install/remove at runtime).
479
+ - Improve error reporting in subagents.
480
+
481
+ ---
482
+
483
+ ## 🔒 Security Notes
484
+
485
+ ---
486
+
487
+ ## 🛠 Error Handling & Recovery Flows
488
+ BluMa handles different classes of errors gracefully:
489
+ - **Network/API Errors**: Retry logic with exponential backoff.
490
+ - **Authentication Failures**: Immediate notification to user, requires updating environment variables.
491
+ - **Tool Execution Errors**: Displayed with detailed message; execution can be retried or skipped.
492
+ - **LLM/API Exceptions**: Fall back to safe mode and keep context intact.
493
+ - **Session/History Save Failures**: Warn user and continue without losing core functionality.
494
+
495
+ ---
496
+
497
+ ## 📈 Metrics & Observability
498
+ - **Performance Metrics**: Average response time, tokens used per request, tool execution times.
499
+ - **Usage Tracking**: Number of commands executed, tool calls, sessions created.
500
+ - **Logging**: Structured logs for all events.
501
+ - Integration-ready with Prometheus/Grafana or external observability platforms.
502
+
503
+ ---
504
+
505
+ ## 🔐 Advanced Security Practices
506
+ - Use secret management tools (Vault, AWS Secrets Manager) to store environment variables.
507
+ - Apply principle of least privilege for API keys.
508
+ - Validate and sanitize all user inputs to avoid prompt injection attacks.
509
+ - Regularly rotate API keys.
510
+
511
+ ---
512
+
513
+ ## 🚀 Performance & Scalability
514
+ - Optimize context window by pruning irrelevant history.
515
+ - Batch related operations to reduce LLM calls.
516
+ - Support for distributed execution or remote agent hosting.
517
+ - Cache static responses where possible.
518
+
519
+ ---
520
+
521
+ ## 🔄 Development Cycle & CI/CD
522
+ - **Testing**: `npm test` and `npm run test:watch` for development.
523
+ - **Linting**: Enforce coding standards with ESLint/Prettier.
524
+ - **CI/CD**: Recommended GitHub Actions or similar to run tests/build on push.
525
+ - **Deployment**: Automatic packaging to npm or internal registry.
526
+
527
+ ---
528
+
529
+ ## 🗺 Roadmap & Release Notes
530
+ **Upcoming:**
531
+ - Multi-LLM provider support.
532
+ - Web-based dashboard.
533
+ - Richer subagent plugin APIs.
534
+
535
+ **Release Notes**:
536
+ - Follow [CHANGELOG.md](CHANGELOG.md) for version history.
537
+
538
+ ---
539
+
540
+ ## 🎯 Advanced Use Cases
541
+ - Chain multiple tools with complex decision-making.
542
+ - Build custom subagents for domain-specific automation.
543
+ - Integrate with CI pipelines for automated code review and refactoring.
544
+
545
+ ---
546
+
547
+ ## 📏 Code Standards & Contribution Guidelines
548
+ - Follow TypeScript strict mode.
549
+ - Commit messages must follow Conventional Commits (`feat:`, `fix:`, `chore:`).
550
+ - Keep functions short, modular and documented.
551
+ - Add unit tests for all business logic.
552
+
553
+ ---
554
+ - Protect your API keys: never commit `.env` files.
555
+ - `edit_tool` can modify files — review previews before accepting.
556
+ - Use restricted permissions for API tokens wherever possible.
557
+ - If using on shared systems, ensure `.bluma-cli` config is private.
package/dist/main.js CHANGED
@@ -142,9 +142,15 @@ function inputReducer(state, action, viewWidth) {
142
142
  }
143
143
  case "SET": {
144
144
  const t = action.payload.text.replace(/(||)/gm, "");
145
- const moveToEnd = action.payload.moveCursorToEnd ?? true;
145
+ let newCursorPosition;
146
+ if (typeof action.payload.cursorPosition === "number") {
147
+ newCursorPosition = Math.min(action.payload.cursorPosition, t.length);
148
+ } else if (action.payload.moveCursorToEnd ?? true) {
149
+ newCursorPosition = t.length;
150
+ } else {
151
+ newCursorPosition = Math.min(state.cursorPosition, t.length);
152
+ }
146
153
  const newText = t;
147
- const newCursorPosition = moveToEnd ? newText.length : Math.min(state.cursorPosition, newText.length);
148
154
  const newViewStart = adjustView(newCursorPosition, 0);
149
155
  return { text: newText, cursorPosition: newCursorPosition, viewStart: newViewStart };
150
156
  }
@@ -375,12 +381,16 @@ function useAtCompletion({
375
381
  let chosen = suggestions[selected].label;
376
382
  const isDir = suggestions[selected].isDir;
377
383
  chosen = chosen.replace(/\\/g, "/").replace(/\|/g, "");
378
- let insertVal = chosen;
379
- if (insertVal.includes("/")) {
380
- insertVal = insertVal.replace(/\/+$/g, "");
381
- const parts = insertVal.split("/");
382
- insertVal = parts[parts.length - 1];
384
+ let insertVal = chosen.replace(/\/+$/g, "");
385
+ const currentPattern = res.pattern || "";
386
+ if (currentPattern.length > 0) {
387
+ const normalizedPattern = currentPattern.replace(/\/+$/g, "");
388
+ if (insertVal.startsWith(normalizedPattern)) {
389
+ insertVal = insertVal.slice(normalizedPattern.length);
390
+ insertVal = insertVal.replace(/^\/+/, "");
391
+ }
383
392
  }
393
+ insertVal = insertVal.split("\\").join("/");
384
394
  if (isDir && !insertVal.endsWith("/")) insertVal = insertVal + "/";
385
395
  const pattern = res.pattern || "";
386
396
  const lastSlash = pattern.lastIndexOf("/");
@@ -389,13 +399,16 @@ function useAtCompletion({
389
399
  const before = text.slice(0, segmentStart);
390
400
  const after = text.slice(cursorPosition);
391
401
  const newText = before + insertVal + after;
392
- setText(newText + (isDir ? "" : " "), true);
402
+ const finalText = newText + " ";
403
+ setText(finalText, finalText.length);
404
+ globalThis.__BLUMA_FORCE_CURSOR_END__ = true;
405
+ update(finalText, finalText.length);
393
406
  if (isDir) {
394
407
  setOpen(false);
395
408
  setSuggestions([]);
396
409
  setTimeout(() => {
397
410
  setOpen(true);
398
- update(newText, newText.length);
411
+ update(finalText, finalText.length);
399
412
  }, 0);
400
413
  } else {
401
414
  setOpen(false);
@@ -496,6 +509,12 @@ var InputPrompt = ({ onSubmit, isReadOnly, onInterrupt, disableWhileProcessing =
496
509
  setSlashOpen(false);
497
510
  }
498
511
  }, { isActive: slashOpen });
512
+ useEffect2(() => {
513
+ if (globalThis.__BLUMA_FORCE_CURSOR_END__) {
514
+ setText(text, text.length);
515
+ delete globalThis.__BLUMA_FORCE_CURSOR_END__;
516
+ }
517
+ }, [text, setText]);
499
518
  const cwd = process.cwd();
500
519
  const pathAutocomplete = useAtCompletion({ cwd, text, cursorPosition, setText });
501
520
  useInput2((input, key) => {
@@ -514,6 +533,7 @@ var InputPrompt = ({ onSubmit, isReadOnly, onInterrupt, disableWhileProcessing =
514
533
  if (m) {
515
534
  globalThis.__BLUMA_SUPPRESS_SUBMIT__ = true;
516
535
  pathAutocomplete.insertAtSelection();
536
+ return;
517
537
  }
518
538
  }
519
539
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomad-e/bluma-cli",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "BluMa independent agent for automation and advanced software engineering.",
5
5
  "author": "Alex Fonseca",
6
6
  "license": "Apache-2.0",