Skip to content

fix(roadmap): detect function-defined CLI commands in stage #4119

Closed

Description

@dan-petty

Problem Description

The stage planner generates command checks that only search for string literals.

In pull request #4112 for issue #3296, the planner generated checks to detect new CLI commands. The check searched only for double-quoted strings such as f'"{word}"' in the command file.

Many CLI commands in src/devops_cli/commands/ use @app.command() with standard function definitions such as def <command_name>(. They do not pass a string literal to the decorator. A check that only searches for string literals fails to detect these commands. The check then treats edits to existing commands as new command additions. This causes false-positive failures during planning and implementation checks.

Reproduction Steps

  1. Inspect pull request docs(openspec): plan #3296 Require a new command's companion registrations #4112 for issue feat(roadmap): check new commands register dry-run and mcp #3296.
  2. Review the generated design.md and specs/roadmap-stage/spec.md.
  3. Observe that command detection logic checked only double-quoted strings.
  4. Compare against src/devops_cli/commands/workspace.py and src/devops_cli/commands/branches.py.
  5. Notice that commands define names through function names without literal arguments.

Expected vs Actual Behavior

Expected: Stage planning instructions and checks detect CLI commands registered either as string literals or as function names.
Actual: Stage planning generated checks that only search for double-quoted string literals.

Proposed Solution

  1. Update stage prompt instructions in src/devops_cli/ai/tasks/roadmap_stage_change.md.
  2. State that CLI command detection must inspect both string literals and function definitions under command decorators.
  3. Update AST parsing or regex checks in roadmap stage verification to recognize def <command_name>( under @app.command() or @<group>.command().

Environment Diagnostics

  • DevOps CLI Version: 0.86.0
  • Python Version: 3.14.10
  • Execution Environment: Roadmap Service Stage Job

Source: #4112

Alternatives check of 2026-11-10: partly.
Tool: griffe (https://pypi.org/project/griffe), ISC, last activity 2026-10-22, maintained.

Proposed design

Problem statement

The stage prompt does not state that a CLI command can register by a string literal or by a function name. A planner can write a negative search that looks only for a quoted literal. The stage form refuses that search, or the search misses the function form. The AST detector in the issue adds no refusal, so the change leaves it out. The change updates the prompt to name both forms and the bare-name search.

Acceptance criteria

Requirement: Stage prompt states both command registration forms

The stage prompt SHALL state that CLI command detection checks both the string literal in a command decorator and the function name under a command decorator.

Scenario: Prompt names literal and function forms

  • WHEN A reader opens src/devops_cli/ai/tasks/roadmap_stage_change.md.
  • THEN The text states that @app.command("name") registers the string literal and that @app.command() or @<group>.command() registers the function name.

Requirement: Stage prompt states the bare-name negative search

The stage prompt SHALL state that a negative search for a command name uses the bare name, so the search finds both the quoted literal and the def <name>( form.

Scenario: Prompt names the bare-name search

  • WHEN A reader opens src/devops_cli/ai/tasks/roadmap_stage_change.md.
  • THEN The text states that ! git grep -n -F <name> <path> finds both @app.command("<name>") and def <name>(.

Existing Tool Considered

griffe (https://pypi.org/project/griffe) is an open, maintained tool. It parses decorators and function names. It lacks the roadmap-stage rule for which decorators count as command registrations, the stage-verification refusal, and the prompt text. This change adopts no parser and builds no code: it updates the stage prompt only.

Key questions

  • Which command registration forms do the command files use?: The files show both forms. src/devops_cli/commands/workspace.py defines @app.command() above def add(. src/devops_cli/commands/branches.py defines @app.command("sync") and @app.command() above def update(. [sources: src/devops_cli/commands/workspace.py, src/devops_cli/commands/branches.py]
  • Where does the stage prompt hold the command detection rule?: The stage prompt is src/devops_cli/ai/tasks/roadmap_stage_change.md. [sources: src/devops_cli/ai/tasks/roadmap_stage_change.md]
  • How should the stage prompt tell the planner to detect a CLI command name?: Use the bare command name in a negative search. The search then finds the quoted literal and the def <name>( form. The stage check already refuses a search with a surviving hit. (best practice) [sources: src/devops_cli/ai/tasks/roadmap_stage_change.md, src/devops_cli/commands/workspace.py, src/devops_cli/commands/branches.py]
    • Chosen: Bare-name negative search. It finds both registration forms and the stage check refuses a surviving hit.
    • Rejected: Quoted literal only. It misses the function form and the negative-search grammar refuses the quoted literal.
    • Rejected: AST parser in the stage check. It adds no refusal and no test can trigger it.
  • Does the stage verification need an AST detector for function-defined commands?: No. A negative search for the bare name finds def add( in src/devops_cli/commands/workspace.py, so the existing no-hit rule refuses the plan. A quoted literal is refused by the negative-search grammar, and shlex.split removes the quotes. An AST detector adds no refusal. (best practice) [sources: src/devops_cli/commands/workspace.py, src/devops_cli/roadmap/stage/stage_form.py, src/devops_cli/roadmap/stage/stage_paths.py]
    • Chosen: Update the stage prompt only. The stage check already refuses a negative search that has a surviving hit.
    • Rejected: Add an AST detector to the stage verification. It adds no refusal, and no test can trigger the proposed criteria.
    • Rejected: Change the negative-search grammar. The grammar already refuses a quoted literal, and the bare name matches the function definition.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 8, 2026
  2. dan-petty commented on Nov 8, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. The defect causes false-positive check failures that block valid PRs from passing stage verification.
    • Value: Medium. False positives in command detection block valid work and erode trust in the stage planner.
    • Effort: Low. The fix targets prompt instructions and one regex or AST pattern in the stage verification path.
    • Related: feat(roadmap): check new commands register dry-run and mcp #3296, which asks for a different change. Both deal with new CLI command checks in the stage planner, but #3296 adds companion registration checks while the candidate fixes how commands are detected.
  3. added
    priority/p2-medium
    on Nov 8, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 54e5d46 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: The searches turned up only general Python static-analysis and CLI-introspection packages; griffe is the closest, since it parses decorators and function names from source and so detects both command forms the issue reports. It does not supply the project's own rule for which decorators are command registrations, nor the stage-verification refusal of a negative search, so it covers only the parsing part of the need. No ADR in force names a tool for this.

    Tool: griffe (https://pypi.org/project/griffe)

    • License: ISC
    • Last activity: 2026-10-22
    • Maintained: yes

    Covers:

    • Reads a Python module statically, without importing it, and exposes its functions with their names and decorators
    • Finds both registration forms the issue names: the string literal of @app.command("name") and the function name under @app.command() or @<group>.command()
    • Works on one source file path, which is what a stage negative search such as git grep over src/devops_cli/commands/workspace.py names

    Lacks:

    • The roadmap-stage rule for which decorators count as command registrations
    • The stage-verification behaviour that refuses a negative search which finds a function-defined command and reports the command name
    • The prompt text change in src/devops_cli/ai/tasks/roadmap_stage_change.md
    • The wiring of the detector into the stage change checks and their tests

    Tools considered:

    Searches run:

    • Typer list registered commands app.registered_commands introspect, results: 5
    • python library find typer commands defined in source file without importing AST, results: 5
    • typer.tiangolo.com Typer app registered_commands get_command API, results: 5
    • "typer" python static analysis extract command names from decorators, results: 5
    • libcst codemod find decorators function names python, results: 5
    • Typer CLI framework command introspection registered_commands, results: 5
    • typer python library, results: 5
    • python ast decorator parsing library cli command detection, results: 5
    • site:typer.tiangolo.com subcommands registered commands, results: 5
    • griffe python static analysis decorators functions API, results: 5

    Sources:

    Checked on 2026-11-10. A person decides what this means for the item. The check changes no label and closes no issue.

  7. dan-petty commented on Nov 15, 2026

    @dan-petty
    OwnerAuthor

    Returned: the refined acceptance criteria cannot trigger on the current stage grammar. Proof, read on 2026-11-15 (origin/main ca62d6a, pip 0.158.0): (1) git grep -F add src/devops_cli/commands/workspace.py gives 5 hits, among them def add( at line 143, so a negative search for a function-defined command finds it and the no-hit rule refuses the plan; there is no false pass. (2) A quoted literal that would dodge the definition is refused before any check: read_negative_search(shlex.split('! git grep -n -F -e "add" -- src/devops_cli/commands/workspace.py')) answers 'the text is not a literal of letters, digits, spaces and the signs ...'. (3) shlex.split removes the shell quotes, so -F '"add"' reaches the check as add, which matches the definition again. The stage check therefore cannot treat an existing function-defined command as new through a negative search, and an AST detector adds no refusal. File a new item if the prompt should still name both registration forms.

  8. added
    status/new
    and removed
    status/ready
    on Nov 15, 2026
  9. added
    status/ready
    and removed
    status/new
    on Nov 15, 2026
  10. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at ca62d6a (see proposed design in issue body).

  11. added
    status/in-progress
    and removed
    status/ready
    on Nov 17, 2026
  12. removed
    status/in-progress
    on Nov 17, 2026
  13. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-17 09:25 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions