Skip to content

Comments

refactor(skills): rewrite compactor to use native agent reasoning (remove external deps)#2

Merged
Yuhuan0216 merged 5 commits intomainfrom
evolution
Feb 7, 2026
Merged

refactor(skills): rewrite compactor to use native agent reasoning (remove external deps)#2
Yuhuan0216 merged 5 commits intomainfrom
evolution

Conversation

@Yuhuan0216
Copy link
Owner

This PR refactors the compactor skill to use native agent reasoning, removing external dependencies. It also includes cleanups to usage stats and cron scheduling.

@Yuhuan0216
Copy link
Owner Author

Code Review 總結

這個 PR 包含了三個主要變更,但範圍過於龐大,建議拆分。以下是詳細的
審查意見:

🔴 嚴重問題

  1. Compactor Skill 設計缺陷
  • 問題: 新的 SKILL.md
    只提供了「指導方針」,但沒有提供任何可執行的工具或命令
  • 影響: Agent 無法實際執行 compactor 功能,因為沒有明確的入口點
  • 建議: 應該提供一個具體的執行模式,例如:
    • 保留一個簡單的 shell script wrapper
    • 或者明確說明 agent 應該直接讀取檔案並在回應中提供摘要
    • 參考其他 skills 的模式,確保一致性
  1. 重複程式碼 (DRY violation)

在 workspace.ts:237-248 和
workspace.ts:273-284,相同的過濾邏輯重複了兩次:
const promptEntries = eligible.filter((entry) => {
if (entry.invocation?.disableModelInvocation === true) return
false;
const isSearch = entry.skill.name === "skills-search";
const isAlways = entry.frontmatter?.always === true ||
entry.frontmatter?.always === "true";
return isSearch || isAlways;
});
建議: 抽取為共用函數 filterPromptEligibleSkills()

  1. 型別不一致

workspace.ts:243: entry.frontmatter?.always === "true" -
frontmatter 的 always 應該是 boolean,為什麼要檢查字串 "true"?
建議: 確認 frontmatter 的型別定義,並統一處理方式

🟡 中度問題

  1. skills-search 路徑問題

skills-search/scripts/search.py:66:
parser.add_argument("--root", default="../..", ...)
使用相對路徑可能在不同執行環境下失效
建議: 使用環境變數或從專案根目錄計算絕對路徑

  1. UI 變更缺少樣式

PR 新增了 .chat-message-buttons 和 .chat-message-button CSS
classes,但沒有看到對應的樣式定義
建議: 確認是否有對應的 CSS 檔案更新

  1. 缺少錯誤處理

grouped-render.ts:65-73: extractButtons() 沒有處理格式錯誤的情況
建議: 添加 try-catch 或更嚴格的型別檢查

🟢 次要問題

  1. PR 範圍過大

PR 標題是 "refactor compactor",但實際包含:

  • Compactor 重構
  • 新增 skills-search 功能
  • UI inline buttons 支援

建議: 拆分為三個獨立的 PR

  1. 缺少測試

沒有任何測試檔案更新
建議: 至少為 search.py 和新的 UI 功能添加測試

  1. 缺少 Changelog

根據專案規範,應該更新 CHANGELOG.md
建議: 添加 changelog entry

  1. 文件描述不清晰

skills-search/SKILL.md:32: 說明使用 read tool,但這不是 shell
command,可能造成混淆
建議: 改寫為更清楚的說明,例如「Use the Read tool to load the skill
file」

✅ 優點

  1. ✅ 移除了外部依賴(@google/generative-ai),簡化部署
  2. ✅ 動態載入機制可以有效減少 context 使用
  3. ✅ UI 按鈕功能向後相容,同時支援多種格式
  4. ✅ Python script 結構清晰,邏輯合理

📋 建議行動

  1. 立即修復: 重複程式碼、型別不一致
  2. 補充: 測試、Changelog、CSS 樣式
  3. 討論: Compactor skill 的執行模式
  4. 考慮: 拆分為多個 PR

總評: 這個 PR 的方向是正確的(移除外部依賴、動態載入),但實作上有
一些問題需要修正,且範圍過大建議拆分

@Yuhuan0216 Yuhuan0216 force-pushed the evolution branch 2 times, most recently from 0581d60 to 46bac4c Compare February 7, 2026 03:16
@Yuhuan0216
Copy link
Owner Author

🔴 新發現的嚴重問題

CSS 文件被意外破壞

ui/src/styles/components.css 從 1911 行 縮減到 31 行:

  • 刪除了幾乎所有樣式(cards, buttons, forms, tables, agents, etc.
  • 只保留了新的 inline buttons 樣式
  • 這會導致整個 UI 崩潰
  • 看起來是 Git 衝突解決錯誤或意外的檔案覆蓋

-@import "./chat.css";

-/* Cards, Stats, Buttons, Forms, Tables, Agents... 1880+ lines /
+/
Only 30 lines of button styles remain */

建議: 需要立即恢復 components.css,只添加新的 button
樣式,不要刪除現有樣式。

🟡 中度問題

bin/compact shim 實用性不足

目前的 bash shim 只是打印提示訊息:
echo "To compact '$1', please:"
echo "1. Read the file content."
echo "2. Summarize it using the rules defined in SKILL.md."
這對用戶來說可能會造成困惑 - 看起來像是命令未完成。

建議: 考慮以下選項之一:

  1. 完全移除 bin/compact,在 SKILL.md 中說明這是純 agent reasoning
  2. 讓 shim 實際讀取檔案並輸出內容,讓 agent 可以處理
  3. 讓它呼叫 openclaw agent 並傳遞 compaction prompt

🟢 次要問題

  1. 測試仍然是佔位符 - workspace.test.ts
    只檢查函數是否存在,沒有實際測試邏輯
  2. PR 範圍仍然過大 - 三個不相關的功能應該拆分
  3. SKILL.md 文件可以更清晰 - skills-search/SKILL.md:332 的 "read
    tool" 說明仍可改進

📋 行動建議

緊急 (必須修復)

  1. 恢復 components.css 文件 - 不要刪除現有樣式,只添加新的 button
    樣式

建議修復

  1. 改進 bin/compact shim 或移除它
  2. 為 filterPromptEligibleSkills 添加實際測試

可選

  1. 考慮拆分 PR(但如果想保持現狀也可接受)

評分:

  • 程式碼品質: 8/10 (重複程式碼已解決)
  • 完整性: 4/10 (CSS 檔案被破壞)
  • 可合併性: ❌ 暫不可合併 (需修復 CSS)

@Yuhuan0216 Yuhuan0216 merged commit 2bea1ca into main Feb 7, 2026
Yuhuan0216 pushed a commit that referenced this pull request Feb 8, 2026
- health-manager: use resolveConfigDir() for health-stats.json path (Critical #1)

- health-manager: replace console.error with subsystem logger (Minor #3)

- health-manager: document async load race condition (Minor #2)

- bindings: use resolveConfigDir() for routing.json path (Minor #5)
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.

1 participant