Skip to content

Implement Stream Redirection Support #24

@FerdinandSu

Description

@FerdinandSu

Description / 功能描述

English:
Implement stream redirection functionality from MobileSuit .NET v4.5+ to allow users to redirect command input/output to files, enabling better integration with shell scripts and automation workflows.

中文:
实现 MobileSuit .NET v4.5+ 的流重定向功能,允许用户将命令输入/输出重定向到文件,从而更好地与shell脚本和自动化工作流集成。

Features / 功能特性

English:

  • Output redirection: command args > output.txt (overwrite)
  • Append redirection: command args >> log.txt (append)
  • Input redirection: command < input.txt (read from file)
  • Support for absolute and relative file paths
  • Proper file handle management and cleanup
  • UTF-8 encoding by default

中文:

  • 输出重定向: command args > output.txt (覆盖)
  • 追加重定向: command args >> log.txt (追加)
  • 输入重定向: command < input.txt (从文件读取)
  • 支持绝对路径和相对路径
  • 正确的文件句柄管理和清理
  • 默认使用UTF-8编码

Tech Stack / 技术栈

  • Extend ParsingService to detect redirect operators / 扩展 ParsingService 检测重定向操作符
  • Create FileIOHub wrapping file streams / 创建包装文件流的 FileIOHub
  • Integration with SuitContext for IOHub swapping / 与 SuitContext 集成以交换IOHub

Difficulty & Time / 难度与时间

Difficulty / 难度: 🟡 Medium / 中等
Estimated Time / 预估时间: 3-5 days / 3-5天

Requirements / 要求

English:

  • MUST follow MobileSuit .NET API (see .claude/MobileSuitFeatures.md Feature 对SuitContext部分进行了单元测试 #12)
  • MUST handle file permission errors gracefully with clear error messages
  • MUST properly close file handles to prevent resource leaks
  • MUST support UTF-8 encoding with proper BOM handling
  • PR MUST include:
    • Unit tests for all redirection types
    • Tests for error scenarios (permission denied, file not found, etc.)
    • Integration tests with real files
    • Documentation with examples

中文:

  • 必须 遵循MobileSuit .NET API(参见 .claude/MobileSuitFeatures.md 功能 对SuitContext部分进行了单元测试 #12
  • 必须 优雅地处理文件权限错误,并提供清晰的错误消息
  • 必须 正确关闭文件句柄以防止资源泄漏
  • 必须 支持UTF-8编码,正确处理BOM
  • PR 必须 包含:
    • 所有重定向类型的单元测试
    • 错误场景测试(权限拒绝、文件未找到等)
    • 真实文件的集成测试
    • 带示例的文档

Acceptance Criteria / 验收标准

  • Parse >, >>, < operators in ParsingService / 在ParsingService中解析操作符
  • Implement output redirection (>) / 实现输出重定向
  • Implement append redirection (>>) / 实现追加重定向
  • Implement input redirection (<) / 实现输入重定向
  • Create/overwrite files for > operator / 为 > 操作符创建/覆盖文件
  • Append to existing files for >> operator / 为 >> 操作符追加到现有文件
  • Read input line-by-line for < operator / 为 < 操作符逐行读取输入
  • Handle file path validation (exists, writable, etc.) / 处理文件路径验证
  • Implement proper error handling / 实现正确的错误处理
  • Ensure file handles are closed (use context managers) / 确保文件句柄关闭(使用上下文管理器)
  • Support both absolute and relative paths / 支持绝对路径和相对路径
  • Add comprehensive unit tests (80%+ coverage) / 添加全面的单元测试
  • Add integration tests with real file I/O / 添加真实文件I/O的集成测试
  • Update documentation / 更新文档

Reference / 参考

See .claude/MobileSuitFeatures.md Feature #12 for detailed specification.
详细规格请参见 .claude/MobileSuitFeatures.md 功能 #12

Before Starting / 开始之前

Please comment on this issue to let us know you're working on it!
请在此issue下评论,让我们知道你正在处理!

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreCore functionality changesenhancementNew feature or requestfeature-parityPorting from MobileSuit .NET

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions