# FR-174 開發環境：jedi-detection 改走工作區原始碼

## 為什麼
P-1 要改 `jedi-detection`（migration 014 等）。主系統釘 Nexus 發行版時，import 到的是舊版，後面 BE 卡會假綠。
開發期改裝工作區（`jedi-python-package/.worktrees/CM-3422`）的原始碼，develop 模式，改檔重啟即生效。

## 現況（本機 .venv，不 commit）
`pyproject.toml` 把下列三支改成 path dependency（`develop = true`），原 pin 註解掉：
- `jedi-detection`（1.7.3b1）
- `jedi-remote-agent`（1.12.0b1）——jedi-detection 1.7.3b1 要求 `>=1.12.0b1`，主系統原釘 1.11.0，不一起改解析會失敗
- `jedi-agent-protocol`（0.2.0b1）——remote-agent 的相依，一併指工作區

`pyproject.toml`、`poetry.lock` 已 `git update-index --assume-unchanged`，`git status` 看不到。
指令：`env -u VIRTUAL_ENV poetry update jedi-detection jedi-remote-agent jedi-agent-protocol`（禁 `poetry install`、禁裸 `poetry update`）。

## 驗證
```
.venv/bin/python -c "import jedi_detection,inspect;print(inspect.getfile(jedi_detection))"
```
要印出 `.../jedi-python-package/.worktrees/CM-3422/jedi-detection/jedi_detection/__init__.py`。remote-agent、agent-protocol 同理。
起服務：`PORT=8003 .venv/bin/python main.py`，`GET /api/1.0/detection-tools` 回 401（路由已註冊、需登入）。

## 還原（Z-1 做）
```
git update-index --no-assume-unchanged pyproject.toml poetry.lock
git checkout -- pyproject.toml poetry.lock
```
之後套件發版，pin 改成新版號（detection／remote-agent／agent-protocol 三支）再 `poetry update <套件名>`。

## DEV 資料庫狀態
- 2026-11-01：DEV（localhost:5432 / guidant_ai_dev）已套 `packages/jedi_detection/014-fr174-url-profile-snapshot.sql` 並登記 `schema_migrations`（note `FR-174 H-1 DEV`）。
- `flatten_pkg_migrations.sh` 只掃 site-packages；jedi-detection 走 path 模式時不會被攤平，014 要手動複製到 `scripts/sql/packages/jedi_detection/`（目錄 gitignore）。
- SYSTEM 範圍 Profile 的重抽端點（`POST /api/1.0/detection-tool-profile-versions/<version uid>/extraction`）要平台管理員，一般管理員回 403。
- 重抽成功的前提是物件儲存可達：DEV `system_configs` 指向 `192.168.50.188:8333`，該埠不通時抓取成功但存檔失敗（status=failed，error 為 HTTPConnectionPool）。
- 2026-11-02：DEV 兩支 dev-sec（version id 2、3）重抽成功，`source_type=file`、`url` 保留、`file_id` 6405／6406；DEV 物件儲存（188:8333）已恢復。
- BE worktree 要先合 `feature/FR-172` 才起得來：remote-agent 1.12.0 的 `dispatch_gate` 參數主線才有。
- 本機 Agent 主控台在 8444（`https://agent.local:8444`，curl 要 `--resolve agent.local:8444:127.0.0.1`）；本機登入碼用 `local_login.issue()` 發，POST `/console/session`。下拉 `GET /console/api/scan/profiles?tool=inspec` 回兩支；`tool=cinc_auditor` 回空（Profile 的 tool 欄位是 `inspec`）。
