/garden-extract

Infrastructure L2+ Production low usage

/garden-extract

Overview

/garden-extract is a production command in the Infrastructure category of the Prismatic Platform that extracts reusable patterns, components, and knowledge from GARDEN (Growing Archive of Reusable Development and Engineering Nuggets) repositories and integrates them into the active platform codebase. While /garden-explore discovers what exists in the GARDEN ecosystem, /garden-extract performs the actual knowledge transfer -- transforming historical implementations into production-ready components that conform to current platform standards.

The command operates under the L2+ authority level and is executed by the garden-cultivator agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The garden-cultivator agent manages the complex process of adapting code from diverse technology stacks and coding conventions into the platform's standardized Elixir/OTP architecture, ensuring that extracted components meet all quality gates and doctrine requirements.

The GARDEN ecosystem contains 116 repositories with over 3,050 files spanning 20+ years of engineering practice. Much of this knowledge exists in older technology stacks (Python, JavaScript, Ruby) or in Elixir code that predates the platform's current quality standards. The /garden-extract command handles the translation layer, converting patterns into idiomatic Elixir that passes compilation with zero warnings, Credo strict mode, Dialyzer analysis, and the full battery of quality gates.

Extraction is not mere copying. The command performs pattern analysis to identify the essential algorithm or architectural concept, strips away implementation-specific details tied to the source technology, and generates a new implementation that leverages Elixir/OTP idioms such as GenServer state management, supervision trees, and the {:ok, result} | {:error, reason} return pattern. This ensures that extracted knowledge genuinely improves the platform rather than introducing technical debt from legacy codebases.

Architecture

The extraction pipeline operates as a multi-stage transformation process.

Source Repo --> Pattern Analyzer --> Transformer --> Generator --> Quality Gate --> Integration
     |               |                   |              |              |              |
  Raw Code      Essential         Technology       Elixir/OTP    Compilation     Target App
  (any lang)    Pattern ID        Translation      Code Gen      + Credo + Tests  Placement

Pipeline Stages

StageComponentResponsibility
AnalysisGarden.PatternAnalyzerIdentifies the essential pattern, separating algorithm from implementation details
TranslationGarden.TransformerConverts technology-specific constructs to Elixir/OTP equivalents
GenerationGarden.CodeGeneratorProduces idiomatic Elixir modules with typespecs, docs, and tests
ValidationGarden.QualityValidatorRuns quality gates on generated code before integration
IntegrationGarden.IntegratorPlaces generated code in the target application with proper module naming

Supported Source Technologies

TechnologyPattern TypesTranslation Complexity
ElixirDirect port, GenServer patterns, Phoenix patternsLow (same ecosystem)
PythonData pipelines, ML patterns, OSINT providersMedium (paradigm shift)
JavaScriptAsync patterns, API clients, event handlersMedium (async model differs)
RustPerformance patterns, systems patternsHigh (ownership model)
GoConcurrency patterns, service patternsMedium (goroutines to processes)
RubyOOP patterns, DSL patterns, Rails patternsMedium (OOP to FP)

Usage

Basic Usage

# Extract a specific pattern from a repository
/garden-extract sig --pattern osint-provider

# Extract and place in a specific target application
/garden-extract sig --pattern osint-provider --target apps/prismatic_agents/

# Extract all patterns from a repository
/garden-extract kuzu-ex --all

# Dry-run extraction to preview what would be generated
/garden-extract prismatic-legacy --pattern blackboard --dry-run

Selective Extraction

# Extract only the core algorithm, skip tests and docs
/garden-extract sig --pattern provider-registry --components core

# Extract with full test suite generation
/garden-extract sig --pattern provider-registry --components core,tests,docs

# Extract and adapt to a specific module namespace
/garden-extract crisstal --pattern event-pipeline --namespace PrismaticAgents.Events

Cross-Language Extraction

# Extract a Python OSINT provider and convert to Elixir
/garden-extract sig --pattern shodan-provider --source-lang python --target apps/prismatic_agents/

# Extract a Go service pattern and convert to GenServer
/garden-extract comtesse --pattern worker-pool --source-lang rust --target apps/prismatic/

Options & Parameters

OptionTypeDefaultDescription
REPOstringrequiredSource GARDEN repository name
--patternstringnoneSpecific pattern name to extract
--allbooleanfalseExtract all patterns from the repository
--targetstringautoTarget application directory for placement
--namespacestringautoElixir module namespace for generated code
--componentsstringallComponents to extract: core, tests, docs, config
--source-langstringautoSource language hint for cross-language extraction
--dry-runbooleanfalsePreview extraction without writing files
--forcebooleanfalseOverwrite existing files at the target location
--formatstringelixirOutput format: elixir, markdown (for documentation extraction)
--quality-levelstringstrictQuality gate level: strict, standard, relaxed
--verbosebooleanfalseShow detailed extraction steps and transformations

Execution Flow

  1. Source Resolution: Locate the source repository in the GARDEN submodule directory (garden/REPO_NAME/). Verify the submodule is initialized and contains the expected files.

  2. Pattern Identification: If --pattern is specified, locate the pattern definition in the repository's pattern index. If --all is specified, enumerate all extractable patterns.

  3. Source Analysis: The PatternAnalyzer examines the source code to identify the essential pattern -- the core algorithm, data structures, and architectural decisions that constitute reusable knowledge. Implementation-specific details (database drivers, HTTP clients, framework bindings) are separated from the essential pattern.

  4. Translation Planning: Based on the source language and target Elixir environment, the Transformer creates a translation plan that maps source constructs to Elixir/OTP equivalents. For example, Python classes become Elixir modules, async/await becomes Task/GenServer, and mutable state becomes GenServer state.

  5. Code Generation: The CodeGenerator produces Elixir modules following platform conventions: proper module documentation with @moduledoc, function documentation with @doc, type specifications with @spec, and the {:ok, result} | {:error, reason} return pattern.

  6. Test Generation: Companion test modules are generated with property-based tests (using StreamData) and example-based tests that verify the extracted pattern behaves correctly.

  7. Quality Validation: Generated code is validated against the platform's quality gates: zero compilation warnings, Credo strict compliance, Dialyzer success, and typespec coverage.

  8. Integration: Validated code is placed in the target application directory with proper file naming and module structure. Existing files are never overwritten unless --force is specified.

Integration Points

ComponentIntegration TypeDescription
Prismatic AgentsExecutionInvoked by garden-cultivator agent
GARDEN EcosystemSourceReads from 116 GARDEN repositories
/garden-exploreWorkflowExploration typically precedes extraction
/garden-searchDiscoverySearch results identify extraction targets
/garden-syncPrerequisiteSync ensures source repositories are current
Quality GatesValidationExtracted code must pass all quality gates
CredoStatic AnalysisGenerated code checked for Credo compliance
TelemetryMetricsExtraction events and success rates tracked

Best Practices

Always explore before extracting. Use /garden-explore to understand what a pattern contains and which repositories implement it before running extraction. Blind extraction may pull in inappropriate patterns or miss better alternatives.

Use dry-run for complex extractions. Cross-language extractions and large pattern sets benefit from --dry-run to preview the generated code before it is written to disk. This prevents quality issues from reaching the codebase.

Specify a target namespace. The auto-generated namespace may not match the platform's module organization conventions. Use --namespace to place extracted code in the correct module hierarchy.

Extract incrementally. For repositories with many patterns, extract one pattern at a time and verify its integration before proceeding to the next. This makes it easier to identify and resolve integration issues.

Review generated tests carefully. While the CodeGenerator produces functional tests, the generated tests may not cover all edge cases specific to the platform's usage context. Supplement generated tests with domain-specific assertions.

Error Handling

ErrorCauseResolution
{:error, :repo_not_found}Source repository does not exist in GARDENVerify repository name; run /garden-explore to list available repos
{:error, :pattern_not_found}Specified pattern does not exist in the repositoryCheck pattern name; use --verbose to see available patterns
{:error, :translation_failed}Cross-language translation encountered unsupported constructsUse --source-lang to hint the correct language; some patterns require manual adaptation
{:error, :quality_gate_failed}Generated code did not pass quality validationUse --quality-level relaxed for initial extraction, then fix violations manually
{:error, :target_exists}Target file already exists and --force is not specifiedUse --force to overwrite or specify a different --namespace
{:error, :submodule_missing}GARDEN submodule is not initializedRun git submodule update --init garden/REPO_NAME

Advanced Usage

Batch Extraction with Quality Pipeline

# Extract all OSINT providers from sig repository
/garden-extract sig --pattern "osint-*" --target apps/prismatic_agents/lib/providers/

# Extract and immediately verify integration
/garden-extract sig --pattern shodan-provider --target apps/prismatic_agents/ && \
  mix compile --warnings-as-errors && \
  mix credo --strict && \
  mix test apps/prismatic_agents/test/

Pattern Composition

Combine multiple extracted patterns to build higher-level components:

# Extract the base provider pattern
/garden-extract sig --pattern base-provider --namespace PrismaticAgents.Providers.Base

# Extract specific provider implementations
/garden-extract sig --pattern shodan-provider --namespace PrismaticAgents.Providers.Shodan
/garden-extract sig --pattern censys-provider --namespace PrismaticAgents.Providers.Censys

# Extract the registry pattern that ties them together
/garden-extract sig --pattern provider-registry --namespace PrismaticAgents.Providers.Registry

Documentation Extraction

Extract documentation and knowledge without code:

# Extract architectural documentation from a repository
/garden-extract prismatic-legacy --pattern blackboard --format markdown --target docs/architecture/

# Extract pattern descriptions for the promo site
/garden-extract sig --all --format markdown --components docs --target sites/promo/content/

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for incomplete execution or quality violations. Extracted code must pass all quality gates before integration. No stubs, no TODOs, no incomplete implementations.
  • NO DOUBTS: Full investigation before action, evidence-based results. The analysis phase ensures that the essential pattern is fully understood before translation begins. Extraction never proceeds on partial understanding.

The command enforces the platform's meta-rule: if the extracted code could be written identically in Node.js, the extraction has failed. All extracted patterns must leverage Elixir/OTP idioms -- processes, supervision, pattern matching, and functional composition.

  • /gardener - GARDEN legacy knowledge repository management across 116 repos
  • /garden-explore - Explore GARDEN repositories for patterns and knowledge
  • /garden-search - Fast pattern search across all GARDEN reference repositories
  • /garden-sync - Synchronize GARDEN submodules to latest remote commits
  • /propagate-pattern - Propagate successful patterns across the ecosystem
  • /quality-gates - Enforce quality gate checkpoints with zero-warning compilation validation

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL