nsauditor-ai 0.1.20 → 0.1.21

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 (2) hide show
  1. package/package.json +1 -1
  2. package/utils/validate.mjs +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nsauditor-ai",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Modular AI-assisted network security audit platform — Community Edition",
5
5
  "type": "module",
6
6
  "private": false,
@@ -20,8 +20,15 @@
20
20
  import fsp from 'node:fs/promises';
21
21
  import path from 'node:path';
22
22
  import dnsP from 'node:dns/promises';
23
+ import { fileURLToPath } from 'node:url';
23
24
  import { resolveBaseOutDir } from './output_dir.mjs';
24
25
 
26
+ // Package root — derived from THIS file's location (utils/validate.mjs) by
27
+ // going up one directory. Used as the default plugin-discovery base so that
28
+ // `nsauditor-ai validate` finds the plugins shipped with the package, NOT
29
+ // whatever happens to be in the user's cwd. Fixed in v0.1.21 (Task N.25).
30
+ const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
31
+
25
32
  export const STATUSES = Object.freeze({
26
33
  OK: 'ok',
27
34
  WARN: 'warn',
@@ -36,26 +43,32 @@ const DEFAULT_NETWORK_HOST = 'localhost'; // hermetic — no external dependency
36
43
  /**
37
44
  * Verify all installed plugins load without error.
38
45
  *
46
+ * Discovery base is the **package root** (derived from this file's location),
47
+ * not `process.cwd()`. Critical: when the bin shim is invoked from anywhere
48
+ * other than the install dir, `process.cwd()` is the user's working
49
+ * directory — which has no plugins. v0.1.20 had this bug; fixed in v0.1.21.
50
+ *
39
51
  * @param {object} [opts]
40
52
  * @param {Function} [opts.discover] - Override for testing.
53
+ * @param {string} [opts.pkgRoot] - Override package root path (test injection).
41
54
  */
42
- export async function checkPlugins({ discover } = {}) {
55
+ export async function checkPlugins({ discover, pkgRoot = PKG_ROOT } = {}) {
43
56
  try {
44
57
  const fn = discover || (await import('./plugin_discovery.mjs')).discoverPlugins;
45
- const result = await fn(process.cwd());
58
+ const result = await fn(pkgRoot);
46
59
  const plugins = Array.isArray(result) ? result : (result?.plugins ?? []);
47
60
  return {
48
61
  name: 'plugins',
49
62
  status: STATUSES.OK,
50
63
  message: `${plugins.length} plugin${plugins.length === 1 ? '' : 's'} loaded`,
51
- details: { count: plugins.length },
64
+ details: { count: plugins.length, basePath: pkgRoot },
52
65
  };
53
66
  } catch (err) {
54
67
  return {
55
68
  name: 'plugins',
56
69
  status: STATUSES.ERROR,
57
70
  message: `Plugin discovery failed: ${err.message}`,
58
- details: { error: err.message },
71
+ details: { error: err.message, basePath: pkgRoot },
59
72
  };
60
73
  }
61
74
  }
@@ -276,4 +289,5 @@ export const _internals = {
276
289
  FREE_SPACE_WARN_MB,
277
290
  DEFAULT_NETWORK_TIMEOUT_MS,
278
291
  DEFAULT_NETWORK_HOST,
292
+ PKG_ROOT,
279
293
  };