本卡屬 FR-091(母卡 CM-1690)三張大卡之一。重:施工日誌 189 處(全部套件最多)、35 條 route、11 張表、2 支 migration、沒有 harness,且主專案接線走
config/app_modules.py的舊 blueprint 迴圈(api/detection_tools/__init__.py+infra/detection_tools/adapters.py),不在 CM-1689 的 11 支內——本卡 G 組收進core/plugins/detection.py。STATE §2 裁「detection 要開 identity port」:實查detection_profile_service.py:50與detection_orchestration_service.py:30直接from jedi_iam.domain.entities.user_query_entity import UserQueryEntity查暱稱,改走 D8 identity。
jedi-detection(檢測工具整合:profile、編排、任務下發到 agent)plugin.py 324 行 6 dataclass;api/init.py 含 ctx() 9 處與 35 條路由;logger 四種名(common.jedi_detection 11、__name__ 4、jedi_detection 1、"app" 1);22 個 entity 只有 11 個 dataclass(半套);189 處施工日誌。兩支 app service 直接 import jedi_iam 查使用者暱稱(_users.get_users(UserQueryEntity(_in_login_name=...))),是套件間反向依賴。主專案側接線散在 api/ 與 infra/ 兩處。
首腦核對(2026-09-13):plugin.py 324 行 6 dataclass;route 35;ctx() 9;entity 檔 22(11 dataclass);表 11;migration 2;tests 44 支(baseline 已跑:44 passed,無 integration);harness 無;施工日誌 189 處;logger 四種;jedi_iam 直接 import 2 處(非 authz);有吐 created_user_name(12 處);_PKG_ROOT = parent.parent / "jedi_detection"(不中 plugin 坑)。主專案 31 檔 import;接線 api/detection_tools/__init__.py(create_module)+infra/detection_tools/adapters.py(port adapter,另有 infra/readmodel/detection/detection_profile_usage_query.py 也實作 port)+config/app_modules.py:100;venv 指工作樹。
套件:/Users/chouraymond/Projects/Jedicogy/module/jedi-python-package/jedi-detection/
app/service/detection_profile_service.py:50、:1068(UserQueryEntity 查暱稱)
app/service/detection_orchestration_service.py:30
identity 範例:jedi-asset plugin/contract.py:83+app/service/_audit_names.py;jedi-survey CM-1716 commit 79e7b28;jedi-compliance-audit CM-1715(若已收回,照它)
新建 harness 範例:jedi-issue CM-1712 commit d510eb2(也是從零建)
SOP:extraction-sop.md §3.2/§4.3/§5.1/§5.2
主專案(本卡 G 組允許動):
api/detection_tools/__init__.py → 併進 core/plugins/detection.py 後刪
infra/detection_tools/adapters.py → 併進同檔 ① 段後刪(AST 掃誰在 import,若 di_containers 也用,照 CM-1700/1701 判準整批搬)
infra/readmodel/detection/detection_profile_usage_query.py → 是 readmodel 查詢實作 port,留原地並登記守衛白名單(寫明理由)
config/app_modules.py:100 → 拿掉 "detection_tools"
core/plugins/__init__.py → PLUGINS 加一列
di_containers/detection_tools/detection_orchestration/agent_task → 只改 import
test/test_module_boundaries.py → 守衛清單
現成範本:core/plugins/evidence_classification.py、core/plugins/license.py
plugin.py → plugin/ 五檔(含 migrations.py,MIGRATIONS_DIR 用 parent.parent);api/__init__.py → guards.py+routing.py(35 條)。對外 import 一字不改,31 檔 AST 掃逐一實跑。common.jedi_detection;兩支 service 拔 jedi_iam import——contract 加 identity: Optional[Any] = None,build_services() 傳進去,_users.get_users(UserQueryEntity(...)) 改 identity.resolve_user_names(logins);None 時暱稱回 None 不炸。疆界守衛突變:加回 from jedi_iam.domain... → 紅(若白名單放行了 jedi_iam 拿掉,jedi_iam.authz 若有用到保留)。inspect.signature 逐欄對照,比對表貼回寫。檢測任務狀態欄預設值要特別對。harness/(compose+--migrate+--smoke:test client 打 profile 列表 401/200,agent 呼叫用假物件頂替);pyproject.toml 加 addopts;README 補新結構、identity 接法、接線路徑。core/plugins/detection.py 三段(① infra/detection_tools/adapters.py 的 adapter 搬來 ② build_adapters 含 identity=container.identity_container.identity() ③ mount);PLUGINS 加一列;app_modules 拿掉;刪 api/detection_tools/;readmodel 那支留原地登記白名單;di_containers 改 import;守衛清單更新。adapter 延遲解析。先 AST 掃全部 import。jedi_iam.domain 的突變;identity 單元測試(假 IdentityContext → 暱稱正確;None → None 不炸)。tests/integration/test_service_behaviour.py(目錄新建):真 postgres 套 001/002,建 profile→建編排→查任務清單一輪,grant 生效。infra/detection_tools/。.venv/bin/python -c "import jedi_detection;print(jedi_detection.__file__)"。