@mnemom/mnemom 0.14.0 → 0.14.1

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { pathToFileURL } from "node:url";
3
2
  import { program } from "commander";
3
+ import { isEntrypoint } from "./lib/entrypoint.js";
4
4
  import { CLI_VERSION } from "./version.js";
5
5
  import { statusCommand } from "./commands/status.js";
6
6
  import { integrityCommand } from "./commands/integrity.js";
@@ -1326,8 +1326,8 @@ program
1326
1326
  // statically introspect the command surface WITHOUT executing the CLI.
1327
1327
  export { program };
1328
1328
  // Parse argv only when invoked as the CLI entrypoint — not when imported.
1329
- // (ESM has no `require.main`; compare this module's URL to argv[1].)
1330
- const invokedDirectly = process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href;
1331
- if (invokedDirectly) {
1329
+ // The symlink-safe guard lives in ./lib/entrypoint so it can be unit-tested
1330
+ // without executing this module's top-level parse().
1331
+ if (isEntrypoint(import.meta.url, process.argv[1])) {
1332
1332
  program.parse();
1333
1333
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Decide whether the current module is being run as the CLI entrypoint
3
+ * (so it should `program.parse()`) rather than merely imported.
4
+ *
5
+ * ESM has no `require.main`, so we compare this module's URL to argv[1].
6
+ * The catch: npm installs the global bin as a SYMLINK
7
+ * (…/bin/mnemom → …/dist/index.js). When invoked through that symlink Node
8
+ * sets `process.argv[1]` to the symlink path while `import.meta.url` is the
9
+ * real resolved file — so a naive comparison never matches and the CLI
10
+ * silently no-ops. Canonicalize argv[1] with `realpathSync` before comparing
11
+ * so the symlinked global bin and the real path both resolve to the same URL.
12
+ *
13
+ * `realpathSync` is wrapped in try/catch because argv[1] may be missing or
14
+ * point at a path that no longer exists (ENOENT); in that case we return
15
+ * `false` to preserve the safe default of not auto-running.
16
+ */
17
+ export declare function isEntrypoint(moduleUrl: string, argv1: string | undefined): boolean;
@@ -0,0 +1,28 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
+ /**
4
+ * Decide whether the current module is being run as the CLI entrypoint
5
+ * (so it should `program.parse()`) rather than merely imported.
6
+ *
7
+ * ESM has no `require.main`, so we compare this module's URL to argv[1].
8
+ * The catch: npm installs the global bin as a SYMLINK
9
+ * (…/bin/mnemom → …/dist/index.js). When invoked through that symlink Node
10
+ * sets `process.argv[1]` to the symlink path while `import.meta.url` is the
11
+ * real resolved file — so a naive comparison never matches and the CLI
12
+ * silently no-ops. Canonicalize argv[1] with `realpathSync` before comparing
13
+ * so the symlinked global bin and the real path both resolve to the same URL.
14
+ *
15
+ * `realpathSync` is wrapped in try/catch because argv[1] may be missing or
16
+ * point at a path that no longer exists (ENOENT); in that case we return
17
+ * `false` to preserve the safe default of not auto-running.
18
+ */
19
+ export function isEntrypoint(moduleUrl, argv1) {
20
+ if (argv1 === undefined)
21
+ return false;
22
+ try {
23
+ return pathToFileURL(realpathSync(argv1)).href === moduleUrl;
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
@@ -2,6 +2,9 @@
2
2
  // smoltbot is deprecated — this shim prints a warning then hands off to mnemom
3
3
  process.stderr.write("\n⚠️ The smoltbot command is deprecated. Use mnemom instead.\n" +
4
4
  " Install: npm install -g @mnemom/mnemom\n\n");
5
- // Dynamic import runs index.ts which calls program.parse(process.argv) automatically
6
- await import("./index.js");
5
+ // argv[1] here is the smoltbot bin path, so index.js's entrypoint guard never
6
+ // fires (it resolves to dist/index.js, not this shim). Import the assembled
7
+ // program and call parse() explicitly instead of relying on its auto-parse.
8
+ const { program } = await import("./index.js");
9
+ program.parse(process.argv);
7
10
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnemom/mnemom",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Transparent AI agent tracing",
5
5
  "type": "module",
6
6
  "bin": {