Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add commands/awesome-embedded-learning-studio/cfdesktop/optimizegit clone --depth 1 https://github.com/Awesome-Embedded-Learning-Studio/CFDesktopWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.00865 |
| Opus 5 | $0.00000 | $0.00432 |
| Sonnet 5 | $0.00000 | $0.00173 |
| Haiku 4.5 | $0.00000 | $0.00086 |
Grade A, and why
optimize scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
/optimize — 代码优化
基于 C++23 和现代 C++ 工程实践,对代码进行逼近零开销的小改动优化。
触发方式
/optimize <文件/函数>— 优化指定代码- Review 输出对接 — 用户基于审查报告请求优化
硬约束 (MUST)
- 每项优化改动 1-5 行
- 禁止改变公共 API 签名(破坏 ABI)
- 禁止改变行为(只做优化)
- 禁止大规模重构
- 必须通过
-Wall -Wextra -Wpedantic编译 - 必须通过现有测试
- 每文件每轮最多 10 项优化
- 不确定时加
@note FIXME而非猜测
优化流程
Step 1: 读取目标代码
- 读取指定文件完整内容
- 读取相关头文件和测试文件
- 理解类层次和使用上下文
Step 2: 优化检查清单
2.1 constexpr 提升
- 编译期可计算的函数 →
constexpr - 魔数 →
constexpr常量 - 类型特征和辅助工具 →
constexpr优先于模板元编程 if constexpr替代运行时分支(类型分发场景)
2.2 移动语义
- 按值返回 vs 显式
std::move(NRVO 场景不要 move,会阻碍优化) - Sink 参数用按值传递 +
std::move进成员 - 构造函数中用
std::move初始化成员 - 不要对返回局部变量
std::move(阻碍 RVO/NRVO)
2.3 零开销抽象
- 编译期可确定的多态 → 模板参数替代虚分派
- 小函数隐式内联(头文件定义)
- CRTP 替代虚分派(静态多态)
- 固定大小容器 →
std::array替代std::vector
2.4 [[nodiscard]] 标注
- 所有 const getter
- 返回所有权的工厂函数
- 返回
expected<T>或错误码的函数 - 忽略返回值会导致 bug 的函数
2.5 智能指针优化
- 独占所有权 →
std::unique_ptr(零开销) - 共享所有权 →
std::shared_ptr(仅在必要时) std::make_unique/std::make_shared优于裸new- 观察者模式 → 裸指针/引用,不用智能指针
2.6 Qt 特定优化
QString→ 使用QStringView/qsizetype- Signal/Slot → 新式连接 (
&Class::method) - 避免
QString::fromStdString不必要转换 - 像素操作 →
QImage优于QPixmap Q_FOREACH→ 范围 for 循环
Step 3: 输出格式 (中文)
# 优化建议: <file_name>
## 优化 1: <标题>
- **类别**: constexpr/移动语义/零开销/[[nodiscard]]/智能指针/Qt
- **当前代码**:
```cpp
// file:line
- 优化后代码:
// 修改后 - 原理: ...
- 影响范围: 低/中
- 验证方法: 编译 + 运行测试
优化 2: ...
总结
- 优化项数: N
- 预估性能提升: ...
- 风险等级: 整体低/中
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 94 lines · 0 tokens per session scan A 442332c5abc0
optimize is a command published in the GitHub repository Awesome-Embedded-Learning-Studio/CFDesktop (10 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 865 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other commands, from other repositories
fix-int
Fix integer type definitions for specified platform.
verify-claim
验证一条 C++ 断言 —— 编译最小例子 + 查 cppreference,给出成立/不成立的实证(金科玉律固化版).
explain
给 C++ 学习者讲一个概念 —— 先在仓库定位项目怎么讲、再验证、用项目声音讲解(learning track 4 守则固化版).
gui-anything
Build a complete GUI harness for any software application.
validate
Validate a GUI harness against HARNESS.md standards and best practices.
refine
Expand and improve an existing GUI harness with additional coverage.