Skip to content

[Bug]: ForgeIntegration._apply_forge_transformations corrupts frontmatter with blank lines in handoffs or nested name keys #5589

Backlog

Description

@adityajai119

Summary

ForgeIntegration._apply_forge_transformations() in src/specify_cli/integrations/forge/__init__.py uses a line scanner that mishandles valid YAML frontmatter in two ways:

  1. Blank lines inside a handoffs: block produce invalid YAML.
    Lines 228-233 exit skip_until_outdent on any line whose first character is not a space or tab, including blank lines separating handoffs: list entries. All subsequent indented handoffs: items are then emitted verbatim at the top level of frontmatter after the blank line, causing yaml.safe_load() to fail with ScannerError: mapping values are not allowed here and leaving incompatible handoffs entries in the generated Forge command file.
  2. Indented nested keys are matched as top-level name: / handoffs:.
    Lines 235 and 242 call line.strip().startswith('handoffs:') and line.strip().startswith('name:') without checking column-0 indentation. As a result, a nested mapping containing name: (for example metadata:\n name: custom) prevents injecting the required top-level name: speckit-<cmd> key, and an indented nested handoffs: sub-key is silently deleted.

Reproduction

import yaml
from specify_cli.integrations.forge import ForgeIntegration
from specify_cli.agents import CommandRegistrar

forge = ForgeIntegration()

case_blank = """---
description: Create spec
handoffs:
  - label: Build Technical Plan
    agent: speckit.plan

  - label: Clarify Spec Requirements
    agent: speckit.clarify
---

# Body
"""
out = forge._apply_forge_transformations(case_blank, "specify")
yaml.safe_load(out.split("---")[1])
# Raises: yaml.scanner.ScannerError: mapping values are not allowed here

case_nested = """---
description: Custom command
metadata:
  name: custom-meta
  handoffs: keep-me
---

# Body
"""
fm, _ = CommandRegistrar().parse_frontmatter(
    forge._apply_forge_transformations(case_nested, "specify")
)
# Returns {'description': 'Custom command', 'metadata': {'name': 'custom-meta'}}
# Missing top-level 'name' and deleted nested metadata.handoffs

Expected behavior

  • Strip only a top-level handoffs: block, continuing across blank lines inside that block so valid YAML is emitted and subsequent top-level keys remain intact.
  • Check only top-level name: when deciding whether to inject name: speckit-<cmd>, preserving existing top-level name: values and leaving nested mappings untouched.

Disclosure

This issue was discovered and filed by an AI agent (OpenCode, model: Gemini 4 Neon, autonomous mode) acting on behalf of adityajai119; reproduction was verified directly against main (f201054).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions