@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/cli.js CHANGED
@@ -239,7 +239,7 @@ var PotassiumClient = class {
239
239
  params: {
240
240
  protocolVersion: "2025-03-26",
241
241
  capabilities: {},
242
- clientInfo: { name: "@luaward/mcp", version: "0.2.3" }
242
+ clientInfo: { name: "@luaward/mcp", version: "0.2.5" }
243
243
  }
244
244
  })
245
245
  });
@@ -514,6 +514,105 @@ import { homedir as homedir2 } from "node:os";
514
514
  import { join as join2 } from "node:path";
515
515
  import { createInterface } from "node:readline";
516
516
  import { inflateSync } from "node:zlib";
517
+ var LUAU_RESERVED_KEYWORDS = /* @__PURE__ */ new Set([
518
+ "and",
519
+ "break",
520
+ "do",
521
+ "else",
522
+ "elseif",
523
+ "end",
524
+ "false",
525
+ "for",
526
+ "function",
527
+ "if",
528
+ "in",
529
+ "local",
530
+ "nil",
531
+ "not",
532
+ "or",
533
+ "repeat",
534
+ "return",
535
+ "then",
536
+ "true",
537
+ "until",
538
+ "while"
539
+ ]);
540
+ var LUAU_IDENT_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
541
+ function escapeLuauString(str) {
542
+ let out = '"';
543
+ for (let i = 0; i < str.length; i++) {
544
+ const code = str.charCodeAt(i);
545
+ if (code === 34) {
546
+ out += '\\"';
547
+ } else if (code === 92) {
548
+ out += "\\\\";
549
+ } else if (code === 10) {
550
+ out += "\\n";
551
+ } else if (code === 13) {
552
+ out += "\\r";
553
+ } else if (code === 9) {
554
+ out += "\\t";
555
+ } else if (code < 32 || code === 127) {
556
+ out += `\\${String(code).padStart(3, "0")}`;
557
+ } else {
558
+ out += str[i];
559
+ }
560
+ }
561
+ out += '"';
562
+ return out;
563
+ }
564
+ function toLuauLiteral(value) {
565
+ if (value === null || value === void 0) {
566
+ return "nil";
567
+ }
568
+ if (typeof value === "boolean") {
569
+ return value ? "true" : "false";
570
+ }
571
+ if (typeof value === "number") {
572
+ if (Number.isNaN(value)) return "0";
573
+ if (!Number.isFinite(value)) return value > 0 ? "math.huge" : "-math.huge";
574
+ return String(value);
575
+ }
576
+ if (typeof value === "string") {
577
+ return escapeLuauString(value);
578
+ }
579
+ if (Array.isArray(value)) {
580
+ if (value.length === 0) return "{}";
581
+ return `{ ${value.map((item) => toLuauLiteral(item)).join(", ")} }`;
582
+ }
583
+ if (typeof value === "object") {
584
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0);
585
+ if (entries.length === 0) return "{}";
586
+ const fields = entries.map(([k, v]) => {
587
+ const keyExpr = LUAU_IDENT_RE.test(k) && !LUAU_RESERVED_KEYWORDS.has(k) ? k : `[${escapeLuauString(k)}]`;
588
+ return `${keyExpr} = ${toLuauLiteral(v)}`;
589
+ });
590
+ return `{ ${fields.join(", ")} }`;
591
+ }
592
+ return "nil";
593
+ }
594
+ function buildStudioSpawnSpec(batchPath) {
595
+ const isBat = /\.(?:bat|cmd)$/i.test(batchPath);
596
+ if (isBat) {
597
+ return {
598
+ command: "cmd.exe",
599
+ args: ["/d", "/s", "/c", `"${batchPath}"`],
600
+ options: {
601
+ stdio: ["pipe", "pipe", "pipe"],
602
+ windowsVerbatimArguments: true,
603
+ windowsHide: true
604
+ }
605
+ };
606
+ }
607
+ return {
608
+ command: batchPath,
609
+ args: [],
610
+ options: {
611
+ stdio: ["pipe", "pipe", "pipe"],
612
+ windowsHide: true
613
+ }
614
+ };
615
+ }
517
616
  function discoverRobloxStudioMcpBatch(env = process.env) {
518
617
  if (env.ROBLOX_STUDIO_MCP_PATH?.trim()) {
519
618
  return env.ROBLOX_STUDIO_MCP_PATH.trim();
@@ -571,16 +670,19 @@ function parseStudioToolResponse(rpcRes) {
571
670
  var RobloxStudioMcpClient = class {
572
671
  batchPath;
573
672
  timeoutMs;
673
+ defaultDataModelType;
574
674
  customTransport;
575
675
  child = null;
576
676
  initPromise = null;
577
677
  pending = /* @__PURE__ */ new Map();
578
678
  rpcSeq = 9e3;
579
679
  cachedToolNames = null;
680
+ cachedToolSchemas = /* @__PURE__ */ new Map();
580
681
  exitHookInstalled = false;
581
682
  constructor(options = {}) {
582
683
  this.batchPath = options.batchPath || discoverRobloxStudioMcpBatch(options.env);
583
684
  this.timeoutMs = options.timeoutMs ?? 25e3;
685
+ this.defaultDataModelType = options.defaultDataModelType ?? "Edit";
584
686
  this.customTransport = options.transport;
585
687
  }
586
688
  dispose() {
@@ -610,14 +712,8 @@ var RobloxStudioMcpClient = class {
610
712
  `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.`
611
713
  );
612
714
  }
613
- const isBat = /\.(?:bat|cmd)$/i.test(this.batchPath);
614
- const child = isBat ? spawn("cmd.exe", ["/d", "/s", "/c", `"${this.batchPath}"`], {
615
- stdio: ["pipe", "pipe", "pipe"],
616
- windowsHide: true
617
- }) : spawn(this.batchPath, [], {
618
- stdio: ["pipe", "pipe", "pipe"],
619
- windowsHide: true
620
- });
715
+ const spec = buildStudioSpawnSpec(this.batchPath);
716
+ const child = spawn(spec.command, spec.args, spec.options);
621
717
  child.unref();
622
718
  this.child = child;
623
719
  if (!this.exitHookInstalled) {
@@ -658,7 +754,7 @@ var RobloxStudioMcpClient = class {
658
754
  await this.sendRawRpc("initialize", {
659
755
  protocolVersion: "2025-03-26",
660
756
  capabilities: {},
661
- clientInfo: { name: "@luaward/mcp", version: "0.2.3" }
757
+ clientInfo: { name: "@luaward/mcp", version: "0.2.5" }
662
758
  });
663
759
  if (this.child && !this.child.killed) {
664
760
  this.child.stdin.write(
@@ -701,6 +797,12 @@ var RobloxStudioMcpClient = class {
701
797
  const res = await this.sendRpc("tools/list", {});
702
798
  const tools = res?.result?.tools;
703
799
  if (Array.isArray(tools)) {
800
+ this.cachedToolSchemas.clear();
801
+ for (const t of tools) {
802
+ if (typeof t?.name === "string" && t.name && t.inputSchema && typeof t.inputSchema === "object") {
803
+ this.cachedToolSchemas.set(t.name, t.inputSchema);
804
+ }
805
+ }
704
806
  this.cachedToolNames = tools.map((t) => typeof t?.name === "string" ? t.name : "").filter(Boolean);
705
807
  return this.cachedToolNames;
706
808
  }
@@ -710,7 +812,8 @@ var RobloxStudioMcpClient = class {
710
812
  }
711
813
  async listStudios() {
712
814
  const tools = await this.listTools();
713
- const listToolName = tools.find((t) => t === "list_studios" || t === "get_studios" || t === "list_clients") ?? "list_studios";
815
+ const listPriority = ["list_roblox_studios", "list_studios", "get_studios", "list_clients"];
816
+ const listToolName = listPriority.find((candidate) => tools.includes(candidate)) ?? "list_roblox_studios";
714
817
  try {
715
818
  const rpcRes = await this.sendRpc("tools/call", { name: listToolName, arguments: {} });
716
819
  const parsed = parseStudioToolResponse(rpcRes);
@@ -725,19 +828,24 @@ var RobloxStudioMcpClient = class {
725
828
  if (item && typeof item === "object") {
726
829
  const obj = item;
727
830
  const sid = String(
728
- obj.studio_id ?? obj.studioId ?? obj.id ?? obj.session_id ?? obj.pid ?? ""
831
+ obj.id ?? obj.studio_id ?? obj.studioId ?? obj.session_id ?? obj.pid ?? ""
729
832
  ).trim();
730
833
  if (sid) {
834
+ const placeNameRaw = obj.place_name ?? obj.placeName ?? obj.local_file_name ?? obj.name;
731
835
  studios.push({
836
+ id: sid,
732
837
  studio_id: sid,
733
838
  place_id: obj.place_id ?? obj.placeId,
734
- place_name: typeof (obj.place_name ?? obj.placeName ?? obj.name) === "string" ? String(obj.place_name ?? obj.placeName ?? obj.name) : void 0,
839
+ game_id: obj.game_id ?? obj.gameId,
840
+ place_name: typeof placeNameRaw === "string" ? placeNameRaw : void 0,
841
+ local_file_name: typeof obj.local_file_name === "string" ? obj.local_file_name : void 0,
735
842
  user: typeof obj.user === "string" ? obj.user : void 0,
736
843
  raw: obj
737
844
  });
738
845
  }
739
846
  } else if (typeof item === "string" || typeof item === "number") {
740
- studios.push({ studio_id: String(item) });
847
+ const sid = String(item);
848
+ studios.push({ id: sid, studio_id: sid });
741
849
  }
742
850
  }
743
851
  return { ok: true, studios, rawText: parsed.text };
@@ -746,7 +854,7 @@ var RobloxStudioMcpClient = class {
746
854
  ...parsed.text.matchAll(/\b(?:studio_id|studioId|studio|id)[:=\s"']*([A-Za-z0-9_-]{2,64})\b/gi)
747
855
  ];
748
856
  for (const m of matches) {
749
- if (m[1]) studios.push({ studio_id: m[1] });
857
+ if (m[1]) studios.push({ id: m[1], studio_id: m[1] });
750
858
  }
751
859
  return { ok: true, studios, rawText: parsed.text };
752
860
  } catch (err) {
@@ -762,10 +870,11 @@ var RobloxStudioMcpClient = class {
762
870
  */
763
871
  async resolveStudioId(explicitStudioId) {
764
872
  if (explicitStudioId && explicitStudioId.trim()) {
873
+ const sid = explicitStudioId.trim();
765
874
  return {
766
875
  ok: true,
767
- studioId: explicitStudioId.trim(),
768
- studios: [{ studio_id: explicitStudioId.trim() }],
876
+ studioId: sid,
877
+ studios: [{ id: sid, studio_id: sid }],
769
878
  autoSelected: false
770
879
  };
771
880
  }
@@ -779,9 +888,10 @@ var RobloxStudioMcpClient = class {
779
888
  };
780
889
  }
781
890
  if (listed.studios.length === 1 && listed.studios[0]) {
891
+ const sid = listed.studios[0].id || listed.studios[0].studio_id;
782
892
  return {
783
893
  ok: true,
784
- studioId: listed.studios[0].studio_id,
894
+ studioId: sid,
785
895
  studios: listed.studios,
786
896
  autoSelected: true
787
897
  };
@@ -794,7 +904,7 @@ var RobloxStudioMcpClient = class {
794
904
  err: "No connected Roblox Studio instance found via %LOCALAPPDATA%\\Roblox\\mcp.bat. Open a place in Roblox Studio with MCP enabled first."
795
905
  };
796
906
  }
797
- const listStr = listed.studios.map((s) => `${s.studio_id}${s.place_name ? ` ("${s.place_name}")` : ""}`).join(", ");
907
+ const listStr = listed.studios.map((s) => `${s.id || s.studio_id}${s.place_name ? ` ("${s.place_name}")` : ""}`).join(", ");
798
908
  return {
799
909
  ok: false,
800
910
  studios: listed.studios,
@@ -806,7 +916,8 @@ var RobloxStudioMcpClient = class {
806
916
  const finalArgs = { ...args };
807
917
  let studioId = typeof finalArgs.studio_id === "string" ? finalArgs.studio_id.trim() : void 0;
808
918
  let autoSelected = false;
809
- if (!studioId && name !== "list_studios" && name !== "get_studios") {
919
+ const isListTool = name === "list_roblox_studios" || name === "list_studios" || name === "get_studios" || name === "list_clients";
920
+ if (!studioId && !isListTool) {
810
921
  const resolved = await this.resolveStudioId();
811
922
  if (!resolved.ok) {
812
923
  return { ok: false, text: resolved.err ?? "Failed to resolve studio_id", isError: true };
@@ -817,6 +928,12 @@ var RobloxStudioMcpClient = class {
817
928
  finalArgs.studio_id = studioId;
818
929
  }
819
930
  }
931
+ if (!isListTool && finalArgs.datamodel_type === void 0) {
932
+ const schemaProps = this.cachedToolSchemas.get(name)?.properties;
933
+ if (name === "execute_luau" || schemaProps && "datamodel_type" in schemaProps) {
934
+ finalArgs.datamodel_type = this.defaultDataModelType;
935
+ }
936
+ }
820
937
  try {
821
938
  const rpcRes = await this.sendRpc("tools/call", { name, arguments: finalArgs });
822
939
  const parsed = parseStudioToolResponse(rpcRes);
@@ -835,7 +952,7 @@ var RobloxStudioMcpClient = class {
835
952
  };
836
953
  }
837
954
  }
838
- async runStudioLuau(code, explicitStudioId) {
955
+ async runStudioLuau(code, explicitStudioId, datamodelType) {
839
956
  const resolved = await this.resolveStudioId(explicitStudioId);
840
957
  if (!resolved.ok) {
841
958
  return {
@@ -845,13 +962,30 @@ var RobloxStudioMcpClient = class {
845
962
  };
846
963
  }
847
964
  const tools = await this.listTools();
848
- const execTool = tools.find((t) => t === "run_code" || t === "execute_luau" || t === "run_script" || t === "eval") ?? "run_code";
849
- const res = await this.callTool(execTool, {
850
- command: code,
851
- code,
852
- source: code,
965
+ const execPriority = ["execute_luau", "run_code", "run_script", "eval"];
966
+ const execTool = execPriority.find((candidate) => tools.includes(candidate)) ?? "execute_luau";
967
+ const dmType = datamodelType ?? this.defaultDataModelType;
968
+ const schemaProps = this.cachedToolSchemas.get(execTool)?.properties;
969
+ const toolArgs = {
970
+ datamodel_type: dmType,
853
971
  ...resolved.studioId ? { studio_id: resolved.studioId } : {}
854
- });
972
+ };
973
+ if (execTool === "execute_luau") {
974
+ toolArgs.code = code;
975
+ if (schemaProps && "command" in schemaProps) {
976
+ toolArgs.command = code;
977
+ }
978
+ } else if (execTool === "run_code") {
979
+ toolArgs.command = code;
980
+ if (!schemaProps || "code" in schemaProps) {
981
+ toolArgs.code = code;
982
+ }
983
+ } else {
984
+ toolArgs.code = code;
985
+ toolArgs.command = code;
986
+ toolArgs.source = code;
987
+ }
988
+ const res = await this.callTool(execTool, toolArgs);
855
989
  return {
856
990
  ...res,
857
991
  studioId: resolved.studioId,
@@ -2232,7 +2366,7 @@ function matchesWindowTarget(w, filter) {
2232
2366
  }
2233
2367
 
2234
2368
  // src/index.ts
2235
- var MCP_BRIDGE_VERSION = "0.2.3";
2369
+ var MCP_BRIDGE_VERSION = "0.2.5";
2236
2370
  var DEFAULT_MCP_URL = "https://luaward.com/mcp";
2237
2371
  var TOKEN_CREATE_URL = "https://dash.luaward.com/dashboard/ai";
2238
2372
  var TOKEN_SHAPE = /^lwm_[0-9a-f]{48}$/;
@@ -2748,7 +2882,12 @@ var LOCAL_HYBRID_TOOLS = [
2748
2882
  properties: {
2749
2883
  root: {
2750
2884
  type: "string",
2751
- description: "Root service/path to mirror (default 'ReplicatedStorage')"
2885
+ description: "Root service or dotted path to mirror (e.g. 'ReplicatedStorage' or 'ReplicatedStorage.Remotes')"
2886
+ },
2887
+ roots: {
2888
+ type: "array",
2889
+ items: { type: "string" },
2890
+ description: "Optional list of root services to mirror when root is omitted (default ['ReplicatedStorage', 'Workspace'])"
2752
2891
  },
2753
2892
  filter: {
2754
2893
  type: "string",
@@ -2765,6 +2904,21 @@ var LOCAL_HYBRID_TOOLS = [
2765
2904
  maximum: 500,
2766
2905
  description: "Maximum remotes to mirror (default 200)"
2767
2906
  },
2907
+ max_depth: {
2908
+ type: "integer",
2909
+ minimum: 1,
2910
+ maximum: 12,
2911
+ description: "Maximum hierarchy depth (default 6)"
2912
+ },
2913
+ clear_existing: {
2914
+ type: "boolean",
2915
+ description: "Recreate existing remotes of the same class in Studio (default false)"
2916
+ },
2917
+ datamodel_type: {
2918
+ type: "string",
2919
+ enum: ["Edit", "Client", "Server"],
2920
+ description: "Roblox Studio DataModel context (default 'Edit'; use 'Client' or 'Server' during playtest)"
2921
+ },
2768
2922
  studio_id: {
2769
2923
  type: "string",
2770
2924
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -2795,26 +2949,49 @@ var LOCAL_HYBRID_TOOLS = [
2795
2949
  type: "string",
2796
2950
  description: "Live GUI root path or #n handle to mirror (default 'Players.LocalPlayer.PlayerGui')"
2797
2951
  },
2952
+ target_path: {
2953
+ type: "string",
2954
+ description: "Alias for target (live GUI path or #n handle to mirror)"
2955
+ },
2798
2956
  studio_root: {
2799
2957
  type: "string",
2800
- description: "Destination container in Roblox Studio (default 'StarterGui')"
2958
+ description: "Destination container name in Roblox Studio StarterGui (default 'LuawardMirroredGui')"
2959
+ },
2960
+ container_name: {
2961
+ type: "string",
2962
+ description: "Alias for studio_root container folder name inside StarterGui (default 'LuawardMirroredGui')"
2801
2963
  },
2802
2964
  depth: {
2803
2965
  type: "integer",
2804
2966
  minimum: 1,
2805
2967
  maximum: 12,
2806
- description: "Maximum hierarchy depth (default 6)"
2968
+ description: "Maximum hierarchy depth (default 10)"
2807
2969
  },
2808
2970
  max_instances: {
2809
2971
  type: "integer",
2810
2972
  minimum: 1,
2811
- maximum: 600,
2973
+ maximum: 1e3,
2812
2974
  description: "Maximum GUI instances to mirror (default 250)"
2813
2975
  },
2976
+ max_nodes: {
2977
+ type: "integer",
2978
+ minimum: 1,
2979
+ maximum: 1e3,
2980
+ description: "Alias for max_instances (default 250)"
2981
+ },
2814
2982
  only_visible: {
2815
2983
  type: "boolean",
2816
2984
  description: "Only mirror visible GUI elements (default false)"
2817
2985
  },
2986
+ include_core_gui: {
2987
+ type: "boolean",
2988
+ description: "Include non-RobloxGui ScreenGuis from CoreGui (default false)"
2989
+ },
2990
+ datamodel_type: {
2991
+ type: "string",
2992
+ enum: ["Edit", "Client", "Server"],
2993
+ description: "Roblox Studio DataModel context (default 'Edit')"
2994
+ },
2818
2995
  studio_id: {
2819
2996
  type: "string",
2820
2997
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -2837,18 +3014,34 @@ var LOCAL_HYBRID_TOOLS = [
2837
3014
  {
2838
3015
  name: "studio_diff",
2839
3016
  title: "Diff scripts, remotes, or GUI between Roblox Studio and live game",
2840
- 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.",
3017
+ 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.",
2841
3018
  inputSchema: {
2842
3019
  type: "object",
2843
3020
  properties: {
2844
3021
  scope: {
2845
3022
  type: "string",
2846
3023
  enum: ["scripts", "remotes", "gui", "all"],
2847
- description: "What to compare (default 'scripts')"
3024
+ description: "What to compare (default 'all')"
2848
3025
  },
2849
3026
  target: {
2850
3027
  type: "string",
2851
- description: "Optional root or specific script path to compare (default 'ReplicatedStorage')"
3028
+ description: "Optional root service to compare (e.g. 'ReplicatedStorage')"
3029
+ },
3030
+ roots: {
3031
+ type: "array",
3032
+ items: { type: "string" },
3033
+ description: "Optional list of root services to compare (default ['ReplicatedStorage', 'StarterGui', 'Workspace'])"
3034
+ },
3035
+ max_depth: {
3036
+ type: "integer",
3037
+ minimum: 1,
3038
+ maximum: 10,
3039
+ description: "Maximum hierarchy depth (default 5)"
3040
+ },
3041
+ datamodel_type: {
3042
+ type: "string",
3043
+ enum: ["Edit", "Client", "Server"],
3044
+ description: "Roblox Studio DataModel context (default 'Edit')"
2852
3045
  },
2853
3046
  studio_id: {
2854
3047
  type: "string",
@@ -2880,6 +3073,18 @@ var LOCAL_HYBRID_TOOLS = [
2880
3073
  type: "string",
2881
3074
  description: "Script path in Roblox Studio (e.g. 'StarterPlayer.StarterPlayerScripts.Main') or 'Selection' for currently selected script (default 'Selection')"
2882
3075
  },
3076
+ code: {
3077
+ type: "string",
3078
+ description: "Optional inline Luau code to run instead of reading from studio_path"
3079
+ },
3080
+ collect: {
3081
+ type: "boolean",
3082
+ description: "Use run_and_collect instead of exec (default true)"
3083
+ },
3084
+ wait_seconds: {
3085
+ type: "number",
3086
+ description: "Wait time in seconds for run_and_collect (default 1.5)"
3087
+ },
2883
3088
  clean_env: {
2884
3089
  type: "boolean",
2885
3090
  description: "Run in clean native Luau SAFEENV environment (default true)"
@@ -2898,6 +3103,11 @@ var LOCAL_HYBRID_TOOLS = [
2898
3103
  maximum: 15e3,
2899
3104
  description: "Settle window in ms after return (default 300)"
2900
3105
  },
3106
+ datamodel_type: {
3107
+ type: "string",
3108
+ enum: ["Edit", "Client", "Server"],
3109
+ description: "Roblox Studio DataModel context (default 'Edit')"
3110
+ },
2901
3111
  studio_id: {
2902
3112
  type: "string",
2903
3113
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -2920,13 +3130,29 @@ var LOCAL_HYBRID_TOOLS = [
2920
3130
  {
2921
3131
  name: "studio_publish",
2922
3132
  title: "Publish a Roblox Studio script to Luaward Cloud",
2923
- 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.",
3133
+ description: "Read a script's Luau source directly from Roblox Studio (%LOCALAPPDATA%\\Roblox\\mcp.bat) and create or deploy/protect it on Luaward Cloud.",
2924
3134
  inputSchema: {
2925
3135
  type: "object",
2926
3136
  properties: {
2927
3137
  script: {
2928
3138
  type: "string",
2929
- description: "Target Luaward Cloud script name or ID"
3139
+ description: "Target Luaward Cloud script name or ID to deploy to"
3140
+ },
3141
+ script_id: {
3142
+ type: "string",
3143
+ description: "Target Luaward Cloud script ID to deploy to"
3144
+ },
3145
+ name: {
3146
+ type: "string",
3147
+ description: "New Luaward Cloud script name when creating a new script"
3148
+ },
3149
+ description: {
3150
+ type: "string",
3151
+ description: "Optional description when creating a new Luaward script"
3152
+ },
3153
+ note: {
3154
+ type: "string",
3155
+ description: "Optional build note when deploying to an existing Luaward script"
2930
3156
  },
2931
3157
  studio_path: {
2932
3158
  type: "string",
@@ -2941,12 +3167,16 @@ var LOCAL_HYBRID_TOOLS = [
2941
3167
  enum: ["fast", "balanced", "max"],
2942
3168
  description: "Optional protection preset"
2943
3169
  },
3170
+ datamodel_type: {
3171
+ type: "string",
3172
+ enum: ["Edit", "Client", "Server"],
3173
+ description: "Roblox Studio DataModel context (default 'Edit')"
3174
+ },
2944
3175
  studio_id: {
2945
3176
  type: "string",
2946
3177
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
2947
3178
  }
2948
3179
  },
2949
- required: ["script"],
2950
3180
  additionalProperties: false
2951
3181
  },
2952
3182
  annotations: {
@@ -2975,7 +3205,11 @@ var LOCAL_HYBRID_TOOLS = [
2975
3205
  },
2976
3206
  studio_root: {
2977
3207
  type: "string",
2978
- description: "Optional destination container in Studio (e.g. 'ServerStorage.LiveImports'; omit to mirror into matching services)"
3208
+ description: "Optional destination container in Studio ServerStorage (default 'LuawardLiveScripts')"
3209
+ },
3210
+ container_name: {
3211
+ type: "string",
3212
+ description: "Alias for studio_root destination folder name in ServerStorage (default 'LuawardLiveScripts')"
2979
3213
  },
2980
3214
  max: {
2981
3215
  type: "integer",
@@ -2983,10 +3217,25 @@ var LOCAL_HYBRID_TOOLS = [
2983
3217
  maximum: 100,
2984
3218
  description: "Maximum scripts to import in one call (default 15)"
2985
3219
  },
3220
+ limit: {
3221
+ type: "integer",
3222
+ minimum: 1,
3223
+ maximum: 100,
3224
+ description: "Alias for max (default 15)"
3225
+ },
2986
3226
  disabled: {
2987
3227
  type: "boolean",
2988
3228
  description: "Set .Disabled = true on imported LocalScripts in Studio (default true)"
2989
3229
  },
3230
+ include_decompiled: {
3231
+ type: "boolean",
3232
+ description: "Decompile script source via decompile() in the live executor (default true)"
3233
+ },
3234
+ datamodel_type: {
3235
+ type: "string",
3236
+ enum: ["Edit", "Client", "Server"],
3237
+ description: "Roblox Studio DataModel context (default 'Edit')"
3238
+ },
2990
3239
  studio_id: {
2991
3240
  type: "string",
2992
3241
  description: "Optional Roblox Studio instance ID (auto-filled when 1 Studio is open)"
@@ -3716,7 +3965,7 @@ ${lines.join("\n")}` }]
3716
3965
  };
3717
3966
  }
3718
3967
  const lookupCode = [
3719
- `local inst, err = lw.resolve(${JSON.stringify(target)})`,
3968
+ `local inst, err = lw.resolve(${toLuauLiteral(target)})`,
3720
3969
  "if not inst then error(err or 'target not found') end",
3721
3970
  "local pos, size = inst.AbsolutePosition, inst.AbsoluteSize",
3722
3971
  "if not (pos and size) then error(lw.path(inst) .. ' has no AbsolutePosition/AbsoluteSize') end",
@@ -3916,35 +4165,75 @@ ${diffSummary}`);
3916
4165
  }
3917
4166
  return null;
3918
4167
  }
4168
+ parseStudioDataModelType(raw) {
4169
+ if (raw === "Client" || raw === "Server" || raw === "Edit") {
4170
+ return raw;
4171
+ }
4172
+ return "Edit";
4173
+ }
3919
4174
  async handleStudioMirrorRemotes(args) {
3920
- const roots = Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "Workspace"];
3921
- const maxDepth = typeof args.max_depth === "number" ? Math.max(1, Math.min(12, args.max_depth)) : 6;
4175
+ const singleRoot = typeof args.root === "string" && args.root.trim() ? args.root.trim() : "";
4176
+ const roots = singleRoot ? [singleRoot] : Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "Workspace"];
4177
+ const filter = typeof args.filter === "string" ? args.filter.trim().toLowerCase() : "";
4178
+ const kind = args.kind === "network" || args.kind === "bindable" ? args.kind : "all";
4179
+ const max = typeof args.max === "number" ? Math.max(1, Math.min(500, Math.floor(args.max))) : 200;
4180
+ const maxDepth = typeof args.max_depth === "number" ? Math.max(1, Math.min(12, Math.floor(args.max_depth))) : 6;
3922
4181
  const clearExisting = args.clear_existing === true;
4182
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
3923
4183
  const session = typeof args.session === "string" ? args.session : void 0;
3924
4184
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4185
+ const remoteClassesMap = kind === "network" ? { RemoteEvent: true, RemoteFunction: true, UnreliableRemoteEvent: true } : kind === "bindable" ? { BindableEvent: true, BindableFunction: true } : {
4186
+ RemoteEvent: true,
4187
+ RemoteFunction: true,
4188
+ UnreliableRemoteEvent: true,
4189
+ BindableEvent: true,
4190
+ BindableFunction: true
4191
+ };
3925
4192
  const liveScanCode = [
3926
4193
  "local HttpService = game:GetService('HttpService')",
3927
- `local roots = ${JSON.stringify(roots)}`,
3928
- `local maxDepth = ${maxDepth}`,
3929
- "local remoteClasses = { RemoteEvent = true, RemoteFunction = true, UnreliableRemoteEvent = true, BindableEvent = true, BindableFunction = true }",
4194
+ `local roots = ${toLuauLiteral(roots)}`,
4195
+ `local filter = ${toLuauLiteral(filter)}`,
4196
+ `local maxItems = ${toLuauLiteral(max)}`,
4197
+ `local maxDepth = ${toLuauLiteral(maxDepth)}`,
4198
+ `local remoteClasses = ${toLuauLiteral(remoteClassesMap)}`,
3930
4199
  "local items = {}",
4200
+ "local function resolveRoot(rPath)",
4201
+ " local segs = {}",
4202
+ " for seg in string.gmatch(rPath, '[^%.]+') do segs[#segs + 1] = seg end",
4203
+ " if #segs == 0 then return nil, nil, nil end",
4204
+ " local startIdx = (segs[1] == 'game') and 2 or 1",
4205
+ " local rootName = segs[startIdx]",
4206
+ " if not rootName then return nil, nil, nil end",
4207
+ " local ok, cur = pcall(function() return game:GetService(rootName) end)",
4208
+ " if not ok or not cur then return nil, nil, nil end",
4209
+ " local baseSegs = {}",
4210
+ " for i = startIdx + 1, #segs do",
4211
+ " cur = cur and cur:FindFirstChild(segs[i])",
4212
+ " baseSegs[#baseSegs + 1] = segs[i]",
4213
+ " end",
4214
+ " return cur, rootName, baseSegs",
4215
+ "end",
3931
4216
  "local function scan(inst, rootName, segs, depth)",
3932
- " if depth > maxDepth then return end",
4217
+ " if depth > maxDepth or #items >= maxItems then return end",
3933
4218
  " for _, child in ipairs(inst:GetChildren()) do",
4219
+ " if #items >= maxItems then break end",
3934
4220
  " local nextSegs = {}",
3935
4221
  " for i = 1, #segs do nextSegs[i] = segs[i] end",
3936
4222
  " nextSegs[#nextSegs + 1] = child.Name",
4223
+ " local fullPath = rootName .. '.' .. table.concat(nextSegs, '.')",
3937
4224
  " if remoteClasses[child.ClassName] then",
3938
- " items[#items + 1] = { root = rootName, className = child.ClassName, segments = nextSegs, path = rootName .. '.' .. table.concat(nextSegs, '.') }",
4225
+ " if filter == '' or string.find(string.lower(fullPath), filter, 1, true) then",
4226
+ " items[#items + 1] = { root = rootName, className = child.ClassName, segments = nextSegs, path = fullPath }",
4227
+ " end",
3939
4228
  " end",
3940
- " if #child:GetChildren() > 0 then",
4229
+ " if #child:GetChildren() > 0 and #items < maxItems then",
3941
4230
  " scan(child, rootName, nextSegs, depth + 1)",
3942
4231
  " end",
3943
4232
  " end",
3944
4233
  "end",
3945
- "for _, rName in ipairs(roots) do",
3946
- " local ok, svc = pcall(function() return game:GetService(rName) end)",
3947
- " if ok and svc then scan(svc, rName, {}, 1) end",
4234
+ "for _, rPath in ipairs(roots) do",
4235
+ " local inst, rootName, baseSegs = resolveRoot(rPath)",
4236
+ " if inst and rootName and baseSegs then scan(inst, rootName, baseSegs, 1) end",
3948
4237
  "end",
3949
4238
  "return HttpService:JSONEncode(items)"
3950
4239
  ].join("\n");
@@ -3961,9 +4250,8 @@ ${diffSummary}`);
3961
4250
  }
3962
4251
  const items = this.extractJsonPayloadFromExec(liveRes.text) ?? [];
3963
4252
  const studioCode = [
3964
- "local HttpService = game:GetService('HttpService')",
3965
- `local items = HttpService:JSONDecode(${JSON.stringify(JSON.stringify(items))})`,
3966
- `local clearExisting = ${clearExisting ? "true" : "false"}`,
4253
+ `local items = ${toLuauLiteral(items)}`,
4254
+ `local clearExisting = ${toLuauLiteral(clearExisting)}`,
3967
4255
  "local created, existing = 0, 0",
3968
4256
  "for _, item in ipairs(items) do",
3969
4257
  " local ok, rootInst = pcall(function() return game:GetService(item.root) end)",
@@ -4001,7 +4289,7 @@ ${diffSummary}`);
4001
4289
  "end",
4002
4290
  "return string.format('mirrored %d remotes (created=%d, existing=%d)', #items, created, existing)"
4003
4291
  ].join("\n");
4004
- const studioRes = await this.studio.runStudioLuau(studioCode, requestedStudioId);
4292
+ const studioRes = await this.studio.runStudioLuau(studioCode, requestedStudioId, datamodelType);
4005
4293
  if (!studioRes.ok) {
4006
4294
  return {
4007
4295
  content: [
@@ -4019,8 +4307,8 @@ ${diffSummary}`);
4019
4307
  {
4020
4308
  type: "text",
4021
4309
  text: [
4022
- `studio_mirror_remotes complete (studio_id=${studioRes.studioId ?? "auto"}):`,
4023
- `- Live remotes discovered: ${items.length} across ${roots.join(", ")}`,
4310
+ `studio_mirror_remotes complete (studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4311
+ `- Live remotes discovered: ${items.length} across ${roots.join(", ")} (kind=${kind}${filter ? `, filter="${filter}"` : ""}, max=${max})`,
4024
4312
  `- Studio result: ${studioRes.text}`,
4025
4313
  ...samplePaths.length > 0 ? ["- Sample mirrored paths:", ...samplePaths] : []
4026
4314
  ].join("\n")
@@ -4029,25 +4317,37 @@ ${diffSummary}`);
4029
4317
  };
4030
4318
  }
4031
4319
  async handleStudioMirrorGui(args) {
4032
- const targetPath = typeof args.target_path === "string" ? args.target_path.trim() : "";
4033
- const containerName = typeof args.container_name === "string" && args.container_name.trim() ? args.container_name.trim() : "LuawardMirroredGui";
4034
- const maxNodes = typeof args.max_nodes === "number" ? Math.max(10, Math.min(1e3, args.max_nodes)) : 250;
4320
+ 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() : "";
4321
+ const targetPath = rawTarget === "Players.LocalPlayer.PlayerGui" || rawTarget === "PlayerGui" ? "" : rawTarget;
4322
+ 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";
4323
+ const containerName = rawContainer === "StarterGui" ? "LuawardMirroredGui" : rawContainer.replace(/^StarterGui\./, "") || "LuawardMirroredGui";
4324
+ const maxDepth = typeof args.depth === "number" ? Math.max(1, Math.min(12, Math.floor(args.depth))) : 10;
4325
+ const rawMaxNodes = typeof args.max_nodes === "number" ? args.max_nodes : typeof args.max_instances === "number" ? args.max_instances : 250;
4326
+ const maxNodes = Math.max(1, Math.min(1e3, Math.floor(rawMaxNodes)));
4327
+ const onlyVisible = args.only_visible === true;
4035
4328
  const includeCoreGui = args.include_core_gui === true;
4329
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4036
4330
  const session = typeof args.session === "string" ? args.session : void 0;
4037
4331
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4038
4332
  const liveGuiCode = [
4039
4333
  "local HttpService = game:GetService('HttpService')",
4040
4334
  "local Players = game:GetService('Players')",
4041
- `local targetPath = ${JSON.stringify(targetPath)}`,
4042
- `local maxNodes = ${maxNodes}`,
4043
- `local includeCore = ${includeCoreGui ? "true" : "false"}`,
4335
+ `local targetPath = ${toLuauLiteral(targetPath)}`,
4336
+ `local maxNodes = ${toLuauLiteral(maxNodes)}`,
4337
+ `local maxDepth = ${toLuauLiteral(maxDepth)}`,
4338
+ `local onlyVisible = ${toLuauLiteral(onlyVisible)}`,
4339
+ `local includeCore = ${toLuauLiteral(includeCoreGui)}`,
4044
4340
  "local nodes = {}",
4045
4341
  "local count = 0",
4046
4342
  "local function serColor(c) return c and { c.R, c.G, c.B } or nil end",
4047
4343
  "local function serUDim2(u) return u and { u.X.Scale, u.X.Offset, u.Y.Scale, u.Y.Offset } or nil end",
4048
4344
  "local function serVec2(v) return v and { v.X, v.Y } or nil end",
4049
4345
  "local function serializeTree(inst, depth)",
4050
- " if count >= maxNodes or depth > 10 then return nil end",
4346
+ " if count >= maxNodes or depth > maxDepth then return nil end",
4347
+ " if onlyVisible then",
4348
+ " if inst:IsA('LayerCollector') and inst.Enabled == false then return nil end",
4349
+ " if inst:IsA('GuiObject') and inst.Visible == false then return nil end",
4350
+ " end",
4051
4351
  " count = count + 1",
4052
4352
  " local node = { className = inst.ClassName, name = inst.Name, children = {} }",
4053
4353
  " pcall(function()",
@@ -4080,7 +4380,10 @@ ${diffSummary}`);
4080
4380
  "end",
4081
4381
  "if targetPath ~= '' and lw and lw.resolve then",
4082
4382
  " local inst = lw.resolve(targetPath)",
4083
- " if inst then nodes[#nodes + 1] = serializeTree(inst, 1) end",
4383
+ " if inst then",
4384
+ " local n = serializeTree(inst, 1)",
4385
+ " if n then nodes[#nodes + 1] = n end",
4386
+ " end",
4084
4387
  "else",
4085
4388
  " local lp = Players.LocalPlayer",
4086
4389
  " local pgui = lp and lp:FindFirstChildOfClass('PlayerGui')",
@@ -4122,10 +4425,9 @@ ${diffSummary}`);
4122
4425
  trees: []
4123
4426
  };
4124
4427
  const studioBuildCode = [
4125
- "local HttpService = game:GetService('HttpService')",
4126
4428
  "local StarterGui = game:GetService('StarterGui')",
4127
- `local containerName = ${JSON.stringify(containerName)}`,
4128
- `local payload = HttpService:JSONDecode(${JSON.stringify(JSON.stringify(payload))})`,
4429
+ `local containerName = ${toLuauLiteral(containerName)}`,
4430
+ `local payload = ${toLuauLiteral(payload)}`,
4129
4431
  "local folder = StarterGui:FindFirstChild(containerName)",
4130
4432
  "if folder then folder:Destroy() end",
4131
4433
  "folder = Instance.new('Folder')",
@@ -4168,7 +4470,7 @@ ${diffSummary}`);
4168
4470
  "for _, tree in ipairs(payload.trees or {}) do buildNode(tree, folder) end",
4169
4471
  "return string.format('mirrored %d GUI nodes into StarterGui.%s', created, containerName)"
4170
4472
  ].join("\n");
4171
- const studioRes = await this.studio.runStudioLuau(studioBuildCode, requestedStudioId);
4473
+ const studioRes = await this.studio.runStudioLuau(studioBuildCode, requestedStudioId, datamodelType);
4172
4474
  if (!studioRes.ok) {
4173
4475
  return {
4174
4476
  content: [
@@ -4185,7 +4487,7 @@ ${diffSummary}`);
4185
4487
  {
4186
4488
  type: "text",
4187
4489
  text: [
4188
- `studio_mirror_gui complete (studio_id=${studioRes.studioId ?? "auto"}):`,
4490
+ `studio_mirror_gui complete (studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4189
4491
  `- Live GUI nodes serialized: ${payload.count} (${payload.trees.length} root trees)`,
4190
4492
  `- Studio container: StarterGui.${containerName}`,
4191
4493
  `- Studio result: ${studioRes.text}`
@@ -4195,17 +4497,19 @@ ${diffSummary}`);
4195
4497
  };
4196
4498
  }
4197
4499
  async handleStudioDiff(args) {
4198
- const roots = Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "StarterGui", "Workspace"];
4500
+ const singleTarget = typeof args.target === "string" && args.target.trim() ? args.target.trim() : "";
4501
+ const roots = singleTarget ? [singleTarget] : Array.isArray(args.roots) && args.roots.length > 0 ? args.roots.map(String) : ["ReplicatedStorage", "StarterGui", "Workspace"];
4199
4502
  const scope = typeof args.scope === "string" ? args.scope : "all";
4200
4503
  const maxDepth = typeof args.max_depth === "number" ? Math.max(1, Math.min(10, args.max_depth)) : 5;
4504
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4201
4505
  const session = typeof args.session === "string" ? args.session : void 0;
4202
4506
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4203
4507
  const buildDiffScanCode = (isLive) => [
4204
4508
  "local HttpService = game:GetService('HttpService')",
4205
- `local roots = ${JSON.stringify(roots)}`,
4206
- `local scope = ${JSON.stringify(scope)}`,
4207
- `local maxDepth = ${maxDepth}`,
4208
- `local isLive = ${isLive ? "true" : "false"}`,
4509
+ `local roots = ${toLuauLiteral(roots)}`,
4510
+ `local scope = ${toLuauLiteral(scope)}`,
4511
+ `local maxDepth = ${toLuauLiteral(maxDepth)}`,
4512
+ `local isLive = ${toLuauLiteral(isLive)}`,
4209
4513
  "local entries = {}",
4210
4514
  "local count = 0",
4211
4515
  "local remoteClasses = { RemoteEvent = true, RemoteFunction = true, UnreliableRemoteEvent = true, BindableEvent = true, BindableFunction = true }",
@@ -4245,7 +4549,7 @@ ${diffSummary}`);
4245
4549
  readonly: true,
4246
4550
  ...session ? { session } : {}
4247
4551
  }),
4248
- this.studio.runStudioLuau(buildDiffScanCode(false), requestedStudioId)
4552
+ this.studio.runStudioLuau(buildDiffScanCode(false), requestedStudioId, datamodelType)
4249
4553
  ]);
4250
4554
  if (!liveRes.ok) {
4251
4555
  return {
@@ -4285,7 +4589,7 @@ ${diffSummary}`);
4285
4589
  }
4286
4590
  }
4287
4591
  const lines = [
4288
- `studio_diff report (scope=${scope}, roots=${roots.join(", ")}, studio_id=${studioRes.studioId ?? "auto"}):`,
4592
+ `studio_diff report (scope=${scope}, roots=${roots.join(", ")}, studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4289
4593
  `- Matched instances: ${matchedCount}`,
4290
4594
  `- Only in Live Game: ${onlyInLive.length}`,
4291
4595
  ...onlyInLive.slice(0, 20).map((x) => ` + [Live] ${x}`),
@@ -4303,15 +4607,22 @@ ${diffSummary}`);
4303
4607
  buildStudioReadScriptSourceCode(studioPath) {
4304
4608
  return [
4305
4609
  "local HttpService = game:GetService('HttpService')",
4306
- `local pathStr = ${JSON.stringify(studioPath)}`,
4307
- "local segs = {}",
4308
- "for seg in string.gmatch(pathStr, '[^%.]+') do segs[#segs + 1] = seg end",
4309
- "if #segs == 0 then error('Empty studio_path') end",
4310
- "local startIdx = 1",
4311
- "if segs[1] == 'game' then startIdx = 2 end",
4312
- "local cur = game:GetService(segs[startIdx])",
4313
- "for i = startIdx + 1, #segs do",
4314
- " cur = cur and cur:FindFirstChild(segs[i])",
4610
+ `local pathStr = ${toLuauLiteral(studioPath)}`,
4611
+ "local cur = nil",
4612
+ "if pathStr == '' or pathStr == 'Selection' then",
4613
+ " local sel = game:GetService('Selection'):Get()",
4614
+ " cur = sel and sel[1] or nil",
4615
+ " if not cur then error('No script is currently selected in Roblox Studio Selection') end",
4616
+ "else",
4617
+ " local segs = {}",
4618
+ " for seg in string.gmatch(pathStr, '[^%.]+') do segs[#segs + 1] = seg end",
4619
+ " if #segs == 0 then error('Empty studio_path') end",
4620
+ " local startIdx = 1",
4621
+ " if segs[1] == 'game' then startIdx = 2 end",
4622
+ " cur = game:GetService(segs[startIdx])",
4623
+ " for i = startIdx + 1, #segs do",
4624
+ " cur = cur and cur:FindFirstChild(segs[i])",
4625
+ " end",
4315
4626
  "end",
4316
4627
  "if not cur then error('Studio instance not found: ' .. pathStr) end",
4317
4628
  "local ok, src = pcall(function() return cur.Source end)",
@@ -4320,24 +4631,20 @@ ${diffSummary}`);
4320
4631
  ].join("\n");
4321
4632
  }
4322
4633
  async handleStudioToLive(args) {
4323
- const studioPath = typeof args.studio_path === "string" ? args.studio_path.trim() : "";
4324
4634
  const directCode = typeof args.code === "string" ? args.code : "";
4635
+ const studioPath = typeof args.studio_path === "string" && args.studio_path.trim() ? args.studio_path.trim() : directCode.trim() ? "" : "Selection";
4636
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4325
4637
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4326
4638
  const session = typeof args.session === "string" ? args.session : void 0;
4327
4639
  const collect = args.collect !== false;
4328
- if (!studioPath && !directCode.trim()) {
4329
- return {
4330
- content: [{ type: "text", text: "studio_to_live requires either studio_path or code" }],
4331
- isError: true
4332
- };
4333
- }
4334
4640
  let codeToRun = directCode;
4335
4641
  let sourceLabel = "inline Studio snippet";
4336
4642
  let resolvedStudioId = requestedStudioId;
4337
4643
  if (studioPath) {
4338
4644
  const studioRes = await this.studio.runStudioLuau(
4339
4645
  this.buildStudioReadScriptSourceCode(studioPath),
4340
- requestedStudioId
4646
+ requestedStudioId,
4647
+ datamodelType
4341
4648
  );
4342
4649
  if (!studioRes.ok) {
4343
4650
  return {
@@ -4364,14 +4671,17 @@ ${diffSummary}`);
4364
4671
  };
4365
4672
  }
4366
4673
  codeToRun = parsed.source;
4367
- sourceLabel = `${parsed.path} [${parsed.className}] (${codeToRun.length} bytes, studio_id=${resolvedStudioId ?? "auto"})`;
4674
+ sourceLabel = `${parsed.path} [${parsed.className}] (${codeToRun.length} bytes, studio_id=${resolvedStudioId ?? "auto"}, datamodel_type=${datamodelType})`;
4368
4675
  }
4369
4676
  const cloudTool = collect ? "run_and_collect" : "exec";
4370
4677
  const cloudArgs = {
4371
4678
  code: codeToRun,
4372
4679
  ...collect ? {
4373
4680
  wait_seconds: typeof args.wait_seconds === "number" ? args.wait_seconds : 1.5,
4374
- clean_env: typeof args.clean_env === "boolean" ? args.clean_env : true
4681
+ clean_env: typeof args.clean_env === "boolean" ? args.clean_env : true,
4682
+ ...typeof args.track_resources === "boolean" ? { track_resources: args.track_resources } : {},
4683
+ ...typeof args.auto_cleanup === "boolean" ? { auto_cleanup: args.auto_cleanup } : {},
4684
+ ...typeof args.settle_ms === "number" ? { settle_ms: args.settle_ms } : {}
4375
4685
  } : {},
4376
4686
  ...session ? { session } : {}
4377
4687
  };
@@ -4388,17 +4698,13 @@ ${liveRes.text}`
4388
4698
  };
4389
4699
  }
4390
4700
  async handleStudioPublish(args) {
4391
- const studioPath = typeof args.studio_path === "string" ? args.studio_path.trim() : "";
4392
- if (!studioPath) {
4393
- return {
4394
- content: [{ type: "text", text: "studio_publish requires studio_path" }],
4395
- isError: true
4396
- };
4397
- }
4701
+ const studioPath = typeof args.studio_path === "string" && args.studio_path.trim() ? args.studio_path.trim() : "Selection";
4702
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4398
4703
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4399
4704
  const studioRes = await this.studio.runStudioLuau(
4400
4705
  this.buildStudioReadScriptSourceCode(studioPath),
4401
- requestedStudioId
4706
+ requestedStudioId,
4707
+ datamodelType
4402
4708
  );
4403
4709
  if (!studioRes.ok) {
4404
4710
  return {
@@ -4423,18 +4729,22 @@ ${liveRes.text}`
4423
4729
  isError: true
4424
4730
  };
4425
4731
  }
4426
- const scriptId = typeof args.script_id === "string" ? args.script_id.trim() : "";
4427
- if (scriptId) {
4732
+ 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() : "";
4733
+ if (scriptTarget) {
4428
4734
  const deployRes = await this.callCloudTool("deploy_script", {
4429
- script_id: scriptId,
4735
+ ...typeof args.script_id === "string" && args.script_id.trim() ? { script_id: args.script_id.trim() } : {},
4736
+ ...typeof args.script === "string" && args.script.trim() ? { script: args.script.trim() } : {},
4737
+ ...!args.script_id && !args.script ? { script: scriptTarget } : {},
4430
4738
  source: parsed.source,
4431
- ...typeof args.note === "string" ? { note: args.note } : {}
4739
+ ...typeof args.note === "string" ? { note: args.note } : {},
4740
+ ...typeof args.publish === "boolean" ? { publish: args.publish } : {},
4741
+ ...typeof args.preset === "string" ? { preset: args.preset } : {}
4432
4742
  });
4433
4743
  return {
4434
4744
  content: [
4435
4745
  {
4436
4746
  type: "text",
4437
- text: `studio_publish deployed ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}) to Luaward script ${scriptId}:
4747
+ text: `studio_publish deployed ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}) to Luaward script ${scriptTarget}:
4438
4748
  ${deployRes.text}`
4439
4749
  }
4440
4750
  ],
@@ -4451,7 +4761,7 @@ ${deployRes.text}`
4451
4761
  content: [
4452
4762
  {
4453
4763
  type: "text",
4454
- text: `studio_publish created Luaward script "${scriptName}" from ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}):
4764
+ text: `studio_publish created Luaward script "${scriptName}" from ${parsed.path} (${parsed.source.length} bytes, studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):
4455
4765
  ${createRes.text}`
4456
4766
  }
4457
4767
  ],
@@ -4459,40 +4769,55 @@ ${createRes.text}`
4459
4769
  };
4460
4770
  }
4461
4771
  async handleLiveScriptsToStudio(args) {
4772
+ const targets = Array.isArray(args.targets) && args.targets.length > 0 ? args.targets.map(String) : [];
4462
4773
  const filter = typeof args.filter === "string" ? args.filter.trim() : "";
4463
- const containerName = typeof args.container_name === "string" && args.container_name.trim() ? args.container_name.trim() : "LuawardLiveScripts";
4464
- const limit = typeof args.limit === "number" ? Math.max(1, Math.min(50, args.limit)) : 15;
4774
+ 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";
4775
+ const containerName = rawContainer.replace(/^ServerStorage\./, "") || "LuawardLiveScripts";
4776
+ const rawLimit = typeof args.max === "number" ? args.max : typeof args.limit === "number" ? args.limit : 15;
4777
+ const limit = Math.max(1, Math.min(100, Math.floor(rawLimit)));
4778
+ const disabled = args.disabled !== false;
4465
4779
  const includeDecompiled = args.include_decompiled !== false;
4780
+ const datamodelType = this.parseStudioDataModelType(args.datamodel_type);
4466
4781
  const session = typeof args.session === "string" ? args.session : void 0;
4467
4782
  const requestedStudioId = typeof args.studio_id === "string" ? args.studio_id : void 0;
4468
4783
  const liveCollectCode = [
4469
4784
  "local HttpService = game:GetService('HttpService')",
4470
- `local filter = string.lower(${JSON.stringify(filter)})`,
4471
- `local limit = ${limit}`,
4472
- `local includeDecompiled = ${includeDecompiled ? "true" : "false"}`,
4785
+ `local targets = ${toLuauLiteral(targets)}`,
4786
+ `local filter = string.lower(${toLuauLiteral(filter)})`,
4787
+ `local limit = ${toLuauLiteral(limit)}`,
4788
+ `local includeDecompiled = ${toLuauLiteral(includeDecompiled)}`,
4473
4789
  "local roots = { game:GetService('ReplicatedStorage'), game:GetService('StarterPlayer'), game:GetService('Workspace'), game:GetService('Players').LocalPlayer }",
4474
4790
  "local results = {}",
4475
4791
  "local seen = {}",
4476
4792
  "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",
4477
- "for _, root in ipairs(roots) do",
4478
- " if root then",
4479
- " local ok, list = pcall(function() return root:GetDescendants() end)",
4480
- " if ok and type(list) == 'table' then",
4481
- " for _, inst in ipairs(list) do",
4482
- " if #results >= limit then break end",
4483
- " if not seen[inst] and (inst.ClassName == 'LocalScript' or inst.ClassName == 'ModuleScript') then",
4484
- " seen[inst] = true",
4485
- " local fullPath = inst:GetFullName()",
4486
- " if filter == '' or string.find(string.lower(fullPath), filter, 1, true) then",
4487
- " local src = '-- Live script: ' .. fullPath .. '\\n-- ClassName: ' .. inst.ClassName",
4488
- " if includeDecompiled and decompFn then",
4489
- " local okD, dec = pcall(decompFn, inst)",
4490
- " if okD and type(dec) == 'string' and #dec > 0 then",
4491
- " src = src .. '\\n\\n' .. dec:sub(1, 32000)",
4492
- " end",
4493
- " end",
4494
- " results[#results + 1] = { name = inst.Name, className = inst.ClassName, path = fullPath, source = src }",
4495
- " end",
4793
+ "local function collectOne(inst)",
4794
+ " if not inst or seen[inst] or #results >= limit then return end",
4795
+ " if inst.ClassName ~= 'LocalScript' and inst.ClassName ~= 'ModuleScript' then return end",
4796
+ " seen[inst] = true",
4797
+ " local fullPath = inst:GetFullName()",
4798
+ " if #targets == 0 and filter ~= '' and not string.find(string.lower(fullPath), filter, 1, true) then return end",
4799
+ " local src = '-- Live script: ' .. fullPath .. '\\n-- ClassName: ' .. inst.ClassName",
4800
+ " if includeDecompiled and decompFn then",
4801
+ " local okD, dec = pcall(decompFn, inst)",
4802
+ " if okD and type(dec) == 'string' and #dec > 0 then",
4803
+ " src = src .. '\\n\\n' .. dec:sub(1, 32000)",
4804
+ " end",
4805
+ " end",
4806
+ " results[#results + 1] = { name = inst.Name, className = inst.ClassName, path = fullPath, source = src }",
4807
+ "end",
4808
+ "if #targets > 0 and lw and lw.resolve then",
4809
+ " for _, tPath in ipairs(targets) do",
4810
+ " local inst = lw.resolve(tPath)",
4811
+ " if inst then collectOne(inst) end",
4812
+ " end",
4813
+ "else",
4814
+ " for _, root in ipairs(roots) do",
4815
+ " if root then",
4816
+ " local ok, list = pcall(function() return root:GetDescendants() end)",
4817
+ " if ok and type(list) == 'table' then",
4818
+ " for _, inst in ipairs(list) do",
4819
+ " if #results >= limit then break end",
4820
+ " collectOne(inst)",
4496
4821
  " end",
4497
4822
  " end",
4498
4823
  " end",
@@ -4518,10 +4843,10 @@ ${createRes.text}`
4518
4843
  }
4519
4844
  const scripts = this.extractJsonPayloadFromExec(liveRes.text) ?? [];
4520
4845
  const studioImportCode = [
4521
- "local HttpService = game:GetService('HttpService')",
4522
4846
  "local ServerStorage = game:GetService('ServerStorage')",
4523
- `local containerName = ${JSON.stringify(containerName)}`,
4524
- `local items = HttpService:JSONDecode(${JSON.stringify(JSON.stringify(scripts))})`,
4847
+ `local containerName = ${toLuauLiteral(containerName)}`,
4848
+ `local setDisabled = ${toLuauLiteral(disabled)}`,
4849
+ `local items = ${toLuauLiteral(scripts)}`,
4525
4850
  "local folder = ServerStorage:FindFirstChild(containerName)",
4526
4851
  "if not folder then",
4527
4852
  " folder = Instance.new('Folder')",
@@ -4534,6 +4859,9 @@ ${createRes.text}`
4534
4859
  " if ok and inst then",
4535
4860
  " inst.Name = item.name .. '_' .. tostring(imported + 1)",
4536
4861
  " pcall(function() inst:SetAttribute('LivePath', item.path) end)",
4862
+ " if setDisabled and (item.className == 'LocalScript' or item.className == 'Script') then",
4863
+ " pcall(function() inst.Disabled = true end)",
4864
+ " end",
4537
4865
  " pcall(function() inst.Source = item.source end)",
4538
4866
  " inst.Parent = folder",
4539
4867
  " imported = imported + 1",
@@ -4541,7 +4869,7 @@ ${createRes.text}`
4541
4869
  "end",
4542
4870
  "return string.format('imported %d live scripts into ServerStorage.%s', imported, containerName)"
4543
4871
  ].join("\n");
4544
- const studioRes = await this.studio.runStudioLuau(studioImportCode, requestedStudioId);
4872
+ const studioRes = await this.studio.runStudioLuau(studioImportCode, requestedStudioId, datamodelType);
4545
4873
  if (!studioRes.ok) {
4546
4874
  return {
4547
4875
  content: [
@@ -4559,7 +4887,7 @@ ${createRes.text}`
4559
4887
  {
4560
4888
  type: "text",
4561
4889
  text: [
4562
- `live_scripts_to_studio complete (studio_id=${studioRes.studioId ?? "auto"}):`,
4890
+ `live_scripts_to_studio complete (studio_id=${studioRes.studioId ?? "auto"}, datamodel_type=${datamodelType}):`,
4563
4891
  `- Scripts collected from live game: ${scripts.length}`,
4564
4892
  `- Studio container: ServerStorage.${containerName}`,
4565
4893
  `- Studio result: ${studioRes.text}`,