Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ type Client struct {

// SupermodelIR is the raw response from the Supermodel API /v1/graphs/supermodel endpoint.
type SupermodelIR struct {
Repo string `json:"repo"`
Summary irSummary `json:"summary"`
Metadata irMetadata `json:"metadata"`
Domains []irDomain `json:"domains"`
}

type irSummary struct {
FilesProcessed int `json:"filesProcessed"`
Functions int `json:"functions"`
PrimaryLanguage *string `json:"primaryLanguage"`
Repo string `json:"repo"`
Summary map[string]any `json:"summary"`
Metadata irMetadata `json:"metadata"`
Domains []irDomain `json:"domains"`
}

type irMetadata struct {
Expand All @@ -67,13 +61,21 @@ func (ir *SupermodelIR) toProjectGraph(projectName string) *ProjectGraph {
if len(ir.Metadata.Languages) > 0 {
lang = ir.Metadata.Languages[0]
}
if ir.Summary.PrimaryLanguage != nil && *ir.Summary.PrimaryLanguage != "" {
lang = *ir.Summary.PrimaryLanguage
if v, ok := ir.Summary["primaryLanguage"]; ok && v != nil {
if s, ok := v.(string); ok && s != "" {
lang = s
}
}

langMap := make(map[string]int, len(ir.Metadata.Languages))
for _, l := range ir.Metadata.Languages {
langMap[l] = 0 // count not available from API
// Extract integer fields from the free-form summary map.
// JSON numbers unmarshal as float64 in map[string]any.
summaryInt := func(key string) int {
if v, ok := ir.Summary[key]; ok {
if n, ok := v.(float64); ok {
return int(n)
}
}
return 0
}

domains := make([]Domain, 0, len(ir.Domains))
Expand All @@ -96,9 +98,9 @@ func (ir *SupermodelIR) toProjectGraph(projectName string) *ProjectGraph {
Language: lang,
Domains: domains,
Stats: Stats{
TotalFiles: ir.Summary.FilesProcessed,
TotalFunctions: ir.Summary.Functions,
Languages: langMap,
TotalFiles: summaryInt("filesProcessed"),
TotalFunctions: summaryInt("functions"),
Languages: ir.Metadata.Languages,
},
UpdatedAt: time.Now(),
}
Expand Down Expand Up @@ -127,10 +129,9 @@ type Domain struct {

// Stats holds codebase statistics.
type Stats struct {
TotalFiles int `json:"total_files"`
TotalFunctions int `json:"total_functions"`
TotalLines int `json:"total_lines"`
Languages map[string]int `json:"languages,omitempty"`
TotalFiles int `json:"total_files"`
TotalFunctions int `json:"total_functions"`
Languages []string `json:"languages,omitempty"`
}

// JobStatus is the async envelope returned by the Supermodel API.
Expand Down
10 changes: 3 additions & 7 deletions internal/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const contextBombTmpl = `# Uncompact Context — {{.ProjectName}}
**Language:** {{.Graph.Language}}{{if .Graph.Framework}}
**Framework:** {{.Graph.Framework}}{{end}}{{if .Graph.Description}}
**Description:** {{.Graph.Description}}{{end}}
**Codebase:** {{.Graph.Stats.TotalFiles}} files · {{.Graph.Stats.TotalFunctions}} functions · {{.Graph.Stats.TotalLines}} lines
**Codebase:** {{.Graph.Stats.TotalFiles}} files · {{.Graph.Stats.TotalFunctions}} functions
{{- if .Graph.Stats.Languages}}

**Languages:** {{languageList .Graph.Stats.Languages}}{{end}}
Expand Down Expand Up @@ -73,12 +73,8 @@ func Render(graph *api.ProjectGraph, projectName string, opts RenderOptions) (st

funcMap := gotmpl.FuncMap{
"join": strings.Join,
"languageList": func(langs map[string]int) string {
parts := make([]string, 0, len(langs))
for lang, count := range langs {
parts = append(parts, fmt.Sprintf("%s (%d)", lang, count))
}
return strings.Join(parts, ", ")
"languageList": func(langs []string) string {
return strings.Join(langs, ", ")
},
}

Expand Down