fix: show real project runtime agents

This commit is contained in:
Yoilun
2026-05-25 23:40:52 +08:00
parent 4262191462
commit b6648f384d
6 changed files with 371 additions and 26 deletions

View File

@@ -121,7 +121,20 @@ func readThreads(db *sql.DB, sourcePath string, sources SourceMap) ([]Thread, er
sources["threads"] = tableSource("sqlite_schema_drift", sourcePath, "threads table is missing required id column.")
return []Thread{}, nil
}
query := `SELECT ` + textColumn(columns, "id") + `, ` + textColumn(columns, "role") + `, ` + textColumn(columns, "status") + `, ` + textColumn(columns, "created_at") + `, ` + textColumn(columns, "updated_at") + ` FROM threads ORDER BY ` + orderBy(columns, "created_at", "id")
query := `SELECT ` +
textColumn(columns, "id") + `, ` +
firstTextColumn(columns, "agent_role", "role") + `, ` +
textColumn(columns, "status") + `, ` +
firstTextColumn(columns, "created_at_ms", "created_at") + `, ` +
firstTextColumn(columns, "updated_at_ms", "updated_at") + `, ` +
textColumn(columns, "cwd") + `, ` +
textColumn(columns, "title") + `, ` +
textColumn(columns, "agent_nickname") + `, ` +
textColumn(columns, "agent_role") + `, ` +
textColumn(columns, "agent_path") + `, ` +
textColumn(columns, "thread_source") + `, ` +
textColumn(columns, "preview") +
` FROM threads ORDER BY ` + orderBy(columns, "created_at_ms", "created_at", "id")
rows, err := db.Query(query)
if err != nil {
if isMissingTable(err) {
@@ -133,7 +146,20 @@ func readThreads(db *sql.DB, sourcePath string, sources SourceMap) ([]Thread, er
var threads []Thread
for rows.Next() {
var item Thread
if err := rows.Scan(&item.ID, &item.Role, &item.Status, &item.CreatedAt, &item.UpdatedAt); err != nil {
if err := rows.Scan(
&item.ID,
&item.Role,
&item.Status,
&item.CreatedAt,
&item.UpdatedAt,
&item.CWD,
&item.Title,
&item.AgentNickname,
&item.AgentRole,
&item.AgentPath,
&item.ThreadSource,
&item.Preview,
); err != nil {
return nil, err
}
item.Source = SourceEvidence{Kind: "sqlite_table", Path: sourcePath, Confidence: "high"}
@@ -152,11 +178,16 @@ func readSpawnEdges(db *sql.DB, sourcePath string, sources SourceMap) ([]SpawnEd
sources["thread_spawn_edges"] = tableSource("sqlite_missing_table", sourcePath, "thread_spawn_edges table was not found.")
return []SpawnEdge{}, nil
}
if !columns["from_thread_id"] || !columns["to_thread_id"] {
if !(columns["from_thread_id"] && columns["to_thread_id"]) && !(columns["parent_thread_id"] && columns["child_thread_id"]) {
sources["thread_spawn_edges"] = tableSource("sqlite_schema_drift", sourcePath, "thread_spawn_edges table is missing required endpoint columns.")
return []SpawnEdge{}, nil
}
query := `SELECT ` + textColumn(columns, "from_thread_id") + `, ` + textColumn(columns, "to_thread_id") + `, ` + textColumn(columns, "reason") + `, ` + textColumn(columns, "created_at") + ` FROM thread_spawn_edges ORDER BY ` + orderBy(columns, "created_at", "from_thread_id", "to_thread_id")
query := `SELECT ` +
firstTextColumn(columns, "from_thread_id", "parent_thread_id") + `, ` +
firstTextColumn(columns, "to_thread_id", "child_thread_id") + `, ` +
firstTextColumn(columns, "reason", "status") + `, ` +
textColumn(columns, "created_at") +
` FROM thread_spawn_edges ORDER BY ` + orderBy(columns, "created_at", "from_thread_id", "parent_thread_id", "to_thread_id", "child_thread_id")
rows, err := db.Query(query)
if err != nil {
if isMissingTable(err) {
@@ -191,7 +222,12 @@ func readGoals(db *sql.DB, sourcePath string, sources SourceMap) ([]Goal, error)
sources["thread_goals"] = tableSource("sqlite_schema_drift", sourcePath, "thread_goals table is missing required thread_id column.")
return []Goal{}, nil
}
query := `SELECT ` + textColumn(columns, "thread_id") + `, ` + textColumn(columns, "goal") + `, ` + textColumn(columns, "status") + `, ` + textColumn(columns, "updated_at") + ` FROM thread_goals ORDER BY ` + orderBy(columns, "updated_at", "thread_id")
query := `SELECT ` +
textColumn(columns, "thread_id") + `, ` +
firstTextColumn(columns, "goal", "objective") + `, ` +
textColumn(columns, "status") + `, ` +
firstTextColumn(columns, "updated_at_ms", "updated_at") +
` FROM thread_goals ORDER BY ` + orderBy(columns, "updated_at_ms", "updated_at", "thread_id")
rows, err := db.Query(query)
if err != nil {
if isMissingTable(err) {
@@ -244,6 +280,15 @@ func textColumn(columns map[string]bool, name string) string {
return "COALESCE(CAST(" + name + " AS TEXT), '')"
}
func firstTextColumn(columns map[string]bool, names ...string) string {
for _, name := range names {
if columns[name] {
return textColumn(columns, name)
}
}
return "''"
}
func orderBy(columns map[string]bool, names ...string) string {
var order []string
for _, name := range names {