Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultRecentProjectsPath() (string, error)
- func ListenForMulti(port int) (net.Listener, error)
- func NewMultiMux(reg *ProjectRegistry, recentPath string) http.Handler
- func NewMux(resolver WorkspaceResolver) http.Handler
- func SaveRecentProjects(path string, rp *RecentProjects) error
- func ServeMulti(ctx context.Context, reg *ProjectRegistry, ln net.Listener, recentPath string) (int, error)
- func Start(ws *protocol.CachedWorkspace, pm *ProcessManager, port int) error
- func StartMulti(ctx context.Context, reg *ProjectRegistry, port int, recentPath string) error
- func StartMultiOnListener(ctx context.Context, reg *ProjectRegistry, port int, recentPath string) (int, error)
- type BatchWorkspace
- type Cmd
- type Launcher
- type ProcessManager
- type ProcessWorkspace
- type ProjectEntry
- type ProjectListItem
- type ProjectRegistry
- func (r *ProjectRegistry) Add(ws *protocol.Workspace) string
- func (r *ProjectRegistry) Count() int
- func (r *ProjectRegistry) Get(id string) *protocol.CachedWorkspace
- func (r *ProjectRegistry) List() []ProjectListItem
- func (r *ProjectRegistry) Remove(id string) bool
- func (r *ProjectRegistry) ShutdownAll()
- type RecentProjects
- type RunInfo
- type WorkspaceResolver
Constants ¶
const DefaultPort = 4567
DefaultPort 是 dashboard server 的預設監聽 port,為 CLI(`4x live`)與桌面殼 (macOS Swift、Windows/Linux Tauri)啟動時的預設猜測值之單一事實來源。 Swift(dashboard/macos/Sources/main.swift)與 Rust(dashboard/tauri/src-tauri/src/main.rs) 各自維護一份等值字面常量(無法跨語言直接讀取此常量),由 internal/server/port_sync_test.go 的一致性測試守護三者不漂移;異動此值須同步更新該兩處字面常量。
Variables ¶
var Version = "dev"
Version 是目前 CLI binary 的版本號,由 main 在啟動時透過 ldflags 注入。
Functions ¶
func DefaultRecentProjectsPath ¶
DefaultRecentProjectsPath 回傳 ~/.4x/recent-projects.json
func ListenForMulti ¶ added in v0.1.2
ListenForMulti 在指定 port 建立 TCP listener,port 為 0 時由 OS 自動分配可用 port。
func NewMultiMux ¶
func NewMultiMux(reg *ProjectRegistry, recentPath string) http.Handler
NewMultiMux 建立支援多專案的 HTTP handler
func NewMux ¶
func NewMux(resolver WorkspaceResolver) http.Handler
NewMux 建立 dashboard 的 HTTP handler。每個需要資料的 handler 透過傳入的 resolver 解析該請求對應的 workspace/process manager/batch manager,使路由表只定義一次, 由 singleResolver(單一專案)或 multiResolver(多專案)共用。
func SaveRecentProjects ¶
func SaveRecentProjects(path string, rp *RecentProjects) error
SaveRecentProjects 寫入 recent-projects.json,自動建立父目錄
func ServeMulti ¶ added in v0.1.2
func ServeMulti(ctx context.Context, reg *ProjectRegistry, ln net.Listener, recentPath string) (int, error)
ServeMulti 在已建立的 listener 上啟動 dashboard server。
func Start ¶
func Start(ws *protocol.CachedWorkspace, pm *ProcessManager, port int) error
Start 啟動 dashboard web server。
func StartMulti ¶
StartMulti 啟動多專案 dashboard server,ctx 取消時 graceful shutdown。
func StartMultiOnListener ¶ added in v0.1.2
func StartMultiOnListener(ctx context.Context, reg *ProjectRegistry, port int, recentPath string) (int, error)
StartMultiOnListener 在已建立的 listener 上啟動 server(由 ListenForMulti 取得)。 回傳實際使用的 port。若傳入 port 而非 listener,使用 StartMulti。
Types ¶
type BatchWorkspace ¶ added in v0.3.6
type BatchWorkspace interface {
DotDir() string
WriteBatchStop() error
ReadBatchPID() (int, error)
ClearBatchPID() error
}
BatchWorkspace 是 BatchManager 依賴的最小 workspace 介面。 *protocol.Workspace 已滿足此介面。
type Cmd ¶ added in v0.3.6
type Cmd interface {
SetDir(dir string)
StdoutPipe() (io.ReadCloser, error)
StderrPipe() (io.ReadCloser, error)
Start() error
Wait() error
Pid() int
Signal(sig os.Signal) error
Kill() error
}
Cmd 抽出子程序需要的最小操作介面(設定工作目錄、輸出管線、啟動、等待、訊號), 讓 ProcessManager/BatchManager 依賴介面而非具體 *exec.Cmd,測試可注入假實作而不需真的產生子程序。
type ProcessManager ¶
type ProcessManager struct {
// contains filtered or unexported fields
}
ProcessManager 管理 4x run subprocess 的生命週期。
func NewProcessManager ¶
func NewProcessManager(ws *protocol.Workspace, maxParallel int, binName string) *ProcessManager
NewProcessManager 建立 ProcessManager,binName 通常是 "4x",測試可替換成假 command。
func (*ProcessManager) SetMaxParallel ¶
func (pm *ProcessManager) SetMaxParallel(n int)
SetMaxParallel 更新最大併發數,供設定變更後即時生效。
func (*ProcessManager) Shutdown ¶
func (pm *ProcessManager) Shutdown()
Shutdown 終止所有仍在執行中的 subprocess。
func (*ProcessManager) Start ¶
func (pm *ProcessManager) Start(featureID, runner string, maxRounds int, profile string, overrides []phaseOverrideReq) (*RunInfo, error)
Start 啟動一個 4x run subprocess。profile 與 overrides 為本次 run 的 pipeline profile 與 per-phase 臨時覆寫(皆可為空),會轉成對應 CLI args 傳給子程序、不寫回 settings.json。
func (*ProcessManager) Stop ¶
func (pm *ProcessManager) Stop(id string) error
Stop 終止指定的 run(SIGTERM → 5 秒 → SIGKILL)。
type ProcessWorkspace ¶ added in v0.3.6
type ProcessWorkspace interface {
AppendEvent(featureID string, evt protocol.Event) error
ReadState(featureID string) (protocol.State, error)
WriteState(featureID string, s protocol.State) error
}
ProcessWorkspace 是 ProcessManager 依賴的最小 workspace 介面,只涵蓋啟動/監控子程序需要的方法, 讓測試可注入假 workspace 而不需完整 *protocol.Workspace。*protocol.Workspace 已滿足此介面。
type ProjectEntry ¶
ProjectEntry 記錄一個最近開過的專案
type ProjectListItem ¶
type ProjectListItem struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
TaskCount int `json:"taskCount"`
}
ProjectListItem 是 GET /api/projects 的回應項目
type ProjectRegistry ¶
type ProjectRegistry struct {
// contains filtered or unexported fields
}
ProjectRegistry 管理多個 workspace 的 in-memory 註冊表
func NewProjectRegistry ¶
func NewProjectRegistry() *ProjectRegistry
NewProjectRegistry 建立空的 registry
func (*ProjectRegistry) Add ¶
func (r *ProjectRegistry) Add(ws *protocol.Workspace) string
Add 註冊一個 workspace,回傳分配的 project ID(base name,重名時加數字後綴)
func (*ProjectRegistry) Get ¶
func (r *ProjectRegistry) Get(id string) *protocol.CachedWorkspace
Get 取得指定 ID 的 workspace
func (*ProjectRegistry) Remove ¶
func (r *ProjectRegistry) Remove(id string) bool
Remove 從 registry 移除指定 ID
func (*ProjectRegistry) ShutdownAll ¶
func (r *ProjectRegistry) ShutdownAll()
ShutdownAll 終止所有專案的 subprocess
type RecentProjects ¶
type RecentProjects struct {
Projects []ProjectEntry `json:"projects"`
}
RecentProjects 管理最近開過的專案列表(LRU 順序)
func LoadRecentProjects ¶
func LoadRecentProjects(path string) (*RecentProjects, error)
LoadRecentProjects 讀取 recent-projects.json,檔案不存在時回傳空列表
func (*RecentProjects) Touch ¶
func (rp *RecentProjects) Touch(path string)
Touch 將路徑加到最前面(若已存在則移到最前),超過上限時淘汰最舊
type RunInfo ¶
type RunInfo struct {
ID string `json:"id"`
FeatureID string `json:"featureId"`
Runner string `json:"runner"`
Profile string `json:"profile,omitempty"`
Pid int `json:"pid,omitempty"`
Cmd Cmd `json:"-"`
StartTime time.Time `json:"startTime"`
// contains filtered or unexported fields
}
RunInfo 描述一個執行中的 4x run subprocess。
type WorkspaceResolver ¶
type WorkspaceResolver func(r *http.Request) (*protocol.CachedWorkspace, *ProcessManager, error)
WorkspaceResolver 從 HTTP request 解析出該請求對應的 workspace 與 process manager。 讓 NewMux 的路由表只定義一次:單一專案模式用 singleResolver 回傳固定實例,多專案模式用 multiResolver 依 URL prefix(經外層 mux 注入 context)或 compat 邏輯查找對應專案。