Skip to content

Implement fractal algorithmic spine with deterministic structural validation#23

Merged
tikazyq merged 3 commits intomainfrom
claude/fractal-synodic-algorithms-hK1ce
Mar 18, 2026
Merged

Implement fractal algorithmic spine with deterministic structural validation#23
tikazyq merged 3 commits intomainfrom
claude/fractal-synodic-algorithms-hK1ce

Conversation

@tikazyq
Copy link
Contributor

@tikazyq tikazyq commented Mar 18, 2026

Summary

Replace AI subagent calls with classical algorithms for all structurally-decidable operations in fractal decomposition. This implements the "AI for semantics, algorithms for structure" principle, reducing AI calls by ~40% while improving determinism, reproducibility, and cost.

Key Changes

  • Decompose Gate (cli/src/fractal/decompose.rs):

    • TF-IDF weighted cosine similarity for orthogonality checking (via rust-tfidf crate)
    • Kahn's topological sort for dependency cycle detection
    • Weighted feature scoring for complexity estimation
    • Proportional budget allocation by complexity score
    • Coverage analysis via set difference
  • Solve Scheduler (cli/src/fractal/schedule.rs):

    • DAG-based critical path scheduling using BFS layer decomposition
    • Computes parallel execution waves from dependency graph
    • Longest-path DP for critical path analysis
    • Replaces binary parallel/sequential choice with optimal scheduling
  • Reunify Merge (cli/src/fractal/reunify.rs):

    • 3-way merge via git merge-tree for code reunification
    • Structural conflict detection: boundary violations, redundant files, interface gaps
    • Set intersection analysis for scope violations
    • Auto-resolution of structural conflicts without AI
  • Prune Gate (cli/src/fractal/prune.rs):

    • Greedy set cover approximation for minimal covering set
    • Subset analysis for output containment detection
    • Identity detection for duplicate outputs
    • File coverage mapping
  • CLI Integration (cli/src/cmd/fractal.rs, cli/src/main.rs):

    • New synodic fractal command with subcommands: gate, schedule, reunify, prune, complexity
    • JSON stdin/stdout interface for integration with orchestration layer
    • Standalone complexity scoring pre-filter
  • Documentation (docs/FRACTAL.md, specs/047-fractal-algorithmic-spine/README.md):

    • Comprehensive guide to fractal decomposition with algorithmic spine
    • Detailed algorithm descriptions and classical analogs
    • Orchestration protocol and configuration reference
    • AI vs algorithm split visualization
  • Shared Types (cli/src/fractal/mod.rs):

    • Common data structures for decompose, schedule, reunify, prune gates
    • Term extraction utilities (Jaccard similarity, term set operations)

Implementation Details

  • Term Extraction: Regex-based extraction of 3+ char alphanumeric terms with stop-word filtering
  • TF-IDF: Uses rust-tfidf crate for proper inverse document frequency weighting; discriminative terms get higher weight than ubiquitous ones
  • Cycle Detection: Kahn's algorithm with in-degree tracking; O(V+E) complexity
  • Scheduling: Topological sort into waves; critical path computed via DP on longest dependency chain
  • Set Cover: Greedy approximation with O(ln n) ratio guarantee
  • Thresholds: Jaccard > 30% OR TF-IDF cosine > 30% for orthogonality flags; coverage < 80% for coverage flags

All operations are deterministic and reproducible, with no randomness or external state dependencies.

https://claude.ai/code/session_01Gpuehvo6XBmDyQeCQS142c

claude added 3 commits March 18, 2026 21:56
…gorithms for structure

Replace AI subagent calls with classical algorithms wherever the operation is
structurally decidable. Adds TF-IDF cosine similarity (replaces Jaccard),
Kahn's topological sort (cycle detection + solve scheduling), git merge-tree
reunification, greedy set cover pruning, and complexity scoring. AI is now
reserved for semantic operations only: decompose, solve, conflict resolution.

New scripts:
- solve_scheduler.py: DAG-based critical path scheduling into parallel waves
- reunify_merge.py: git 3-way merge + structural conflict detection
- prune_gate.py: set cover redundancy analysis

Enhanced:
- decompose_gate.py: TF-IDF, cycle detection, complexity scoring, budget allocation
- SKILL.md: algorithmic spine design principle + updated orchestration protocol

Spec: 047-fractal-algorithmic-spine

https://claude.ai/code/session_01Gpuehvo6XBmDyQeCQS142c
Replace Python scripts (.harness/scripts/) with native Rust modules
(cli/src/fractal/) and a new `synodic fractal` CLI subcommand.

Modules:
- fractal/decompose.rs: TF-IDF cosine similarity via rust-tfidf crate,
  combined with Jaccard pre-filter for orthogonality. Kahn's topological
  sort for cycle detection. Weighted feature scoring for complexity.
  Proportional budget allocation.
- fractal/schedule.rs: DAG-based BFS layer decomposition for solve wave
  scheduling. Critical path analysis via longest-path DP.
- fractal/reunify.rs: git merge-tree 3-way merge for code reunification.
  Set intersection for boundary/redundancy/gap detection.
- fractal/prune.rs: Greedy set cover for minimal covering set.
  Subset detection and identical output pairing.

CLI subcommands:
  synodic fractal gate        — decompose validation
  synodic fractal schedule    — solve wave scheduling
  synodic fractal reunify     — code reunification analysis
  synodic fractal prune       — redundancy detection
  synodic fractal complexity  — standalone complexity scoring

60 tests pass (28 new fractal tests + 32 existing).

https://claude.ai/code/session_01Gpuehvo6XBmDyQeCQS142c
Comprehensive docs/FRACTAL.md covering:
- Architecture flowchart (ASCII) showing algorithmic spine vs AI calls
- AI vs algorithm split diagram with call count comparison
- Visual breakdowns for each gate (decompose, solve, reunify, prune)
- Complexity scoring weight visualization
- Wave scheduling example with dependency graph
- Conflict classification table
- Node status lifecycle diagram
- CLI reference with input/output JSON examples
- Algorithm table with complexity classes
- Classical algorithm analog mapping
- Governance integration checkpoint diagram
- Test coverage matrix

https://claude.ai/code/session_01Gpuehvo6XBmDyQeCQS142c
Copilot AI review requested due to automatic review settings March 18, 2026 22:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a deterministic “algorithmic spine” for Fractal decomposition by adding Rust-based structural gates/schedulers/mergers/pruners and updating the Fractal skill/docs to use these CLI subcommands instead of AI subagents for structurally decidable work.

Changes:

  • Added synodic fractal CLI with subcommands for gate/schedule/reunify/prune/complexity, plus shared manifest/types/utilities.
  • Implemented classical algorithms in Rust (TF‑IDF similarity, topo scheduling, merge-tree analysis, greedy set cover) to reduce AI calls and improve reproducibility.
  • Updated Fractal documentation/specs and removed the legacy Python decompose gate script.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
specs/047-fractal-algorithmic-spine/README.md New spec describing the algorithmic spine approach and algorithms used
skills/fractal/SKILL.md Updates orchestration protocol to use synodic fractal algorithmic subcommands
docs/README.md Adds Fractal documentation entry
docs/FRACTAL.md New comprehensive Fractal algorithmic spine documentation
cli/src/main.rs Wires new Fractal top-level CLI command
cli/src/cmd/mod.rs Exposes new cmd::fractal module
cli/src/cmd/fractal.rs Implements synodic fractal {gate,schedule,reunify,prune,complexity} command parsing and I/O
cli/src/fractal/mod.rs Adds shared Fractal types + term extraction/Jaccard utilities
cli/src/fractal/decompose.rs Implements decompose gate (TF‑IDF, coverage, budget, cycles, waves, complexity)
cli/src/fractal/schedule.rs Implements dependency-wave scheduling + critical path computation
cli/src/fractal/reunify.rs Implements structural reunify conflict checks + git merge-tree-based analysis
cli/src/fractal/prune.rs Implements prune gate (subset/identity detection + greedy set cover)
cli/Cargo.toml Adds rust-tfidf dependency
cli/Cargo.lock Locks rust-tfidf dependency
.harness/scripts/decompose_gate.py Removes legacy Python gate script

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +116 to +134
/// Extract lowercase alphanumeric terms (>=3 chars), filtering stop words.
pub fn extract_terms(text: &str) -> HashSet<String> {
let stop: HashSet<&str> = STOP_WORDS.iter().copied().collect();
let re = regex::Regex::new(r"[a-zA-Z][a-zA-Z0-9_-]{2,}").unwrap();
re.find_iter(text)
.map(|m| m.as_str().to_lowercase())
.filter(|w| !stop.contains(w.as_str()))
.collect()
}

