MCPcopy Create free account
hub / github.com/diillson/chatcli / addAttachedToGraph

Method addAttachedToGraph

cli/graphview_adapter.go:158–213  ·  view source on GitHub ↗

addAttachedToGraph appends the session's attached context bases (with their files) and knowledge-mode corpora, all linked to the session root.

(data *plugins.GraphData, rootID string)

Source from the content-addressed store, hash-verified

156// addAttachedToGraph appends the session's attached context bases (with their
157// files) and knowledge-mode corpora, all linked to the session root.
158func (a *graphViewPluginAdapter) addAttachedToGraph(data *plugins.GraphData, rootID string) {
159 if a.cli.contextHandler == nil {
160 return
161 }
162 mgr := a.cli.contextHandler.GetManager()
163 if mgr == nil {
164 return
165 }
166 sessionID := a.cli.currentSessionName
167 if sessionID == "" {
168 sessionID = "default"
169 }
170
171 contexts, _ := mgr.GetAttachedContexts(sessionID)
172 for _, fc := range contexts {
173 if fc == nil {
174 continue
175 }
176 cid := "ctx:" + fc.ID
177 summary := fc.Description
178 if summary == "" {
179 summary = fmt.Sprintf("%d file(s), %.2f MB", fc.FileCount, float64(fc.TotalSize)/1024/1024)
180 }
181 data.Nodes = append(data.Nodes, plugins.GraphNode{ID: cid, Label: "📎 " + fc.Name, Kind: "context", Summary: summary, Weight: 3})
182 data.Edges = append(data.Edges, plugins.GraphEdge{Source: rootID, Target: cid, Weight: 2})
183
184 for i, f := range fc.Files {
185 if i >= graphViewMaxFilesPerContext {
186 moreID := cid + ":more"
187 data.Nodes = append(data.Nodes, plugins.GraphNode{
188 ID: moreID, Label: fmt.Sprintf("+%d more files", len(fc.Files)-graphViewMaxFilesPerContext), Kind: "file", Weight: 1,
189 })
190 data.Edges = append(data.Edges, plugins.GraphEdge{Source: cid, Target: moreID, Weight: 1})
191 break
192 }
193 fid := cid + ":file:" + f.Path
194 data.Nodes = append(data.Nodes, plugins.GraphNode{ID: fid, Label: filepath.Base(f.Path), Kind: "file", Summary: f.Path, Weight: 1})
195 data.Edges = append(data.Edges, plugins.GraphEdge{Source: cid, Target: fid, Weight: 1})
196 }
197 }
198
199 for _, kb := range mgr.AttachedKnowledge(sessionID) {
200 if kb == nil {
201 continue
202 }
203 kid := "kb:" + kb.ID
204 data.Nodes = append(data.Nodes, plugins.GraphNode{
205 ID: kid,
206 Label: "📚 " + kb.Name,
207 Kind: "knowledge",
208 Summary: fmt.Sprintf("%d passage(s), %.2f MB indexed", kb.FileCount, float64(kb.TotalSize)/1024/1024),
209 Weight: 3,
210 })
211 data.Edges = append(data.Edges, plugins.GraphEdge{Source: rootID, Target: kid, Weight: 2})
212 }
213}
214
215// graphViewTurnLabel renders a short, role-prefixed label for a turn node.

Callers 1

ConversationGraphMethod · 0.95

Calls 3

GetAttachedContextsMethod · 0.80
AttachedKnowledgeMethod · 0.80
GetManagerMethod · 0.45

Tested by

no test coverage detected