-
Notifications
You must be signed in to change notification settings - Fork 566
feat(cli): add logs command for viewing and managing plugin logs #385
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
base: dev
Are you sure you want to change the base?
Conversation
Add new CLI command to view, filter, and manage oh-my-opencode logs: - View last N log entries with colors and formatting - Filter by log level (all, info, warn, error) - Follow logs in real-time (tail -f style) - Output in JSON format for automation - Clear log file - Show log file path Includes 22 tests for parser functionality.
|
All contributors have signed the CLA. Thank you! ✅ |
Greptile SummaryAdds Key changes:
Issues found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI as CLI (index.ts)
participant Runner as logs/runner.ts
participant Parser as logs/parser.ts
participant Formatter as logs/formatter.ts
participant Logger as shared/logger.ts
participant FS as File System
User->>CLI: bunx oh-my-opencode logs [options]
CLI->>Runner: logs(options)
alt --path flag
Runner->>Logger: getLogFilePath()
Logger-->>Runner: log file path
Runner->>Formatter: formatPath()
Formatter-->>Runner: formatted path
Runner-->>User: display path
else --clear flag
Runner->>FS: writeFileSync(logPath, "")
Runner->>Formatter: formatSuccess()
Formatter-->>Runner: success message
Runner-->>User: "Logs cleared"
else --follow flag
Runner->>FS: readFileSync(logPath)
FS-->>Runner: initial content
Runner->>Parser: parseLogFile(content)
Parser->>Parser: parseLogLine() for each line
Parser->>Parser: detectLevel(), extractSource(), extractJsonData()
Parser-->>Runner: LogEntry[]
Runner->>Parser: filterByLevel(), getLastNEntries()
Parser-->>Runner: filtered entries
Runner->>Formatter: formatLogEntries() / formatJsonOutput()
Formatter-->>Runner: formatted output
Runner-->>User: display initial logs
loop Every 500ms
Runner->>FS: readFileSync(logPath)
FS-->>Runner: current content
Runner->>Parser: parseLogFile(content)
Parser-->>Runner: all entries
Runner->>Runner: compare with lastEntries
alt new entries detected
Runner->>Parser: filterByLevel(newEntries)
Parser-->>Runner: filtered new entries
Runner->>Formatter: formatLogEntries() / formatJsonOutput()
Formatter-->>Runner: formatted output
Runner-->>User: display new logs
end
end
else default view
Runner->>FS: readFileSync(logPath)
FS-->>Runner: file content
Runner->>Parser: parseLogFile(content)
Parser->>Parser: parseLogLine() for each line
Parser->>Parser: detectLevel(), extractSource(), extractJsonData()
Parser-->>Runner: LogEntry[]
Runner->>Parser: filterByLevel(entries, level)
Parser-->>Runner: filtered entries
Runner->>Parser: getLastNEntries(filtered, lines)
Parser-->>Runner: last N entries
Runner->>Formatter: formatLogEntries() / formatJsonOutput()
Formatter-->>Runner: formatted output
Runner-->>User: display logs
end
Runner-->>CLI: exit code
CLI-->>User: process.exit()
|
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.
Additional Comments (1)
-
src/cli/logs/parser.ts, line 64 (link)logic: greedy regex will incorrectly parse messages containing braces. If message is "User {username} failed" with data
{"error": "timeout"}, regex matches from first{in message to last}in JSON, treating{username} failed {"error": "timeout"}as JSON.
1 file reviewed, 1 comment
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.
4 issues found across 8 files
Confidence score: 3/5
src/cli/index.tsstill leaveslinesasNaNwhen the user passes a non-numeric count, so the CLI can behave unpredictably instead of falling back to 50 lines.src/cli/logs/types.tsallowsLogEntryobjects withlevel: "all", blurring filter vs entry semantics and risking incorrect downstream handling.- Smaller polish gaps remain (unreachable tail code in
src/cli/logs/runner.tsand the singular/plural wording insrc/cli/logs/formatter.ts), suggesting the CLI experience could be tightened further. - Pay close attention to
src/cli/index.ts,src/cli/logs/types.ts- input validation and log-level typing still need refinement.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/cli/logs/types.ts">
<violation number="1" location="src/cli/logs/types.ts:37">
P2: Type `LogLevel` conflates two different concepts: filter levels (where "all" means no filtering) and entry levels (where "all" is invalid). A `LogEntry` should never have `level: "all"`, but the current type allows it. Consider separating these:
```typescript
export type LogLevel = "info" | "warn" | "error"
export type LogLevelFilter = "all" | LogLevel
Then use LogLevelFilter for LogsOptions.level and LogLevel for LogEntry.level.
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
I have read the CLA Document and I hereby sign the CLA |
- Separate LogLevel (info/warn/error) from LogLevelFilter (all + LogLevel) - Fix pluralization in formatLogCount (1 entry vs N entries) - Handle NaN from parseInt for --lines option - Refactor followLogs to use Promise resolution instead of process.exit
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.
1 issue found across 6 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/cli/logs/runner.ts">
<violation number="1" location="src/cli/logs/runner.ts:152">
P2: Signal listeners are never removed after cleanup. Add `process.off()` calls to prevent potential listener accumulation in tests or if the function is reused.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Summary
oh-my-opencode logsCLI command for viewing and managing plugin logsdoctorcommand for debuggingFeatures
logslogs -n 100logs -flogs --level errorlogs --jsonlogs --clearlogs --pathFiles Added
Test Plan
bun test src/cli/logs/logs.test.tspasses (22 tests)bun run buildsucceedsSummary by cubic
Add a new
oh-my-opencode logsCLI command to view, filter, and follow plugin logs. This helps users quickly diagnose issues and complements thedoctorcommand.Written for commit 02062e5. Summary will update on new commits.