@trops/dash-core 0.1.718 → 0.1.719

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.
@@ -491,6 +491,7 @@ var scanWidgetPackagePermissions_1 = {
491
491
  mergePermissions,
492
492
  applyScanToPackageJson,
493
493
  backfillPackagePermissions,
494
+ toolListAllows,
494
495
  };
495
496
 
496
497
  var scanWidgetPackagePermissions$1 = /*@__PURE__*/getDefaultExportFromCjs(scanWidgetPackagePermissions_1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trops/dash-core",
3
- "version": "0.1.718",
3
+ "version": "0.1.719",
4
4
  "description": "Core framework for Dash dashboard applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -2,14 +2,18 @@
2
2
  /**
3
3
  * scanWidgetManifestCli.js
4
4
  *
5
- * CLI shim around electron/utils/manifestScanner.js. Run from a widget
6
- * package root to compare detected MCP usage against the package's
7
- * `dash.permissions.mcp` block.
5
+ * CLI shim around the widget permission scanner
6
+ * (electron/utils/scanWidgetPackagePermissions.js, shipped as
7
+ * dist/scanner). Run from a widget package root to compare the MCP tools
8
+ * its widgets call against the package's `dash.permissions.mcp` block.
9
+ * It's the same scanner the publish and install flows use, so templated
10
+ * tool names (`algolia_search_${index}`) show up as wildcards
11
+ * (`algolia_search_*`).
8
12
  *
9
13
  * Usage:
10
14
  * npx dash-scan-manifest # scan ./, print diff (default --check)
11
15
  * npx dash-scan-manifest <dir> # scan <dir>
12
- * npx dash-scan-manifest --init # write missing manifest into package.json
16
+ * npx dash-scan-manifest --init # add the scanned tools to package.json
13
17
  * npx dash-scan-manifest --json # machine-readable output
14
18
  *
15
19
  * Exit codes:
@@ -22,21 +26,24 @@
22
26
  const fs = require("fs");
23
27
  const path = require("path");
24
28
 
25
- // Find the scanner in either the repo layout (electron/) or the
26
- // published package layout (dist/electron/). Whichever exists wins.
29
+ // The published package ships the built scanner (dist/scanner); a repo
30
+ // checkout without a build falls back to the source.
27
31
  const scannerPath = (() => {
28
- const distPath = path.join(
32
+ const distPath = path.join(__dirname, "..", "dist", "scanner", "index.js");
33
+ if (fs.existsSync(distPath)) return distPath;
34
+ return path.join(
29
35
  __dirname,
30
36
  "..",
31
- "dist",
32
37
  "electron",
33
38
  "utils",
34
- "manifestScanner.js",
39
+ "scanWidgetPackagePermissions.js",
35
40
  );
36
- if (fs.existsSync(distPath)) return distPath;
37
- return path.join(__dirname, "..", "electron", "utils", "manifestScanner.js");
38
41
  })();
39
- const { scanForMcpUsage } = require(scannerPath);
42
+ const {
43
+ scanWidgetPackagePermissions,
44
+ applyScanToPackageJson,
45
+ toolListAllows,
46
+ } = require(scannerPath);
40
47
 
41
48
  function parseArgs(argv) {
42
49
  const args = { dir: null, mode: "check", json: false };
@@ -71,34 +78,20 @@ function getDeclaredManifest(pkg) {
71
78
  }
72
79
 
73
80
  function diff(detected, declared) {
74
- // detected: { servers: { [name]: { tools[] } } }
75
- // declared: { [name]: { tools[], readPaths[], writePaths[] } } | null
76
- const missing = {}; // detected but not declared
77
- const declaredServers = (declared && declared) || {};
78
- for (const [name, entry] of Object.entries(detected.servers)) {
79
- const declTools = declaredServers[name]?.tools || [];
80
- const missingTools = entry.tools.filter((t) => !declTools.includes(t));
81
- if (!declaredServers[name] || missingTools.length > 0) {
82
- missing[name] = {
83
- tools: missingTools.length > 0 ? missingTools : entry.tools,
84
- };
85
- }
81
+ // detected: { [server]: { tools[] } }
82
+ // declared: { [server]: { tools[], readPaths[], writePaths[] } } | null
83
+ // A declared wildcard covers the tools (and narrower wildcards) it matches.
84
+ const missing = {};
85
+ for (const [name, entry] of Object.entries(detected)) {
86
+ const declTools = declared?.[name]?.tools || [];
87
+ const missingTools = entry.tools.filter(
88
+ (t) => !toolListAllows(declTools, t),
89
+ );
90
+ if (missingTools.length > 0) missing[name] = { tools: missingTools };
86
91
  }
87
92
  return { missing };
88
93
  }
89
94
 
90
- function buildSyntheticManifest(detected) {
91
- const out = {};
92
- for (const [name, entry] of Object.entries(detected.servers)) {
93
- out[name] = {
94
- tools: entry.tools,
95
- readPaths: [],
96
- writePaths: [],
97
- };
98
- }
99
- return out;
100
- }
101
-
102
95
  function main() {
103
96
  const args = parseArgs(process.argv.slice(2));
104
97
  const dir = path.resolve(args.dir);
@@ -108,8 +101,8 @@ function main() {
108
101
  process.exit(2);
109
102
  }
110
103
 
111
- const detected = scanForMcpUsage({ dir });
112
- const { path: pkgPath, pkg } = readPackageJson(dir);
104
+ const detected = scanWidgetPackagePermissions(dir);
105
+ const { pkg } = readPackageJson(dir);
113
106
  const declared = getDeclaredManifest(pkg);
114
107
  const d = diff(detected, declared);
115
108
 
@@ -118,10 +111,9 @@ function main() {
118
111
  JSON.stringify(
119
112
  {
120
113
  dir,
121
- detected: detected.servers,
114
+ detected,
122
115
  declared: declared || null,
123
116
  missing: d.missing,
124
- warnings: detected.warnings,
125
117
  },
126
118
  null,
127
119
  2,
@@ -137,42 +129,29 @@ function main() {
137
129
  );
138
130
  process.exit(2);
139
131
  }
140
- if (declared) {
141
- console.error(
142
- `package.json already declares dash.permissions.mcp. --init refuses to overwrite. Use --check to see the diff.`,
132
+ // Additive: hand-written entries (and their paths) are kept.
133
+ const merged = applyScanToPackageJson(dir);
134
+ if (!merged) {
135
+ console.log("No MCP usage detected — package.json left unchanged.");
136
+ } else {
137
+ console.log(
138
+ `Updated dash.permissions in ${path.join(dir, "package.json")}.`,
139
+ );
140
+ console.log(
141
+ "Review the readPaths and writePaths arrays — the scanner cannot infer paths.",
143
142
  );
144
- process.exit(2);
145
143
  }
146
- pkg.dash = pkg.dash || {};
147
- pkg.dash.permissions = pkg.dash.permissions || {};
148
- pkg.dash.permissions.mcp = buildSyntheticManifest(detected);
149
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
150
- console.log(`Wrote starter manifest to ${pkgPath}.`);
151
- console.log(
152
- "Review the readPaths and writePaths arrays — the scanner cannot infer paths.",
153
- );
154
144
  process.exit(0);
155
145
  }
156
146
 
157
147
  // --check (default)
158
148
  console.log(`Scanned: ${dir}`);
159
- if (Object.keys(detected.servers).length === 0) {
160
- console.log("No literal MCP usage detected.");
149
+ if (Object.keys(detected).length === 0) {
150
+ console.log("No MCP usage detected.");
161
151
  } else {
162
152
  console.log("\nDetected MCP usage:");
163
- for (const [name, entry] of Object.entries(detected.servers)) {
164
- console.log(
165
- ` ${name}: ${entry.tools.join(", ") || "(no literal tools)"}`,
166
- );
167
- }
168
- }
169
-
170
- if (detected.warnings.length > 0) {
171
- console.log(
172
- `\n${detected.warnings.length} dynamic call(s) — scanner could not analyze:`,
173
- );
174
- for (const w of detected.warnings) {
175
- console.log(` ${w.file}:${w.line} [${w.kind}] ${w.snippet}`);
153
+ for (const [name, entry] of Object.entries(detected)) {
154
+ console.log(` ${name}: ${entry.tools.join(", ")}`);
176
155
  }
177
156
  }
178
157
 
@@ -190,9 +169,7 @@ function main() {
190
169
  for (const [name, entry] of Object.entries(d.missing)) {
191
170
  console.log(` ${name}: ${entry.tools.join(", ")}`);
192
171
  }
193
- console.log(
194
- "\nRun `dash-scan-manifest --init` to write a starter manifest.",
195
- );
172
+ console.log("\nRun `dash-scan-manifest --init` to add them.");
196
173
  process.exit(1);
197
174
  }
198
175
  console.log("\nManifest looks complete.");