@@ -17,21 +17,27 @@ import (
1717// CopilotAdapter parses GitHub Copilot chat session logs
1818type CopilotAdapter struct {
1919 * BaseAdapter
20- sessionID string
21- hierarchy * hierarchy.HierarchyCache
22- log * logrus.Logger
20+ sessionID string
21+ workspaceID string // VS Code workspace ID from file path
22+ hierarchy * hierarchy.HierarchyCache
23+ log * logrus.Logger
24+ projectIDInt int // Parsed integer project ID
2325}
2426
2527// NewCopilotAdapter creates a new Copilot adapter
2628func NewCopilotAdapter (projectID string , hierarchyCache * hierarchy.HierarchyCache , log * logrus.Logger ) * CopilotAdapter {
2729 if log == nil {
2830 log = logrus .New ()
2931 }
32+ // Parse projectID string to int, default to 215 for testing
33+ projID := 215
34+
3035 return & CopilotAdapter {
31- BaseAdapter : NewBaseAdapter ("github-copilot" , projectID ),
32- sessionID : uuid .New ().String (),
33- hierarchy : hierarchyCache ,
34- log : log ,
36+ BaseAdapter : NewBaseAdapter ("github-copilot" , projectID ),
37+ sessionID : uuid .New ().String (),
38+ hierarchy : hierarchyCache ,
39+ log : log ,
40+ projectIDInt : projID ,
3541 }
3642}
3743
@@ -114,7 +120,7 @@ func (a *CopilotAdapter) ParseLogFile(filePath string) ([]*types.AgentEvent, err
114120 // Extract workspace ID from path first
115121 // Path format: .../workspaceStorage/{workspace-id}/chatSessions/{session-id}.json
116122 workspaceID := extractWorkspaceIDFromPath (filePath )
117-
123+
118124 // Resolve hierarchy context if workspace ID found and hierarchy cache available
119125 var hierarchyCtx * hierarchy.WorkspaceContext
120126 if workspaceID != "" && a .hierarchy != nil {
@@ -123,11 +129,11 @@ func (a *CopilotAdapter) ParseLogFile(filePath string) ([]*types.AgentEvent, err
123129 a .log .Warnf ("Failed to resolve workspace %s: %v - continuing without hierarchy" , workspaceID , err )
124130 } else {
125131 hierarchyCtx = ctx
126- a .log .Debugf ("Resolved hierarchy for workspace %s: project=%d, machine=%d" ,
132+ a .log .Debugf ("Resolved hierarchy for workspace %s: project=%d, machine=%d" ,
127133 workspaceID , ctx .ProjectID , ctx .MachineID )
128134 }
129135 }
130-
136+
131137 // Read the entire file
132138 data , err := os .ReadFile (filePath )
133139 if err != nil {
@@ -144,6 +150,9 @@ func (a *CopilotAdapter) ParseLogFile(filePath string) ([]*types.AgentEvent, err
144150 sessionID := extractSessionID (filePath )
145151 a .sessionID = sessionID
146152
153+ // Extract workspace ID from file path
154+ a .workspaceID = extractWorkspaceIDFromPath (filePath )
155+
147156 var events []* types.AgentEvent
148157
149158 // Process each request in the session
@@ -179,15 +188,15 @@ func extractSessionID(filePath string) string {
179188func extractWorkspaceIDFromPath (filePath string ) string {
180189 // Normalize path separators
181190 normalizedPath := filepath .ToSlash (filePath )
182-
191+
183192 // Look for workspaceStorage pattern
184193 parts := strings .Split (normalizedPath , "/" )
185194 for i , part := range parts {
186195 if part == "workspaceStorage" && i + 1 < len (parts ) {
187196 return parts [i + 1 ]
188197 }
189198 }
190-
199+
191200 return ""
192201}
193202
@@ -260,12 +269,16 @@ func (a *CopilotAdapter) createLLMRequestEvent(
260269 Timestamp : timestamp ,
261270 Type : types .EventTypeLLMRequest ,
262271 AgentID : a .name ,
272+ AgentVersion : "1.0.0" ,
263273 SessionID : a .sessionID ,
274+ ProjectID : a .projectIDInt ,
264275 LegacyProjectID : a .projectID , // Keep for backward compatibility
265276 Context : map [string ]interface {}{
266277 "username" : session .RequesterUsername ,
267278 "location" : session .InitialLocation ,
268279 "variablesCount" : len (request .VariableData .Variables ),
280+ "workspaceId" : a .workspaceID ,
281+ "workspacePath" : session .InitialLocation ,
269282 },
270283 Data : map [string ]interface {}{
271284 "requestId" : request .RequestID ,
@@ -279,7 +292,7 @@ func (a *CopilotAdapter) createLLMRequestEvent(
279292 }
280293
281294 // Add hierarchy context if available
282- if hierarchyCtx != nil {
295+ if hierarchyCtx != nil && hierarchyCtx . ProjectID > 0 {
283296 event .ProjectID = hierarchyCtx .ProjectID
284297 event .MachineID = hierarchyCtx .MachineID
285298 event .WorkspaceID = hierarchyCtx .WorkspaceID
@@ -304,7 +317,9 @@ func (a *CopilotAdapter) createLLMResponseEvent(
304317 Timestamp : timestamp .Add (time .Second ), // Slightly after request
305318 Type : types .EventTypeLLMResponse ,
306319 AgentID : a .name ,
320+ AgentVersion : "1.0.0" ,
307321 SessionID : a .sessionID ,
322+ ProjectID : a .projectIDInt ,
308323 LegacyProjectID : a .projectID ,
309324 Data : map [string ]interface {}{
310325 "requestId" : request .RequestID ,
@@ -318,7 +333,7 @@ func (a *CopilotAdapter) createLLMResponseEvent(
318333 }
319334
320335 // Add hierarchy context if available
321- if hierarchyCtx != nil {
336+ if hierarchyCtx != nil && hierarchyCtx . ProjectID > 0 {
322337 event .ProjectID = hierarchyCtx .ProjectID
323338 event .MachineID = hierarchyCtx .MachineID
324339 event .WorkspaceID = hierarchyCtx .WorkspaceID
@@ -345,7 +360,9 @@ func (a *CopilotAdapter) createFileReferenceEvent(
345360 Timestamp : timestamp ,
346361 Type : types .EventTypeFileRead ,
347362 AgentID : a .name ,
363+ AgentVersion : "1.0.0" ,
348364 SessionID : a .sessionID ,
365+ ProjectID : a .projectIDInt ,
349366 LegacyProjectID : a .projectID ,
350367 Data : map [string ]interface {}{
351368 "requestId" : request .RequestID ,
@@ -358,7 +375,7 @@ func (a *CopilotAdapter) createFileReferenceEvent(
358375 }
359376
360377 // Add hierarchy context if available
361- if hierarchyCtx != nil {
378+ if hierarchyCtx != nil && hierarchyCtx . ProjectID > 0 {
362379 event .ProjectID = hierarchyCtx .ProjectID
363380 event .MachineID = hierarchyCtx .MachineID
364381 event .WorkspaceID = hierarchyCtx .WorkspaceID
@@ -399,7 +416,9 @@ func (a *CopilotAdapter) extractToolAndResponseEvents(
399416 Timestamp : timestamp .Add (timeOffset ),
400417 Type : types .EventTypeFileRead ,
401418 AgentID : a .name ,
419+ AgentVersion : "1.0.0" ,
402420 SessionID : a .sessionID ,
421+ ProjectID : a .projectIDInt ,
403422 LegacyProjectID : a .projectID ,
404423 Data : map [string ]interface {}{
405424 "requestId" : request .RequestID ,
@@ -408,7 +427,7 @@ func (a *CopilotAdapter) extractToolAndResponseEvents(
408427 },
409428 }
410429 // Add hierarchy context if available
411- if hierarchyCtx != nil {
430+ if hierarchyCtx != nil && hierarchyCtx . ProjectID > 0 {
412431 event .ProjectID = hierarchyCtx .ProjectID
413432 event .MachineID = hierarchyCtx .MachineID
414433 event .WorkspaceID = hierarchyCtx .WorkspaceID
@@ -423,15 +442,17 @@ func (a *CopilotAdapter) extractToolAndResponseEvents(
423442 Timestamp : timestamp .Add (timeOffset ),
424443 Type : types .EventTypeFileModify ,
425444 AgentID : a .name ,
445+ AgentVersion : "1.0.0" ,
426446 SessionID : a .sessionID ,
447+ ProjectID : a .projectIDInt ,
427448 LegacyProjectID : a .projectID ,
428449 Data : map [string ]interface {}{
429450 "requestId" : request .RequestID ,
430451 "editCount" : len (item .Edits ),
431452 },
432453 }
433454 // Add hierarchy context if available
434- if hierarchyCtx != nil {
455+ if hierarchyCtx != nil && hierarchyCtx . ProjectID > 0 {
435456 event .ProjectID = hierarchyCtx .ProjectID
436457 event .MachineID = hierarchyCtx .MachineID
437458 event .WorkspaceID = hierarchyCtx .WorkspaceID
@@ -478,13 +499,15 @@ func (a *CopilotAdapter) createToolInvocationEvent(
478499 Timestamp : timestamp ,
479500 Type : types .EventTypeToolUse ,
480501 AgentID : a .name ,
502+ AgentVersion : "1.0.0" ,
481503 SessionID : a .sessionID ,
504+ ProjectID : a .projectIDInt ,
482505 LegacyProjectID : a .projectID ,
483506 Data : data ,
484507 }
485508
486509 // Add hierarchy context if available
487- if hierarchyCtx != nil {
510+ if hierarchyCtx != nil && hierarchyCtx . ProjectID > 0 {
488511 event .ProjectID = hierarchyCtx .ProjectID
489512 event .MachineID = hierarchyCtx .MachineID
490513 event .WorkspaceID = hierarchyCtx .WorkspaceID
0 commit comments