Skip to content

fix(cli): short-circuit leaf command help - #46

Merged
phodal merged 2 commits into
QoderAI:mainfrom
zqaini002:fix/leaf-command-help
Aug 1, 2026
Merged

fix(cli): short-circuit leaf command help#46
phodal merged 2 commits into
QoderAI:mainfrom
zqaini002:fix/leaf-command-help

Conversation

@zqaini002

@zqaini002 zqaini002 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

Complete side-effect-free --help and -h handling for every registered leaf command.

Why

Traceability and Scope

  • Spec/ADR: docs/specs/2026-07-31-37-leaf-command-help.md
  • Acceptance criteria addressed: AC-1, AC-2, AC-3, AC-4, AC-5
  • Canonical owners changed: CLI dispatcher; cloc; dependency-governance; harness checkup; core-change-watch help handlers
  • Explicit non-goals: normal command execution, command registry metadata, and command paths remain unchanged.

Change Type

  • Bug fix

Test and Review Evidence

Check Result
node --test test/better-harness-cli.test.mjs 35 passed; 1 Windows symlink skip
node --test test/doc-link-graph.test.mjs 6 passed
npm run pack:verify passed
npm test 1041 passed; 4 local Windows symlink-permission failures

The inventory test runs every registered terminal path from an isolated non-Git directory, compares canonical help output, verifies exact owner dispatch, and activates filesystem, stdin, process/Git, and network canaries.

Risk and Recovery

  • Cross-platform: argv-only dispatch; CI covers Windows, macOS, and Linux.
  • Package impact: package verification passed.
  • Recovery: revert this PR.
  • Residual risk: the new CI run requires maintainer approval before execution.

AI Involvement

  • Level: Generated
  • Human review and validation: automated checks listed above; no independent human review recorded.

Route registered terminal paths containing a help flag to canonical help before runtime dispatch. This prevents invalid preceding arguments from triggering runtime work. Fixes QoderAI#37.

Spec: docs/specs/2026-07-31-37-leaf-command-help.md

Test: node --test test/better-harness-cli.test.mjs; npm run pack:verify

Co-authored-by: Codex (GPT 5.6 Sol) <codex@openai.com>
@phodal

phodal commented Aug 1, 2026

Copy link
Copy Markdown
Member

Thanks for taking this on, and especially for adding a traceable spec and inventory-driven coverage. The centralized dispatch change is a useful direction. I tested the exact current head, 0526d23157c11c1ccf343315c477cce4bb05ba64, and found a few blockers that should be addressed before merge.

  1. Some registered leaf owners still execute runtime work instead of returning help.

    I materialized the PR head into an isolated non-Git directory and ran:

    node --test test/better-harness-cli.test.mjs
    

    The new inventory test failed at:

    core-change-watch change-drift invalid-before-help --help
    git rev-parse --show-toplevel failed: fatal: not a git repository
    

    Continuing across all 41 registered terminal paths showed 10 paths that still do not emit canonical help:

    • cloc runs a source count.
    • dependency-governance scans the workspace.
    • harness checkup scans workspace, agent-asset, and session evidence.
    • All seven core-change-watch subcommands execute runtime behavior: six attempt Git discovery and fail outside a repository, while qoder-consistency-schema emits a runtime JSON result.

    The dispatcher now removes preceding arguments and forwards --help, but that cannot guarantee an early return when the selected leaf owner does not implement help handling. Because -h is normalized to --help, this affects 20 of the 82 invocations described in Leaf command help can execute runtime work #37.

  2. The plain positional value help is treated as a help flag.

    hasHelpFlag(argv) calls argv.some(isHelp), and isHelp also accepts the literal string "help". For example:

    base: better-harness cloc help -> dispatches ["help"]
    head: better-harness cloc help -> dispatches ["--help"]
    

    A path, session identifier, or other valid value named help therefore changes behavior even though neither --help nor -h was supplied. This conflicts with the issue/spec requirement to preserve normal execution when no help flag is present.

  3. Built-in discovery behavior is intercepted before its existing handlers.

    The new branch runs before commands, command describe, and schema. Two reproduced examples:

    • commands --help --audience advanced previously rendered advanced-audience help; the PR falls back to workflow root help.
    • schema --help previously emitted the OpenCLI schema; the PR returns root help.

    The first case directly conflicts with AC-3's audience-filtering requirement.

  4. The new test can report false positives inside a normal Git checkout.

    It only asserts exit status, empty stderr, and non-empty stdout. Runtime reports from cloc, dependency-governance, or checkup satisfy those assertions even though they are not help and have already read workspace state. It also does not implement the prohibited-operation canary requested by Leaf command help can execute runtime work #37, assert the exact owner script, or verify that stdout is canonical help. This explains why the exact-head Linux/macOS/Windows CI matrix is green while the isolated reproduction still fails.

Suggested next steps:

  • Recognize only --help and -h as flags when scanning arbitrary argument positions.
  • Ensure every remaining leaf owner returns help before workspace/home/stdin/Git/process/network work, or provide canonical leaf help without entering runtime execution.
  • Run the inventory test from an isolated non-Git working directory.
  • Add observable read/write/stdin/child-process/Git/network canaries and verify the exact registered owner.
  • Compare stdout with canonical help rather than only checking that it is non-empty.
  • Add regressions for built-in discovery commands and the literal positional value help.
  • Update the spec acceptance/test evidence so it retains the complete side-effect boundary from Leaf command help can execute runtime work #37.

Thanks again for the contribution—the dispatcher routing is a solid foundation, but the leaf-owner and test-boundary gaps need to be closed for the issue contract to be satisfied.

Complete the QoderAI#37 help contract by preserving discovery commands, restricting help normalization to explicit flags, and returning early from every remaining runtime owner. The inventory test now verifies exact owner dispatch, canonical help output, and blocked side effects from an isolated non-Git directory.

Spec: docs/specs/2026-07-31-37-leaf-command-help.md

Test: node --test test/better-harness-cli.test.mjs; node --test test/doc-link-graph.test.mjs; npm run pack:verify

Co-authored-by: Codex (GPT 5.6 Sol) <codex@openai.com>
@zqaini002

Copy link
Copy Markdown
Author

Addressed in 443ec46.

  • Added early help returns for the remaining leaf owners.
  • Restricted positional help detection to --help and -h.
  • Preserved built-in discovery behavior.
  • Added isolated non-Git inventory coverage with side-effect canaries.

Validation:

  • node --test test/better-harness-cli.test.mjs: 35 passed, 1 Windows symlink skip
  • node --test test/doc-link-graph.test.mjs: 6 passed
  • npm run pack:verify: passed
  • npm test: 1041 passed; 4 pre-existing Windows symlink-permission failures

The new CI run is awaiting maintainer approval.

@phodal
phodal merged commit 76cb732 into QoderAI:main Aug 1, 2026
4 checks passed
sxyseo added a commit to sxyseo/better-harness that referenced this pull request Aug 1, 2026
Merge upstream/main through 76cb732 into PR QoderAI#47. Preserve both the leaf-command help side-effect guards from QoderAI#46 and the delegated machine-failure contract coverage from this branch.

Test: node --test test/better-harness-cli.test.mjs; node --test --test-name-pattern=record-fix-output test/task-loop-report.test.mjs; node --test test/scripts-refactor-contract.test.mjs; node --test test/doc-link-graph.test.mjs; npm run pack:verify

Co-authored-by: Codex (GPT 5.6 Sol) <codex@openai.com>
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.

2 participants