Skip to content

refactor(pipeline): 优化 Pipeline 保存路径及浏览器打开逻辑#15

Merged
MistEO merged 2 commits intoMAA-AI:mainfrom
kqcoxn:main
Dec 19, 2025
Merged

refactor(pipeline): 优化 Pipeline 保存路径及浏览器打开逻辑#15
MistEO merged 2 commits intoMAA-AI:mainfrom
kqcoxn:main

Conversation

@kqcoxn
Copy link
Copy Markdown
Contributor

@kqcoxn kqcoxn commented Dec 18, 2025

省流:在用户 downloads 文件夹里拉💩(

  • 默认保存 Pipeline 文件到用户 Downloads 目录,确保目录存在
  • 依据文件路径推断起始目录参数,支持 Downloads、Documents、Desktop、Music、Pictures、Videos
  • 去除基于数据压缩的分享链接生成,改为传递导入目录和文件名参数
  • 添加路径无效或无法推断时的错误提示信息
  • 使用 URL 参数打开系统默认浏览器,提示用户选择本地文件导入
  • 保留原有文件名清理和时间戳命名逻辑,增强文件管理方便性

Summary by Sourcery

优化管道文件保存的默认行为,并通过传递导入提示而非嵌入数据的方式,简化基于浏览器的可视化集成。

新功能:

  • 默认将导出的管道 JSON 文件保存到用户的下载目录中,并使用清理过且带时间戳的文件名。
  • 使用带 URL 参数的方式打开系统浏览器,通过参数提示用于管道可视化导入的目录和文件名。

增强内容:

  • 用轻量级的、与导入相关的查询参数替代在分享 URL 中嵌入压缩管道数据的做法。
  • 在浏览器中打开可视化页面时,根据管道文件路径推断建议的起始目录(Downloads、Documents、Desktop、Music、Pictures、Videos),若无法推断则报错。
  • 在启动可视化工具时,对无效的管道文件路径或不受支持的位置添加校验,并给出清晰的错误信息。
Original summary in English

Summary by Sourcery

Refine pipeline file saving defaults and simplify browser-based visualization integration by passing import hints instead of embedded data.

New Features:

  • Default pipeline JSON exports to the user's Downloads directory with cleaned, timestamped filenames.
  • Open the system browser with URL parameters that hint the import directory and file name for pipeline visualization.

Enhancements:

  • Replace embedding compressed pipeline data in the share URL with lightweight import-related query parameters.
  • Infer the suggested starting directory (Downloads, Documents, Desktop, Music, Pictures, Videos) from the pipeline file path when opening in the browser, and error if it cannot be determined.
  • Add validation and clear error messages for invalid pipeline file paths or unsupported locations when launching the visualizer.

新功能:

  • 将流水线文件默认保存到用户的下载目录,并使用已清理且带时间戳的文件名。
  • 使用 URL 参数打开系统浏览器,这些参数提供用于流水线可视化导入的目录和文件名提示。

增强改进:

  • 在浏览器中打开时,根据流水线文件路径,从(下载、文档、桌面、音乐、图片、视频)中推断合适的起始目录。
  • 当流水线路径无效或无法推断起始目录时,提供明确的错误信息。
  • 移除嵌入在 URL 中的压缩流水线数据及其大小检查,改为使用简单的与导入相关的查询参数。
Original summary in English

Summary by Sourcery

优化管道文件保存的默认行为,并通过传递导入提示而非嵌入数据的方式,简化基于浏览器的可视化集成。

新功能:

  • 默认将导出的管道 JSON 文件保存到用户的下载目录中,并使用清理过且带时间戳的文件名。
  • 使用带 URL 参数的方式打开系统浏览器,通过参数提示用于管道可视化导入的目录和文件名。

增强内容:

  • 用轻量级的、与导入相关的查询参数替代在分享 URL 中嵌入压缩管道数据的做法。
  • 在浏览器中打开可视化页面时,根据管道文件路径推断建议的起始目录(Downloads、Documents、Desktop、Music、Pictures、Videos),若无法推断则报错。
  • 在启动可视化工具时,对无效的管道文件路径或不受支持的位置添加校验,并给出清晰的错误信息。
Original summary in English

Summary by Sourcery

Refine pipeline file saving defaults and simplify browser-based visualization integration by passing import hints instead of embedded data.

New Features:

  • Default pipeline JSON exports to the user's Downloads directory with cleaned, timestamped filenames.
  • Open the system browser with URL parameters that hint the import directory and file name for pipeline visualization.

Enhancements:

  • Replace embedding compressed pipeline data in the share URL with lightweight import-related query parameters.
  • Infer the suggested starting directory (Downloads, Documents, Desktop, Music, Pictures, Videos) from the pipeline file path when opening in the browser, and error if it cannot be determined.
  • Add validation and clear error messages for invalid pipeline file paths or unsupported locations when launching the visualizer.

- 默认保存 Pipeline 文件到用户 Downloads 目录,确保目录存在
- 依据文件路径推断起始目录参数,支持 Downloads、Documents、Desktop、Music、Pictures、Videos
- 去除基于数据压缩的分享链接生成,改为传递导入目录和文件名参数
- 添加路径无效或无法推断时的错误提示信息
- 使用 URL 参数打开系统默认浏览器,提示用户选择本地文件导入
- 保留原有文件名清理和时间戳命名逻辑,增强文件管理方便性
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我已经review 了你的改动,这里有一些反馈:

  • 默认保存路径被硬编码为 Path.home() / "Downloads",这可能与本地化或平台特定的下载目录不一致;建议改为使用操作系统 API,或现有的配置/可信数据源来获取用户的下载文件夹。
  • open_pipeline_in_browser 中的起始目录推断依赖对完整路径做子串检查(例如检查 "docs""download"),这很容易造成误判;更稳妥的方式是检查路径组件(Path.parts),或者维护一份已知根目录的小映射表。
  • 当起始目录无法推断时,该函数会抛出错误并强制用户将文件移动到特定文件夹;建议在无法推断时退回到一个合理的默认值(例如 downloads),并仍然使用这个提示打开浏览器,以减少使用阻力。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The default save path is hardcoded to `Path.home() / "Downloads"`, which may not match localized or platform-specific download directories; consider using an OS API or an existing configuration/source of truth for the user’s download folder instead.
- The start directory inference in `open_pipeline_in_browser` relies on substring checks over the full path (e.g., checking for `"docs"` or `"download"`), which can easily cause false positives; it would be more robust to inspect path components (`Path.parts`) or use a small mapping of known root folders.
- When the start directory cannot be inferred, the function raises an error and forces users to move the file into specific folders; consider falling back to a reasonable default (e.g., `downloads`) and still opening the browser with that hint to reduce friction.

## Individual Comments

### Comment 1
<location> `maa_mcp/pipeline.py:501-510` </location>
<code_context>
+    file_name = file_path.name
+
+    # 推断起始目录
+    lower_path = str(file_path).lower()
+    if "downloads" in lower_path or "download" in lower_path or "下载" in lower_path:
+        start_dir = "downloads"
+    elif "documents" in lower_path or "docs" in lower_path or "文档" in lower_path:
+        start_dir = "documents"
+    elif "desktop" in lower_path or "桌面" in lower_path:
+        start_dir = "desktop"
+    elif "music" in lower_path or "音乐" in lower_path:
+        start_dir = "music"
+    elif "pictures" in lower_path or "图片" in lower_path:
+        start_dir = "pictures"
+    elif "videos" in lower_path or "视频" in lower_path:
+        start_dir = "videos"
+    else:
</code_context>

<issue_to_address>
**suggestion:** Directory inference based on substring matching can misclassify paths and might be better done by inspecting path segments.

Because the heuristic looks for substrings like `"downloads" in lower_path`, it will also match paths such as `/home/user/mydownloads_backup` or `/data/documents_archive`, and the first match wins. To avoid this, consider iterating over `Path(file_path).parts` and matching full path segments against a small whitelist per category. This should make the inferred start directory more accurate and less surprising for users with similarly named folders.

Suggested implementation:

```python
    # 提取文件名
    file_name = file_path.name

    # 推断起始目录:基于路径段而不是子串匹配,避免误判如 "mydownloads_backup"
    path_parts = [part.lower() for part in Path(file_path).parts]

    if any(part in {"downloads", "download", "下载"} for part in path_parts):
        start_dir = "downloads"
    elif any(part in {"documents", "docs", "文档"} for part in path_parts):
        start_dir = "documents"
    elif any(part in {"desktop", "桌面"} for part in path_parts):
        start_dir = "desktop"
    elif any(part in {"music", "音乐"} for part in path_parts):
        start_dir = "music"
    elif any(part in {"pictures", "图片"} for part in path_parts):
        start_dir = "pictures"
    elif any(part in {"videos", "视频"} for part in path_parts):
        start_dir = "videos"
    else:

```

1. Make sure `from pathlib import Path` is imported at the top of `maa_mcp/pipeline.py` (it appears to be present already since `Path.home()` is used, but confirm).
2. If this logic is inside a method where `file_path` might not be a `Path` instance, ensure it is converted beforehand (e.g., `file_path = Path(file_path)`).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的review。
Original comment in English

Hey there - I've reviewed your changes - here's some feedback:

  • The default save path is hardcoded to Path.home() / "Downloads", which may not match localized or platform-specific download directories; consider using an OS API or an existing configuration/source of truth for the user’s download folder instead.
  • The start directory inference in open_pipeline_in_browser relies on substring checks over the full path (e.g., checking for "docs" or "download"), which can easily cause false positives; it would be more robust to inspect path components (Path.parts) or use a small mapping of known root folders.
  • When the start directory cannot be inferred, the function raises an error and forces users to move the file into specific folders; consider falling back to a reasonable default (e.g., downloads) and still opening the browser with that hint to reduce friction.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The default save path is hardcoded to `Path.home() / "Downloads"`, which may not match localized or platform-specific download directories; consider using an OS API or an existing configuration/source of truth for the user’s download folder instead.
- The start directory inference in `open_pipeline_in_browser` relies on substring checks over the full path (e.g., checking for `"docs"` or `"download"`), which can easily cause false positives; it would be more robust to inspect path components (`Path.parts`) or use a small mapping of known root folders.
- When the start directory cannot be inferred, the function raises an error and forces users to move the file into specific folders; consider falling back to a reasonable default (e.g., `downloads`) and still opening the browser with that hint to reduce friction.

## Individual Comments

### Comment 1
<location> `maa_mcp/pipeline.py:501-510` </location>
<code_context>
+    file_name = file_path.name
+
+    # 推断起始目录
+    lower_path = str(file_path).lower()
+    if "downloads" in lower_path or "download" in lower_path or "下载" in lower_path:
+        start_dir = "downloads"
+    elif "documents" in lower_path or "docs" in lower_path or "文档" in lower_path:
+        start_dir = "documents"
+    elif "desktop" in lower_path or "桌面" in lower_path:
+        start_dir = "desktop"
+    elif "music" in lower_path or "音乐" in lower_path:
+        start_dir = "music"
+    elif "pictures" in lower_path or "图片" in lower_path:
+        start_dir = "pictures"
+    elif "videos" in lower_path or "视频" in lower_path:
+        start_dir = "videos"
+    else:
</code_context>

<issue_to_address>
**suggestion:** Directory inference based on substring matching can misclassify paths and might be better done by inspecting path segments.

Because the heuristic looks for substrings like `"downloads" in lower_path`, it will also match paths such as `/home/user/mydownloads_backup` or `/data/documents_archive`, and the first match wins. To avoid this, consider iterating over `Path(file_path).parts` and matching full path segments against a small whitelist per category. This should make the inferred start directory more accurate and less surprising for users with similarly named folders.

Suggested implementation:

```python
    # 提取文件名
    file_name = file_path.name

    # 推断起始目录:基于路径段而不是子串匹配,避免误判如 "mydownloads_backup"
    path_parts = [part.lower() for part in Path(file_path).parts]

    if any(part in {"downloads", "download", "下载"} for part in path_parts):
        start_dir = "downloads"
    elif any(part in {"documents", "docs", "文档"} for part in path_parts):
        start_dir = "documents"
    elif any(part in {"desktop", "桌面"} for part in path_parts):
        start_dir = "desktop"
    elif any(part in {"music", "音乐"} for part in path_parts):
        start_dir = "music"
    elif any(part in {"pictures", "图片"} for part in path_parts):
        start_dir = "pictures"
    elif any(part in {"videos", "视频"} for part in path_parts):
        start_dir = "videos"
    else:

```

1. Make sure `from pathlib import Path` is imported at the top of `maa_mcp/pipeline.py` (it appears to be present already since `Path.home()` is used, but confirm).
2. If this logic is inside a method where `file_path` might not be a `Path` instance, ensure it is converted beforehand (e.g., `file_path = Path(file_path)`).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread maa_mcp/pipeline.py
Comment on lines +501 to +510
lower_path = str(file_path).lower()
if "downloads" in lower_path or "download" in lower_path or "下载" in lower_path:
start_dir = "downloads"
elif "documents" in lower_path or "docs" in lower_path or "文档" in lower_path:
start_dir = "documents"
elif "desktop" in lower_path or "桌面" in lower_path:
start_dir = "desktop"
elif "music" in lower_path or "音乐" in lower_path:
start_dir = "music"
elif "pictures" in lower_path or "图片" in lower_path:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: 基于子串匹配的目录推断可能会误分类路径,改为检查路径段会更可靠。

由于当前启发式会查找类似 "downloads" in lower_path 这样的子串,它同样会匹配诸如 /home/user/mydownloads_backup/data/documents_archive 这样的路径,而且是第一个匹配就生效。为避免这种情况,建议遍历 Path(file_path).parts,并将完整路径段与每个类别的一小段白名单进行匹配。这样推断出的起始目录会更准确,对于拥有类似命名文件夹的用户也不那么出乎意料。

建议的实现:

    # 提取文件名
    file_name = file_path.name

    # 推断起始目录:基于路径段而不是子串匹配,避免误判如 "mydownloads_backup"
    path_parts = [part.lower() for part in Path(file_path).parts]

    if any(part in {"downloads", "download", "下载"} for part in path_parts):
        start_dir = "downloads"
    elif any(part in {"documents", "docs", "文档"} for part in path_parts):
        start_dir = "documents"
    elif any(part in {"desktop", "桌面"} for part in path_parts):
        start_dir = "desktop"
    elif any(part in {"music", "音乐"} for part in path_parts):
        start_dir = "music"
    elif any(part in {"pictures", "图片"} for part in path_parts):
        start_dir = "pictures"
    elif any(part in {"videos", "视频"} for part in path_parts):
        start_dir = "videos"
    else:
  1. 请确保在 maa_mcp/pipeline.py 文件顶部已经导入了 from pathlib import Path(看起来已经存在,因为使用了 Path.home(),但最好确认一下)。
  2. 如果这段逻辑位于一个方法内部,并且 file_path 可能不是 Path 实例,请确保在此之前将其转换(例如 file_path = Path(file_path))。
Original comment in English

suggestion: Directory inference based on substring matching can misclassify paths and might be better done by inspecting path segments.

Because the heuristic looks for substrings like "downloads" in lower_path, it will also match paths such as /home/user/mydownloads_backup or /data/documents_archive, and the first match wins. To avoid this, consider iterating over Path(file_path).parts and matching full path segments against a small whitelist per category. This should make the inferred start directory more accurate and less surprising for users with similarly named folders.

Suggested implementation:

    # 提取文件名
    file_name = file_path.name

    # 推断起始目录:基于路径段而不是子串匹配,避免误判如 "mydownloads_backup"
    path_parts = [part.lower() for part in Path(file_path).parts]

    if any(part in {"downloads", "download", "下载"} for part in path_parts):
        start_dir = "downloads"
    elif any(part in {"documents", "docs", "文档"} for part in path_parts):
        start_dir = "documents"
    elif any(part in {"desktop", "桌面"} for part in path_parts):
        start_dir = "desktop"
    elif any(part in {"music", "音乐"} for part in path_parts):
        start_dir = "music"
    elif any(part in {"pictures", "图片"} for part in path_parts):
        start_dir = "pictures"
    elif any(part in {"videos", "视频"} for part in path_parts):
        start_dir = "videos"
    else:
  1. Make sure from pathlib import Path is imported at the top of maa_mcp/pipeline.py (it appears to be present already since Path.home() is used, but confirm).
  2. If this logic is inside a method where file_path might not be a Path instance, ensure it is converted beforehand (e.g., file_path = Path(file_path)).

Comment thread maa_mcp/pipeline.py Outdated
@kqcoxn
Copy link
Copy Markdown
Contributor Author

kqcoxn commented Dec 19, 2025

感觉兼容性更低了()

@MistEO MistEO merged commit de33a56 into MAA-AI:main Dec 19, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants