Skip to content

Conversation

@XiangqianHuang
Copy link
Collaborator

概述

添加 cueme proto rm/remove 命令,作为 cueme proto apply 的反向操作,允许用户干净地移除已应用的 HAP 协议。

功能特性

  • 移除 HAP 协议管理块 (BEGIN_MARKER 到 END_MARKER)
  • 保留文件中其他非管理块的内容
  • 如果文件移除后为空,自动删除文件
  • 智能处理不同的换行符风格 (CRLF/LF)
  • 友好的错误处理和提示信息

使用方法

# 使用 rm 移除协议
$ cueme proto rm windsurf
ok: removed managed block from: ~/.codeium/windsurf/memories/global_rules.md

# 使用 remove 别名
$ cueme proto remove kiro
ok: removed managed block and deleted empty file: ~/.kiro/steering/cueme_proto.md

使用场景

  • 卸载不再需要的 HAP 协议
  • 清理测试环境
  • 重新配置前先移除旧配置

实现细节

修改内容

  • 添加 protoRemove() 函数用于移除已应用的协议块
  • 在 CLI 中注册 rmremove 两个命令别名
  • 更新帮助文档显示新命令
  • 导出 protoRemove 函数到 module.exports

代码逻辑

  1. 读取目标文件内容
  2. 查找 BEGIN_MARKER 和 END_MARKER
  3. 移除标记之间的内容
  4. 保留文件中的其他内容
  5. 如果文件为空则删除文件

测试

# 测试 rm 命令
$ cueme proto apply kiro
ok: applied to ~/.kiro/steering/cueme_proto.md

$ cueme proto rm kiro
ok: removed managed block and deleted empty file: ~/.kiro/steering/cueme_proto.md

# 测试 remove 别名
$ cueme proto apply kiro
ok: applied to ~/.kiro/steering/cueme_proto.md

$ cueme proto remove kiro
ok: removed managed block and deleted empty file: ~/.kiro/steering/cueme_proto.md

相关文档

Implement cueme proto rm/remove command as the reverse operation of
cueme proto apply. This allows users to cleanly remove the HAP protocol
from agent configuration files.

Features:
- Add protoRemove() function to remove managed blocks
- Support both 'rm' and 'remove' aliases
- Automatically delete file if it becomes empty after removal
- Preserve file content outside managed blocks
- Handle cases where file or managed block doesn't exist

Usage:
  cueme proto rm <agent>
  cueme proto remove <agent>

Examples:
  cueme proto rm windsurf
  cueme proto remove kiro

The command removes content between BEGIN_MARKER and END_MARKER,
preserving any other content in the file. If the file only contains
the managed block, it will be deleted entirely.
Copy link
Collaborator

@nmhjklnm nmhjklnm left a comment

Choose a reason for hiding this comment

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

Thanks — this feature makes a lot of sense as the reverse operation of cueme proto apply, and CI is green.

A couple of things I’d suggest before merging:

Must-fix

  1. protoRemove() has an unused local (exists).

    • You set it but never read it; please remove it.
  2. When deleting the file fails (fs.unlinkSync throws), the command still returns ok: and exits 0.

    • I’d treat this as an error (e.g. return error: and set a non-zero exit), otherwise users may think everything is clean but the file is still there.

Nice-to-have / confirm behavior

  1. Marker pairing robustness: current logic removes from the first BEGIN match to the first END match.

    • If someone accidentally duplicates markers, this might delete an unexpected range. Consider pairing BEGIN with the next END after it (more explicit index search), or at least document the “first block only” behavior.
  2. trimEnd() changes trailing whitespace/newlines of the remaining content.

    • Probably fine, but please confirm this is intended; otherwise keep the existing tail formatting and only remove the managed block.

Once you address (1)-(2), I think this is good to go.

Address all feedback from code review:

Must-fix items:
1. Remove unused 'exists' variable in protoRemove()
2. Throw error when file deletion fails instead of returning ok
   - Changed from 'ok: ... but failed to delete' to throwing Error
   - This ensures non-zero exit code and proper error handling

Improvements:
3. Removed trimEnd() to preserve original file formatting
   - Keep trailing whitespace/newlines as they were
   - Only remove the managed block itself

The function now:
- Cleanly removes managed blocks
- Preserves original file formatting
- Properly reports errors when file deletion fails
- Has no unused variables
@nmhjklnm nmhjklnm self-assigned this Jan 17, 2026
Copy link
Collaborator

@nmhjklnm nmhjklnm left a comment

Choose a reason for hiding this comment

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

Re-review: looks good.

  • Removed the unused exists variable.
  • Deletion failure now throws an error (non-zero exit), which is safer.
  • Preserves existing file formatting (no trimEnd()), while still removing the managed block.

CI is green. Approving.

@nmhjklnm nmhjklnm merged commit 12664a3 into main Jan 17, 2026
2 checks passed
@nmhjklnm nmhjklnm deleted the feature/add-proto-remove branch January 17, 2026 13:24
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.

3 participants