MCPcopy Create free account
hub / github.com/github/gh-aw / findEventsJSONLFile

Function findEventsJSONLFile

pkg/cli/copilot_events_jsonl.go:102–137  ·  view source on GitHub ↗

findEventsJSONLFile searches for an events.jsonl file in logDir. It first checks the canonical location at sandbox/agent/logs/copilot-session-state/ /events.jsonl and then falls back to a full recursive walk of logDir. Returns the first path found, or an empty string if not found.

(logDir string)

Source from the content-addressed store, hash-verified

100// and then falls back to a full recursive walk of logDir.
101// Returns the first path found, or an empty string if not found.
102func findEventsJSONLFile(logDir string) string {
103 copilotEventsJSONLLog.Printf("Searching for events.jsonl in: %s", logDir)
104
105 // Try the canonical location first (avoids a full directory walk in the common case)
106 sessionStateDir := filepath.Join(logDir, "sandbox", "agent", "logs", "copilot-session-state")
107 if canonicalPath := findFileInDir(sessionStateDir, "events.jsonl"); canonicalPath != "" {
108 copilotEventsJSONLLog.Printf("Found events.jsonl at canonical location: %s", canonicalPath)
109 return canonicalPath
110 }
111
112 // Fall back to a recursive search of the full log directory
113 var foundPath string
114 if walkErr := filepath.Walk(logDir, func(path string, info os.FileInfo, err error) error {
115 if err != nil {
116 copilotEventsJSONLLog.Printf("walk error at %s: %v", path, err)
117 return nil
118 }
119 if info == nil {
120 return nil
121 }
122 if !info.IsDir() && info.Name() == "events.jsonl" && foundPath == "" {
123 foundPath = path
124 return errWalkStop
125 }
126 return nil
127 }); walkErr != nil && !errors.Is(walkErr, errWalkStop) {
128 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("filesystem error walking %s: %v", logDir, walkErr)))
129 }
130
131 if foundPath != "" {
132 copilotEventsJSONLLog.Printf("Found events.jsonl via recursive search: %s", foundPath)
133 } else {
134 copilotEventsJSONLLog.Printf("events.jsonl not found in: %s", logDir)
135 }
136 return foundPath
137}
138
139// findFileInDir searches for a file by name within dir (recursively).
140// Returns the first matching path, or empty string if not found.

Callers 4

TestFindEventsJSONLFileFunction · 0.85
extractLogMetricsFunction · 0.85
inferFallbackLogMetricsFunction · 0.85

Calls 3

FormatWarningMessageFunction · 0.92
findFileInDirFunction · 0.85
PrintfMethod · 0.45

Tested by 1

TestFindEventsJSONLFileFunction · 0.68