feat(daemon-beta t1): 多資料夾 config——watch_folders[]+單數相容、manifest 每根一份、多根掃描標 Root、托盤資料層相容;rag-wave1 closed→daemon-beta 實作卷 active

- direct.go: Folders() 正規化(去重保序)/manifestPathFor(單根沿用不丟狀態、多根 sha 尾碼)/RunDirectOnce 多根彙總
- 新測試 4 支全綠(單數相容/多根去重/缺欄驗證/多根 dry-run 標 Root);既有 7 支不動全綠
- tray: config 加 watch_folders 欄(防存檔洗掉)+addWatchFolder 資料層;勾選 UI=task 7
This commit is contained in:
2026-07-24 12:09:40 +08:00
parent 44a9aeddc4
commit b355165180
3 changed files with 236 additions and 32 deletions
+35 -13
View File
@@ -16,9 +16,9 @@
package main
import (
neturl "net/url"
"encoding/json"
"fmt"
neturl "net/url"
"os"
"path/filepath"
@@ -36,16 +36,17 @@ import (
// directConfig 是 collector direct 的設定(與 collector/direct.go 的 DirectConfig 同結構;
// 這裡只需讀寫 watch_folder,其餘由安裝器帶入)。
type directConfig struct {
WatchFolder string `json:"watch_folder"`
Manifest string `json:"manifest"`
CypherURL string `json:"cypher_url"`
Namespace string `json:"namespace"`
APIKey string `json:"api_key,omitempty"`
Library string `json:"library,omitempty"`
IngestWF string `json:"ingest_workflow,omitempty"`
RemovedWF string `json:"removed_workflow,omitempty"`
PollSec int `json:"poll_interval_sec,omitempty"`
MaxRemoved float64 `json:"max_removed_ratio,omitempty"`
WatchFolder string `json:"watch_folder,omitempty"` // 單數舊制(第一個資料夾的鏡像,維持相容)
WatchFolders []string `json:"watch_folders,omitempty"` // 多資料夾(daemon-beta task 1;完整勾選 UItask 7
Manifest string `json:"manifest"`
CypherURL string `json:"cypher_url"`
Namespace string `json:"namespace"`
APIKey string `json:"api_key,omitempty"`
Library string `json:"library,omitempty"`
IngestWF string `json:"ingest_workflow,omitempty"`
RemovedWF string `json:"removed_workflow,omitempty"`
PollSec int `json:"poll_interval_sec,omitempty"`
MaxRemoved float64 `json:"max_removed_ratio,omitempty"`
}
// appDir 是設定與 manifest 落地處:~/.arcrun-rag/
@@ -69,15 +70,36 @@ func loadConfig() *directConfig {
if data, err := os.ReadFile(configPath()); err == nil {
_ = json.Unmarshal(data, c)
}
if c.WatchFolder == "" {
if c.WatchFolder == "" && len(c.WatchFolders) == 0 {
c.WatchFolder = defaultWatchFolder()
}
if c.WatchFolder == "" && len(c.WatchFolders) > 0 {
c.WatchFolder = c.WatchFolders[0] // 單數欄位=第一根鏡像(舊 collector 相容)
}
if c.Manifest == "" {
c.Manifest = filepath.Join(appDir(), "manifest.json")
}
return c
}
// addWatchFolder 把資料夾加進監看清單(去重、保序),並維持單數欄位=第一根的鏡像。
// 完整的「勾選/移除」UI 是 task 7;本函式先保證資料層正確。
func addWatchFolder(c *directConfig, p string) {
if p == "" {
return
}
if len(c.WatchFolders) == 0 && c.WatchFolder != "" && c.WatchFolder != defaultWatchFolder() {
c.WatchFolders = []string{c.WatchFolder}
}
for _, f := range c.WatchFolders {
if f == p {
return
}
}
c.WatchFolders = append(c.WatchFolders, p)
c.WatchFolder = c.WatchFolders[0]
}
func saveConfig(c *directConfig) error {
if err := os.MkdirAll(appDir(), 0o755); err != nil {
return err
@@ -123,7 +145,7 @@ func main() {
if err != nil || uri == nil {
return
}
cfg.WatchFolder = uri.Path()
addWatchFolder(cfg, uri.Path())
if err := saveConfig(cfg); err != nil {
dialog.ShowError(err, win)
return