Skip to content

fix: honor export --format json; accept neighbors/query positionals - #24

Merged
unbraind merged 11 commits into
mainfrom
fix/pm-graph-export-format-json-neighbors-query-args
Jul 14, 2026
Merged

fix: honor export --format json; accept neighbors/query positionals#24
unbraind merged 11 commits into
mainfrom
fix/pm-graph-export-format-json-neighbors-query-args

Conversation

@unbraind

@unbraind unbraind commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Problem

Two confirmed-live bugs in pm-graph v2026.7.14 (pm-graph-1fr9):

  • G2 (LOW): pm pm-graph export --format json is accepted but emits TOON (ok: true ...), not JSON. Only --json yields JSON.
  • G1 (MED): pm pm-graph neighbors <node-id> and pm pm-graph query "<cypher>" reject their documented positional arg at the contract layer with Too many arguments for extension command, while sibling commands path <from> <to> and impact <id> accept positionals.

Root cause

G2: The pm-graph export handler ignored --format entirely and always returned { ok, graph }, which the host renders as TOON by default (JSON only with --json).

G1: This is NOT primarily a missing arguments: declaration. path/impact work because they throw CommandError (numeric exitCode), which pm's runCommandHandler rethrows so the error propagates cleanly. neighbors/query threw plain Error (no exitCode), which runCommandHandler swallows (handled: false), causing a fall-through to runRequiredExtensionCommandvalidateDynamicExtensionCommandArgs; with no arguments declared, maxCount = 0 and the positional triggered the Too many arguments contract rejection. (The file already documents this contract at the top of src/index.ts.)

Fix

G2: The export handler now parses --format (both --format <fmt> and --format=<fmt>). When present, it renders the graph via the existing renderExport and returns the raw payload wrapped in a __pmGraphRawOutput marker. A registered output_format service override — chained (multiple overrides coexist by design) and strictly scoped to pm-graph export + the marker — unwraps the marker so the host writes the raw string straight to stdout. --format json now emits a valid JSON Graph document (JSON.parse(stdout) succeeds); cypher|mermaid|dot|graphml|plantuml work via the same path. Default (no --format) and --json behaviour are unchanged. Adds the services capability to manifest.json.

G1: Declare the positional arguments on neighbors (node-id) and query (cypher-query, variadic to preserve the multi-token join(" ") behaviour), AND throw CommandError (with exitCode) instead of plain Error so errors propagate cleanly to the "Neo4j is not configured" message instead of a contract/usage rejection.

Test evidence

11 new integration tests (test/export-and-contract.test.ts) drive the real pm CLI contract layer against a throwaway pm init workspace with the locally-built package installed. All 66 tests pass (npm test):

  • pm pm-graph export --format json → stdout is valid JSON (JSON.parse succeeds, has graph.nodes/graph.edges, no ok envelope).
  • pm pm-graph export (no --format) → unchanged TOON ok: true summary.
  • pm pm-graph export --json → unchanged JSON { ok, graph } envelope.
  • pm pm-graph export --format mermaid → raw graph TD diagram (no TOON prefix).
  • pm pm-graph export --format svg → clean USAGE Unknown --format "svg".
  • pm pm-graph neighbors TASK-42 → exits non-zero with Neo4j is not configured (NOT Too many arguments).
  • pm pm-graph query "MATCH (n) RETURN n LIMIT 5" → exits non-zero with Neo4j is not configured (NOT Too many arguments).
  • pm pm-graph neighbors (no arg) → contract Missing required argument node-id.
  • pm pm-graph query "CREATE (n) RETURN n"Blocked destructive Cypher keyword "CREATE" (clean, not contract rejection).
  • pm pm-graph path/impact still accept positionals and reach the handler.

npm run build, npm run typecheck, and npm run changelog:check pass.

pm item

pm-graph-1fr9


Summary by cubic

Fixes pm-graph CLI handling: pm pm-graph export --format json now writes raw, valid JSON to stdout, and neighbors/query accept their positionals with clear errors. Also switches graph loading to a single-call path to avoid N+1 subprocesses. Addresses pm item pm-graph-1fr9.

  • Bug Fixes

    • Export --format: Parse both --format <cypher|mermaid|dot|json|graphml|plantuml> and --format=<...>, last-wins if repeated, reject missing/invalid values, render via the existing exporter, and write the raw payload via an output_format service override. Default output (no --format) and --json are unchanged. Adds "services" to manifest.json.
    • Arguments and flags: Declare neighbors <node-id> and query <cypher-query...> positionals. Strip only the exact flags --json and --help from positionals so they aren’t absorbed; preserve all Cypher dash tokens (e.g. --, -->, <--, -1). Guard --format parsing from swallowing short or following flags and keep last-wins.
    • Error handling: Preserve an existing CommandError (and its exit code) in export and sync paths instead of flattening to a generic failure.
  • Refactors

    • Graph loading: Use loadGraphForContext (single list-all --include-body call) across graph commands; remove the N+1 subprocess path.
    • Output formatting: Simplify the object guard in the output_format override (no behavior change).

Written for commit 082be73. Summary will update on new commits.

Review in cubic

…ery positionals

Two confirmed-live bugs in pm-graph v2026.7.14 (pm-graph-1fr9):

G2 (export --format json emits TOON, not JSON):
The `pm-graph export` handler ignored `--format` entirely and always
returned `{ ok, graph }`, which the host renders as TOON by default (JSON
only with --json). Now the handler parses `--format` (both `--format <fmt>`
and `--format=<fmt>`); when present it renders the graph via `renderExport`
and returns the raw payload wrapped in a `__pmGraphRawOutput` marker. A
registered `output_format` service override — chained (multiple overrides
coexist by design) and strictly scoped to `pm-graph export` + the marker —
unwraps the marker so the host writes the raw string straight to stdout.
`--format json` now emits a valid JSON Graph document (JSON.parse(stdout)
succeeds); `cypher|mermaid|dot|graphml|plantuml` work via the same path.
Default (no --format) and --json behaviour is unchanged. Adds the
`services` capability to manifest.json for the service override.

G1 (neighbors/query reject documented positional at contract layer):
`pm pm-graph neighbors <id>` / `pm pm-graph query "<cypher>"` failed with
"Too many arguments for extension command". Root cause: these handlers
threw plain `Error` (no `exitCode`), which pm's `runCommandHandler` swallows
(handled=false), falling through to `runRequiredExtensionCommand` ->
`validateDynamicExtensionCommandArgs`; with no `arguments` declared,
maxCount=0 and the positional triggered the contract rejection. Sibling
commands `path`/`impact` work because they throw `CommandError` (numeric
exitCode), which `runCommandHandler` rethrows so it propagates cleanly. Fix:
declare the positional arguments on `neighbors` (`node-id`) and `query`
(`cypher-query`, variadic to preserve the multi-token join behaviour) AND
throw `CommandError` so errors propagate to the clear "Neo4j is not
configured" message instead of a contract/usage rejection.

Tests: 11 new integration tests drive the real pm CLI contract layer
against a throwaway workspace, asserting --format json validity, default
/--json regression, neighbors/query reaching "Neo4j is not configured"
(not "Too many arguments"), missing-arg contract enforcement, and that
path/impact still accept positionals. 66 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @unbraind, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Updates pm-graph export formatting, positional argument contracts, graph loading, error handling, documentation, issue records, and integration tests.

Changes

pm-graph command behavior

Layer / File(s) Summary
Command contracts and graph loading
src/index.ts
Adds command/service typing, filters host flags, replaces legacy graph loading, and updates cypher and sync.
Offline export rendering
src/index.ts, manifest.json
Adds validated offline formats, raw output handling, and the services capability.
Query and neighbors positional arguments
src/index.ts
Declares required positionals, filters known flags, and standardizes command errors.
Integration validation and project records
test/export-and-contract.test.ts, .agents/pm/..., CHANGELOG.md, README.md
Adds CLI regression coverage and records the fixes in project history, changelog, and documentation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant pm_graph_export
  participant loadGraphForContext
  participant renderExport
  participant output_format
  CLI->>pm_graph_export: invoke export with --format
  pm_graph_export->>loadGraphForContext: load graph
  pm_graph_export->>renderExport: render selected format
  pm_graph_export->>output_format: return raw-output marker
  output_format-->>CLI: print rendered graph
Loading

