Repository navigation
feat: add natural language log querying #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package nlq | ||
|
|
||
| import "context" | ||
|
|
||
| type QueryIntent struct { | ||
| Query string `json:"query"` | ||
| Level string `json:"level"` | ||
| Service string `json:"service"` | ||
| Host string `json:"host"` | ||
| Since string `json:"since"` | ||
| } | ||
|
|
||
| type IntentParser interface { | ||
| Parse( | ||
| ctx context.Context, | ||
| query string, | ||
| ) (*QueryIntent, error) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Does Go time.ParseDuration support day units like 7d?💡 Result:
No, Go's time.ParseDuration function does not support "d" (day) or any units larger than hours [1][2][3]. The valid unit suffixes supported by time.ParseDuration are [1][2]: - ns (nanoseconds) - us or µs (microseconds) - ms (milliseconds) - s (seconds) - m (minutes) - h (hours) The Go language designers intentionally omitted units for days or larger intervals to avoid the ambiguity caused by daylight savings time transitions and varying day lengths [4][5][6]. If you need to represent a duration in days, you should convert it to hours (e.g., use "72h" instead of "3d" or "7d") [3][5].
Citations:
🏁 Script executed:
Repository: Aneeshie/Loom
Length of output: 95
🏁 Script executed:
# Count lines in the file to understand its size wc -l cmd/query/main.goRepository: Aneeshie/Loom
Length of output: 79
🏁 Script executed:
Repository: Aneeshie/Loom
Length of output: 255
🏁 Script executed:
Repository: Aneeshie/Loom
Length of output: 1166
🏁 Script executed:
Repository: Aneeshie/Loom
Length of output: 931
time.ParseDurationdoes not support day units ("7d").The LLM parser likely outputs durations like
"7d"for natural language queries such as "last week", but Go'stime.ParseDurationonly supportsns,us,ms,s,m,h. When parsing fails, the error is silently ignored (lines 192–193), causing theStartTimefilter to remain unset.Either normalize day units (e.g., convert
"7d"to"168h") before parsing or warn the user when parsing fails.Proposed fix — convert days to hours before parsing
if intent.Since != "" { + // Normalize day units to hours (time.ParseDuration doesn't support "d") + since := intent.Since + if strings.HasSuffix(since, "d") { + daysStr := strings.TrimSuffix(since, "d") + if days, err := strconv.Atoi(daysStr); err == nil { + since = fmt.Sprintf("%dh", days*24) + } + } duration, err := time.ParseDuration( - intent.Since, + since, ) - if err == nil { - + if err != nil { + fmt.Fprintf(os.Stderr, "warning: could not parse duration %q: %v\n", intent.Since, err) + } else { start := time.Now(). Add(-duration). Unix() - filter.StartTime = &start } }Add imports for
strconv,strings, andos.🤖 Prompt for AI Agents