@trops/dash-core 0.1.923 → 0.1.924

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.
@@ -4749,7 +4749,7 @@ function readDataDirectoryFromSettings() {
4749
4749
  * @returns {string} validated absolute real-path
4750
4750
  * @throws if requested is not contained within any allowed root
4751
4751
  */
4752
- function safePath$4(requested, allowedRoots) {
4752
+ function safePath$3(requested, allowedRoots) {
4753
4753
  if (typeof requested !== "string" || !requested) {
4754
4754
  throw new Error("safePath: requested must be a non-empty string");
4755
4755
  }
@@ -4803,9 +4803,87 @@ function safePath$4(requested, allowedRoots) {
4803
4803
  );
4804
4804
  }
4805
4805
 
4806
+ /**
4807
+ * A path the way a server reads it, for comparing: forward slashes, no
4808
+ * "./" or doubled slashes, no leading or trailing slash. Never resolved
4809
+ * against this machine's disk.
4810
+ */
4811
+ function serverPathOf(p) {
4812
+ return path$v.posix
4813
+ .normalize(String(p).replace(/\\/g, "/"))
4814
+ .replace(/^\/+/, "")
4815
+ .replace(/\/+$/, "")
4816
+ .replace(/^\.$/, "");
4817
+ }
4818
+
4819
+ /**
4820
+ * Is `requested` inside one of `roots`, as paths on an MCP server (a notes
4821
+ * vault, a remote drive) rather than files on this computer? Both sides are
4822
+ * normalized the same way; anything that climbs out with ".." is refused.
4823
+ * A root may be a folder or a single file.
4824
+ */
4825
+ function withinServerRoots(requested, roots) {
4826
+ if (typeof requested !== "string" || !requested) return false;
4827
+ const req = serverPathOf(requested);
4828
+ if (req === ".." || req.startsWith("../")) return false;
4829
+ return (roots || []).some((root) => {
4830
+ const r = serverPathOf(root);
4831
+ return r === "" || req === r || req.startsWith(r + "/");
4832
+ });
4833
+ }
4834
+
4835
+ /** A root that names a real folder or file on this computer. */
4836
+ function isLocalRoot(root) {
4837
+ if (typeof root !== "string" || !path$v.isAbsolute(root)) return false;
4838
+ try {
4839
+ return fs$s.existsSync(root);
4840
+ } catch (_e) {
4841
+ return false;
4842
+ }
4843
+ }
4844
+
4845
+ /**
4846
+ * The check for a path argument to an MCP tool. Roots that are real
4847
+ * places on this computer (a filesystem provider's folders) keep
4848
+ * safePath's check, symlinks and all; every other root — relative, or a
4849
+ * path that only means something on the server, like "Life/Modules" — is
4850
+ * compared as a server path. The tool still gets the argument unchanged.
4851
+ *
4852
+ * @returns {{ ok: true } | { ok: false, reason: string }}
4853
+ */
4854
+ function checkToolPath$1(requested, roots) {
4855
+ const list = Array.isArray(roots) ? roots.filter(Boolean) : [];
4856
+ const local = list.filter(isLocalRoot);
4857
+ const server = list.filter((r) => !isLocalRoot(r));
4858
+ if (local.length) {
4859
+ try {
4860
+ safePath$3(requested, local);
4861
+ return { ok: true };
4862
+ } catch (_e) {
4863
+ // Not inside a local root: it may still be inside a server root.
4864
+ }
4865
+ }
4866
+ if (server.length && withinServerRoots(requested, server)) {
4867
+ return { ok: true };
4868
+ }
4869
+ return {
4870
+ ok: false,
4871
+ reason:
4872
+ "requested path is not within any allowed root. Requested: " +
4873
+ requested +
4874
+ " (as a server path: " +
4875
+ (serverPathOf(requested) || "/") +
4876
+ "). Allowed roots: " +
4877
+ list.map((r) => `${r} (${serverPathOf(r) || "/"})`).join(", "),
4878
+ };
4879
+ }
4880
+
4806
4881
  var safePath_1 = {
4807
- safePath: safePath$4,
4882
+ safePath: safePath$3,
4808
4883
  getAllowedRoots: getAllowedRoots$2,
4884
+ serverPathOf,
4885
+ withinServerRoots,
4886
+ checkToolPath: checkToolPath$1,
4809
4887
  };
4810
4888
 
4811
4889
  /**
@@ -14798,7 +14876,7 @@ var manifestScanner = {
14798
14876
 
14799
14877
  const fs$l = require$$0$3;
14800
14878
  const path$o = require$$1$1;
14801
- const { safePath: safePath$3 } = safePath_1;
14879
+ const { safePath: safePath$2 } = safePath_1;
14802
14880
 
14803
14881
  const NAME_RE = /^@?[a-z0-9][a-z0-9.-]*(\/[a-z0-9][a-z0-9.-]*)?$/i;
14804
14882
  const SEMVER_RE$1 = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/;
@@ -14903,7 +14981,7 @@ function loadWidgetManifest(folderPath) {
14903
14981
  // resolve-and-prefix check.
14904
14982
  const candidate = path$o.join(folderPath, entry);
14905
14983
  if (fs$l.existsSync(candidate)) {
14906
- safePath$3(candidate, [folderPath]);
14984
+ safePath$2(candidate, [folderPath]);
14907
14985
  } else {
14908
14986
  const resolved = path$o.resolve(candidate);
14909
14987
  const rootResolved = path$o.resolve(folderPath);
@@ -14983,7 +15061,7 @@ function walkSourceContainment(rootPath) {
14983
15061
  const stack = [rootPath];
14984
15062
  while (stack.length > 0) {
14985
15063
  const current = stack.pop();
14986
- safePath$3(current, [rootPath]);
15064
+ safePath$2(current, [rootPath]);
14987
15065
 
14988
15066
  const stat = fs$l.lstatSync(current);
14989
15067
  if (stat.isDirectory()) {
@@ -22749,7 +22827,7 @@ var fs$k = require$$0$3;
22749
22827
  const path$n = require$$1$1;
22750
22828
  const events$5 = events$8;
22751
22829
  const { getFileContents: getFileContents$5, writeToFile: writeToFile$1 } = file$1;
22752
- const { safePath: safePath$2, getAllowedRoots: getAllowedRoots$1 } = safePath_1;
22830
+ const { safePath: safePath$1, getAllowedRoots: getAllowedRoots$1 } = safePath_1;
22753
22831
  const { gateFsCall, gateFsCallWithJit } = fsGate;
22754
22832
  const {
22755
22833
  gateNetworkCall: gateNetworkCall$1,
@@ -22859,7 +22937,7 @@ const dataController$1 = {
22859
22937
  );
22860
22938
  let filename;
22861
22939
  try {
22862
- filename = safePath$2(candidate, getAllowedRoots$1("data"));
22940
+ filename = safePath$1(candidate, getAllowedRoots$1("data"));
22863
22941
  } catch (pathErr) {
22864
22942
  win.webContents.send(events$5.DATA_JSON_TO_CSV_FILE_ERROR, {
22865
22943
  error: pathErr.message,
@@ -22925,7 +23003,7 @@ const dataController$1 = {
22925
23003
  try {
22926
23004
  let validated;
22927
23005
  try {
22928
- validated = safePath$2(filepath, getAllowedRoots$1("data"));
23006
+ validated = safePath$1(filepath, getAllowedRoots$1("data"));
22929
23007
  } catch (pathErr) {
22930
23008
  win.webContents.send(events$5.READ_LINES_ERROR, {
22931
23009
  error: pathErr.message,
@@ -22959,7 +23037,7 @@ const dataController$1 = {
22959
23037
  try {
22960
23038
  let validated;
22961
23039
  try {
22962
- validated = safePath$2(filepath, getAllowedRoots$1("data"));
23040
+ validated = safePath$1(filepath, getAllowedRoots$1("data"));
22963
23041
  } catch (pathErr) {
22964
23042
  win.webContents.send(events$5.READ_JSON_ERROR, {
22965
23043
  error: pathErr.message,
@@ -23025,7 +23103,7 @@ const dataController$1 = {
23025
23103
  // Validate toFilepath is within the app data directory.
23026
23104
  // safePath replaces the previous inline check; same containment
23027
23105
  // intent, plus realpath/symlink protection.
23028
- const resolvedFilepath = safePath$2(toFilepath, getAllowedRoots$1("data"));
23106
+ const resolvedFilepath = safePath$1(toFilepath, getAllowedRoots$1("data"));
23029
23107
 
23030
23108
  const writeStream = fs$k.createWriteStream(resolvedFilepath);
23031
23109
 
@@ -23075,8 +23153,8 @@ const dataController$1 = {
23075
23153
  let validatedIn, validatedOut;
23076
23154
  try {
23077
23155
  const roots = getAllowedRoots$1("data");
23078
- validatedIn = safePath$2(filepath, roots);
23079
- validatedOut = safePath$2(outpath, roots);
23156
+ validatedIn = safePath$1(filepath, roots);
23157
+ validatedOut = safePath$1(outpath, roots);
23080
23158
  } catch (pathErr) {
23081
23159
  win.webContents.send(events$5.PARSE_XML_STREAM_ERROR, {
23082
23160
  error: pathErr.message,
@@ -23135,8 +23213,8 @@ const dataController$1 = {
23135
23213
  let validatedIn, validatedOut;
23136
23214
  try {
23137
23215
  const roots = getAllowedRoots$1("data");
23138
- validatedIn = safePath$2(filepath, roots);
23139
- validatedOut = safePath$2(outpath, roots);
23216
+ validatedIn = safePath$1(filepath, roots);
23217
+ validatedOut = safePath$1(outpath, roots);
23140
23218
  } catch (pathErr) {
23141
23219
  win.webContents.send(events$5.PARSE_CSV_STREAM_ERROR, {
23142
23220
  error: pathErr.message,
@@ -23219,7 +23297,7 @@ const dataController$1 = {
23219
23297
  );
23220
23298
  let toFilename;
23221
23299
  try {
23222
- toFilename = safePath$2(candidate, getAllowedRoots$1("data"));
23300
+ toFilename = safePath$1(candidate, getAllowedRoots$1("data"));
23223
23301
  } catch (pathErr) {
23224
23302
  win.webContents.send(events$5.DATA_SAVE_TO_FILE_ERROR, {
23225
23303
  success: false,
@@ -42026,7 +42104,7 @@ streamableHttp$1.StreamableHTTPClientTransport = StreamableHTTPClientTransport$1
42026
42104
  *
42027
42105
  * 2. **Path-argument containment** — for tools whose arguments
42028
42106
  * include a path-shaped key (`path`, `uri`, `filepath`, `file`,
42029
- * `directory`), the supplied path is validated with safePath()
42107
+ * `directory`), the supplied path is validated with checkToolPath()
42030
42108
  * against the widget's granted `readPaths` or `writePaths` for
42031
42109
  * the target server. The read/write distinction is heuristic
42032
42110
  * based on the tool name (e.g. `write_file` is treated as a
@@ -42040,7 +42118,7 @@ streamableHttp$1.StreamableHTTPClientTransport = StreamableHTTPClientTransport$1
42040
42118
  */
42041
42119
 
42042
42120
  const { getGrant: getGrant$1, setGrant: setGrant$1 } = grantedPermissions;
42043
- const { safePath: safePath$1 } = safePath_1;
42121
+ const { checkToolPath } = safePath_1;
42044
42122
  const { requestApproval } = jitConsent$1;
42045
42123
  const { approvalErrorReason } = approvalErrorReason_1;
42046
42124
  const { lookup: lookupMountToken } = mountTokenRegistry;
@@ -42191,16 +42269,14 @@ function _evaluateGrant({
42191
42269
  "'",
42192
42270
  };
42193
42271
  }
42194
- try {
42195
- safePath$1(v, allowedPaths);
42196
- } catch (e) {
42272
+ // Local folders get the on-disk check; a server's own paths
42273
+ // (a notes vault) are compared as server paths. The argument itself
42274
+ // goes to the tool unchanged.
42275
+ const checked = checkToolPath(v, allowedPaths);
42276
+ if (!checked.ok) {
42197
42277
  return {
42198
42278
  allow: false,
42199
- reason:
42200
- "path argument '" +
42201
- key +
42202
- "' rejected: " +
42203
- (e && e.message ? e.message : String(e)),
42279
+ reason: "path argument '" + key + "' rejected: " + checked.reason,
42204
42280
  };
42205
42281
  }
42206
42282
  }
@@ -69603,100 +69679,91 @@ var toolDefinitions$1 = {
69603
69679
  * Pure (NFR-006): no Electron.
69604
69680
  */
69605
69681
 
69606
- var activeLayout;
69607
- var hasRequiredActiveLayout;
69608
-
69609
- function requireActiveLayout () {
69610
- if (hasRequiredActiveLayout) return activeLayout;
69611
- hasRequiredActiveLayout = 1;
69612
-
69613
- /** The page the dashboard shows, or null for a dashboard without pages. */
69614
- function shownPage(ws) {
69615
- if (!ws || !Array.isArray(ws.pages) || !ws.pages.length) return null;
69616
- return ws.pages.find((p) => p && p.id === ws.activePageId) || ws.pages[0];
69617
- }
69618
-
69619
- /**
69620
- * Resolve a page by id or name (case-insensitive); none asked → the shown
69621
- * page. @returns {{ page: object|null, error?: string }}
69622
- */
69623
- function resolvePage(ws, page) {
69624
- const hasPages = ws && Array.isArray(ws.pages) && ws.pages.length > 0;
69625
- if (page === undefined || page === null || page === "") {
69626
- return { page: shownPage(ws) };
69627
- }
69628
- if (!hasPages) {
69629
- return { page: null, error: "This dashboard has no pages." };
69630
- }
69631
- const want = String(page).trim().toLowerCase();
69632
- const hit =
69633
- ws.pages.find((p) => p && String(p.id).toLowerCase() === want) ||
69634
- ws.pages.find(
69635
- (p) =>
69636
- p &&
69637
- String(p.name || "")
69638
- .trim()
69639
- .toLowerCase() === want,
69640
- );
69641
- if (!hit) {
69642
- return {
69643
- page: null,
69644
- error: `No page "${page}". Pages: ${ws.pages
69645
- .map((p) => p && p.name)
69646
- .filter(Boolean)
69647
- .join(", ")}.`,
69648
- };
69649
- }
69650
- return { page: hit };
69651
- }
69682
+ /** The page the dashboard shows, or null for a dashboard without pages. */
69683
+ function shownPage$2(ws) {
69684
+ if (!ws || !Array.isArray(ws.pages) || !ws.pages.length) return null;
69685
+ return ws.pages.find((p) => p && p.id === ws.activePageId) || ws.pages[0];
69686
+ }
69652
69687
 
69653
- /**
69654
- * The layout a tool works on: the asked-for page's, else the shown page's,
69655
- * else the top-level layout. @returns {{ layout: object[], page: object|null,
69656
- * error?: string }}
69657
- */
69658
- function layoutOf(ws, page) {
69659
- const res = resolvePage(ws, page);
69660
- if (res.error) return { layout: [], page: null, error: res.error };
69661
- if (res.page) {
69662
- return {
69663
- layout: Array.isArray(res.page.layout) ? res.page.layout : [],
69664
- page: res.page,
69665
- };
69666
- }
69667
- return {
69668
- layout: Array.isArray(ws && ws.layout) ? ws.layout : [],
69669
- page: null,
69670
- };
69671
- }
69688
+ /**
69689
+ * Resolve a page by id or name (case-insensitive); none asked → the shown
69690
+ * page. @returns {{ page: object|null, error?: string }}
69691
+ */
69692
+ function resolvePage(ws, page) {
69693
+ const hasPages = ws && Array.isArray(ws.pages) && ws.pages.length > 0;
69694
+ if (page === undefined || page === null || page === "") {
69695
+ return { page: shownPage$2(ws) };
69696
+ }
69697
+ if (!hasPages) {
69698
+ return { page: null, error: "This dashboard has no pages." };
69699
+ }
69700
+ const want = String(page).trim().toLowerCase();
69701
+ const hit =
69702
+ ws.pages.find((p) => p && String(p.id).toLowerCase() === want) ||
69703
+ ws.pages.find(
69704
+ (p) =>
69705
+ p &&
69706
+ String(p.name || "")
69707
+ .trim()
69708
+ .toLowerCase() === want,
69709
+ );
69710
+ if (!hit) {
69711
+ return {
69712
+ page: null,
69713
+ error: `No page "${page}". Pages: ${ws.pages
69714
+ .map((p) => p && p.name)
69715
+ .filter(Boolean)
69716
+ .join(", ")}.`,
69717
+ };
69718
+ }
69719
+ return { page: hit };
69720
+ }
69672
69721
 
69673
- /**
69674
- * Put a changed layout back where it came from (mutates `ws`): into its page,
69675
- * and into the top-level mirror when that page is the one shown (or the
69676
- * dashboard has no pages).
69677
- */
69678
- function withLayout(ws, layout, page) {
69679
- if (page) {
69680
- page.layout = layout;
69681
- if (page === shownPage(ws)) ws.layout = JSON.parse(JSON.stringify(layout));
69682
- } else {
69683
- ws.layout = layout;
69684
- }
69685
- return ws;
69686
- }
69722
+ /**
69723
+ * The layout a tool works on: the asked-for page's, else the shown page's,
69724
+ * else the top-level layout. @returns {{ layout: object[], page: object|null,
69725
+ * error?: string }}
69726
+ */
69727
+ function layoutOf$2(ws, page) {
69728
+ const res = resolvePage(ws, page);
69729
+ if (res.error) return { layout: [], page: null, error: res.error };
69730
+ if (res.page) {
69731
+ return {
69732
+ layout: Array.isArray(res.page.layout) ? res.page.layout : [],
69733
+ page: res.page,
69734
+ };
69735
+ }
69736
+ return {
69737
+ layout: Array.isArray(ws && ws.layout) ? ws.layout : [],
69738
+ page: null,
69739
+ };
69740
+ }
69687
69741
 
69688
- /** Every layout the dashboard holds (each page's, or the top-level one). */
69689
- function allLayouts(ws) {
69690
- if (ws && Array.isArray(ws.pages) && ws.pages.length) {
69691
- return ws.pages.map((p) => (p && Array.isArray(p.layout) ? p.layout : []));
69692
- }
69693
- return [Array.isArray(ws && ws.layout) ? ws.layout : []];
69694
- }
69742
+ /**
69743
+ * Put a changed layout back where it came from (mutates `ws`): into its page,
69744
+ * and into the top-level mirror when that page is the one shown (or the
69745
+ * dashboard has no pages).
69746
+ */
69747
+ function withLayout$2(ws, layout, page) {
69748
+ if (page) {
69749
+ page.layout = layout;
69750
+ if (page === shownPage$2(ws)) ws.layout = JSON.parse(JSON.stringify(layout));
69751
+ } else {
69752
+ ws.layout = layout;
69753
+ }
69754
+ return ws;
69755
+ }
69695
69756
 
69696
- activeLayout = { shownPage, resolvePage, layoutOf, withLayout, allLayouts };
69697
- return activeLayout;
69757
+ /** Every layout the dashboard holds (each page's, or the top-level one). */
69758
+ function allLayouts$1(ws) {
69759
+ if (ws && Array.isArray(ws.pages) && ws.pages.length) {
69760
+ return ws.pages.map((p) => (p && Array.isArray(p.layout) ? p.layout : []));
69761
+ }
69762
+ return [Array.isArray(ws && ws.layout) ? ws.layout : []];
69698
69763
  }
69699
69764
 
69765
+ var activeLayout = { shownPage: shownPage$2, resolvePage, layoutOf: layoutOf$2, withLayout: withLayout$2, allLayouts: allLayouts$1 };
69766
+
69700
69767
  /**
69701
69768
  * themeFromUrlErrors.js
69702
69769
  *
@@ -71676,7 +71743,7 @@ const {
71676
71743
  withLayout: withLayout$1,
71677
71744
  allLayouts,
71678
71745
  shownPage: shownPage$1,
71679
- } = requireActiveLayout();
71746
+ } = activeLayout;
71680
71747
 
71681
71748
  /** An MCP error result with a plain message. */
71682
71749
  function errorResult(message) {
@@ -87547,7 +87614,7 @@ var botRegistryInstall = { downloadBotPackage: downloadBotPackage$1 };
87547
87614
  * the one asked for) and the mirror is kept in step (activeLayout.js).
87548
87615
  */
87549
87616
 
87550
- const { layoutOf, withLayout, shownPage } = requireActiveLayout();
87617
+ const { layoutOf, withLayout, shownPage } = activeLayout;
87551
87618
 
87552
87619
  function clone$1(v) {
87553
87620
  return JSON.parse(JSON.stringify(v));
@@ -112808,7 +112875,7 @@ const botController$1 = {
112808
112875
  }
112809
112876
  const saved = this._saveWorkspace(placed.workspace);
112810
112877
  if (saved.error) return saved;
112811
- const { layoutOf } = requireActiveLayout();
112878
+ const { layoutOf } = activeLayout;
112812
112879
  const target = layoutOf(placed.workspace, page || undefined);
112813
112880
  return {
112814
112881
  component: resolved.component,