Suggested reviewers: github-actions[bot]

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the two main fixes: export format handling and neighbors/query positional arguments.
Description check ✅ Passed The description is directly related to the changeset and accurately explains the bugs, fixes, and test coverage.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pm-graph-export-format-json-neighbors-query-args

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 4 minutes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two bugs in pm-graph: it ensures that pm pm-graph export --format json outputs valid JSON instead of TOON by utilizing a new output_format service override, and it resolves contract-layer positional argument rejections for the neighbors and query commands by declaring their arguments and throwing CommandErrors. The changes also introduce comprehensive integration tests. Feedback on the new tests highlights two issues: spawnSync does not throw on missing executables, which breaks the pmAvailable check when pm is absent, and using __dirname as a fallback in ES modules will cause a ReferenceError on Node.js versions older than v20.11.0.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/export-and-contract.test.ts Outdated
Comment thread test/export-and-contract.test.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two bugs in pm-graph: it ensures that pm pm-graph export --format json correctly outputs valid JSON on stdout by utilizing a new output_format service override, and it resolves a contract-layer positional argument rejection for the neighbors and query commands by declaring their arguments and throwing CommandError instead of generic errors. Additionally, it updates the manifest, types, documentation, and adds comprehensive integration tests. The review feedback highlights a bug in the flag-parsing helper readFlagStringValue where a flag without a value (e.g., --format) followed by another flag (e.g., --json) would incorrectly consume the subsequent flag as its value, and provides code suggestions to fix this behavior.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts Outdated
Comment thread dist/index.js
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes pm-graph export formatting and positional CLI handling. The main changes are:

  • Adds raw export --format output through an output_format service override.
  • Declares query and neighbors positional arguments.
  • Converts several handler failures to CommandError.
  • Switches graph loading to list-all --include-body.
  • Adds integration tests for the pm CLI contract layer.

Confidence Score: 4/5

The export formatting and positional contract changes otherwise look covered by the added tests.

The changed query parsing path still mishandles a valid split Cypher token: query checks command help before rebuilding the variadic Cypher text, so a split query containing -h can return help output instead of reaching Neo4j.

src/index.ts

T-Rex T-Rex Logs

What T-Rex did

  • Reproduced the help-flag behavior by running a real-CLI repro script against the local pm-graph extension, and observed that the control split query pm pm-graph query WITH 1 AS h RETURN h exits nonzero and reaches the Neo4j is not configured path.
  • Verified that the -h path prints the usage help instead of attempting to reach configuration, confirming the help flag routing in the same repro run.
  • Inspected the contract-focused npm test run and confirmed 67 tests passed with no failures, indicating the contract-validation workflow passes.
  • Reviewed the supplementary Node test run, which exited successfully but skipped pm-dependent integration tests, providing context for coverage.
  • Linked artifacts to the proof: the Repro: generated real-CLI help-flag repro script and the command-output artifact that shows help output versus config path.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/index.ts Updates command registration, output formatting, graph loading, and argument handling for the affected pm-graph commands.
manifest.json Adds the services capability needed for the new output formatting override.
test/export-and-contract.test.ts Adds integration coverage for export formatting and positional command contract behavior.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/index.ts:2421
**Help Flag Becomes Query Control**

When a split variadic Cypher query contains `-h`, such as `WITH 1 AS h RETURN -h`, this branch runs before the query text is rebuilt. The command returns help output instead of preserving the token and running the query, so callers do not get the expected Neo4j result or configuration error.

Reviews (19): Last reviewed commit: "fix(graph): preserve typed CommandError ..." | Re-trigger Greptile

Comment thread src/index.ts
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes pm-graph CLI output and argument handling. The main changes are:

  • Adds raw export --format output through a scoped output_format service override.
  • Preserves default export output and --json envelope behavior.
  • Declares query and neighbors positional arguments.
  • Converts related handler failures to CommandError.
  • Adds integration tests for the real pm CLI contract layer.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues were found in the changed code. The raw-output override is scoped to pm-graph export and the marker payload, and the argument declarations match the handlers and covered CLI flows.

No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • I reviewed the general contract validation proof and confirmed that the log captures the full command, working directory, test output, and an EXIT_CODE of 0.
  • I verified the test run summary indicating 11 tests were executed and all 11 passed with no failures.
  • I noted that direct smoke testing was unnecessary because the highest-value existing integration slice passed and produced per-case assertions in the Node test output.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/index.ts Adds service override typing, raw export formatting, and query/neighbors argument and error handling updates.
manifest.json Adds the services capability required by the new output override.
test/export-and-contract.test.ts Adds integration coverage for export formatting and positional argument validation through the real CLI.
README.md Documents the new export format behavior and examples.

Reviews (2): Last reviewed commit: "fix(export/neighbors/query): honor --for..." | Re-trigger Greptile

…flag values

Addresses review findings on the neighbors/query positional + --format fix:

- Greptile P1: the variadic Cypher positional joined ALL context.args, so a
  trailing '--json' became part of the query string ('MATCH ... LIMIT 10
  --json'), which Neo4j rejects as a syntax error. Filter out '--'-prefixed
  flag tokens before joining. Same guard applied to 'neighbors <id>'.
- Gemini (medium): readFlagStringValue consumed a following flag as a value
  ('--format --json' -> format='--json'). Treat a next-token starting with
  '--' (or absent) as 'no value' and return null so the default applies.
- Gemini (high/medium) in the contract test: spawnSync does not throw on
  ENOENT, so the pm-availability probe now checks result.error/status instead
  of a try/catch; and __dirname (undefined in ESM) is replaced with a
  fileURLToPath(import.meta.url) derivation that works on all Node versions.

66/66 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves two main issues: G2, which enables pm pm-graph export --format json to output valid JSON to stdout instead of a TOON summary, and G1, which fixes contract-level argument rejections for neighbors and query commands by declaring positional arguments and propagating CommandErrors correctly. It introduces an output_format service override to handle raw outputs, adds robust flag parsing, and includes comprehensive integration tests. Feedback on the changes suggests refining the flag parser helper to prevent swallowing short flags starting with a single hyphen.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 18 minutes.

… --long

Gemini follow-up: readFlagStringValue only skipped '--'-prefixed values, so a
short flag (e.g. '-j') after '--format' would still be swallowed. No valid
flag value or node id starts with '-', so guard on startsWith('-') for the
flag-value lookahead and the query/neighbors arg filters alike.

66/66 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread src/index.ts Outdated
…eserve Cypher

Greptile P1 follow-up: filtering single-dash tokens from the variadic query
positional dropped valid Cypher negative literals (e.g. 'n.score < -1'). Cypher
never uses '--'-prefixed tokens, so strip only two-dash flags (--json/--help)
from the positionals to preserve query text. The short-flag guard stays on
readFlagStringValue (--format), whose values never start with '-'.

66/66 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 55 minutes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two bugs in pm-graph: it fixes the export --format json command to output valid JSON on stdout instead of TOON format by introducing an output_format service override, and it resolves positional argument rejection at the contract layer for the neighbors and query commands by declaring their arguments and throwing CommandErrors. It also adds comprehensive integration tests. The review feedback highlights a performance bottleneck where the loadGraph helper function inefficiently spawns N+1 parallel child processes; it is recommended to replace it with loadGraphForContext to fetch the graph in a single call.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts Outdated
Comment thread src/index.ts Outdated
Gemini follow-up: loadGraph spawned N+1 child processes (one list-all plus a
per-item 'pm deps <id>' call) to build the graph, which can exhaust OS process
limits on large workspaces. loadGraphForContext already builds the same graph
from a single 'list-all --json --include-body' call (the payload carries
dependencies[]/blocked_by), so switch all four command call sites to it and
drop the now-unused loadGraph + dependencyRows helpers.

66/66 tests pass (graph output unchanged).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 38 minutes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two bugs in the pm-graph extension: it ensures pm pm-graph export --format json outputs valid JSON on stdout by utilizing a new output_format service override, and it resolves contract-layer positional argument rejections for the neighbors and query commands by declaring their arguments and throwing CommandErrors. Additionally, unused helper functions were cleaned up, and comprehensive integration tests were added. The review feedback suggests preserving the original exitCode when catching and wrapping errors that are already instances of CommandError in several catch blocks across src/index.ts to ensure accurate error propagation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/index.ts
…tive -h help override

- Gemini: the sync graph-load catch now re-throws an existing CommandError
  as-is instead of re-wrapping it and flattening exitCode to GENERIC_FAILURE.
- Greptile/CodeRabbit '-h in split query': verified the pm HOST contract layer
  intercepts a standalone '-h'/'--help' token and prints command help BEFORE the
  handler runs, so an extension-level help override is dead code — reverted it.
  The documented usage quotes the query into one arg (covered by the dash-token
  test), where the host never sees a standalone '-h'. Unquoted split queries
  with a bare '-h' are a host-level limitation, not extension-controllable.

67/67 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@unbraind

Copy link
Copy Markdown
Owner Author

Round-7 responses (commit ca81bee)

  • Gemini — re-wrapping an existing CommandError: fixed. The sync graph-load catch now if (err instanceof CommandError) throw err; before wrapping, so a typed error keeps its own exitCode instead of being flattened to GENERIC_FAILURE.
  • Greptile/CodeRabbit — -h in a split query treated as help: I verified this empirically and it is a host-level behavior, not extension-controllable. Running pm pm-graph query WITH 1 AS h RETURN -h (unquoted) prints the pm contract layer's own help (Usage: pm pm-graph query [options] <cypher-query...>) before the handler is invoked — the host intercepts a standalone -h/--help token globally. An extension-side help override is therefore dead code (I tried it; it never runs), so I reverted it. The documented usage quotes the query into a single arg (query "...RETURN -h"), where the host never sees a standalone -h — this path is covered by a passing regression test. Unquoted split queries with a bare -h would need a pm-cli change (out of scope for this extension PR).

67/67 tests pass.

@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 16 minutes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses two bugs in the pm-graph extension: it ensures pm-graph export --format json outputs valid JSON on stdout by registering an output_format service override, and it declares positional arguments for neighbors and query commands to prevent contract-layer argument validation failures. Additionally, integration tests were added, and unused helper functions were removed. The review feedback suggests preserving the original CommandError instances and their exit codes when catching errors in the export command handlers, rather than flattening them to a generic failure code.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts
Comment thread src/index.ts
Comment thread src/index.ts
Gemini: the two 'Export failed' catch blocks flattened an already-typed
CommandError from loadGraphForContext to GENERIC_FAILURE, masking its exit code
(same issue fixed in sync). Add 'if (err instanceof CommandError) throw err;'
guards so all three graph-load catches preserve the original error. 67/67 tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@unbraind

Copy link
Copy Markdown
Owner Author

Round-8 responses (commit 082be73)

  • Gemini — CommandError flattened in the two export catch blocks: fixed. Both 'Export failed' catches now if (err instanceof CommandError) throw err; before wrapping, matching the sync fix — all three graph-load catch sites preserve the original typed error + exit code now.
  • Greptile — -h in split query (re-flag): as detailed above and verified empirically, this is a pm host contract-layer behavior — a standalone -h/--help token is intercepted and rendered as command help before the extension handler runs, so it is not fixable in the extension (an override is dead code). Documented usage quotes the query (single arg, covered by a passing test). Filed upstream as Contract layer intercepts -h/--help before variadic-positional handlers, blocking legit positional content pm-cli#557 to let commands opt a variadic positional out of global flag interception.

67/67 tests pass.

@unbraind

Copy link
Copy Markdown
Owner Author

@greptileai review

@unbraind

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@unbraind

Copy link
Copy Markdown
Owner Author

/gemini review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 47 seconds.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves two key bugs in the pm-graph extension. First, it updates the pm pm-graph export command to support the --format flag (including json, mermaid, dot, etc.) and ensures that raw formatted strings are written directly to stdout using a new output_format service override. Second, it fixes positional argument rejection for pm pm-graph neighbors and pm pm-graph query by declaring their arguments in the command registration and throwing CommandError instead of plain Error to prevent the host from swallowing errors and falling through to a contract rejection. Feedback is provided regarding a potential bug in pm-graph query where an unquoted query containing -h (e.g., RETURN -h) would prematurely trigger the help screen due to the generic hasHelpFlag check.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/index.ts
Comment thread src/index.ts
@unbraind

Copy link
Copy Markdown
Owner Author

Final note on the unquoted--h re-flags

Both remaining comments are the same host-level limitation, and I want to be precise about why the suggested extension-side fix cannot work:

I implemented exactly the suggested hasHelpFlag refinement (only treat -h as help when there's no positional content) and tested it against the real pm CLI. It is dead code: pm pm-graph query WITH 1 AS h RETURN -h prints the host's contract-layer help (Usage: pm pm-graph query [options] <cypher-query...>) before the handler is ever invoked. The pm host intercepts a standalone -h/--help token globally, so no handler-level check runs. I reverted the ineffective override.

What IS fixed and tested here: the documented single-arg (quoted) usage passes all dash tokens through intact (--, -->, -1, -h) — see the passing query with Cypher dash tokens test. The unquoted-split limitation needs a pm-cli change, filed as unbraind/pm-cli#557 (opt a variadic positional out of global flag interception).

Resolving these as not-extension-actionable. All other findings across the review (exact-token flag stripping, last-wins flag values, CommandError preservation at all three catch sites, N+1→single-call graph load) are fixed with 67/67 tests green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant