Skip to content

bug: duplicate annotations on re-init + annotations placed outside PHP tags in mixed HTML/PHP files #4

@workingfm

Description

@workingfm

Bug 1: Duplicate annotations on re-init (no idempotency check)

Running codedna-cli init --no-llm multiple times on an already-annotated file produces duplicate annotation blocks. The CLI does not detect that a CodeDNA header already exists before writing a new one.

Observed behavior:

// form.php — form module.
//
// exports: none
// used_by: none
// rules:   none
// agent:   codedna-cli (no-llm) | codedna-cli | 2026-04-19 | codedna-cli | initial CodeDNA annotation pass
// message: 

// form.php — form module.
//
// exports: none
// used_by: none
// rules:   none
// agent:   codedna-cli (no-llm) | codedna-cli | 2026-04-19 | codedna-cli | initial CodeDNA annotation pass

// form.php — form module.
//
// exports: none
// used_by: none
// rules:   none
// agent:   codedna-cli (no-llm) | codedna-cli | 2026-04-17 | codedna-cli | initial CodeDNA annotation pass

// form.php — form module.
//
// exports: none
// used_by: none
// rules:   none
// agent:   codedna-cli (no-llm) | codedna-cli | 2026-04-17 | codedna-cli | initial CodeDNA annotation pass

4 duplicate headers in the same file across 2 different dates (2026-04-17 and 2026-04-19), each slightly different (message: field present or absent).

Expected behavior: If a file already contains a CodeDNA annotation block (detected by presence of exports:, used_by:, rules:, agent: fields in the first comment), the CLI must skip it — no new header written.


Bug 2: Annotations injected outside <?php tags in mixed HTML/PHP files

Some PHP files use a mixed HTML+PHP structure (HTML markup with embedded <?php ?> blocks). The CLI places the annotation as a top-level // comment before the first <?php tag, so the annotation text renders as visible plain text in the browser.

Example file structure:

<!DOCTYPE html>
<html>
<!-- ... HTML content ... -->
<?php
  // actual PHP logic
?>

CLI output (broken):

// header.php — header module.
//
// exports: none
// ...
<!DOCTYPE html>
<html>

Expected behavior: For mixed HTML/PHP files, the annotation should be injected inside the first <?php block, not prepended as raw text before it. Detection heuristic: if the file starts with <!DOCTYPE, <html, or any HTML tag before the first <?php, treat it as a mixed file and place the annotation inside <?php ... ?>.


Environment

  • codedna version: 1.2.0 (installed via pip install git+https://github.com/Larens94/codedna.git)
  • mode: --no-llm
  • PHP files affected: mixed HTML/PHP templates (inc/header.php, inc/footer.php, template layouts)
  • OS: macOS Darwin 25.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions