Skip to content

feat: code scanner, LLM linker, and interactive FDML Viewer#17

Open
kolanski wants to merge 14 commits intomainfrom
claude/project-assessment-review-luOC7
Open

feat: code scanner, LLM linker, and interactive FDML Viewer#17
kolanski wants to merge 14 commits intomainfrom
claude/project-assessment-review-luOC7

Conversation

@kolanski
Copy link
Owner

@kolanski kolanski commented Feb 8, 2026

Summary

Full reverse-engineering pipeline + interactive viewer for FDML specs:

Stage 1: Code Scanner (fdml parse-code)

  • AST-based scanning for Python, Java, C#, JavaScript, TypeScript, Go
  • Extracts classes, functions, methods, fields, imports, inheritance
  • Builds module hierarchy tree with relative paths
  • Auto-excludes dependency dirs (node_modules, venv, target, etc.)

Stage 2: Code-to-Spec Linker (fdml link-code)

  • Generates metaprompt from scan results for LLM consumption
  • Dual-provider support: --provider anthropic (API) or --provider claude (CLI)
  • Auto-fallback between providers
  • FDML spec reference template including flows section

Stage 3: Interactive Viewer (fdml serve)

  • Spec View — hierarchical cards: Features → Actions → Scenarios → Entities → Constraints
  • Graph View — full ReactFlow + ELK layout with all nodes and edges
  • Flows View — dedicated DAG visualization with flow selector dropdown
  • Flow Inference Engine — detects entity data-flow chains between actions, clusters via BFS into named lifecycle flows (e.g. "Notebook Lifecycle", "Workflow Lifecycle")
  • Health Analysis — scores spec quality (dangling refs, orphans, missing descriptions), coverage metrics, severity-grouped issues panel
  • Cross-Navigation — bidirectional scroll-to between entities, actions, features
  • Search/Filter — toolbar search filters cards live, auto-expands matches
  • Mini Flow Chains — inside expanded FeatureCards shows data-flow between actions
  • SSE Live Reload — file watcher triggers browser refresh on FDML changes
  • /api/validate endpoint using existing Validator

Example

  • examples/studio/studio.fdml — 18 entities, 24 actions, 8 features, 11 constraints

Test plan

  • cargo build compiles clean
  • cargo test — 50/50 tests pass
  • cd web && npm run build — TypeScript compiles
  • fdml serve examples/studio/studio.fdml — viewer loads
  • Verify Graph tab renders full node/edge layout
  • Verify Flows tab shows inferred lifecycle flows
  • Verify Health badge + panel shows score and issues
  • Verify search filters cards in Spec view

🤖 Generated with Claude Code

claude and others added 14 commits February 8, 2026 11:54
Implements the first stage of the reverse engineering pipeline:
existing source code → FDML inventory. Uses tree-sitter for AST
parsing with grammars statically linked into the binary.

Supports Python, Java, and C# with auto-detection by file extension.
Extracts classes, functions, methods, fields, imports, inheritance,
and inter-module relationships. Excludes dependency directories
(node_modules, venv, site-packages, etc.) automatically.

Tested on real project (slowapi): 9 classes, 9 functions, 28 methods,
82 fields, 44 relationships detected correctly.

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
For class attributes like `ENABLED = "RATELIMIT_ENABLED"`, the scanner
now correctly infers type as "str" and stores the actual value in a
separate default_value field, instead of dumping raw values into
return_type.

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
…ection

- Convert absolute file paths to relative from project root
- Add module_path field to FileAnalysis (e.g. slowapi.extension)
- Add ModuleNode tree to ScanResult showing package hierarchy
- Detect nested classes (e.g. BlackHoleHandler inside __init__)
- Detect nested functions/closures inside methods
- Use module paths in relationships for proper architecture mapping

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
- Add LinkCode command variant to CLI args
- Create linker/types.rs with LinkReport, EntityLink, ActionLink,
  FeatureSuggestion, TraceLink, CoverageReport structures
- Linking logic implementation in progress

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
- Link code inventory (from parse-code) to FDML spec elements
- Match classes → entities, functions/methods → actions by name similarity
- Suggest features from module groupings
- Generate traceability links with confidence scores
- Compute spec/code coverage percentages
- Generate structured metaprompt for LLM to make semantic decisions
  (which classes are entities vs helpers, BDD scenarios, constraints)
