@naseej/blox 1.11.0 → 1.13.0

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 (4) hide show
  1. package/dist/run.js +3271 -1201
  2. package/dist/sdk.js +44 -4
  3. package/package.json +5 -2
  4. package/readme.md +46 -14
package/dist/sdk.js CHANGED
@@ -70,7 +70,8 @@ var isNonInteractive = () => nonInteractiveFlag || !process.stdin.isTTY;
70
70
 
71
71
  // src/config/runtime.ts
72
72
  var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
73
- var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
73
+ var forceMinimalMode = false;
74
+ var isMinimalMode = () => forceMinimalMode || !!import_extra_typings2.program.opts()?.minimal;
74
75
 
75
76
  // src/shared/terminal/index.ts
76
77
  var import_ansis = __toESM(require("ansis"));
@@ -196,15 +197,54 @@ var multiselect = async (opts) => {
196
197
 
197
198
  // src/shared/spinner.ts
198
199
  var import_prompts4 = require("@clack/prompts");
200
+ var import_string_width = __toESM(require("string-width"));
201
+ var SPINNER_RESERVED_COLUMNS = 7;
202
+ var ANSI_PATTERN = /\u001B\[[0-9;]*[A-Za-z]/y;
203
+ var segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
204
+ var fitToTerminal = (msg, columns = process.stdout.columns) => {
205
+ if (!columns) return msg;
206
+ const max = Math.max(columns - SPINNER_RESERVED_COLUMNS, 10);
207
+ if ((0, import_string_width.default)(msg) <= max) return msg;
208
+ let out = "";
209
+ let visible = 0;
210
+ let hasAnsi = false;
211
+ for (let i = 0; i < msg.length; ) {
212
+ ANSI_PATTERN.lastIndex = i;
213
+ const match = ANSI_PATTERN.exec(msg);
214
+ if (match) {
215
+ out += match[0];
216
+ i += match[0].length;
217
+ hasAnsi = true;
218
+ continue;
219
+ }
220
+ const next = msg.indexOf("\x1B", i + 1);
221
+ const chunk = msg.slice(i, next === -1 ? void 0 : next);
222
+ let consumed = 0;
223
+ let full = true;
224
+ for (const { segment } of segmenter.segment(chunk)) {
225
+ const w = (0, import_string_width.default)(segment);
226
+ if (visible + w > max - 1) {
227
+ full = false;
228
+ break;
229
+ }
230
+ out += segment;
231
+ visible += w;
232
+ consumed += segment.length;
233
+ }
234
+ if (!full) break;
235
+ i += consumed;
236
+ }
237
+ return `${out}${hasAnsi ? "\x1B[0m" : ""}\u2026`;
238
+ };
199
239
  var spinner = () => {
200
- const s = (0, import_prompts4.spinner)();
201
240
  const minimal = isMinimalMode() || isDebugMode();
241
+ const s = minimal ? void 0 : (0, import_prompts4.spinner)();
202
242
  const stop = (msg = "error", code) => {
203
243
  minimal ? code ? import_prompts2.log.error(msg) : import_prompts2.log.step(msg || "success") : s.stop(code ? fmt.red(msg) : fmt.green(msg), code);
204
244
  };
205
245
  return {
206
246
  start: (msg) => {
207
- minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg);
247
+ minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg && fitToTerminal(msg));
208
248
  },
209
249
  stop,
210
250
  success: (msg = "success") => {
@@ -217,7 +257,7 @@ var spinner = () => {
217
257
  stop(msg, 0);
218
258
  },
219
259
  message: (msg) => {
220
- minimal ? import_prompts2.log.message(msg) : s.message(msg);
260
+ minimal ? import_prompts2.log.message(msg) : s.message(fitToTerminal(msg));
221
261
  }
222
262
  };
223
263
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "blox cli",
5
5
  "exports": {
6
6
  "./sdk": {
@@ -47,6 +47,7 @@
47
47
  "postinstall": "patch-package"
48
48
  },
49
49
  "devDependencies": {
50
+ "@modelcontextprotocol/client": "2.4.0",
50
51
  "@playwright/test": "^1.59.1",
51
52
  "@tsconfig/node20": "^20.1.4",
52
53
  "@types/cross-spawn": "^6.0.6",
@@ -79,9 +80,9 @@
79
80
  "@clack/core": "0.3.5",
80
81
  "@clack/prompts": "0.8.2",
81
82
  "@commander-js/extra-typings": "12.1.0",
83
+ "@modelcontextprotocol/server": "2.4.0",
82
84
  "ansis": "3.3.2",
83
85
  "commander": "12.1.0",
84
- "typescript": "^5.7.2",
85
86
  "cross-spawn": "^7.0.6",
86
87
  "dayjs": "1.11.13",
87
88
  "ejs": "^3.1.10",
@@ -93,6 +94,8 @@
93
94
  "lodash": "^4.17.21",
94
95
  "ms": "2.1.3",
95
96
  "semver": "^7.7.4",
97
+ "string-width": "^7.2.0",
98
+ "typescript": "^5.7.2",
96
99
  "zod": "^4.4.3"
97
100
  }
98
101
  }
package/readme.md CHANGED
@@ -51,49 +51,54 @@ Available commands:
51
51
  - `blox upgrade`: upgrade BLOX CLI
52
52
  - `blox skills`: run BLOX CLI skills commands
53
53
  - `blox doctor`: diagnose and optionally repair BLOX workspace issues
54
+ - `blox mcp`: run the BLOX MCP server over stdio for MCP-compatible clients
54
55
 
55
56
  ## Projects with applications
56
57
 
57
- A BLOX project can contain complete applications vendored under `apps/` inside a single repository. Each application is a full BLOX project with its own `.blox`, configuration, dependencies, and `blocks/` directory:
58
+ A BLOX project can act as a workspace containing complete applications under `apps/`. The workspace is itself a full BLOX template with its own Git repository, and every application is an independent BLOX project with its own Git repository, `.blox`, configuration, dependencies, and `blocks/` directory:
58
59
 
59
60
  ```text
60
61
  my-project/
62
+ ├── .git/
61
63
  ├── .blox
62
- ├── blocks/ # shared root blocks
64
+ ├── .gitignore # ignores apps/<name> directories
65
+ ├── blocks/ # workspace root blocks
63
66
  └── apps/
64
67
  ├── web/
68
+ │ ├── .git/
65
69
  │ ├── .blox
66
70
  │ └── blocks/ # web-specific blocks
67
71
  └── api/
72
+ ├── .git/
68
73
  ├── .blox
69
74
  └── blocks/
70
75
  ```
71
76
 
72
77
  Key behaviors:
73
78
 
74
- - There is one Git repository at the workspace root — applications do not have nested repositories.
79
+ - The workspace and every application are independent Git repositories. Application directories are added to the workspace `.gitignore`, so the root repository never tracks them.
75
80
  - Commands run inside `apps/<name>` automatically scope to that application; `--app <name>` scopes them from the workspace root.
76
81
  - Applications are added and removed like blocks: `blox add app/web` materializes an application under `apps/`; `blox remove app/web` removes it.
77
- - Block dependencies resolve in the owning scope: application blocks resolve same-application blocks first, then root shared blocks; root blocks only resolve other root blocks.
82
+ - Blocks resolve only within their owning scope: application blocks resolve same-application blocks; root blocks only resolve other root blocks. There are no shared blocks between the workspace and its applications.
78
83
  - `blox update` at the workspace root updates the root project and every application sequentially; `--app <name>` restricts it to one application.
79
- - Registries declare applications in a nested `apps` map on the template entry, mirroring `blocks`:
84
+ - `blox contribute` at the workspace root contributes the workspace template; `--app <name>` contributes only that application's repository.
85
+ - Registries declare applications as an `apps` array on the template entry; each entry references an existing template in the registry:
80
86
 
81
87
  ```json
82
88
  {
83
89
  "templates": {
84
90
  "fullstack": {
85
- "apps": {
86
- "web": {
87
- "source": "/template-web",
88
- "destination": "web",
89
- "blocks": { "auth": {} }
90
- }
91
- }
91
+ "apps": [
92
+ { "template": "web-template", "name": "web", "version": 1 },
93
+ { "template": "api-service" }
94
+ ]
92
95
  }
93
96
  }
94
97
  }
95
98
  ```
96
99
 
100
+ `template` (required) names the template that provides the application's source and block catalog; `name` (optional) is the application name inside the workspace and defaults to the template name; `version` (optional) pins a requested major version, otherwise the latest available version is used.
101
+
97
102
  ### init
98
103
 
99
104
  Initialize a new app.
@@ -195,7 +200,7 @@ Important notes:
195
200
  - If `components` are omitted, BLOX prompts with a multiselect from installed blocks and applications.
196
201
  - You can pass registry keys or installed folder names under `blocks/`.
197
202
  - Only directories under `blocks/` containing a valid `.blox` file are treated as removable blocks. Applications are `apps/<name>` directories containing a `.blox` file.
198
- - Removing a root block checks dependents across the root and every application's blocks; removing an application block checks dependents only within the same application.
203
+ - Removing a block checks dependents within the same project scope only (the workspace root, or the application it belongs to).
199
204
  - Blocks are processed sequentially in the order provided.
200
205
 
201
206
  ### update
@@ -307,6 +312,7 @@ Important options:
307
312
  - `--breaking-summary <summary>`: breaking-change summary (required with `--breaking`)
308
313
  - `--breaking-migration <instructions>`: migration instructions (required with `--breaking`)
309
314
  - `--branch <name>`: existing contribution branch (used with `--existing`)
315
+ - `--app <name>`: contribute the application `apps/<name>` repository instead of the workspace; inside an application directory this is implicit
310
316
  - `--force`: bypass safety pre-flight checks
311
317
  - `--non-interactive`: run without prompts; missing inputs fail instead of prompting
312
318
  - `--json`: emit a machine-readable JSON result on stdout
@@ -437,11 +443,37 @@ Exit codes:
437
443
  - `1`: invalid findings remain, or a repair failed
438
444
  - `2`: a check could not complete reliably
439
445
 
446
+ ### mcp
447
+
448
+ Start the BLOX MCP server for one BLOX project. MCP-compatible clients launch it as a subprocess and own its lifecycle:
449
+
450
+ ```sh
451
+ blox mcp # serve the project containing the current directory
452
+ blox mcp --cwd /projects/my-dashboard # serve an explicit project
453
+ blox mcp --cwd ../my-dashboard # relative paths resolve against the current directory
454
+ ```
455
+
456
+ One server serves one project. The project is resolved and validated once at startup: `--cwd` (default: the current directory) must exist, be readable, and be inside a BLOX project (the nearest `.blox`, so a subdirectory or `apps/<name>` works). Otherwise the server exits with a non-zero code and an error on stderr; it never falls back to another directory. Start one server per project.
457
+
458
+ The server uses stdio transport. Stdout is reserved for MCP protocol messages; logs and diagnostics go to stderr. It exposes block-focused tools for project context, installed/available block discovery, block inspection, block addition and removal, project updates, and doctor checks, plus read-only `blox://` resources for the configured project (including a `blox://blocks/{name}` template for block details). Application management is not exposed yet.
459
+
460
+ Tools operate on the configured project; they do not need a project path. The optional `cwd` tool argument must stay inside the project (relative paths resolve against the project root; `..` and symlinks leading outside are rejected with `OUTSIDE_PROJECT`), and `app` targets an application under `apps/`. MCP roots are not used. `update_project` accepts `dryRun: true` to return a read-only plan (current vs. target registry versions, breaking changes, blockers) without changing files or git state. `remove_blocks` also accepts `dryRun: true` (paths, dependents, lifecycle hooks, blockers); a real removal requires a clean git working tree, checks the whole batch before deleting anything, refuses blocks other blocks depend on unless `force: true`, rolls back on failure, and never removes applications.
461
+
462
+ Example client configuration:
463
+
464
+ ```json
465
+ {
466
+ "mcpServers": {
467
+ "blox": { "command": "blox", "args": ["mcp", "--cwd", "/projects/my-dashboard"] }
468
+ }
469
+ }
470
+ ```
471
+
440
472
  ## Features
441
473
 
442
474
  ### Non-interactive Use and JSON Output
443
475
 
444
- All commands except `blox skills` support two independent flags:
476
+ All commands except `blox skills` and `blox mcp` support two independent flags:
445
477
 
446
478
  - **`--non-interactive`** controls interaction: nothing is ever prompted; missing required arguments are reported together and the command exits non-zero.
447
479
  - **`--json`** controls output format: the CLI writes one JSON envelope to stdout while prompts, progress, warnings, and diagnostics go to stderr.