@cleocode/cleo 2026.3.48 → 2026.3.50

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.
@@ -2,57 +2,61 @@
2
2
  /**
3
3
  * NPM Postinstall Hook - Bootstrap Global CLEO System
4
4
  *
5
- * This script runs automatically after `npm install -g @cleocode/cleo`.
6
- * It delegates to the shared bootstrap module in @cleocode/core so that
7
- * both postinstall and `cleo install-global` use the same logic.
5
+ * Runs automatically after `npm install -g @cleocode/cleo`.
6
+ * Delegates to @cleocode/core's bootstrapGlobalCleo().
8
7
  *
9
- * Bootstraps:
10
- * - ~/.cleo/ directory structure
11
- * - Global templates (CLEO-INJECTION.md)
12
- * - CAAMP provider configs
13
- * - MCP server to detected providers
14
- * - Core skills globally
15
- * - Provider adapters
8
+ * Detection: runs bootstrap when installed in a global node_modules path.
9
+ * Skips for workspace/dev installs (no global prefix in path).
16
10
  *
17
11
  * @task T5267
18
12
  */
19
13
 
20
- import { dirname, resolve } from 'node:path';
14
+ import { existsSync } from 'node:fs';
15
+ import { dirname, join, resolve } from 'node:path';
21
16
  import { fileURLToPath } from 'node:url';
22
17
 
23
18
  const __filename = fileURLToPath(import.meta.url);
24
19
  const __dirname = dirname(__filename);
25
20
 