- Three output formats: yaml (report), json (report), prompt (LLM-ready markdown)
- When writing to file, auto-generates .prompt.md alongside report

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
Include compact FDML specification reference in the LLM metaprompt:
entity, action, feature, constraint, traceability, system structures
with data types and relation types. LLM now has full context to
generate valid FDML YAML output.

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
- Add --llm, --fast, --model flags to link-code command
- Call Anthropic API via curl (no Node.js overhead from claude CLI)
- API key from ANTHROPIC_API_KEY env var
- Progress output: prompt size, model, response size, token usage
- Strip markdown fences from LLM response
- Default: sonnet, --fast: haiku, --model: any specific model
- Without --llm: works as before (yaml/json/prompt output)

Usage:
  export ANTHROPIC_API_KEY=sk-ant-...
  fdml link-code --code inventory.yaml --llm --output spec.yaml
  fdml link-code --code inventory.yaml --llm --fast  # haiku draft

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
- call_llm() tries ANTHROPIC_API_KEY (curl) first, falls back to claude CLI
- claude CLI now uses proper flags per official docs:
  --max-turns 1, --system-prompt, --no-session-persistence, --output-format text
- Model alias support: haiku/sonnet/opus resolved to full model IDs for API
- strip_yaml_fences() shared utility for both providers

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
- --provider cli: force claude CLI (no API key needed)
- --provider api: force Anthropic API (requires ANTHROPIC_API_KEY)
- Default (auto): try API first, on failure fall back to claude CLI
- Fixes issue where invalid ANTHROPIC_API_KEY blocked CLI fallback

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
…alization

- Skip test files (tests/, test_*, *_test) from entity/action/feature candidates
- Filter test class/function names from candidates
- Fix normalize_name to handle acronyms: SlowAPIMiddleware → slow_api_middleware
- Tests still included in scan inventory, just excluded from FDML candidate lists
- Reduces prompt noise significantly (57→21 actions, 13→10 entities for slowapi)

https://claude.ai/code/session_01BnbZisntq1vNbG6S6xHAKF
Add tree-sitter based scanners for three new languages:

- JavaScript: classes, functions, arrow functions, ES module imports,
  CommonJS require(), exports, #private fields, JSDoc comments
- TypeScript: all JS constructs plus interfaces, type aliases, enums,
  abstract classes, generics, decorators, accessibility modifiers,
  type annotations on params/returns
- Go: structs, interfaces, functions, methods with receiver (attached
  to their struct), embedded types as bases, const/var declarations,
  grouped imports, visibility by name case (Upper=public, lower=internal)

Also adds:
- Frontend exclude dirs (.next, .nuxt, .cache, .turbo, storybook-static, etc.)
- Generated file filtering (.d.ts, .min.js, .bundle.js, _test.go, .pb.go)
- Module path computation for JS/TS (strip src/, index→parent dir) and
  Go (strip cmd/, internal/, pkg/)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Update supported languages list: add JavaScript, TypeScript, Go
- Add auto-skip note for node_modules, .d.ts, .min.js, _test.go, etc.
- Document link-code command with all flags and usage examples

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…is, cross-navigation

- Add flow inference engine (inferFlows.ts) that detects entity data-flow chains
  between actions and clusters them into named lifecycle flows via BFS
- Add multi-view tabs: Spec (hierarchical cards), Graph (ReactFlow+ELK), Flows (DAG)
- Add spec health analysis with scoring (errors -5, warnings -2, info -1),
  coverage metrics, and slide-out HealthPanel sidebar
- Add bidirectional navigation: entity→action and action→entity scroll-to
- Add search/filter in toolbar that filters and auto-expands matching cards
- Add mini data-flow chains inside expanded FeatureCards
- Fix metaprompt to include flows: section template and instruction #6
- Add /api/validate endpoint using existing Validator
- Add *.prompt.md to gitignore
- Include studio.fdml example (18 entities, 24 actions, 8 features)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kolanski kolanski changed the title feat: add fdml parse-code command — Stage 1 code scanner feat: code scanner, LLM linker, and interactive FDML Viewer Feb 19, 2026
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