feat: code scanner, LLM linker, and interactive FDML Viewer#17
Open
feat: code scanner, LLM linker, and interactive FDML Viewer#17
Conversation
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>
fdml parse-code command — Stage 1 code scanner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Full reverse-engineering pipeline + interactive viewer for FDML specs:
Stage 1: Code Scanner (
fdml parse-code)Stage 2: Code-to-Spec Linker (
fdml link-code)--provider anthropic(API) or--provider claude(CLI)Stage 3: Interactive Viewer (
fdml serve)/api/validateendpoint using existing ValidatorExample
examples/studio/studio.fdml— 18 entities, 24 actions, 8 features, 11 constraintsTest plan
cargo buildcompiles cleancargo test— 50/50 tests passcd web && npm run build— TypeScript compilesfdml serve examples/studio/studio.fdml— viewer loads🤖 Generated with Claude Code