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

Method addConversationThread

cli/graphview_adapter.go:109–154  ·  view source on GitHub ↗

addConversationThread appends the turn thread and the tools it invoked, anchoring the first turn to the session root.

(data *plugins.GraphData, rootID string)

Source from the content-addressed store, hash-verified

107// addConversationThread appends the turn thread and the tools it invoked,
108// anchoring the first turn to the session root.
109func (a *graphViewPluginAdapter) addConversationThread(data *plugins.GraphData, rootID string) {
110 history := a.cli.history
111 if len(history) > graphViewMaxConversationMsgs {
112 history = history[len(history)-graphViewMaxConversationMsgs:]
113 }
114 toolSeen := make(map[string]bool)
115 prevID := ""
116 idx := 0
117 for _, m := range history {
118 if m.Role == "system" || m.Role == "tool" {
119 continue
120 }
121 content := strings.TrimSpace(m.Content)
122 if content == "" && len(m.ToolCalls) == 0 {
123 continue
124 }
125 id := "msg:" + strconv.Itoa(idx)
126 data.Nodes = append(data.Nodes, plugins.GraphNode{
127 ID: id,
128 Label: graphViewTurnLabel(m.Role, content),
129 Kind: m.Role,
130 Summary: truncateForLog(content, 400),
131 Weight: 1,
132 })
133 anchor := prevID
134 if anchor == "" {
135 anchor = rootID // first turn attaches to the session hub
136 }
137 data.Edges = append(data.Edges, plugins.GraphEdge{Source: anchor, Target: id, Weight: 1})
138 prevID = id
139
140 for _, tc := range m.ToolCalls {
141 name := strings.TrimSpace(tc.Name)
142 if name == "" {
143 continue
144 }
145 toolID := "tool:" + name
146 if !toolSeen[name] {
147 toolSeen[name] = true
148 data.Nodes = append(data.Nodes, plugins.GraphNode{ID: toolID, Label: name, Kind: "tool", Weight: 2})
149 }
150 data.Edges = append(data.Edges, plugins.GraphEdge{Source: id, Target: toolID, Weight: 1})
151 }
152 idx++
153 }
154}
155
156// addAttachedToGraph appends the session's attached context bases (with their
157// files) and knowledge-mode corpora, all linked to the session root.

Callers 1

ConversationGraphMethod · 0.95

Calls 2

graphViewTurnLabelFunction · 0.85
truncateForLogFunction · 0.70

Tested by

no test coverage detected