feat(dawgrun): CLI mode#84
Conversation
WalkthroughAdds one-shot CLI mode to dawgrun, implements JSON-backed connection persistence and a concurrency-safe Scope, extracts text rendering helpers, controls styled output, and updates commands and main routing to use the new abstractions. ChangesCLI mode and config infrastructure for dawgrun
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tools/dawgrun/pkg/commands/config.go`:
- Around line 36-45: When loading connections in the loop that calls
openConnection for each entry in config.Connections, avoid leaving a partially
applied state by tracking successfully opened connections (e.g., opened :=
[]string{}) and on any openConnection error iterate over opened to roll them
back: call an existing teardown API (or implement one) such as
closeConnection(ctx, name) or removeConnection(name) to close resources and
remove them from the in-memory registry, then return the original error (or an
aggregated error if you prefer); update the loop around openConnection and
ensure opened is appended only after a successful open and cleaned up on error.
In `@tools/dawgrun/pkg/commands/db.go`:
- Around line 186-187: The error message currently includes the raw connStr
which may leak credentials; update the fmt.Errorf call in the DB open path (the
return using driverName and connStr) to omit or redact connStr and instead
include only safe identifiers like driverName or a connection identifier.
Replace fmt.Errorf("error opening %s database connection '%s': %w", driverName,
connStr, err) with a message that does not embed connStr (e.g. fmt.Errorf("error
opening %s database connection: %w", driverName, err)) or use a
sanitized/redacted version of connStr if you must show it.
In `@tools/dawgrun/README.md`:
- Around line 54-64: Replace the indented code examples in the README CLI
section with fenced code blocks using triple backticks and a language tag (use
"text") so markdownlint MD046 is satisfied; for each example that currently
shows lines like "dawgrun >", "dawgrun parse \"match (n) return n limit 1\"",
"dawgrun > list-connections", "dawgrun > save-connections", "dawgrun >
load-connections", and the two examples with paths, wrap the example lines with
```text and ``` (opening before the example and closing after) rather than using
indentation, and apply the same fenced-block change to the other occurrences in
the same README section.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7c3893c9-4ed3-44c8-8dee-f346eb88638a
📒 Files selected for processing (20)
tools/dawgrun/.gitignoretools/dawgrun/README.mdtools/dawgrun/cmd/dawgrun/main.gotools/dawgrun/cmd/dawgrun/main_test.gotools/dawgrun/docs/RFC.mdtools/dawgrun/pkg/commands/commandcontext.gotools/dawgrun/pkg/commands/commandcontext_test.gotools/dawgrun/pkg/commands/commandscope.gotools/dawgrun/pkg/commands/config.gotools/dawgrun/pkg/commands/config_test.gotools/dawgrun/pkg/commands/cypher.gotools/dawgrun/pkg/commands/db.gotools/dawgrun/pkg/commands/help.gotools/dawgrun/pkg/commands/helpers.gotools/dawgrun/pkg/commands/opengraph.gotools/dawgrun/pkg/commands/registry.gotools/dawgrun/pkg/commands/runtime.gotools/dawgrun/pkg/texttools/cypher.gotools/dawgrun/pkg/texttools/style.gotools/dawgrun/pkg/types/config.go
💤 Files with no reviewable changes (1)
- tools/dawgrun/pkg/commands/helpers.go
| Run without arguments to start the REPL: | ||
|
|
||
| dawgrun > | ||
|
|
||
| Pass a command and its arguments to execute that command once and exit: | ||
|
|
||
| dawgrun parse "match (n) return n limit 1" | ||
|
|
||
| CLI mode reads `$XDG_CONFIG_HOME/dawgrun/config.json` (or the platform | ||
| equivalent) if it exists, so commands can refer to configured | ||
| connection names without an interactive `open` first. |
There was a problem hiding this comment.
Use fenced code blocks to satisfy markdownlint MD046.
These newly added command examples are indented code blocks, but markdownlint expects fenced blocks in this repo style (warnings at Lines 56, 60, 105, 112, 116, 120).
Suggested doc fix
-Run without arguments to start the REPL:
-
- dawgrun >
+Run without arguments to start the REPL:
+```text
+dawgrun >
+```
-Pass a command and its arguments to execute that command once and exit:
-
- dawgrun parse "match (n) return n limit 1"
+Pass a command and its arguments to execute that command once and exit:
+```text
+dawgrun parse "match (n) return n limit 1"
+```
-To list open and configured connection names directly:
-
- dawgrun > list-connections
+To list open and configured connection names directly:
+```text
+dawgrun > list-connections
+```
-Save the currently open connections to the default config file:
-
- dawgrun > save-connections
+Save the currently open connections to the default config file:
+```text
+dawgrun > save-connections
+```
-Load and open connections from the default config file:
-
- dawgrun > load-connections
+Load and open connections from the default config file:
+```text
+dawgrun > load-connections
+```
-Both commands accept an optional config path:
-
- dawgrun > save-connections ./dawgrun.local.json
- dawgrun > load-connections ./dawgrun.local.json
+Both commands accept an optional config path:
+```text
+dawgrun > save-connections ./dawgrun.local.json
+dawgrun > load-connections ./dawgrun.local.json
+```Also applies to: 103-121
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 56-56: Code block style
Expected: fenced; Actual: indented
(MD046, code-block-style)
[warning] 60-60: Code block style
Expected: fenced; Actual: indented
(MD046, code-block-style)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tools/dawgrun/README.md` around lines 54 - 64, Replace the indented code
examples in the README CLI section with fenced code blocks using triple
backticks and a language tag (use "text") so markdownlint MD046 is satisfied;
for each example that currently shows lines like "dawgrun >", "dawgrun parse
\"match (n) return n limit 1\"", "dawgrun > list-connections", "dawgrun >
save-connections", "dawgrun > load-connections", and the two examples with
paths, wrap the example lines with ```text and ``` (opening before the example
and closing after) rather than using indentation, and apply the same
fenced-block change to the other occurrences in the same README section.
kpom-specter
left a comment
There was a problem hiding this comment.
Love the direction! This sets us up for more/different way of interacting with the data
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tools/dawgrun/pkg/commands/commandscope.go (1)
85-92:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winInvalidate the cached kind map when replacing a connection.
AddConnectionupdates the handle/config but keeps any existingconnKindMaps[name]. Rebinding the same logical name can then reuse stale kind metadata from the previous backend.Suggested fix
func (s *Scope) AddConnection(name string, querier graph.Database, config types.ConnectionConfig) { s.mu.Lock() defer s.mu.Unlock() s.connections[name] = querier s.connectionConfigs[name] = config + delete(s.connKindMaps, name) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/dawgrun/pkg/commands/commandscope.go` around lines 85 - 92, AddConnection currently replaces s.connections[name] and s.connectionConfigs[name] but leaves stale metadata in s.connKindMaps[name]; update AddConnection (on type Scope) to invalidate the cached kind map for the given name when rebinding a connection by removing or clearing s.connKindMaps[name] (e.g., delete from map or set to nil) while holding s.mu, so the next use will rebuild fresh kind metadata.tools/dawgrun/pkg/commands/config.go (1)
39-58:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPreserve configured entries even when
load-connectionscannot open them.Right now only successful opens are recorded in
scope. If one connection fails to open, that entry disappears from session state, and a latersave-connectionswill rewrite the config without it. Seed the loaded configs into scope before the open loop so failed entries remain visible as configured-but-unopened.Suggested fix
if len(config.Connections) == 0 { fmt.Fprintf(ctx.output, "No connections found in %s\n", configPath) return nil } + ctx.scope.SetConnectionConfigs(config.Connections) + var connErrs error openedConns := 0 for _, connName := range slices.Sorted(maps.Keys(config.Connections)) { connConfig := config.Connections[connName]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/dawgrun/pkg/commands/config.go` around lines 39 - 58, Seed the session scope with the configured connections before attempting to open them so failed opens stay recorded: iterate the keys of config.Connections and add each config entry into the runtime scope (the same map/structure used by save-connections) prior to the loop that calls openConnection; then keep the existing open loop (which uses openConnection, connErrs, openedConns, configPath) to attempt to open each connection and only update openedConns/logging on success. Ensure the symbol you write to is the same scope/state used by save-connections so a later save will include failed-but-configured entries.
🧹 Nitpick comments (1)
tools/dawgrun/pkg/commands/help.go (1)
59-66: ⚡ Quick winSort
help alloutput for deterministic command ordering.Line 59 iterates
cmdRegistrydirectly, sohelp alloutput order is nondeterministic across runs.♻️ Proposed fix
- for name, cmd := range cmdRegistry { + for _, name := range slices.Sorted(maps.Keys(cmdRegistry)) { + cmd := cmdRegistry[name] // skip commands that are disabled for this run mode if slices.Contains(cmd.DisallowRunModes, ctx.scope.GetRunMode()) { continue } fmt.Fprintf(ctx.output, "%s", renderHelp(name, cmd)) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tools/dawgrun/pkg/commands/help.go` around lines 59 - 66, The help output iterates cmdRegistry in map order causing nondeterministic listing; to fix, collect the map keys (command names) into a slice, sort them (e.g., sort.Strings), then iterate the sorted names and for each lookup cmd := cmdRegistry[name] apply the same DisallowRunModes check (using cmd.DisallowRunModes and ctx.scope.GetRunMode()) and call fmt.Fprintf(ctx.output, "%s", renderHelp(name, cmd)); this preserves existing filtering (renderHelp, ctx.output) but ensures deterministic ordering.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tools/dawgrun/pkg/commands/commandscope.go`:
- Around line 85-92: AddConnection currently replaces s.connections[name] and
s.connectionConfigs[name] but leaves stale metadata in s.connKindMaps[name];
update AddConnection (on type Scope) to invalidate the cached kind map for the
given name when rebinding a connection by removing or clearing
s.connKindMaps[name] (e.g., delete from map or set to nil) while holding s.mu,
so the next use will rebuild fresh kind metadata.
In `@tools/dawgrun/pkg/commands/config.go`:
- Around line 39-58: Seed the session scope with the configured connections
before attempting to open them so failed opens stay recorded: iterate the keys
of config.Connections and add each config entry into the runtime scope (the same
map/structure used by save-connections) prior to the loop that calls
openConnection; then keep the existing open loop (which uses openConnection,
connErrs, openedConns, configPath) to attempt to open each connection and only
update openedConns/logging on success. Ensure the symbol you write to is the
same scope/state used by save-connections so a later save will include
failed-but-configured entries.
---
Nitpick comments:
In `@tools/dawgrun/pkg/commands/help.go`:
- Around line 59-66: The help output iterates cmdRegistry in map order causing
nondeterministic listing; to fix, collect the map keys (command names) into a
slice, sort them (e.g., sort.Strings), then iterate the sorted names and for
each lookup cmd := cmdRegistry[name] apply the same DisallowRunModes check
(using cmd.DisallowRunModes and ctx.scope.GetRunMode()) and call
fmt.Fprintf(ctx.output, "%s", renderHelp(name, cmd)); this preserves existing
filtering (renderHelp, ctx.output) but ensures deterministic ordering.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6d30fffa-b478-43a6-9260-480e7ef9c0b4
📒 Files selected for processing (11)
tools/dawgrun/README.mdtools/dawgrun/cmd/dawgrun/main.gotools/dawgrun/cmd/dawgrun/main_test.gotools/dawgrun/pkg/commands/commandcontext.gotools/dawgrun/pkg/commands/commandcontext_test.gotools/dawgrun/pkg/commands/commandscope.gotools/dawgrun/pkg/commands/config.gotools/dawgrun/pkg/commands/config_test.gotools/dawgrun/pkg/commands/db.gotools/dawgrun/pkg/commands/help.gotools/dawgrun/pkg/commands/runtime.go
✅ Files skipped from review due to trivial changes (1)
- tools/dawgrun/README.md
Description
Adds a CLI mode to dawgrun, enabling users (and agents) to run queries, copy datasets, etc.
Note that this does not have any changes in the production path.
Type of Change
Testing
make test_allwithCONNECTION_STRINGset)Screenshots (if appropriate):
Driver Impact
drivers/pg)drivers/neo4j)Checklist
go.mod/go.sumare up to date if dependencies changedSummary by CodeRabbit
New Features
Documentation
Tests