本卡屬 FR-166(母卡 CM-3109 延伸),決策者 2026-10-28 手測後追加。主 repo(compliance-manager-be)。同批另有「排程去重」卡,兩張不改同一個檔。
白話
主系統「Agent 自主執行紀錄」頁現在只列網路除錯與一般工具的掃描,Agent 主控台手動跑的「第三方元件弱點掃描」看不到。原因是第三方元件的結果當初設計成直接落第三方元件風險自己的表(source_scans,origin=agent_manual),走跟主系統派工完全同一條分析,刻意不重複寫進 agent_local_runs。決策者要這頁變成一份完整的「Agent 掃描執行紀錄」:第三方元件那幾筆也要列出來,但只當索引、點進去跳到第三方元件結果頁,分析結果不搬、不複製。
同時把這頁改名「Agent 掃描執行紀錄」,從系統管理搬到「合規與稽核」群組、排在「第三方元件風險」後面。
問題在哪
- core/plugins/_agent_local_runs.py list_local_runs 只查套件 local_run_service(agent_local_runs 表),source_scans 裡 origin=agent_manual 的列沒進來。
- ui_routes 的 agent-local-runs 掛在 group-system-admin(sort 46),描述與 FE menu.json 都叫「Agent 自主執行紀錄」。
怎麼做
- 【extend】core/plugins/_agent_local_runs.py:list_local_runs 多撈一段 source_scans 的 origin=agent_manual 列(經 jedi-source-scan 的 domain service/repo,不直接 import ORM model;若 repo 沒有「依 origin 分頁」就在套件 repo 加一支 page_agent_manual_scans,走 poetry path dependency 開發、不發版),轉成跟 _serialize 同形狀:kind=scan、tool=sbom-scan、targets=[源碼檔名]、status 對應(done→succeeded、failed→failed、其餘視為進行中不列)、summary 帶 error_message(取 source_scans.error)、多一欄 source_scan_uid 給前端跳結果頁、has_report=false(報告在主系統第三方元件頁,不走 Agent 代取)。兩邊合併後依時間排序再切頁;總數相加。
- 【權限,新的門不可比舊的寬】這段只在呼叫者同時有 detection.remote-agent.read(本頁既有門檻)與 detection.source-scan.read 時才合併進來;沒有 source-scan.read 就只回原本那份,不報錯。判斷用 common/authz 的 capability 工具(先 grep common/authz/capability.py 既有函式名,不另寫)。
- 【extend】篩選:kind=scan 與 tool=sbom-scan 要能篩到合併進來的列;started_from/started_to 與 agent_uid 同樣套用。status 篩 succeeded/failed 對應 done/failed。
- 【new migration】scripts/sql/2026-10-28-fr166-agent-scan-runs-menu-move.sql:ui_routes 改 pid 到 group-compliance-audit、sort 放 source-scan(40)之後(41 或 42,先查現況避免撞 flow-template-manage 的 40)、description 改「Agent 掃描執行紀錄」;route name 與 url 不改(FE 路由 name 比對用、改了舊書籤會壞)。照 sql-migration skill:日期註解、驗證 DO 區塊、收尾 INSERT schema_migrations。只套 DEV;回報「出貨基線待重產」。
- 【不做】主系統臨時觸發其他工具(另案);檢測工具管理調整(另案);搬資料或複製 findings。
改哪些檔
- core/plugins/_agent_local_runs.py(154 行,可直接加;超過 300 行就把 source_scans 那段抽成 core/plugins/_agent_local_runs_source_scan.py)
- api/remote_agent/routes/agent_local_run_route.py(只有 doc 字串與回應欄位說明要補 source_scan_uid)
- scripts/sql/2026-10-28-fr166-agent-scan-runs-menu-move.sql(新)
- ~/Projects/Jedicogy/module/jedi-python-package/jedi-source-scan/jedi_source_scan/infra/source_scan/repository/source_scan_repo_impl.py 與 domain repo 介面(若需加 page_agent_manual_scans;路徑開發、不發版、pyproject path 改動不 commit)
驗證
- DEV 實打 GET /api/1.0/remote-agents/local-runs:有 source-scan.read 的帳號看到 origin=agent_manual 的三筆(兩筆 failed 帶 error_message、一筆 succeeded 帶 source_scan_uid)與原本的網路除錯列合在一起、時間新到舊;拿掉 source-scan.read 的角色只看到原本的列。