Files
Eric Rollei 1f9fa9b670 Add backward compatibility, XMP regions, per-node hooks toggle, and enhancements
Major Features:
- Backward compatibility: VALIDATE_INPUTS handles old boolean True/False values for enable_runtime_hooks parameter
- Phase 3: XMP region metadata with MWG-RS compliance (faces, areas, coordinates, extensions)
- Phase 4.4: Per-node UI toggle for runtime hooks (dropdown: Auto/Enabled/Disabled)
- Runtime hooks enhancements: performance tracking, disagreement logging, configurable limits

New Files:
- config.json: Configuration file for runtime hooks and metadata settings
- eric_metadata/hooks/runtime_capture.py: Runtime hook infrastructure
- eric_metadata/utils/config.py: Configuration loader with priority system
- eric_metadata/utils/version.py: Version helper for generated_by labels
- eric_metadata/utils/a1111.py: Automatic1111 parameter string generation
- eric_metadata/utils/jpeg_fallback.py: 4-stage JPEG metadata fallback
- eric_metadata/workflow/: Workflow parsing and generation helpers
- tests/test_backward_compatibility.py: 7 tests for parameter migration
- tests/test_xmp_regions.py: 6 tests for XMP region round-trip
- tests/test_per_node_runtime_hooks.py: 9 tests for per-node toggle

Documentation:
- CONFIG_GUIDE.md: Configuration options and usage
- RUNTIME_HOOKS_QUICK_REFERENCE.md: Quick reference for runtime hooks
- RUNTIME_HOOKS_ENHANCEMENTS_SUMMARY.md: Detailed enhancement documentation
- SAFE_RUNTIME_HOOKS_RESEARCH.md: Safety analysis and validation
- edit_log.md: Complete change history

Test Results: All 143 tests passing
- 7 backward compatibility tests
- 6 XMP region tests
- 9 per-node toggle tests
- 17 runtime hooks enhancement tests
- 104 existing tests

Breaking Changes: None - fully backward compatible
2025-11-20 01:26:04 -08:00

3.4 KiB

Metadata Emitter Integration Checklist

Use this checklist when wiring any custom node or utility into the AAA Metadata System so emitted data remains consistent and versioned correctly.

1. Imports and shared constants

  • from custom_nodes.AAA_Metadata_System import MetadataService
  • from custom_nodes.AAA_Metadata_System.eric_metadata.utils.version import get_metadata_system_version_label
  • Cache once per module: METADATA_SYSTEM_GENERATED_BY = get_metadata_system_version_label()

2. Acquire the MetadataService

  • Reuse a service passed in by parent nodes when available.
  • Otherwise construct one during __init__ (e.g., self.metadata_service = MetadataService(debug=self.debug, human_readable_text=True)).
  • Do not instantiate a new service inside hot call loops.

3. Decide where the emitter sits in the pipeline

Choose the correct section in the metadata payload:

  • ai_info.generation for sampler/execution details (already defined by save-image nodes).
  • ai_info.analysis for inspections or classifiers.
  • workflow/assist namespaces only if aligning with established schema; coordinate before introducing new top-level keys.

4. Shape and merge the payload

  • Start from an empty dict or augment an existing metadata object with _deep_merge / _merge_metadata.
  • Always add a provenance stamp: payload_section['generated_by'] = METADATA_SYSTEM_GENERATED_BY.
  • Prefer explicit keys (top_prompt, primary_subject) over ambiguous arrays.
  • Clamp numeric values, strip long strings when embedding, and move large blobs to sidecar attachments.

5. Select targets before writing

Use Case Suggested Targets
Human-readable summary only ['txt']
Structured data only ['xmp']
Shareable + structured ['txt', 'xmp']
PNG/JPEG with small payload include 'embedded'
Database sync enabled append 'db'

Adjust per node defaults or expose toggles to the user.

6. Write the metadata

self.metadata_service.write_metadata(
    resource_path,
    payload,
    targets=targets,
    resource_identifier=resource_uri,  # optional but recommended
)
  • resource_path should point at the primary output file.
  • If emitting pre-save (e.g., analysis-only node), use a logical URI and let downstream writers merge later.

7. Coordinate with discovery mode

  • When self.metadata_service.discovery_mode is True, collect unknown labels, node types, or schema changes and push them into metadata_service.discovery_logger.
  • Keep log messages concise; avoid spamming the console.

8. Tests & validation

  1. Extend or add pytest coverage that exercises the emitter and asserts the expected keys.
  2. Run the standard regression suite:
    A:/Comfy25/ComfyUI_windows_portable/python_embeded/python.exe -m pytest tests/prep/test_module_boundaries.py
    
  3. Manually inspect an emitted TXT/XMP file to confirm generated_by matches version.txt.
  4. (If applicable) open the discovery report to ensure new fields appear under the correct namespace.

9. Documentation & change log

  • Summarize the emitter addition in documentation/edit_log.md with test command.
  • Update any relevant schema docs so downstream consumers know about new keys or namespaces.

Following this checklist keeps every metadata emitter aligned with the shared version helper and prevents accidental divergence between nodes.