Complexity Budget Rule for Splitting Sections in AI Website-Cloner
The AI Website-Cloner enforces a strict ~150-line complexity budget that automatically splits oversized section specifications into smaller sub-components to maintain generation quality and enable parallel processing.
The complexity budget rule is a core orchestration constraint in the JCodesMore/ai-website-cloner-template repository that prevents builder agents from receiving unmanageable prompt sizes. When a section's specification exceeds approximately 150 lines of content, the system treats it as too complex for a single agent and mandates decomposition into logical sub-components such as individual cards, tab sets, or interactive elements.
What Is the Complexity Budget Rule?
The complexity budget rule is a mechanical safeguard hardcoded into the AI Website-Cloner's workflow logic. According to the source documentation in .windsurf/workflows/clone-website.md, the rule states: "If a builder prompt exceeds ~150 lines of spec content, the section is too complex for one agent. Break it into smaller pieces. This is a mechanical check — don't override it with 'but it's all related.'"
This threshold is enforced uniformly across all agent dispatch operations. The rule appears in multiple orchestration files—including .opencode/commands/clone-website.md and .github/skills/clone-website/SKILL.md—ensuring that both local Windsurf workflows and GitHub-based CI/CD pipelines respect the same constraint.
Why 150 Lines? The Technical Rationale
The ~150-line limit is not arbitrary; it balances LLM context window limitations with practical parallelization needs.
Readability and LLM Context Windows
Prompts longer than 150 lines become difficult for large language models to parse reliably. When specifications grow beyond this threshold, the density of detail—CSS values, asset lists, and nested component structures—overwhelms the agent's ability to generate coherent, bug-free code in a single pass.
Parallel Agent Dispatch
Smaller prompts enable the orchestrator to dispatch multiple builder agents simultaneously across separate work-trees. This parallelization significantly accelerates the cloning process for complex webpages, as distinct sub-components can be generated concurrently rather than sequentially.
Error Isolation and Retry Efficiency
When a single agent handles an oversized section, any failure requires regenerating the entire specification. By splitting sections at the 150-line boundary, errors become isolated to specific sub-components. If one agent fails, the orchestrator retries only that discrete chunk rather than the entire section, reducing computational overhead and latency.
Where the Rule Is Defined in the Source Code
The complexity budget rule is documented authoritatively in line 46-47 of .windsurf/workflows/clone-website.md. The same wording propagates to .opencode/commands/clone-website.md for command-line interface operations and .github/skills/clone-website/SKILL.md for GitHub skill definitions. This triplicate documentation ensures consistent enforcement whether the tool runs in Windsurf, Opencode, or GitHub Actions environments.
How to Implement the Complexity Budget Rule
Applying the rule requires a systematic line-counting and splitting workflow:
- Count specification lines including all generated code snippets, asset lists, and detailed CSS values intended for the builder prompt.
- Identify logical sub-components such as cards, navigation items, tab panels, or distinct interactive elements.
- Create separate spec files for each sub-component and dispatch a distinct builder agent for each file.
- Merge work-trees after all agents complete, combining the sub-components into the final section output.
Programmatically Enforcing the Budget in Code
The repository includes utility functions that automate the complexity check and splitting logic. The splitSpecIfNeeded function in the specification builder utilities demonstrates the mechanical enforcement:
// utils/specBuilder.ts
export function splitSpecIfNeeded(spec: string): string[] {
const MAX_LINES = 150;
const lines = spec.split('\n');
// If within budget, return a single‑prompt array
if (lines.length <= MAX_LINES) return [spec];
// Otherwise split by top‑level component markers (e.g. `--- Component: Card ---`)
const chunks: string[] = [];
let current: string[] = [];
for (const line of lines) {
if (line.startsWith('--- Component:')) {
// Start a new component – push previous chunk if not empty
if (current.length) chunks.push(current.join('\n'));
current = [line]; // include the marker line
} else {
current.push(line);
}
}
if (current.length) chunks.push(current.join('\n'));
// Ensure each chunk respects the line budget (fallback: further split by size)
return chunks.flatMap(chunk =>
chunk.split('\n').length > MAX_LINES
? chunk.match(new RegExp(`(.{1,${MAX_LINES * 80}})`, 'g')) ?? []
: [chunk]
);
}
The dispatch logic then handles the parallel execution:
// scripts/dispatchBuilders.ts
import { splitSpecIfNeeded } from '@/utils/specBuilder';
import { dispatchBuilderAgent } from '@/agents/builder';
async function handleSection(sectionSpec: string) {
const prompts = splitSpecIfNeeded(sectionSpec);
for (const prompt of prompts) {
await dispatchBuilderAgent(prompt); // each prompt runs in its own worktree
}
}
These implementations perform a line-count check, automatically split by component markers, and provide a fallback splitting mechanism when individual chunks still exceed the budget.
Summary
- The complexity budget rule mandates splitting any builder prompt exceeding ~150 lines of specification content.
- This rule is a mechanical safeguard documented in
.windsurf/workflows/clone-website.md,.opencode/commands/clone-website.md, and.github/skills/clone-website/SKILL.md. - The 150-line threshold optimizes LLM readability, enables parallel agent processing, and provides error isolation for efficient retries.
- Implement the rule using the
splitSpecIfNeededutility to automatically decompose oversized specifications into manageable sub-components.
Frequently Asked Questions
What happens if I ignore the 150-line complexity budget?
Ignoring the threshold causes builder agents to receive overwhelming amounts of detail, which degrades the quality of generated code and increases the likelihood of syntax errors and logical bugs. The orchestrator treats the 150-line limit as non-negotiable to prevent these failure modes.
How do I count lines for the complexity budget check?
Count every line in the specification you intend to send to the builder agent, including generated code snippets, asset lists, detailed CSS values, and structural markup. The splitSpecIfNeeded function in src/utils/specBuilder.ts automates this by splitting the spec string on newline characters and checking the array length against MAX_LINES.
Can I increase the complexity budget limit beyond 150 lines?
No. The rule is explicitly documented as a mechanical check that agents must not override. Even if sub-components seem logically related, exceeding 150 lines violates the architectural safeguards designed to maintain generation quality and parallelization efficiency.
What constitutes a logical sub-component for splitting?
Logical sub-components include discrete UI elements such as individual cards, navigation items, tab panels, button groups, or distinct interactive elements. The code example uses markers like --- Component: Card --- to identify these boundaries programmatically, ensuring each resulting chunk remains under the 150-line threshold.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →