Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
aba1288
Validate multi-language Lineage support
cuzzo Jun 16, 2026
791119a
Validate language support quality
cuzzo Jun 16, 2026
27afcdd
Improve multi-language architecture signals
cuzzo Jun 16, 2026
f592ae3
Add Tree-sitter extraction and systems hazards
cuzzo Jun 16, 2026
f4ef9db
Move Lineage UI shell into templates
cuzzo Jun 16, 2026
71f1373
Add native Decomplex co-update detector runner
cuzzo Jun 16, 2026
adf782b
Refine Lineage source review UI
cuzzo Jun 16, 2026
8ec541d
Port decomplex detectors to mirrored Rust architecture
cuzzo Jun 16, 2026
f4f1f99
Add ordered parallel parsing for decomplex rust
cuzzo Jun 16, 2026
a4a265f
WIP: Decomplex: Migrate decision pressure to Rust
cuzzo Jun 16, 2026
b9739e2
Decomplex: Finish Tier 1 metric migration to Rust
cuzzo Jun 16, 2026
5665755
Decomplex: Finish Tier 2 metric migration to Rust
cuzzo Jun 17, 2026
9924915
Decomplex: Finish Tier 3 metric migration to Rust
cuzzo Jun 17, 2026
8f107a1
Decomplex: Fix O(N^2) performance and recursion limits in Rust detectors
cuzzo Jun 17, 2026
9aa7f71
WIP decomplex rust migration
cuzzo Jun 18, 2026
281f1d4
Add Java Kotlin Swift native support
cuzzo Jun 18, 2026
062ee4a
WIP improve decomplex native parity
cuzzo Jun 18, 2026
01927f1
WIP: add tree-sitter normalization adapters
cuzzo Jun 18, 2026
19687ed
Improve tree-sitter facade lookup performance
cuzzo Jun 18, 2026
0603acd
Fix cross-language tree normalizer parity
cuzzo Jun 19, 2026
fde8f51
Refactor syntax fact extraction profiles
cuzzo Jun 19, 2026
606fd0d
Seed syntax walks with language context
cuzzo Jun 19, 2026
b32e7fa
Remove generic syntax profile fallback
cuzzo Jun 19, 2026
a408e47
Move Tree-sitter quirks into language profiles
cuzzo Jun 19, 2026
cda67cd
Add cross-language decomplex oracle fixtures
cuzzo Jun 19, 2026
c5153a7
Add parallel decomplex test runner audit
cuzzo Jun 19, 2026
2e6ce58
Fix Decomplex cross-language syntax boundaries
cuzzo Jun 19, 2026
35d7da4
Refactor decomplex syntax adapters
cuzzo Jun 19, 2026
a19082b
Refactor decomplex Rust adapters
cuzzo Jun 19, 2026
33eb75e
Add Rust PHP support for Decomplex
cuzzo Jun 19, 2026
15140bb
Fix decomplex Rust facts indexing architecture
cuzzo Jun 19, 2026
e9eb509
Advance Rust decomplex parity and oracle coverage
cuzzo Jun 20, 2026
52a643c
Fix Rust decomplex detector parity
cuzzo Jun 20, 2026
a3462a5
Fix Rust local flow parity
cuzzo Jun 20, 2026
59c595b
Improve Python and Rust detector parity
cuzzo Jun 20, 2026
f9007f7
Fix Python local flow parity
cuzzo Jun 20, 2026
40a8d23
Align decomplex Rust adapter parity
cuzzo Jun 20, 2026
336b682
Align decomplex Rust detector parity
cuzzo Jun 20, 2026
3c4a1bf
Fix decomplex Python parity regressions
cuzzo Jun 20, 2026
6b365d0
Improve decomplex Go local-flow parity
cuzzo Jun 20, 2026
b7569ac
Improve decomplex Rust detector fact architecture
cuzzo Jun 20, 2026
7766983
Add shared Decomplex fact oracles
cuzzo Jun 20, 2026
360fe24
Add shared markdown report oracle
cuzzo Jun 20, 2026
7797384
Add CLEAR launch planning docs
cuzzo Jun 20, 2026
4dccb18
Add Ruby syntax facts oracle
cuzzo Jun 20, 2026
9ee6fed
Expand syntax facts oracle with clone candidates
cuzzo Jun 20, 2026
3d7209f
Add Rust Zig and Go syntax facts oracles
cuzzo Jun 20, 2026
23baef8
Enforce shared syntax oracle across Ruby and Rust
cuzzo Jun 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
!/.devcontainer/
!/.github/
!/.gitignore
!/.npmrc
!/.rspec
!/.vscode/
!/CLAUDE.md
Expand All @@ -17,6 +18,8 @@
!/gems/**
!/LICENSE
!/ONE-PAGER.md
!/package-lock.json
!/package.json
!/README.md
!/TODO.md
!/clear
Expand Down Expand Up @@ -159,3 +162,6 @@ transpile-tests/fuzz/*.cht

# Generated architecture reports
gems/espalier/architecture.yml

# Decomplex native Rust build artifacts
gems/decomplex/rust/target/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ group :development do
gem 'minitest', '~> 5.25'
gem 'rspec'
gem 'parallel_rspec'
gem "parallel_tests", "~> 5.7", require: false
gem 'tty-cursor', require: false
gem 'tty-reader', require: false
gem 'tty-screen', require: false
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ GEM
parallel_rspec (3.0.0)
rake (> 10.0)
rspec
parallel_tests (5.7.0)
parallel
parlour (9.1.2)
commander (~> 5.0)
parser
Expand Down Expand Up @@ -298,6 +300,7 @@ DEPENDENCIES
mutant-rspec
nil-kill!
parallel_rspec
parallel_tests (~> 5.7)
reek
rspec
rubocop
Expand Down
46 changes: 46 additions & 0 deletions docs/agents/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Launch Checklist: CLEAR v0.1 & Generalized Gems

## Phase 1: The "Secret Sauce" Launch (Weeks 1-6)

### 1. Lineage (The Backbone)
- [ ] Finalize Rust `lineage` crate with VCS Trait support (Git/JJ/Hg).
- [ ] Implement Sentry/Stack-trace ingestion with verification anchors.
- [ ] Implement Coverage-Delta ingestion (Aggregates only).
- [ ] Build the Local UI Server (Rust/Axum + React/Monaco) with gutters.

### 2. Boobytrap & SlopCop (The Integrity Wall)
- [ ] Generalize SlopCop regexes into language-neutral providers.
- [ ] Implement Systems-Test Coverage detection (Atomics -> Loom, etc.) for Zig.
- [ ] Add `--format sarif` output for native GitHub Check Annotations.
- [ ] Update Boobytrap to use Lineage SQLite DB for function-level history.

### 3. Nil-Kill & Auto-Type (The Repair Engine)
- [ ] Complete the extraction of `auto-type` from `nil-kill`.
- [ ] Implement the `auto-type` Provider Registry (Template/LLM/AST tiers).
- [ ] Abstract Nil-Kill Z3 evidence extraction into language providers.
- [ ] Launch "Hidden Enum Discovery" as a flagship AI-refactoring feature.

## Phase 2: CLEAR v0.1 Architectural Preview (Weeks 7-8)

### 4. Compiler Hardening
- [ ] **Must Build:** Promote the "Memory Brains" (`Type`, `CleanupClassifier`, `EscapeAnalysis`) to Hard-Gated mutation status.
- [ ] Ensure 100% of safety invariants in `CLAUDE.md` are killed by transpile-mutants.
- [ ] Conduct a final parity run: Tree-sitter-Ruby vs. Prism-Ruby facts.

### 5. Launch Artifacts
- [ ] Finalize the "Language Tour" featuring the MiniVM (`_bc_runner.cht`) as proof of logic.
- [ ] Release the 3-week "Decomplex Expansion" narrative (Ruby -> Python -> Universal).

## Phase 3: CLEAR v0.2 Self-Hosted Release (Weeks 9-10+)

### 6. The Great Migration
- [ ] Execute the "Narrowing the Funnel" refactor: move Ruby source to "Spiritual CLEAR".
- [ ] Run the S2S Script (Ruby-to-CLEAR) on the Kernel (AST/Type/Annotator).
- [ ] Achieve first successful self-compiled "Hello World".
- [ ] Achieve full self-hosting of the MIR Lowering and Checker passes.

## Phase 4: Enterprise & Scalability

- [ ] Port the Lineage UI to a standalone **Tauri** Desktop Application.
- [ ] Design the "Cloud Fact-Store" for aggregate team risk (hosting-safe).
- [ ] Finalize per-seat license model for the "Systems Integrity Platform".
67 changes: 67 additions & 0 deletions docs/agents/self-host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Self-Hosting Plan: The "Boiling Frog" Transpilation

This document outlines a phased bootstrapping approach to self-hosting the CLEAR compiler. Rather than a single "big bang" transpilation, we build the transpiler incrementally to handle the specific Ruby features used in each compiler pass.

## Core Strategy

1. **Surgical Ruby Refactoring (Phase 0)**: Eliminate dynamic hazards (e.g., `send`, `instance_variable_get`) in the Ruby source to simplify the transpiler and ensure idiomatic CLEAR output.
2. **Phase-Locked Development**: Build the transpiler logic required for Pass N, then transpile Pass N.
3. **Surgical Manual Intervention**: Complex Ruby idioms (e.g., dynamic regex generation in the Lexer, or complex metaprogramming in the Annotator) are manually converted during each pass.
4. **Fact-Driven Memory Safety**: Use `decomplex` to detect aliasing and ownership facts in the Ruby source to drive correct CLEAR capability selection (GIVE vs. Borrow vs. Shared).

## Phase Estimates

| Phase | Component | Ruby LOC | Transpiler LOC (Cumulative) | Manual Work |
| :--- | :--- | :---: | :---: | :---: |
| **P0** | **Source Refactor** | N/A | 0 | 0% |
| **P1** | **Lexer** | 360 | 1,000 | 0% |
| **P2** | **Parser & AST** | 18,500 | 3,000 | 5% |
| **P3** | **Type Inference (Annotator)** | 11,000 | 5,000 | 10% |
| **P4** | **Cap & Effect Tracking** | 11,200 | 6,500 | 15% |
| **P5** | **Escape Analysis** | 4,100 | 7,500 | 15% |
| **P6** | **AST/MIR Re-writing** | 1,500 | 8,500 | 10% |
| **P7** | **Thunk Conversion** | 3,300 | 9,500 | 20% |
| **P8** | **FSM Conversion** | 7,500 | 10,500 | 25% |
| **P9** | **MIR Lowering** | 22,000 | 11,500 | 15% |
| **P10** | **MIR Safety Verification** | 3,000 | 12,000 | 5% |
| **P11** | **Zig Emission** | 4,200 | 12,500 | 5% |
| **P12** | **Test Suite (spec/)** | 100,000+ | 16,000 | 15% |

### Phase Details

#### P0: Surgical Refactor
- **Goal**: Remove dynamic Ruby features that are difficult to transpile.
- **Actions**: Replace `send` with explicit interfaces; replace `instance_variable_get` with getters; simplify RSpec mocks to use structural doubles.
- **Benefit**: Reduces transpiler complexity by ~2,000 LOC and ensures the output follows CLEAR "Fortress Architecture" principles.

#### P1-P2: Frontend (Lexer & Parser)
- **Ruby Surface**: String scanning, recursive descent, large case/match blocks, AST node instantiation.
- **Transpiler Goal**: Map Ruby `StringScanner` to CLEAR `Scanner`, and `case` to CLEAR `MATCH`.
- **Manual Work**: Complex regex-driven tokenization rules that don't map 1:1 to Zig's regex engine.

#### P3-P4: Semantic Analysis (Annotator)
- **Ruby Surface**: Symbol tables, recursive tree walks, Sorbet `sig` blocks, `T::Hash`, `T::Set`.
- **Transpiler Goal**: Robust mapping of Sorbet types to CLEAR types; mapping Ruby `Hash/Set` to CLEAR `@map/@set`.
- **Manual Work**: Deeply nested type-inference edge cases and circular dependency resolution in the declaration index.

#### P5-P8: Middle-End (Semantic & Transforms)
- **Ruby Surface**: Flow-sensitive analysis, graph traversal, tree-to-tree transformations (Rewriters), closure/thunk generation.
- **Transpiler Goal**: Implementing a "Data-Flow Bridge" in `decomplex` to detect aliasing hazards.
- **Manual Work**: FSM conversion logic is the most complex Ruby in the codebase, requiring careful manual verification of the generated state machines.

#### P9-P11: Backend (Lowering & Emission)
- **Ruby Surface**: Explicit memory decision logic, cleanup classification, Zig template strings.
- **Transpiler Goal**: High-fidelity mapping of Ruby logic to CLEAR's ownership markers (`Cleanup`, `MoveMark`).
- **Manual Work**: Very low; these passes are already designed with "CLEAR-like" semantics (mechanical and fact-driven).

#### P12: Test Suite (spec/)
- **Ruby Surface**: RSpec DSL (`expect`, `it`, `describe`), dynamic doubles, `send` for white-box testing.
- **Transpiler Goal**: Map RSpec DSL to CLEAR `TEST` and `ASSERT` blocks.
- **Manual Work**: High (~15%) due to the highly dynamic nature of Ruby test mocking.

## Success Criteria

A phase is considered complete when:
1. The CLEAR-transpiled version of Pass N passes all unit tests when driven by the Ruby versions of Passes 0..(N-1).
2. Decomplex reports 0 "Encapsulation Breaches" in the generated CLEAR code.
3. The binary size and performance of the self-hosted pass are within 20% of the Ruby baseline (targeting 2-5x faster eventually).
14 changes: 14 additions & 0 deletions gems/decomplex/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ Prefer one clear signal over a broad blended score. If a metric is noisy,
mark it tier 3 or make it supporting evidence for convergence/root-cause
clusters.

## Running Tests

Run the Decomplex Minitest suite in parallel with:

```bash
bundle exec parallel_test gems/decomplex/test
```

For a smaller local run while debugging output, cap workers explicitly:

```bash
bundle exec parallel_test gems/decomplex/test -n 4 --serialize-stdout
```

## Language Support

New language work should go through the syntax/profile boundary:
Expand Down
16 changes: 16 additions & 0 deletions gems/decomplex/benchmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require_relative "lib/decomplex"
require "benchmark"

files = ["lib/decomplex/ast.rb"]
detectors = Decomplex::DetectorRunner::DETECTORS.keys

Benchmark.bm(40) do |x|
detectors.each do |det|
x.report("#{det} (ruby)") do
Decomplex::DetectorRunner.run(det, files, engine: "ruby")
end
x.report("#{det} (rust)") do
Decomplex::DetectorRunner.run(det, files, engine: "rust")
end
end
end
18 changes: 18 additions & 0 deletions gems/decomplex/benchmark_dir.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative "lib/decomplex"
require "benchmark"

files = Dir.glob("lib/decomplex/**/*.rb")
detectors = Decomplex::DetectorRunner::DETECTORS.keys

