@claude-flow/cli 3.1.0-alpha.44 → 3.1.0-alpha.45

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/bin/cli.js CHANGED
@@ -6,8 +6,36 @@
6
6
  *
7
7
  * Auto-detects MCP mode when stdin is piped and no args provided.
8
8
  * This allows: echo '{"jsonrpc":"2.0",...}' | npx @claude-flow/cli
9
+ *
10
+ * Includes pre-flight npx cache repair to prevent ENOTEMPTY errors
11
+ * in remote/CI environments (known npm 10.x bug).
9
12
  */
10
13
 
14
+ // Pre-flight: repair stale npx cache to prevent ENOTEMPTY on next run
15
+ import { existsSync, readdirSync, rmSync, statSync } from 'node:fs';
16
+ import { join } from 'node:path';
17
+ import { homedir } from 'node:os';
18
+
19
+ try {
20
+ const npxRoot = join(homedir(), '.npm', '_npx');
21
+ if (existsSync(npxRoot)) {
22
+ for (const dir of readdirSync(npxRoot)) {
23
+ const nm = join(npxRoot, dir, 'node_modules');
24
+ if (!existsSync(nm)) continue;
25
+ try {
26
+ for (const entry of readdirSync(nm)) {
27
+ if (entry.startsWith('.') && entry.includes('-') && /[A-Za-z]{8}$/.test(entry)) {
28
+ try {
29
+ const p = join(nm, entry);
30
+ if (statSync(p).isDirectory()) rmSync(p, { recursive: true, force: true });
31
+ } catch {}
32
+ }
33
+ }
34
+ } catch {}
35
+ }
36
+ }
37
+ } catch {}
38
+
11
39
  import { randomUUID } from 'crypto';
12
40
 
13
41
  // Check if we should run in MCP server mode
package/bin/mcp-server.js CHANGED
@@ -5,8 +5,36 @@
5
5
  * Direct stdio MCP server for Claude Code integration.
6
6
  * This entry point handles stdin/stdout directly for MCP protocol
7
7
  * without any CLI formatting output that would corrupt the protocol.
8
+ *
9
+ * Includes pre-flight npx cache repair to prevent ENOTEMPTY errors
10
+ * in remote/CI environments (known npm 10.x bug).
8
11
  */
9
12
 
13
+ // Pre-flight: repair stale npx cache to prevent ENOTEMPTY on next run
14
+ import { existsSync, readdirSync, rmSync, statSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+ import { homedir } from 'node:os';
17
+
18
+ try {
19
+ const npxRoot = join(homedir(), '.npm', '_npx');
20
+ if (existsSync(npxRoot)) {
21
+ for (const dir of readdirSync(npxRoot)) {
22
+ const nm = join(npxRoot, dir, 'node_modules');
23
+ if (!existsSync(nm)) continue;
24
+ try {
25
+ for (const entry of readdirSync(nm)) {
26
+ if (entry.startsWith('.') && entry.includes('-') && /[A-Za-z]{8}$/.test(entry)) {
27
+ try {
28
+ const p = join(nm, entry);
29
+ if (statSync(p).isDirectory()) rmSync(p, { recursive: true, force: true });
30
+ } catch {}
31
+ }
32
+ }
33
+ } catch {}
34
+ }
35
+ }
36
+ } catch {}
37
+
10
38
  import { randomUUID } from 'crypto';
11
39
  import { listMCPTools, callMCPTool, hasTool } from '../dist/src/mcp-client.js';
12
40
 
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Preinstall hook: repairs npm/npx cache to prevent ENOTEMPTY and ECOMPROMISED.
4
+ *
5
+ * Handles two common npm bugs in remote/CI/Codespaces environments:
6
+ * - ENOTEMPTY: leftover .package-XxXxXxXx dirs from interrupted atomic renames
7
+ * - ECOMPROMISED: corrupted integrity manifests in _cacache
8
+ *
9
+ * Works on Windows, macOS, and Linux. Uses only Node.js built-ins (CJS).
10
+ * Intentionally uses var/ES5 for maximum Node.js compatibility (14+).
11
+ */
12
+ var fs = require('fs');
13
+ var path = require('path');
14
+ var os = require('os');
15
+
16
+ var npmDir = path.join(os.homedir(), '.npm');
17
+
18
+ // 1. Clean stale rename artifacts from npx cache (fixes ENOTEMPTY)
19
+ try {
20
+ var npxRoot = path.join(npmDir, '_npx');
21
+ if (fs.existsSync(npxRoot)) {
22
+ var dirs = fs.readdirSync(npxRoot);
23
+ for (var i = 0; i < dirs.length; i++) {
24
+ var nm = path.join(npxRoot, dirs[i], 'node_modules');
25
+ if (fs.existsSync(nm) === false) continue;
26
+
27
+ try {
28
+ var entries = fs.readdirSync(nm);
29
+ for (var k = 0; k < entries.length; k++) {
30
+ var entry = entries[k];
31
+ // Stale rename targets: .package-name-XxXxXxXx (dot prefix, dash, 8+ alpha suffix)
32
+ if (entry.charAt(0) === '.' && entry.indexOf('-') > 0 && /[A-Za-z]{8}$/.test(entry)) {
33
+ try {
34
+ var p = path.join(nm, entry);
35
+ var stat = fs.statSync(p);
36
+ if (stat.isDirectory()) {
37
+ fs.rmSync(p, { recursive: true, force: true });
38
+ }
39
+ } catch (e) { /* ignore individual failures */ }
40
+ }
41
+ }
42
+ } catch (e) { /* can't read dir, skip */ }
43
+ }
44
+ }
45
+ } catch (e) { /* non-fatal */ }
46
+
47
+ // 2. Remove corrupted integrity entries from _cacache (fixes ECOMPROMISED)
48
+ // Only removes the index directory which contains integrity manifests.
49
+ // The content-v2 directory (actual cached tarballs) is left intact.
50
+ try {
51
+ var cacheIndex = path.join(npmDir, '_cacache', 'index-v5');
52
+ if (fs.existsSync(cacheIndex)) {
53
+ // Check if the index is readable — if not, it's corrupted
54
+ try {
55
+ fs.readdirSync(cacheIndex);
56
+ } catch (e) {
57
+ if (e.code === 'EACCES' || e.code === 'EPERM') {
58
+ // Permission issue — try to fix
59
+ fs.rmSync(cacheIndex, { recursive: true, force: true });
60
+ }
61
+ }
62
+ }
63
+ } catch (e) { /* non-fatal */ }
64
+
65
+ // 3. Remove stale package-lock.json files from npx cache entries
66
+ try {
67
+ if (fs.existsSync(npxRoot)) {
68
+ var cDirs = fs.readdirSync(npxRoot);
69
+ for (var j = 0; j < cDirs.length; j++) {
70
+ var lockFile = path.join(npxRoot, cDirs[j], 'package-lock.json');
71
+ try {
72
+ if (fs.existsSync(lockFile)) {
73
+ var lockStat = fs.statSync(lockFile);
74
+ // Remove lock files older than 1 hour (likely stale)
75
+ var ageMs = Date.now() - lockStat.mtimeMs;
76
+ if (ageMs > 3600000) {
77
+ fs.unlinkSync(lockFile);
78
+ }
79
+ }
80
+ } catch (e) { /* ignore */ }
81
+ }
82
+ }
83
+ } catch (e) { /* non-fatal */ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.1.0-alpha.44",
3
+ "version": "3.1.0-alpha.45",
4
4
  "type": "module",
5
5
  "description": "Claude Flow CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",
@@ -75,6 +75,7 @@
75
75
  "test": "vitest run",
76
76
  "test:plugin-store": "npx tsx src/plugins/tests/standalone-test.ts",
77
77
  "test:pattern-store": "npx tsx src/transfer/store/tests/standalone-test.ts",
78
+ "preinstall": "node bin/preinstall.cjs || true",
78
79
  "prepublishOnly": "cp ../../../README.md ./README.md",
79
80
  "release": "npm version prerelease --preid=alpha && npm run publish:all",
80
81
  "publish:all": "./scripts/publish.sh"