ms-vite-plugin 1.1.4 → 1.1.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/mcp/tools.js CHANGED
@@ -269,6 +269,39 @@ function registerDocTools(server) {
269
269
  * registerRuntimeTools(server)
270
270
  */
271
271
  function registerRuntimeTools(server) {
272
+ /**
273
+ * MCP 进程内当前工作目录(可通过 set_workspace 修改)
274
+ */
275
+ let currentWorkspacePath;
276
+ /**
277
+ * 解析并记忆工作目录
278
+ * @param workspacePath 可选的工作目录
279
+ * @returns 返回本次生效的绝对路径
280
+ * @example
281
+ * const workspace = resolveWorkspacePath("/Users/demo/project")
282
+ */
283
+ function resolveWorkspacePath(workspacePath) {
284
+ if (workspacePath && workspacePath.trim()) {
285
+ currentWorkspacePath = path.resolve(workspacePath.trim());
286
+ return currentWorkspacePath;
287
+ }
288
+ if (currentWorkspacePath) {
289
+ return currentWorkspacePath;
290
+ }
291
+ return process.cwd();
292
+ }
293
+ /**
294
+ * 校验并返回有效工作目录
295
+ * @param workspacePath 可选工作目录
296
+ * @returns 返回校验通过的绝对路径
297
+ * @example
298
+ * const workspace = await ensureWorkspacePath("/Users/demo/project")
299
+ */
300
+ async function ensureWorkspacePath(workspacePath) {
301
+ const workspace = resolveWorkspacePath(workspacePath);
302
+ await (0, project_2.ensureValidKuaiJSProject)(workspace);
303
+ return workspace;
304
+ }
272
305
  /**
273
306
  * 解析运行目标:
274
307
  * - 显式 transport=ws: 强制走 ws
@@ -306,6 +339,41 @@ function registerRuntimeTools(server) {
306
339
  label: `${device.ip}:${device.port}`,
307
340
  };
308
341
  }
342
+ server.registerTool("set_workspace", {
343
+ title: "Set Workspace",
344
+ description: "设置默认工作目录。后续 build/run/package/watch 等工具会优先使用该目录。",
345
+ inputSchema: {
346
+ workspacePath: z
347
+ .string()
348
+ .min(1)
349
+ .describe("快点JS 项目目录绝对路径(需包含 package.json 与 scripts)"),
350
+ },
351
+ }, async ({ workspacePath }) => {
352
+ const workspace = await ensureWorkspacePath(workspacePath);
353
+ return {
354
+ content: [
355
+ {
356
+ type: "text",
357
+ text: `默认工作目录已设置为: ${workspace}`,
358
+ },
359
+ ],
360
+ };
361
+ });
362
+ server.registerTool("get_workspace", {
363
+ title: "Get Workspace",
364
+ description: "查看当前 MCP 生效的工作目录。",
365
+ inputSchema: {},
366
+ }, async () => {
367
+ const workspace = resolveWorkspacePath();
368
+ return {
369
+ content: [
370
+ {
371
+ type: "text",
372
+ text: `当前工作目录: ${workspace}`,
373
+ },
374
+ ],
375
+ };
376
+ });
309
377
  server.registerTool("set_device", {
310
378
  title: "Set Device",
311
379
  description: "设置默认设备连接信息。首次配置后,后续 run/stop 可不再传 ip。",
@@ -525,6 +593,11 @@ function registerRuntimeTools(server) {
525
593
  title: "Watch Logs",
526
594
  description: "通过 SSE 监听设备日志并自动判定异常。首次可传 ip,也可复用 set_device 保存的默认设备。",
527
595
  inputSchema: {
596
+ workspacePath: z
597
+ .string()
598
+ .min(1)
599
+ .optional()
600
+ .describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
528
601
  ip: z
529
602
  .string()
530
603
  .min(1)
@@ -554,8 +627,8 @@ function registerRuntimeTools(server) {
554
627
  .default(200)
555
628
  .describe("最多收集日志条数,默认 200"),
556
629
  },
557
- }, async ({ ip, port, durationSeconds, maxLogs }) => {
558
- await (0, project_2.ensureValidKuaiJSProject)(process.cwd());
630
+ }, async ({ workspacePath, ip, port, durationSeconds, maxLogs }) => {
631
+ await ensureWorkspacePath(workspacePath);
559
632
  const device = await (0, device_config_1.resolveDeviceConfig)(ip, port);
560
633
  const result = await (0, project_1.watchDeviceLogsBySse)(device.ip, device.port, durationSeconds * 1000, maxLogs);
561
634
  const findingsPreview = result.findings
@@ -589,14 +662,19 @@ function registerRuntimeTools(server) {
589
662
  title: "Build Project",
590
663
  description: "构建 KuaiJS 项目,支持开发模式与生产模式。",
591
664
  inputSchema: {
665
+ workspacePath: z
666
+ .string()
667
+ .min(1)
668
+ .optional()
669
+ .describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
592
670
  dev: z
593
671
  .boolean()
594
672
  .optional()
595
673
  .describe("是否开发模式构建,true=开发模式,false=生产模式"),
596
674
  },
597
- }, async ({ dev }) => {
598
- await (0, project_2.ensureValidKuaiJSProject)(process.cwd());
599
- await (0, build_1.buildAll)(Boolean(dev), process.cwd());
675
+ }, async ({ workspacePath, dev }) => {
676
+ const workspace = await ensureWorkspacePath(workspacePath);
677
+ await (0, build_1.buildAll)(Boolean(dev), workspace);
600
678
  return {
601
679
  content: [
602
680
  { type: "text", text: `构建完成,模式: ${dev ? "dev" : "prod"}` },
@@ -606,10 +684,16 @@ function registerRuntimeTools(server) {
606
684
  server.registerTool("package_project", {
607
685
  title: "Package Project",
608
686
  description: "执行生产构建并加密,返回 enc.msbundle 路径。",
609
- inputSchema: {},
610
- }, async () => {
611
- await (0, project_2.ensureValidKuaiJSProject)(process.cwd());
612
- const encryptedPath = await (0, packager_1.packageProject)(process.cwd());
687
+ inputSchema: {
688
+ workspacePath: z
689
+ .string()
690
+ .min(1)
691
+ .optional()
692
+ .describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
693
+ },
694
+ }, async ({ workspacePath }) => {
695
+ const workspace = await ensureWorkspacePath(workspacePath);
696
+ const encryptedPath = await (0, packager_1.packageProject)(workspace);
613
697
  return {
614
698
  content: [{ type: "text", text: `打包完成: ${encryptedPath}` }],
615
699
  };
@@ -648,9 +732,14 @@ function registerRuntimeTools(server) {
648
732
  .max(600000)
649
733
  .optional()
650
734
  .describe("WS 等待连接超时毫秒(transport=ws 时可选,默认 30000)"),
735
+ workspacePath: z
736
+ .string()
737
+ .min(1)
738
+ .optional()
739
+ .describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
651
740
  },
652
- }, async ({ transport, ip, port, wsPort, wsWaitMs }) => {
653
- await (0, project_2.ensureValidKuaiJSProject)(process.cwd());
741
+ }, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
742
+ const workspace = await ensureWorkspacePath(workspacePath);
654
743
  const target = await resolvePreferredRuntimeTarget({
655
744
  transport,
656
745
  ip,
@@ -663,11 +752,13 @@ function registerRuntimeTools(server) {
663
752
  transport: "ws",
664
753
  wsPort: target.wsPort,
665
754
  wsWaitMs: target.wsWaitMs,
755
+ workspacePath: workspace,
666
756
  }
667
757
  : {
668
758
  ip: target.ip,
669
759
  port: target.port,
670
760
  transport: "http",
761
+ workspacePath: workspace,
671
762
  });
672
763
  return {
673
764
  content: [
@@ -712,9 +803,14 @@ function registerRuntimeTools(server) {
712
803
  .max(600000)
713
804
  .optional()
714
805
  .describe("WS 等待连接超时毫秒(transport=ws 时可选,默认 30000)"),
806
+ workspacePath: z
807
+ .string()
808
+ .min(1)
809
+ .optional()
810
+ .describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
715
811
  },
716
- }, async ({ transport, ip, port, wsPort, wsWaitMs }) => {
717
- await (0, project_2.ensureValidKuaiJSProject)(process.cwd());
812
+ }, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
813
+ const workspace = await ensureWorkspacePath(workspacePath);
718
814
  const target = await resolvePreferredRuntimeTarget({
719
815
  transport,
720
816
  ip,
@@ -727,11 +823,13 @@ function registerRuntimeTools(server) {
727
823
  transport: "ws",
728
824
  wsPort: target.wsPort,
729
825
  wsWaitMs: target.wsWaitMs,
826
+ workspacePath: workspace,
730
827
  }
731
828
  : {
732
829
  ip: target.ip,
733
830
  port: target.port,
734
831
  transport: "http",
832
+ workspacePath: workspace,
735
833
  });
736
834
  return {
737
835
  content: [
@@ -776,9 +874,14 @@ function registerRuntimeTools(server) {
776
874
  .max(600000)
777
875
  .optional()
778
876
  .describe("WS 等待连接超时毫秒(transport=ws 时可选,默认 30000)"),
877
+ workspacePath: z
878
+ .string()
879
+ .min(1)
880
+ .optional()
881
+ .describe("可选工作目录;不传时使用 set_workspace 记录值或 MCP 启动目录"),
779
882
  },
780
- }, async ({ transport, ip, port, wsPort, wsWaitMs }) => {
781
- await (0, project_2.ensureValidKuaiJSProject)(process.cwd());
883
+ }, async ({ transport, ip, port, wsPort, wsWaitMs, workspacePath }) => {
884
+ resolveWorkspacePath(workspacePath);
782
885
  const target = await resolvePreferredRuntimeTarget({
783
886
  transport,
784
887
  ip,
package/dist/project.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface DeviceCliOptions {
7
7
  transport?: string;
8
8
  wsPort?: string;
9
9
  wsWaitMs?: string;
10
+ workspacePath?: string;
10
11
  }
11
12
  /**
12
13
  * 设备日志条目
package/dist/project.js CHANGED
@@ -709,7 +709,9 @@ async function ensureWsReady(options) {
709
709
  * await runOnDevice({ ip: "192.168.1.10", port: "9800", path: "./demo" })
710
710
  */
711
711
  async function runOnDevice(options) {
712
- const workspacePath = process.cwd();
712
+ const workspacePath = options.workspacePath
713
+ ? path.resolve(options.workspacePath)
714
+ : process.cwd();
713
715
  const transport = parseTransport(options);
714
716
  console.log(`🔧 开始构建项目: ${workspacePath}`);
715
717
  await runDevBuild(workspacePath);
@@ -737,7 +739,9 @@ async function runOnDevice(options) {
737
739
  * await runUIOnDevice({ ip: "192.168.1.10", port: "9800", path: "./demo" })
738
740
  */
739
741
  async function runUIOnDevice(options) {
740
- const workspacePath = process.cwd();
742
+ const workspacePath = options.workspacePath
743
+ ? path.resolve(options.workspacePath)
744
+ : process.cwd();
741
745
  const transport = parseTransport(options);
742
746
  console.log(`🔧 开始构建项目: ${workspacePath}`);
743
747
  await runDevBuild(workspacePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {