Orchestrata Ultimate / Specs / 112-scripts-to-modules

112-scripts-to-modules: scripts/ → Modules Consolidation

Consolidate the scripts/ folder so that scripts hold no business logic — every script becomes a thin CLI shim (arg-parse + one call) delegating to a package module under src/orchestrata_ultimate/. Logic that today lives in a script moves into the package where it belongs, with @traces, tests, and the same public behavior.

At a glance

Item Value
Spec directory specs/112-scripts-to-modules/
Status line in the spec Draft
Requirement IDs defined 12
With a @traces citation in src/ 0 (0.0%)
With a @traces citation in tests/ 0 (0.0%)
Tracked files 2
RTM page 112-scripts-to-modules

Reading this spec

This spec consolidates the scripts/ folder so that scripts hold no business logic. Every script becomes a thin command-line shim (argument parsing plus one call) that delegates to a module in the src/orchestrata_ultimate/ package, and the logic moves into the package with @traces, tests and the same public behaviour. The reason given is that scripts/ has grown to 137 files, about 96 of which carry real logic. Logic there cannot be imported as a library, escapes the package's structural gates (architecture, imports, standards), is harder to test in isolation and is invisible to the code-intelligence graph. The largest case is the 12,253-line AST toolkit script.

An analysis pass already classified the 137 scripts into three categories. Category A (6 scripts) is the codemod and refactor extraction, done first because it aligns with specs 110 and 111. Category B (52 scripts) holds extraction targets, organized by destination package. Category C (79 scripts) stays in place but is audited for thinness. Extraction proceeds category by category and preserves CLI behaviour exactly, so a shim's help text and outputs stay byte-compatible; a structural gate then keeps scripts/ thin.

The twelve requirement IDs follow the seven functional requirements. REQ-112-FR1 is the thin-shim invariant: scripts contain only CLI wiring, and each extraction leaves a backward-compatible shim at the original path. FR2 is behaviour preservation: the CLI surface and exit codes are byte-compatible, and each script's existing test passes unchanged or only with an updated import path. FR3 requires extracted code to carry @traces and satisfy the structural gates scripts were exempt from. FR4 extracts the six category-A scripts and decomposes the AST toolkit into cohesive modules. FR5 extracts the 52 category-B scripts one package at a time with tests green after each step, creating missing target packages first. FR6 audits the 79 category-C scripts and reclassifies any that hold extractable logic. FR7 adds a gate that fails CI when a script defines domain classes or algorithms beyond a shim threshold.

The spec's status line reads Draft, and no code module cites it yet. The requirements traceability matrix lists every ID. It tracks 2 files. No src/ symbol cites any of the 12 requirements, so measured trace coverage is 0.0%, and in tests/, 0 requirements are cited by a test-side @traces. All 12 requirements have no citing symbol, spread over the groups REQ-112-FR1 (2), REQ-112-FR2 (2) and REQ-112-FR3 (2) among others; the behaviour may still exist in code that was never annotated.

Requirements

Checkbox is the state recorded in the requirements checklist; Traced by is the count of src/ symbols whose @traces names the ID.

ID Done Requirement Traced by
REQ-112-FR1-001 no Scripts under scripts/ contain only CLI wiring (arg parse + I/O + delegation); no domain classes/algorithms (RUL-scripts-thin, gated by FR-007) none
REQ-112-FR1-002 no Every extraction leaves a backward-compatible thin shim at the original scripts/<name>.py path that imports and calls the extracted module none
REQ-112-FR2-001 no Post-extraction CLI surface (--help, subcommands, flags, exit codes, stdout/stderr) is byte-compatible with pre-extraction behavior none
REQ-112-FR2-002 no Each script's existing tests/scripts/test_<name>.py passes unchanged, or is updated only to the new import path while asserting identical behavior none
REQ-112-FR3-001 no Extracted module code carries @traces to its origin spec/requirement none
REQ-112-FR3-002 no Extracted modules satisfy the structural gates scripts were exempt from (absolute imports, check-deps, architecture boundaries, standards) none
REQ-112-FR4-001 no The 6 category-A scripts are extracted into refactor.codemod/refactor; serialize_codebase_ast.py (12,253 L AST toolkit) is decomposed into cohesive modules as it moves none
REQ-112-FR4-002 no Category-A extraction is sequenced first (the AST toolkit + codemod are the substrate SPEC-110/111 depend on) none
REQ-112-FR5-001 no The 52 category-B scripts are extracted into their target packages per the mapping, one package at a time, tests green after each none
REQ-112-FR5-002 no Missing target packages (e.g. standards for the 5 static-analysis gates) are created with docstring + __init__ before extraction none
REQ-112-FR6-001 no The 79 category-C scripts are audited to confirm genuine thinness; any holding extractable logic are reclassified to A/B none
REQ-112-FR7-001 no A structural gate (architecture_checker extension or new scripts_are_thin gate) fails CI when a scripts/ file defines domain classes/algorithms beyond a shim threshold none

