CWS_conf.yaml 改變 projects 的設定方式 #1

Closed
opened 2026-04-16 14:32:17 +08:00 by MarioYang · 2 comments
Owner

目前需要再 CWS_conf.yaml 中設定要自動回覆的project,並指定他的 local 與 remote 的 path,branch
是否有可能設定 tea / gh 即可依照登入帳號找到具備權限的repo,並且在辨識標籤或 @cws 後再回覆呢?

目前需要再 `CWS_conf.yaml `中設定要自動回覆的project,並指定他的 local 與 remote 的 path,branch 是否有可能設定 tea / gh 即可依照登入帳號找到具備權限的repo,並且在辨識標籤或 @cws 後再回覆呢?
Author
Owner

[!NOTE]
Automated reply generated by code_work_spawner via gitea as @MarioYang.
Review it as bot output, not as a direct human response.

自動探索 Repo 的設計方向

這個功能(repo auto-discovery)可以拆成兩個部份分開實作:


1. Auto-discovery:用 tea / gh 列出有權限的 repo

概念:CWS_conf.yaml 新增一個 discover 區塊,取代手動列出 projects

# 新設定方式(提案)
discover:
  - provider: gitea          # 或 github
    eventSource:
      type: tea/polling
      pollInterval: 30s
    filter:
      labels: ["cws"]         # 只監聽有此 label 的 repo(optional)
      topics: ["cws-enabled"] # 或 topic 篩選
    defaultBranch: main
    worktreeBase: ~/.worktrees

# 手動 projects 仍可並存
projects:
  my-special-repo:
    ...

實作步驟(lib/src/config/config.dart + config_schema.dart):

  1. AppConfigDocument 新增 final List<DiscoverConfigDocument>? discover;
  2. 新增 DiscoverConfigDocument schema class(provider、eventSource、filter、defaultBranch)
  3. AppConfig.load() / _fromDocument() 裡,執行子程序 tea repos list --limit 50 --output json(或 gh repo list --json name,owner,defaultBranchRef),parse 結果後動態生成 ProjectConfig 實例
  4. 動態產生的 project key 用 owner/repo slug
  5. path 預設為 worktreeDir/<owner>-<repo>(可加 autoClone: true 選項讓 CWS 自動 clone)

關鍵 Dart 程式碼位置:

  • lib/src/config/config.dart_fromDocument() 新增 discovery 邏輯
  • lib/src/config/config_schema.dart → 新增 DiscoverConfigDocument
  • lib/src/core/process_launcher.dart → 可重用子程序執行

2. Label / @cws 觸發篩選(已有部份支援)

目前 mentionTriggers 已支援 @mention 偵測。Labels 觸發需要額外擴充:

defaults:
  issueAssistant:
    triggerLabels: ["needs-ai", "@cws"]  # 新增欄位
    mentionTriggers: ["@cws", "@helper"]

實作位置: IssueAssistantConfigDocument + IssueAssistantConfig,在 issue event 判斷邏輯中加入 label 檢查(參考 lib/src/core/issue_assistant_app.dart)。


建議實作順序

  1. Schema 擴充config_schema.dart)→ DiscoverConfigDocument + triggerLabels
  2. Config loadingconfig.dart)→ 執行 CLI 取得 repo 列表,動態建立 ProjectConfig
  3. Issue triggerissue_assistant_app.dart)→ 加入 label 觸發判斷
  4. Auto-clone(workspace 模組)→ 若 path 不存在則自動 git clone

注意事項

  • tea / gh 需要已登入(tea login list / gh auth status),建議在 startup 時驗證並給出明確錯誤
  • Discovery 結果應該 cache 至 dataDir,避免每次啟動都呼叫 CLI
  • 手動 projects 設定應保持向後相容

Automation note: generated by code_work_spawner via gitea as @MarioYang.

> [!NOTE] > Automated reply generated by `code_work_spawner` via `gitea` as `@MarioYang`. > Review it as bot output, not as a direct human response. ## 自動探索 Repo 的設計方向 這個功能(repo auto-discovery)可以拆成兩個部份分開實作: --- ### 1. Auto-discovery:用 `tea` / `gh` 列出有權限的 repo **概念:** 在 `CWS_conf.yaml` 新增一個 `discover` 區塊,取代手動列出 `projects`。 ```yaml # 新設定方式(提案) discover: - provider: gitea # 或 github eventSource: type: tea/polling pollInterval: 30s filter: labels: ["cws"] # 只監聽有此 label 的 repo(optional) topics: ["cws-enabled"] # 或 topic 篩選 defaultBranch: main worktreeBase: ~/.worktrees # 手動 projects 仍可並存 projects: my-special-repo: ... ``` **實作步驟(`lib/src/config/config.dart` + `config_schema.dart`):** 1. 在 `AppConfigDocument` 新增 `final List<DiscoverConfigDocument>? discover;` 2. 新增 `DiscoverConfigDocument` schema class(provider、eventSource、filter、defaultBranch) 3. 在 `AppConfig.load()` / `_fromDocument()` 裡,執行子程序 `tea repos list --limit 50 --output json`(或 `gh repo list --json name,owner,defaultBranchRef`),parse 結果後動態生成 `ProjectConfig` 實例 4. 動態產生的 project key 用 `owner/repo` slug 5. `path` 預設為 `worktreeDir/<owner>-<repo>`(可加 `autoClone: true` 選項讓 CWS 自動 clone) **關鍵 Dart 程式碼位置:** - `lib/src/config/config.dart` → `_fromDocument()` 新增 discovery 邏輯 - `lib/src/config/config_schema.dart` → 新增 `DiscoverConfigDocument` - `lib/src/core/process_launcher.dart` → 可重用子程序執行 --- ### 2. Label / @cws 觸發篩選(已有部份支援) 目前 `mentionTriggers` 已支援 @mention 偵測。Labels 觸發需要額外擴充: ```yaml defaults: issueAssistant: triggerLabels: ["needs-ai", "@cws"] # 新增欄位 mentionTriggers: ["@cws", "@helper"] ``` **實作位置:** `IssueAssistantConfigDocument` + `IssueAssistantConfig`,在 issue event 判斷邏輯中加入 label 檢查(參考 `lib/src/core/issue_assistant_app.dart`)。 --- ### 建議實作順序 1. **Schema 擴充**(`config_schema.dart`)→ `DiscoverConfigDocument` + `triggerLabels` 2. **Config loading**(`config.dart`)→ 執行 CLI 取得 repo 列表,動態建立 `ProjectConfig` 3. **Issue trigger**(`issue_assistant_app.dart`)→ 加入 label 觸發判斷 4. **Auto-clone**(workspace 模組)→ 若 `path` 不存在則自動 `git clone` --- ### 注意事項 - `tea` / `gh` 需要已登入(`tea login list` / `gh auth status`),建議在 startup 時驗證並給出明確錯誤 - Discovery 結果應該 cache 至 `dataDir`,避免每次啟動都呼叫 CLI - 手動 `projects` 設定應保持向後相容 _Automation note: generated by `code_work_spawner` via `gitea` as `@MarioYang`._ <!-- code-work-spawner:159e4f20e3e5037c5873dcbace56f774800923c9831b16474e9912d089f1d982 -->

不建議,因為 public repo 理論上是無限的。

建議還是 顯式的設定,不會有 surprise

不建議,因為 public repo 理論上是無限的。 建議還是 顯式的設定,不會有 surprise
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: MarioYang/code_work_spawner#1
No description provided.