I need to understand the full structure and relationships within desloppify/languages/ to plan a reorganization. Specifically:
What's in _shared/ — all files, what they export, who imports from them
What's in framework/ — all files and subdirs, what they export, who imports from them
How do _shared and framework relate to each other? Does _shared import from framework or vice versa?
What does the discovery mechanism in discovery.py do exactly — how does it find plugins?
Are there any other non-plugin directories or files at the languages/ level besides _shared, framework, __init__.py, and README.md?
Look at a few representative language plugin __init__.py files — what do they import from _shared vs framework?
Check if framework internally references _shared or if they're truly independent
Be thorough — I need to understand the full dependency graph between these packages to decide the best reorganization.
Assistant
I'll conduct a thorough analysis of the desloppify/languages/ directory structure and dependencies. Let me start by mapping out the files and their relationships.
Assistant
Now let me get a comprehensive directory structure:
Assistant
Now let me examine the _shared/ directory contents:
Assistant
Now the framework/ directory:
Assistant
Now let me read the key files to understand the structure. Let me start with imports in each:
Assistant
Now let me examine the shared phase files and understand what they export:
Assistant
Now let me check what framework modules import from _shared and vice versa:
Assistant
Let me check the generic.py file to see how it imports from _shared:
Assistant
Let me check what imports are in framework/generic.py and look for the _shared imports more carefully:
Assistant
Now let me check representative language plugin init.py files to see what they import:
Assistant
Now let me check what else is exported from _shared/phases_treesitter.py and phases_common.py:
Assistant
Now let me check what's in other non-plugin directories at the languages/ level:
Assistant
Now let me look at the framework base types to understand the type foundations:
Assistant
Now let me check imports more broadly. Let me look at what imports are in the framework files:
Assistant
Let me now look at framework/base/phase_builders.py to understand what shared phase builders are there:
Assistant
Now let me check shared_phases.py to see what's exported there:
Assistant
Let me get the rest of shared_phases and check all exports:
Assistant
Now let me look at what other framework files import from _shared or treesitter:
Assistant
Let me check the treesitter package structure:
Assistant
Now let me check what the treesitter init.py exports and imports:
Assistant
Now let me look at a couple more language plugins to see patterns - like Csharp and Dart which might be using generic or treesitter:
Assistant
Now let me check one of the scaffold language plugins to see their structure:
Assistant
Let me check what's in framework/treesitter/_specs.py:
Assistant
Perfect. Now let me create a comprehensive summary. Let me check one more thing - what is in the framework/base/structural.py:
Assistant
User
I'm planning a reorganization of desloppify/languages/. The goal is to merge _shared/ into framework/ so there's exactly one infrastructure directory alongside ~31 language plugin directories.
review_data/ — contains dimensions.json and __init__.py
review_dimensions.py — review dimension helpers
Assistant
I'll systematically explore the codebase to understand the current structure, imports, naming, and the move command's capabilities before designing the merge plan.
Assistant
Now let me examine the contents of all the key files to understand what's in each one and how they relate.
Assistant
Now let me examine the framework files for naming conflicts and understand the existing structure.
Assistant
Now let me examine the discovery mechanism, the move command, the review_data directory, and the actual import sites.
Assistant
Now let me look at the move command, the review_data reference in dimensions.json, the generic.py file, and the pyproject.toml for package data configuration.
Assistant
Now let me examine how review_data is actually loaded (the data loading module), the move command implementation, and the framework structural layout.
Assistant
Let me now look at how the new generic plugins reference _shared, check for any other review_data directories, and look at the framework structure more comprehensively.
Assistant
Now let me examine the remaining framework files and understand the full naming scheme.
Assistant
Let me now check the remaining pieces: how imports reference things, the _shared__init__.py exports, the README.md for languages, and the framework treesitter/__init__.py.
Assistant
Let me also check what tests exist referencing _shared and check the languages/README.md.
Assistant
Now let me check if there are any tests that directly import from _shared and look at how the .importlinter config might be relevant.
Assistant
Now I have a comprehensive understanding of the codebase. Let me check one final thing -- whether the _shared naming convention is used by discovery to skip it.
Assistant
Good. Now I have the full picture. Let me verify one last thing -- the _shared/phases_common.py vs framework/base/shared_phases.py content overlap.
Assistant
Now I have enough information. Let me compile a comprehensive analysis:
Analysis: desloppify/languages/ Structure and Dependencies
1. _shared/ Directory — All Files and Exports
Files:
__init__.py — (empty, minimal)
phases_common.py — Shared phase runners for scaffold language plugins
phases_treesitter.py — Tree-sitter phase factories for language plugins
review_data/__init__.py — Review data package (minimal)
make_*_findings() functions for specific detector outputs
discovery.py
load_all(), raise_load_errors()
generic.py
generic_lang() — factory for scaffold language plugins
Purpose:framework contains all infrastructure for building language plugins: types, registries, discovery, shared phase implementations, tree-sitter integration, and factory functions.
3. _shared ↔ framework Dependency Relationship
Direction: _shared imports FROM framework (one-way dependency):
phases_common.py imports:
from desloppify.languages.framework.base.structural import add_structural_signal, merge_structural_signals
from desloppify.languages.framework.runtime import LangRun
from desloppify.languages.framework.finding_factories import make_cycle_findings, make_orphaned_findings, make_single_use_findings
phases_treesitter.py imports:
from desloppify.languages.framework.base.types import DetectorPhase
scaffold_detect_commands.py imports:
None detected from framework (uses external detectors)
Direction: framework imports FROM _shared (opposite direction):
framework/generic.py imports:
from desloppify.languages._shared.phases_treesitter import make_ast_smells_phase, make_cohesion_phase, ...
from desloppify.languages._shared.phases_common import run_structural_phase, run_coupling_phase
Relationship Summary:
framework is the lower-level infrastructure (types, registries, discovery, shared phases)
_shared is higher-level reusable code that depends on framework types and utilities
generic.py (in framework) imports from _shared to assemble scaffold plugin phases
Effectively: _shared and framework form a layered stack where framework is the foundation
framework is the foundational layer — no reorganization there without major ripple effects
_shared contains reusable logic — could be moved INTO framework/ as a subpackage without breaking dependencies, since only generic.py imports it
generic.py is the coupling point — it's the only place in framework that imports _shared
Language plugins are decoupled — most only import from framework, not _shared directly (except tree-sitter-using ones like GDScript, TypeScript, C#, Dart)
Suggestion: Could flatten to framework/phases/ subpackage containing both shared runners and tree-sitter factories, eliminating the _shared directory entirely and making dependencies clearer
Import counts: 133 imports from framework, 15 from _shared.
The project has a desloppify move command that handles import rewiring.
Plan the optimal merge:
Where should each _shared file go within framework/? Should they go at the top level of framework, or into a new subpackage?
What about naming conflicts? (e.g., _shared/phases_common.py vs framework/base/shared_phases.py)
Should _shared/review_data/ (JSON files) go into framework or stay somewhere else?
What's the best order of operations?
Are there any risks with the desloppify move command for this kind of restructuring (it's designed for source files in scanned projects, not necessarily for moving its own internal modules)?
After the merge, the hardcoded d.name != "framework" check in discovery.py — should it stay, or should we rename framework to _framework for consistency?
Consider that the user said "I want this to be beautiful" — optimize for clarity, not just minimum effort.
Now I have a thorough understanding of the entire layout. Let me compile the analysis and plan.
Here is the complete analysis and implementation plan for merging _shared/ into framework/.
1. Current State Summary
_shared/ contains 5 Python files and 1 data directory (17 total import sites):
Destination: framework/base/shared_phases.py -- merge into the existing file.
Reasoning: shared_phases.py already contains phase_security, phase_test_coverage, phase_dupes, phase_boilerplate_duplication, phase_signature, phase_subjective_review, phase_private_imports, and helper find_external_test_files. These are all shared phase runners. run_structural_phase and run_coupling_phase are exactly the same concept. The existing file is 305 lines; adding 175 lines brings it to ~480 -- substantial but coherent since every function is a shared phase runner with the same signature pattern (path, lang) -> (findings, potentials).
Naming conflict resolution: The names run_structural_phase and run_coupling_phase use a run_* prefix while existing functions in shared_phases.py use a phase_* prefix. I recommend keeping the existing names as-is during the merge (no renames) to minimize churn across the 6 import sites. A follow-up rename to phase_structural and phase_coupling could be done later if desired, but is not essential.
Destination: framework/treesitter/phases.py -- new file in the existing treesitter/ subpackage.
Reasoning: This file creates DetectorPhase objects that wrap tree-sitter detectors living in framework/treesitter/. It already imports from framework/treesitter/_smells, framework/treesitter/_cohesion, framework/treesitter/_unused_imports, and framework/treesitter/_specs. Moving it into framework/treesitter/ eliminates the cross-package reach and groups phase factories with the detectors they wrap. The treesitter/__init__.py is the natural re-export point.
Destination: framework/base/types.py or framework/policy.py.
Actually, looking more carefully: this is a 20-line file with a single list constant. The best home is framework/policy.py, which already houses REQUIRED_FILES, REQUIRED_DIRS, and ALLOWED_SCAN_PROFILES. It is specifically for policy/configuration constants. Adding HOLISTIC_REVIEW_DIMENSIONS (a default list for review config) fits perfectly.
Destination: framework/commands_base.py (append to existing file).
Reasoning: commands_base.py already contains "shared command factories for detect subcommands" -- factory functions that generate command handlers for language plugins. scaffold_defaults.py contains default implementations for scaffolded language plugins' move/review/verify commands. Both are "shared defaults for plugin commands." The commands_base.py file is 270 lines; adding 42 lines keeps it manageable.
Destination: framework/commands_base.py (append to existing file).
Reasoning: This contains make_cmd_deps, make_cmd_cycles, make_cmd_orphaned, make_cmd_dupes -- detect command factories that are structurally identical to what commands_base.py already provides (make_cmd_large, make_cmd_complexity, make_cmd_naming, make_cmd_single_use). Both files are detect-command factories differing only in which detector they wrap. Merging them into one file gives a single location for all detect command factories. commands_base.py is ~270 lines + scaffold_detect_commands.py is ~186 lines = ~456 lines total, still coherent.
review_data/ (dimensions.json + init.py)
Destination: framework/review_data/ -- move the entire directory.
Reasoning: The JSON data file is loaded by intelligence/review/dimensions/data.py via a hardcoded path: _DATA_DIR = _LANG_DIR / "_shared" / _LANG_DATA_SUBDIR. This path needs to change to _LANG_DIR / "framework" / _LANG_DATA_SUBDIR. The review_data/ subdirectory pattern is already used by individual language plugins (python/review_data/, typescript/review_data/, etc.) for overrides, so it is consistent to have the base data in framework/review_data/. The pyproject.toml package-data entry must also change from "desloppify.languages._shared" to "desloppify.languages.framework".
3. Naming Conflict Analysis
Potential conflict
Resolution
_shared/phases_common.py vs framework/base/shared_phases.py
Merge contents into shared_phases.py. No name collision -- run_structural_phase/run_coupling_phase are distinct from existing phase_* functions.
_shared/scaffold_detect_commands.py vs framework/commands_base.py
Merge contents. No name collision -- make_cmd_deps/make_cmd_cycles/make_cmd_orphaned/make_cmd_dupes are distinct from existing make_cmd_large/make_cmd_complexity/etc.
_shared/scaffold_defaults.py appended to commands_base.py
No collision.
_shared/review_dimensions.py into policy.py
No collision -- new constant HOLISTIC_REVIEW_DIMENSIONS joins existing constants.
No actual naming conflicts exist. The separation was organizational, not due to name collisions.
4. Order of Operations
Execute in this order, each step independently committable:
Step 1: Move review_data/ directory
Why first: This is data-only (JSON), has the simplest import surface (one path constant in data.py), and validates the merge approach.
Move _shared/review_data/ to framework/review_data/
Add re-exports to framework/treesitter/__init__.py for discoverability
Delete _shared/phases_treesitter.py
Step 6: Merge phases_common.py into framework/base/shared_phases.py
Why last: Most import sites (6), most code (175 lines).
Move run_structural_phase and run_coupling_phase into framework/base/shared_phases.py
Update the imports needed by these functions (they import from framework.base.structural, framework.runtime, framework.finding_factories -- all of which are already available within framework/)
Delete the _shared/ directory entirely (only __init__.py should remain at this point)
Remove any leftover __pycache__ directories
Update languages/README.md to reflect the new structure (remove all _shared/ references, update the layout diagram)
Run full test suite
5. Risks with desloppify move
The desloppify move command is not suitable for this refactoring. Here is why:
It operates on scanned projects, not on itself. The move command uses lang.build_dep_graph(scan_path) to build a dependency graph of the scanned codebase, then rewrites imports in those files. But the files being moved here are part of desloppify itself, not a project being scanned.
It requires a language plugin. The move command resolves a language plugin by file extension and uses language-specific move modules (find_replacements, find_self_replacements). For Python files, this would work in theory, but only if desloppify is scanning itself.
It would not update non-import references. The pyproject.toml package-data entry, the _DATA_DIR path constant in data.py, the README.md references -- these are not import statements and would not be caught.
The merge operations are not simple file moves. Steps 2-4 and 6 are content merges (appending code to existing files), not file relocations. The move command handles file-to-file renames, not content consolidation.
Recommendation: Do this manually with editor operations. Use grep -r or the project's own scan to verify completeness after each step. Each step should be its own commit for easy bisection if something breaks.
6. The framework vs _framework Question
The discovery code at line 51-57 of discovery.py:
python
for d in sorted(lang_dir.iterdir()):
if (
d.is_dir()
and (d / "__init__.py").exists()
and not d.name.startswith("_")
and d.name != "framework"
):
There are two exclusion mechanisms: startswith("_") (convention-based) and d.name != "framework" (hardcoded string). The question is whether to rename framework/ to _framework/ for consistency.
Recommendation: Rename to _framework. Here is the reasoning:
Convention alignment. Python's underscore prefix convention means "internal/private." The framework directory is internal infrastructure, not a language plugin. Using _framework makes this self-documenting -- any reader of ls languages/ immediately understands which directories are plugins and which are infrastructure.
Eliminates the hardcoded exception. The d.name != "framework" check is a code smell -- it requires the discovery code to have specific knowledge of the infrastructure directory name. With _framework, the existing startswith("_") check handles it automatically. The hardcoded check can be deleted.
Consistency with former _shared. After the merge, _framework would be the only underscore-prefixed directory. This communicates clearly: "one infrastructure package, N language plugins."
No functional risk. The rename only affects import paths. With ~133 import sites from framework, this is a larger find-and-replace, but it is purely mechanical. A sed pass or editor global replace handles it.
However, if the 133-import rename feels too risky to combine with the merge, a pragmatic approach is:
Complete the _shared merge first (Steps 1-7 above)
Then do the framework -> _framework rename as a separate operation
This separates the structural consolidation from the naming normalization.
Counter-argument for keeping framework: The underscore prefix in Python conventionally means "don't import this from outside." But frameworkis imported by language plugins -- that's its entire purpose. The underscore could be misleading. A reasonable alternative is to keep framework without underscore and accept the single hardcoded exclusion as the cost of clarity.
My recommendation is: keep framework as-is for now. The hardcoded exclusion is one line of obvious code. Renaming 133 import sites for a cosmetic improvement that is arguably semantically wrong (underscore = don't-import-this, but plugins must import it) is not worth the risk and churn. Delete the _shared directory and you already achieve the goal: exactly one infrastructure directory alongside ~31 language plugin directories.
Summary: Final Framework Structure
code
languages/
framework/
__init__.py # Re-exports LangConfig, DetectorPhase, etc.
base/
__init__.py
types.py # LangConfig, DetectorPhase, FixerConfig, etc.
shared_phases.py # ALL shared phase runners (+ merged run_structural/coupling)
phase_builders.py # DetectorPhase factory helpers
structural.py # Structural signal helpers
treesitter/
__init__.py # is_available, TreeSitterLangSpec, cache control
phases.py # NEW: merged from _shared/phases_treesitter.py
_cache.py, _cohesion.py, _complexity.py, _extractors.py,
_imports.py, _normalize.py, _smells.py, _specs.py, _unused_imports.py
review_data/
__init__.py
dimensions.json # MOVED from _shared/review_data/
commands_base.py # ALL detect command factories (+ merged scaffold commands/defaults)
discovery.py
resolution.py
runtime.py
finding_factories.py
facade_common.py
contract_validation.py
structure_validation.py
policy.py # + HOLISTIC_REVIEW_DIMENSIONS
registry_state.py
generic.py
python/
typescript/
csharp/
dart/
gdscript/
bash/
... (26 more language dirs)
Critical Files for Implementation
/Users/user_c042661f/Documents/desloppify/desloppify/languages/framework/base/shared_phases.py - Merge target for phases_common.py (run_structural_phase, run_coupling_phase)
/Users/user_c042661f/Documents/desloppify/desloppify/languages/framework/commands_base.py - Merge target for scaffold_defaults.py and scaffold_detect_commands.py
/Users/user_c042661f/Documents/desloppify/desloppify/intelligence/review/dimensions/data.py - Contains hardcoded _DATA_DIR path to _shared/review_data/ that must change
/Users/user_c042661f/Documents/desloppify/desloppify/languages/framework/discovery.py - Plugin discovery with d.name != "framework" exclusion to potentially update
/Users/user_c042661f/Documents/desloppify/desloppify/languages/framework/generic.py - Has 3 lazy imports from _shared that must be rewired