Code that traces this spec

No src/ symbol cites a requirement of this spec.

Checklists

checklists/requirements.md

The requirement list above comes from this file; 0 of 12 checkbox items are ticked.

Full spec text

Verbatim from specs/112-scripts-to-modules/spec.md; headings are pushed down two levels.

SPEC-112: scripts/ → Modules Consolidation

Metadata

1. Overview

What

Consolidate the scripts/ folder so that scripts hold no business logic — every script becomes a thin CLI shim (arg-parse + one call) delegating to a package module under src/orchestrata_ultimate/. Logic that today lives in a script moves into the package where it belongs, with @traces, tests, and the same public behavior.

Why

scripts/ has grown to 137 files, ~96 of which carry real logic. Logic in scripts/ is: not importable as a library (only runnable), not covered by the package's structural gates (architecture, imports, standards), harder to test in isolation, and invisible to the code-intelligence graph as first-class package API. The single largest offender — serialize_codebase_ast.py (12,253 lines) — is the AST toolkit itself, the very substrate SPEC-110/111 build on, yet it lives as a script. Pulling logic into modules makes it importable, gated, traced, and graph-visible.

How

An analysis pass (already run) classified all 137 scripts into three buckets. Extraction proceeds bucket by bucket, each extraction preserving CLI behavior exactly (the shim's --help and outputs are byte-compatible), with the moved logic tested and traced. A structural gate then keeps scripts/ thin going forward.

2. Categorization (authoritative counts)

Bucket Count Meaning
A — extract → codemod/refactor 6 AST-transform / trace-application logic → refactor.codemod (SPEC-110) / refactor
B — extract → named module 52 real logic belongs in a specific package; script becomes a shim
C — thin / stays 79 already thin, or a genuine dev/CI/build/ops/one-shot runner whose home IS scripts/

has_logic=true for 96/137; many category-C runners carry logic but legitimately belong in scripts/ (test runners, wheel builds, one-shot KG migrations, infra/ops).

Category A (6) — the codemod/refactor extraction (do first; aligns with SPEC-110/111)
Category B (52) — extraction targets by package
Target package Count
verification (+ .review, .autofix) 11
tools 10
knowledge_graph 8
factory (the non-delegating SPEC-033 factory_*) 6
standards (new package for the static-analysis gates) 5
orchestrator 3
prolog, governance, integrations 2 each
llm, memory, openspec 1 each
Category C (79) — stays, but audited for thinness

Genuine runners/ops: test runners (run_tests*), wheel builds (build_ft_*), benchmarks, one-shot KG migrations/repairs, infra readiness (start_test_services, health_check, bootstrap_graphs), git-hook helpers, and scripts that already delegate (e.g. rename_engine.py — 13 package imports; the 10 delegating factory_*; kg_schema, semantic_search, context_pack). No logic to extract; audited only to confirm the shim is genuinely thin.

3. Functional Requirements

FR-001: Thin-shim invariant (the rule)
FR-002: Behavior preservation
FR-003: Traceability + gating of extracted code
FR-004: Category-A extraction (codemod/refactor)
FR-005: Category-B extraction (by package)
FR-006: Category-C audit
FR-007: Enforcement gate

4. Non-Goals

5. Sequencing

  1. A → codemod (6 scripts; flagship: AST toolkit) — unblocks/aligns SPEC-110/111.
  2. B by package, highest-logic-density first (verification, tools, knowledge_graph, factory, standards, …).
  3. C audit + FR-007 gate to lock it in.

6. Traceability

All extracted code SHALL carry @traces to its origin spec. The move itself is tracked against REQ-112-*. The authoritative per-script mapping is scratchpad/scripts_categorized.json, to be committed into plans/ when SPEC-112 execution begins.