puts "Benchmarking across #{files.size} files in lib/decomplex/"

Benchmark.bm(40) do |x|
detectors.each do |det|
x.report("#{det} (ruby)") do
Decomplex::DetectorRunner.run(det, files, engine: "ruby")
end
x.report("#{det} (rust)") do
Decomplex::DetectorRunner.run(det, files, engine: "rust")
end
end
end
44 changes: 44 additions & 0 deletions gems/decomplex/docs/agents/aliasing-complexity-metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Aliasing and Ownership Complexity Metrics

This document outlines the expansion of Decomplex to include pointer-aliasing and ownership detection. These metrics transform Decomplex from a heuristic structural analyzer into a semantic fact-engine capable of driving high-accuracy transpilation to CLEAR's affine ownership model.

## Metric Tiers

### Tier 1: High Confidence / Structural Hazards
**Metric: Encapsulation Breach**
- **Description**: Detects when a class returns a mutable reference to an internal state field (`@ivar`) without a copy (`.dup` / `.clone`) or conversion.
- **Architectural Risk**: Violates "Fortress Architecture" principles. It allows external callers to bypass class invariants and validation by mutating state "from the outside."
- **CLEAR Impact**: Identifies sites where CLEAR must either enforce a `COPY` or wrap the field in a read-only borrow.

