structure-swift-sources
Organize Swift source trees and oversized Swift files by feature, layer, and declaration group; split large files, normalize `// MARK:` sections, enforce plain-language block-comment file headers, and move TODO and FIXME text into ledger files. Use after `format-swift-sources` ha
What it does
Structure Swift Sources
Purpose
Use this skill as the top-level workflow for structural cleanup inside existing Swift repositories. It governs file splitting, file moves, section grouping, plain-language file headers, and TODO or FIXME ledger extraction. scripts/run_workflow.py is the runtime wrapper for repo-shape detection, cleanup-kind classification, header-policy loading, split-threshold loading, and clean handoffs to DocC or Xcode execution workflows. It is not the formatter or linter integration authority, and it is not the DocC authoring authority. Use format-swift-sources before this skill starts mutating source layout, use author-swift-docc-docs when the request becomes symbol-doc or DocC-content work, and run format-swift-sources again after this skill finishes.
When To Use
- Use this skill when the user wants to split oversized Swift files or move files into a clearer repo layout.
- Use this skill when the user wants high-signal
// MARK:sections, declaration grouping, or view-modifier extraction in SwiftUI code. - Use this skill when the user wants consistent block-comment file headers that describe a file's purpose and area of concern in plain terms.
- Use this skill when the user wants structured project-and-file banner headers with deterministic project, filename, copyright, and optional cross-reference fields.
- Use this skill when the user wants TODO or FIXME text moved out of source files into repo ledger files.
- Use this skill when a Swift package or Xcode app repo has drifted away from the intended feature-plus-layer directory shape.
- Recommend
format-swift-sourcesfirst when formatter or linter setup is missing, unclear, or stale. - Recommend
author-swift-docc-docswhen the task becomes symbol documentation, DocC article work, landing-page structure, topic groups, or DocC-oriented review. - Recommend
swift-package-build-run-workfloworswift-package-testing-workflowwhen structural cleanup in a plain package repo turns into ordinary package execution or SwiftPM validation. - Recommend
xcode-build-run-workflowwhen structural cleanup turns into active Xcode execution, scheme validation, file-membership follow-through, or guarded project mutation work. - Recommend
xcode-testing-workflowwhen structural cleanup turns into active Xcode test validation or test-target diagnosis. - Recommend
sync-xcode-project-guidanceorsync-swift-package-guidancewhen the real need is repo-levelAGENTS.mdalignment rather than source-structure cleanup.
Single-Path Workflow
- Classify the request:
- repo layout cleanup
- large-file split
- section and MARK normalization
- file-header normalization
- TODO or FIXME ledger extraction
- combined source-hygiene pass
- Run or confirm
format-swift-sourcesfirst:- use it to establish a clean baseline before file moves or file splits
- if the repo does not have a clear formatter or linter path yet, stop and set that up first
- Resolve the repo shape:
swift-packagexcode-app-projectmixed
- Read the relevant references:
references/glossary.mdreferences/layout-rules.mdreferences/source-organization-rules.mdreferences/file-headers.mdreferences/todo-fixme-ledgers.mdreferences/automation-prompts.mdreferences/customization-flow.md
- Apply the structure rules:
- strongly consider splitting a file once it exceeds the configured soft split threshold and clearly holds
2or more separate concerns - always split a file once it exceeds the configured hard split threshold
- when the underlying type is still one coherent type, extract grouped concerns into extension files such as
<Original>+Models.swiftor<Original>+<Concern>.swift - add
// MARK:groups only when a file is large enough or varied enough that the grouping materially improves navigation, concern ownership, or declaration discovery - skip
// MARK:groups entirely when a short file or an already-obvious declaration run does not present meaningful navigation ambiguity - when groups are warranted, use explicit
// MARK: - <Heading>sections that name a real responsibility boundary instead of restating declaration kinds or symbol names in slightly different words - add a secondary
// MARK: <Comment>line only when it answers a useful navigation question such as why this section exists, what job it serves, or how it differs from nearby sections - never use headings or secondary comments that just restate an obvious type, symbol, or method name, narrate intuitive code in a small file, or pad the file with redundant structure
- require or recommend the documented project-and-file banner header according to the effective header policy
- keep
ConcernandPurposetext in plain terms that explain what the file owns and what job it does, instead of repeating the filename or symbol names as jargon - treat
Key TypesandSee Alsoas optional high-signal fields rather than mandatory filler - move TODO and FIXME text into
TODO.mdandFIXME.md, keeping only ticket IDs in source comments - when the task is TODO or FIXME normalization, use
scripts/normalize_todo_fixme_ledgers.pyfor the deterministic ledger rewrite pass across supported Swift and Objective-C source forms - when the task is file-header normalization or a full cleanup pass that includes headers, use
scripts/normalize_swift_file_headers.pyto audit or apply the documented header shape
- strongly consider splitting a file once it exceeds the configured soft split threshold and clearly holds
- Apply repo-shape rules:
- for Swift packages, prefer directories grouped by layer and feature, such as
API/<Feature>/<Concern>.swiftandFeatures/<Feature>/<Concern>.swift - for Xcode app projects, ensure important app-facing source directories such as
Views/,Controllers/, andModels/ - for SwiftUI views, keep view files in
Views/and pair them with<Name>+Model.swiftand<Name>+Modifier.swiftfiles when those concerns exist
- for Swift packages, prefer directories grouped by layer and feature, such as
- Finish with
format-swift-sourcesagain so the moved or split files end in a normalized state.
Inputs
cleanup_kind: one of the request classes aboverepository_kind:swift-package,xcode-app-project, ormixedtarget_scope: optional narrowed scope such as one file, one feature directory, or the whole reposplit_mode: optional; use values such asadvisory,required, orfull-passtodo_fixme_mode: optional; use values such asreport-only,rewrite-ledgers, ornormalize-existingfile_header_mode: optional; use values such asadvisoryorrequiredfile_header_style: optional; currentlyproject-banner- Defaults:
- run
format-swift-sourcesbefore and after structural mutation - prefer feature-plus-layer layout over flat buckets when the repo has meaningful feature boundaries
- prefer extracted extensions before inventing new wrapper types
- prefer
TODO.mdandFIXME.mdas separate ledger files - prefer the project-and-file banner header described in
references/file-headers.md
- run
Outputs
statussuccess: a supported structure path was selected and explainedhandoff: another skill should take the next stepblocked: the request lacks a safe structural path or the repo shape is too unclear
path_typeprimary: the documented structure path completedfallback: a narrower safe pass was chosen
outputcleanup_kindrepository_kindrecommended_pathlayout_targetssplit_targetsledger_filesheader_policyhelper_scriptscaveatsverification
Guards and Stop Conditions
- Do not split files purely by line count when the code still represents one small, coherent concern and the real problem is formatting or comments.
- Do not invent new abstraction layers just to make a file shorter.
- Do not move files across Xcode-managed boundaries without accounting for project membership and validation.
- Do not treat file-header automation as permission to invent vague or generic purpose text. Header content must come from the actual code understanding or an explicit inventory.
- Do not make end users reverse-engineer the file-header inventory shape from prose or tests. Point them at
references/file-header-inventory.template.yamlwhen--apply --inventoryis the right path. - Do not rewrite TODO or FIXME comments into ledger IDs unless the ledger files are updated in the same pass.
- Do not absorb symbol-doc or DocC-content work; hand that off to
author-swift-docc-docs. - Stop with
blockedwhen the repo shape is too ambiguous to choose feature-first versus layer-first layout safely. - Stop with
handoffwhen project-file mutation or Xcode membership updates need guarded execution throughxcode-build-run-workflow.
Fallbacks and Handoffs
- If the repo lacks a clear formatter or linter baseline, hand off to
format-swift-sourcesbefore any structural mutation. - If a broad repo-wide cleanup is too risky, fall back to one feature directory or one oversized file at a time.
- If the request becomes symbol-doc or DocC-content work, hand off to
author-swift-docc-docs. - If Xcode project integrity must be revalidated after file moves, hand off to
xcode-build-run-workflow. scripts/run_workflow.pyis the top-level runtime entrypoint and converts repo inspection plus request inference into the documented JSON contract.- Recommend
sync-xcode-project-guidanceorsync-swift-package-guidancewhen the request is really about durable repo rules rather than current-file cleanup.
Customization
- Use
references/customization-flow.md. scripts/customization_config.pystores and reports customization state.scripts/run_workflow.pyloads the runtime-enforced header policy and split thresholds before shaping the final workflow contract.
References
Workflow References
references/glossary.mdreferences/layout-rules.mdreferences/source-organization-rules.mdreferences/file-headers.mdreferences/todo-fixme-ledgers.md
Contract References
references/automation-prompts.mdreferences/customization-flow.md
Support References
- Recommend
format-swift-sourcesfirst for formatter or linter setup and again after structural edits complete. - Recommend
references/layout-rules.mdwhen the user needs the package-versus-app directory contract explained.
Script Inventory
scripts/customization_config.pyscripts/run_workflow.pyscripts/normalize_todo_fixme_ledgers.pyscripts/normalize_swift_file_headers.pyreferences/file-header-inventory.template.yaml
Capabilities
Install
Quality
deterministic score 0.45 from registry signals: · indexed on github topic:agent-skills · 7 github stars · SKILL.md body (10,663 chars)