@luaward/mcp 0.2.3 → 0.2.5

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
@@ -233,7 +233,7 @@ var PotassiumClient = class {
233
233
  params: {
234
234
  protocolVersion: "2025-03-26",
235
235
  capabilities: {},
236
- clientInfo: { name: "@luaward/mcp", version: "0.2.3" }
236
+ clientInfo: { name: "@luaward/mcp", version: "0.2.5" }
237
237
  }
238
238
  })
239
239
  });
@@ -508,6 +508,105 @@ import { homedir as homedir2 } from "node:os";
508
508
  import { join as join2 } from "node:path";
509
509
  import { createInterface } from "node:readline";
510
510
  import { inflateSync } from "node:zlib";
511
+ var LUAU_RESERVED_KEYWORDS = /* @__PURE__ */ new Set([
512
+ "and",
513
+ "break",
514
+ "do",
515
+ "else",
516
+ "elseif",
517
+ "end",
518
+ "false",
519
+ "for",
520
+ "function",
521
+ "if",
522
+ "in",
523
+ "local",
524
+ "nil",
525
+ "not",
526
+ "or",
527
+ "repeat",
528
+ "return",
529
+ "then",
530
+ "true",
531
+ "until",
532
+ "while"
533
+ ]);
534
+ var LUAU_IDENT_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
535
+ function escapeLuauString(str) {
536
+ let out = '"';
537
+ for (let i = 0; i < str.length; i++) {
538
+ const code = str.charCodeAt(i);
539
+ if (code === 34) {
540
+ out += '\\"';
541
+ } else if (code === 92) {
542
+ out += "\\\\";
543
+ } else if (code === 10) {
544
+ out += "\\n";
545
+ } else if (code === 13) {
546
+ out += "\\r";
547
+ } else if (code === 9) {
548
+ out += "\\t";
549
+ } else if (code < 32 || code === 127) {
550
+ out += `\\${String(code).padStart(3, "0")}`;
551
+ } else {
552
+ out += str[i];
553
+ }
554
+ }
555
+ out += '"';
556
+ return out;
557
+ }
558
+ function toLuauLiteral(value) {
559
+ if (value === null || value === void 0) {
560
+ return "nil";
561
+ }
562
+ if (typeof value === "boolean") {
563
+ return value ? "true" : "false";
564
+ }
565
+ if (typeof value === "number") {
566
+ if (Number.isNaN(value)) return "0";
567
+ if (!Number.isFinite(value)) return value > 0 ? "math.huge" : "-math.huge";
568
+ return String(value);
569
+ }
570
+ if (typeof value === "string") {
571
+ return escapeLuauString(value);
572
+ }
573
+ if (Array.isArray(value)) {
574
+ if (value.length === 0) return "{}";
575
+ return `{ ${value.map((item) => toLuauLiteral(item)).join(", ")} }`;
576
+ }
577
+ if (typeof value === "object") {
578
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0);
579
+ if (entries.length === 0) return "{}";
580
+ const fields = entries.map(([k, v]) => {
581
+ const keyExpr = LUAU_IDENT_RE.test(k) && !LUAU_RESERVED_KEYWORDS.has(k) ? k : `[${escapeLuauString(k)}]`;
582
+ return `${keyExpr} = ${toLuauLiteral(v)}`;
583
+ });
584
+ return `{ ${fields.join(", ")} }`;
585
+ }
586
+ return "nil";
587
+ }
588
+ function buildStudioSpawnSpec(batchPath) {
589
+ const isBat = /\.(?:bat|cmd)$/i.test(batchPath);
590
+ if (isBat) {
591
+ return {
592
+ command: "cmd.exe",
593
+ args: ["/d", "/s", "/c", `"${batchPath}"`],
594
+ options: {
595
+ stdio: ["pipe", "pipe", "pipe"],
596
+ windowsVerbatimArguments: true,
597
+ windowsHide: true
598
+ }
599
+ };
600
+ }
601
+ return {
602
+ command: batchPath,
603
+ args: [],
604
+ options: {
605
+ stdio: ["pipe", "pipe", "pipe"],
606
+ windowsHide: true
607
+ }
608
+ };
609
+ }
511
610
  function discoverRobloxStudioMcpBatch(env = process.env) {
512
611
  if (env.ROBLOX_STUDIO_MCP_PATH?.trim()) {
513
612
  return env.ROBLOX_STUDIO_MCP_PATH.trim();
@@ -565,16 +664,19 @@ function parseStudioToolResponse(rpcRes) {
565
664
  var RobloxStudioMcpClient = class {
566
665
  batchPath;
567
666
  timeoutMs;
667
+ defaultDataModelType;
568
668
  customTransport;
569
669
  child = null;
570
670
  initPromise = null;
571
671
  pending = /* @__PURE__ */ new Map();
572
672
  rpcSeq = 9e3;
573
673
  cachedToolNames = null;
674
+ cachedToolSchemas = /* @__PURE__ */ new Map();
574
675
  exitHookInstalled = false;
575
676
  constructor(options = {}) {
576
677
  this.batchPath = options.batchPath || discoverRobloxStudioMcpBatch(options.env);
577
678
  this.timeoutMs = options.timeoutMs ?? 25e3;
679
+ this.defaultDataModelType = options.defaultDataModelType ?? "Edit";
578
680
  this.customTransport = options.transport;
579
681
  }
580
682
  dispose() {
@@ -604,14 +706,8 @@ var RobloxStudioMcpClient = class {
604
706
  `Roblox Studio MCP launcher not found at "${this.batchPath}". Ensure Roblox Studio is installed with MCP enabled (expected %LOCALAPPDATA%\\Roblox\\mcp.bat) or set ROBLOX_STUDIO_MCP_PATH.`
605
707
  );
606
708
  }
607
- const isBat = /\.(?:bat|cmd)$/i.test(this.batchPath);
608
- const child = isBat ? spawn("cmd.exe", ["/d", "/s", "/c", `"${this.batchPath}"`], {
609
- stdio: ["pipe", "pipe", "pipe"],
610
- windowsHide: true
611
- }) : spawn(this.batchPath, [], {
612
- stdio: ["pipe", "pipe", "pipe"],
613
- windowsHide: true
614
- });
709
+ const spec = buildStudioSpawnSpec(this.batchPath);
710
+ const child = spawn(spec.command, spec.args, spec.options);
615
711
  child.unref();
616
712
  this.child = child;
617
713
  if (!this.exitHookInstalled) {
@@ -652,7 +748,7 @@ var RobloxStudioMcpClient = class {
652
748
  await this.sendRawRpc("initialize", {
653
749
  protocolVersion: "2025-03-26",
654
750
  capabilities: {},
655
- clientInfo: { name: "@luaward/mcp", version: "0.2.3" }
751
+ clientInfo: { name: "@luaward/mcp", version: "0.2.5" }
656
752
  });
657
753
  if (this.child && !this.child.killed) {
658
754
  this.child.stdin.write(
@@ -695,6 +791,12 @@ var RobloxStudioMcpClient = class {
695
791
  const res = await this.sendRpc("tools/list", {});
696
792
  const tools = res?.result?.tools;
697
793
  if (Array.isArray(tools)) {
794
+ this.cachedToolSchemas.clear();
795
+ for (const t of tools) {
796
+ if (typeof t?.name === "string" && t.name && t.inputSchema && typeof t.inputSchema === "object") {
797
+ this.cachedToolSchemas.set(t.name, t.inputSchema);
798
+ }
799
+ }
698
800
  this.cachedToolNames = tools.map((t) => typeof t?.name === "string" ? t.name : "").filter(Boolean);
699
801
  return this.cachedToolNames;
700
802
  }
@@ -704,7 +806,8 @@ var RobloxStudioMcpClient = class {
704
806
  }
705
807
  async listStudios() {
706
808
  const tools = await this.listTools();
707
- const listToolName = tools.find((t) => t === "list_studios" || t === "get_studios" || t === "list_clients") ?? "list_studios";
809
+ const listPriority = ["list_roblox_studios", "list_studios", "get_studios", "list_clients"];
810
+ const listToolName = listPriority.find((candidate) => tools.includes(candidate)) ?? "list_roblox_studios";
708
811
  try {
709
812
  const rpcRes = await this.sendRpc("tools/call", { name: listToolName, arguments: {} });
710
813
  const parsed = parseStudioToolResponse(rpcRes);
@@ -719,19 +822,24 @@ var RobloxStudioMcpClient = class {
719
822
  if (item && typeof item === "object") {
720
823
  const obj = item;
721
824
  const sid = String(
722
- obj.studio_id ?? obj.studioId ?? obj.id ?? obj.session_id ?? obj.pid ?? ""
825
+ obj.id ?? obj.studio_id ?? obj.studioId ?? obj.session_id ?? obj.pid ?? ""
723
826
  ).trim();
724
827
  if (sid) {
828
+ const placeNameRaw = obj.place_name ?? obj.placeName ?? obj.local_file_name ?? obj.name;
725
829
  studios.push({
830
+ id: sid,
726
831
  studio_id: sid,
727
832
  place_id: obj.place_id ?? obj.placeId,
728
- place_name: typeof (obj.place_name ?? obj.placeName ?? obj.name) === "string" ? String(obj.place_name ?? obj.placeName ?? obj.name) : void 0,
833
+ game_id: obj.game_id ?? obj.gameId,
834
+ place_name: typeof placeNameRaw === "string" ? placeNameRaw : void 0,
835
+ local_file_name: typeof obj.local_file_name === "string" ? obj.local_file_name : void 0,
729
836
  user: typeof obj.user === "string" ? obj.user : void 0,
730
837
  raw: obj
731
838
  });
732
839
  }
733
840
  } else if (typeof item === "string" || typeof item === "number") {
734
- studios.push({ studio_id: String(item) });
841
+ const sid = String(item);
842
+ studios.push({ id: sid, studio_id: sid });
735
843
  }
736
844
  }
737
845
  return { ok: true, studios, rawText: parsed.text };
@@ -740,7 +848,7 @@ var RobloxStudioMcpClient = class {
740
848
  ...parsed.text.matchAll(/\b(?:studio_id|studioId|studio|id)[:=\s"']*([A-Za-z0-9_-]{2,64})\b/gi)
741
849
  ];
742
850
  for (const m of matches) {
743
- if (m[1]) studios.push({ studio_id: m[1] });
851
+ if (m[1]) studios.push({ id: m[1], studio_id: m[1] });
744
852
  }
745
853
  return { ok: true, studios, rawText: parsed.text };
746
854
  } catch (err) {
@@ -756,10 +864,11 @@ var RobloxStudioMcpClient = class {
756
864
  */
757
865
  async resolveStudioId(explicitStudioId) {
758
866
  if (explicitStudioId && explicitStudioId.trim()) {
867
+ const sid = explicitStudioId.trim();
759
868
  return {
760
869
  ok: true,
761
- studioId: explicitStudioId.trim(),
762
- studios: [{ studio_id: explicitStudioId.trim() }],
870
+ studioId: sid,
871
+ studios: [{ id: sid, studio_id: sid }],
763
872
  autoSelected: false
764
873
  };
765
874
  }
@@ -773,9 +882,10 @@ var RobloxStudioMcpClient = class {
773
882
  };
774
883
  }
775
884
  if (listed.studios.length === 1 && listed.studios[0]) {
885
+ const sid = listed.studios[0].id || listed.studios[0].studio_id;
776
886
  return {
777
887
  ok: true,
778
- studioId: listed.studios[0].studio_id,
888
+ studioId: sid,
779
889
  studios: listed.studios,
780
890
  autoSelected: true
781
891
  };
@@ -788,7 +898,7 @@ var RobloxStudioMcpClient = class {
788
898
  err: "No connected Roblox Studio instance found via %LOCALAPPDATA%\\Roblox\\mcp.bat. Open a place in Roblox Studio with MCP enabled first."
789
899
  };
790
900
  }
791
- const listStr = listed.studios.map((s) => `${s.studio_id}${s.place_name ? ` ("${s.place_name}")` : ""}`).join(", ");
901
+ const listStr = listed.studios.map((s) => `${s.id || s.studio_id}${s.place_name ? ` ("${s.place_name}")` : ""}`).join(", ");
792
902
  return {
793
903
  ok: false,
794
904
  studios: listed.studios,
@@ -800,7 +910,8 @@ var RobloxStudioMcpClient = class {
800
910
  const finalArgs = { ...args };
801
911
  let studioId = typeof finalArgs.studio_id === "string" ? finalArgs.studio_id.trim() : void 0;
802
912
  let autoSelected = false;
803
- if (!studioId && name !== "list_studios" && name !== "get_studios") {
913
+ const isListTool = name === "list_roblox_studios" || name === "list_studios" || name === "get_studios" || name === "list_clients";
914
+ if (!studioId && !isListTool) {
804
915
  const resolved = await this.resolveStudioId();
805
916
  if (!resolved.ok) {
806
917
  return { ok: false, text: resolved.err ?? "Failed to resolve studio_id", isError: true };
@@ -811,6 +922,12 @@ var RobloxStudioMcpClient = class {
811
922
  finalArgs.studio_id = studioId;
812
923
  }
813
924
  }
925
+ if (!isListTool && finalArgs.datamodel_type === void 0) {
926
+ const schemaProps = this.cachedToolSchemas.get(name)?.properties;
927
+ if (name === "execute_luau" || schemaProps && "datamodel_type" in schemaProps) {
928
+ finalArgs.datamodel_type = this.defaultDataModelType;
929
+ }
930
+ }
814
931
  try {
815
932
  const rpcRes = await this.sendRpc("tools/call", { name, arguments: finalArgs });
816
933
  const parsed = parseStudioToolResponse(rpcRes);
@@ -829,7 +946,7 @@ var RobloxStudioMcpClient = class {
829
946
  };
830
947
  }
831
948
  }
832
- async runStudioLuau(code, explicitStudioId) {
949
+ async runStudioLuau(code, explicitStudioId, datamodelType) {
833
950
  const resolved = await this.resolveStudioId(explicitStudioId);
834
951
  if (!resolved.ok) {
835
952
  return {
@@ -839,13 +956,30 @@ var RobloxStudioMcpClient = class {
839
956
  };
840
957
  }
841
958
  const tools = await this.listTools();
842
- const execTool = tools.find((t) => t === "run_code" || t === "execute_luau" || t === "run_script" || t === "eval") ?? "run_code";
843
- const res = await this.callTool(execTool, {
844
- command: code,
845
- code,
846
- source: code,
959
+ const execPriority = ["execute_luau", "run_code", "run_script", "eval"];
960
+ const execTool = execPriority.find((candidate) => tools.includes(candidate)) ?? "execute_luau";
961
+ const dmType = datamodelType ?? this.defaultDataModelType;
962
+ const schemaProps = this.cachedToolSchemas.get(execTool)?.properties;
963
+ const toolArgs = {
964
+ datamodel_type: dmType,
847
965
  ...resolved.studioId ? { studio_id: resolved.studioId } : {}
848
- });
966
+ };
967
+ if (execTool === "execute_luau") {
968
+ toolArgs.code = code;
969
+ if (schemaProps && "command" in schemaProps) {
970
+ toolArgs.command = code;
971
+ }
972
+ } else if (execTool === "run_code") {
973
+ toolArgs.command = code;
974
+ if (!schemaProps || "code" in schemaProps) {
975
+ toolArgs.code = code;
976
+ }
977
+ } else {
978
+ toolArgs.code = code;
979
+ toolArgs.command = code;
980
+ toolArgs.source = code;
981
+ }
982
+ const res = await this.callTool(execTool, toolArgs);
849
983
  return {
850
984
  ...res,
851
985
  studioId: resolved.studioId,
@@ -2226,7 +2360,7 @@ function matchesWindowTarget(w, filter) {
2226
2360
  }
2227
2361
 
2228
2362
  // src/index.ts
2229
- var MCP_BRIDGE_VERSION = "0.2.3";
2363
+ var MCP_BRIDGE_VERSION = "0.2.5";
2230
2364
  var DEFAULT_MCP_URL = "https://luaward.com/mcp";
2231
2365
  var TOKEN_CREATE_URL = "https://dash.luaward.com/dashboard/ai";
2232
2366
  var TOKEN_SHAPE = /^lwm_[0-9a-f]{48}$/;
@@ -2742,7 +2876,12 @@ var LOCAL_HYBRID_TOOLS = [
2742
2876
  properties: {
2743
2877
  root: {
2744
2878
  type: "string",
2745
- description: "Root service/path to mirror (default 'ReplicatedStorage')"
2879
+ description: "Root service or dotted path to mirror (e.g. 'ReplicatedStorage' or 'ReplicatedStorage.Remotes')"
2880
+ },
2881
+ roots: {
2882
+ type: "array",
2883
+ items: { type: "string" },
2884
+ description: "Optional list of root services to mirror when root is omitted (default ['ReplicatedStorage', 'Workspace'])"
2746
2885
  },
2747
2886
  filter: {
2748
2887
  type: "string",
@@ -2759,6 +2898,21 @@ var LOCAL_HYBRID_TOOLS = [
2759
2898
  maximum: 500,
2760
2899
  description: "Maximum remotes to mirror (default 200)"
2761
2900
  },
2901
+ max_depth: {
2902
+ type: "integer",
2903
+ minimum: 1,
2904
+ maximum: 12,
2905
+ description: "Maximum hierarchy depth (default 6)"
2906
+ },
2907
+ clear_existing: {
2908
+ type: "boolean",
2909
+ description: "Recreate existing remotes of the same class in Studio (default false)"
2910
+ },
2911
+ datamodel_type: {
2912
+ type: "string",
2913
+ enum: ["Edit", "Client", "Server"],
2914
+ description: "Roblox Studio DataModel context (default 'Edit'; use 'Client' or 'Server' during playtest)"
2915
+ },
2762
2916
  studio_id: {
2763
2917
  type: "string",
2764
2918
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -2789,26 +2943,49 @@ var LOCAL_HYBRID_TOOLS = [
2789
2943
  type: "string",
2790
2944
  description: "Live GUI root path or #n handle to mirror (default 'Players.LocalPlayer.PlayerGui')"
2791
2945
  },
2946
+ target_path: {
2947
+ type: "string",
2948
+ description: "Alias for target (live GUI path or #n handle to mirror)"
2949
+ },
2792
2950
  studio_root: {
2793
2951
  type: "string",
2794
- description: "Destination container in Roblox Studio (default 'StarterGui')"
2952
+ description: "Destination container name in Roblox Studio StarterGui (default 'LuawardMirroredGui')"
2953
+ },
2954
+ container_name: {
2955
+ type: "string",
2956
+ description: "Alias for studio_root container folder name inside StarterGui (default 'LuawardMirroredGui')"
2795
2957
  },
2796
2958
  depth: {
2797
2959
  type: "integer",
2798
2960
  minimum: 1,
2799
2961
  maximum: 12,
2800
- description: "Maximum hierarchy depth (default 6)"
2962
+ description: "Maximum hierarchy depth (default 10)"
2801
2963
  },
2802
2964
  max_instances: {
2803
2965
  type: "integer",
2804
2966
  minimum: 1,
2805
- maximum: 600,
2967
+ maximum: 1e3,
2806
2968
  description: "Maximum GUI instances to mirror (default 250)"
2807
2969
  },
2970
+ max_nodes: {
2971
+ type: "integer",
2972
+ minimum: 1,
2973
+ maximum: 1e3,
2974
+ description: "Alias for max_instances (default 250)"
2975
+ },
2808
2976
  only_visible: {
2809
2977
  type: "boolean",
2810
2978
  description: "Only mirror visible GUI elements (default false)"
2811
2979
  },
2980
+ include_core_gui: {
2981
+ type: "boolean",
2982
+ description: "Include non-RobloxGui ScreenGuis from CoreGui (default false)"
2983
+ },
2984
+ datamodel_type: {
2985
+ type: "string",
2986
+ enum: ["Edit", "Client", "Server"],
2987
+ description: "Roblox Studio DataModel context (default 'Edit')"
2988
+ },
2812
2989
  studio_id: {
2813
2990
  type: "string",
2814
2991
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -2831,18 +3008,34 @@ var LOCAL_HYBRID_TOOLS = [
2831
3008
  {
2832
3009
  name: "studio_diff",
2833
3010
  title: "Diff scripts, remotes, or GUI between Roblox Studio and live game",
2834
- description: "Compare scripts, remotes, or GUI hierarchy between Roblox Studio (%LOCALAPPDATA%\\Roblox\\mcp.bat) and the live connected Roblox game, reporting items only in live, only in Studio, modified items, and line diffs.",
3011
+ description: "Compare scripts, remotes, or GUI hierarchy between Roblox Studio (%LOCALAPPDATA%\\Roblox\\mcp.bat) and the live connected Roblox game, reporting items only in live, only in Studio, and class mismatches.",
2835
3012
  inputSchema: {
2836
3013
  type: "object",
2837
3014
  properties: {
2838
3015
  scope: {
2839
3016
  type: "string",
2840
3017
  enum: ["scripts", "remotes", "gui", "all"],
2841
- description: "What to compare (default 'scripts')"
3018
+ description: "What to compare (default 'all')"
2842
3019
  },
2843
3020
  target: {
2844
3021
  type: "string",
2845
- description: "Optional root or specific script path to compare (default 'ReplicatedStorage')"
3022
+ description: "Optional root service to compare (e.g. 'ReplicatedStorage')"
3023
+ },
3024
+ roots: {
3025
+ type: "array",
3026
+ items: { type: "string" },
3027
+ description: "Optional list of root services to compare (default ['ReplicatedStorage', 'StarterGui', 'Workspace'])"
3028
+ },
3029
+ max_depth: {
3030
+ type: "integer",
3031
+ minimum: 1,
3032
+ maximum: 10,
3033
+ description: "Maximum hierarchy depth (default 5)"
3034
+ },
3035
+ datamodel_type: {
3036
+ type: "string",
3037
+ enum: ["Edit", "Client", "Server"],
3038
+ description: "Roblox Studio DataModel context (default 'Edit')"
2846
3039
  },
2847
3040
  studio_id: {
2848
3041
  type: "string",
@@ -2874,6 +3067,18 @@ var LOCAL_HYBRID_TOOLS = [
2874
3067
  type: "string",
2875
3068
  description: "Script path in Roblox Studio (e.g. 'StarterPlayer.StarterPlayerScripts.Main') or 'Selection' for currently selected script (default 'Selection')"
2876
3069
  },
3070
+ code: {
3071
+ type: "string",
3072
+ description: "Optional inline Luau code to run instead of reading from studio_path"
3073
+ },
3074
+ collect: {
3075
+ type: "boolean",
3076
+ description: "Use run_and_collect instead of exec (default true)"
3077
+ },
3078
+ wait_seconds: {
3079
+ type: "number",
3080
+ description: "Wait time in seconds for run_and_collect (default 1.5)"
3081
+ },
2877
3082
  clean_env: {
2878
3083
  type: "boolean",
2879
3084
  description: "Run in clean native Luau SAFEENV environment (default true)"
@@ -2892,6 +3097,11 @@ var LOCAL_HYBRID_TOOLS = [
2892
3097
  maximum: 15e3,
2893
3098
  description: "Settle window in ms after return (default 300)"
2894
3099
  },
3100
+ datamodel_type: {
3101
+ type: "string",
3102
+ enum: ["Edit", "Client", "Server"],
3103
+ description: "Roblox Studio DataModel context (default 'Edit')"
3104
+ },
2895
3105
  studio_id: {
2896
3106
  type: "string",
2897
3107
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -2914,13 +3124,29 @@ var LOCAL_HYBRID_TOOLS = [
2914
3124
  {
2915
3125
  name: "studio_publish",
2916
3126
  title: "Publish a Roblox Studio script to Luaward Cloud",
2917
- description: "Read a script's Luau source directly from Roblox Studio (%LOCALAPPDATA%\\Roblox\\mcp.bat) and deploy/protect it on Luaward Cloud via deploy_script.",
3127
+ description: "Read a script's Luau source directly from Roblox Studio (%LOCALAPPDATA%\\Roblox\\mcp.bat) and create or deploy/protect it on Luaward Cloud.",
2918
3128
  inputSchema: {
2919
3129
  type: "object",
2920
3130
  properties: {
2921
3131
  script: {
2922
3132
  type: "string",
2923
- description: "Target Luaward Cloud script name or ID"
3133
+ description: "Target Luaward Cloud script name or ID to deploy to"
3134
+ },
3135
+ script_id: {
3136
+ type: "string",
3137
+ description: "Target Luaward Cloud script ID to deploy to"
3138
+ },
3139
+ name: {
3140
+ type: "string",
3141
+ description: "New Luaward Cloud script name when creating a new script"
3142
+ },
3143
+ description: {
3144
+ type: "string",
3145
+ description: "Optional description when creating a new Luaward script"
3146
+ },
3147
+ note: {
3148
+ type: "string",
3149
+ description: "Optional build note when deploying to an existing Luaward script"
2924
3150
  },
2925
3151
  studio_path: {
2926
3152
  type: "string",
@@ -2935,12 +3161,16 @@ var LOCAL_HYBRID_TOOLS = [
2935
3161
  enum: ["fast", "balanced", "max"],
2936
3162
  description: "Optional protection preset"
2937
3163
  },
3164
+ datamodel_type: {
3165
+ type: "string",
3166
+ enum: ["Edit", "Client", "Server"],
3167
+ description: "Roblox Studio DataModel context (default 'Edit')"
3168
+ },
2938
3169
  studio_id: {
2939
3170
  type: "string",
2940
3171
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
2941
3172
  }
2942
3173
  },
2943
- required: ["script"],
2944
3174
  additionalProperties: false
2945
3175
  },
2946
3176
  annotations: {
@@ -2969,7 +3199,11 @@ var LOCAL_HYBRID_TOOLS = [
2969
3199
  },
2970
3200
  studio_root: {
2971
3201
  type: "string",
2972
- description: "Optional destination container in Studio (e.g. 'ServerStorage.LiveImports'; omit to mirror into matching services)"
3202
+ description: "Optional destination container in Studio ServerStorage (default 'LuawardLiveScripts')"
3203
+ },
3204
+ container_name: {
3205
+ type: "string",
3206
+ description: "Alias for studio_root destination folder name in ServerStorage (default 'LuawardLiveScripts')"
2973
3207
  },
2974
3208
  max: {
2975
3209
  type: "integer",
@@ -2977,10 +3211,25 @@ var LOCAL_HYBRID_TOOLS = [
2977
3211
  maximum: 100,
2978
3212
  description: "Maximum scripts to import in one call (default 15)"
2979
3213
  },
3214
+ limit: {
3215
+ type: "integer",
3216
+ minimum: 1,
3217
+ maximum: 100,
3218
+ description: "Alias for max (default 15)"
3219
+ },
2980
3220
  disabled: {
2981
3221
  type: "boolean",
2982
3222
  description: "Set .Disabled = true on imported LocalScripts in Studio (default true)"
2983
3223
  },
3224
+ include_decompiled: {
3225
+ type: "boolean",
3226
+ description: "Decompile script source via decompile() in the live executor (default true)"
3227
+ },
3228
+ datamodel_type: {
3229
+ type: "string",
3230
+ enum: ["Edit", "Client", "Server"],
3231
+ description: "Roblox Studio DataModel context (default 'Edit')"
3232
+ },
2984
3233
  studio_id: {
2985
3234
  type: "string",
2986
3235
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -3710,7 +3959,7 @@ ${lines.join("\n")}` }]
3710
3959
  };
3711
3960
  }
3712
3961
  const lookupCode = [
3713
- `local inst, err = lw.resolve(${JSON.stringify(target)})`,
3962
+ `local inst, err = lw.resolve(${toLuauLiteral(target)})`,
3714
3963
  "if not inst then error(err or 'target not found') end",
3715
3964
  "local pos, size = inst.AbsolutePosition, inst.AbsoluteSize",
3716
3965
  "if not (pos and size) then error(lw.path(inst) .. ' has no AbsolutePosition/AbsoluteSize') end",
@@ -3910,35 +4159,75 @@ ${diffSummary}`);
3910
4159
  }
3911
4160
  return null;
3912
4161
  }
4162
+ parseStudioDataModelType(raw) {
4163
+ if (raw === "Client" || raw === "Server" || raw === "Edit") {
4164
+ return raw;
4165
+ }
4166
+ return "Edit";
4167
+ }
3913
4168
  async handleStudioMirrorRemotes(args) {
3914
- const roots = Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "Workspace"];
3915
- const maxDepth = typeof args.max_depth === "number" ? Math.max(1, Math.min(12, args.max_depth)) : 6;
4169
+ const singleRoot = typeof args.root === "string" && args.root.trim() ? args.root.trim() : "";
4170
+ const roots = singleRoot ? [singleRoot] : Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "Workspace"];
4171
+ const filter = typeof args.filter === "string" ? args.filter.trim().toLowerCase() : "";
4172
+ const kind = args.kind === "network" || args.kind === "bindable" ? args.kind : "all";
4173
+ const max = typeof args.max === "number" ? Math.max(1, Math.min(500, Math.floor(args.max))) : 200;
4174
+ const maxDepth = typeof args.max_depth === "number" ? Math.max(1, Math.min(12, Math.floor(args.max_depth))) : 6;
3916
4175
  const clearExisting = args.clear_existing === true;
4176
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
3917
4177
  const session = typeof args.session === "string" ? args.session : void 0;
3918
4178
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4179
+ const remoteClassesMap = kind === "network" ? { RemoteEvent: true, RemoteFunction: true, UnreliableRemoteEvent: true } : kind === "bindable" ? { BindableEvent: true, BindableFunction: true } : {
4180
+ RemoteEvent: true,
4181
+ RemoteFunction: true,
4182
+ UnreliableRemoteEvent: true,
4183
+ BindableEvent: true,
4184
+ BindableFunction: true
4185
+ };
3919
4186
  const liveScanCode = [
3920
4187
  "local HttpService = game:GetService('HttpService')",
3921
- `local roots = ${JSON.stringify(roots)}`,
3922
- `local maxDepth = ${maxDepth}`,
3923
- "local remoteClasses = { RemoteEvent = true, RemoteFunction = true, UnreliableRemoteEvent = true, BindableEvent = true, BindableFunction = true }",
4188
+ `local roots = ${toLuauLiteral(roots)}`,
4189
+ `local filter = ${toLuauLiteral(filter)}`,
4190
+ `local maxItems = ${toLuauLiteral(max)}`,
4191
+ `local maxDepth = ${toLuauLiteral(maxDepth)}`,
4192
+ `local remoteClasses = ${toLuauLiteral(remoteClassesMap)}`,
3924
4193
  "local items = {}",
4194
+ "local function resolveRoot(rPath)",
4195
+ " local segs = {}",
4196
+ " for seg in string.gmatch(rPath, '[^%.]+') do segs[#segs + 1] = seg end",
4197
+ " if #segs == 0 then return nil, nil, nil end",
4198
+ " local startIdx = (segs[1] == 'game') and 2 or 1",
4199
+ " local rootName = segs[startIdx]",
4200
+ " if not rootName then return nil, nil, nil end",
4201
+ " local ok, cur = pcall(function() return game:GetService(rootName) end)",
4202
+ " if not ok or not cur then return nil, nil, nil end",
4203
+ " local baseSegs = {}",
4204
+ " for i = startIdx + 1, #segs do",
4205
+ " cur = cur and cur:FindFirstChild(segs[i])",
4206
+ " baseSegs[#baseSegs + 1] = segs[i]",
4207
+ " end",
4208
+ " return cur, rootName, baseSegs",
4209
+ "end",
3925
4210
  "local function scan(inst, rootName, segs, depth)",
3926
- " if depth > maxDepth then return end",
4211
+ " if depth > maxDepth or #items >= maxItems then return end",
3927
4212
  " for _, child in ipairs(inst:GetChildren()) do",
4213
+ " if #items >= maxItems then break end",
3928
4214
  " local nextSegs = {}",
3929
4215
  " for i = 1, #segs do nextSegs[i] = segs[i] end",
3930
4216
  " nextSegs[#nextSegs + 1] = child.Name",
4217
+ " local fullPath = rootName .. '.' .. table.concat(nextSegs, '.')",
3931
4218
  " if remoteClasses[child.ClassName] then",
3932
- " items[#items + 1] = { root = rootName, className = child.ClassName, segments = nextSegs, path = rootName .. '.' .. table.concat(nextSegs, '.') }",
4219
+ " if filter == '' or string.find(string.lower(fullPath), filter, 1, true) then",
4220
+ " items[#items + 1] = { root = rootName, className = child.ClassName, segments = nextSegs, path = fullPath }",
4221
+ " end",
3933
4222
  " end",
3934
- " if #child:GetChildren() > 0 then",
4223
+ " if #child:GetChildren() > 0 and #items < maxItems then",
3935
4224
  " scan(child, rootName, nextSegs, depth + 1)",
3936
4225
  " end",
3937
4226
  " end",
3938
4227
  "end",
3939
- "for _, rName in ipairs(roots) do",
3940
- " local ok, svc = pcall(function() return game:GetService(rName) end)",
3941
- " if ok and svc then scan(svc, rName, {}, 1) end",
4228
+ "for _, rPath in ipairs(roots) do",
4229
+ " local inst, rootName, baseSegs = resolveRoot(rPath)",
4230
+ " if inst and rootName and baseSegs then scan(inst, rootName, baseSegs, 1) end",
3942
4231
  "end",
3943
4232
  "return HttpService:JSONEncode(items)"
3944
4233
  ].join("\n");
@@ -3955,9 +4244,8 @@ ${diffSummary}`);
3955
4244
  }
3956
4245
  const items = this.extractJsonPayloadFromExec(liveRes.text) ?? [];
3957
4246
  const studioCode = [
3958
- "local HttpService = game:GetService('HttpService')",
3959
- `local items = HttpService:JSONDecode(${JSON.stringify(JSON.stringify(items))})`,
3960
- `local clearExisting = ${clearExisting ? "true" : "false"}`,
4247
+ `local items = ${toLuauLiteral(items)}`,
4248
+ `local clearExisting = ${toLuauLiteral(clearExisting)}`,
3961
4249
  "local created, existing = 0, 0",
3962
4250
  "for _, item in ipairs(items) do",
3963
4251
  " local ok, rootInst = pcall(function() return game:GetService(item.root) end)",
@@ -3995,7 +4283,7 @@ ${diffSummary}`);
3995
4283
  "end",
3996
4284
  "return string.format('mirrored %d remotes (created=%d, existing=%d)', #items, created, existing)"
3997
4285
  ].join("\n");
3998
- const studioRes = await this.studio.runStudioLuau(studioCode, requestedStudioId);
4286
+ const studioRes = await this.studio.runStudioLuau(studioCode, requestedStudioId, datamodelType);
3999
4287
  if (!studioRes.ok) {
4000
4288
  return {
4001
4289
  content: [
@@ -4013,8 +4301,8 @@ ${diffSummary}`);
4013
4301
  {
4014
4302
  type: "text",
4015
4303
  text: [
4016
- `studio_mirror_remotes complete (studio_id=${studioRes.studioId ?? "auto"}):`,
4017
- `- Live remotes discovered: ${items.length} across ${roots.join(", ")}`,
4304
+ `studio_mirror_remotes complete (studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4305
+ `- Live remotes discovered: ${items.length} across ${roots.join(", ")} (kind=${kind}${filter ? `, filter="${filter}"` : ""}, max=${max})`,
4018
4306
  `- Studio result: ${studioRes.text}`,
4019
4307
  ...samplePaths.length > 0 ? ["- Sample mirrored paths:", ...samplePaths] : []
4020
4308
  ].join("\n")
@@ -4023,25 +4311,37 @@ ${diffSummary}`);
4023
4311
  };
4024
4312
  }
4025
4313
  async handleStudioMirrorGui(args) {
4026
- const targetPath = typeof args.target_path === "string" ? args.target_path.trim() : "";
4027
- const containerName = typeof args.container_name === "string" && args.container_name.trim() ? args.container_name.trim() : "LuawardMirroredGui";
4028
- const maxNodes = typeof args.max_nodes === "number" ? Math.max(10, Math.min(1e3, args.max_nodes)) : 250;
4314
+ const rawTarget = typeof args.target_path === "string" && args.target_path.trim() ? args.target_path.trim() : typeof args.target === "string" && args.target.trim() ? args.target.trim() : "";
4315
+ const targetPath = rawTarget === "Players.LocalPlayer.PlayerGui" || rawTarget === "PlayerGui" ? "" : rawTarget;
4316
+ const rawContainer = typeof args.container_name === "string" && args.container_name.trim() ? args.container_name.trim() : typeof args.studio_root === "string" && args.studio_root.trim() ? args.studio_root.trim() : "LuawardMirroredGui";
4317
+ const containerName = rawContainer === "StarterGui" ? "LuawardMirroredGui" : rawContainer.replace(/^StarterGui\./, "") || "LuawardMirroredGui";
4318
+ const maxDepth = typeof args.depth === "number" ? Math.max(1, Math.min(12, Math.floor(args.depth))) : 10;
4319
+ const rawMaxNodes = typeof args.max_nodes === "number" ? args.max_nodes : typeof args.max_instances === "number" ? args.max_instances : 250;
4320
+ const maxNodes = Math.max(1, Math.min(1e3, Math.floor(rawMaxNodes)));
4321
+ const onlyVisible = args.only_visible === true;
4029
4322
  const includeCoreGui = args.include_core_gui === true;
4323
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4030
4324
  const session = typeof args.session === "string" ? args.session : void 0;
4031
4325
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4032
4326
  const liveGuiCode = [
4033
4327
  "local HttpService = game:GetService('HttpService')",
4034
4328
  "local Players = game:GetService('Players')",
4035
- `local targetPath = ${JSON.stringify(targetPath)}`,
4036
- `local maxNodes = ${maxNodes}`,
4037
- `local includeCore = ${includeCoreGui ? "true" : "false"}`,
4329
+ `local targetPath = ${toLuauLiteral(targetPath)}`,
4330
+ `local maxNodes = ${toLuauLiteral(maxNodes)}`,
4331
+ `local maxDepth = ${toLuauLiteral(maxDepth)}`,
4332
+ `local onlyVisible = ${toLuauLiteral(onlyVisible)}`,
4333
+ `local includeCore = ${toLuauLiteral(includeCoreGui)}`,
4038
4334
  "local nodes = {}",
4039
4335
  "local count = 0",
4040
4336
  "local function serColor(c) return c and { c.R, c.G, c.B } or nil end",
4041
4337
  "local function serUDim2(u) return u and { u.X.Scale, u.X.Offset, u.Y.Scale, u.Y.Offset } or nil end",
4042
4338
  "local function serVec2(v) return v and { v.X, v.Y } or nil end",
4043
4339
  "local function serializeTree(inst, depth)",
4044
- " if count >= maxNodes or depth > 10 then return nil end",
4340
+ " if count >= maxNodes or depth > maxDepth then return nil end",
4341
+ " if onlyVisible then",
4342
+ " if inst:IsA('LayerCollector') and inst.Enabled == false then return nil end",
4343
+ " if inst:IsA('GuiObject') and inst.Visible == false then return nil end",
4344
+ " end",
4045
4345
  " count = count + 1",
4046
4346
  " local node = { className = inst.ClassName, name = inst.Name, children = {} }",
4047
4347
  " pcall(function()",
@@ -4074,7 +4374,10 @@ ${diffSummary}`);
4074
4374
  "end",
4075
4375
  "if targetPath ~= '' and lw and lw.resolve then",
4076
4376
  " local inst = lw.resolve(targetPath)",
4077
- " if inst then nodes[#nodes + 1] = serializeTree(inst, 1) end",
4377
+ " if inst then",
4378
+ " local n = serializeTree(inst, 1)",
4379
+ " if n then nodes[#nodes + 1] = n end",
4380
+ " end",
4078
4381
  "else",
4079
4382
  " local lp = Players.LocalPlayer",
4080
4383
  " local pgui = lp and lp:FindFirstChildOfClass('PlayerGui')",
@@ -4116,10 +4419,9 @@ ${diffSummary}`);
4116
4419
  trees: []
4117
4420
  };
4118
4421
  const studioBuildCode = [
4119
- "local HttpService = game:GetService('HttpService')",
4120
4422
  "local StarterGui = game:GetService('StarterGui')",
4121
- `local containerName = ${JSON.stringify(containerName)}`,
4122
- `local payload = HttpService:JSONDecode(${JSON.stringify(JSON.stringify(payload))})`,
4423
+ `local containerName = ${toLuauLiteral(containerName)}`,
4424
+ `local payload = ${toLuauLiteral(payload)}`,
4123
4425
  "local folder = StarterGui:FindFirstChild(containerName)",
4124
4426
  "if folder then folder:Destroy() end",
4125
4427
  "folder = Instance.new('Folder')",
@@ -4162,7 +4464,7 @@ ${diffSummary}`);
4162
4464
  "for _, tree in ipairs(payload.trees or {}) do buildNode(tree, folder) end",
4163
4465
  "return string.format('mirrored %d GUI nodes into StarterGui.%s', created, containerName)"
4164
4466
  ].join("\n");
4165
- const studioRes = await this.studio.runStudioLuau(studioBuildCode, requestedStudioId);
4467
+ const studioRes = await this.studio.runStudioLuau(studioBuildCode, requestedStudioId, datamodelType);
4166
4468
  if (!studioRes.ok) {
4167
4469
  return {
4168
4470
  content: [
@@ -4179,7 +4481,7 @@ ${diffSummary}`);
4179
4481
  {
4180
4482
  type: "text",
4181
4483
  text: [
4182
- `studio_mirror_gui complete (studio_id=${studioRes.studioId ?? "auto"}):`,
4484
+ `studio_mirror_gui complete (studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4183
4485
  `- Live GUI nodes serialized: ${payload.count} (${payload.trees.length} root trees)`,
4184
4486
  `- Studio container: StarterGui.${containerName}`,
4185
4487
  `- Studio result: ${studioRes.text}`
@@ -4189,17 +4491,19 @@ ${diffSummary}`);
4189
4491
  };
4190
4492
  }
4191
4493
  async handleStudioDiff(args) {
4192
- const roots = Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "StarterGui", "Workspace"];
4494
+ const singleTarget = typeof args.target === "string" && args.target.trim() ? args.target.trim() : "";
4495
+ const roots = singleTarget ? [singleTarget] : Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "StarterGui", "Workspace"];
4193
4496
  const scope = typeof args.scope === "string" ? args.scope : "all";
4194
4497
  const maxDepth = typeof args.max_depth === "number" ? Math.max(1, Math.min(10, args.max_depth)) : 5;
4498
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4195
4499
  const session = typeof args.session === "string" ? args.session : void 0;
4196
4500
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4197
4501
  const buildDiffScanCode = (isLive) => [
4198
4502
  "local HttpService = game:GetService('HttpService')",
4199
- `local roots = ${JSON.stringify(roots)}`,
4200
- `local scope = ${JSON.stringify(scope)}`,
4201
- `local maxDepth = ${maxDepth}`,
4202
- `local isLive = ${isLive ? "true" : "false"}`,
4503
+ `local roots = ${toLuauLiteral(roots)}`,
4504
+ `local scope = ${toLuauLiteral(scope)}`,
4505
+ `local maxDepth = ${toLuauLiteral(maxDepth)}`,
4506
+ `local isLive = ${toLuauLiteral(isLive)}`,
4203
4507
  "local entries = {}",
4204
4508
  "local count = 0",
4205
4509
  "local remoteClasses = { RemoteEvent = true, RemoteFunction = true, UnreliableRemoteEvent = true, BindableEvent = true, BindableFunction = true }",
@@ -4239,7 +4543,7 @@ ${diffSummary}`);
4239
4543
  readonly: true,
4240
4544
  ...session ? { session } : {}
4241
4545
  }),
4242
- this.studio.runStudioLuau(buildDiffScanCode(false), requestedStudioId)
4546
+ this.studio.runStudioLuau(buildDiffScanCode(false), requestedStudioId, datamodelType)
4243
4547
  ]);
4244
4548
  if (!liveRes.ok) {
4245
4549
  return {
@@ -4279,7 +4583,7 @@ ${diffSummary}`);
4279
4583
  }
4280
4584
  }
4281
4585
  const lines = [
4282
- `studio_diff report (scope=${scope}, roots=${roots.join(", ")}, studio_id=${studioRes.studioId ?? "auto"}):`,
4586
+ `studio_diff report (scope=${scope}, roots=${roots.join(", ")}, studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4283
4587
  `- Matched instances: ${matchedCount}`,
4284
4588
  `- Only in Live Game: ${onlyInLive.length}`,
4285
4589
  ...onlyInLive.slice(0, 20).map((x) => ` + [Live] ${x}`),
@@ -4297,15 +4601,22 @@ ${diffSummary}`);
4297
4601
  buildStudioReadScriptSourceCode(studioPath) {
4298
4602
  return [
4299
4603
  "local HttpService = game:GetService('HttpService')",
4300
- `local pathStr = ${JSON.stringify(studioPath)}`,
4301
- "local segs = {}",
4302
- "for seg in string.gmatch(pathStr, '[^%.]+') do segs[#segs + 1] = seg end",
4303
- "if #segs == 0 then error('Empty studio_path') end",
4304
- "local startIdx = 1",
4305
- "if segs[1] == 'game' then startIdx = 2 end",
4306
- "local cur = game:GetService(segs[startIdx])",
4307
- "for i = startIdx + 1, #segs do",
4308
- " cur = cur and cur:FindFirstChild(segs[i])",
4604
+ `local pathStr = ${toLuauLiteral(studioPath)}`,
4605
+ "local cur = nil",
4606
+ "if pathStr == '' or pathStr == 'Selection' then",
4607
+ " local sel = game:GetService('Selection'):Get()",
4608
+ " cur = sel and sel[1] or nil",
4609
+ " if not cur then error('No script is currently selected in Roblox Studio Selection') end",
4610
+ "else",
4611
+ " local segs = {}",
4612
+ " for seg in string.gmatch(pathStr, '[^%.]+') do segs[#segs + 1] = seg end",
4613
+ " if #segs == 0 then error('Empty studio_path') end",
4614
+ " local startIdx = 1",
4615
+ " if segs[1] == 'game' then startIdx = 2 end",
4616
+ " cur = game:GetService(segs[startIdx])",
4617
+ " for i = startIdx + 1, #segs do",
4618
+ " cur = cur and cur:FindFirstChild(segs[i])",
4619
+ " end",
4309
4620
  "end",
4310
4621
  "if not cur then error('Studio instance not found: ' .. pathStr) end",
4311
4622
  "local ok, src = pcall(function() return cur.Source end)",
@@ -4314,24 +4625,20 @@ ${diffSummary}`);
4314
4625
  ].join("\n");
4315
4626
  }
4316
4627
  async handleStudioToLive(args) {
4317
- const studioPath = typeof args.studio_path === "string" ? args.studio_path.trim() : "";
4318
4628
  const directCode = typeof args.code === "string" ? args.code : "";
4629
+ const studioPath = typeof args.studio_path === "string" && args.studio_path.trim() ? args.studio_path.trim() : directCode.trim() ? "" : "Selection";
4630
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4319
4631
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4320
4632
  const session = typeof args.session === "string" ? args.session : void 0;
4321
4633
  const collect = args.collect !== false;
4322
- if (!studioPath && !directCode.trim()) {
4323
- return {
4324
- content: [{ type: "text", text: "studio_to_live requires either studio_path or code" }],
4325
- isError: true
4326
- };
4327
- }
4328
4634
  let codeToRun = directCode;
4329
4635
  let sourceLabel = "inline Studio snippet";
4330
4636
  let resolvedStudioId = requestedStudioId;
4331
4637
  if (studioPath) {
4332
4638
  const studioRes = await this.studio.runStudioLuau(
4333
4639
  this.buildStudioReadScriptSourceCode(studioPath),
4334
- requestedStudioId
4640
+ requestedStudioId,
4641
+ datamodelType
4335
4642
  );
4336
4643
  if (!studioRes.ok) {
4337
4644
  return {
@@ -4358,14 +4665,17 @@ ${diffSummary}`);
4358
4665
  };
4359
4666
  }
4360
4667
  codeToRun = parsed.source;
4361
- sourceLabel = `${parsed.path} [${parsed.className}] (${codeToRun.length} bytes, studio_id=${resolvedStudioId ?? "auto"})`;
4668
+ sourceLabel = `${parsed.path} [${parsed.className}] (${codeToRun.length} bytes, studio_id=${resolvedStudioId ?? "auto"}, datamodel_type=${datamodelType})`;
4362
4669
  }
4363
4670
  const cloudTool = collect ? "run_and_collect" : "exec";
4364
4671
  const cloudArgs = {
4365
4672
  code: codeToRun,
4366
4673
  ...collect ? {
4367
4674
  wait_seconds: typeof args.wait_seconds === "number" ? args.wait_seconds : 1.5,
4368
- clean_env: typeof args.clean_env === "boolean" ? args.clean_env : true
4675
+ clean_env: typeof args.clean_env === "boolean" ? args.clean_env : true,
4676
+ ...typeof args.track_resources === "boolean" ? { track_resources: args.track_resources } : {},
4677
+ ...typeof args.auto_cleanup === "boolean" ? { auto_cleanup: args.auto_cleanup } : {},
4678
+ ...typeof args.settle_ms === "number" ? { settle_ms: args.settle_ms } : {}
4369
4679
  } : {},
4370
4680
  ...session ? { session } : {}
4371
4681
  };
@@ -4382,17 +4692,13 @@ ${liveRes.text}`
4382
4692
  };
4383
4693
  }
4384
4694
  async handleStudioPublish(args) {
4385
- const studioPath = typeof args.studio_path === "string" ? args.studio_path.trim() : "";
4386
- if (!studioPath) {
4387
- return {
4388
- content: [{ type: "text", text: "studio_publish requires studio_path" }],
4389
- isError: true
4390
- };
4391
- }
4695
+ const studioPath = typeof args.studio_path === "string" && args.studio_path.trim() ? args.studio_path.trim() : "Selection";
4696
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4392
4697
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4393
4698
  const studioRes = await this.studio.runStudioLuau(
4394
4699
  this.buildStudioReadScriptSourceCode(studioPath),
4395
- requestedStudioId
4700
+ requestedStudioId,
4701
+ datamodelType
4396
4702
  );
4397
4703
  if (!studioRes.ok) {
4398
4704
  return {
@@ -4417,18 +4723,22 @@ ${liveRes.text}`
4417
4723
  isError: true
4418
4724
  };
4419
4725
  }
4420
- const scriptId = typeof args.script_id === "string" ? args.script_id.trim() : "";
4421
- if (scriptId) {
4726
+ const scriptTarget = typeof args.script_id === "string" && args.script_id.trim() ? args.script_id.trim() : typeof args.script === "string" && args.script.trim() ? args.script.trim() : "";
4727
+ if (scriptTarget) {
4422
4728
  const deployRes = await this.callCloudTool("deploy_script", {
4423
- script_id: scriptId,
4729
+ ...typeof args.script_id === "string" && args.script_id.trim() ? { script_id: args.script_id.trim() } : {},
4730
+ ...typeof args.script === "string" && args.script.trim() ? { script: args.script.trim() } : {},
4731
+ ...!args.script_id && !args.script ? { script: scriptTarget } : {},
4424
4732
  source: parsed.source,
4425
- ...typeof args.note === "string" ? { note: args.note } : {}
4733
+ ...typeof args.note === "string" ? { note: args.note } : {},
4734
+ ...typeof args.publish === "boolean" ? { publish: args.publish } : {},
4735
+ ...typeof args.preset === "string" ? { preset: args.preset } : {}
4426
4736
  });
4427
4737
  return {
4428
4738
  content: [
4429
4739
  {
4430
4740
  type: "text",
4431
- text: `studio_publish deployed ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}) to Luaward script ${scriptId}:
4741
+ text: `studio_publish deployed ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}) to Luaward script ${scriptTarget}:
4432
4742
  ${deployRes.text}`
4433
4743
  }
4434
4744
  ],
@@ -4445,7 +4755,7 @@ ${deployRes.text}`
4445
4755
  content: [
4446
4756
  {
4447
4757
  type: "text",
4448
- text: `studio_publish created Luaward script "${scriptName}" from ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}):
4758
+ text: `studio_publish created Luaward script "${scriptName}" from ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):
4449
4759
  ${createRes.text}`
4450
4760
  }
4451
4761
  ],
@@ -4453,40 +4763,55 @@ ${createRes.text}`
4453
4763
  };
4454
4764
  }
4455
4765
  async handleLiveScriptsToStudio(args) {
4766
+ const targets = Array.isArray(args.targets) && args.targets.length > 0 ? args.targets.map(String) : [];
4456
4767
  const filter = typeof args.filter === "string" ? args.filter.trim() : "";
4457
- const containerName = typeof args.container_name === "string" && args.container_name.trim() ? args.container_name.trim() : "LuawardLiveScripts";
4458
- const limit = typeof args.limit === "number" ? Math.max(1, Math.min(50, args.limit)) : 15;
4768
+ const rawContainer = typeof args.container_name === "string" && args.container_name.trim() ? args.container_name.trim() : typeof args.studio_root === "string" && args.studio_root.trim() ? args.studio_root.trim() : "LuawardLiveScripts";
4769
+ const containerName = rawContainer.replace(/^ServerStorage\./, "") || "LuawardLiveScripts";
4770
+ const rawLimit = typeof args.max === "number" ? args.max : typeof args.limit === "number" ? args.limit : 15;
4771
+ const limit = Math.max(1, Math.min(100, Math.floor(rawLimit)));
4772
+ const disabled = args.disabled !== false;
4459
4773
  const includeDecompiled = args.include_decompiled !== false;
4774
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4460
4775
  const session = typeof args.session === "string" ? args.session : void 0;
4461
4776
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4462
4777
  const liveCollectCode = [
4463
4778
  "local HttpService = game:GetService('HttpService')",
4464
- `local filter = string.lower(${JSON.stringify(filter)})`,
4465
- `local limit = ${limit}`,
4466
- `local includeDecompiled = ${includeDecompiled ? "true" : "false"}`,
4779
+ `local targets = ${toLuauLiteral(targets)}`,
4780
+ `local filter = string.lower(${toLuauLiteral(filter)})`,
4781
+ `local limit = ${toLuauLiteral(limit)}`,
4782
+ `local includeDecompiled = ${toLuauLiteral(includeDecompiled)}`,
4467
4783
  "local roots = { game:GetService('ReplicatedStorage'), game:GetService('StarterPlayer'), game:GetService('Workspace'), game:GetService('Players').LocalPlayer }",
4468
4784
  "local results = {}",
4469
4785
  "local seen = {}",
4470
4786
  "local decompFn = (type(decompile) == 'function' and decompile) or (type(getscriptbytecode) == 'function' and function(s) local ok, b = pcall(getscriptbytecode, s); return ok and b and ('-- bytecode (' .. tostring(#b) .. ' bytes)') or nil end) or nil",
4471
- "for _, root in ipairs(roots) do",
4472
- " if root then",
4473
- " local ok, list = pcall(function() return root:GetDescendants() end)",
4474
- " if ok and type(list) == 'table' then",
4475
- " for _, inst in ipairs(list) do",
4476
- " if #results >= limit then break end",
4477
- " if not seen[inst] and (inst.ClassName == 'LocalScript' or inst.ClassName == 'ModuleScript') then",
4478
- " seen[inst] = true",
4479
- " local fullPath = inst:GetFullName()",
4480
- " if filter == '' or string.find(string.lower(fullPath), filter, 1, true) then",
4481
- " local src = '-- Live script: ' .. fullPath .. '\\n-- ClassName: ' .. inst.ClassName",
4482
- " if includeDecompiled and decompFn then",
4483
- " local okD, dec = pcall(decompFn, inst)",
4484
- " if okD and type(dec) == 'string' and #dec > 0 then",
4485
- " src = src .. '\\n\\n' .. dec:sub(1, 32000)",
4486
- " end",
4487
- " end",
4488
- " results[#results + 1] = { name = inst.Name, className = inst.ClassName, path = fullPath, source = src }",
4489
- " end",
4787
+ "local function collectOne(inst)",
4788
+ " if not inst or seen[inst] or #results >= limit then return end",
4789
+ " if inst.ClassName ~= 'LocalScript' and inst.ClassName ~= 'ModuleScript' then return end",
4790
+ " seen[inst] = true",
4791
+ " local fullPath = inst:GetFullName()",
4792
+ " if #targets == 0 and filter ~= '' and not string.find(string.lower(fullPath), filter, 1, true) then return end",
4793
+ " local src = '-- Live script: ' .. fullPath .. '\\n-- ClassName: ' .. inst.ClassName",
4794
+ " if includeDecompiled and decompFn then",
4795
+ " local okD, dec = pcall(decompFn, inst)",
4796
+ " if okD and type(dec) == 'string' and #dec > 0 then",
4797
+ " src = src .. '\\n\\n' .. dec:sub(1, 32000)",
4798
+ " end",
4799
+ " end",
4800
+ " results[#results + 1] = { name = inst.Name, className = inst.ClassName, path = fullPath, source = src }",
4801
+ "end",
4802
+ "if #targets > 0 and lw and lw.resolve then",
4803
+ " for _, tPath in ipairs(targets) do",
4804
+ " local inst = lw.resolve(tPath)",
4805
+ " if inst then collectOne(inst) end",
4806
+ " end",
4807
+ "else",
4808
+ " for _, root in ipairs(roots) do",
4809
+ " if root then",
4810
+ " local ok, list = pcall(function() return root:GetDescendants() end)",
4811
+ " if ok and type(list) == 'table' then",
4812
+ " for _, inst in ipairs(list) do",
4813
+ " if #results >= limit then break end",
4814
+ " collectOne(inst)",
4490
4815
  " end",
4491
4816
  " end",
4492
4817
  " end",
@@ -4512,10 +4837,10 @@ ${createRes.text}`
4512
4837
  }
4513
4838
  const scripts = this.extractJsonPayloadFromExec(liveRes.text) ?? [];
4514
4839
  const studioImportCode = [
4515
- "local HttpService = game:GetService('HttpService')",
4516
4840
  "local ServerStorage = game:GetService('ServerStorage')",
4517
- `local containerName = ${JSON.stringify(containerName)}`,
4518
- `local items = HttpService:JSONDecode(${JSON.stringify(JSON.stringify(scripts))})`,
4841
+ `local containerName = ${toLuauLiteral(containerName)}`,
4842
+ `local setDisabled = ${toLuauLiteral(disabled)}`,
4843
+ `local items = ${toLuauLiteral(scripts)}`,
4519
4844
  "local folder = ServerStorage:FindFirstChild(containerName)",
4520
4845
  "if not folder then",
4521
4846
  " folder = Instance.new('Folder')",
@@ -4528,6 +4853,9 @@ ${createRes.text}`
4528
4853
  " if ok and inst then",
4529
4854
  " inst.Name = item.name .. '_' .. tostring(imported + 1)",
4530
4855
  " pcall(function() inst:SetAttribute('LivePath', item.path) end)",
4856
+ " if setDisabled and (item.className == 'LocalScript' or item.className == 'Script') then",
4857
+ " pcall(function() inst.Disabled = true end)",
4858
+ " end",
4531
4859
  " pcall(function() inst.Source = item.source end)",
4532
4860
  " inst.Parent = folder",
4533
4861
  " imported = imported + 1",
@@ -4535,7 +4863,7 @@ ${createRes.text}`
4535
4863
  "end",
4536
4864
  "return string.format('imported %d live scripts into ServerStorage.%s', imported, containerName)"
4537
4865
  ].join("\n");
4538
- const studioRes = await this.studio.runStudioLuau(studioImportCode, requestedStudioId);
4866
+ const studioRes = await this.studio.runStudioLuau(studioImportCode, requestedStudioId, datamodelType);
4539
4867
  if (!studioRes.ok) {
4540
4868
  return {
4541
4869
  content: [
@@ -4553,7 +4881,7 @@ ${createRes.text}`
4553
4881
  {
4554
4882
  type: "text",
4555
4883
  text: [
4556
- `live_scripts_to_studio complete (studio_id=${studioRes.studioId ?? "auto"}):`,
4884
+ `live_scripts_to_studio complete (studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4557
4885
  `- Scripts collected from live game: ${scripts.length}`,
4558
4886
  `- Studio container: ServerStorage.${containerName}`,
4559
4887
  `- Studio result: ${studioRes.text}`,
@@ -4941,6 +5269,7 @@ export {
4941
5269
  buildListWindowsPsScript,
4942
5270
  buildRobloxDeepLink,
4943
5271
  buildScreenshotPsScript,
5272
+ buildStudioSpawnSpec,
4944
5273
  buildUiTreePsScript,
4945
5274
  buildUipiWarning,
4946
5275
  comparePngBase64,
@@ -4958,6 +5287,7 @@ export {
4958
5287
  resolveBridgeConfig,
4959
5288
  resolveStoredToken,
4960
5289
  resolveVirtualKeyCode,
4961
- startStdioBridge
5290
+ startStdioBridge,
5291
+ toLuauLiteral
4962
5292
  };
4963
5293
  //# sourceMappingURL=index.js.map