26
- // Determine if we're running from npm global install
27
- function isNpmGlobalInstall() {
28
- const execPath = process.argv[1] || '';
29
- // Check if running from node_modules/@cleocode/cleo/
30
- return (
31
- execPath.includes('node_modules/@cleocode/cleo/') ||
32
- execPath.includes('node_modules\\@cleocode\\cleo\\')
33
- );
21
+ /**
22
+ * Detect if this is a global npm install (not a workspace/dev install).
23
+ * Checks multiple signals since npm staging paths vary by version.
24
+ */
25
+ function isGlobalInstall() {
26
+ const pkgRoot = resolve(__dirname, '..');
27
+
28
+ // Signal 1: npm_config_global env var (set by npm during global installs)
29
+ if (process.env.npm_config_global === 'true') return true;
30
+
31
+ // Signal 2: path contains a global node_modules (npm, pnpm, yarn)
32
+ if (/[/\\]lib[/\\]node_modules[/\\]/.test(pkgRoot)) return true;
33
+
34
+ // Signal 3: npm_config_prefix matches the package path
35
+ const prefix = process.env.npm_config_prefix;
36
+ if (prefix && pkgRoot.startsWith(prefix)) return true;
37
+
38
+ // Signal 4: not inside a pnpm workspace (no workspace root marker)
39
+ const workspaceMarker = join(pkgRoot, '..', '..', 'pnpm-workspace.yaml');
40
+ if (existsSync(workspaceMarker)) return false;
41
+
42
+ return false;
34
43
  }
35
44
 
36
- // Get package root (bin/ is one level below package root)
37
45
  function getPackageRoot() {
38
46
  return resolve(__dirname, '..');
39
47
  }
40
48
 
41
49
  async function runPostinstall() {
42
- // Only run for npm global installs, not local dev or other contexts
43
- if (!isNpmGlobalInstall()) {
44
- console.log('CLEO: Skipping global bootstrap (not npm global install)');
50
+ if (!isGlobalInstall()) {
51
+ console.log('CLEO: Skipping global bootstrap (not global install)');
45
52
  return;
46
53
  }
47
54
 
48
55
  console.log('CLEO: Bootstrapping global system...');
49
56
 
50
57
  try {
51
- // Import the shared bootstrap from the built core dist.
52
- // At postinstall time, dist/ should already be present in the published package.
53
- const { bootstrapGlobalCleo } = await import(
54
- '../dist/core/bootstrap.js'
55
- );
58
+ // Import bootstrap from @cleocode/core (installed as dependency)
59
+ const { bootstrapGlobalCleo } = await import('@cleocode/core/internal');
56
60
 
57
61
  const result = await bootstrapGlobalCleo({
58
62
  packageRoot: getPackageRoot(),
@@ -68,16 +72,14 @@ async function runPostinstall() {
68
72
  console.log('CLEO: Global bootstrap complete!');
69
73
  console.log('CLEO: Run "cleo init" in any project to set up local CLEO.');
70
74
  } catch (err) {
71
- // Bootstrap is best-effort CAAMP/MCP may not be configured yet
72
- console.log('CLEO: CAAMP/MCP setup deferred (will complete on first use)');
75
+ console.log('CLEO: Bootstrap deferred (will complete on first "cleo install-global")');
73
76
  if (process.env.CLEO_DEBUG) {
74
77
  console.error('CLEO: Bootstrap detail:', err);
75
78
  }
76
79
  }
77
80
  }
78
81
 
79
- // Run bootstrap — never fail npm install
80
82
  runPostinstall().catch((err) => {
81
83
  console.error('CLEO: Bootstrap error (non-fatal):', err.message);
82
- process.exit(0); // Never fail npm install
84
+ process.exit(0);
83
85
  });
package/dist/cli/index.js CHANGED
@@ -64333,7 +64333,14 @@ async function initAgentDefinition(created, warnings) {
64333
64333
  try {
64334
64334
  try {
64335
64335
  const stat3 = await lstat(globalAgentsDir);
64336
- if (stat3.isSymbolicLink() || stat3.isDirectory()) {
64336
+ if (stat3.isSymbolicLink()) {
64337
+ const { readlink } = await import("node:fs/promises");
64338
+ const currentTarget = await readlink(globalAgentsDir);
64339
+ if (currentTarget === agentSourceDir) {
64340
+ return;
64341
+ }
64342
+ await unlink4(globalAgentsDir);
64343
+ } else if (stat3.isDirectory()) {
64337
64344
  return;
64338
64345
  }
64339
64346
  } catch {
@@ -65462,6 +65469,7 @@ __export(src_exports, {
65462
65469
  });
65463
65470
  var init_src2 = __esm({
65464
65471
  "packages/core/src/index.ts"() {
65472
+ "use strict";
65465
65473
  init_src();
65466
65474
  init_adapters();
65467
65475
  init_admin();
@@ -65559,6 +65567,10 @@ async function bootstrapGlobalCleo(options) {
65559
65567
  warnings: [],
65560
65568
  isDryRun: options?.dryRun ?? false
65561
65569
  };
65570
+ try {
65571
+ await ensureGlobalHome();
65572
+ } catch {
65573
+ }
65562
65574
  await ensureGlobalTemplatesBootstrap(ctx, options?.packageRoot);
65563
65575
  await injectAgentsHub(ctx);
65564
65576
  await installMcpToProviders(ctx);
@@ -65614,13 +65626,9 @@ async function injectAgentsHub(ctx) {
65614
65626
  await mkdir17(globalAgentsDir, { recursive: true });
65615
65627
  if (existsSync103(globalAgentsMd)) {
65616
65628
  const content = await readFile19(globalAgentsMd, "utf8");
65617
- const stripped = content.replace(
65618
- /\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
65619
- ""
65620
- );
65621
- if (stripped !== content) {
65622
- await writeFile12(globalAgentsMd, stripped, "utf8");
65623
- }
65629
+ const stripped = content.replace(/\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g, "").replace(/\n?<!-- CAAMP:START -->[\s\S]*?<!-- CAAMP:END -->\n?/g, "").trim();
65630
+ await writeFile12(globalAgentsMd, stripped ? `${stripped}
65631
+ ` : "", "utf8");
65624
65632
  }
65625
65633
  const expectedContent = "@~/.cleo/templates/CLEO-INJECTION.md";
65626
65634
  const action = await inject2(globalAgentsMd, expectedContent);