### Tier 2: Design Pressure / Structural Risk
**Metric: Aliasing Tangle (Action-at-a-Distance)**
- **Description**: Identifies single objects that are aliased across three or more disparate modules/subsystems.
- **Architectural Risk**: Creates "tangled webs" where mutation in one module causes unpredictable behavior in another. This is the primary driver of "locality drag"—where a developer must understand 5 files to change 1.
- **CLEAR Impact**: Signals that a resource requires a Group 1 capability (e.g., `@shared:locked` or `@shared:writeLocked`) rather than simple affine move semantics.

### Tier 3: Strategic / Project Context
**Metric: Entanglement Density**
- **Description**: An aggregate heatmap quantifying the ratio of aliased references to total references within a file or directory.
- **Architectural Risk**: High-density files are objectively harder to refactor, test, and reason about. They represent the "dark matter" of the codebase where most regressions occur.
- **CLEAR Impact**: Prioritization metric. Files with low entanglement density are "low-hanging fruit" for 98% automated transpilation. High-density files require manual architectural review before migration.

## Implementation Strategy

The implementation leverages a two-pass semantic analyzer within `gems/decomplex/lib/decomplex/`:

1. **Escape & Reachability Pass**:
- Extends `LocalFlow` to track def-use chains across method boundaries.
- Builds a **Reachability Graph** to determine if an object allocated in Scope A can reach Scope B via return, argument passing, or field assignment.

2. **Ownership Synthesis**:
- Aggregates escape facts to classify bindings as `Unique`, `Borrowed`, or `Shared`.
- Detects "Reification Misses" where a developer intended for an object to be private but allowed it to escape via a getter.

## Transpiler Bridge

When the CLEAR transpiler processes Ruby code, it queries the Decomplex fact-graph:

- **Fact: Unique** -> Transpile to `GIVE` (Move).
- **Fact: Borrowed** -> Transpile to `WITH ... AS alias` (Borrow).
- **Fact: Shared** -> Transpile to `@shared:locked` (Arc/RwLock).
- **Fact: Escaped Field** -> Transpile to `RETURN COPY field` or `@indirect` wrapper.
Loading
Loading