/// Extract terms preserving duplicates (for TF calculation).
pub fn extract_term_list(text: &str) -> Vec<String> {
let stop: HashSet<&str> = STOP_WORDS.iter().copied().collect();
let re = regex::Regex::new(r"[a-zA-Z][a-zA-Z0-9_-]{2,}").unwrap();
re.find_iter(text)
.map(|m| m.as_str().to_lowercase())
.filter(|w| !stop.contains(w.as_str()))
.collect()
}
Comment on lines +203 to +224
// Find merge base
let merge_base = Command::new("git")
.args(["merge-base", base_ref, &child.branch])
.output()
.ok()?;

if !merge_base.status.success() {
return None;
}

let base = String::from_utf8_lossy(&merge_base.stdout)
.trim()
.to_string();

// Try merge-tree
let result = Command::new("git")
.args(["merge-tree", "--write-tree", &base, base_ref, &child.branch])
.output()
.ok()?;

if result.status.success() {
return Some(MergeTreeResult {
@@ -0,0 +1,421 @@
---
status: draft
Comment on lines +373 to +375
return children
.iter()
.map(|c| (c.slug.clone(), remaining_budget.min(1) / n.max(1)))
Comment on lines +32 to +35
matches!(
node.status.as_str(),
"leaf" | "forced-leaf" | "pending"
) && node.children.is_empty()
Comment on lines +82 to +113
/// Detect boundary violations: child modified files outside its scope.
fn check_scope_violations(children: &[ReunifyChild]) -> Vec<Conflict> {
let mut conflicts = Vec::new();

for child in children {
let child_files: std::collections::HashSet<&String> = child.files.iter().collect();

for sibling in children {
if sibling.slug == child.slug {
continue;
}
let sibling_files: std::collections::HashSet<&String> =
sibling.files.iter().collect();
let overlap: Vec<String> = child_files
.intersection(&sibling_files)
.map(|f| f.to_string())
.collect();

if !overlap.is_empty() {
// Only flag once per pair (alphabetical order)
if child.slug < sibling.slug {
conflicts.push(Conflict {
category: "boundary".to_string(),
children: vec![child.slug.clone(), sibling.slug.clone()],
description: format!(
"Children '{}' and '{}' both modified: {}",
child.slug,
sibling.slug,
overlap.join(", "),
),
files: overlap,
});
> ## Reunification strategy: {reunification}
>
> ## Structural analysis (from algorithmic pre-check)
> {conflicts detected by reunify_merge.py, if any}

let mut prunable: Vec<String> = reasons.keys().cloned().collect();
prunable.sort();
let mut kept: Vec<String> = all_slugs.difference(&prunable.iter().cloned().collect()).cloned().collect();
Comment on lines +338 to +347
let enumeration_count = lines
.iter()
.filter(|l| {
let trimmed = l.trim();
trimmed.starts_with("- ")
|| trimmed.starts_with("* ")
|| regex::Regex::new(r"^\d+\.")
.unwrap()
.is_match(trimmed)
})
@tikazyq tikazyq merged commit 9f4f567 into main Mar 18, 2026
6 checks passed
@tikazyq tikazyq deleted the claude/fractal-synodic-algorithms-hK1ce branch March 18, 2026 22:29
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.

3 participants