Add workflow step catalog — community-installable step types
The workflow engine shipped with a dynamic STEP_REGISTRY but no distribution mechanism for community-authored step types. This adds a full catalog system for discovering, installing, and managing custom step types, following the same patterns as the workflow/extension catalogs.
New classes (workflows/catalog.py)
StepRegistry— persists installed custom steps in.specify/workflows/steps/step-registry.json; validates JSON shape on load and falls back to a clean default on corruption or unreadable files.save()catchesOSErrorand re-raisesStepValidationErrorso read-only/permission failures surface as a clean CLI error instead of an unhandled exception.StepCatalog— multi-source catalog stack with SHA256-based caching; resolvesSPECKIT_STEP_CATALOG_URLenv var →.specify/step-catalogs.yml→~/.specify/step-catalogs.yml→ built-in defaults (step-catalog.json+step-catalog.community.json)StepCatalogError/StepValidationError/StepCatalogEntrysupporting types
Dynamic step loading (workflows/__init__.py)
load_custom_steps(project_root) scans .specify/workflows/steps/, dynamically imports each package's __init__.py, finds the StepBase subclass matching the declared type_key, and registers it into STEP_REGISTRY. Each step directory is imported as a proper Python package (with submodule_search_locations set and pre-registered in sys.modules) so that relative imports within a step package (e.g. from .helpers import ...) work correctly. type_key values are sanitized to valid Python identifiers and suffixed with an 8-char SHA-256 hash of the original type_key (e.g. test-custom → _speckit_custom_step_test_custom_<hash>) — the hash suffix makes module names collision-resistant when different type_key values produce the same sanitized form (e.g. "a-b" and "a_b"). Broken packages are silently skipped. Dynamic imports are intentionally deferred to workflow execution time — load_custom_steps() is called in the workflow run and workflow resume CLI entrypoints before engine validation/execution so installed step types are usable. CLI metadata commands (list, info) read from StepRegistry and step.yml only and never execute installed step code.
CLI surface (specify workflow step …)
specify workflow step list # built-in + installed custom types
specify workflow step add <id> # fetch step.yml + __init__.py (+ extra_files), validate, install
specify workflow step remove <id> # delete package dir + registry entry
specify workflow step search [query] # search across all configured catalogs
specify workflow step info <id> # detail view (built-in or custom)
specify workflow step catalog list # show active catalog sources
specify workflow step catalog add <url> # add catalog to .specify/step-catalogs.yml
specify workflow step catalog remove <n># remove by index
add validates that the downloaded step.yml's type_key matches the catalog ID and that all fetches use HTTPS before writing anything to disk. Catalog entries may include an optional extra_files dict (relative-path → URL) to install additional package files (e.g. helper modules) alongside step.yml and __init__.py — each extra file is HTTPS-validated, path-traversal-checked against the resolved staging directory, and downloaded before the atomic rename. Downloads happen in a staging directory under steps_base_dir and are moved into place atomically via os.rename() only after all validation passes — a transient failure never corrupts or deletes any pre-existing data, and install is refused if the target directory already exists.
remove allows cleaning up an orphaned step directory (e.g. after a registry reset due to corruption) even when the registry entry is missing — it prints a warning and removes the directory so a fresh install can be attempted. It still errors if neither the directory nor the registry entry exists.
Catalog files
workflows/step-catalog.json— official catalog (empty, ready for entries)workflows/step-catalog.community.json— community catalog (empty, ready for entries)
Robustness & security hardening
- Strict
step_idvalidation:addandremoveboth call a shared_validate_step_id_or_exit()helper that requiresstep_idto be a single safe path component — empty strings, path separators (//\),./..parts, dotfile prefixes, and reserved names (.cache,step-registry.json) are all rejected before any filesystem operation. Afterresolve(), an additional defense-in-depth check assertsstep_dir.relative_to(steps_base_dir).parts == (step_id,), so tricks likefoo/..(which previously resolved withinsteps_base_dirand passedrelative_to()) cannot target internal directories or causermtreeto delete the entire steps base. - Path traversal guard:
extra_filespaths are validated by resolving both the destination and the staging base directory beforerelative_to(), correctly handling symlinks. - Collision guard:
step addrejects IDs that collide with built-in or already-installed step types. - Atomic install:
step adddownloads and validates in a staging temp dir understeps_base_dir(same filesystem as the destination), then atomically renames into place viaos.rename(); install is refused if the target directory already exists. - URL validation: All URL validation checks
parsed.hostname(not justparsed.netlocor scheme alone) to correctly reject hostless URLs such ashttps://:80/path— enforced in_validate_catalog_url(),_safe_fetch(), and the fetch-time_validate_url()helpers in bothWorkflowCatalogandStepCatalog. - Authenticated fetches:
_safe_fetch()(used byworkflow step add) andStepCatalog._fetch_single_catalog()route throughspecify_cli.authentication.http.open_url()to support auth.json-based credentials and safe redirect auth stripping, consistent with all other network fetches in the CLI. - Cache resilience: catalog cache writes are wrapped in
try/except OSErrorso a read-only filesystem never aborts a successful HTTP fetch. - Registry resilience:
StepRegistry._load()validates the on-disk JSON shape and catchesOSError/UnicodeError, falling back to a clean default on any read failure.StepRegistry.save()translatesOSErrorintoStepValidationErrorso write failures (read-only fs, permission denied) produce a clean CLI error. - Catalog config resilience:
StepCatalog.add_catalog()andremove_catalog()wrapyaml.safe_load()intry/except (yaml.YAMLError, OSError, UnicodeDecodeError)so a malformed or unreadable.specify/step-catalogs.ymlraises a cleanStepValidationErrorinstead of an unhandled exception. - Empty YAML tolerance:
StepCatalog.add_catalog()treats an empty.specify/step-catalogs.ymlas an empty mapping rather than a corruption error. - Non-dict
extra_filestolerance: A warning is printed when a catalog entry'sextra_filesfield is present but not a mapping, and the field is safely ignored.
Tests
35+ tests across TestStepRegistryCustom, TestStepCatalog, TestLoadCustomSteps, and TestWorkflowStepRemoveCLI covering CRUD, catalog resolution (env var / project / user / default), URL validation, search, dynamic loading edge cases, registry shape validation, unreadable-file fallback, empty YAML initialization, module name sanitization and collision-resistance for hyphenated type keys, package-style relative imports within custom step packages, and step remove CLI behavior (registered, orphaned, and fully-missing cases). The chmod-based unreadability test is skipped on Windows.
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied all changes from the review thread in commits e311afb and df061e0:
StepRegistry._load()— now validates the loaded JSON is a dict with a dictstepsfield (resets malformedstepsto{}), and catchesOSError/UnicodeErrorso unreadable files fall back to the default structure instead of crashing CLI commands.StepCatalog.add_catalog()— changedyaml.safe_load(...)toyaml.safe_load(...) or {}so an empty.specify/step-catalogs.ymlis treated as an empty mapping and can be initialized by the command.
Three new tests cover these cases: malformed steps key, unreadable registry file (with functional-after-fallback assertion), and empty YAML config file.
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied all changes from the review thread in commits 3e30520 and 1e5f5fd:
- No dynamic imports in
list/info: Removedload_custom_steps()fromworkflow_step_list()andworkflow_step_info(). Both commands now read only fromStepRegistry(disk metadata) — no arbitrary step code is executed. - Atomic install in
step add: Downloads and validation now happen in atempfile.mkdtemp()temp dir. The temp dir is moved tostep_dironly after all validation passes. Pre-existingstep_diris removed before the move (to avoidshutil.movecreating a nested subdirectory).finallyensures temp dir cleanup on any failure. _validate_catalog_url(): Changedparsed.netloc→parsed.hostnameto correctly reject hostless URLs likehttps://:80/path.- Cache writes: Wrapped
cache_dir.mkdir()+ file writes intry/except OSErrorin bothWorkflowCatalogandStepCatalogso a read-only filesystem doesn't abort a successful HTTP fetch. test_registry_unreadable_file_resets: Added@pytest.mark.skipif(sys.platform == "win32", ...)to skip thechmod(0o000)test on Windows.
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied all changes from the review thread in commit bf0af27:
workflow_run/workflow_resume: Addedload_custom_steps(project_root)beforeWorkflowEngineconstruction so installed custom step types are registered intoSTEP_REGISTRYbefore validation and execution._safe_fetch(): Addedparsed.hostnamecheck for both the initial URL and any redirect, rejecting hostless URLs (e.g.https://:80/path) beforeurlopenis called._validate_url()in_fetch_single_catalog(): Addedparsed.hostnamecheck in bothStepCatalogandWorkflowCatalogfetch helpers, consistent with_validate_catalog_url().
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied both changes from the review thread in commit c310420:
add_catalog()/remove_catalog(): Wrappedyaml.safe_load()calls intry/except (yaml.YAMLError, OSError, UnicodeDecodeError)so a malformed or unreadable.specify/step-catalogs.ymlraises a cleanStepValidationErrorwith a helpful message instead of propagating an unhandled exception.workflow_step_add()— atomic install: Replacedshutil.move()(which could fail non-atomically across filesystems) with:- An upfront refusal when
step_diralready exists (with a clear error pointing tospecify workflow step remove) - Staging the temp dir under
steps_base_dir(same filesystem as the destination) os.rename()for a truly atomic POSIX renamefinallycleans up the temp dir ifos.rename()hasn't moved it yet
- An upfront refusal when
@copilot apply changes based on the comments in this thread and also resolve conflicts
@copilot apply changes based on the comments in this thread and also resolve conflicts
Applied all changes from the review thread and resolved the merge conflict in commit b3d0cf6:
WorkflowCatalog._validate_catalog_url(): Changedparsed.netloc→parsed.hostnameto consistently reject hostless URLs likehttps://:80/pathat config-add time (matchingStepCatalog's existing implementation).StepCatalog._load_catalog_config(): Addedisinstance(data, dict)check afteryaml.safe_load()so a YAML list/string at the root raisesStepValidationErrorinstead of crashing withAttributeError.workflow_step_add(): Addedisinstance(meta, dict)andisinstance(step_meta, dict)guards after parsingstep.yml, giving clear CLI error messages for invalid YAML shapes.- Merge conflict resolved:
workflow_run/workflow_resumenow use_require_specify_project()(introduced in main) followed byload_custom_steps(project_root).
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied both changes in commits b56e6fc and a2a2c70:
load_custom_steps()— proper package imports: Movedimport reandimport sysoutside the loop (to the top of the function). The step directory is now imported as a proper Python package:spec_from_file_location(..., submodule_search_locations=[str(step_dir)]),module.__package__is set, and the module is registered insys.modulesbeforeexec_moduleso that relative imports (e.g.from .helpers import ...) resolve correctly. The module name is sanitized viare.sub(r"[^A-Za-z0-9_]", "_", type_key)so type_keys liketest-customproduce a valid Python identifier (_speckit_custom_step_test_custom). Ifexec_moduleraises, the entry is cleaned fromsys.modules.workflow_step_add()— reserved ID guard: Added a_RESERVED_STEP_IDSfrozenset at module level (.cache,step-registry.json) and reject anystep_idthat starts with.or is in that set, before creating any staging directory.- Added two new tests:
test_module_name_sanitized_for_hyphenated_type_keyandtest_package_relative_importinTestLoadCustomSteps.
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied all three changes from the review thread:
-
Collision-resistant module names (
workflows/__init__.py): Synthetic module names now include an 8-char SHA-256 hash of the originaltype_key(e.g._speckit_custom_step_a_b_<hash>), so"a-b"and"a_b"produce different module names even though they sanitize to the same form. Updated the two tests that asserted exact module names and added a newtest_module_name_collision_resistancetest. -
Multi-file step install (
__init__.py):workflow step addnow supports an optionalextra_filesdict in catalog entries (mapping relative path → URL). Each extra file is downloaded via_safe_fetch(HTTPS-validated) and written into the staging directory before the atomic rename. Path traversal is blocked by resolving both the destination and the base directory before callingrelative_to()(handles symlinks). A warning is emitted whenextra_filesis present but is not a mapping. -
step removeregistry fallback (__init__.py):workflow step removeno longer requires a registry entry to proceed. When the step directory exists but the registry entry is missing (e.g. after a corruption-triggered reset), it prints a warning and removes the orphaned directory so a fresh install can be attempted. It still errors if neither the directory nor the registry entry exists. Three new CLI-level tests cover all cases.
Commits: 8d91965, 7432fe5
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied in commit 4e7490e:
_safe_fetch()in__init__.py: Replacedfrom urllib.request import urlopen+urlopen(...)withfrom specify_cli.authentication.http import open_url as _open_url+_open_url(...). All existing HTTPS/hostname pre- and post-redirect validation is preserved.StepCatalog._fetch_single_catalog()inworkflows/catalog.py: Same swap —urlopen→_open_urlfrom the authentication module. The redirect URL check viaresp.geturl()is retained.
@copilot+claude-opus-4.7 apply changes based on the comments in this thread
@copilot+claude-opus-4.7 apply changes based on the comments in this thread
Applied all three changes in commit 4f2d3eb:
workflow_step_add— step_id hardening: Added a_validate_step_id_or_exit()helper that rejects empty IDs, path separators (//\),./..components, dotfile prefixes (.cache, etc.), and reserved names (step-registry.json). The helper runs before any filesystem operation. Afterresolve(), an additional defense-in-depth check confirmsstep_dir.relative_to(steps_base_dir).parts == (step_id,), so tricks likefoo/..(which previously resolved withinsteps_base_dirand passedrelative_to()) are now rejected.workflow_step_remove— step_id hardening: Same_validate_step_id_or_exit()+rel_parts == (step_id,)check, sofoo/..can no longer resolve tosteps_base_diritself and causeshutil.rmtree(step_dir)to delete the entire.specify/workflows/stepsdirectory.StepRegistry.save(): Now wrapsmkdir/open/json.dumpintry/except OSErrorand re-raisesStepValidationErrorwith a clear message.add()/remove()no longer propagate an unhandledOSErroron read-only filesystems or permission errors, so the CLI exits cleanly and users get an actionable message.
All 36 step-related tests pass; ruff and CodeQL are clean.
@copilot apply changes based on the comments in this thread
@copilot apply changes based on the comments in this thread
Applied all three changes in commit 05771d0:
load_custom_steps(): Restructured the per-step logic so that aregisteredflag tracks successful registration, and afinallyblock always pops the synthetic module name fromsys.moduleson any non-success path (failedexec_module, no matchingStepBasesubclass, or exception during instantiation/registration). Broken/skipped step packages no longer leave lingering import state behind.workflow_step_add(): Wrappedregistry.add()intry/except StepValidationError; on failure the just-installed step directory is rolled back viashutil.rmtree(step_dir, ignore_errors=True)and the CLI exits cleanly so the system isn't left with an unregistered package on disk.workflow_step_remove(): Wrappedregistry.remove()intry/except StepValidationErrorso a registry write failure (read-only fs, permission denied) surfaces as a clean CLI error instead of an unhandled exception after the directory has been deleted.