memoryblock 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -115
- package/bin/mblk.js +68 -71
- package/dist/commands/create.d.ts +2 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +48 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/delete.d.ts +5 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +147 -0
- package/dist/commands/delete.js.map +1 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +209 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/permissions.d.ts +13 -0
- package/dist/commands/permissions.d.ts.map +1 -0
- package/dist/commands/permissions.js +60 -0
- package/dist/commands/permissions.js.map +1 -0
- package/dist/commands/plugin-settings.d.ts +6 -0
- package/dist/commands/plugin-settings.d.ts.map +1 -0
- package/dist/commands/plugin-settings.js +118 -0
- package/dist/commands/plugin-settings.js.map +1 -0
- package/dist/commands/plugins.d.ts +3 -0
- package/dist/commands/plugins.d.ts.map +1 -0
- package/dist/commands/plugins.js +83 -0
- package/dist/commands/plugins.js.map +1 -0
- package/dist/commands/reset.d.ts +8 -0
- package/dist/commands/reset.d.ts.map +1 -0
- package/dist/commands/reset.js +96 -0
- package/dist/commands/reset.js.map +1 -0
- package/dist/commands/server.d.ts +25 -0
- package/dist/commands/server.d.ts.map +1 -0
- package/dist/commands/server.js +295 -0
- package/dist/commands/server.js.map +1 -0
- package/dist/commands/service.d.ts +18 -0
- package/dist/commands/service.d.ts.map +1 -0
- package/dist/commands/service.js +309 -0
- package/dist/commands/service.js.map +1 -0
- package/dist/commands/start.d.ts +11 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +794 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +78 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/stop.d.ts +9 -0
- package/dist/commands/stop.d.ts.map +1 -0
- package/dist/commands/stop.js +83 -0
- package/dist/commands/stop.js.map +1 -0
- package/dist/commands/web.d.ts +5 -0
- package/dist/commands/web.d.ts.map +1 -0
- package/dist/commands/web.js +63 -0
- package/dist/commands/web.js.map +1 -0
- package/dist/commands.d.ts +7 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +7 -0
- package/dist/commands.js.map +1 -0
- package/dist/constants.d.ts +41 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +81 -0
- package/dist/constants.js.map +1 -0
- package/dist/entry.d.ts +9 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +345 -0
- package/dist/entry.js.map +1 -0
- package/package.json +32 -11
- package/dist/engine/agent.d.ts +0 -15
- package/dist/engine/agent.d.ts.map +0 -1
- package/dist/engine/agent.js +0 -19
- package/dist/engine/agent.js.map +0 -1
- package/dist/engine/conversation-log.d.ts +0 -35
- package/dist/engine/conversation-log.d.ts.map +0 -1
- package/dist/engine/conversation-log.js +0 -83
- package/dist/engine/conversation-log.js.map +0 -1
- package/dist/engine/cost-tracker.d.ts +0 -52
- package/dist/engine/cost-tracker.d.ts.map +0 -1
- package/dist/engine/cost-tracker.js +0 -110
- package/dist/engine/cost-tracker.js.map +0 -1
- package/dist/engine/gatekeeper.d.ts +0 -20
- package/dist/engine/gatekeeper.d.ts.map +0 -1
- package/dist/engine/gatekeeper.js +0 -43
- package/dist/engine/gatekeeper.js.map +0 -1
- package/dist/engine/memory.d.ts +0 -28
- package/dist/engine/memory.d.ts.map +0 -1
- package/dist/engine/memory.js +0 -69
- package/dist/engine/memory.js.map +0 -1
- package/dist/engine/monitor.d.ts +0 -81
- package/dist/engine/monitor.d.ts.map +0 -1
- package/dist/engine/monitor.js +0 -610
- package/dist/engine/monitor.js.map +0 -1
- package/dist/engine/prompts.d.ts +0 -31
- package/dist/engine/prompts.d.ts.map +0 -1
- package/dist/engine/prompts.js +0 -93
- package/dist/engine/prompts.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/utils/config.d.ts +0 -24
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -86
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/fs.d.ts +0 -18
- package/dist/utils/fs.d.ts.map +0 -1
- package/dist/utils/fs.js +0 -65
- package/dist/utils/fs.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -12
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -40
- package/dist/utils/logger.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,149 +37,107 @@
|
|
|
37
37
|
|
|
38
38
|
</div>
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
`memoryblock` is a lightweight framework for orchestrating isolated AI background workers. Instead of building monolithic chatbots, we provision local workspaces called **blocks**. Each block acts as a dedicated environment equipped with its own continuous memory, toolset, and execution loop.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
Spawn a devops block to watch your infrastructure, a research block to scrape web data, and your primary home block to coordinate tasks. No state pollution, no crossed context boundaries.
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
├── channel ───── block "devops" (monitors + alerts)
|
|
49
|
-
└── web ui ────── block "research" (deep dives + summaries)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## ✨ What Makes This Different
|
|
53
|
-
|
|
54
|
-
### It's cheap to run. Seriously.
|
|
55
|
-
|
|
56
|
-
Most AI tools send the entire tool schema. Thousands of tokens. On *every single message*. For a background agent running all day, that's money on fire.
|
|
57
|
-
|
|
58
|
-
Memoryblock was engineered around this problem:
|
|
59
|
-
|
|
60
|
-
- **On-demand schema loading** - tool definitions are injected only when needed, then dropped. Payload sizes go from ~2,600 tokens to ~1,200 tokens per turn.
|
|
61
|
-
- **History trimming** - large tool outputs (log dumps, file contents) are read once, then truncated in memory to 500 characters. The LLM already saw it. No need to pay for it again.
|
|
62
|
-
- **Smart context recovery** - when context fills up, the engine summarizes everything into clean, actionable notes and starts fresh. No crash, no data loss, no compact context error loops.
|
|
63
|
-
|
|
64
|
-
> In testing, these optimizations reduce token growth between turns from 4.2× to under 2×, resulting in over 50% cost reduction on sustained sessions.
|
|
65
|
-
|
|
66
|
-
### It runs on Bun. Nothing else.
|
|
67
|
-
|
|
68
|
-
No Node.js. No Electron. No heavy frameworks. The entire core, HTTP server, WebSocket streaming, static file serving, is built on native APIs. Cold starts are fast. Memory usage is small.
|
|
69
|
-
|
|
70
|
-
### Every block is its own world.
|
|
71
|
-
|
|
72
|
-
Each block gets its own `config.json`, `memory.md`, `monitor.md`, `costs.json`, and log directory. Move a block between machines by copying its folder. Back it up by zipping it. There's no shared database, no centralized state, no magic.
|
|
73
|
-
|
|
74
|
-
### Talk to it from anywhere.
|
|
75
|
-
|
|
76
|
-
Your blocks are accessible through the **CLI** (a simple interactive terminal), different **Channels** (including Telegram, Discord, Slack, and more), and a **Web Dashboard** (with live WebSocket updates). Same block, same memory, different surfaces.
|
|
77
|
-
|
|
78
|
-
### Use any model you want.
|
|
79
|
-
|
|
80
|
-
Memoryblock doesn't lock you into one provider. Swap models per-block, per-task, or per-agent:
|
|
81
|
-
|
|
82
|
-
| Adapter | Auth |
|
|
83
|
-
|:---|:---|
|
|
84
|
-
| **AWS Bedrock** | AWS credentials |
|
|
85
|
-
| **OpenAI** | API key |
|
|
86
|
-
| **Google Gemini** | API key |
|
|
87
|
-
| **Anthropic** | API key |
|
|
88
|
-
|
|
89
|
-
Adding a new adapter is one file. See [adapter docs](https://docs.memoryblock.io/adapters/) for examples.
|
|
44
|
+
* **Absolute Isolation**: Every agent lives inside a dedicated filesystem directory (`config.json`, `memory.md`, `logs/`). To move an agent to a new server, you just copy its folder. No centralized databases to manage.
|
|
45
|
+
* **Token Pruning**: Running background agents is historically expensive. `memoryblock` mitigates this by lazy-loading tool schemas only when invoked, and proactively truncating long tool outputs once analyzed. This typically halves the cost of sustained sessions.
|
|
46
|
+
* **Native & Lean**: Zero dependency on heavy Node.js runtimes or Electron ecosystems. The core engine, HTTP server, and WebSocket router rely purely on [Bun's](https://bun.sh) native primitives for maximal I/O speed and minimal RAM overhead.
|
|
47
|
+
* **Model Agnostic**: Provision blocks dynamically utilizing native definitions for OpenAI, Anthropic, AWS Bedrock, or Google Gemini.
|
|
90
48
|
|
|
91
49
|
## Quick Start
|
|
92
50
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
### 1. Install memoryblock
|
|
96
|
-
|
|
97
|
-
**- Option A: Bun (Recommended)**
|
|
98
|
-
If you already use Bun, this is the absolute fastest way to install:
|
|
99
|
-
```bash
|
|
100
|
-
bun install -g memoryblock
|
|
101
|
-
```
|
|
51
|
+
`memoryblock` leverages Bun under the hood for native execution speed. If you use npm, we automatically manage the local Bun environment for you.
|
|
102
52
|
|
|
103
|
-
|
|
53
|
+
**Install the framework globally:**
|
|
104
54
|
```bash
|
|
105
|
-
|
|
55
|
+
bun install -g memoryblock # Option A: Fastest
|
|
56
|
+
npm install -g memoryblock # Option B: Managed internally
|
|
106
57
|
```
|
|
107
58
|
|
|
108
|
-
|
|
109
|
-
Run the setup wizard to verify your local environment and enter your initial provider API keys:
|
|
59
|
+
**Initialize your environment:**
|
|
110
60
|
```bash
|
|
111
61
|
mblk init
|
|
112
62
|
```
|
|
63
|
+
*This interactive wizard verifies your local environment and configures your initial LLM provider credentials.*
|
|
113
64
|
|
|
114
|
-
|
|
115
|
-
That's it! You can now start your very first personal assistant block:
|
|
65
|
+
**Start your default block:**
|
|
116
66
|
```bash
|
|
117
|
-
mblk start
|
|
67
|
+
mblk start [block-name]
|
|
118
68
|
```
|
|
69
|
+
*Your autonomous assistant is now running in the background.*
|
|
119
70
|
|
|
120
|
-
|
|
71
|
+
## Working with Channels
|
|
121
72
|
|
|
73
|
+
Your blocks are decoupled from the UI. Communicate with them via the terminal, secure web dashboard, or standard chat clients.
|
|
74
|
+
|
|
75
|
+
**Launch the Web Dashboard:**
|
|
122
76
|
```bash
|
|
123
77
|
mblk web
|
|
124
78
|
```
|
|
79
|
+
*Access real-time stream logs, cost tracking, and memory management at `localhost:8420`.*
|
|
125
80
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
### Channels
|
|
129
|
-
|
|
81
|
+
**Route a block to social channels:**
|
|
130
82
|
```bash
|
|
131
83
|
mblk start home --channel telegram
|
|
132
84
|
```
|
|
85
|
+
*Securely interact with your existing agent state from anywhere without losing active history.*
|
|
133
86
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
## Commands
|
|
87
|
+
## Command Reference
|
|
137
88
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
|
141
|
-
|
|
142
|
-
| `mblk
|
|
143
|
-
| `mblk
|
|
144
|
-
| `mblk
|
|
145
|
-
| `mblk
|
|
146
|
-
| `mblk
|
|
147
|
-
| `mblk
|
|
148
|
-
| `mblk
|
|
149
|
-
| `mblk
|
|
150
|
-
|
|
151
|
-
|
|
89
|
+
| Command | Description |
|
|
90
|
+
|:---|:---|
|
|
91
|
+
| `mblk init` | Interactive setup - configure credentials and create your first block |
|
|
92
|
+
| `mblk create <name>` | Create a new block (isolated AI workspace) |
|
|
93
|
+
| `mblk start [block]` | Start a block's monitor loop (or all blocks) |
|
|
94
|
+
| `mblk stop [block]` | Stop a running block monitor (or all blocks) |
|
|
95
|
+
| `mblk status` | Show all blocks and their state |
|
|
96
|
+
| `mblk delete <block>` | Archive a block safely (use `--hard` to permanently delete) |
|
|
97
|
+
| `mblk restore <name>` | Restore an archived block |
|
|
98
|
+
| `mblk reset <block>` | Reset memory, costs, and session (use `--hard` to wipe identity) |
|
|
99
|
+
| `mblk permissions <block>` | View or update block permissions |
|
|
100
|
+
| `mblk settings [plugin]` | View or edit plugin settings |
|
|
101
|
+
| `mblk add [plugin]` | Install a plugin (no args lists available) |
|
|
102
|
+
| `mblk remove <plugin>` | Remove an installed plugin |
|
|
103
|
+
| `mblk server start` | Start the web UI and API server |
|
|
104
|
+
| `mblk server stop` | Stop the running server |
|
|
105
|
+
| `mblk server status` | Show server status |
|
|
106
|
+
| `mblk server token` | View or regenerate the API auth token |
|
|
107
|
+
| `mblk service install` | Register memoryblock to start on boot/login |
|
|
108
|
+
| `mblk shutdown` | Stop all blocks and the server |
|
|
109
|
+
| `mblk restart` | Full restart — shutdown then start everything as daemons |
|
|
110
|
+
|
|
111
|
+
Full reference: [command docs](https://docs.memoryblock.io/commands/)
|
|
152
112
|
|
|
153
113
|
## Plugins
|
|
154
114
|
|
|
155
115
|
Blocks come with a core set of tools. Need more? Add them:
|
|
156
116
|
|
|
157
117
|
```bash
|
|
158
|
-
mblk add web-search #
|
|
159
|
-
mblk add fetch-webpage #
|
|
160
|
-
mblk add agents #
|
|
118
|
+
mblk add web-search # Enables high-fidelity SERP querying
|
|
119
|
+
mblk add fetch-webpage # Extracts and chunks text from structured URLs
|
|
120
|
+
mblk add agents # Allows blocks to spawn ephemeral sub-agents
|
|
161
121
|
```
|
|
162
122
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
| Plugin | What it does |
|
|
166
|
-
|:---|:---|
|
|
167
|
-
| `web-search` | Search the web with your configured provider |
|
|
168
|
-
| `fetch-webpage` | Extract clean text from URLs |
|
|
169
|
-
| `agents` | Spawn sub-agents for delegated tasks |
|
|
170
|
-
| `aws` | Cloud SDK code generation tools |
|
|
123
|
+
Adapters for **OpenAI, Anthropic, Google Gemini, and AWS Bedrock** are natively supported out-of-the-box. Adding a custom provider adapter requires implementing a single unified payload interface.
|
|
171
124
|
|
|
172
|
-
##
|
|
125
|
+
## Monorepo Architecture
|
|
173
126
|
|
|
174
|
-
|
|
127
|
+
`memoryblock` is built as a highly modular TypeScript monorepo utilizing a strict one-way Directed Acyclic Graph (DAG) for dependency management. All sub-packages are independently publishable.
|
|
175
128
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
129
|
+
| Package | Responsibility |
|
|
130
|
+
|:---|:---|
|
|
131
|
+
| `memoryblock` | Global executable wrapper, setup tooling, and CLI orchestration. |
|
|
132
|
+
| `@memoryblock/core` | Extracted engine runtime (Gatekeeper, Memory Manager, Monitor loops). |
|
|
133
|
+
| `@memoryblock/types` | Centralized Zod validation schemas and TypeScript interfaces. |
|
|
134
|
+
| `@memoryblock/daemon` | Low-level OS process spawner and background lifecycle manager. |
|
|
135
|
+
| `@memoryblock/adapters` | Unified REST/SDK implementations for LLM providers. |
|
|
136
|
+
| `@memoryblock/channels` | Transport layer for CLI, WebSockets, and messaging platforms. |
|
|
137
|
+
| `@memoryblock/tools` | Core functional schemas (File I/O, OS interactions). |
|
|
138
|
+
| `@memoryblock/api` | Fast, dependency-injected HTTP web server integration. |
|
|
139
|
+
| `@memoryblock/locale` | Formatting tools and centralized translation strings. |
|
|
140
|
+
| `@memoryblock/web` | Standalone UI distribution package. |
|
|
183
141
|
|
|
184
142
|
## Community & Support
|
|
185
143
|
|
|
@@ -191,18 +149,18 @@ Supported and upcoming channels are documented in [channels](https://docs.memory
|
|
|
191
149
|
**memoryblock** is a highly modular system. Here are the official packages:
|
|
192
150
|
|
|
193
151
|
**The Core**
|
|
194
|
-
* [**memoryblock**](https://www.npmjs.com/package/memoryblock) -
|
|
195
|
-
* [**@memoryblock/
|
|
196
|
-
* [**@memoryblock/
|
|
197
|
-
* [**@memoryblock/
|
|
198
|
-
* [**@memoryblock/types**](https://www.npmjs.com/package/@memoryblock/types) - Core TypeScript definitions and schemas.
|
|
152
|
+
* [**memoryblock**](https://www.npmjs.com/package/memoryblock) - CLI orchestrator and command routing.
|
|
153
|
+
* [**@memoryblock/core**](https://www.npmjs.com/package/@memoryblock/core) - Engine runtime, memory manager, gatekeeper.
|
|
154
|
+
* [**@memoryblock/types**](https://www.npmjs.com/package/@memoryblock/types) - Shared TypeScript definitions and schemas.
|
|
155
|
+
* [**@memoryblock/locale**](https://www.npmjs.com/package/@memoryblock/locale) - Localization strings and utilities.
|
|
199
156
|
|
|
200
157
|
**Integrations & Tooling**
|
|
201
|
-
* [**@memoryblock/adapters**](https://www.npmjs.com/package/@memoryblock/adapters) - LLM adapters (OpenAI, Anthropic, Bedrock, etc).
|
|
158
|
+
* [**@memoryblock/adapters**](https://www.npmjs.com/package/@memoryblock/adapters) - LLM provider adapters (OpenAI, Anthropic, Bedrock, etc).
|
|
202
159
|
* [**@memoryblock/channels**](https://www.npmjs.com/package/@memoryblock/channels) - Communication channels (CLI, Telegram, Web).
|
|
203
|
-
* [**@memoryblock/tools**](https://www.npmjs.com/package/@memoryblock/tools) -
|
|
204
|
-
* [**@memoryblock/
|
|
205
|
-
* [**@memoryblock/
|
|
160
|
+
* [**@memoryblock/tools**](https://www.npmjs.com/package/@memoryblock/tools) - Tool registry and built-in definitions.
|
|
161
|
+
* [**@memoryblock/daemon**](https://www.npmjs.com/package/@memoryblock/daemon) - Background process spawner and manager.
|
|
162
|
+
* [**@memoryblock/api**](https://www.npmjs.com/package/@memoryblock/api) - HTTP/WebSocket API server.
|
|
163
|
+
* [**@memoryblock/web**](https://www.npmjs.com/package/@memoryblock/web) - Front-end dashboard static files.
|
|
206
164
|
|
|
207
165
|
**Plugins**
|
|
208
166
|
* [**@memoryblock/plugin-installer**](https://www.npmjs.com/package/@memoryblock/plugin-installer) - Plugin installer and registry manager.
|
package/bin/mblk.js
CHANGED
|
@@ -1,88 +1,85 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
|
-
* memoryblock
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* memoryblock CLI — Universal Entry Point
|
|
5
|
+
*
|
|
6
|
+
* This is the bin proxy installed by `npm install -g memoryblock`.
|
|
7
|
+
* It ensures Bun is available (auto-installing if needed), then re-executes
|
|
8
|
+
* itself under Bun for optimal performance.
|
|
9
|
+
*
|
|
10
|
+
* If Bun is already the runtime, we skip the proxy and run the CLI directly.
|
|
11
|
+
*
|
|
12
|
+
* Design:
|
|
13
|
+
* npm install -g memoryblock → symlinks `mblk` to this file
|
|
14
|
+
* User runs `mblk start` → this script detects Node, installs bun, re-execs via bun
|
|
15
|
+
* Subsequent runs → bun is found immediately, re-exec is instant
|
|
8
16
|
*/
|
|
9
|
-
const { execSync, spawnSync } = require('child_process');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
const fs = require('fs');
|
|
12
|
-
const os = require('os');
|
|
13
|
-
|
|
14
|
-
// Helper to silently run commands
|
|
15
|
-
const run = (cmd) => {
|
|
16
|
-
try {
|
|
17
|
-
return execSync(cmd, { stdio: 'pipe' }).toString().trim();
|
|
18
|
-
} catch {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
import { execSync, spawnSync } from 'node:child_process';
|
|
19
|
+
import { existsSync } from 'node:fs';
|
|
20
|
+
import { join, dirname } from 'node:path';
|
|
21
|
+
import { homedir } from 'node:os';
|
|
22
|
+
import { fileURLToPath } from 'node:url';
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const result = spawnSync(localBun, [cliScriptBun, ...process.argv.slice(2)], { stdio: 'inherit' });
|
|
30
|
-
process.exit(result.status ?? 1);
|
|
31
|
-
}
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
32
26
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const hasBunFn = !!run('command -v bun');
|
|
27
|
+
// ─── Step 0: Are we already running under Bun? ──────────────────────
|
|
28
|
+
// If yes, skip the proxy and run the CLI entry point directly.
|
|
29
|
+
const isBun = typeof globalThis.Bun !== 'undefined';
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
if (isBun) {
|
|
32
|
+
// Running under Bun — load the compiled CLI entry point
|
|
33
|
+
// This file is at: packages/memoryblock/bin/mblk.js
|
|
34
|
+
// Entry point is at: packages/memoryblock/dist/entry.js
|
|
35
|
+
const entryPath = join(__dirname, '..', 'dist', 'entry.js');
|
|
42
36
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.
|
|
46
|
-
|
|
47
|
-
console.error('
|
|
37
|
+
await import(entryPath);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error('❌ Failed to load memoryblock CLI.');
|
|
40
|
+
console.error(' This usually means the package was not built correctly.');
|
|
41
|
+
console.error(' Try reinstalling: npm install -g memoryblock');
|
|
42
|
+
if (err && typeof err === 'object' && 'message' in err) {
|
|
43
|
+
console.error(`\n Error: ${err.message}`);
|
|
44
|
+
}
|
|
48
45
|
process.exit(1);
|
|
49
46
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
47
|
+
} else {
|
|
48
|
+
// ─── Step 1: Running under Node.js — find or install Bun ─────────
|
|
49
|
+
const localBun = join(homedir(), '.bun', 'bin', 'bun');
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
const findBun = () => {
|
|
52
|
+
try {
|
|
53
|
+
return execSync('command -v bun', { stdio: 'pipe' }).toString().trim();
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
// (We also gracefully check if NPM already downloaded it first so we don't redownload)
|
|
59
|
-
if (!fs.existsSync(cliScript) && npmGlobalRoot) {
|
|
60
|
-
const npmScript = path.join(npmGlobalRoot, '@memoryblock/cli', 'bin', 'mblk.js');
|
|
61
|
-
if (fs.existsSync(npmScript)) cliScript = npmScript;
|
|
62
|
-
}
|
|
59
|
+
let bunPath = findBun();
|
|
63
60
|
|
|
64
|
-
if (!
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
cliScript = path.join(npmGlobalRoot, '@memoryblock/cli', 'bin', 'mblk.js');
|
|
75
|
-
} catch (err) {
|
|
76
|
-
console.error('\n❌ Failed to sync @memoryblock/cli. Please run manually: npm install -g @memoryblock/cli');
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
console.error(`\n❌ Failed to sync @memoryblock/cli. Please run manually: ${bunPath} install -g @memoryblock/cli`);
|
|
61
|
+
if (!bunPath && !existsSync(localBun)) {
|
|
62
|
+
console.log('\n⚡ \x1b[1mmemoryblock\x1b[0m is powered by \x1b[33mBun\x1b[0m for extreme performance.');
|
|
63
|
+
console.log(' Installing the lightweight engine automatically...\n');
|
|
64
|
+
try {
|
|
65
|
+
execSync('curl -fsSL https://bun.sh/install | bash', { stdio: 'inherit' });
|
|
66
|
+
bunPath = localBun;
|
|
67
|
+
console.log('\n✅ Bun installed successfully!\n');
|
|
68
|
+
} catch {
|
|
69
|
+
console.error('\n❌ Failed to install Bun automatically.');
|
|
70
|
+
console.error(' Please install manually: curl -fsSL https://bun.sh/install | bash');
|
|
81
71
|
process.exit(1);
|
|
82
72
|
}
|
|
83
73
|
}
|
|
84
|
-
}
|
|
85
74
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
if (!bunPath) bunPath = localBun;
|
|
76
|
+
|
|
77
|
+
// ─── Step 2: Re-execute this same file under Bun ─────────────────
|
|
78
|
+
// Bun will detect itself as the runtime and take the fast path above.
|
|
79
|
+
const result = spawnSync(bunPath, [__filename, ...process.argv.slice(2)], {
|
|
80
|
+
stdio: 'inherit',
|
|
81
|
+
env: { ...process.env, MEMORYBLOCK_BUN_PROXY: '1' },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
process.exit(result.status ?? 1);
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAYA,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiDpE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { ensureDir, writeJson, atomicWrite, pathExists } from '@memoryblock/core';
|
|
3
|
+
import { loadGlobalConfig, resolveBlockPath, isInitialized, } from '@memoryblock/core';
|
|
4
|
+
import { BlockConfigSchema, PulseStateSchema } from '@memoryblock/types';
|
|
5
|
+
import { log } from '@memoryblock/core';
|
|
6
|
+
import { FILE_TEMPLATES } from '@memoryblock/core';
|
|
7
|
+
// Templates moved to prompts.ts
|
|
8
|
+
export async function createCommand(blockName) {
|
|
9
|
+
if (!(await isInitialized())) {
|
|
10
|
+
throw new Error('Not initialized. Run `mblk init` first.');
|
|
11
|
+
}
|
|
12
|
+
if (!/^[a-z0-9][a-z0-9-]{0,31}$/.test(blockName)) {
|
|
13
|
+
throw new Error('Block name must start with a letter/number and contain only lowercase letters, numbers, and hyphens (max 32 chars).');
|
|
14
|
+
}
|
|
15
|
+
const globalConfig = await loadGlobalConfig();
|
|
16
|
+
const blockPath = resolveBlockPath(globalConfig, blockName);
|
|
17
|
+
if (await pathExists(blockPath)) {
|
|
18
|
+
throw new Error(`Block "${blockName}" already exists at ${blockPath}`);
|
|
19
|
+
}
|
|
20
|
+
log.brand(`Creating block: ${blockName}\n`);
|
|
21
|
+
// Directory structure
|
|
22
|
+
await ensureDir(blockPath);
|
|
23
|
+
await ensureDir(join(blockPath, 'agents'));
|
|
24
|
+
await ensureDir(join(blockPath, 'logs'));
|
|
25
|
+
// Block config (inherits global defaults)
|
|
26
|
+
const blockConfig = BlockConfigSchema.parse({
|
|
27
|
+
name: blockName,
|
|
28
|
+
adapter: globalConfig.defaults.adapter,
|
|
29
|
+
memory: globalConfig.defaults.memory,
|
|
30
|
+
pulse: globalConfig.defaults.pulse,
|
|
31
|
+
});
|
|
32
|
+
await writeJson(join(blockPath, 'config.json'), blockConfig);
|
|
33
|
+
log.success('Created config.json');
|
|
34
|
+
// Initial pulse state
|
|
35
|
+
const pulse = PulseStateSchema.parse({});
|
|
36
|
+
await writeJson(join(blockPath, 'pulse.json'), pulse);
|
|
37
|
+
log.success('Created pulse.json');
|
|
38
|
+
// Core identity files
|
|
39
|
+
await atomicWrite(join(blockPath, 'memory.md'), FILE_TEMPLATES.MEMORY_MD);
|
|
40
|
+
log.success('Created memory.md');
|
|
41
|
+
await atomicWrite(join(blockPath, 'monitor.md'), FILE_TEMPLATES.MONITOR_MD(blockName));
|
|
42
|
+
log.success('Created monitor.md');
|
|
43
|
+
console.log('');
|
|
44
|
+
log.brand(`Block "${blockName}" is ready.`);
|
|
45
|
+
log.dim(` Path: ${blockPath}`);
|
|
46
|
+
log.dim(` Start: mblk start ${blockName}`);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../src/commands/delete.ts"],"names":[],"mappings":"AA6DA,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAmElG;AAED,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCvE"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { promises as fsp } from 'node:fs';
|
|
3
|
+
import * as p from '@clack/prompts';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { loadGlobalConfig, resolveBlocksDir, isInitialized } from '@memoryblock/core';
|
|
6
|
+
import { ensureDir, pathExists } from '@memoryblock/core';
|
|
7
|
+
import { log } from '@memoryblock/core';
|
|
8
|
+
import { t } from '@memoryblock/locale';
|
|
9
|
+
/**
|
|
10
|
+
* Find archived folders matching a block name.
|
|
11
|
+
* Supports both:
|
|
12
|
+
* - Exact archive name: "dev-pal_2026-03-21T10-33-24-242Z"
|
|
13
|
+
* - Block name prefix: "dev-pal" (matches all archives of that block)
|
|
14
|
+
*/
|
|
15
|
+
async function findArchives(archiveDir, query) {
|
|
16
|
+
// Strip _archive/ prefix if user pastes it
|
|
17
|
+
const name = query.replace(/^_archive\//, '');
|
|
18
|
+
try {
|
|
19
|
+
const entries = await fsp.readdir(archiveDir);
|
|
20
|
+
// 1. Exact match
|
|
21
|
+
if (entries.includes(name))
|
|
22
|
+
return [name];
|
|
23
|
+
// 2. Prefix match: "dev-pal" matches "dev-pal_2026-03-21T10-33-24-242Z"
|
|
24
|
+
const matches = entries
|
|
25
|
+
.filter(e => e.startsWith(`${name}_`))
|
|
26
|
+
.sort()
|
|
27
|
+
.reverse(); // newest first
|
|
28
|
+
return matches;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve a single archive — if multiple exist, let user pick.
|
|
36
|
+
*/
|
|
37
|
+
async function resolveArchive(archiveDir, query) {
|
|
38
|
+
const matches = await findArchives(archiveDir, query);
|
|
39
|
+
if (matches.length === 0)
|
|
40
|
+
return null;
|
|
41
|
+
if (matches.length === 1)
|
|
42
|
+
return matches[0];
|
|
43
|
+
// Multiple archives — let the user pick
|
|
44
|
+
const selection = await p.select({
|
|
45
|
+
message: `Multiple archives found for "${query}". Which one?`,
|
|
46
|
+
options: matches.map(m => {
|
|
47
|
+
// Extract the timestamp for a cleaner label
|
|
48
|
+
const tsMatch = m.match(/_(\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2})/);
|
|
49
|
+
const hint = tsMatch ? tsMatch[1].replace(/-/g, ':').replace('T', ' ').slice(0, 16) : '';
|
|
50
|
+
return { value: m, label: m, hint };
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
if (p.isCancel(selection))
|
|
54
|
+
return null;
|
|
55
|
+
return selection;
|
|
56
|
+
}
|
|
57
|
+
export async function deleteCommand(blockName, options) {
|
|
58
|
+
if (!(await isInitialized())) {
|
|
59
|
+
throw new Error(t.general.notInitialized);
|
|
60
|
+
}
|
|
61
|
+
const globalConfig = await loadGlobalConfig();
|
|
62
|
+
const blocksDir = resolveBlocksDir(globalConfig);
|
|
63
|
+
const blockPath = join(blocksDir, blockName);
|
|
64
|
+
// Check if it's a direct block path first
|
|
65
|
+
if (await pathExists(blockPath)) {
|
|
66
|
+
if (blockName.startsWith('_archive/')) {
|
|
67
|
+
if (!options?.hard) {
|
|
68
|
+
throw new Error(t.archive.mustUseHard);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (options?.hard) {
|
|
72
|
+
try {
|
|
73
|
+
await fsp.rm(blockPath, { recursive: true, force: true });
|
|
74
|
+
log.success(t.archive.hardDeleteSuccess(blockName));
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
throw new Error(`Failed to delete: ${err.message}`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Soft delete — move to _archive directory
|
|
82
|
+
const archiveDir = join(blocksDir, '_archive');
|
|
83
|
+
await ensureDir(archiveDir);
|
|
84
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
85
|
+
const archiveName = `${blockName}_${timestamp}`;
|
|
86
|
+
const archivePath = join(archiveDir, archiveName);
|
|
87
|
+
try {
|
|
88
|
+
await fsp.rename(blockPath, archivePath);
|
|
89
|
+
log.success(t.archive.success(blockName));
|
|
90
|
+
log.dim(` ${t.archive.location(`_archive/${archiveName}`)}`);
|
|
91
|
+
log.dim(` ${t.archive.restoreCmd(blockName)}`);
|
|
92
|
+
log.dim(` ${t.archive.deleteCmd(blockName)}`);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
throw new Error(`Failed to archive block: ${err.message}`);
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Not a live block — maybe user wants to hard-delete an archive by name?
|
|
100
|
+
if (options?.hard) {
|
|
101
|
+
const archiveDir = join(blocksDir, '_archive');
|
|
102
|
+
const resolved = await resolveArchive(archiveDir, blockName);
|
|
103
|
+
if (!resolved) {
|
|
104
|
+
throw new Error(`Block or archive "${blockName}" not found.`);
|
|
105
|
+
}
|
|
106
|
+
const archivePath = join(archiveDir, resolved);
|
|
107
|
+
try {
|
|
108
|
+
await fsp.rm(archivePath, { recursive: true, force: true });
|
|
109
|
+
log.success(`"${resolved}" permanently deleted from archive.`);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
throw new Error(`Failed to delete: ${err.message}`);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`Block "${blockName}" not found. Run \`mblk status\` to see available blocks.`);
|
|
117
|
+
}
|
|
118
|
+
export async function restoreCommand(archiveName) {
|
|
119
|
+
if (!(await isInitialized())) {
|
|
120
|
+
throw new Error(t.general.notInitialized);
|
|
121
|
+
}
|
|
122
|
+
const globalConfig = await loadGlobalConfig();
|
|
123
|
+
const blocksDir = resolveBlocksDir(globalConfig);
|
|
124
|
+
const archiveDir = join(blocksDir, '_archive');
|
|
125
|
+
// Resolve the archive — supports block name, full name, or prefix
|
|
126
|
+
const resolved = await resolveArchive(archiveDir, archiveName);
|
|
127
|
+
if (!resolved) {
|
|
128
|
+
throw new Error(`No archive found for "${archiveName}". Run \`mblk status\` to check archives.`);
|
|
129
|
+
}
|
|
130
|
+
const archivePath = join(archiveDir, resolved);
|
|
131
|
+
// Extract original block name (strip timestamp suffix)
|
|
132
|
+
const match = resolved.match(/^(.*?)_\d{4}-\d{2}-\d{2}T.*/);
|
|
133
|
+
const targetName = match ? match[1] : resolved;
|
|
134
|
+
const targetPath = join(blocksDir, targetName);
|
|
135
|
+
if (await pathExists(targetPath)) {
|
|
136
|
+
throw new Error(`Cannot restore: A block named "${targetName}" already exists. Delete or rename it first.`);
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
await fsp.rename(archivePath, targetPath);
|
|
140
|
+
log.success(`Block "${targetName}" restored successfully.`);
|
|
141
|
+
log.dim(` Start with: ${chalk.bold(`mblk start ${targetName}`)}`);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
throw new Error(`Failed to restore block: ${err.message}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=delete.js.map
|